本地加载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)
相关推荐
IT_陈寒26 分钟前
React的useState居然还有这种坑?我差点删库跑路
前端·人工智能·后端
用户413062258291 小时前
给AI回答加引用角标citation:RAG前端实现
人工智能
米小虾2 小时前
WAIC 2026 倒计时30天:300+ AI 产品全球首发,今年看点全解析
人工智能
码上天下2 小时前
多模态Agent上传图片:前端压缩格式与预览实战
人工智能
姗姗来迟了2 小时前
Vue3封装可复用AI对话组件:一次抽象复盘
人工智能
怕浪猫2 小时前
哪些软件对 Chrome DevTools Protocol 频繁使用
人工智能·架构·前端框架
leo在掘金4 小时前
从DeepSeek 510亿融资到GitHub 33K Star开源项目:这周的技术生态发生了什么?
人工智能
小姜前线技术5 小时前
AI流式渲染打字机效果抖动?节流方案踩坑实录
人工智能