🚀 DeBERTa-v3-base-mnli-fever-anli
該模型在文本分類和零樣本分類任務中表現出色,基於特定數據集訓練,能有效處理自然語言推理問題,為相關領域研究和應用提供了有力支持。
🚀 快速開始
簡單的零樣本分類管道
from transformers import pipeline
classifier = pipeline("zero-shot-classification", model="MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli")
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)
NLI使用案例
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-anli"
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", "neutral", "contradiction"]
prediction = {name: round(float(pred) * 100, 1) for pred, name in zip(prediction, label_names)}
print(prediction)
✨ 主要特性
- 該模型在MultiNLI、Fever - NLI和Adversarial - NLI (ANLI)數據集上進行訓練,包含763913個NLI假設 - 前提對。
- 此基礎模型在ANLI基準測試中幾乎優於所有大型模型。
- 基礎模型是微軟的DeBERTa - v3 - base,DeBERTa的v3變體通過不同的預訓練目標,顯著優於該模型的先前版本。
📦 安裝指南
在使用模型前,你需要安裝transformers
庫,可使用以下命令進行安裝:
💻 使用示例
基礎用法
from transformers import pipeline
classifier = pipeline("zero-shot-classification", model="MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli")
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-anli"
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", "neutral", "contradiction"]
prediction = {name: round(float(pred) * 100, 1) for pred, name in zip(prediction, label_names)}
print(prediction)
📚 詳細文檔
訓練數據
DeBERTa - v3 - base - mnli - fever - anli在MultiNLI、Fever - NLI和Adversarial - NLI (ANLI)數據集上進行訓練,這些數據集包含763913個NLI假設 - 前提對。
訓練過程
DeBERTa - v3 - base - mnli - fever - anli使用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 |
mnli - mm |
fever - nli |
anli - all |
anli - r3 |
0.903 |
0.903 |
0.777 |
0.579 |
0.495 |
🔧 技術細節
該模型基於微軟的DeBERTa - v3 - base
,其v3變體通過不同的預訓練目標,顯著優於該模型的先前版本。具體可參考原始DeBERTa論文的附錄11。
📄 許可證
本項目採用MIT許可證。
⚠️ 重要提示
請參考原始DeBERTa論文和不同NLI數據集的相關文獻,以瞭解潛在的偏差。