本地加载hugging face模型:Bert

找了个hf的镜像站,把config.json和pytorch_model.bin两个文件进行下载下来,模型文件uncased_L-12_H-768_A-12.zip下载下来先。

解压模型文件压缩包,把前面下载的两个文件也放进去,总共6个文件。这个文件夹就是代码

tokenizer = BertTokenizer.from_pretrained(BERT_PATH)

BERT_PATH这里对应的文件路径。

Some weights of BertForSequenceClassification were not initialized from the model checkpoint at bert-base-uncased and are newly initialized: ['classifier.bias', 'classifier.weight']

pip install tensorflow

复制代码
from transformers import BertModel, BertTokenizer

model_name = 'bert-base-uncased'
tokenizer = BertTokenizer.from_pretrained(model_name)
model = BertModel.from_pretrained(model_name, from_tf=True)
相关推荐
听风吹等浪起6 分钟前
NLP实战(4):使用PyTorch构建LSTM模型预测糖尿病
人工智能·pytorch·自然语言处理·lstm
敖云岚21 分钟前
【AI】SpringAI 第五弹:接入千帆大模型
java·大数据·人工智能·spring boot·后端
三道杠卷胡30 分钟前
【AI News | 20250424】每日AI进展
人工智能·pytorch·python·语言模型·github
追逐☞31 分钟前
机器学习(9)——随机森林
人工智能·随机森林·机器学习
pljnb36 分钟前
长短期记忆网络(LSTM)
人工智能·rnn·lstm
何双新43 分钟前
第1讲:Transformers 的崛起:从RNN到Self-Attention
人工智能·rnn·深度学习
爱的叹息1 小时前
通过AI工具或模型创建PPT的不同方式详解,结合 Assistants API、DALL·E 3 等工具的功能对比及表格总结
人工智能·powerpoint
AIGC大时代1 小时前
高质量学术引言如何妙用ChatGPT?如何写提示词
人工智能·深度学习·chatgpt·学术写作·chatgpt-o3·deep reaserch
zenRRan2 小时前
综述 | GUI Agent:让AI学会「玩手机」的新革命
人工智能