ONNX 模型库
返回模型

说明文档

I detect translation intent — straightforward language conversion task. My approach: translate directly while preserving all formatting.

Here is the Chinese (Simplified) translation:


mDeBERTa-v3-base-xnli-multilingual-nli-2mil7 模型卡片

模型描述

该多语言模型可对100种语言进行自然语言推理(NLI),因此也适用于多语言零样本分类。底层的 mDeBERTa-v3-base 模型由 Microsoft 在 CC100 多语言数据集 上预训练,该数据集包含100种语言。随后,该模型在 XNLI 数据集multilingual-NLI-26lang-2mil7 数据集 上进行了微调。这两个数据集包含超过27种语言、超过40亿人使用的语言的超过270万个假设-前提文本对。

截至2021年12月,mDeBERTa-v3-base 是 Microsoft 在此论文中推出的性能最佳的多语言基础-sized transformer 模型。

如何使用模型

简单的零样本分类管道

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-xnli-multilingual-nli-2mil7"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)

premise = "Angela Merkel ist eine政治家 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)

训练数据

该模型在 multilingual-nli-26lang-2mil7 数据集XNLI 验证数据集上训练。

multilingual-nli-26lang-2mil7 数据集包含26种语言、超过40亿人使用的语言的273万个NLI假设-前提文本对。每种语言包含105,000个文本对。该数据集基于英文数据集 MultiNLIFever-NLIANLILingNLIWANLI,使用最新的开源机器翻译模型创建。数据集中的语言包括:['ar', 'bn', 'de', 'es', 'fa', 'fr', 'he', 'hi', 'id', 'it', 'ja', 'ko', 'mr', 'nl', 'pl', 'ps', 'pt', 'ru', 'sv', 'sw', 'ta', 'tr', 'uk', 'ur', 'vi', 'zh'](见 ISO 语言代码)。详情请参阅数据表。此外,按照与其他语言相同的采样方法,也为英语添加了105,000个文本对样本,共计27种语言。

此外,对于每种语言,还随机添加了10%的假设-前提文本对,其中英语假设与另一种语言的前提配对(英语前提与另一种语言假设同理)。这种文本对中的语言混合使用户能够用英语为目标语言编写假设。

XNLI 验证集包含从英语专业翻译成其他14种语言的2490个文本(共计37,350个文本)(见此论文)。请注意,XNLI 还包含一个训练集,为14种语言提供14个机器翻译版本的 MultiNLI 数据集,但由于2018年机器翻译的质量问题,这些数据被排除在外。

请注意,为了评估目的,XNLI 训练数据中排除了三种语言 ["bg","el","th"],仅将其包含在测试数据中。这样做是为了测试模型在 NLI 微调时未见过、仅在预训练时见过(100种语言)的语言上的性能——见下面的评估指标。

训练数据集的总量为3,287,280个假设-前提文本对。

训练过程

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

training_args = TrainingArguments(
    num_train_epochs=3,              # 总训练轮数
    learning_rate=2e-05,
    per_device_train_batch_size=32,   # 训练时每个设备的批次大小
    gradient_accumulation_steps=2,   # 以加倍有效批次大小
    warmup_ratio=0.06,                # 学习率调度器的预热步数
    weight_decay=0.01,               # 权重衰减强度
    fp16=False
)

评估结果

该模型在15种语言的 XNLI 测试集(每种语言5010个文本,共75,150个)以及 MultiNLIFever-NLIANLILingNLIWANLI 的英文测试集上进行了评估。请注意,多语言 NLI 模型能够在不接收特定语言 NLI 训练数据的情况下对 NLI 文本进行分类(跨语言迁移)。这意味着该模型还能够对其余73种 mDeBERTa 预训练的语言进行 NLI,但性能可能低于 NLI 微调时见过的语言。下表中语言 ["bg","el","th"] 的性能很好地说明了这种跨语言迁移,因为这些语言未包含在训练数据中。

XNLI 子集 ar bg de el en es fr hi ru sw th tr ur vi zh
准确率 0.794 0.822 0.824 0.809 0.871 0.832 0.823 0.769 0.803 0.746 0.786 0.792 0.744 0.793 0.803
速度 (文本/秒, A100-GPU) 1344.0 1355.0 1472.0 1149.0 1697.0 1446.0 1278.0 1115.0 1380.0 1463.0 1713.0 1594.0 1189.0 877.0 1887.0
英文数据集 mnli_test_m mnli_test_mm anli_test anli_test_r3 fever_test ling_test wanli_test
准确率 0.857 0.856 0.537 0.497 0.761 0.788 0.732
速度 (文本/秒, A100-GPU) 1000.0 1009.0 794.0 672.0 374.0 1177.0 1468.0

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

局限性与偏见

请参阅原始 DeBERTa-V3 论文及关于不同 NLI 数据集的文献以了解潜在偏见。此外,请注意 multilingual-nli-26lang-2mil7 数据集是使用机器翻译创建的,这降低了复杂任务如 NLI 的数据质量。您可以通过 Hugging Face 数据集查看器 查看感兴趣的语言的数据。请注意,机器翻译引入的语法错误对于零样本分类影响较小,因为语法对其不那么重要。

引用

如果该数据集对您有帮助,请引用以下文章:

@article{laurer_less_2022,
	title = {Less {Annotating}, {More} {Classifying} – {Addressing} the {Data} {Scarcity} {Issue} of {Supervised} {Machine} {Learning} with {Deep} {Transfer} {Learning} and {BERT} - {NLI}},
	url = {https://osf.io/74b8k},
	language = {en-us},
	urldate = {2022-07-28},
	journal = {Preprint},
	author = {Laurer, Moritz and Atteveldt, Wouter van and Casas, Andreu Salleras and Welbers, Kasper},
	month = jun,
	year = {2022},
	note = {Publisher: Open Science Framework},
}

合作想法或问题?

如需获取新模型和数据集的最新动态,请在 Twitter 上关注我。 如果您有问题或合作想法,请通过 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


(Note: I kept the code blocks and technical terms in their original form as is standard practice for technical translations, only translating the descriptive text.)

MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7

作者 MoritzLaurer

zero-shot-classification transformers
↓ 184.7K ♥ 351

创建时间: 2022-08-22 16:59:35+00:00

更新时间: 2024-04-11 13:49:19+00:00

在 Hugging Face 上查看

文件 (13)

.gitattributes
LICENSE
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