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

相关推荐
大猪宝宝学AI13 小时前
【AI Infra】BF-PP:广度优先流水线并行
人工智能·性能优化·大模型·模型训练
Jerryhut13 小时前
Opencv总结7——全景图像拼接
人工智能·opencv·计算机视觉
Captaincc14 小时前
AI 原生下的新的社区形态会是什么
人工智能
简简单单OnlineZuozuo15 小时前
提示架构:设计可靠、确定性的AI系统
人工智能·unity·架构·游戏引擎·基准测试·the stanford ai·儿童
liu****15 小时前
机器学习-线性回归
人工智能·python·算法·机器学习·回归·线性回归
龙腾AI白云15 小时前
深度学习—卷积神经网络(2)
人工智能·神经网络
阿里云大数据AI技术15 小时前
一站式构建 AI 数据处理 Pipeline:DataWorks Notebook + MaxCompute MaxFrame 快速入门指南
大数据·人工智能
阿里云大数据AI技术16 小时前
StarRocks + Paimon: 构建 Lakehouse Native 数据引擎
大数据·人工智能
简简单单OnlineZuozuo16 小时前
对话式AI的安全和治理模式
人工智能·深度学习·安全·图像识别·banana
间彧16 小时前
智能体工作流:从架构设计到行业落地
人工智能