本地加载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)
相关推荐
火山引擎开发者社区3 小时前
漫话火山 Milvus|为 Agent、RAG 、语义搜索而生,AI 时代的极致性价比之选
人工智能
jikemaoshiyanshi9 小时前
AWS 中国峰会 2026 有哪些 AI Agent 相关演讲可以看?按业务、研发与生产阶段选看
大数据·人工智能
网易易盾9 小时前
AI互动产品安全合规体系架构:制度/技术/运营/证据四层落地
人工智能·安全·aigc·内容安全
新知图书9 小时前
4.3 链接速读
人工智能·语音识别·ai助手·千问
江苏久众新视10 小时前
SOP-AI实战:基于AI视觉与视频检测,精准管控空调管件装配防漏防错
人工智能
u01030552711 小时前
Java AWT鼠标事件全解析
人工智能·1024程序员节
tuanxiang11 小时前
中英文AI检测的跨语系误判问题排查与修复
人工智能
冬奇Lab11 小时前
开源项目第178期:OptMem — 426 个 token 的提示词,给 AI Agent 跨会话的持久记忆
人工智能·开源·资讯
冬奇Lab11 小时前
代码库知识库系列(09):用 codebase-memory-mcp 实战——在 LightRAG 上跑三路召回
人工智能