Need to use the Helsinki-NLP/opus-mt-tc-big-en-it · Hugging Face to translate some medical terms from English to Italian.
Setup an environment with conda as follows:
conda create --name huggingface python=3.9 black pylint
conda activate huggingface
conda install -c conda-forge tensorflow
conda install -c huggingface transformers
conda install -c conda-forge sentencepiece
then try to run the small sample program listed in the model’s page:
from transformers import MarianMTModel, MarianTokenizer
src_text = [
"He was always very respectful.",
"This cat is black. Is the dog, too?"
]
model_name = "pytorch-models/opus-mt-tc-big-en-it"
tokenizer = MarianTokenizer.from_pretrained(model_name)
model = MarianMTModel.from_pretrained(model_name)
translated = model.generate(**tokenizer(src_text, return_tensors="pt", padding=True))
for t in translated:
print( tokenizer.decode(t, skip_special_tokens=True) )
get the following errors:
(huggingface) bob@Roberts-Mac-mini engdisorders2italian % python test.py
Traceback (most recent call last):
File "/Users/bob/opt/miniconda3/envs/huggingface/lib/python3.9/site-packages/huggingface_hub-0.10.1-py3.8.egg/huggingface_hub/utils/_errors.py", line 213, in hf_raise_for_status
File "/Users/bob/opt/miniconda3/envs/huggingface/lib/python3.9/site-packages/requests/models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://huggingface.co/pytorch-models/opus-mt-tc-big-en-it/resolve/main/source.spm
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/bob/opt/miniconda3/envs/huggingface/lib/python3.9/site-packages/transformers/utils/hub.py", line 409, in cached_file
resolved_file = hf_hub_download(
File "/Users/bob/opt/miniconda3/envs/huggingface/lib/python3.9/site-packages/huggingface_hub-0.10.1-py3.8.egg/huggingface_hub/file_download.py", line 1053, in hf_hub_download
File "/Users/bob/opt/miniconda3/envs/huggingface/lib/python3.9/site-packages/huggingface_hub-0.10.1-py3.8.egg/huggingface_hub/file_download.py", line 1359, in get_hf_file_metadata
File "/Users/bob/opt/miniconda3/envs/huggingface/lib/python3.9/site-packages/huggingface_hub-0.10.1-py3.8.egg/huggingface_hub/utils/_errors.py", line 242, in hf_raise_for_status
huggingface_hub.utils._errors.RepositoryNotFoundError: 401 Client Error. (Request ID: hZlXOfQHdWwkux5NvawFh)
Repository Not Found for url: https://huggingface.co/pytorch-models/opus-mt-tc-big-en-it/resolve/main/source.spm.
Please make sure you specified the correct `repo_id` and `repo_type`.
If the repo is private, make sure you are authenticated.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/bob/Documents/work/engdisorders2italian/test.py", line 9, in <module>
tokenizer = MarianTokenizer.from_pretrained(model_name)
File "/Users/bob/opt/miniconda3/envs/huggingface/lib/python3.9/site-packages/transformers/tokenization_utils_base.py", line 1734, in from_pretrained
resolved_vocab_files[file_id] = cached_file(
File "/Users/bob/opt/miniconda3/envs/huggingface/lib/python3.9/site-packages/transformers/utils/hub.py", line 424, in cached_file
raise EnvironmentError(
OSError: pytorch-models/opus-mt-tc-big-en-it is not a local folder and is not a valid model identifier listed on 'https://huggingface.co/models'
If this is a private repository, make sure to pass a token having permission to this repo with `use_auth_token` or log in with `huggingface-cli login` and pass `use_auth_token=True`.
no clue as how to fix this.
Environment is Mac mini with Apple CPU (M1 Arm) with MacOS Monterey
Python managed via conda
Thank you for any help