Revisiting Over-smoothing in BERT from the Perspective of Graph

1 INTRODUCTION . Over the past few years , Transformer ( Vaswani et al. , 2017 ) has been widely used in various natural language processing ( NLP ) tasks , including text classification ( Wang et al. , 2018a ) , text translation ( Ott et al. , 2018 ) , question answering ( Rajpurkar et al. , 2016 ; 2018 ) and text generation ( Brown et al. , 2020 ) . The recent application of Transformer in computer vision ( CV ) field also demonstrate the potential capacity of Transformer architecture . For instance , Transformer variants have been successfully used for image classification ( Dosovitskiy et al. , 2021 ) , object detection ( Carion et al. , 2020 ) and semantic segmentation ( Strudel et al. , 2021 ) . Three fundamental descendants from Transformer include BERT ( Devlin et al. , 2019 ) , RoBERTa ( Liu et al. , 2019 ) and ALBERT ( Lan et al. , 2020 ) , which achieve state-of-the-art performance on a wide range of NLP tasks . Recently , Dong et al . ( 2021 ) observes the “ token uniformity ” problem , which reduces the capacity of Transformer-based architectures by making all token representations identical . They claim that pure self-attention ( SAN ) modules cause token uniformity , but they do not discuss whether the token uniformity problem still exists in Transformer blocks . On the other hand , Gong et al . ( 2021 ) observe the “ over-smoothing ” problem for ViT ( Dosovitskiy et al. , 2021 ) , in that different input patches are mapped to a similar latent representation . To prevent loss of information , they introduce additional loss functions to encourage diversity and successfully improve model performance by suppressing over-smoothing . Moreover , “ overthinking ” phenomenon , indicating that shallow representations are better than deep representations , also be observed in ( Zhou et al. , 2020 ; Kaya et al. , 2019 ) . As discussed in Section 3 , this phenomenon has some inherent connection with over-smoothing . In this paper , we use “ over-smoothing ” to unify the above issues , and refer this as the phenomenon that the model performance is deteriorated because different inputs are mapped to a similar representation . As the over-smoothing problem is first studied in the graph neural network ( GNN ) literature ( Li et al. , 2018 ; Xu et al. , 2018 ; Zhao & Akoglu , 2020 ) , in this paper , we attempt to explore the cause of such ∗Equal contribution . problem by building a relationship between Transformer blocks and graphs . Specifically , we consider the self-attention matrix as the normalized adjacency matrix of a weighted graph , whose nodes are the tokens in a sentence . Furthermore , we consider the inherent connection between BERT and graph convolutional networks ( Kipf & Welling , 2017 ) . Inspired by the over-smoothing problem in GNN , we study over-smoothing in BERT from a theoretical view via matrix projection . As opposed to Dong et al . ( 2021 ) , where the authors claim that layer normalization is irrelevant to over-smoothing , we find that layer normalization ( Ba et al. , 2016 ) plays an important role in over-smoothing . Specifically , we theoretically prove that , if the standard deviation in layer normalization is sufficiently large , the outputs of the Transformer stacks will converge to a low-rank subspace , resulting in over-smoothing . Empirically , we verify that the conditions hold for a certain number of samples for a pre-trained and fine-tuned BERT model ( Devlin et al. , 2019 ) , which is consistent with our above observations . To alleviate the over-smoothing problem , we propose a hierarchical fusion strategy that adaptively fuses representations from different layers . Three fusion approaches are used : ( i ) Concat Fusion , ( ii ) Max Fusion , and ( iii ) Gate Fusion . The proposed method reduces the similarity between tokens and outperforms BERT baseline on the GLUE ( Wang et al. , 2018a ) , SWAG ( Zellers et al. , 2018 ) and SQuAD ( Rajpurkar et al. , 2016 ; 2018 ) data sets . In summary , the contributions of this paper are as follows : ( i ) We develop the relationship between self-attention and graph for a better understanding of over-smoothing in BERT . ( ii ) We provide theoretical analysis on over-smoothing in the BERT model , and empirically verify the theoretical results . ( iii ) We propose hierarchical fusion strategies that adaptively combine different layers to alleviate over-smoothing . Extensive experimental results verify our methods ’ effectiveness . 2 RELATED WORK . 2.1 TRANSFORMER BLOCK AND SELF-ATTENTION . Transformer block is a basic component in Transformer model ( Vaswani et al. , 2017 ) . Each Transformer block consists of a self-attention layer and a feed-forward layer . Let X ∈ Rn×d be the input to a Transformer block , where n is the number of input tokens and d is the embedding size . The self-attention layer output can be written as : Attn ( X ) = X + h∑ k=1 σ ( XWQk ( XW K k ) > ) XW Vk W O > k = X + h∑ k=1 ÂkXW V O k , ( 1 ) where h is the number of heads , σ is the softmax function , and WQk , W K k , W V k , W O k ∈ Rd×dh ( where dh = d/h is the dimension of a single-head output ) are weight matrices for the query , key , value , and output , respectively of the kth head . In particular , the self-attention matrix Â = σ ( XWQ ( XWK ) > ) = σ ( QK > ) ( 2 ) in ( 1 ) plays a key role in the self-attention layer ( Park et al. , 2019 ; Gong et al. , 2019 ; Kovaleva et al. , 2019 ) . As in ( Yun et al. , 2020 ; Shi et al. , 2021 ; Dong et al. , 2021 ) , we drop the scale product 1/ √ dh to simplify analysis . The feed-forward layer usually has two fully-connected ( FC ) layers with residual connection : FF ( X ) = Attn ( X ) +ReLU ( Attn ( X ) W1 + b1 ) W2 + b2 , where W1 ∈ Rd×dff , W2 ∈ Rdff×d ( dff is the size of the intermediate layer ) are the weight matrices , and b1 , b2 are the biases . Two layer normalization ( Ba et al. , 2016 ) operations are performed after the self-attention layer and fully-connected layer , respectively . 2.2 OVER-SMOOTHING . In graph neural networks , over-smoothing refers to the problem that the performance deteriorates as representations of all the nodes become similar ( Li et al. , 2018 ; Xu et al. , 2018 ; Huang et al. , 2020 ) . Its main cause is the stacked aggregation layer using the same adjacency matrix . Recently , several approaches have been proposed to alleviate the over-smoothing problem . Xu et al . ( 2018 ) propose a jumping knowledge network for better structure-aware representation , which flexibly leverages different neighborhood ranges . ResGCN ( Li et al. , 2019 ) adapts the residual connection and dilated convolution in the graph convolutional network ( GCN ) , and successfully scales the GCN to 56 layers . Zhao & Akoglu ( 2020 ) propose PairNorm , a novel normalization layer , that prevents node embeddings from becoming too similar . DropEdge ( Rong et al. , 2020 ; Huang et al. , 2020 ) randomly removes edges from the input graph at each training epoch , and reduces the effect of over-smoothing . Unlike graph neural networks , over-smoothing in Transformer-based architectures has not been discussed in detail . Dong et al . ( 2021 ) introduce the “ token-uniformity ” problem for self-attention , and show that skip connections and multi-layer perceptron can mitigate this problem . However , Gong et al . ( 2021 ) still observe over-smoothing on the Vision Transformers ( Dosovitskiy et al. , 2021 ) . 3 DOES OVER-SMOOTHING EXIST IN BERT ? . In this section , we first explore the existence of over-smoothing in BERT , by measuring the similarity between tokens in each Transformer layer . Specifically , we use the token-wise cosine similarity ( Gong et al. , 2021 ) as our similarity measure : CosSim = 1 n ( n− 1 ) ∑ i 6=j h > i hj ‖hi‖2‖hj‖2 , where n is the number of tokens , hi and hj are two representations of different tokens , and ‖ · ‖2 is the Euclidean norm . Following Dong et al . ( 2021 ) , we use WikiBio ( Lebret et al. , 2016 ) as input to the following Transformer-based models fine-tuned on the SQuAD data set ( Rajpurkar et al. , 2018 ) : ( i ) BERT ( Devlin et al. , 2019 ) , ( ii ) RoBERTa ( Liu et al. , 2019 ) and ( iii ) ALBERT ( Lan et al. , 2020 ) .1 For comparison , all three models are stacked with 12 blocks . We calculate each CosSim for each data sample and show the average and standard derivation of CosSim values over all WikiBio data . In the figures , layer 0 represents original input token representation , and layer 1-12 represents the corresponding transformer layers . As shown in Figure 1 ( a ) , the original token representations are different from each other , while token similarities are high in the last layer . For instance , the average token-wise cosine similarity of the last layer of ALBERT and RoBERTa are both larger than 90 % . To illustrate the relationship between “ over-thinking ” and “ over-smoothing ” , we compare the tokenwise cosine similarity at each layer with the corresponding error rate . As for the corresponding error rate of layer i , we use the representations from layer i as the final output and fine-tune the classifier . Following Zhou et al . ( 2020 ) , we experiment with ALBERT ( Lan et al. , 2020 ) fine-tuned on the MRPC data set ( Dolan & Brockett , 2005 ) and use their error rate results for convenience . As shown in Figure 1 ( b ) , layer 10 has the lowest cosine similarity and error rate . At layers 11 and 12 , the tokens have larger cosine similarities , making them harder to distinguish and resulting in the performance drop . Thus , “ over-thinking ” can be explained by “ over-smoothing ” . A direct consequence of over-smoothing is that the performance can not be improved when the model gets deeper , since the individual tokens are no longer distinguishable . To illustrate this , we increase the number of layers in BERT to 24 while keeping the other settings . As shown in Figure 1 ( c ) , the 1Our implementation is based on the HuggingFace ’ s Transformers library ( Wolf et al. , 2020 ) . performance of vanilla BERT can not improve as the model gets deeper . In contrast , the proposed hierarchical fusion ( as will be discussed in Section 6 ) consistently outperforms the baseline , and has better and better performance as the model gets deeper . Based on these observations , we conclude that the over-smoothing problem still exists in BERT . 4 RELATIONSHIP BETWEEN SELF-ATTENTION AND GRAPH . Since over-smoothing is first discussed in the graph neural network literature ( Li et al. , 2018 ; Zhao & Akoglu , 2020 ) , we attempt to understand its cause from a graph perspective in this section .

Summary: The current manuscript explored the token over-smoothing problem in Bert transformer blocks. Empirically, the authors showed that the token over-smooth problem is increasingly severe in deeper layers of a Bert model. The token over-smoothing is potentially harmful to task performance. As the over-smoothing problems have been discussed in graph networks extensively, the authors established a connection between transformer blocks with graph networks and looked at the over-smoothing problem of transformer blocks analogously. The authors revealed that layer normalization in the transformer blocks contributed to the over-smoothing issue both theoretically and empirically. Moreover, the authors proposed to improve the over-smoothing issue by hierarchical fusion strategies, that is utilize token representation from earlier layers. Overall, the author applied a novel approach to shed light on an insufficiently investigated problem. The paper was well written.