Bert下载和使用(以bert-base-uncased为例)
Bert官方github地址:https://github.com/google-research/bert?tab=readme-ov-file
在github下载:
在huggingface(地址)下载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
来源:https://blog.csdn.net/GCTTTTTT/article/details/136055023
(为防止来源出现意外消失故在此转载作为笔记)