Bert官方github地址:https://github.com/google-research/bert?tab=readme-ov-file
【hugging face无法加载预训练模型】OSError:Can‘t load config for ‘./bert-base-uncased‘. If you‘re trying
如何下载和在本地使用Bert预训练模型
以bert-base-uncased为例:
在github下载:
在huggingface(https://huggingface.co/bert-base-uncased/tree/main)下载config.json和pytorch_model.bin
将github下载的解压,并将huggingface下载的config.json和pytorch_model.bin放到解压后的文件夹:
测试:
from transformers import BertModel,BertTokenizer
BERT_PATH = '上面解压好的文件夹的路径'
tokenizer = BertTokenizer.from_pretrained(BERT_PATH)
print(tokenizer.tokenize('I have a good time, thank you.'))
bert = BertModel.from_pretrained(BERT_PATH)
print('load bert model over')
输出:
['i', 'have', 'a', 'good', 'time', ',', 'thank', 'you', '.']
load bert model over
文章评论