本地加载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)
相关推荐
love530love3 小时前
【ComfyUI】解决 ModuleNotFoundError: No module named ‘inference_core_nodes‘ 问题
人工智能·windows·python·comfyui·inference-core
大模型任我行3 小时前
华为:构建特征级LLM编码评测基准
人工智能·语言模型·自然语言处理·论文笔记
Jason_Honey23 小时前
【平安Agent算法岗面试-二面】
人工智能·算法·面试
Godspeed Zhao3 小时前
现代智能汽车中的无线技术106——ETC(0)
网络·人工智能·汽车
恋猫de小郭3 小时前
AGENTS.md 真的对 AI Coding 有用吗?或许在此之前你没用对?
前端·人工智能·ai编程
久邦科技4 小时前
OpenCode 完整入门(安装 + 配置 + 使用 + 模板)
人工智能
zhangshuang-peta4 小时前
模型上下文协议(MCP):演进历程、功能特性与Peta的崛起
人工智能·ai agent·mcp·peta
heimeiyingwang4 小时前
企业供应链 AI 优化:需求预测与智能调度
大数据·数据库·人工智能·机器学习
bst@微胖子5 小时前
PyTorch深度学习框架之基础实战二
人工智能·深度学习