huggingface pipeline零训练样本分类Zero-Shot Classification的实现

1 : 默认的model 。

python 复制代码
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 :

python 复制代码
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

python 复制代码
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:

python 复制代码
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)
相关推荐
学历真的很重要1 小时前
LangChain V1.0 Short-term Memory 详细指南
后端·python·语言模型·面试·langchain·agent·ai编程
LitchiCheng2 小时前
Mujoco 基础:获取模型中所有 body 的 name, id 以及位姿
人工智能·python
老鱼说AI2 小时前
算法基础教学第一步:数据结构
数据结构·python·算法
2301_795167202 小时前
Python 高手编程系列八:缓存
开发语言·python·缓存
闲人编程2 小时前
Django测试框架深度使用:Factory Boy与Fixture对比
数据库·python·django·sqlite·钩子·fixture·codecapsule
梅花142 小时前
基于Django房屋租赁系统
后端·python·django·bootstrap·django项目·django网站
今天没有盐2 小时前
Python数据分析实战:从超市销售到教学评估
python·pycharm·编程语言
white-persist4 小时前
【攻防世界】reverse | IgniteMe 详细题解 WP
c语言·汇编·数据结构·c++·python·算法·网络安全
霍格沃兹测试开发学社-小明4 小时前
AI来袭:自动化测试在智能实战中的华丽转身
运维·人工智能·python·测试工具·开源
@游子4 小时前
Python学习笔记-Day2
开发语言·python