本地加载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)
相关推荐
Raink老师5 分钟前
【AI面试临阵磨枪-76】社交 AI:内容生成、审核、智能回复、多模态理解、安全治理
人工智能·安全·面试
装不满的克莱因瓶20 分钟前
SpringAI Alibaba Tool工具调用机制实战-注解注册与函数调用全流程
人工智能·ai·tools·智能体·springai·tool
ZhengEnCi23 分钟前
09ab-无偏置线性层是什么?
人工智能
Lkstar26 分钟前
Transformer 核心机制拆解:自注意力、多头注意力、位置编码,一篇讲透
人工智能
云烟成雨TD38 分钟前
Spring AI Alibaba 1.x 系列【60】检查点机制原理与全流程剖析
java·人工智能·spring
极光代码工作室39 分钟前
基于机器学习的二手商品价格预测系统
人工智能·python·深度学习·机器学习
YueJoy.AI42 分钟前
AI应用的隐私保护:从设计开始的隐私
人工智能·ai·语言模型
小当家.10543 分钟前
PostgreSQL 做向量数据库:pgvector 在 RAG 中的实战与多场景适配
数据库·人工智能·postgresql·rag
ForgeAI码匠1 小时前
Maven 多模块项目如何避免越写越乱?Forge Admin 的模块边界实践
java·人工智能·开源·maven
Dola_Zou1 小时前
工业软件防破解避坑指南:CodeMeter 全流程入门与选型(上)
人工智能·自动化·视觉检测·软件工程·软件加密