未知任务文本分类,可用任务有['feature-extraction', 'sentiment-analysis',

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

我第一次尝试基于这个模型使用变形金刚:

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

此处提供的示例代码其:

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)

但是我得到这个错误:

---------------------------------------------------------------------------
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']"

是的,我先安装了变压器

您从他们的文档中引用的示例似乎已过时。 text-classification 管道已重命名为 sentiment-analysis,因此您需要替换:

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

与:

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

如果您想阅读更多相关信息,请点击此处link to the pipeline docs