google-research / bert

TensorFlow code and pre-trained models for BERT
https://arxiv.org/abs/1810.04805
Apache License 2.0
37.86k stars 9.56k forks source link

Help:! unable to load the pretrained model from local/colab directory #955

Open AjitAntony opened 4 years ago

AjitAntony commented 4 years ago

Hi i downloaded the saved to a directory in colab.

when i try to load the model im getting "We assumed '/content/drive/My Drive/bert_training/uncased_L-12_H-768_A-12/config.json"

this is how i loaded the model: from transformers import BertForMaskedLM BertNSP=BertForMaskedLM.from_pretrained('/content/drive/My Drive/bert_training/uncased_L-12_H-768_A-12/')

is this the correct way of loading model from the directory when i have downloaded the pretrained model ? Im getting error " '/content/drive/My Drive/bert_training/uncased_L-12_H-768A-12/config.json' " the downloaded model had these naming conventions where file name start with bert but the BertForMaskedLM class is expecting the file name to be config.json .

bert_config.json
bert_model.ckpt.data-00000-of-00001 bert_model.ckpt.index vocab.txt bert_model.ckpt.meta

FULL ERROR: Model name '/content/drive/My Drive/bert_training/uncased_L-12_H-768_A-12/' 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, bert-base-german-cased, bert-large-uncased-whole-word-masking, bert-large-cased-whole-word-masking, bert-large-uncased-whole-word-masking-finetuned-squad, bert-large-cased-whole-word-masking-finetuned-squad, bert-base-cased-finetuned-mrpc, bert-base-german-dbmdz-cased, bert-base-german-dbmdz-uncased). We assumed '/content/drive/My Drive/bert_training/uncased_L-12_H-768_A-12/config.json' was a path or url to a configuration file named config.json or a directory containing such a file but couldn't find any such file at this path or url.

when i renamed the above 4 files by removing bert from all 4 file names , i get this error even though the "model.ckpt.index" files exist "OSError: Error no file named ['pytorch_model.bin', 'tf_model.h5', 'model.ckpt.index'] found in directory /content/drive/My Drive/bert_training/uncased_L-12_H-768_A-12/ or from_tf set to False"

Bigmai-1234 commented 4 years ago

i got the same problem