文章目录
- [OSError: Can't load tokenizer for 'bert-base-chinese'](#OSError: Can't load tokenizer for 'bert-base-chinese')
OSError: Can't load tokenizer for 'bert-base-chinese'
1.问题描述
使用from_pretrained()
函数从预训练的权重中加载模型时报错:
OSError: Can't load tokenizer for 'bert-base-chinese'. 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-chinese' is the correct path to a directory containing allrelevant files for a BertTokenizer tokenizer.

原因:主机或服务器 不能访问https://huggingface.co/页面,因此不能下载相应的权重。
2.解决办法
将权重文件下载到本地或服务器,使用本地权重文件实现加载,而不是在线下载。
- 进入官网,Models页面,下载对应的Bert模型的权重。


- 将下载的权重文件,放到某个文件夹下(加载路径的位置)

- 修改权重文件的加载路径,也就是
from_pretrained()
函数里面的权重文件路径。注意:必须是绝对路径!

成功解决!!!
😃😃😃