[问题解决]加载huggingface模型出现“Connection error, and we cannot find the requested files in the cached path”

在尝试使用HuggingFace加载Bio_ClinicalBERT模型时遇到连接错误,尽管模型已在本地缓存。尝试设置local_only和force_download参数无效。问题在于加载模型和词表时路径处理不同,正确方式是不加./加载模型,加载词表时需要。此解决方案解决了加载问题,使编码可以继续进行。

最近训练多模态模型时需要用到BERT作为文本端的Encoder,按照huggingface官网说明,之前代码如下:

BERT_TYPE = 'emilyalsentzer/Bio_ClinicalBERT'
model = AutoModel.from_pretrained(BERT_TYPE, output_hidden_states=True)
tokenizer = AutoTokenizer.from_pretrained(BERT_TYPE,return_tensors="pt")

然后会自动联网下载需要的文件,昨天再用确报错:

ValueError: Connection error, and we cannot find the requested files in the cached path. Please try again or make sure your Internet connection is on.

确认了不是网络的问题,之前用过该模型,本地缓存应该有模型和配置文件,在~/.cache/huggingface/transformers下。但就是不行。参考了stackoverflow和github上的解决方法:

1.增加local_only参数(没用)

BERT_TYPE = 'emilyalsentzer/Bio_ClinicalBERT'
tokenizer = AutoTokenizer.from_pretrained(BERT_TYPE,return_tensors="pt",local_only=True))

2.强制下载,增加force_download=True(没用)

BERT_TYPE = 'emilyalsentzer/Bio_ClinicalBERT'
tokenizer = AutoTokenizer.from_pretrained(BERT_
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值