admin管理员组

文章数量:1590354

NLP之DeBERTa:DeBERTa的简介、安装和使用方法、案例应用之详细攻略

目录

相关论文

《DeBERTa: Decoding-enhanced BERT with Disentangled Attention》翻译与解读

Abstract

6、Conclusion

DeBERTa的简介

DeBERTa的安装和使用方法

1、更新

03/18/2023,DeBERTaV3 论文被ICLR 2023接受。

12/8/2021,添加了DeBERTa-V3-XSmall

11/16/2021,新作品DeBERTa V3:

3/31/2021,添加了遮蔽语言模型任务

2/03/2021,DeBERTa v2代码

12/29/2020,DeBERTa 1.5B模型

06/13/2020,DeBERTa预训练模型、源代码和微调脚本

1、预训练模型

2、使用模型

3、使用docker

4、使用pip

在现有代码中使用DeBERTa

从命令行运行DeBERTa实验,对于glue任务

5、实验

在NLU任务上进行微调

在XNLI上进行微调

使用MLM和RTD目标进行预训练

DeBERTa的案例应用


相关论文

《DeBERTa: Decoding-enhanced BERT with Disentangled Attention》翻译与解读

地址

论文地址:https://arxiv/abs/2006.03654

时间

2020年6月5日

作者

Pengcheng He, Xiaodong Liu, Jianfeng Gao, Weizhu Chen

Microsoft

总结

此论文提出了一种新的Transformer模型架构DeBERTa(Decoding-enhanced BERT with Disentangled Attention),它通过两种新技术来改进BERT和RoBERTa模型:

背景痛点:现有的Transformer模型,如BERT和RoBERTa,都存在一定的问题。它们在解码层仅使用词与词之间的相对位置信息,但在预测掩盖词时,词在句子中的绝对位置信息同样很重要。此外,词与词之间关系不仅取决于内容,也取决于它们的相对位置关系。

解答方案

(1) 拆分注意力机制:DeBERTa采用拆分注意力机制每个词由两个向量表示其内容和位置信息。词对之间的注意力权重通过分离矩阵计算内容和相对位置信息。

(2) 增强掩码解码器:DeBERTa在解码层中引入词的绝对位置嵌入,用于MLM预训练任务中的掩盖词预测。

核心特点

(1) 更好地表示词与词之间的关系,考虑内容相对位置双因素影响。

(2) 在解码任务中利用词的绝对位置信息,提高预测能力。

优势:经过大量下游任务实验验证,DeBERTa模型训练效率更高,同时在NLU和NLG下游任务上效果都显著优于BERT、RoBERTa等SOTA模型。特别是,单个DeBERTa1.5B模型在SuperGLUE上的macro平均分数首次超过人类水平。

以上总结了该论文提出的DeBERTa模型的主要痛点、解决方案、核心特点和实验验证的优势。

Abstract

Recent progress in pre-trained neural language models has significantly improved the performance of many natural language processing (NLP) tasks. In this pa-per we propose a new model architecture DeBERTa (Decoding-enhanced BERT with disentangled attention) that improves the BERT and RoBERTa models using two novel techniques. The first is the disentangled attention mechanism, where each word is represented using two vectors that encode its content and position, respectively, and the attention weights among words are computed using disen-tangled matrices on their contents and relative positions, respectively. Second, an enhanced mask decoder is used to incorporate absolute positions in the de-coding layer to predict the masked tokens in model pre-training. In addition, a new virtual adversarial training method is used for fine-tuning to improve models’ generalization. We show that these techniques significantly improve the efficiency of model pre-training and the performance of both natural language understand (NLU) and natural langauge generation (NLG) downstream tasks. Compared to RoBERTa-Large, a DeBERTa model trained on half of the training data per-forms consistently better on a wide range of NLP tasks, achieving improvements on MNLI by +0.9% (90.2% vs. 91.1%), on SQuAD v2.0 by +2.3% (88.4% vs. 90.7%) and RACE by +3.6% (83.2% vs. 86.8%). Notably, we scale up DeBERTa by training a larger version that consists of 48 Transform layers with 1.5 bil-lion parameters. The significant performance boost makes the single DeBERTa model surpass the human performance on the SuperGLUE benchmark (Wang et al., 2019a) for the first time in terms of macro-average score (89.9 versus 89.8), and the ensemble DeBERTa model sits atop the SuperGLUE leaderboard as of Jan-uary 6, 2021, outperforming the human baseline by a decent margin (90.3 versus 89.8). The pre-trained DeBERTa models and the source code were released at: https://github/microsoft/DeBERTa1.

