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

相关推荐
智算菩萨4 小时前
实战:用 Python + 传统NLP 自动总结长文章
开发语言·人工智能·python
whitelbwwww5 小时前
Pytorch--张量表示实际数据
人工智能·pytorch·python
roman_日积跬步-终至千里5 小时前
【人工智能导论】05-学习-机器学习基础:从数据到智能决策
人工智能·学习·机器学习
nice_lcj5205 小时前
【AI进阶】拒绝“人工智障”:掌握提示词工程(Prompt Engineering)的6大核心技巧
人工智能·prompt
万俟淋曦5 小时前
【论文速递】2025年第40周(Sep-28-Oct-04)(Robotics/Embodied AI/LLM)
人工智能·深度学习·ai·机器人·大模型·论文·具身智能
jiayong235 小时前
Spring AI Alibaba 深度解析(一):框架概述与核心功能
java·人工智能·spring
亚马逊云开发者5 小时前
基于Amazon Q Developer实现IoT设备的Amazon Timestream性能与成本优化
人工智能
cyyt5 小时前
深度学习周报(12.15~12.21)
人工智能·深度学习·最优传输
Blossom.1185 小时前
大模型推理优化实战:连续批处理与PagedAttention性能提升300%
大数据·人工智能·python·神经网络·算法·机器学习·php
陈天伟教授5 小时前
人工智能训练师认证教程(1)数据标注-Labelimg的使用教程
人工智能·神经网络·机器学习