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

相关推荐
suke4 分钟前
RAG 已死,Agent 永生:理解 AI 检索的范式革命
人工智能·程序员·aigc
cooldream20095 分钟前
大模型分类与应用全景解析:从文本到多模态的智能演进
人工智能·ai·大模型基础
ECT-OS-JiuHuaShan9 分钟前
哥德尔不完备定理中的完备是什么?是还原论证的具足幻想。不还原就是完备,哥德尔搞不完定理
人工智能·数学建模·学习方法·几何学·量子计算·拓扑学·空间计算
i.ajls13 分钟前
强化学习入门-3(AC)
人工智能·深度学习·机器学习·actor-critic
Blossom.11817 分钟前
把AI“浓缩”到1KB:超紧凑型决策树在MCU上的极限优化实战
人工智能·python·单片机·深度学习·决策树·机器学习·数据挖掘
CoovallyAIHub25 分钟前
AI基础设施新玩家:Tinker如何重新定义LLM微调工作流?
深度学习·算法·计算机视觉
努力努力再nuli27 分钟前
学习华为昇腾AI教材图像处理原理与应用部分Day1
图像处理·人工智能·学习
学术小白人27 分钟前
【IEEE出版 | 早鸟优惠本周截止】人工智能驱动图像处理与计算机视觉技术国际学术研讨会 (AIPCVT 2025)
图像处理·人工智能·计算机视觉
新知图书29 分钟前
A2A架构详解
人工智能·架构·ai agent·智能体·大模型应用
飞哥数智坊40 分钟前
不再记得代码细节?别慌,你正在经历 AI 时代的编程能力重塑
人工智能·ai编程