本地加载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)
相关推荐
小兵张健6 小时前
35岁程序员的春天来了
人工智能
大怪v6 小时前
AI抢饭?前端佬:我要验牌!
前端·人工智能·程序员
冬奇Lab6 小时前
OpenClaw 深度解析(六):节点、Canvas 与子 Agent
人工智能·开源
刀法如飞7 小时前
AI提示词框架深度对比分析
人工智能·ai编程
IT_陈寒9 小时前
Python开发者必知的5大性能陷阱:90%的人都踩过的坑!
前端·人工智能·后端
1G10 小时前
openclaw控制浏览器/自动化的playwright MCP + Mcporter方案实现
人工智能
踩着两条虫10 小时前
VTJ.PRO 双向代码转换原理揭秘
前端·vue.js·人工智能
扉川川10 小时前
OpenClaw 架构解析:一个生产级 AI Agent 是如何设计的
前端·人工智能
星浩AI10 小时前
让模型自己写 Skills——从素材到自动生成工作流
人工智能·后端·agent
千寻girling14 小时前
Python 是用来做 AI 人工智能 的 , 不适合开发 Web 网站 | 《Web框架》
人工智能·后端·算法