语言:
- 多语言
- 英语
- 阿拉伯语
- 保加利亚语
- 德语
- 希腊语
- 西班牙语
- 法语
- 印地语
- 俄语
- 斯瓦希里语
- 泰语
- 土耳其语
- 乌尔都语
- 越南语
- 中文
许可证: cc-by-nc-4.0
数据集:
- xnli
- facebook/anli
管道标签: 零样本分类
基础模型: facebook/drama-large
模型索引:
- 名称: drama-large-xnli-anli
结果: []
drama-large-xnli-anli
该模型是基于facebook/drama-large在XNLI和ANLI数据集上微调的版本。
模型描述
DRAMA: 利用大型语言模型为小型密集检索器提供多样化增强。
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 = "总有一天我会环游世界"
candidate_labels = ['旅行', '烹饪', '舞蹈']
classifier(sequence_to_classify, candidate_labels)
如果多个候选标签可能正确,传递multi_class=True
以独立计算每个类别:
candidate_labels = ['旅行', '烹饪', '舞蹈', '探险']
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 = "但我以为你发誓不喝咖啡了。"
hypothesis = "我以为你发誓要多喝咖啡。"
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 = ["蕴含", "中立", "矛盾"]
prediction = {name: round(float(pred) * 100, 2) for pred, name in zip(prediction, label_names)}
print(prediction)
评估结果
该模型在15种语言的XNLI测试集上进行了评估:英语(en)、阿拉伯语(ar)、保加利亚语(bg)、德语(de)、希腊语(el)、西班牙语(es)、法语(fr)、印地语(hi)、俄语(ru)、斯瓦希里语(sw)、泰语(th)、土耳其语(tr)、乌尔都语(ur)、越南语(vi)和中文(zh)。使用的指标是准确率。
数据集 |
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的测试集上进行了评估。使用的指标是准确率。
训练超参数
训练期间使用了以下超参数:
- 学习率: 2e-05
- 训练批次大小: 16
- 评估批次大小: 16
- 随机种子: 42
- 优化器: Adam,betas=(0.9,0.999),epsilon=1e-08
- 学习率调度器类型: 线性
- 学习率调度器预热比例: 0.1
框架版本
- Transformers 4.49.0
- Pytorch 2.6.0+cu124
- Datasets 3.2.0
- Tokenizers 0.21.0