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)
相关推荐
深蓝电商API几秒前
Scrapy与Splash结合爬取JavaScript渲染页面
javascript·爬虫·python·scrapy
AIFQuant1 分钟前
2026 澳大利亚证券交易所(ASX)API 接入与 Python 量化策略
开发语言·python·websocket·金融·restful
木头左2 分钟前
VIX期货基差异常下的指数期权波动率互换套利策略实现
python
人工干智能7 分钟前
python的高级技巧:Pandas中的`iloc[]`和`loc[]`
开发语言·python·pandas
duyinbi75177 分钟前
【深度学习】基于YOLO11的数字仪表识别与分类实现_HAFB_1
人工智能·深度学习·分类
未定义.22111 分钟前
第5篇:进阶优化:数据驱动+日志体系+失败重试实战
python·ui·自动化·jenkins·集成测试·pytest
小白学大数据21 分钟前
随机间隔在 Python 爬虫中的应用实践
开发语言·c++·爬虫·python
tjjucheng38 分钟前
专业小程序定制开发生产厂家
python
无我198742 分钟前
靠谱的厌氧池清淤哪家妙
大数据·人工智能·python
坚持学习前端日记1 小时前
后台管理系统文档
java·开发语言·windows·spring boot·python·spring