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

相关推荐
红衣小蛇妖10 分钟前
神经网络-Day46
人工智能·深度学习·神经网络
带电的小王35 分钟前
【动手学深度学习】3.1. 线性回归
人工智能·深度学习·线性回归
谢尔登40 分钟前
结合 AI 生成 mermaid、plantuml 等图表
人工智能
VR最前沿1 小时前
【应用】Ghost Dance:利用惯性动捕构建虚拟舞伴
人工智能·科技
说私域1 小时前
内容力重塑品牌增长:开源AI大模型驱动下的智能名片与S2B2C商城赋能抖音生态种草范式
人工智能·小程序·开源·零售
l1t1 小时前
三种读写传统xls格式文件开源库libxls、xlslib、BasicExcel的比较
c++·人工智能·开源·mfc
AI浩2 小时前
【Block总结】EBlock,快速傅里叶变换(FFT)增强输入图像的幅度|即插即用|CVPR2025
人工智能·目标检测·计算机视觉
Vertira2 小时前
Pytorch安装后 如何快速查看经典的网络模型.py文件(例如Alexnet,VGG)(已解决)
人工智能·pytorch·python
Listennnn2 小时前
信号处理基础到进阶再到前沿
人工智能·深度学习·信号处理
奔跑吧邓邓子2 小时前
DeepSeek 赋能智能养老:情感陪伴机器人的温暖革新
人工智能·机器人·deepseek·智能养老·情感陪伴