本地加载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)
相关推荐
学历真的很重要21 分钟前
VsCode+Roo Code+Gemini 2.5 Pro+Gemini Balance AI辅助编程环境搭建(理论上通过多个Api Key负载均衡达到无限免费Gemini 2.5 Pro)
前端·人工智能·vscode·后端·语言模型·负载均衡·ai编程
普通网友22 分钟前
微服务注册中心与负载均衡实战精要,微软 2025 年 8 月更新:对固态硬盘与电脑功能有哪些潜在的影响。
人工智能·ai智能体·技术问答
苍何25 分钟前
一人手搓!AI 漫剧从0到1详细教程
人工智能
苍何34 分钟前
Gemini 3 刚刷屏,蚂蚁灵光又整活:一句话生成「闪游戏」
人工智能
苍何1 小时前
越来越对 AI 做的 PPT 敬佩了!(附7大用法)
人工智能
苍何1 小时前
超全Nano Banana Pro 提示词案例库来啦,小白也能轻松上手
人工智能
阿杰学AI2 小时前
AI核心知识39——大语言模型之World Model(简洁且通俗易懂版)
人工智能·ai·语言模型·aigc·世界模型·world model·sara
智慧地球(AI·Earth)2 小时前
Vibe Coding:你被取代了吗?
人工智能
大、男人2 小时前
DeepAgent学习
人工智能·学习
测试人社区—66793 小时前
提升测试覆盖率的有效手段剖析
人工智能·学习·flutter·ui·自动化·测试覆盖率