Chapter 1 questions

How can we do part of speech tagging using pipeline?

In the try-it-out section before Question Answering module in Transformers What can they do submodule, we are asked to try POS on this sentence “My name is Sylvain and I work at Hugging Face in Brooklyn.”

However in pipeline, I could only see the following tasks

[‘audio-classification’, ‘automatic-speech-recognition’, ‘conversational’, ‘depth-estimation’, ‘document-question-answering’, ‘feature-extraction’, ‘fill-mask’, ‘image-classification’, ‘image-segmentation’, ‘image-to-text’, ‘ner’, ‘object-detection’, ‘question-answering’, ‘sentiment-analysis’, ‘summarization’, ‘table-question-answering’, ‘text-classification’, ‘text-generation’, ‘text2text-generation’, ‘token-classification’, ‘translation’, ‘video-classification’, ‘visual-question-answering’, ‘vqa’, ‘zero-shot-audio-classification’, ‘zero-shot-classification’, ‘zero-shot-image-classification’, ‘zero-shot-object-detection’, ‘translation_XX_to_YY’]

There is no support for the POS task. Should we use text-classification and ask it to predict B-Noun, I-Noun, O, B-Verb, O, I-Verb or something like this to get it done?

The pipeline function does not support translation task out of the box. I get a KeyError as follows

KeyError                                  Traceback (most recent call last)
Cell In[34], line 1
----> 1 translator = pipeline("translation", model = "HariSekhar/Eng_Marathi_translation")

File ~/huggingface/lib/python3.10/site-packages/transformers/pipelines/__init__.py:692, in pipeline(task, model, config, tokenizer, feature_extractor, image_processor, framework, revision, use_fast, use_auth_token, device, device_map, torch_dtype, trust_remote_code, model_kwargs, pipeline_class, **kwargs)
    690     hub_kwargs["_commit_hash"] = config._commit_hash
    691 elif config is None and isinstance(model, str):
--> 692     config = AutoConfig.from_pretrained(model, _from_pipeline=task, **hub_kwargs, **model_kwargs)
    693     hub_kwargs["_commit_hash"] = config._commit_hash
    695 custom_tasks = {}

File ~/huggingface/lib/python3.10/site-packages/transformers/models/auto/configuration_auto.py:917, in AutoConfig.from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
    915     return config_class.from_pretrained(pretrained_model_name_or_path, **kwargs)
    916 elif "model_type" in config_dict:
--> 917     config_class = CONFIG_MAPPING[config_dict["model_type"]]
    918     return config_class.from_dict(config_dict, **unused_kwargs)
    919 else:
    920     # Fallback: use pattern matching on the string.
    921     # We go from longer names to shorter names to catch roberta before bert (for instance)

File ~/huggingface/lib/python3.10/site-packages/transformers/models/auto/configuration_auto.py:623, in _LazyConfigMapping.__getitem__(self, key)
    621     return self._extra_content[key]
    622 if key not in self._mapping:
--> 623     raise KeyError(key)
    624 value = self._mapping[key]
    625 module_name = model_type_to_module_name(key)

KeyError: 'translation'

Does the pipeline now not support the translation task? I am using transformers 4.27.4 version.

i face some problem because of tensorflow and transforemer version so please anyone guide me that which versio is working in the given cource?

Hi
I’m doing
:pencil2: Try it out! Search the Model Hub for a model able to do part-of-speech tagging (usually abbreviated as POS) in English. What does this model predict for the sentence in the example above?

But I’m confused about the pipeline to use (ner or token-classification), and why

pos = pipeline("ner", grouped_entities=True, model="QCRI/bert-base-multilingual-cased-pos-english", device=device)    
pos = pipeline("token-classification", grouped_entities=True, model="QCRI/bert-base-multilingual-cased-pos-english", device=device)

