python中的transformers是可以下载下来并且正常import的,但是却没有办法使用
这里是一个最简单的代码
from transformers import pipeline
classifier = pipeline(task='sentiment-analysis')
res = classifier('Today is a nice day!')
print(res)
如果我开clash的话,会产生如下报错:
D:\桌面\pythonProject1\venv\Scripts\python.exe D:\桌面\pythonProject1\mne\transformers_try.py
2024-05-11 22:23:00.272259: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2024-05-11 22:23:00.872298: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
No model was supplied, defaulted to distilbert/distilbert-base-uncased-finetuned-sst-2-english and revision af0f99b (https://huggingface.co/distilbert/distilbert-base-uncased-finetuned-sst-2-english).
Using a pipeline without specifying a model name and revision in production is not recommended.
D:\桌面\pythonProject1\venv\lib\site-packages\huggingface_hub\file_download.py:1132: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`.
warnings.warn(
urllib3.exceptions.SSLError: EOF occurred in violation of protocol (_ssl.c:1129)
The above exception was the direct cause of the following exception:
urllib3.exceptions.ProxyError: ('Unable to connect to proxy', SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1129)')))
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\桌面\pythonProject1\venv\lib\site-packages\requests\adapters.py", line 486, in send
resp = conn.urlopen(
File "D:\桌面\pythonProject1\venv\lib\site-packages\urllib3\connectionpool.py", line 847, in urlopen
retries = retries.increment(
File "D:\桌面\pythonProject1\venv\lib\site-packages\urllib3\util\retry.py", line 515, in increment
raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /distilbert/distilbert-base-uncased-finetuned-sst-2-english/resolve/main/config.json (Caused by ProxyError('Unable to connect to proxy', SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1129)'))))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\桌面\pythonProject1\mne\transformers_try.py", line 3, in <module>
classifier = pipeline(task='sentiment-analysis')
File "D:\桌面\pythonProject1\venv\lib\site-packages\transformers\pipelines\__init__.py", line 875, in pipeline
config = AutoConfig.from_pretrained(model, _from_pipeline=task, **hub_kwargs, **model_kwargs)
File "D:\桌面\pythonProject1\venv\lib\site-packages\transformers\models\auto\configuration_auto.py", line 928, in from_pretrained
config_dict, unused_kwargs = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
File "D:\桌面\pythonProject1\venv\lib\site-packages\transformers\configuration_utils.py", line 631, in get_config_dict
config_dict, kwargs = cls._get_config_dict(pretrained_model_name_or_path, **kwargs)
File "D:\桌面\pythonProject1\venv\lib\site-packages\transformers\configuration_utils.py", line 686, in _get_config_dict
resolved_config_file = cached_file(
File "D:\桌面\pythonProject1\venv\lib\site-packages\transformers\utils\hub.py", line 398, in cached_file
resolved_file = hf_hub_download(
File "D:\桌面\pythonProject1\venv\lib\site-packages\huggingface_hub\utils\_validators.py", line 114, in _inner_fn
return fn(*args, **kwargs)
File "D:\桌面\pythonProject1\venv\lib\site-packages\huggingface_hub\file_download.py", line 1221, in hf_hub_download
return _hf_hub_download_to_cache_dir(
File "D:\桌面\pythonProject1\venv\lib\site-packages\huggingface_hub\file_download.py", line 1282, in _hf_hub_download_to_cache_dir
(url_to_download, etag, commit_hash, expected_size, head_call_error) = _get_metadata_or_catch_error(
File "D:\桌面\pythonProject1\venv\lib\site-packages\huggingface_hub\file_download.py", line 1722, in _get_metadata_or_catch_error
metadata = get_hf_file_metadata(url=url, proxies=proxies, timeout=etag_timeout, headers=headers)
File "D:\桌面\pythonProject1\venv\lib\site-packages\huggingface_hub\utils\_validators.py", line 114, in _inner_fn
return fn(*args, **kwargs)
File "D:\桌面\pythonProject1\venv\lib\site-packages\huggingface_hub\file_download.py", line 1645, in get_hf_file_metadata
r = _request_wrapper(
File "D:\桌面\pythonProject1\venv\lib\site-packages\huggingface_hub\file_download.py", line 372, in _request_wrapper
response = _request_wrapper(
File "D:\桌面\pythonProject1\venv\lib\site-packages\huggingface_hub\file_download.py", line 395, in _request_wrapper
response = get_session().request(method=method, url=url, **params)
File "D:\桌面\pythonProject1\venv\lib\site-packages\requests\sessions.py", line 589, in request
resp = self.send(prep, **send_kwargs)
File "D:\桌面\pythonProject1\venv\lib\site-packages\requests\sessions.py", line 703, in send
r = adapter.send(request, **kwargs)
File "D:\桌面\pythonProject1\venv\lib\site-packages\huggingface_hub\utils\_http.py", line 66, in send
return super().send(request, *args, **kwargs)
File "D:\桌面\pythonProject1\venv\lib\site-packages\requests\adapters.py", line 513, in send
raise ProxyError(e, request=request)
requests.exceptions.ProxyError: (MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /distilbert/distilbert-base-uncased-finetuned-sst-2-english/resolve/main/config.json (Caused by ProxyError('Unable to connect to proxy', SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1129)'))))"), '(Request ID: fca6c479-9a60-4f19-a4ae-f296560ca597)')
Process finished with exit code 1
如果我不开clash的话,也会产生如下报错:
D:\桌面\pythonProject1\venv\Scripts\python.exe D:\桌面\pythonProject1\mne\transformers_try.py
2024-05-11 22:24:11.833690: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2024-05-11 22:24:12.441548: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
No model was supplied, defaulted to distilbert/distilbert-base-uncased-finetuned-sst-2-english and revision af0f99b (https://huggingface.co/distilbert/distilbert-base-uncased-finetuned-sst-2-english).
Using a pipeline without specifying a model name and revision in production is not recommended.
D:\桌面\pythonProject1\venv\lib\site-packages\huggingface_hub\file_download.py:1132: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`.
warnings.warn(
Traceback (most recent call last):
File "D:\桌面\pythonProject1\venv\lib\site-packages\urllib3\connection.py", line 198, in _new_conn
sock = connection.create_connection(
File "D:\桌面\pythonProject1\venv\lib\site-packages\urllib3\util\connection.py", line 85, in create_connection
raise err
File "D:\桌面\pythonProject1\venv\lib\site-packages\urllib3\util\connection.py", line 73, in create_connection
sock.connect(sa)
socket.timeout: timed out
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\桌面\pythonProject1\venv\lib\site-packages\urllib3\connectionpool.py", line 793, in urlopen
response = self._make_request(
File "D:\桌面\pythonProject1\venv\lib\site-packages\urllib3\connectionpool.py", line 491, in _make_request
raise new_e
File "D:\桌面\pythonProject1\venv\lib\site-packages\urllib3\connectionpool.py", line 467, in _make_request
self._validate_conn(conn)
File "D:\桌面\pythonProject1\venv\lib\site-packages\urllib3\connectionpool.py", line 1099, in _validate_conn
conn.connect()
File "D:\桌面\pythonProject1\venv\lib\site-packages\urllib3\connection.py", line 616, in connect
self.sock = sock = self._new_conn()
File "D:\桌面\pythonProject1\venv\lib\site-packages\urllib3\connection.py", line 207, in _new_conn
raise ConnectTimeoutError(
urllib3.exceptions.ConnectTimeoutError: (<urllib3.connection.HTTPSConnection object at 0x0000017951631F40>, 'Connection to huggingface.co timed out. (connect timeout=10)')
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\桌面\pythonProject1\venv\lib\site-packages\requests\adapters.py", line 486, in send
resp = conn.urlopen(
File "D:\桌面\pythonProject1\venv\lib\site-packages\urllib3\connectionpool.py", line 847, in urlopen
retries = retries.increment(
File "D:\桌面\pythonProject1\venv\lib\site-packages\urllib3\util\retry.py", line 515, in increment
raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /distilbert/distilbert-base-uncased-finetuned-sst-2-english/resolve/main/config.json (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x0000017951631F40>, 'Connection to huggingface.co timed out. (connect timeout=10)'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\桌面\pythonProject1\venv\lib\site-packages\huggingface_hub\file_download.py", line 1722, in _get_metadata_or_catch_error
metadata = get_hf_file_metadata(url=url, proxies=proxies, timeout=etag_timeout, headers=headers)
File "D:\桌面\pythonProject1\venv\lib\site-packages\huggingface_hub\utils\_validators.py", line 114, in _inner_fn
return fn(*args, **kwargs)
File "D:\桌面\pythonProject1\venv\lib\site-packages\huggingface_hub\file_download.py", line 1645, in get_hf_file_metadata
r = _request_wrapper(
File "D:\桌面\pythonProject1\venv\lib\site-packages\huggingface_hub\file_download.py", line 372, in _request_wrapper
response = _request_wrapper(
File "D:\桌面\pythonProject1\venv\lib\site-packages\huggingface_hub\file_download.py", line 395, in _request_wrapper
response = get_session().request(method=method, url=url, **params)
File "D:\桌面\pythonProject1\venv\lib\site-packages\requests\sessions.py", line 589, in request
resp = self.send(prep, **send_kwargs)
File "D:\桌面\pythonProject1\venv\lib\site-packages\requests\sessions.py", line 703, in send
r = adapter.send(request, **kwargs)
File "D:\桌面\pythonProject1\venv\lib\site-packages\huggingface_hub\utils\_http.py", line 66, in send
return super().send(request, *args, **kwargs)
File "D:\桌面\pythonProject1\venv\lib\site-packages\requests\adapters.py", line 507, in send
raise ConnectTimeout(e, request=request)
requests.exceptions.ConnectTimeout: (MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /distilbert/distilbert-base-uncased-finetuned-sst-2-english/resolve/main/config.json (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x0000017951631F40>, 'Connection to huggingface.co timed out. (connect timeout=10)'))"), '(Request ID: 142bce7b-1f54-4c29-886c-37ff87abdbe2)')
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\桌面\pythonProject1\venv\lib\site-packages\transformers\utils\hub.py", line 398, in cached_file
resolved_file = hf_hub_download(
File "D:\桌面\pythonProject1\venv\lib\site-packages\huggingface_hub\utils\_validators.py", line 114, in _inner_fn
return fn(*args, **kwargs)
File "D:\桌面\pythonProject1\venv\lib\site-packages\huggingface_hub\file_download.py", line 1221, in hf_hub_download
return _hf_hub_download_to_cache_dir(
File "D:\桌面\pythonProject1\venv\lib\site-packages\huggingface_hub\file_download.py", line 1325, in _hf_hub_download_to_cache_dir
_raise_on_head_call_error(head_call_error, force_download, local_files_only)
File "D:\桌面\pythonProject1\venv\lib\site-packages\huggingface_hub\file_download.py", line 1826, in _raise_on_head_call_error
raise LocalEntryNotFoundError(
huggingface_hub.utils._errors.LocalEntryNotFoundError: An error happened while trying to locate the file on the Hub and we cannot find the requested files in the local cache. Please check your connection and try again or make sure your Internet connection is on.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\桌面\pythonProject1\mne\transformers_try.py", line 3, in <module>
classifier = pipeline(task='sentiment-analysis')
File "D:\桌面\pythonProject1\venv\lib\site-packages\transformers\pipelines\__init__.py", line 875, in pipeline
config = AutoConfig.from_pretrained(model, _from_pipeline=task, **hub_kwargs, **model_kwargs)
File "D:\桌面\pythonProject1\venv\lib\site-packages\transformers\models\auto\configuration_auto.py", line 928, in from_pretrained
config_dict, unused_kwargs = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
File "D:\桌面\pythonProject1\venv\lib\site-packages\transformers\configuration_utils.py", line 631, in get_config_dict
config_dict, kwargs = cls._get_config_dict(pretrained_model_name_or_path, **kwargs)
File "D:\桌面\pythonProject1\venv\lib\site-packages\transformers\configuration_utils.py", line 686, in _get_config_dict
resolved_config_file = cached_file(
File "D:\桌面\pythonProject1\venv\lib\site-packages\transformers\utils\hub.py", line 441, in cached_file
raise EnvironmentError(
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/distilbert-base-uncased-finetuned-sst-2-english is not the path to a directory containing a file named config.json.
Checkout your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
Process finished with exit code 1
总之就是连和huggingface.co的连接应该是有问题的,连最基本的模型都没办法导入,请各位指点一下应该具体怎么改进,能在不把模型下到本地的情况下完成对transformers的应用,也就是解决这里面的网络问题