本地加载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)
相关推荐
MicrosoftReactor2 小时前
技术速递|使用 GitHub Security Lab Taskflow Agent 实现 AI 驱动的模糊测试
人工智能·ai·github·copilot·agent·模糊测试·ai-agent
promanz2 小时前
关于RAG文件格式转换
人工智能
桃西西呀2 小时前
Spring AI Alibaba 之五:我把五个子智能体拼成客服流水线,才看懂内置 flow 编排和 A2A 远程调用
人工智能
翻滚的芋头2 小时前
神经网络基础——前馈神经网络FNN
人工智能
IamZJT_2 小时前
Agent 系统工程 10|一次长任务失败,如何定位原因并验证修复?
人工智能
橘和柠2 小时前
模型量化完全指南:GGUF、GPTQ、AWQ 怎么选
人工智能
小白马突突突2 小时前
零信脱敏正式提出“不过度脱敏”产品原则
人工智能·文件脱敏·文档脱敏·零信脱敏·pdf脱敏工具
Code_Solitude2 小时前
高数第一章函数笔记(原稿手写+AI识别优化)
人工智能·笔记
龙亘川2 小时前
面向绿色低碳城市:一网统管打通交通与能源治理的关键路径
大数据·人工智能·智慧城市·能源·开源软件
蓝悦无人机2 小时前
无人机系列之飞控算法:从PID到AI,飞行控制的核心进化
人工智能·算法·无人机·飞控系统