【问题标题】:How to specify a proxy in transformers pipeline如何在变压器管道中指​​定代理
【发布时间】:2022-04-25 15:47:49
【问题描述】:

我正在使用here 所述的情绪分析管道。

from transformers import pipeline
classifier = pipeline('sentiment-analysis')

连接失败并显示连接错误消息

ValueError:连接错误,我们在缓存路径中找不到请求的文件。请重试或确保您的 Internet 连接已打开。

有没有办法在管道方法中指定一个代理,以便它能够连接到互联网并下载所需的文件?

【问题讨论】:

  • 你能用proxies={'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}试试吗?如果这不起作用,您需要使用此参数自己初始化标记器和模型(我可以告诉您如何做,以防其他选项不起作用)。
  • 尝试了代理选项。至少它没有抛出任何语法错误,但在运行模型时我仍然不断收到连接错误。可能是一些我无法计算的网络限制。我最终在名为“cached_model”的本地文件夹中手动下载了 config.json、pytorch_model.bin、vocab.txt,并将其作为 model = './cached_model' 传递到管道函数中。
  • 也许他们没有正确转发代理设置。可以试试m = DistilBertModel.from_retrained('distilbert-base-uncased', proxies={'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'})吗?

标签: python bert-language-model huggingface-transformers


【解决方案1】:

应该是代理问题。您可以尝试添加此代码 sn-p 以通过代理。

import os
os.environ['HTTP_PROXY'] = 'http://xxx:xxx@xxx:xxx'
os.environ['HTTPS_PROXY'] = 'http://xxx:xxx@xxx:xxx'

from transformers import pipeline
classifier = pipeline('sentiment-analysis')

注意:请记住使用 http 而不是 https 作为代理值。

【讨论】:

    猜你喜欢
    • 2019-12-17
    • 2018-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-06
    • 2020-01-13
    • 2021-02-18
    • 2020-07-05
    相关资源
    最近更新 更多