Error while trying to run using my saved model: TypeError: ‘NoneType’ object is not iterable

I have trained a BertForSequenceClassification model, saved the model and tokenizer by


I’m trying to run and I want it to load the saved model above:

python \
    --model_name_or_path /path/to/output_mlm_cls \
    --train_file /path/to/my_data.txt \
    --do_train \
    --output_dir /output_dir

Then I get this error message:

Traceback (most recent call last):
File “”, line 408, in
File “”, line 367, in main
train_result = trainer.train(resume_from_checkpoint=checkpoint)
File “/home/cl/jungmin-c/.pyenv/versions/anaconda3-5.1.0/envs/jp/lib/python3.7/site-packages/transformers/”, line 1066, in train
File “/home/cl/jungmin-c/.pyenv/versions/anaconda3-5.1.0/envs/jp/lib/python3.7/site-packages/transformers/”, line 1387, in _load_state_dict_in_model
if set(load_result.missing_keys) == set(self.model._keys_to_ignore_on_save):
TypeError: ‘NoneType’ object is not iterable

I could not figure out what is wrong with my approach. I would greatly appreciate your suggestion.
Thank you!

Based on the error message it seems that one of the inputs to set is a None object as seen here:

> TypeError: 'NoneType' object is not iterable

My guess would be that the transformers.trainer object is unable to load the desired file and returns None instead.
CC @stas for viz.

1 Like

Thanks for the ping, @ptrblck!

I’m not familiar with: transformers/ at master · huggingface/transformers · GitHub as it’s some experimental example I have never used and it’s not being maintained, so it’s very likely to be out of sync with the current code base. Therefore @jungminc88 please file an Issue at Issues · huggingface/transformers · GitHub

You probably need to tag the person who wrote this example, see the original PR:

1 Like