【问题解决】| 对于代码访问transformers库报错,无法正常下载模型及其参数的问题

对于访问Transformer库的问题

  • 考虑用科学上网,直接进行下载
  • 把模型提前下好后放到本地

但是如果能用第一种方式会好很多,但是实际中可能会遇到如下问题

报这个错,原因是未开启科学上网

OSError: We couldn't connect to 'https://huggingface.co' to load this file, couldn't find it in the cached files and it looks like distilbert-base-uncased-finetuned-sst-2-english is not the path to a directory containing a file named config.json.

科学上网打开了,有可能又会报这个错

requests.exceptions.ProxyError: (MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url

降级两个包即可(注意降级包的时候,报错很多黄色的WARNIG:Retrying的时候,记得把科学上网关掉再降级)

第一个包 requests降级到2.27.1,第二个包 urllib3 降到1.25.11

pip install requests==2.27.1
pip install urllib3==1.25.11

可以看到如下图,可以正常下载了

在这里插入图片描述

现在一个问题,模型下到了哪里?

模型默认会下载到 home/用户名/.cache/huggingface里面,不需要的话可以把他手动删除,Windows的话是C盘的.cache里面

如果想自定义下载路径,该怎么做?

可以在后面加一个cache_dir=

如下

from transformers import AutoTokenizer, AutoModel
tokenizer = AutoTokenizer.from_pretrained("bert-base-chinese", cache_dir="new_directory/")
model = AutoModel.from_pretrained("bert-base-chinese", cache_dir="new_directory/")
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值