本地加载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)
相关推荐
CodePlayer竟然被占用了44 分钟前
Codex 用电脑的三种姿势:选错模式,你就白烧 Token
人工智能
袋鼠云数栈UED团队1 小时前
一套 Spec-First 的 AI 编程工作流
前端·人工智能
Awu12271 小时前
⚡从零开发 Agent CLI(二):CLI 框架搭建与子命令路由
人工智能·aigc
码上天下1 小时前
React Query 缓存 AI 对话历史的几个权衡
人工智能
米小虾2 小时前
2026半年盘点:AI界发生的6件大事,正在彻底改变产业格局
人工智能
道友可好4 小时前
让 AI 自己验收,等于让学生自己批卷
前端·人工智能·后端
美团技术团队4 小时前
美团海报生成 AIGC 技术创新与实践
人工智能
冬哥聊AI4 小时前
放弃 Spring AI?这 3 个开源框架,才是让 SpringBoot 玩转 AI Agent 的正解
人工智能
小爷毛毛_卓寿杰4 小时前
当 max_tokens=1 遇上 reasoning 模型:从 Xagent 一次“测试连接“按钮的失败说起
人工智能