🚀 DeBERTa-v3-base-mnli-fever-docnli-ling-2c
该模型主要用于文本分类和零样本分类任务。它基于多个自然语言推理(NLI)数据集进行训练,能有效预测“蕴含”或“非蕴含”关系,在相关任务中表现出色。
🚀 快速开始
本模型可用于简单的零样本分类任务,也能处理自然语言推理(NLI)相关用例。以下是使用示例:
💻 使用示例
基础用法
from transformers import pipeline
classifier = pipeline("zero-shot-classification", model="MoritzLaurer/DeBERTa-v3-base-mnli-fever-docnli-ling-2c")
sequence_to_classify = "Angela Merkel is a politician in Germany and leader of the CDU"
candidate_labels = ["politics", "economy", "entertainment", "environment"]
output = classifier(sequence_to_classify, candidate_labels, multi_label=False)
print(output)
高级用法
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
model_name = "MoritzLaurer/DeBERTa-v3-base-mnli-fever-docnli-ling-2c"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
premise = "I first thought that I liked the movie, but upon second thought it was actually disappointing."
hypothesis = "The movie was good."
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", "not_entailment"]
prediction = {name: round(float(pred) * 100, 1) for pred, name in zip(prediction, label_names)}
print(prediction)
✨ 主要特性
- 该模型是模型中心唯一在8个NLI数据集上训练的模型,其中包括包含长文本的DocNLI,可学习长距离推理。
- 基于Microsoft的DeBERTa-v3-base模型,其v3变体通过不同的预训练目标显著优于之前的版本。
- 模型在二分类NLI任务上进行训练,可预测“蕴含”或“非蕴含”关系。
📦 安装指南
文档未提及具体安装步骤,可参考Hugging Face的相关文档进行安装。
📚 详细文档
模型描述
该模型基于8个NLI数据集的1279665个假设 - 前提对进行训练,这些数据集包括MultiNLI、Fever-NLI、LingNLI和DocNLI(其中包括ANLI、QNLI、DUC、CNN/DailyMail、Curation)。
基础模型是Microsoft的DeBERTa-v3-base。DeBERTa的v3变体通过不同的预训练目标显著优于之前的版本,具体可参考原始DeBERTa论文的附录11以及DeBERTa-V3论文。
若追求更高性能(但速度较慢),建议使用https://huggingface.co/MoritzLaurer/DeBERTa-v3-large-mnli-fever-anli-ling-wanli。
训练数据
该模型基于8个NLI数据集的1279665个假设 - 前提对进行训练,这些数据集包括MultiNLI、Fever-NLI、LingNLI和DocNLI(其中包括ANLI、QNLI、DUC、CNN/DailyMail、Curation)。
训练过程
DeBERTa-v3-small-mnli-fever-docnli-ling-2c使用Hugging Face训练器进行训练,超参数如下:
training_args = TrainingArguments(
num_train_epochs=3, # total number of training epochs
learning_rate=2e-05,
per_device_train_batch_size=32, # batch size per device during training
per_device_eval_batch_size=32, # batch size for evaluation
warmup_ratio=0.1, # number of warmup steps for learning rate scheduler
weight_decay=0.06, # strength of weight decay
fp16=True # mixed precision training
)
评估结果
该模型使用MultiNLI和ANLI的二分类测试集以及Fever-NLI的二分类开发集进行评估(两个类别而非三个),使用的指标是准确率。
数据集 |
准确率 |
mnli-m-2c |
0.935 |
mnli-mm-2c |
0.933 |
fever-nli-2c |
0.897 |
anli-all-2c |
0.710 |
anli-r3-2c |
0.678 |
lingnli-2c |
0.895 |
🔧 技术细节
- 模型在二分类NLI任务上进行训练,将DocNLI数据集中的“中立”和“矛盾”类别合并为“非蕴含”类别。
- 使用Hugging Face训练器进行训练,设置了特定的超参数,如训练轮数、学习率、批次大小等。
📄 许可证
本模型使用MIT许可证。
局限性和偏差
请参考原始DeBERTa论文和不同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年12月6日发布,较旧版本的HF Transformers在运行该模型时可能会出现问题(例如分词器问题)。使用Transformers >= 4.13可能会解决一些问题。