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

相关推荐
向上的车轮4 分钟前
AI Infra 是什么?AI Infra的发展趋势是怎样的?
人工智能
liangshanbo12157 分钟前
Express SSE 流式输出实战:从入门 Demo 到 AI 生产级架构
人工智能·架构·express
安全指北针11 分钟前
AI Agent自主入侵真实系统:OpenAI和Anthropic两大模型接连“失控“,给安全行业敲响了什么警钟?
人工智能·安全
2601_9657996814 分钟前
2026 在线笔试平台深度测评与选型指南:从功能、稳定性、AI能力、防作弊全面分析
人工智能·笔记·功能测试
2601_9494999420 分钟前
芯瑞科技 DT-1414 光模块工程实测:完美兼容博通(安华高) HFBR-1414PTZ,VCSEL 替代方案
大数据·网络·人工智能·科技·光模块
城事漫游Molly21 分钟前
研究论证的四要素:主张、理由、证据、保证——用AI逐一检验
人工智能·ai for science·论文发表·博士生必读·论证argument·科研论文投稿
字节跳动视频云技术团队29 分钟前
AI 视频降本的三种做法,只有一种不牺牲画质
人工智能·aigc
自动化测试行业观察40 分钟前
从“自动化”到“智能化”:TestMan AI测试平台引领软件测试范式转移
运维·自动化测试·人工智能·测试工具·自动化·app测试·移动应用测试
HyperAI超神经1 小时前
在线教程|ProteinGym 第一名!VenusREM 用「检索增强」预测蛋白突变影响,加速蛋白质设计
人工智能·深度学习·生物信息学·大模型推理·生物医学
合调于形1 小时前
Bianfchheng (Baf) 《边城(八)》全文汉语拼音字母标调实测案例
人工智能·自然语言处理·人机交互·语音识别·学习方法