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

相关推荐
怪奇云呼军1 分钟前
知识库也会注入指令?闪电智能VoiceAgent 如何防住 Prompt Injection
人工智能·python·算法·云计算·音视频
xushichang123_3 分钟前
企业降本刚需下,云上模型蒸馏与轻量化部署怎么选?AWS“大模型教研+小模型推理” 路径
大数据·人工智能
EasyDSS23 分钟前
开会不用装App:私有化音视频系统EasyDSS即时视频会议,浏览器点开就能聊,AI帮你写纪要
人工智能·音视频
阿里云大数据AI技术34 分钟前
基于 EMR Serverless Ray 实现 Qwen 模型批量推理实践
人工智能·算法·agent
ZJU_统一阿萨姆37 分钟前
【算子开发】环境搭建与第一个CUDA程序
开发语言·人工智能·系统架构
老登为啥喜欢吹AI41 分钟前
继DSH之后!Codex Harness 也开源了!Rust 核心、三层架构、人机协作
人工智能
国商联1 小时前
科技引领健康,服务温暖人心——国商联在行动
人工智能·科技·百度·生活
高工智能汽车1 小时前
东土科技李平:神经系统是机器人灵魂的载体
人工智能
天远Date Lab1 小时前
零信任架构实战:基于天远行驶证核查构建自动化车队准入网关
运维·人工智能·架构·自动化