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 @   会自愈的哈士奇  阅读(547)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示