未知的任务文本分类,可用的任务是['feature-temant-rettraction','情感 - 分析',
我试图基于此模型首次使用变形金刚:
这里提供的示例代码:
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']"
是的,我首先安装了Transfomers
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:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您从他们的文档中引用的示例过时。文本计算管道已重命名为感性 - 分析,因此您需要替换:
以下内容:
这是链接到管道文档如果您想了解更多有关它的信息。
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:
with:
Here's a link to the pipeline docs if you want to read more about it.