当前位置:   article > 正文

transformers 加载模型时报错_oserror: can't load tokenizer for 'bert-base-chine

oserror: can't load tokenizer for 'bert-base-chinese'. if you were trying to

transformers加载模型时报错

安装transformers后,拿下面的代码测试

from transformers import AutoTokenizer, TFAutoModel
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
model = TFAutoModel.from_pretrained("bert-base-uncased")
inputs = tokenizer("Hello world!", return_tensors="tf")
outputs = model(inputs)
print(inputs)
print(outputs)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

报错:

HTTPSConnectionPool(host='cdn-lfs.huggingface.co', port=443): Max retries exceeded with url: /bert-base-uncased/a7a17d6d844b5de815ccab5f42cad6d24496db3850a2a43d8258221018ce87d2 (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x0000022BEE03A6A0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',))
Traceback (most recent call last):
  File "D:\Anaconda3\envs\tensorflow_gpu\lib\site-packages\urllib3\connection.py", line 157, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw
  File "D:\Anaconda3\envs\tensorflow_gpu\lib\site-packages\urllib3\util\connection.py", line 61, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "D:\Anaconda3\envs\tensorflow_gpu\lib\socket.py", line 745, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Anaconda3\envs\tensorflow_gpu\lib\site-packages\urllib3\connectionpool.py", line 672, in urlopen
    chunked=chunked,
  File "D:\Anaconda3\envs\tensorflow_gpu\lib\site-packages\urllib3\connectionpool.py", line 376, in _make_request
    self._validate_conn(conn)
  File "D:\Anaconda3\envs\tensorflow_gpu\lib\site-packages\urllib3\connectionpool.py", line 994, in _validate_conn
    conn.connect()
  File "D:\Anaconda3\envs\tensorflow_gpu\lib\site-packages\urllib3\connection.py", line 300, in connect
    conn = self._new_conn()
  File "D:\Anaconda3\envs\tensorflow_gpu\lib\site-packages\urllib3\connection.py", line 169, in _new_conn
    self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x0000022BEE03A6A0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Anaconda3\envs\tensorflow_gpu\lib\site-packages\requests\adapters.py", line 449, in send
    timeout=timeout
  File "D:\Anaconda3\envs\tensorflow_gpu\lib\site-packages\urllib3\connectionpool.py", line 720, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "D:\Anaconda3\envs\tensorflow_gpu\lib\site-packages\urllib3\util\retry.py", line 436, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='cdn-lfs.huggingface.co', port=443): Max retries exceeded with url: /bert-base-uncased/a7a17d6d844b5de815ccab5f42cad6d24496db3850a2a43d8258221018ce87d2 (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x0000022BEE03A6A0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Anaconda3\envs\tensorflow_gpu\lib\site-packages\transformers\modeling_tf_utils.py", line 702, in from_pretrained
    local_files_only=local_files_only,
  File "D:\Anaconda3\envs\tensorflow_gpu\lib\site-packages\transformers\file_utils.py", line 1007, in cached_path
    local_files_only=local_files_only,
  File "D:\Anaconda3\envs\tensorflow_gpu\lib\site-packages\transformers\file_utils.py", line 1216, in get_from_cache
    http_get(url_to_download, temp_file, proxies=proxies, resume_size=resume_size, user_agent=user_agent)
  File "D:\Anaconda3\envs\tensorflow_gpu\lib\site-packages\transformers\file_utils.py", line 1076, in http_get
    r = requests.get(url, stream=True, proxies=proxies, headers=headers)
  File "D:\Anaconda3\envs\tensorflow_gpu\lib\site-packages\requests\api.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "D:\Anaconda3\envs\tensorflow_gpu\lib\site-packages\requests\api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "D:\Anaconda3\envs\tensorflow_gpu\lib\site-packages\requests\sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "D:\Anaconda3\envs\tensorflow_gpu\lib\site-packages\requests\sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "D:\Anaconda3\envs\tensorflow_gpu\lib\site-packages\requests\adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='cdn-lfs.huggingface.co', port=443): Max retries exceeded with url: /bert-base-uncased/a7a17d6d844b5de815ccab5f42cad6d24496db3850a2a43d8258221018ce87d2 (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x0000022BEE03A6A0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:/tensorflow工程化实战/transformers_demo/uncode01.py", line 4, in <module>
    model = TFAutoModel.from_pretrained("bert-base-uncased")
  File "D:\Anaconda3\envs\tensorflow_gpu\lib\site-packages\transformers\models\auto\modeling_tf_auto.py", line 561, in from_pretrained
    pretrained_model_name_or_path, *model_args, config=config, **kwargs
  File "D:\Anaconda3\envs\tensorflow_gpu\lib\site-packages\transformers\modeling_tf_utils.py", line 711, in from_pretrained
    raise EnvironmentError(msg)
OSError: Can't load weights for 'bert-base-uncased'. Make sure that:

- 'bert-base-uncased' is a correct model identifier listed on 'https://huggingface.co/models'

- or 'bert-base-uncased' is the correct path to a directory containing a file named one of tf_model.h5, pytorch_model.bin.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73

原因
加载模型需要翻墙。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/347533
推荐阅读
相关标签
  

闽ICP备14008679号