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
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