最近在预训练神经语言模型方面取得的进展显著提高了许多自然语言处理(NLP)任务的性能。在本文中,我们提出了一种新的模型架构DeBERTa(Decoding-enhanced BERT with disentangled attention),通过两种新颖的技术改进了BERT和RoBERTa模型。第一种是解缠关注机制,其中每个单词分别用两个向量表示其内容和位置,并且单词之间的关注权重是分别使用它们的内容和相对位置的解缠矩阵计算的。其次,在解码层中使用增强的掩码解码器来预测模型预训练中的屏蔽标记,以包含绝对位置。此外,使用一种新的虚拟对抗训练方法进行微调,以提高模型的泛化能力。

我们展示这些技术显著提高了模型预训练的效率以及自然语言理解(NLU)和自然语言生成(NLG)下游任务的性能。与RoBERTa-Large相比,使用一半的训练数据训练的DeBERTa模型在广泛的NLP任务中表现一致更好,在MNLI上提高了+0.9%(90.2% vs. 91.1%),在SQuAD v2.0上提高了+2.3%(88.4% vs. 90.7%),在RACE上提高了+3.6%(83.2% vs. 86.8%)。值得注意的是,我们通过训练包含48个Transform层15亿参数的更大版本,将DeBERTa扩展起来。显著的性能提升使得单一的DeBERTa模型在SuperGLUE基准测试(Wang等,2019a)上首次在宏平均分数方面超越了人类表现(89.9比89.8),并且截至2021年1月6日,集成DeBERTa模型在SuperGLUE榜单上领先,优于人类基线相当大的差距(90.3比89.8)。预训练的DeBERTa模型和源代码已在https://github/microsoft/DeBERTa上发布。

6Conclusion

This paper presents a new model architecture DeBERTa (Decoding-enhanced BERT with disentangled attention) that improves the BERT and RoBERTa models using two novel techniques. The first is the disentangled attention mechanism, where each word is represented using two vectors that encode its content and position, respectively, and the attention weights among words are computed using disentangled matrices on their contents and relative positions, respectively. The second is an enhanced mask decoder which incorporates absolute positions in the decoding layer to predict the masked tokens in model pre-training. In addition, a new virtual adversarial training method is used for fine-tuning to improve model’s generalization on downstream tasks.

We show through a comprehensive empirical study that these techniques significantly improve the efficiency of model pre-training and the performance of downstream tasks. The DeBERTa model with 1.5 billion parameters surpasses the human performance on the SuperGLUE benchmark for the first time in terms of macro-average score.

DeBERTa surpassing human performance on SuperGLUE marks an important milestone toward general AI. Despite its promising results on SuperGLUE, the model is by no means reaching the human-level intelligence of NLU. Humans are extremely good at leveraging the knowledge learned from different tasks to solve a new task with no or little task-specific demonstration. This is referred to as compositional generalization, the ability to generalize to novel compositions (new tasks) of familiar constituents (subtasks or basic problem-solving skills). Moving forward, it is worth exploring how to make DeBERTa incorporate compositional structures in a more explicit manner, which could allow combining neural and symbolic computation of natural language similar to what humans do.

