You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用KeyBERT时出现ProxyError连接错误,寻求解决方法

解决KeyBERT连接HuggingFace模型时的ProxyError问题

这个错误是KeyBERT尝试从HuggingFace下载paraphrase-MiniLM-L6-v2模型时,代理连接失败导致的。以下是几个可行的解决办法:

1. 检查或修正代理配置

如果你的网络确实需要通过代理访问外部资源,确保代理设置正确:

  • 设置系统环境变量:
    Windows系统执行:
    set HTTP_PROXY=http://你的代理地址:端口
    set HTTPS_PROXY=http://你的代理地址:端口
    
    Linux/macOS系统执行:
    export HTTP_PROXY=http://你的代理地址:端口
    export HTTPS_PROXY=http://你的代理地址:端口
    
    若代理需要账号密码,格式为http://用户名:密码@你的代理地址:端口
  • 在代码中直接设置代理:
    在代码开头添加以下内容:
    import os
    os.environ['HTTP_PROXY'] = 'http://你的代理地址:端口'
    os.environ['HTTPS_PROXY'] = 'http://你的代理地址:端口'
    

2. 关闭不必要的代理

如果你的网络不需要代理,检查是否开启了系统代理、VPN或浏览器代理,关闭这些工具后重新运行代码。

3. 手动下载模型到本地加载

直接下载模型文件到本地,让KeyBERT加载本地模型,避免网络下载步骤:

  1. 下载paraphrase-MiniLM-L6-v2的所有模型文件,保存到本地目录(比如./local-models/paraphrase-MiniLM-L6-v2)
  2. 修改代码,加载本地模型:
    from sentence_transformers import SentenceTransformer
    from keybert import KeyBERT
    
    # 加载本地模型
    model = SentenceTransformer('./local-models/paraphrase-MiniLM-L6-v2')
    kw_model = KeyBERT(model=model)
    
    doc = """
             Supervised learning is the machine learning task of learning a function that
             maps an input to an output based on example input-output pairs. It infers a
             function from labeled training data consisting of a set of training examples.
             In supervised learning, each example is a pair consisting of an input object
             (typically a vector) and a desired output value (also called the supervisory signal). 
             A supervised learning algorithm analyzes the training data and produces an inferred function, 
             which can be used for mapping new examples. An optimal scenario will allow for the 
             algorithm to correctly determine the class labels for unseen instances. This requires 
             the learning algorithm to generalize from the training data to unseen situations in a 
             'reasonable' way (see inductive bias).
          """
    print("naive ...")
    keywords = kw_model.extract_keywords(doc)
    print(keywords)
    

4. 切换网络环境

如果上述方法都无效,尝试切换网络(比如使用手机热点),确认是否是当前网络的访问限制导致无法连接HuggingFace。

内容的提问来源于stack exchange,提问作者zxjyes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 15:45:09