问题描述
目前项目里需要访问,huggingface上的嵌入模型,如下方这行代码
embedding_function = HuggingFaceEmbeddings(model_name=“all-MiniLM-L6-v2”)
报以下问题:
File “D:\software\Anaconda3\envs\DL_pytorch\Lib\site-packages\transformers\utils\hub.py”, line 550, in cached_files
raise OSError(
OSError: We couldn’t connect to ‘https://huggingface.co’ to load the files, and couldn’t find them in the cached files.
Check your internet connection or see how to run the library in offline mode at ‘https://huggingface.co/docs/transformers/installation#offline-mode’.
很明显,它要访问https://huggingface.co地址,而这个地址是国外的,需要科学上网才行。解决版本如下:
使用国内的HF-Mirrors来替换:
代码的上方加上以下内容
import os
# 使用https://hf-mirror.com来替换默认的https://huggingface.co 因为这个访问这个地址需要科学上网
os.environ['HF_ENDPOINT'] = "https://hf-mirror.com"
注:之前用的是 os.environ['HUGGINGFACE_CO_RESOLVE_ENDPOINT'] = "https://hf-mirror.com",发现这样还是不行,因新版本上不再支持,需要将HUGGINGFACE_CO_RESOLVE_ENDPOINT 换成HF_ENDPOINT可以了。
16万+

被折叠的 条评论
为什么被折叠?



