问题:

OSError: Error no file named pytorch_model.bin, tf_model.h5, model.ckpt.index or flax_model.msgpack found in directory

出现过程:

使用transformers的Bertmodel时

问题代码:

model = Bertmodel.from_pretrained('bert_model')

问题原因:

下载的模型文件夹中没有pytorch_model.bin/tf_model.h5等文件,去原网址中查找也未发现相关文件。继而查看transformers官方使用说明:

from_pretrained(pretrained_model_name_or_path,*model_args,**kwargs)

  • pretrained_model_name_or_path– either: – a string with theshortcut nameof a pre-trained model to load from cache or download, e.g.:bert-base-uncased. – a string with theidentifier nameof a pre-trained model that was user-uploaded to our S3, e.g.:dbmdz/bert-base-g