本地加载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)
相关推荐
甲维斯32 分钟前
用AI还原《坦克大战》并3D化升级!
前端·人工智能·游戏开发
IT_陈寒1 小时前
SpringBoot自动配置坑了我一晚上,原来问题出在这
前端·人工智能·后端
吴佳浩2 小时前
Hermes Agent 连环 400 真凶找到了:一个 call_id 让人炸毛
人工智能·llm·agent
程序员cxuan3 小时前
幽默,一个 Github 名字叫“马尾辫”,但是他给你省了 80% 的 token
人工智能·后端·程序员
宋哥转AI3 小时前
Agent记忆模块系列:03存储与检索链路实测验证
人工智能·agent
老金带你玩AI3 小时前
老金开源GoalPro,别让AI把目标越写越烂
人工智能
Bigfish_coding4 小时前
前端转agent-【python】-08 用 LangGraph 把 Agent 做成状态机:像写 Vue 3 状态管理一样编排 AI 流程
人工智能
刺猬的温驯4 小时前
语音克隆模型的难点之一:音素对齐及交叉注意力早期失效问题 (兼论旋转位置编码)——F5-TTS、SupertonicTTS、VoxFlash-TTS 对比
人工智能·语音合成·tts
道友可好5 小时前
AI 是最好的混乱放大器:代码熵管理实战
前端·人工智能·后端