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

相关推荐
ZX0X学习中4 分钟前
一句话让 AI 生成 Excel 多文件合并工具:码道 CLI 实战
人工智能·excel·ai编程·华为云码道
AI小码7 分钟前
WAIC 2026前瞻:AI产业进入拼落地的下半场
人工智能·算法·ai·程序员·大模型·编程·智能体
小企鹅么么11 分钟前
【AI应用开发工程师】第六章:Context Engineering
人工智能·ai
code 小楊13 分钟前
LLM Wiki 深度解析:颠覆传统RAG,开启大模型知识管理新纪元
人工智能·科技
前端H21 分钟前
生成式 UI 实战:AI 如何重塑前端界面
前端·人工智能·ui
nanawinona22 分钟前
2026年AI量化学习,交易认知和技术实现要一起走
人工智能·python
影山飞雄23 分钟前
Using-Superpowers skill 逐行深度解析
人工智能
2601_9564141425 分钟前
AI3D模型生成工具怎么比较?2026主流平台对比与实测维度解析
人工智能·3d
一键生成网站30 分钟前
政务国企数据可视化大屏AI工具对比与信创安全选型指南
人工智能·信息可视化·政务·
故乡de云1 小时前
gemini-3-pro-preview 调用 generateContent 完整配置与排错:REST / Python SDK / Code0 兼容接入
人工智能·大模型·api·claude