概念
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}]