Someones help me ```
^^^^^^^^^^^^^^^^^^^^^^^
PS C:\Users\grknb> & C:/Users/grknb/AppData/Local/Microsoft/WindowsApps/python3.12.exe c:/Users/grknb/ChatBotProject/bot.py
Understood. How can I assist you today from this virtual cockpit, over?Traceback (most recent call last):
File “C:\Users\grknb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\huggingface_hub\utils_errors.py”, line 304, in hf_raise_for_status
response.raise_for_status()
File “C:\Users\grknb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\requests\models.py”, line 1024, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://huggingface.co/mistralai/Mistral-Nemo-Instruct-2407/resolve/main/config.json

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “C:\Users\grknb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\transformers\utils\hub.py”, line 402, in cached_file
resolved_file = hf_hub_download(
^^^^^^^^^^^^^^^^
File “C:\Users\grknb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\huggingface_hub\utils_deprecation.py”, line 101, in inner_f
return f(*args, **kwargs)
^^^^^^^^^^^^^^^^^^
File “C:\Users\grknb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\huggingface_hub\utils_validators.py”, line 114, in _inner_fn
return fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File “C:\Users\grknb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\huggingface_hub\file_download.py”, line 1240, in hf_hub_download
return _hf_hub_download_to_cache_dir(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\grknb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\huggingface_hub\file_download.py”, line 1347, in _hf_hub_download_to_cache_dir
_raise_on_head_call_error(head_call_error, force_download, local_files_only)
File “C:\Users\grknb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\huggingface_hub\file_download.py”, line 1854, in _raise_on_head_call_error
raise head_call_error
File “C:\Users\grknb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\huggingface_hub\file_download.py”, line 1751, in _get_metadata_or_catch_error
metadata = get_hf_file_metadata(
^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\grknb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\huggingface_hub\utils_validators.py”, line 114, in _inner_fn
return fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File “C:\Users\grknb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\huggingface_hub\file_download.py”, line 1673, in get_hf_file_metadata
r = _request_wrapper(
^^^^^^^^^^^^^^^^^
File “C:\Users\grknb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\huggingface_hub\file_download.py”, line 376, in _request_wrapper
response = _request_wrapper(
^^^^^^^^^^^^^^^^^
File “C:\Users\grknb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\huggingface_hub\file_download.py”, line 400, in _request_wrapper
hf_raise_for_status(response)
File “C:\Users\grknb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\huggingface_hub\utils_errors.py”, line 321, in hf_raise_for_status
raise GatedRepoError(message, response) from e
huggingface_hub.utils._errors.GatedRepoError: 401 Client Error. (Request ID: Root=1-66ab6fcd-47b492f27ea0681b1ac8ec4d;a116e880-29f9-442f-a9fe-367fe852eea2)

Cannot access gated repo for url https:/ /huggingface.co/mistralai/Mistral-Nemo-Instruct-2407/resolve/main/config.json.
Access to model mistralai/Mistral-Nemo-Instruct-2407 is restricted. You must be authenticated to access it.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “c:\Users\grknb\ChatBotProject\bot.py”, line 22, in
tokenizer = AutoTokenizer.from_pretrained(model_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\grknb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\transformers\models\auto\tokenization_auto.py”, line 853, in from_pretrained
config = AutoConfig.from_pretrained(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\grknb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\transformers\models\auto\configuration_auto.py”, line 972, in from_pretrained
config_dict, unused_kwargs = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\grknb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\transformers\configuration_utils.py”, line 632, in get_config_dict
config_dict, kwargs = cls._get_config_dict(pretrained_model_name_or_path, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\grknb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\transformers\configuration_utils.py”, line 689, in _get_config_dict
resolved_config_file = cached_file(
^^^^^^^^^^^^
File “C:\Users\grknb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\transformers\utils\hub.py”, line 420, in cached_file
raise EnvironmentError(
OSError: You are trying to access a gated repo.
Make sure to have access to it at https:/ /huggingface.co/mistralai/Mistral-Nemo-Instruct-2407.
401 Client Error. (Request ID: Root=1-66ab6fcd-47b492f27ea0681b1ac8ec4d;a116e880-29f9-442f-a9fe-367fe852eea2)

Cannot access gated repo for url https: // huggingface .co/ mistralai/Mistral-Nemo-Instruct-2407/resolve/main/config.json.
Access to model mistralai/ Mistral-Nemo-Instruct-2407 is restricted. You must be authenticated to access it.

hi @ElisonSherton
I guess config.json · HariSekhar/Eng_Marathi_translation at main should be fixed.

“translation” is not a valid model_type:

1 Like

hi @jmalbarran
ner is an alias for token-classification. You can use either ner or token-classification.

Can someone help me? sentiment-analysis does not work. It crashes with this message:

.venv/lib/python3.12/site-packages/transformers/tokenization_utils_base.py:1602: FutureWarning: `clean_up_tokenization_spaces` was not set. It will be set to `True` by default. This behavior will be deprecated in transformers v4.45, and will be then set to `False` by default. For more details check this issue: https://github.com/huggingface/transformers/issues/31884
  warnings.warn(

hi @fromjon
I guess you run the snippet in Transformers, what can they do? - Hugging Face NLP Course. Actually there is no crash in the output, it’s just a warning. Did you run classifier("example sentence") part?

from transformers import pipeline

classifier = pipeline("sentiment-analysis")
classifier("I've been waiting for a HuggingFace course my whole life.")