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')

相关推荐
MARS_AI_27 分钟前
智能呼叫中心系统:重构客户服务的核心引擎
人工智能·自然语言处理·重构·交互·信息与通信
巴伦是只猫30 分钟前
【深度学习笔记】3 step by step (jupyter)
笔记·深度学习·jupyter
AI街潜水的八角2 小时前
图像修复:深度学习实现老照片划痕修复+老照片上色
人工智能·深度学习
HuggingFace4 小时前
Hugging Face 开源 HopeJR 机器臂!今天晚上直播带你深入技术核心
人工智能
SUPER52664 小时前
AI应用服务
人工智能
义薄云天us5 小时前
028_分布式部署架构
人工智能·分布式·架构·claude code
HuggingFace5 小时前
HF Papers 直播| AI for Science 专场
人工智能
机器视觉与AI5 小时前
半导体制造流程深度解析:外观缺陷检测的AI化路径与实践
人工智能·视觉检测·制造
批量小王子8 小时前
2025-07-15通过边缘线检测图像里的主体有没有出血
人工智能·opencv·计算机视觉
机器学习之心8 小时前
三种深度学习模型(LSTM、CNN-LSTM、贝叶斯优化的CNN-LSTM/BO-CNN-LSTM)对北半球光伏数据进行时间序列预测
深度学习·cnn·lstm·cnn-lstm·贝叶斯优化的cnn-lstm