OSError: Can‘t load tokenizer for ‘bert-base-uncased‘.

一、具体报错:

报错如下:
OSError: Can't load tokenizer for 'bert-base-uncased'. If you were trying to load it from 'https://huggingface.co/models', make sure you don't have a local directory with the same name. Otherwise, make sure 'bert-base-uncased' is the correct path to a dir

二、报错原因:

模型调用bert时,由于huggingface有墙导致模型无法下载

三、 解决方法:

1、通过镜像站下载

直接命令行通过huggingface镜像运行脚本,从而下载对应bert模型权重
HF_ENDPOINT=https://hf-mirror.com python 模型脚本.py

与之相同,通过设置环境变量也可以,以linux为例
export HF_ENDPOINT=https://hf-mirror.com

2、直接下载权重

地址https://huggingface.co/google-bert/bert-base-uncased/tree/main
镜像地址https://hf-mirror.com/google-bert/bert-base-uncased/tree/main
下载内容

xml 复制代码
config.json
pytorch_model.bin
tokenizer.json
tokenizer_config.json
vocab.txt

将对应文件放入一个文件夹内,如bert-base-uncased;查看报错所在的文件具体位置,以及对应引用模型的位置


tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')

from_pretrained()中的内容换成模型所在文件夹的路径,建议填写绝对路径
tokenizer = BertTokenizer.from_pretrained('./bert-base-uncased')

相关推荐
nancy_princess3 小时前
clip实验
人工智能·深度学习
飞哥数智坊3 小时前
TRAE Friends@济南第4次活动:100+极客集结,2小时极限编程燃爆全场!
人工智能
AI自动化工坊4 小时前
ProofShot实战:给AI编码助手添加可视化验证,提升前端开发效率3倍
人工智能·ai·开源·github
飞哥数智坊4 小时前
一场直播涨粉 2 万的背后!OpenClaw + 飞书,正在重塑软件交付的方式
人工智能
飞哥数智坊4 小时前
养虾记第3期:安装、调教、落地,这场沙龙我们全聊了
人工智能
再不会python就不礼貌了4 小时前
从工具到个人助理——AI Agent的原理、演进与安全风险
人工智能·安全·ai·大模型·transformer·ai编程
AI医影跨模态组学4 小时前
Radiother Oncol 空军军医大学西京医院等团队:基于纵向CT的亚区域放射组学列线图预测食管鳞状细胞癌根治性放化疗后局部无复发生存期
人工智能·深度学习·医学影像·影像组学
A尘埃4 小时前
神经网络的激活函数+损失函数
人工智能·深度学习·神经网络·激活函数
没有不重的名么4 小时前
Pytorch深度学习快速入门教程
人工智能·pytorch·深度学习
有为少年5 小时前
告别“唯语料论”:用合成抽象数据为大模型开智
人工智能·深度学习·神经网络·算法·机器学习·大模型·预训练