ONNX 模型库
返回模型

说明文档

多语言 mDeBERTa-v3-base-mnli-xnli

模型描述

该多语言模型可以在100种语言上执行自然语言推理(NLI),因此也适用于多语言零样本分类。该底层模型由微软在 CC100 多语言数据集 上进行预训练。随后在 XNLI 数据集 上进行微调,该数据集包含来自15种语言的假设-前提对,以及英文 MNLI 数据集

截至2021年12月,mDeBERTa-base 是性能最佳的多语言基础尺寸 Transformer 模型,由微软在 这篇论文 中提出。

如果您需要更小、更快(但性能较低)的模型,可以尝试 multilingual-MiniLMv2-L6-mnli-xnli

如何使用该模型

简单的零样本分类管道

from transformers import pipeline
classifier = pipeline("zero-shot-classification", model="MoritzLaurer/mDeBERTa-v3-base-mnli-xnli")

sequence_to_classify = "Angela Merkel ist eine Politikerin in Deutschland und Vorsitzende der CDU"
candidate_labels = ["politics", "economy", "entertainment", "environment"]
output = classifier(sequence_to_classify, candidate_labels, multi_label=False)
print(output)

NLI 使用场景

from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")

model_name = "MoritzLaurer/mDeBERTa-v3-base-mnli-xnli"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)

premise = "Angela Merkel ist eine Politikerin in Deutschland und Vorsitzende der CDU"
hypothesis = "Emmanuel Macron is the President of France"

input = tokenizer(premise, hypothesis, truncation=True, return_tensors="pt")
output = model(input["input_ids"].to(device))  # device = "cuda:0" or "cpu"
prediction = torch.softmax(output["logits"][0], -1).tolist()
label_names = ["entailment", "neutral", "contradiction"]
prediction = {name: round(float(pred) * 100, 1) for pred, name in zip(prediction, label_names)}
print(prediction)

训练数据

该模型在 XNLI 开发数据集和 MNLI 训练数据集上进行训练。XNLI 开发集包含2490篇从英语专业翻译成其他14种语言的文本(总共37350篇文本)(参见 这篇论文)。请注意,XNLI 包含15种语言的 MNLI 数据集的机器翻译版本训练集,但由于这些机器翻译存在质量问题,该模型仅在 XNLI 开发集的专业翻译和原始英文 MNLI 训练集上进行训练(392702篇文本)。不使用机器翻译文本可以避免模型对15种语言过拟合;避免灾难性遗忘 mDeBERTa 预训练时学习的其他85种语言;并显著降低训练成本。

训练过程

mDeBERTa-v3-base-mnli-xnli 使用 Hugging Face trainer 进行训练,超参数如下:

training_args = TrainingArguments(
    num_train_epochs=2,              # 训练总轮数
    learning_rate=2e-05,
    per_device_train_batch_size=16,   # 训练时每个设备的批次大小
    per_device_eval_batch_size=16,    # 评估时的批次大小
    warmup_ratio=0.1,                # 学习率调度器的预热步数比例
    weight_decay=0.06,               # 权重衰减强度
)

评估结果

该模型在15种语言的 XNLI 测试集上进行评估(每种语言5010篇文本,总共75150篇)。请注意,多语言 NLI 模型能够在未接受特定语言 NLI 训练数据的情况下对 NLI 文本进行分类(跨语言迁移)。这意味着该模型也能够在 mDeBERTa 训练过的其他85种语言上进行 NLI,但性能很可能低于 XNLI 中可用的语言。

另外请注意,如果模型中心上的其他多语言模型声称在英语以外的语言上达到约90%的性能,作者很可能在测试过程中犯了错误,因为最新的论文中没有一篇显示在 XNLI 上的多语言平均性能超过80%几个百分点(参见 这里这里)。

平均 ar bg de el en es fr hi ru sw th tr ur vi zh
0.808 0.802 0.829 0.825 0.826 0.883 0.845 0.834 0.771 0.813 0.748 0.793 0.807 0.740 0.795 0.8116

局限性和偏见

请参阅原始 DeBERTa-V3 论文和不同 NLI 数据集的相关文献以了解潜在偏见。

引用

如果您使用该模型,请引用:Laurer, Moritz, Wouter van Atteveldt, Andreu Salleras Casas, and Kasper Welbers. 2022. 'Less Annotating, More Classifying – Addressing the Data Scarcity Issue of Supervised Machine Learning with Deep Transfer Learning and BERT - NLI'. Preprint, June. Open Science Framework. https://osf.io/74b8k.

合作想法或问题?

如果您有问题或合作想法,请通过 m{dot}laurer{at}vu{dot}nl 或 LinkedIn 联系我

调试和问题

请注意,DeBERTa-v3 于2021年底发布,旧版本的 HF Transformers 似乎在运行该模型时存在问题(例如导致分词器问题)。使用 Transformers>=4.13 或更高版本可能会解决一些问题。请注意,mDeBERTa 目前不支持 FP16,请参阅:https://github.com/microsoft/DeBERTa/issues/77

MaagDeveloper/MoritzLaurer-mDeBERTa-v3-base-mnli-xnli

作者 MaagDeveloper

zero-shot-classification
↓ 1 ♥ 0

创建时间: 2025-05-11 15:10:59+00:00

更新时间: 2025-05-11 15:12:35+00:00

在 Hugging Face 上查看

文件 (12)

.gitattributes
README.md
added_tokens.json
config.json
model.safetensors
onnx/model.onnx ONNX
onnx/model_quantized.onnx ONNX
pytorch_model.bin
special_tokens_map.json
spm.model
tokenizer.json
tokenizer_config.json