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)
相关推荐
copyer_xyf5 小时前
Python 文件基本操作
前端·后端·python
嘶哈哈哈5 小时前
# SolidWorks 启动提示“无法获得下列许可 SOLIDWORKS Standard”的解决思路
python
zh路西法6 小时前
【rosbridge-websocket】跨网络的ROS1与ROS2通讯法(上)
linux·网络·c++·python·websocket·网络协议
圆弧YH6 小时前
python→ Language
python
装不满的克莱因瓶6 小时前
掌握神经网络的模型结构
人工智能·python·深度学习·神经网络·机器学习·ai
稷下元歌6 小时前
7天学会plc加机器视觉关于运动控制部份,配套视频在bib
开发语言·c++·git·vscode·python·docker·pip
奋斗的小方6 小时前
Java进阶篇1-1:异常
java·开发语言·python
颜酱6 小时前
LangChain 调大模型:模板拼接 + invoke / stream / batch
python·langchain
ice8130331816 小时前
【Python】调用opencv识别图片人脸位置
人工智能·python·opencv
Full Stack Developme6 小时前
Hutool CollUtil 教程
java·开发语言·windows·python