1 : 默认的model 。
from huggingface_hub.hf_api import HfFolder
HfFolder.save_token('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')
from transformers import MBartForConditionalGeneration, MBart50TokenizerFast
from transformers import pipeline
classifier = pipeline("zero-shot-classification")
result = classifier(
"This is a course about the Transformers library",
candidate_labels=["education", "politics", "business"],
)
print(result)
输出是 education 第一位的。
2 : 使用 morit/chinese_xlm_xnli :
from huggingface_hub.hf_api import HfFolder
HfFolder.save_token('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')
from transformers import pipeline
classifier = pipeline("zero-shot-classification",
model="morit/chinese_xlm_xnli")
result = classifier(
"零训练样本分类 pipeline 允许我们在不提供任何标注数据的情况下自定义分类标签",
candidate_labels=["学术", "商业", "销售"],
)
print(result)
3:使用 facebook/bart-large-mnli文章来源:https://www.toymoban.com/news/detail-830638.html
from huggingface_hub.hf_api import HfFolder
HfFolder.save_token('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')
from transformers import pipeline
classifier = pipeline("zero-shot-classification",
model="facebook/bart-large-mnli")
result = classifier("I have a problem with my iphone that needs to be resolved asap!",
candidate_labels=["urgent", "not urgent", "phone", "tablet", "computer"],
)
print(result)
4:文章来源地址https://www.toymoban.com/news/detail-830638.html
from transformers import pipeline
classifier = pipeline("zero-shot-classification",
model="facebook/bart-large-mnli")
sequence_to_classify = "one day I will see the world"
candidate_labels = ['travel', 'cooking', 'dancing']
a = classifier(sequence_to_classify, candidate_labels)
print(a)
到了这里,关于huggingface pipeline零训练样本分类Zero-Shot Classification的实现的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!