From 751a1e08904fda197366e4b0033bdfb8b10d256c Mon Sep 17 00:00:00 2001 From: Julien Chaumond Date: Mon, 1 Jun 2020 16:25:43 +0200 Subject: [PATCH] [config] Ensure that id2label always takes precedence over num_labels Fixes bug reported in https://github.com/huggingface/transformers/issues/4669 See #3967 for context --- src/transformers/configuration_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/transformers/configuration_utils.py b/src/transformers/configuration_utils.py index 8aafa6dcf2..fb63a94646 100644 --- a/src/transformers/configuration_utils.py +++ b/src/transformers/configuration_utils.py @@ -89,6 +89,7 @@ class PretrainedConfig(object): self.id2label = kwargs.pop("id2label", None) self.label2id = kwargs.pop("label2id", None) if self.id2label is not None: + del kwargs["num_labels"] self.id2label = dict((int(key), value) for key, value in self.id2label.items()) # Keys are always strings in JSON so convert ids to int here. else: