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

相关推荐
小刘私坊5 分钟前
脑科学与人工智能的交叉:未来智能科技的前沿与机遇
人工智能·科技
怎么全是重名6 分钟前
VPN(2020)Cross-view Semantic Segmentation for Sensing Surroundings
人工智能·计算机视觉·目标跟踪
檀越剑指大厂26 分钟前
【零基础玩转多模态AI:Gemma3 27B开源视觉模型本地部署与远程访问】
人工智能·开源
tilblackout31 分钟前
机器学习详解(19):长短期记忆网络LSTM原理详解
人工智能·机器学习·lstm
人类群星闪耀时38 分钟前
从数据海洋中“淘金”——数据挖掘的魔法与实践
人工智能·数据挖掘
易安说AI43 分钟前
我用AI+高德MCP 10分钟搞定苏州三日游
人工智能
Lx35244 分钟前
📌《从Prompt工程到AI思维:开发者新技能树全解析》
人工智能
@MrLiu44 分钟前
# 深度学习中的优化算法详解
人工智能·深度学习·算法·优化器
契合qht53_shine1 小时前
机器学习 从入门到精通 day_03
人工智能·机器学习
IT古董1 小时前
【漫话机器学习系列】199.过拟合 vs 欠拟合(Overfit vs Underfit)
人工智能