利用大模型MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7实现零样本分类

概念

1、零样本分类:在没有样本标签的情况下对文本进行分类。

2、nli:(Natural Language Inference),自然语言推理

3、xnli:(Cross-Lingual Natural Language Inference) ,是一种数据集,支持15种语言,数据集包含10个领域,每个领域包含750条样本,10个领域共计7500条人工标注的英文测试样本,组成了112500对英文--其他语种的标注对。每条数据样本,由两个句子组成,分别是前提和假设,前提和假设之间的关系,有entailment(蕴含)、contradiction(矛盾)、neutral(中立)三类。

模型

1、手动下载MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7到本地,url:MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7 at main

2、Git下载:

bash 复制代码
git lfs install
git clone https://huggingface.co/MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7

代码:

保存为m.py文件

python 复制代码
import torch
import torch.nn.functional as F
from transformers import AutoTokenizer, AutoModelForSequenceClassification
from transformers import pipeline
model_name = "mDeBERTa-v3-base-xnli-multilingual-nli-2mil7"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
for aspect in ['camera', 'phone']:
   print(aspect, classifier('The camera quality of this phone is amazing.',  text_pair=aspect))

输出:

bash 复制代码
[ipa@comm-agi-p]$ python m.py
camera [{'label': 'entailment', 'score': 0.9938687682151794}]
phone [{'label': 'entailment', 'score': 0.9425390362739563}]
相关推荐
蹦蹦跳跳真可爱5892 小时前
Python----深度学习(基于深度学习Pytroch簇分类,圆环分类,月牙分类)
人工智能·pytorch·python·深度学习·分类
Sherlock Ma9 小时前
PDFMathTranslate:基于LLM的PDF文档翻译及双语对照的工具【使用教程】
人工智能·pytorch·语言模型·pdf·大模型·机器翻译·deepseek
搞机小能手9 小时前
六个能够白嫖学习资料的网站
笔记·学习·分类
-曾牛13 小时前
Spring AI 快速入门:从环境搭建到核心组件集成
java·人工智能·spring·ai·大模型·spring ai·开发环境搭建
Aloudata13 小时前
Aloudata Agent :基于 NoETL 明细语义层的分析决策智能体
数据分析·大模型·数据管理·noetl·智能问数·智能归因·智能报告
量子-Alex15 小时前
【遥感图像分类】【综述】遥感影像分类:全面综述与应用
人工智能·分类·数据挖掘
arbboter18 小时前
【AI插件开发】Notepad++ AI插件开发1.0发布和使用说明
人工智能·大模型·notepad++·ai助手·ai插件·aicoder·notepad++插件开发
胡攀峰1 天前
第12章 微调生成模型
人工智能·大模型·llm·sft·强化学习·rlhf·指令微调
HuggingFace2 天前
大模型评估排障指南 | 关于推理
大模型
dundunmm2 天前
【每天一个知识点】如何解决大模型幻觉(hallucination)问题?
人工智能·数据挖掘·大模型