未知的任务文本分类,可用的任务是['feature-temant-rettraction','情感 - 分析',

发布于 2025-01-24 03:53:56 字数 2411 浏览 2 评论 0原文

我试图基于此模型首次使用变形金刚:

https://huggingface.co/bhadresh-savani/distilbert-base-uncased-emotion?text=i+like+yellike+yefy.+ ii+love+yelove+yyou

这里提供的示例代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

画▽骨i 2025-01-31 03:53:56

看起来您从他们的文档中引用的示例过时。文本计算管道已重命名为感性 - 分析,因此您需要替换:

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

以下内容:

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

这是链接到管道文档如果您想了解更多有关它的信息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文