本地加载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)
相关推荐
冬奇Lab2 分钟前
Skill 系列(03):Skill 设计范式——5 个模式让输出从混沌到可预测
人工智能·开源·agent
IT_陈寒2 小时前
Python搞不定字符串编码?这破玩意坑我两小时!
前端·人工智能·后端
大模型真好玩4 小时前
什么是Loop Engineering?最通俗易懂的Loop Engineering核心概念
人工智能·agent·deepseek
叁两4 小时前
前端转型AI Agent该如何学习?(前置篇)
前端·人工智能·node.js
LaiYoung_4 小时前
🎁 送你一套超好用超实用的 FE AI-Coding Skills
前端·人工智能·开源
ZzT7 小时前
怎么做才不会被 AI 替代?
人工智能·程序员
道友可好7 小时前
从今天开始:你的第一个 Harness Engineering 实践
前端·人工智能·后端
小姜前线技术8 小时前
AI回答代码块高亮加一键复制
人工智能
洛阳泰山8 小时前
从 0 到 1.6K Star:一个 Java 开源项目的增长复盘
人工智能·后端·开源
米小虾9 小时前
Agent Skill 设计模式完全指南
人工智能·agent