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

相关推荐
AAA小肥杨5 分钟前
2025人工智能AI新突破:PINN内嵌物理神经网络火了
人工智能·深度学习·神经网络·ai·大模型部署
王国强200926 分钟前
现代循环神经网络4-双向循环神经网络
深度学习
梓羽玩Python41 分钟前
太牛了!OWL:Manus 最强开源复现,开源框架GAIA基准测试中排第一!
人工智能·python
闲人编程1 小时前
经典网络复现与迁移学习
pytorch·深度学习·神经网络
詹天佐1 小时前
ICCE 数字车钥匙介绍
人工智能·算法
坚果的博客1 小时前
uniapp版本加密货币行情应用
人工智能·华为·uni-app·harmonyos
goomind1 小时前
深度学习实战车辆目标跟踪与计数
人工智能·深度学习·目标跟踪·pyqt5·bytetrack·deepsort·撞线计数
金智维科技1 小时前
什么是AI Agent的自学习能力?
人工智能