模型概述
模型特點
模型能力
使用案例
🚀 mDeBERTa-v3-base-xnli-multilingual-nli-2mil7模型
mDeBERTa-v3-base-xnli-multilingual-nli-2mil7是一個多語言模型,能夠在100種語言上執行自然語言推理(NLI)任務,適用於多語言零樣本分類。該模型基於mDeBERTa-v3-base預訓練模型,在多語言數據集上微調得到,具有廣泛的語言適應性和良好的性能。
🚀 快速開始
簡單的零樣本分類管道
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 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)
✨ 主要特性
- 多語言支持:該模型可以在100種語言上執行自然語言推理(NLI)任務,適用於多語言零樣本分類。
- 高性能:mDeBERTa-v3-base是微軟推出的表現最佳的多語言基礎尺寸Transformer模型。
- 豐富的訓練數據:模型在多個數據集上進行了微調,包括XNLI數據集和multilingual-NLI-26lang-2mil7數據集,這些數據集包含了超過270萬個假設 - 前提對,涵蓋27種語言。
📦 安裝指南
文檔未提及安裝步驟,故跳過此章節。
💻 使用示例
基礎用法
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)
高級用法
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 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)
📚 詳細文檔
模型描述
該多語言模型可以在100種語言上執行自然語言推理(NLI)任務,因此也適用於多語言零樣本分類。基礎的mDeBERTa-v3-base模型由微軟在包含100種語言的CC100多語言數據集上進行預訓練。然後,該模型在XNLI數據集和multilingual-NLI-26lang-2mil7數據集上進行了微調。這兩個數據集包含超過270萬個假設 - 前提對,涵蓋27種語言,使用人口超過40億。
截至2021年12月,mDeBERTa-v3-base是微軟在這篇論文中推出的表現最佳的多語言基礎尺寸Transformer模型。
訓練數據
該模型在multilingual-nli-26lang-2mil7數據集和XNLI驗證數據集上進行訓練。
multilingual-nli-26lang-2mil7數據集包含273萬個NLI假設 - 前提對,涵蓋26種語言,使用人口超過40億。每個語言包含10.5萬個文本對。該數據集基於英文數據集MultiNLI、Fever-NLI、ANLI、LingNLI和WANLI,並使用最新的開源機器翻譯模型創建。數據集中的語言包括:['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語言代碼)。更多詳細信息,請參閱datasheet。此外,按照與其他語言相同的採樣方法,為英語添加了10.5萬個文本對,使語言總數達到27種。
此外,對於每種語言,還添加了10%的隨機假設 - 前提對,其中英語假設與其他語言的前提配對(英語前提與其他語言假設同理)。這種文本對中的語言混合應該使用戶能夠為另一種語言的目標文本用英語制定假設。
XNLI驗證集由2490篇從英語專業翻譯為其他14種語言的文本組成(總共37350篇文本)(見這篇論文)。請注意,XNLI還包含一個由MultiNLI數據集的14種機器翻譯版本組成的訓練集,涵蓋14種語言,但由於2018年機器翻譯的質量問題,該數據被排除在外。
請注意,為了評估目的,從XNLI訓練數據中排除了三種語言,僅將其包含在測試數據中:["bg","el","th"]。這樣做是為了測試模型在NLI微調期間未見過的語言上的性能,這些語言僅在100種語言的預訓練期間見過 - 見下面的評估指標。
總訓練數據集包含3287280個假設 - 前提對。
訓練過程
mDeBERTa-v3-base-mnli-xnli使用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
gradient_accumulation_steps=2, # to double the effective batch size for
warmup_ratio=0.06, # number of warmup steps for learning rate scheduler
weight_decay=0.01, # strength of weight decay
fp16=False
)
評估結果
該模型在XNLI測試集的15種語言(每種語言5010篇文本,總共75150篇)以及MultiNLI、Fever-NLI、ANLI、LingNLI和WANLI的英文測試集上進行了評估。請注意,多語言NLI模型能夠在未接受特定語言NLI訓練數據的情況下對NLI文本進行分類(跨語言遷移)。這意味著該模型也能夠在mDeBERTa預訓練的其他73種語言上進行NLI,但性能很可能低於在27種語言上進行NLI微調時見過的語言。下表中["bg","el","th"]語言的性能很好地表明瞭這種跨語言遷移,因為這些語言在NLI微調期間未被包含在訓練數據中,但僅在100種語言的預訓練期間見過。
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 |
英文數據集 | MultiNLI測試匹配集(mnli_test_m) | MultiNLI測試不匹配集(mnli_test_mm) | ANLI測試集(anli_test) | ANLI測試集r3(anli_test_r3) | Fever測試集(fever_test) | Ling測試集(ling_test) | WANLI測試集(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%高出幾個百分點(見這裡或這裡)。
🔧 技術細節
文檔未提供具體的技術實現細節,故跳過此章節。
📄 許可證
本項目採用MIT許可證。
⚠️ 侷限性和偏差
請參考原始的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。