本文提出了一种新的模型架构DeBERTa(Decoding-enhanced BERT with disentangled attention),通过两种新颖的技术改进了BERT和RoBERTa模型。第一种是解缠关注机制,其中每个单词分别用两个向量表示其内容和位置,并且单词之间的关注权重是分别使用它们的内容和相对位置的解缠矩阵计算的。第二种是增强的掩码解码器,它在解码层中包含绝对位置,以预测模型预训练中的屏蔽标记。此外,使用一种新的虚拟对抗训练方法进行微调,以提高模型在下游任务上的泛化能力。

我们通过全面的实证研究表明,这些技术显著提高了模型预训练的效率以及下游任务的性能。具有15亿参数的DeBERTa模型首次在SuperGLUE基准测试中超越了人类的宏平均得分

DeBERTa在SuperGLUE上超越人类表现标志着通向通用人工智能的重要里程碑。尽管在SuperGLUE上取得了令人鼓舞的成果,该模型并不意味着达到了自然语言理解的人类水平智能。人类在利用从不同任务中学到的知识来解决新任务时表现得非常出色,而几乎没有或很少有任务特定的演示。这被称为组合泛化,即能够推广到熟悉组分(子任务或基本问题解决技能)的新组合(新任务)的能力。未来,值得探讨如何使DeBERTa以更明确的方式融入组合结构,这可能允许结合类似于人类的自然语言的神经和符号计算。

DeBERTa的简介

DeBERTa(Decoding-enhanced BERT with disentangled attention)通过两种新颖的技术改进了BERT和RoBERTa模型。第一种是解缠关注机制,其中每个单词分别用两个向量表示其内容和位置,并且单词之间的关注权重是分别使用它们的内容和相对位置的解缠矩阵计算的。第二种是增强的掩码解码器,它用于替换输出softmax层,以预测模型预训练中的屏蔽标记。我们展示了这两种技术显著提高了模型预训练的效率和下游任务的性能。

DeBERTa: 具有解缠关注的解码增强型BERT

这个存储库是DeBERTa: 具有解缠关注的解码增强型BERT以及DeBERTa V3: 使用ELECTRA风格的预训练和梯度解缠嵌入共享改进DeBERTa的官方实现。

GitHub地址:GitHub - microsoft/DeBERTa: The implementation of DeBERTa

DeBERTa的安装和使用方法

1、更新

03/18/2023DeBERTaV3 论文被ICLR 2023接受。

已添加DeBERTaV3预训练和持续训练的代码。请查看语言模型以获取详细信息。

12/8/2021添加了DeBERTa-V3-XSmall

仅有22M主干参数,仅为RoBERTa-Base和XLNet-Base的1/4,DeBERTa-V3-XSmall在MNLI和SQuAD v2.0任务上显著优于后者(即MNLI-m上的1.2%,SQuAD v2.0上的1.5% EM分数)。这进一步证明了DeBERTaV3模型的效率。

11/16/2021新作品DeBERTa V3:

我们新作品DeBERTa V3: 使用ELECTRA风格的预训练和梯度解缠嵌入共享改进DeBERTa的模型现在已经在huggingface模型中心公开可用。这些新模型基于DeBERTa-V2模型,通过使用ELECTRA风格的目标加上梯度解缠嵌入共享来替代MLM,进一步提高了模型的效率。添加了DeBERTa V3模型微调的脚本,添加了RTD任务头的代码,添加了语言模型预训练的文档。

3/31/2021添加了遮蔽语言模型任务

添加了遮蔽语言模型任务,添加了SuperGLUE任务,添加了SiFT代码。

2/03/2021DeBERTa v2代码

DeBERTa v2代码和900M、1.5B模型现在已经发布。这包括我们SuperGLUE单模型提交使用的1.5B模型,实现了89.9,超过了人类基线89.8。您可以在我们的博客中找到有关此提交的更多详细信息。

v2中的新功能

词汇表:在v2中,我们使用了从训练数据构建的大小为128K的新词汇表。我们使用sentencepiece分词器,而不是GPT2分词器。

nGiE(nGram诱导输入编码):在v2中,我们在第一个变换层旁边使用了额外的卷积层,以更好地学习输入令牌的局部依赖性。我们将在此功能上添加更多消融研究。

