🚀 DeBERTa:具有解耦注意力的解碼增強型BERT
DeBERTa是一種基於解耦注意力和增強掩碼解碼器改進的模型,它在BERT和RoBERTa的基礎上進行了優化。該模型使用80GB訓練數據,在大多數自然語言理解(NLU)任務上的表現優於BERT和RoBERTa。更多詳細信息和更新請查看官方倉庫。此為DeBERTa V2 xxlarge模型,有48層,隱藏層大小為1536,總參數達15億,使用160GB原始數據進行訓練。
🚀 快速開始
本部分將為你介紹DeBERTa模型在自然語言理解(NLU)任務上的微調情況,以及如何運行該模型。
✨ 主要特性
- 解耦注意力機制:改進了傳統BERT和RoBERTa模型,在NLU任務上表現更優。
- 增強掩碼解碼器:提升了模型的性能。
- 多任務表現出色:在多個GLUE基準任務和SQuAD數據集上取得了良好的效果。
📦 安裝指南
運行模型前,你需要安裝必要的依賴:
pip install datasets
pip install deepspeed
同時,下載deepspeed配置文件:
wget https://huggingface.co/microsoft/deberta-v2-xxlarge/resolve/main/ds_config.json -O ds_config.json
💻 使用示例
基礎用法
使用Deepspeed
運行模型:
export TASK_NAME=mnli
output_dir="ds_results"
num_gpus=8
batch_size=8
python -m torch.distributed.launch --nproc_per_node=${num_gpus} \
run_glue.py \
--model_name_or_path microsoft/deberta-v2-xxlarge \
--task_name $TASK_NAME \
--do_train \
--do_eval \
--max_seq_length 256 \
--per_device_train_batch_size ${batch_size} \
--learning_rate 3e-6 \
--num_train_epochs 3 \
--output_dir $output_dir \
--overwrite_output_dir \
--logging_steps 10 \
--logging_dir $output_dir \
--deepspeed ds_config.json
高級用法
使用--sharded_ddp
運行模型:
cd transformers/examples/text-classification/
export TASK_NAME=mnli
python -m torch.distributed.launch --nproc_per_node=8 run_glue.py --model_name_or_path microsoft/deberta-v2-xxlarge \
--task_name $TASK_NAME --do_train --do_eval --max_seq_length 256 --per_device_train_batch_size 8 \
--learning_rate 3e-6 --num_train_epochs 3 --output_dir /tmp/$TASK_NAME/ --overwrite_output_dir --sharded_ddp --fp16
📚 詳細文檔
微調結果
以下是DeBERTa在SQuAD 1.1/2.0和多個GLUE基準任務上的開發結果:
模型 |
SQuAD 1.1 |
SQuAD 2.0 |
MNLI-m/mm |
SST-2 |
QNLI |
CoLA |
RTE |
MRPC |
QQP |
STS-B |
|
F1/EM |
F1/EM |
Acc |
Acc |
Acc |
MCC |
Acc |
Acc/F1 |
Acc/F1 |
P/S |
BERT-Large |
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-Large1 |
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-XLarge1 |
-/- |
-/- |
91.5/91.2 |
97.0 |
- |
- |
93.1 |
92.1/94.3 |
- |
92.9/92.7 |
DeBERTa-V2-XLarge1 |
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-XXLarge1,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基於Transformer架構,採用瞭解耦注意力和增強掩碼解碼器。
- 訓練數據:使用了80GB訓練數據,DeBERTa V2 xxlarge模型使用了160GB原始數據。
📄 許可證
本項目採用MIT許可證。
📖 引用
如果你覺得DeBERTa對你的工作有幫助,請引用以下論文:
@inproceedings{
he2021deberta,
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}
}