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

相关推荐
eaglewgs5 分钟前
关于AI书写测试用例,谈一下我的思考
人工智能·测试开发·ai·测试用例·agent·测试经验·agent测试开发
熊野君7 分钟前
第 4 章 技术产品经理核心能力模型
大数据·人工智能·产品经理
问天_观心9 分钟前
大模型微调学习(一)
开发语言·人工智能·学习·语言模型·github
百胜软件@百胜软件12 分钟前
AI赋能零售,迈向智能零售时代丨黄飞获邀担任2026年度上海市专业技术人才知识更新工程急需紧缺人才培养项目讲师
人工智能·百度·零售
财复视界13 分钟前
光智科技从“光学元件”到“稀散金属材料平台”的进化逻辑
大数据·人工智能·科技
大模型丫丫36 分钟前
RAG 检索增强生成:原理、架构与实战指南
人工智能
sel_936 分钟前
深度学习损失函数详解:从 MSE、Cross Entropy 到 Dice、Focal、IoU、Contrastive Loss,一文掌握所有常见 Loss
人工智能·深度学习
绘梨衣54741 分钟前
AI技术栈全景指南_Prompt_RAG_爬虫_MCP
人工智能·爬虫·prompt
zed_231 小时前
RAG 全链路串起来:一个能答专业问题的问答接口
人工智能
2601_962304911 小时前
把出片接进自动化流水线:2026 年批量 AI 视频生成工具的脚本契约与同类项目对照
运维·人工智能·自动化