Transformers: can't load the model

Created on 6 Mar 2019  路  20Comments  路  Source: huggingface/transformers

model = BertModel.from_pretrained('bert-large-cased')
Model name 'bert-large-cased' was not found in model name list (bert-base-uncased, bert-large-uncased, bert-base-cased, bert-large-cased, bert-base-multilingual-uncased, bert-base-multilingual-cased, bert-base-chinese). We assumed 'https://s3.amazonaws.com/models.huggingface.co/bert/bert-large-cased.tar.gz' was a path or url but couldn't find any file associated to this path or url.

Need more information

Most helpful comment

@thomwolf @countback
I finally fixed the problem by downloading the tf checkpoints directly from here, and then using the 'convert_tf_checkpoint_to_pytorch.py' function to create a pytorch_model.bin file.
I then used the path to pytorch_model.bin and bert_config.json file in BertModel.from_pretrained('path/to/bin/and/json') instead of 'bert-base-uncased'.
馃憤
Helpful info was found here.

All 20 comments

Strange error.

Can you try:

import pytorch_pretrained_bert as ppb
assert 'bert-large-cased' in ppb.modeling.PRETRAINED_MODEL_ARCHIVE_MAP

Do you have an open internet connection on the server that run the script?

@thomwolf Is there a way to point to a model on disk? This question seems related enough to daisychain with this issue. :-)

I noticed that this error happens when you exceed the disk space in the temporary directory while downloading BERT.

I ran into the same problem. When I used the Chinese pre-training model, it was sometimes good and sometimes bad.

@thomwolf I've been having the same error, and I received an AssertionError when I try

assert 'bert-based-uncased' in bert.modeling.PRETRAINED_MODEL_ARCHIVE_MAP

I've tried using both conda install and Pip install to get the package but in both cases I am not able to load any models

Hi @DuncanCam-Stein,
Which version of python do you have?
Can you try to install from source?

@thomwolf @countback
I finally fixed the problem by downloading the tf checkpoints directly from here, and then using the 'convert_tf_checkpoint_to_pytorch.py' function to create a pytorch_model.bin file.
I then used the path to pytorch_model.bin and bert_config.json file in BertModel.from_pretrained('path/to/bin/and/json') instead of 'bert-base-uncased'.
馃憤
Helpful info was found here.

The network connection check has been relaxed in the now merged #500.
Serialization of the model have also been simplified a lot with #489.

These improvements will be included in the next PyPI release (probably next week).

In the meantime you can install from master and already use the serialization best-practices described in the README here

As @martiansideofthemoon said, I met this error because I didn't have enough space on disk.

Check if you can download the file with :

wget https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-uncased.tar.gz

@martiansideofthemoon What does that mean if we can download it via wget but not when we use from_pretrained? is it a disk space problem?

@Hannabrahman
If you can download it via wget, it means you have enough disk space, so the issue is from somewhere else.

@Colanim Thanks. I figured out it was memory issue on the cache directory.

@Hannabrahman

@Colanim Thanks. I figured out it was memory issue on the cache directory.

how did you solve this issue?

@raj5287
Free some disk space on the cache directory or specify another cache directory

@Colanim i have enough disk space since i have downloaded the file using
wget https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-uncased.tar.gz but i am not sure how to specify another cache directory or use the downloaded file (i am new to pytorch and ubuntu :| )

@thomwolf @countback
I finally fixed the problem by downloading the tf checkpoints directly from here, and then using the 'convert_tf_checkpoint_to_pytorch.py' function to create a pytorch_model.bin file.
I then used the path to pytorch_model.bin and bert_config.json file in BertModel.from_pretrained('path/to/bin/and/json') instead of 'bert-base-uncased'.
+1
Helpful info was found here.

@DuncanCam-Stein i have downloaded and placed _pytorch_model.bin_ and _bert_config.json_ in _bert_tagger_ folder but when i am doing tokenizer = BertModel.from_pretrained('home/user/Download/bert_pos_tagger/bert_tagger/') i am still getting the error : Model name 'home/user/Downloads/bert_pos_tagger/bert_tagger/' was not found in model name list (bert-base-uncased, bert-large-uncased, bert-base-cased, bert-large-cased, bert-base-multilingual-uncased, bert-base-multilingual-cased, bert-base-chinese). We assumed 'home/user/Downloads/bert_pos_tagger/bert_tagger/' was a path or url but couldn't find any file associated to this path or url.

try to delete cahe file and rerun the command

I noticed that the error appears when I execute my script in debug mode (in Visual Studio Code). I fixed it by executing the script over the terminal python myscriptname.py once. Afterwards Debug mode works fine.

Btw. I got the same problem with the tokenizer and this also fixed it.

model = BertModel.from_pretrained('bert-large-cased')
Model name 'bert-large-cased' was not found in model name list (bert-base-uncased, bert-large-uncased, bert-base-cased, bert-large-cased, bert-base-multilingual-uncased, bert-base-multilingual-cased, bert-base-chinese). We assumed 'https://s3.amazonaws.com/models.huggingface.co/bert/bert-large-cased.tar.gz' was a path or url but couldn't find any file associated to this path or url.

hello锛孖 meet the problem when run the torch bert code 馃憤

OSError: Can't load weights for 'bert-base-uncased'. Make sure that:

  • 'bert-base-uncased' is a correct model identifier listed on 'https://huggingface.co/models'

  • or 'bert-base-uncased' is the correct path to a directory containing a file named one of pytorch_model.bin, tf_model.h5, model.ckpt.
    if I can download the bert-base-uncased weight, where I should put the file in ? hope your reply~

@DTW1004 check your network connection. This happens when I'm behind a proxy and SSL/proxy isn't configured appropriately.

Was this page helpful?
0 / 5 - 0 ratings