当前位置:   article > 正文

HuggingFace:pipeline为特定NLP任务直接调用_huggingface pipeline

huggingface pipeline

1. English Sentiment Analysis

默认情况下,pipeline选择一个特定的预训练模型,该模型已为英语情绪分析进行了微调。创建分类器对象时,将下载并缓存模型。如果重新运行该命令,则将使用缓存的模型,无需再次下载该模型。

from transformers import pipeline

classifier = pipeline("sentiment-analysis")
classifier("I've been waiting for a HuggingFace course my whole life.")
  • 1
  • 2
  • 3
  • 4
输出:[{'label': 'POSITIVE', 'score': 0.9598047137260437}]
  • 1

2. zero-shot classification

from transformers import pipeline

classifier = pipeline("zero-shot-classification")
classifier(
    "This is a course about the Transformers library",
    candidate_labels=["education", "politics", "business", "course"],
)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
输出:
{'sequence': 'This is a course about the Transformers library',
 'labels': ['course', 'education', 'business', 'politics'],
 'scores': [0.9461037516593933,
  0.04552055522799492,
  0.0060350666753947735,
  0.002340571256354451]}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

3. text generation

    声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/462135
    推荐阅读
    相关标签
      

    闽ICP备14008679号