本地加载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)
相关推荐
H03111698510 分钟前
择校参考:枫叶教育 vs 大连美国国际学校,外籍子女学校怎么选
人工智能
刘海东刘海东33 分钟前
一条新的人工智能道路(刘海东)一、二、三章
人工智能
xyz_CDragon41 分钟前
从 RTL 到 GDSII:人与 AI 协作,用开源 EDA 工具链完成 SHA-256 芯片的 SoC 集成与签核全流程(附完整流程+代码)
人工智能·开源·芯片设计·开源 eda·caravel
咕咕AI学堂1 小时前
检索引擎深度对比:Elasticsearch vs Milvus vs Redis 在 RAG 中的定位
人工智能
Java牛马1 小时前
AI Agent 技术栈梳理(Skill / 蒸馏 / MCP / Harness)
人工智能·ai agent·蒸馏·skill·mcp·harness
IT_陈寒1 小时前
Vue的computed属性把我坑惨了,原来我一直用错姿势
前端·人工智能·后端
千维百策6661 小时前
降低 AI 辅助开发摩擦的五种模式
人工智能
有脚就行1 小时前
第38篇-LLM-API网关进阶-流式代理与内容安全
人工智能
AI英德西牛仔1 小时前
从Excel乱象到批量交付:秘塔Excel与“AI导出鸭”PC版的底层重构逻辑
人工智能·重构·excel·deepseek·ai导出鸭
w57w0002 小时前
AI可见度监测方案选型:电商、媒体公关、全球市场等场景的差异化需求与避坑指南
人工智能