Hello!
I created my own model (i.e., class BertForMultiLabelClassification(BertPreTrainedModel)
) and I train it with a transformers.Trainer
. As training arguments I specify save_total_limit=2
, load_best_model_at_end=True
and save_strategy=epoch
. After the training I have trainer.save_model()
. This seems to work fine and I see the saved model and tokenizer files in the proper directory.
Loading and using the tokenizer with AutoTokenizer.from_pretrained(my_path)
works fine.
Loading the model with AutoModel.from_pretrained(my_path)
or BertForMultiLabelClassification.from_pretrained(my_path)
fails with
ValueError: invalid literal for int() with base 10: 'CD000009'
May I ask for some help?
thank you very much!
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-62-3d86b810dabb> in <module>
----> 1 my_model = BertForMultiLabelClassification.from_pretrained(p)
2 my_model
~/.azureml/envs/azureml_389e19432b898fec54de7429d4696827/lib/python3.6/site-packages/transformers/modeling_utils.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
1198 _from_auto=from_auto_class,
1199 _from_pipeline=from_pipeline,
-> 1200 **kwargs,
1201 )
1202 else:
~/.azureml/envs/azureml_389e19432b898fec54de7429d4696827/lib/python3.6/site-packages/transformers/configuration_utils.py in from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
460 )
461
--> 462 return cls.from_dict(config_dict, **kwargs)
463
464 @classmethod
~/.azureml/envs/azureml_389e19432b898fec54de7429d4696827/lib/python3.6/site-packages/transformers/configuration_utils.py in from_dict(cls, config_dict, **kwargs)
565 return_unused_kwargs = kwargs.pop("return_unused_kwargs", False)
566
--> 567 config = cls(**config_dict)
568
569 if hasattr(config, "pruned_heads"):
~/.azureml/envs/azureml_389e19432b898fec54de7429d4696827/lib/python3.6/site-packages/transformers/models/bert/configuration_bert.py in __init__(self, vocab_size, hidden_size, num_hidden_layers, num_attention_heads, intermediate_size, hidden_act, hidden_dropout_prob, attention_probs_dropout_prob, max_position_embeddings, type_vocab_size, initializer_range, layer_norm_eps, pad_token_id, gradient_checkpointing, position_embedding_type, use_cache, **kwargs)
141 **kwargs
142 ):
--> 143 super().__init__(pad_token_id=pad_token_id, **kwargs)
144
145 self.vocab_size = vocab_size
~/.azureml/envs/azureml_389e19432b898fec54de7429d4696827/lib/python3.6/site-packages/transformers/configuration_utils.py in __init__(self, **kwargs)
266 if self.id2label is not None:
267 kwargs.pop("num_labels", None)
--> 268 self.id2label = dict((int(key), value) for key, value in self.id2label.items())
269 # Keys are always strings in JSON so convert ids to int here.
270 else:
~/.azureml/envs/azureml_389e19432b898fec54de7429d4696827/lib/python3.6/site-packages/transformers/configuration_utils.py in <genexpr>(.0)
266 if self.id2label is not None:
267 kwargs.pop("num_labels", None)
--> 268 self.id2label = dict((int(key), value) for key, value in self.id2label.items())
269 # Keys are always strings in JSON so convert ids to int here.
270 else:
ValueError: invalid literal for int() with base 10: 'CD000009'