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 分钟前
书单号视频搬运软件推荐8款(2026实测版)
人工智能·音视频
zhangshuang-peta8 分钟前
保障人工智能集成安全:解决生产环境中的MCP安全漏洞
人工智能·ai agent·mcp·peta
FreeBuf_9 分钟前
AI安全护栏对防御者的束缚远超攻击者,加剧攻防失衡
人工智能·安全
昨夜见军贴061611 分钟前
IACheck结合AI报告审核:列车制动系统气密性检测报告细节全面把控
人工智能
xixixi7777719 分钟前
2026网络安全新战场:AI对抗、勒索软件升级与防御实战
人工智能·安全·机器学习·信息安全·大模型
达宽科技22 分钟前
教程 机器人线束通电检测怎么做?(一)
人工智能
广州赛远22 分钟前
SRA166防静电防护服安装保养指南:避免机器人静电损伤的实操详解
人工智能·机器人
国产化创客22 分钟前
OpenClaw在树莓派全流程安装部署
linux·人工智能·github·agi
视***间26 分钟前
视程空间全系列产品解析:以边缘算力为核,铸就全场景智能硬件标杆
人工智能·机器人·边缘计算·智能硬件·视程空间
微学AI30 分钟前
内网穿透的应用-随时随地用 OpenClaw!cpolar 内网穿透,打造你的专属随身 AI
人工智能