本地加载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)
相关推荐
aifannihao7 分钟前
AI 学习第 14 课:CNN 训 6 轮卡在 0.5352,数据没打乱
pytorch·python·深度学习·cnn·学习路线
AI_Gump10 分钟前
Harness篇|DeepSeek Harness 上手机:五条安卓移植路线与 App 内 Linux 拆解
android·linux·人工智能·智能手机·deepseek
萝卜小白1 小时前
深度学习基础面经
人工智能·深度学习
如夏倾城1 小时前
百度文心(容易被忽略的好用AI)使用方式
人工智能·python·百度·语言模型·dubbo
泯泷1 小时前
为什么 RL 比 SFT 更会"举一反三"?
人工智能·llm·agent
上海潭龙东海科技有限公司2 小时前
客运站管控之动态孪生技术方案(新增一屏管控模块
数据仓库·人工智能·算法·重构·动态规划
民乐团扒谱机2 小时前
Agent-Skills 新手入门与实战部署指南
人工智能·ai·agent·skill
打工仔折腾 AI3 小时前
Changedetection.io 网页变动监控:Docker 部署、通知配置与公网暴露实践
运维·人工智能·后端·python·docker·容器·性能优化
深圳雨林凯AI3 小时前
商品详情长图的自动生成:版块模板、要素抽取与版式约束的实现思路
人工智能·ai
lisw053 小时前
迁移学习(Transfer Learning):概念、历史、内容、挑战与展望
人工智能·机器学习·迁移学习