在关注层中共享位置投影矩阵与内容投影矩阵:根据我们之前的实验,我们发现这可以节省参数而不影响性能。

应用桶编码相对位置:在v2中,我们使用对数桶对相对位置进行编码,类似于T5。

900M模型和1.5B模型:在v2中,我们将模型规模扩大到900M和1.5B,这显著提高了下游任务的性能。

12/29/2020DeBERTa 1.5B模型

使用DeBERTa 1.5B模型,我们超越了T5 11B模型和SuperGLUE榜单上的人类表现。代码和模型将很快发布。请查看我们的论文以获取更多详细信息。

06/13/2020DeBERTa预训练模型、源代码和微调脚本

我们发布了预训练模型、源代码和微调脚本,以重现论文中的一些实验结果。您可以按照类似的脚本将DeBERTa应用于您自己的实验或应用。预训练脚本将在下一步发布。

1、预训练模型

我们的预训练模型已打包成压缩文件。您可以从我们的发布中下载它们,或通过下面的链接下载单个模型:

>> 这是首次超越T5 11B(89.3)和人类表现(89.8)的模型(89.9)在SuperGLUE上。新的128K SPM词汇。

>>这些V3 DeBERTa模型是使用ELECTRA风格的目标加上梯度解缠嵌入共享进行预训练的,这显著提高了模型的效率。

2、使用模型

阅读我们的文档

要求

Linux系统,例如Ubuntu 18.04LTS

CUDA 10.0

pytorch 1.3.0

python 3.6

bash shell 4.0

curl

docker(可选)

nvidia-docker2(可选)

有几种尝试我们的代码的方法,

3、使用docker

Docker是运行代码的推荐方式,因为我们已经将每个依赖项都构建到我们的docker bagai/deberta中,您可以按照docker官方网站的说明在您的机器上安装docker。

要使用docker,请确保您的系统符合上述列表中的要求。以下是尝试GLUE实验的步骤:拉取代码,运行./run_docker.sh,然后您可以在/DeBERTa/experiments/glue/下运行bash命令。

4、使用pip

简介

在代码的根目录中拉取代码并运行pip3 install -r requirements.txt,然后进入代码的experiments/glue/文件夹,尝试运行该文件夹下的bash命令进行glue实验。

安装包

安装包

pip install deberta

在现有代码中使用DeBERTa

从命令行运行DeBERTa实验对于glue任务

获取数据

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缓存预训练模型和分词器,如果下载失败,您可能需要清理它。

您也可以尝试使用HF Transformers测试我们的模型。但是,当您尝试XXLarge模型时,您需要指定--sharded_ddp参数。请查看我们的XXLarge模型卡片以获取更多详细信息。

5、实验

我们的微调实验是在半个DGX-2节点上进行的,使用8x32 V100 GPU卡,由于不同的GPU型号、驱动程序、CUDA SDK版本、使用FP16或FP32以及随机种子,结果可能会有所不同。我们在这里报告了基于多次运行不同随机种子的数字。这是来自Large模型的结果:

在NLU任务上进行微调

我们在SQuAD 1.1/2.0和几个GLUE基准任务上呈现了开发结果。

在XNLI上进行微调

我们在XNLI上呈现了具有零射击跨语言转移设置的开发结果,即仅使用英语数据进行训练,测试其他语言。

注:与RoBERTa一样,对于RTE、MRPC、STS-B,我们基于DeBERTa-Large-MNLI、DeBERTa-XLarge-MNLI、DeBERTa-V2-XLarge-MNLI、DeBERTa-V2-XXLarge-MNLI进行了微调。从MNLI微调模型开始,SST-2/QQP/QNLI/SQuADv2的结果也将稍微提高,但我们只报告了那4个任务从预训练基础模型进行微调的数字。

使用MLM和RTD目标进行预训练

要使用MLM和RTD目标预训练DeBERTa,请查看experiments/language_models。

DeBERTa的案例应用

更新中……

本文标签: 使用方法案例攻略简介详细