Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unknown task text-classification, available tasks are ['feature-extraction', 'sentiment-analysis',

I am trying to use Transformers for the first time based on this model:

https://huggingface.co/bhadresh-savani/distilbert-base-uncased-emotion?text=I+like+you.+I+love+you

The sample code provided here its:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

from transformers import pipeline
classifier = pipeline("text-classification",model='bhadresh-savani/distilbert-base-uncased-emotion', return_all_scores=True)
prediction = classifier("I love using transformers. The best part is wide range of support and its easy to use", )
print(prediction)

However I get this error:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-6-74ca6189abbe> in <module>
      1 from transformers import pipeline
----> 2 classifier = pipeline("text-classification",model='bhadresh-savani/distilbert-base-uncased-emotion', return_all_scores=True)
      3 prediction = classifier("I love using transformers. The best part is wide range of support and its easy to use", )
      4 print(prediction)

/anaconda/envs/azureml_py38/lib/python3.8/site-packages/transformers/pipelines/__init__.py in pipeline(task, model, config, tokenizer, framework, revision, use_fast, use_auth_token, model_kwargs, **kwargs)
    340     """
    341     # Retrieve the task
--> 342     targeted_task, task_options = check_task(task)
    343 
    344     # Use default model/config/tokenizer for the task if no model is provided

/anaconda/envs/azureml_py38/lib/python3.8/site-packages/transformers/pipelines/__init__.py in check_task(task)
    234         raise KeyError(f"Invalid translation task {task}, use 'translation_XX_to_YY' format")
    235 
--> 236     raise KeyError(
    237         f"Unknown task {task}, available tasks are {list(SUPPORTED_TASKS.keys()) + ['translation_XX_to_YY']}"
    238     )

KeyError: "Unknown task text-classification, available tasks are ['feature-extraction', 'sentiment-analysis', 'ner', 'question-answering', 'table-question-answering', 'fill-mask', 'summarization', 'translation', 'text2text-generation', 'text-generation', 'zero-shot-classification', 'conversational', 'translation_XX_to_YY']"

And Yes I Installed transfomers first

>Solution :

It looks like the example that you referenced from their docs is out of date. The text-classification pipeline has been renamed to sentiment-analysis, therefore you need to replace:

classifier = pipeline("text-classification"...

with:

classifier = pipeline("sentiment-analysis"...

Here’s a link to the pipeline docs if you want to read more about it.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading