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

相关推荐
IT·陈寒11 分钟前
Vue组件props传对象给我整不会了
人工智能·大模型·api·创业·变现·简历优化
2601_9657422216 分钟前
全媒体运营与短视频代运营,两者有什么区别?
大数据·数据结构·人工智能·算法·ai·媒体
Joker-Zohar18 分钟前
GPT-Image-2.5 双版本上线:8 组压力测试的提示词拆解,中文渲染零乱码
人工智能·gpt
白帽黑客-晨哥19 分钟前
Copilot 能换成本地吗?本地化 AI 编程助手可行性全解析
人工智能·copilot
阿里云大数据AI技术20 分钟前
Agentic Search + Memory:OpenClaw 从搜索工具到企业认知引擎
人工智能
IT_陈寒26 分钟前
Redis误用keys命令把生产环境搞崩了,血的教训
前端·人工智能·后端
m0_6145235527 分钟前
差异很大的两段视频怎么自然衔接:切点、AI转场与失败回退
人工智能·音视频
Sheakan37 分钟前
从神经元到深度网络:神经网络为什么能起作用
人工智能
Tangyuewei39 分钟前
给老 Spring 项目装个 AI Agent
java·人工智能·spring
工业HMI实战笔记1 小时前
玩具制造HMI:注塑成型的快速换模与质量监控界面
人工智能·学习·交互·制造