1 : 默认的model 。
from huggingface_hub.hf_api import HfFolderHfFolder.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 HfFolderHfFolder.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 HfFolderHfFolder.save_token('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')from transformers import pipelineclassifier = 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 pipelineclassifier = 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)