🚀 多语言e5大模型指令微调XNLI-ANLI
本项目基于XNLI和ANLI数据集对intfloat/multilingual-e5-large-instruct模型进行微调,旨在提升模型在多语言自然语言推理任务上的性能。
🚀 快速开始
零样本分类管道
可以使用zero-shot-classification
管道加载模型,示例代码如下:
from transformers import pipeline
classifier = pipeline("zero-shot-classification",
model="mjwong/multilingual-e5-large-instruct-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-large-instruct-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)
✨ 主要特性
- 多语言支持:支持多种语言,包括英语、阿拉伯语、保加利亚语等。
- 零样本分类:可以对未在训练集中出现的类别进行分类。
- 自然语言推理:适用于自然语言推理任务。
📦 安装指南
文档未提及安装步骤,可根据使用的深度学习框架(如Transformers、PyTorch等)的官方文档进行安装。
💻 使用示例
基础用法
from transformers import pipeline
classifier = pipeline("zero-shot-classification",
model="mjwong/multilingual-e5-large-instruct-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)
高级用法
candidate_labels = ["politics", "economy", "entertainment", "environment"]
classifier(sequence_to_classify, candidate_labels, multi_label=True)
📚 详细文档
评估结果
模型在15种语言的XNLI测试集上进行了评估,使用的指标为准确率。结果如下:
模型还在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.19.2
- Tokenizers 0.12.1
🔧 技术细节
模型基于论文Text Embeddings by Weakly-Supervised Contrastive Pre-training进行开发,作者为Liang Wang、Nan Yang、Xiaolong Huang等,发表于arXiv 2022。
📄 许可证
本模型使用MIT许可证。
属性 |
详情 |
模型类型 |
多语言微调模型 |
训练数据 |
XNLI和ANLI数据集 |