🚀 多语言e5-base-xnli-anli模型
本模型是在XNLI和ANLI数据集上对 intfloat/multilingual-e5-base 进行微调后的版本,可用于零样本分类任务,支持多种语言,为跨语言文本分类提供了高效的解决方案。
🚀 快速开始
本模型可用于零样本分类任务,以下是使用该模型的快速入门指南。
✨ 主要特性
- 多语言支持:支持英语(en)、阿拉伯语(ar)、保加利亚语(bg)、德语(de)、希腊语(el)、西班牙语(es)、法语(fr)、印地语(hi)、俄语(ru)、斯瓦希里语(sw)、泰语(th)、土耳其语(tr)、乌尔都语(ur)、越南语(vi)和中文(zh)等多种语言。
- 零样本分类:可以直接对未在训练中出现的类别进行分类。
- 微调优化:在XNLI和ANLI数据集上进行微调,提升了模型在自然语言推理任务上的性能。
📦 安装指南
文档未提及安装步骤,跳过此章节。
💻 使用示例
基础用法
使用 zero-shot-classification
管道加载模型:
from transformers import pipeline
classifier = pipeline("zero-shot-classification",
model="mjwong/multilingual-e5-base-xnli-anli")
使用此管道将序列分类到指定的类别名称中:
sequence_to_classify = "Angela Merkel ist eine Politikerin in Deutschland und Vorsitzende der CDU"
candidate_labels = ["politics", "economy", "entertainment", "environment"]
classifier(sequence_to_classify, candidate_labels)
如果多个候选标签可能正确,传递 multi_class=True
以独立计算每个类别:
candidate_labels = ["politics", "economy", "entertainment", "environment"]
classifier(sequence_to_classify, candidate_labels, multi_label=True)
高级用法
手动使用PyTorch将模型应用于NLI任务:
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
model_name = "mjwong/multilingual-e5-base-xnli-anli"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
premise = "But I thought you'd sworn off coffee."
hypothesis = "I thought that you vowed to drink more coffee."
input = tokenizer(premise, hypothesis, truncation=True, return_tensors="pt")
output = model(input["input_ids"].to(device))
prediction = torch.softmax(output["logits"][0], -1).tolist()
label_names = ["entailment", "neutral", "contradiction"]
prediction = {name: round(float(pred) * 100, 2) for pred, name in zip(prediction, label_names)}
print(prediction)
📚 详细文档
评估结果
模型在XNLI测试集上对15种语言进行了评估,使用的指标是准确率。
模型还使用MultiNLI的开发集和ANLI的测试集进行了评估,使用的指标是准确率。
训练超参数
训练期间使用了以下超参数:
- 学习率:2e-05
- 训练批次大小:16
- 评估批次大小:16
- 随机种子:42
- 优化器:Adam(β1=0.9,β2=0.999,ε=1e-08)
- 学习率调度器类型:线性
- 学习率调度器预热比例:0.1
框架版本
- Transformers 4.28.1
- Pytorch 1.12.1+cu116
- Datasets 2.11.0
- Tokenizers 0.12.1
🔧 技术细节
本模型基于论文 Text Embeddings by Weakly-Supervised Contrastive Pre-training 进行开发,作者为Liang Wang、Nan Yang、Xiaolong Huang、Binxing Jiao、Linjun Yang、Daxin Jiang、Rangan Majumder和Furu Wei,发表于arXiv 2022。
📄 许可证
本项目采用MIT许可证。
属性 |
详情 |
模型类型 |
多语言零样本分类模型 |
训练数据 |
XNLI和ANLI数据集 |