本文主要是介绍huggingface pipeline零训练样本分类Zero-Shot Classification的实现,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1 : 默认的model 。
from huggingface_hub.hf_api import HfFolder
HfFolder.save_token('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')
from transformers import MBartForConditionalGeneration, MBart50TokenizerFastfrom transformers import pipelineclassifier = 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 pipelineclassifier = pipeline("zero-shot-classification",model="morit/chinese_xlm_xnli")
result = classifier(
"零训练样本分类 pipeline 允许我们在不提供任何标注数据的情况下自定义分类标签",
candidate_labels=["学术", "商业", "销售"],
)
print(result)
3:使用 facebook/bart-large-mnli
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:
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的实现的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!