このリポジトリは、 DeBERTa : Decoding -enhanced BERT with Disentangled AttentionおよびDeBERTa V3: Improving DeBERTa using ELECTRA-Style Pre-Training with Gradient-Disentangled Embedding Sharing の公式実装です。
DeBERTa v2 コードと900M、1.5Bモデルがここにあります。これには、SuperGLUE 単一モデルの提出に使用され、人間のベースライン 89.8 に対して 89.9 を達成した 1.5B モデルが含まれます。この申請に関する詳細については、ブログをご覧ください。
DeBERTa 1.5B モデルでは、SuperGLUE リーダーボードで T5 11B モデルと人間のパフォーマンスを上回りました。コードとモデルは近日公開予定です。詳細については、論文をご覧ください。
論文内の実験結果の一部を再現するために、事前トレーニングされたモデル、ソースコード、および微調整スクリプトをリリースしました。同様のスクリプトに従って、 DeBERTa独自の実験やアプリケーションに適用できます。事前トレーニング スクリプトは次のステップでリリースされます。
DeBERTa (デコーディング強化された BERT とデエンタングルド アテンション) は、2 つの新しい技術を使用して BERT モデルと RoBERTa モデルを改善します。 1 つ目は、解きほぐされたアテンション メカニズムです。このメカニズムでは、各単語は、その内容と位置をそれぞれエンコードする 2 つのベクトルを使用して表現され、単語間のアテンションの重みは、内容と相対位置に関する解きほぐされた行列を使用して計算されます。次に、強化されたマスク デコーダを使用して出力ソフトマックス レイヤーを置き換え、モデルの事前トレーニング用のマスクされたトークンを予測します。これら 2 つの手法により、モデルの事前トレーニングの効率と下流タスクのパフォーマンスが大幅に向上することを示します。
事前トレーニングされたモデルは zip ファイルにパッケージ化されています。これらはリリースからダウンロードすることも、以下のリンクから個別のモデルをダウンロードすることもできます。
モデル | 語彙(K) | バックボーンパラメータ(M) | 隠しサイズ | レイヤー | 注記 |
---|---|---|---|---|---|
V2-XX大1 | 128 | 1320 | 1536年 | 48 | 128K の新しい SPM 語彙 |
V2-XLarge | 128 | 710 | 1536年 | 24 | 128K の新しい SPM 語彙 |
特大 | 50 | 700 | 1024 | 48 | RoBERTaと同じ語彙 |
大きい | 50 | 350 | 1024 | 24 | RoBERTaと同じ語彙 |
ベース | 50 | 100 | 768 | 12 | RoBERTaと同じ語彙 |
V2-XXLarge-MNLI | 128 | 1320 | 1536年 | 48 | MNLIで微調整 |
V2-XLarge-MNLI | 128 | 710 | 1536年 | 24 | MNLIで微調整 |
XLarge-MNLI | 50 | 700 | 1024 | 48 | MNLIで微調整 |
大規模MNLI | 50 | 350 | 1024 | 24 | MNLIで微調整 |
ベース-MNLI | 50 | 86 | 768 | 12 | MNLIで微調整 |
DeBERTa -V3-Large 2 | 128 | 304 | 1024 | 24 | 128K の新しい SPM 語彙 |
DeBERTa -V3-Base 2 | 128 | 86 | 768 | 12 | 128K の新しい SPM 語彙 |
DeBERTa -V3-Small 2 | 128 | 44 | 768 | 6 | 128K の新しい SPM 語彙 |
DeBERTa -V3-XSmall 2 | 128 | 22 | 384 | 12 | 128K の新しい SPM 語彙 |
m DeBERTa -V3-Base 2 | 250 | 86 | 768 | 12 | 250K の新しい SPM 語彙、102 言語の多言語モデル |
ドキュメントを読む
コードを試す方法はいくつかありますが、
コードを実行するには Docker が推奨される方法です。すべての依存関係が既に docker Bagai/ DeBERTaに組み込まれており、docker 公式サイトに従ってマシンに docker をインストールできます。
docker で実行するには、システムが上記のリストの要件を満たしていることを確認してください。 GLUE 実験を試す手順は次のとおりです。コードをプルして./run_docker.sh
を実行すると、 / DeBERTa /experiments/glue/
で bash コマンドを実行できます。
コードをプルし、コードのルート ディレクトリでpip3 install -r requirements.txt
を実行します。次に、コードのexperiments/glue/
フォルダーに入り、そのフォルダーで Glue 実験用の bash コマンドを試します。
pip install DeBERTa
# To apply DeBERTa to your existing code, you need to make two changes to your code,
# 1. change your model to consume DeBERTa as the encoder
from DeBERTa import DeBERTa
import torch
class MyModel ( torch . nn . Module ):
def __init__ ( self ):
super (). __init__ ()
# Your existing model code
self . DeBERTa = DeBERTa . DeBERTa ( pre_trained = 'base' ) # Or 'large' 'base-mnli' 'large-mnli' 'xlarge' 'xlarge-mnli' 'xlarge-v2' 'xxlarge-v2'
# Your existing model code
# do inilization as before
#
self . DeBERTa . apply_state () # Apply the pre-trained model of DeBERTa at the end of the constructor
#
def forward ( self , input_ids ):
# The inputs to DeBERTa forward are
# `input_ids`: a torch.LongTensor of shape [batch_size, sequence_length] with the word token indices in the vocabulary
# `token_type_ids`: an optional torch.LongTensor of shape [batch_size, sequence_length] with the token types indices selected in [0, 1].
# Type 0 corresponds to a `sentence A` and type 1 corresponds to a `sentence B` token (see BERT paper for more details).
# `attention_mask`: an optional parameter for input mask or attention mask.
# - If it's an input mask, then it will be torch.LongTensor of shape [batch_size, sequence_length] with indices selected in [0, 1].
# It's a mask to be used if the input sequence length is smaller than the max input sequence length in the current batch.
# It's the mask that we typically use for attention when a batch has varying length sentences.
# - If it's an attention mask then if will be torch.LongTensor of shape [batch_size, sequence_length, sequence_length].
# In this case, it's a mask indicating which tokens in the sequence should be attended by other tokens in the sequence.
# `output_all_encoded_layers`: whether to output results of all encoder layers, default, True
encoding = DeBERTa . bert ( input_ids )[ - 1 ]
# 2. Change your tokenizer with the tokenizer built-in DeBERTa
from DeBERTa import DeBERTa
vocab_path , vocab_type = DeBERTa . load_vocab ( pretrained_id = 'base' )
tokenizer = DeBERTa . tokenizers [ vocab_type ]( vocab_path )
# We apply the same schema of special tokens as BERT, e.g. [CLS], [SEP], [MASK]
max_seq_len = 512
tokens = tokenizer . tokenize ( 'Examples input text of DeBERTa ' )
# Truncate long sequence
tokens = tokens [: max_seq_len - 2 ]
# Add special tokens to the `tokens`
tokens = [ '[CLS]' ] + tokens + [ '[SEP]' ]
input_ids = tokenizer . convert_tokens_to_ids ( tokens )
input_mask = [ 1 ] * len ( input_ids )
# padding
paddings = max_seq_len - len ( input_ids )
input_ids = input_ids + [ 0 ] * paddings
input_mask = input_mask + [ 0 ] * paddings
features = {
'input_ids' : torch . tensor ( input_ids , dtype = torch . int ),
'input_mask' : torch . tensor ( input_mask , dtype = torch . int )
}
接着作業の場合は、
cache_dir=/tmp/ DeBERTa /
cd experiments/glue
./download_data.sh $cache_dir /glue_tasks
task=STS-B
OUTPUT=/tmp/ DeBERTa /exps/ $task
export OMP_NUM_THREADS=1
python3 -m DeBERTa .apps.run --task_name $task --do_train
--data_dir $cache_dir /glue_tasks/ $task
--eval_batch_size 128
--predict_batch_size 128
--output_dir $OUTPUT
--scale_steps 250
--loss_scale 16384
--accumulative_update 1
--num_train_epochs 6
--warmup 100
--learning_rate 2e-5
--train_batch_size 32
--max_seq_len 128
$HOME/.~ DeBERTa
にキャッシュされます。ダウンロードが予期せず失敗した場合は、クリーンアップする必要がある場合があります。微調整実験は、8x32 V100 GPU カードを搭載した DGX-2 ノードの半分で実行されます。結果は、GPU モデル、ドライバー、CUDA SDK バージョン、FP16 または FP32 の使用、およびランダム シードの違いによって異なる場合があります。ここでは、異なるランダム シードを使用した複数の実行に基づいて数値を報告します。大規模モデルの結果は次のとおりです。
タスク | 指示 | 結果 | 実行時間(8x32G V100 GPU) |
---|---|---|---|
MNLI xxlarge v2 | experiments/glue/mnli.sh xxlarge-v2 | 91.7/91.9 +/-0.1 | 4時間 |
MNLI xlarge v2 | experiments/glue/mnli.sh xlarge-v2 | 91.7/91.6 +/-0.1 | 2.5時間 |
MNLI エクスラージ | experiments/glue/mnli.sh xlarge | 91.5/91.2 +/-0.1 | 2.5時間 |
MNLI大 | experiments/glue/mnli.sh large | 91.3/91.1 +/-0.1 | 2.5時間 |
QQP大 | experiments/glue/qqp.sh large | 92.3 +/-0.1 | 6時間 |
QNLI大 | experiments/glue/qnli.sh large | 95.3 +/-0.2 | 2時間 |
MRPC大 | experiments/glue/mrpc.sh large | 91.9 +/-0.5 | 0.5時間 |
RTE大 | experiments/glue/rte.sh large | 86.6 +/-1.0 | 0.5時間 |
SST-2大 | experiments/glue/sst2.sh large | 96.7 +/-0.3 | 1時間 |
STS-b 大 | experiments/glue/Stsb.sh large | 92.5 +/-0.3 | 0.5時間 |
CoLA大 | experiments/glue/cola.sh | 70.5 +/-1.0 | 0.5時間 |
そして、これがベースモデルの結果です
タスク | 指示 | 結果 | 実行時間(8x32G V100 GPU) |
---|---|---|---|
MNLIベース | experiments/glue/mnli.sh base | 88.8/88.5 +/-0.2 | 1.5時間 |
SQuAD 1.1/2.0 およびいくつかの GLUE ベンチマーク タスクに関する開発結果を紹介します。
モデル | 分隊 1.1 | スクワッド 2.0 | MNLI-m/mm | SST-2 | QNLI | コーラ | RTE | MRPC | QQP | STS-B |
---|---|---|---|---|---|---|---|---|---|---|
F1/EM | F1/EM | ACC | ACC | ACC | MCC | ACC | ACC/F1 | ACC/F1 | 追伸 | |
BERT-ラージ | 90.9/84.1 | 81.8/79.0 | 86.6/- | 93.2 | 92.3 | 60.6 | 70.4 | 88.0/- | 91.3/- | 90.0/- |
RoBERTa-Large | 94.6/88.9 | 89.4/86.5 | 90.2/- | 96.4 | 93.9 | 68.0 | 86.6 | 90.9/- | 92.2/- | 92.4/- |
XLNet-Large | 95.1/89.7 | 90.6/87.9 | 90.8/- | 97.0 | 94.9 | 69.0 | 85.9 | 90.8/- | 92.3/- | 92.5/- |
DeBERTa -大1 | 95.5/90.1 | 90.7/88.0 | 91.3/91.1 | 96.5 | 95.3 | 69.5 | 91.0 | 92.6/94.6 | 92.3/- | 92.8/92.5 |
DeBERTa -XLarge 1 | -/- | -/- | 91.5/91.2 | 97.0 | - | - | 93.1 | 92.1/94.3 | - | 92.9/92.7 |
DeBERTa -V2-XLarge 1 | 95.8/90.8 | 91.4/88.9 | 91.7/91.6 | 97.5 | 95.8 | 71.1 | 93.9 | 92.0/94.2 | 92.3/89.8 | 92.9/92.9 |
DeBERTa -V2-XXLarge 1,2 | 96.1/91.4 | 92.2/89.7 | 91.7/91.9 | 97.2 | 96.0 | 72.0 | 93.5 | 93.1/94.9 | 92.7/90.3 | 93.2/93.1 |
DeBERTa -V3-Large | -/- | 91.5/89.0 | 91.8/91.9 | 96.9 | 96.0 | 75.3 | 92.7 | 92.2/- | 93.0/- | 93.0/- |
DeBERTa -V3-Base | -/- | 88.4/85.4 | 90.6/90.7 | - | - | - | - | - | - | - |
DeBERTa -V3-Small | -/- | 82.9/80.4 | 88.3/87.7 | - | - | - | - | - | - | - |
DeBERTa -V3-XSmall | -/- | 84.8/82.0 | 88.1/88.3 | - | - | - | - | - | - | - |
ゼロショットクロスリンガル転送設定、つまり英語データのみを使用したトレーニング、他の言語でのテストを使用した開発結果を XNLI で示します。
モデル | 平均 | jp | フランス | エス | デ | エル | バックグラウンド | る | tr | あーる | ヴィ | 番目 | zh | こんにちは | スイス | あなた |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
XLM-Rベース | 76.2 | 85.8 | 79.7 | 80.7 | 78.7 | 77.5 | 79.6 | 78.1 | 74.2 | 73.8 | 76.5 | 74.6 | 76.7 | 72.4 | 66.5 | 68.3 |
m DeBERTa -V3-Base | 79.8 +/-0.2 | 88.2 | 82.6 | 84.4 | 82.7 | 82.3 | 82.4 | 80.8 | 79.5 | 78.5 | 78.1 | 76.4 | 79.5 | 75.9 | 73.9 | 72.4 |
MLM および RTD 目標を使用してDeBERTa事前トレーニングするには、 experiments/language_models
を確認してください。
He Pengcheng ([email protected])、Xiaodong Liu ([email protected])、Jianfeng Gao ([email protected])、Weizhu Chen ([email protected])
@misc{he2021 DeBERTa v3,
title={ DeBERTa V3: Improving DeBERTa using ELECTRA-Style Pre-Training with Gradient-Disentangled Embedding Sharing},
author={Pengcheng He and Jianfeng Gao and Weizhu Chen},
year={2021},
eprint={2111.09543},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
@inproceedings{
he2021 DeBERTa ,
title={ DeBERTa : DECODING-ENHANCED BERT WITH DISENTANGLED ATTENTION},
author={Pengcheng He and Xiaodong Liu and Jianfeng Gao and Weizhu Chen},
booktitle={International Conference on Learning Representations},
year={2021},
url={https://openreview.net/forum?id=XPZIaotutsD}
}