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

相关推荐
雪隐1 天前
个人电脑玩AI-06让5060 Ti给你打工——Qwen3.6-35B-A3B + LM Studio + openWebUI
人工智能·后端
得物技术1 天前
从表单到 Agent:得物社区活动搭建的 AI 实践之路
人工智能·架构·agent
Weigang1 天前
给 Agent 接入 Qdrant 前,先写清楚检索合同
人工智能
字节跳动数据库1 天前
文章分享——庖丁解牛-图解查询分析和调优利器Optimizer Trace
人工智能·程序员
以和为贵1 天前
前端手写 RAG 踩坑实录:四个让检索"翻车"的坑
前端·人工智能·面试
何时梦醒1 天前
深入理解 LLM Tokenization:从文本分词到语义向量化的完整旅程
人工智能
冬哥聊AI1 天前
阿里二面:8K Token 撑住 100 轮对话,你的分层记忆架构怎么设计?
人工智能
拾年2751 天前
我用 30 行代码,搞懂了大模型是怎么"读"中文的
javascript·人工智能·llm
Tigger1 天前
受不了 ¥98/年的订阅,我用 Vibe Coding 自己写了个剪贴板工具
人工智能·开源·mac
ZJPRENO1 天前
创作者狂喜!Seedance 2.5 支持 50 份素材同时导入,做短剧广告爽翻
人工智能·ai编程·图像识别