Transformer-based models are popularly used in natural language processing (NLP). Its core component, self-attention, has aroused widespread interest. To understand the self-attention mechanism, a direct method is to visualize the attention map of a pre-trained model. Based on the patterns observed, a series of efficient Transformers with different sparse attention masks have been proposed. From a theoretical perspective, universal approximability of Transformer-based models is also recently proved. However, the above understanding and analysis of self-attention is based on a pre-trained model. To rethink the importance analysis in self-attention, we study the significance of different positions in attention matrix during pre-training. A surprising result is that diagonal elements in the attention map are the least important compared with other attention positions. We provide a proof showing that these diagonal elements can indeed be removed without deteriorating model performance. Furthermore, we propose a Differentiable Attention Mask (DAM) algorithm, which further guides the design of the SparseBERT. Extensive experiments verify our interesting findings and illustrate the effect of the proposed algorithm.
翻译:在自然语言处理(NLP)中广泛使用基于变压器的模型。其核心组成部分,即自我注意,引起了广泛的兴趣。为了了解自我注意机制,直接的方法是直观地描绘一个经过训练的模型的注意图。根据观察到的模式,提出了一系列高效的变压器,其关注面面不同。从理论上看,基于变压器的模型的普遍接近性最近也得到证明。但是,上述对自我注意的理解和分析是以预先训练的模式为基础的。为了重新思考自我注意的重要性分析,我们研究了在训练前的注意矩阵中不同位置的重要性。一个令人惊讶的结果是,与其它注意位置相比,注意图中的对角要素是最不重要的。我们提供的证据表明,这些对角要素确实可以消除,而不会使模型性能恶化。此外,我们建议一种差异式的注意面具算法,进一步指导SparchaBERT的设计。广泛的实验证实了我们有趣的调查结果,并说明了提议的算法的效果。