🚀 drama-large-xnli-anli
本模型是 facebook/drama-large 在XNLI和ANLI数据集上的微调版本。它可用于零样本分类任务,支持多种语言,为跨语言的文本分类提供了强大的解决方案。
🚀 快速开始
模型描述
DRAMA: Diverse Augmentation from Large Language Models to Smaller Dense Retrievers。
Xueguang Ma, Xi Victoria Lin, Barlas Oguz, Jimmy Lin, Wen - tau Yih, Xilun Chen, arXiv 2025
如何使用模型
零样本分类管道
可以使用 zero-shot-classification
管道加载模型,示例代码如下:
from transformers import AutoTokenizer, pipeline
model = "mjwong/drama-large-xnli-anli"
classifier = pipeline("zero-shot-classification",
model=model)
然后可以使用此管道将序列分类到指定的任何类别名称中。
sequence_to_classify = "one day I will see the world"
candidate_labels = ['travel', 'cooking', 'dancing']
classifier(sequence_to_classify, candidate_labels)
如果多个候选标签都可能正确,可以传递 multi_class=True
来独立计算每个类别:
candidate_labels = ['travel', 'cooking', 'dancing', 'exploration']
classifier(sequence_to_classify, candidate_labels, multi_class=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/drama-large-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测试集评估
该模型使用XNLI测试集在15种语言上进行了评估,评估指标为准确率。
数据集 |
英语 (en) |
阿拉伯语 (ar) |
保加利亚语 (bg) |
德语 (de) |
希腊语 (el) |
西班牙语 (es) |
法语 (fr) |
印地语 (hi) |
俄语 (ru) |
斯瓦希里语 (sw) |
泰语 (th) |
土耳其语 (tr) |
乌尔都语 (ur) |
越南语 (vi) |
中文 (zh) |
drama-base-xnli-anli |
0.788 |
0.689 |
0.708 |
0.715 |
0.696 |
0.732 |
0.737 |
0.647 |
0.711 |
0.636 |
0.676 |
0.664 |
0.588 |
0.708 |
0.710 |
drama-large-xnli-anli |
0.799 |
0.698 |
0.730 |
0.721 |
0.717 |
0.754 |
0.754 |
0.649 |
0.718 |
0.652 |
0.678 |
0.656 |
0.594 |
0.719 |
0.719 |
MultiNLI开发集和ANLI测试集评估
该模型还使用MultiNLI开发集和ANLI测试集进行了评估,评估指标为准确率。
🔧 技术细节
训练超参数
训练期间使用了以下超参数:
- 学习率(learning_rate):2e - 05
- 训练批次大小(train_batch_size):16
- 评估批次大小(eval_batch_size):16
- 随机种子(seed):42
- 优化器(optimizer):Adam,其中betas = (0.9, 0.999),epsilon = 1e - 08
- 学习率调度器类型(lr_scheduler_type):线性
- 学习率调度器预热比例(lr_scheduler_warmup_ratio):0.1
框架版本
- Transformers:4.49.0
- Pytorch:2.6.0 + cu124
- Datasets:3.2.0
- Tokenizers:0.21.0
📄 许可证
本模型使用CC - BY - NC - 4.0许可证。
📦 数据集
🛠️ 任务类型
零样本分类(zero - shot - classification)
📋 模型信息
属性 |
详情 |
模型类型 |
drama - large - xnli - anli |
基础模型 |
facebook/drama - large |
支持语言 |
多语言(英语、阿拉伯语、保加利亚语、德语、希腊语、西班牙语、法语、印地语、俄语、斯瓦希里语、泰语、土耳其语、乌尔都语、越南语、中文) |