Fork me on GitHub

Bert下载和使用(以bert-base-uncased为例)

Bert官方github地址:https://github.com/google-research/bert?tab=readme-ov-file
在github下载:
image
在huggingface(地址)下载config.json和pytorch_model.bin
image
将github下载的解压,并将huggingface下载的config.json和pytorch_model.bin放到解压后的文件夹:
image
测试:

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
(为防止来源出现意外消失故在此转载作为笔记)

posted @ 2024-09-16 10:42  会自愈的哈士奇  阅读(112)  评论(0编辑  收藏  举报