Upload 118 files
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- text-versions/attention-markdown/1510.08565_Attention with Intention for a Neural Ne.md +182 -0
- text-versions/attention-markdown/1612.01887_Knowing When to Look Adaptive Attention .md +367 -0
- text-versions/attention-markdown/1704.06567_Attention Strategies for MultiSource Seq.md +212 -0
- text-versions/attention-markdown/1706.03762_Attention Is All You Need.md +300 -0
- text-versions/attention-markdown/1710.03743_Confidence through Attention.md +253 -0
- text-versions/attention-markdown/1803.08475_Attention Learn to Solve Routing Problem.md +572 -0
- text-versions/attention-markdown/1804.03999_Attention UNet Learning Where to Look fo.md +170 -0
- text-versions/attention-markdown/1805.03294_Improved training of endtoend attention .md +229 -0
- text-versions/attention-markdown/1805.12307_AttentionBased LSTM for Psychological St.md +162 -0
- text-versions/attention-markdown/1807.03756_Latent Alignment and Variational Attenti.md +384 -0
- text-versions/attention-markdown/1808.03867_Pervasive Attention 2D Convolutional Neu.md +265 -0
- text-versions/attention-markdown/1904.02874_An Attentive Survey of Attention Models.md +0 -0
- text-versions/attention-markdown/1905.07289_Conversion Prediction Using Multitask Co.md +365 -0
- text-versions/attention-markdown/1905.13497_Attention Is not All You Need for Common.md +136 -0
- text-versions/attention-markdown/1906.02792_Attention is all you need for Videos Sel.md +288 -0
- text-versions/attention-markdown/1906.03674_Attentionbased Conditioning Methods for .md +212 -0
- text-versions/attention-markdown/1908.05819_Mixed HighOrder Attention Network for Pe.md +307 -0
- text-versions/attention-markdown/1909.07913_Learning to Deceive with AttentionBased .md +255 -0
- text-versions/attention-markdown/1910.14537_Attention Is All You Need for Chinese Wo.md +311 -0
- text-versions/attention-markdown/1911.03875_Rethinking SelfAttention Towards Interpr.md +329 -0
- text-versions/attention-markdown/1912.00835_Low Rank Factorization for Compact Multi.md +370 -0
- text-versions/attention-markdown/2002.07028_LowRank Bottleneck in Multihead Attentio.md +417 -0
- text-versions/attention-markdown/2003.11644_MultiLabel Text Classification using Att.md +380 -0
- text-versions/attention-markdown/2005.09561_Normalized Attention Without Probability.md +352 -0
- text-versions/attention-markdown/2006.10962_Attention Mesh Highfidelity Face Mesh Pr.md +100 -0
- text-versions/attention-markdown/2006.13730_AttentionBased Neural Networks for Senti.md +449 -0
- text-versions/attention-markdown/2006.15222_BERTology Meets Biology Interpreting Att.md +384 -0
- text-versions/attention-markdown/2007.04639_Attention Neural Network for Trash Detec.md +152 -0
- text-versions/attention-markdown/2007.08442_Kronecker Attention Networks.md +341 -0
- text-versions/attention-markdown/2009.12064_Attention Meets Perturbations Robust and.md +448 -0
- text-versions/attention-markdown/2010.13154_Attention is All You Need in Speech Sepa.md +200 -0
- text-versions/attention-markdown/2011.09763_AttentionBased Transformers for Instance.md +266 -0
- text-versions/attention-markdown/2012.02994_AttentionDriven Dynamic Graph Convolutio.md +241 -0
- text-versions/attention-markdown/2012.11879_FcaNet Frequency Channel Attention Netwo.md +300 -0
- text-versions/attention-markdown/2101.07715_Meningioma segmentation in T1weighted MR.md +254 -0
- text-versions/attention-markdown/2103.03404_Attention is Not All You Need Pure Atten.md +601 -0
- text-versions/attention-markdown/2104.01541_Attention Backend for Automatic Speaker .md +199 -0
- text-versions/attention-markdown/2104.09497_Attention in Attention Network for Image.md +289 -0
- text-versions/attention-markdown/2105.14103_An Attention Free Transformer.md +448 -0
- text-versions/attention-markdown/2106.01451_Attentionbased Contextual Language Model.md +284 -0
- text-versions/attention-markdown/2107.00135_Attention Bottlenecks for Multimodal Fus.md +409 -0
- text-versions/attention-markdown/2108.11637_SelfAttention for Audio SuperResolution.md +176 -0
- text-versions/attention-markdown/2108.12409_Train Short Test Long Attention with Lin.md +438 -0
- text-versions/attention-markdown/2108.13320_Neural HMMs are all you need for highqua.md +192 -0
- text-versions/attention-markdown/2109.07043_Attention Is Indeed All You Need Semanti.md +496 -0
- text-versions/attention-markdown/2110.03183_Attention is All You Need Good Embedding.md +136 -0
- text-versions/attention-markdown/2110.11773_Sinkformers Transformers with Doubly Sto.md +494 -0
- text-versions/attention-markdown/2111.05498_Attention Approximates Sparse Distribute.md +0 -0
- text-versions/attention-markdown/2201.10801_When Shift Operation Meets Vision Transf.md +258 -0
- text-versions/attention-markdown/2203.10506_Attention Aided CSI Wireless Localizatio.md +223 -0
text-versions/attention-markdown/1510.08565_Attention with Intention for a Neural Ne.md
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1510.08565 Attention With Intention For A Neural Ne
|
| 2 |
+
|
| 3 |
+
## Attention with Intention for a Neural Network Conversation Model
|
| 4 |
+
|
| 5 |
+
Kaisheng Yao ∗ Microsoft Research Geoffrey Zweig Microsoft Research
|
| 6 |
+
|
| 7 |
+
kaisheny@microsoft.com gzweig@microsoft.com
|
| 8 |
+
|
| 9 |
+
Baolin Peng Chinese University of Hong Kong
|
| 10 |
+
|
| 11 |
+
blpeng@se.cuhk.edu.hk
|
| 12 |
+
|
| 13 |
+
## Abstract
|
| 14 |
+
|
| 15 |
+
In a conversation or a dialogue process, attention and intention play intrinsic roles. This paper proposes a neural network based approach that models the attention and intention processes. It essentially consists of three recurrent networks. The encoder network is a word-level model representing source side sentences. The intention network is a recurrent network that models the dynamics of the intention process. The decoder network is a recurrent network that produces responses to the input from the source side. It is a language model that is dependent on the intention and has an attention mechanism to attend to particular source side words, when predicting a symbol in the response. The model is trained end-toend without labeling data. Experiments show that this model generates natural responses to user inputs.
|
| 16 |
+
|
| 17 |
+
## 1 Introduction
|
| 18 |
+
|
| 19 |
+
A conversation process is a process of communication of thoughts through words. It may be considered as a structural process that stresses the role of purpose and processing in discourse [7]. Essentially, the discourse structure is intimately connected with two nonlinguistic notions: intention and attention. In processing an utterance, attention explicates the processing of utterances, for example, paying attention to particular words in a sentence. On the other hand, intention is higher level than attention and has its primary role of explaining discourse structure and coherence. Clearly, a conversation process is inherently complicated because of the two levels of structures.
|
| 20 |
+
|
| 21 |
+
A conversation process may be cast as a sequence-to-sequence mapping task. In this task, the source side of the conversation is from one person and the target side of the conversation is from another person. The sequence-to-sequence mapping task includes machine translation, graphemeto-phoneme conversion, named entity tagging, etc. However, an apparent difference of a dialogue process from these tasks is that a dialogue process involves multiple turns, whereas usually the above tasks involve only one turn of mapping a source sequence to its target sequence.
|
| 22 |
+
|
| 23 |
+
Neural network based approaches have been successfully applied in sequence-to-sequence mapping tasks. They have made significant progresses in machine translation [1,6,13], language understanding [8], and speech recognition [4]. Among those neural network-based approaches, one particular approach, which is called encoder-decoder framework [1, 13], aims at relaxing much requirement on human labeling.
|
| 24 |
+
|
| 25 |
+
Conversation models have been typically designed to be domain specific with much knowledge such as rules [3,18]. Recent methods [15] relax such requirement to some extent but their whole systems are still trained with manual labels because of their sub-components that require so. Manual labels are error prone and expensive. Therefore, it is appealing to train a system end-to-end without manual labels. Recent works in [10,12,14] are in this approach.
|
| 26 |
+
|
| 27 |
+
∗ Presented at NIPS Workshop on Machine Learning for Spoken Language Understanding and Interaction 2015.
|
| 28 |
+
|
| 29 |
+
Table 1: An example of dialogue process.
|
| 30 |
+
|
| 31 |
+
| user my computer is infected agent do you want to retrieve the files that was deleted? user the ones that the virus deleted , yes. agent i can help you resolve the issue with our virus removal and protection service user ok agent here is a link how to run system restore user thank you . agent you welcome |
|
| 32 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 33 |
+
|
| 34 |
+
In general, however, using knowledge is helpful. For example, the alignment information between the source and target side is critical in grapheme-to-phoneme conversion [17] to outperform a strong baseline using n-gram models [2]. In a neural network based machine translation system [6], the alignment information is used to outperform a strong phrase-based baseline [5].
|
| 35 |
+
|
| 36 |
+
In the context of modeling conversation process, a neural network model may be built with the knowledge of the structural information of conversation processes. In particular, the network may incorporate the notion of intention and attention. To test this, we developed a model that consists of three recurrent neural networks (RNNs). The source side RNN, or encoder network, encodes the source side inputs. The target side RNN, or decoder network, uses an attention mechanism to attend to particular words in the source side, when predicting a symbol in its response to the source side. Importantly, this attention in the target side is conditioned on the output from an intention RNN. This model, which has the structural knowledge of the conversation process, is trained end-to-end without labels. We experimented with this model and observed that it generates natural responses to user inputs.
|
| 37 |
+
|
| 38 |
+
## 2 Background
|
| 39 |
+
|
| 40 |
+
In the theory of discourse in [7], discourse structure is composed of three separate but related components. The first is the linguistic structure, which is the structure of the sequence of utterance. The linguistic structure consists of segments of the discourse into which the utterances naturally aggregate. The second structure is the intentional structure, which captures the discourse-relevant purposes, expressed in each of the linguistic segments as well as relationships among them. The third is the attentional state that is dynamic, and records the objects, properties, and relations that are salient at each point of the discourse.
|
| 41 |
+
|
| 42 |
+
In many examples we observe, there are usually just one linguistic segment that consists of all the utterances. Therefore, in the following, we consider a discourse with two structures: intention and attention.
|
| 43 |
+
|
| 44 |
+
In the example in Table 1, there is a clear flow of intentions. The user states the problem, with the user's intention of conveying the problem to the agent. The agent receives the words, processes them, and communicates back to the user. The user responds to the agent afterwards. Therefore, the whole conversation process consists of three intentions processed sequentially. The first is the intention of communication of the problem. The second intention is the process of resolving the issue. The third is the intention of acknowledgment. In processing each of the intentions, the user and the agent pay attention to particular words. For example, when resolving the issue, the agent pays attention to words such as 'virus'.
|
| 45 |
+
|
| 46 |
+
Figure 1: The attention with intention (AWI) model. The model is unrolled into three turns. In each turn has RNNs for encoder network and decoder network. Each session is represented by a fixed-dimension vector, which is a hidden state of an intention RNN network.
|
| 47 |
+
|
| 48 |
+
<!-- image -->
|
| 49 |
+
|
| 50 |
+
## 3 The model
|
| 51 |
+
|
| 52 |
+
## 3.1 The attention with intention (AWI) model
|
| 53 |
+
|
| 54 |
+
We propose a model that attempts to represent the structural process of intentions and the associated attentions. Figure 1 illustrates the model. It shows three layers of processing: encoder network, intention network, and decoder network.
|
| 55 |
+
|
| 56 |
+
The encoder network has inputs from the current source side input. Because the source side in the current turn is also dependent on the previous turn, the source side encoder network is linked with the output from the previous target side. The encoder network creates a representation of the source side in the current turn.
|
| 57 |
+
|
| 58 |
+
The intention network is dependent on its past state, so that it memories the history of intentions. It therefore is a recurrent network, taking a representation of the source side in the current turn and updating its hidden state.
|
| 59 |
+
|
| 60 |
+
The decoder is a recurrent network for language modeling that outputs symbol at each time. This output is dependent on the current intention from the intention network. It also pays attention to particular words in the source side.
|
| 61 |
+
|
| 62 |
+
In more details, a conversation has in totoal U turns. At turn u , a user in the source side, denoted in superscript ( s ) , has an input sequence of ⃗ x ( s,u ) = ( x ( s,u ) t : t = 1 , · · · , T ) with length T . An agent in the target side, denoted in superscript ( t ) , responds to the user with ⃗ y ( t,u ) = ( y ( t,u ) j : j = 1 , · · · J ) with length J . The proposed model is a conditional model of the target given the source, p ( ⃗ y ( t,u ) | ⃗ x ( s,u ) ) . If there is no confusion, we may omit the session index u in the following.
|
| 63 |
+
|
| 64 |
+
## 3.2 Encoder network
|
| 65 |
+
|
| 66 |
+
The encoder network reads the input sentence ⃗ x ( s ) , and converts them into a fixed-length or a variable length representation of the source side sequence. There are many choices to encode the source side. The approach we use is an RNN such that
|
| 67 |
+
|
| 68 |
+
<!-- formula-not-decoded -->
|
| 69 |
+
|
| 70 |
+
where f ( · ) is an RNN. h ( s ) t is the hidden state at time t in the source side. The initial state h ( s ) t with t = 0 is the last hidden state activity, h ( t,k-1 ) T , of the decoder network in the previous turn k -1 .
|
| 71 |
+
|
| 72 |
+
One form of the output from this encoder is the last hidden state activity c ( s ) T = h ( s ) T . This is used as a representation of the source side in the current turn to the intention network. The other form is a variable-length representation, to be used in the attention model described in Sec. 3.4. A general description of the variable length representation is as follows
|
| 73 |
+
|
| 74 |
+
<!-- formula-not-decoded -->
|
| 75 |
+
|
| 76 |
+
where q ( · ) might be a linear network or a nonlinear network.
|
| 77 |
+
|
| 78 |
+
## 3.3 Intention network
|
| 79 |
+
|
| 80 |
+
The signal from the encoder network is fed into an intention network to model the intention process. Following [7], the intention process is a dynamic process to model the intrinsic dynamics of conversation, in which an intention in one turn is dependent on the intention in the previous turn. This property might be modeled using a Markov model, but we choose an RNN.
|
| 81 |
+
|
| 82 |
+
Interestingly, the hidden state of an RNN in a certain turn may be considered as a distributed representation of the intention. Different from the usual process of training distributed representation of words [9], the distribution representation of intentions are trained with previous turns as their context. We use a first order RNN model, in which a hidden state is dependent explicitly on its previous state.
|
| 83 |
+
|
| 84 |
+
The intention model in AWI is therefore an RNN as follows
|
| 85 |
+
|
| 86 |
+
<!-- formula-not-decoded -->
|
| 87 |
+
|
| 88 |
+
where c ( s ) T is the fixed dimension representation of the source side described in Sec. 3.2. k is the index of the current turn. h ( t,k-1 ) T is the last hidden layer activity of the decoder network in the previous turn k -1 .
|
| 89 |
+
|
| 90 |
+
## 3.4 Decoder network
|
| 91 |
+
|
| 92 |
+
The last step is to decode the sequence in the target side, which is framed as a language model over each symbol, generated left to right. In this framework, the decoder computes conditional probability as
|
| 93 |
+
|
| 94 |
+
<!-- formula-not-decoded -->
|
| 95 |
+
|
| 96 |
+
where the hidden state in the decoder is computed using an RNN
|
| 97 |
+
|
| 98 |
+
<!-- formula-not-decoded -->
|
| 99 |
+
|
| 100 |
+
The initial state h ( t ) j at t = 0 is the last hidden state activity from the intention network.
|
| 101 |
+
|
| 102 |
+
The c ( t ) j is a vector to represent the context to generate y ( t ) j . It is dependent on the source side as
|
| 103 |
+
|
| 104 |
+
<!-- formula-not-decoded -->
|
| 105 |
+
|
| 106 |
+
where z ( · ) summerizes the variable-length source side representations { c ( s ) t } using weighted average. The weight is computed using a content-based alignment model [1] that produces high scores if the target side hidden state in previous time h ( t ) j-1 and c ( s ) t are similar. More formally, the weight α jt for the context c ( s ) t is computed using
|
| 107 |
+
|
| 108 |
+
<!-- formula-not-decoded -->
|
| 109 |
+
|
| 110 |
+
<!-- formula-not-decoded -->
|
| 111 |
+
|
| 112 |
+
where
|
| 113 |
+
|
| 114 |
+
The alignment model enables an attention to particular words, represented as a vector c ( s ) t in the source side. Since the decoder network generates responses on condition of the attention and also the intention, our model is called attention with intention (AWI) model.
|
| 115 |
+
|
| 116 |
+
## 3.5 Implementation details
|
| 117 |
+
|
| 118 |
+
All of the recurrent networks are implemented using a recently proposed depth-gated long-shortterm memory (LSTM) network [16]. The context vector c ( s ) t is an embedding vector of the source side word at time t .
|
| 119 |
+
|
| 120 |
+
Table 2: Perplexity results with AWI model. Models have 50 or 200 hidden layer dimension, 25 alignment dimension, and one layer of LSTMs.
|
| 121 |
+
|
| 122 |
+
| # hidden dimension PPL 50 30.8 200 22.1 |
|
| 123 |
+
|------------------------------------------------|
|
| 124 |
+
|
| 125 |
+
The alignment model in Eq. (8) follows the attention model in [1], in which e jt is calculated as
|
| 126 |
+
|
| 127 |
+
<!-- formula-not-decoded -->
|
| 128 |
+
|
| 129 |
+
which is a neural network with one hidden layer of size A and a single output, parameterised by W ( ae ) ∈ R A × H , W ( ah ) ∈ R A × H and ⃗ v ∈ R A . H and A are the hidden layer dimension and alignment dimension.
|
| 130 |
+
|
| 131 |
+
## 4 Evaluation
|
| 132 |
+
|
| 133 |
+
We used an in-house dialogue dataset. The dataset consists of dialogues from a helpdesk chat service. In this service, costumers seeks helps on computer related issues from human agents. Training consists of 10000 dialogues with 96913 turns or conversations. Number of tokens is 2215047 in the source side and 2378950 in the target side. The vocabulary size is 9085 including words from both side. Development set data has 1000 dialogues with 9971 turns. Test set data has 500 dialogues with 5232 turns.
|
| 134 |
+
|
| 135 |
+
We use sentence-level SGD without momentum. Learning rate is initialized to 0.1. Development set is used to control the learning rate. The learning rate is halved when perplexity on the development is increased. One epoch of training has one pass of the training data. The order of training dialogues is randomly shuffled in the beginning of each epoch. The order of turns in the dialogue is however kept.
|
| 136 |
+
|
| 137 |
+
## 4.1 Performances measure in perplexity
|
| 138 |
+
|
| 139 |
+
An objective comparison of different models for conversation is still an open question. We report perplexity (PPL), though it may have drawbacks, to compare different models. Table 2 presents results in perplexity with two models with different hiden layer sizes. Results show that a larger model with 200 hidden layer dimension has lower PPL than the model with 50 dimension.
|
| 140 |
+
|
| 141 |
+
## 4.2 Examples of outputs from the trained model
|
| 142 |
+
|
| 143 |
+
Table 3 lists an example of the conversation process between a human and the trained model. The model has two layers of LSTMs and other setups are the same as used in Sec 4.1. Similarly as observed in [11], the model produces natural responses to user inputs. The flow of intentions is clearly seen in this example.
|
| 144 |
+
|
| 145 |
+
## 5 Related work
|
| 146 |
+
|
| 147 |
+
Our work is related to the recent works in [10, 12, 14], which use an encoder-decoder framework to model conversation. The work in [10] is a model for single turn conversation. The work in [14] is a simple encoder-decoder method using a fixed-dimension representation of the source side. The work in [12] also uses a fixed-dimension representaiton of the source side but has an additional RNN to model dialogue context. This additional RNN is similar to the intention RNN in AWI model.
|
| 148 |
+
|
| 149 |
+
However, AWI model differs from [12] in that it incorprates the concept of attention and intention based on the theory in [7]. Therefore, attention mechanism is essential to AWI. The model in [12] doesn't have an attention model.
|
| 150 |
+
|
| 151 |
+
```
|
| 152 |
+
user hi agent how may i help you today ? user my computer is not responding agent oh ! i sorry to hear that . are you getting an error message ? user yes agent what recent changes did you made with this computer ? user i updated my computer agent i see . is this on windows 7 ? user no it is on linux agent ok . are you using the affected computer right now ? user no agent i can definitely assist you on your issue . user thanks agent we can go ahead and start working on this issue within our office premium software support service . user that is allright agent if in case the issue comes back at all within the next 30 days we will perform the service again for free . agent let me go ahead and prepare the offer and let start working on this issue now , alright ? user please agent sure . may i have your phone number please . user xxx-xxx-xxxx agent thank you . user no problem agent thank you for waiting . user no problem agent i see . user what is the next step agent i see . let me go ahead and prepare the offers for you . user okay agent thank you . user no problem agent thank you for contacting answer desk . have a great day ! user bye agent thanks again for working with me . id like to send you a quick survey . agent it starts with a yes/no question , with a few more questions about your experience with me today. agent the survey takes about a minute and really helps us improve our service . can i send it to you now ? user sure agent thank you . user no problem agent thank you for contacting answer desk . have a great day ! user bye agent goodbye .
|
| 153 |
+
```
|
| 154 |
+
|
| 155 |
+
Table 3: The generated response from the trained model.
|
| 156 |
+
|
| 157 |
+
Because it is not yet clear what objective measure to use to compare different models, it is hard to make claims of superiority of these models. We believe AWI model is an alternative to the models in [12, 14].
|
| 158 |
+
|
| 159 |
+
## 6 Conclusions and discussions
|
| 160 |
+
|
| 161 |
+
We have presented a model that incorporates attention and intention processes in a neural network model. Preliminary experiments show that this model generates natural responses to user inputs. Future works include experiments on common dataset to compare different models and incorporating objective functions such as goals.
|
| 162 |
+
|
| 163 |
+
## References
|
| 164 |
+
|
| 165 |
+
- [1] D. Bahdanau, K. Cho, and Y. Bengio. Neural machine translation by jointly learning to align and translate. In Proceedings of the International Conference on Learning Representations (ICLR) , San Diego, CA, 2015.
|
| 166 |
+
- [2] M. Bisani and H. Ney. Joint-sequence models for grapheme-to-phoneme conversion. Speech Communication , 50(5), 2008.
|
| 167 |
+
- [3] D. Bohus and A. I. Rudnicky. The ravenclaw dialog management framework: architecture and systems. Computer, Speech and Language , 23:332-361, 2009.
|
| 168 |
+
- [4] W. Chan, N. Jaitly, Q. V. Le, and O. Vinyals. Listen, attend and spell. In arXiv:1508.01211 [cs.CL] , 2015.
|
| 169 |
+
- [5] D. Chiang. Hierarchical phrase-based translation. Computational Linguistics , 33(2):201-228, 1999.
|
| 170 |
+
- [6] J. Devlin, R. Zbib, Z. Huang, T. Lamar, R. Schwartz, and J. Makhoul. Fast and robust neural network joint models for statistical machine translation. In ACL , 2014.
|
| 171 |
+
- [7] B. J. Grosz and C. L. Sidner. Attention, intentions, and the structure of discourse. Computational Linguistics , 12:175-204, 1986.
|
| 172 |
+
- [8] G. Mesnil, Y. Dauphin, K. Yao, Y. Bengio, L. Deng, D. Hakkani-Tur, X. He, L. Heck, G. Tur, D. Yu, and G. Zweig. Using recurrent neural networks for slot filling in spoken language understanding. IEEE/ACM Transactions on Audio, Speech, and Language Processing , 2015.
|
| 173 |
+
- [9] T. Mikolov, K. Chen, G. Corrado, and J. Dean. Effcient estimation of word representations in vector space. In NIPS , 2013.
|
| 174 |
+
- [10] L. Shang, Z. Lu, and H. Li. Neural responding machine for short-text conversation. In ACL , 2015.
|
| 175 |
+
- [11] A. Sordoni, Y. Bengio, H. Vahabi, C. Lioma, J. G. Simonsen, and J.-Y. Nie. A hierarchical recurrent encoder-decoder for generative context-aware query suggestion. In arXiv:1507-0222 [cd.NE] , July 2015.
|
| 176 |
+
- [12] A. Sordoni, M. Galley, M. Auli, C. Brockett, Y. Ji, M. Mitchell, J.-Y . Nie, J. Gao, and B. Dolan. A neural network approach to context-sensitive generation of conversation responses. In NAACL , 2015.
|
| 177 |
+
- [13] I. Sutskever, O. Vinyals, and Q. V. Le. Sequence to sequence learning with neural networks. In Neural Information Processing Systems (NIPS) , pages 3104-3112, Montr´ eal, 2014.
|
| 178 |
+
- [14] O. Vinyals and Q. V. Le. A nerual converstion model. In ICML Deep Learning Workshop , 2015.
|
| 179 |
+
- [15] T.-H. Wen, M. Gasic, D. Kim, N. Mrksic, P.-H. Su, D. Vandyke, and S. Young. Stochastic language generation in dialogue using recurrent neural networks with convolutional sentence reranking. Technical report, May 2015.
|
| 180 |
+
- [16] K. Yao, T. Cohn, E. Vylomova, K. Duh, and C. Dyer. Depth-gated LSTM. In arXiv:1508.03790 [cs.NE] , 2015.
|
| 181 |
+
- [17] K. Yao and G. Zweig. Sequence-to-sequence neural net models for grapheme-to-phoneme conversion. In INTERSPEECH , 2015.
|
| 182 |
+
- [18] S. Young, M. Gasic, B. Thomson, and J. D. Williams. POMDP-based statistical spoken dialog systems: A review. Proceedings of the IEEE, 101:1160-1179, 2013.
|
text-versions/attention-markdown/1612.01887_Knowing When to Look Adaptive Attention .md
ADDED
|
@@ -0,0 +1,367 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1612.01887 Knowing When To Look Adaptive Attention
|
| 2 |
+
|
| 3 |
+
## Knowing When to Look: Adaptive Attention via A Visual Sentinel for Image Captioning
|
| 4 |
+
|
| 5 |
+
Jiasen Lu 2 ∗† , Caiming Xiong 1 † , Devi Parikh 3 , Richard Socher 1 1 Salesforce Research, 2 Virginia Tech, 3 Georgia Institute of Technology
|
| 6 |
+
|
| 7 |
+
jiasenlu@vt.edu, parikh@gatech.edu, { cxiong, rsocher } @salesforce.com
|
| 8 |
+
|
| 9 |
+
## Abstract
|
| 10 |
+
|
| 11 |
+
Attention-based neural encoder-decoder frameworks have been widely adopted for image captioning. Most methods force visual attention to be active for every generated word. However, the decoder likely requires little to no visual information from the image to predict nonvisual words such as 'the' and 'of'. Other words that may seem visual can often be predicted reliably just from the language model e.g., 'sign' after 'behind a red stop' or 'phone' following 'talking on a cell'. In this paper, we propose a novel adaptive attention model with a visual sentinel. At each time step, our model decides whether to attend to the image (and if so, to which regions) or to the visual sentinel. The model decides whether to attend to the image and where, in order to extract meaningful information for sequential word generation. We test our method on the COCO image captioning 2015 challenge dataset and Flickr30K. Our approach sets the new state-of-the-art by a significant margin. The source code can be downloaded from https://github.com/jiasenlu/AdaptiveAttention
|
| 12 |
+
|
| 13 |
+
## 1. Introduction
|
| 14 |
+
|
| 15 |
+
Automatically generating captions for images has emerged as a prominent interdisciplinary research problem in both academia and industry. [8, 11, 18, 23, 27, 30]. It can aid visually impaired users, and make it easy for users to organize and navigate through large amounts of typically unstructured visual data. In order to generate high quality captions, the model needs to incorporate fine-grained visual clues from the image. Recently, visual attention-based neural encoder-decoder models [30, 11, 32] have been explored, where the attention mechanism typically produces a spatial map highlighting image regions relevant to each generated word.
|
| 16 |
+
|
| 17 |
+
Most attention models for image captioning and visual question answering attend to the image at every time step, irrespective of which word is going to be emitted next [31, 29, 17]. However, not all words in the caption have corresponding visual signals. Consider the example in Fig. 1 that shows an image and its generated caption 'A white bird perched on top of a red stop sign'. The words 'a' and 'of' do not have corresponding canonical visual signals. Moreover, language correlations make the visual signal unnecessary when generating words like 'on' and 'top' following 'perched', and 'sign' following 'a red stop'. In fact, gradients from non-visual words could mislead and diminish the overall effectiveness of the visual signal in guiding the caption generation process.
|
| 18 |
+
|
| 19 |
+
∗ The major part of this work was done while J. Lu was an intern at Salesforce Research.
|
| 20 |
+
|
| 21 |
+
† Equal contribution
|
| 22 |
+
|
| 23 |
+
Figure 1: Our model learns an adaptive attention model that automatically determines when to look ( sentinel gate ) and where to look ( spatial attention ) for word generation, which are explained in section 2.2, 2.3 & 5.4.
|
| 24 |
+
|
| 25 |
+
<!-- image -->
|
| 26 |
+
|
| 27 |
+
In this paper, we introduce an adaptive attention encoderdecoder framework which can automatically decide when to rely on visual signals and when to just rely on the language model. Of course, when relying on visual signals, the model also decides where - which image region - it should attend to. We first propose a novel spatial attention model for extracting spatial image features. Then as our proposed adaptive attention mechanism, we introduce a new Long Short Term Memory (LSTM) extension, which produces an additional ' visual sentinel ' vector instead of a single hidden state. The 'visual sentinel', an additional latent representa- tion of the decoder's memory, provides a fallback option to the decoder. We further design a new sentinel gate, which decides how much new information the decoder wants to get from the image as opposed to relying on the visual sentinel when generating the next word. For example, as illustrated in Fig. 1, our model learns to attend to the image more when generating words 'white', 'bird', 'red' and 'stop', and relies more on the visual sentinel when generating words 'top', 'of' and 'sign'.
|
| 28 |
+
|
| 29 |
+
Overall, the main contributions of this paper are:
|
| 30 |
+
|
| 31 |
+
- We introduce an adaptive encoder-decoder framework that automatically decides when to look at the image and when to rely on the language model to generate the next word.
|
| 32 |
+
- We first propose a new spatial attention model, and then build on it to design our novel adaptive attention model with 'visual sentinel'.
|
| 33 |
+
- Our model significantly outperforms other state-ofthe-art methods on COCO and Flickr30k.
|
| 34 |
+
- We perform an extensive analysis of our adaptive attention model, including visual grounding probabilities of words and weakly supervised localization of generated attention maps.
|
| 35 |
+
|
| 36 |
+
## 2. Method
|
| 37 |
+
|
| 38 |
+
We first describe the generic neural encoder-decoder framework for image captioning in Sec. 2.1, then introduce our proposed attention-based image captioning models in Sec. 2.2 & 2.3.
|
| 39 |
+
|
| 40 |
+
## 2.1. Encoder-Decoder for Image Captioning
|
| 41 |
+
|
| 42 |
+
Westart by briefly describing the encoder-decoder image captioning framework [27, 30]. Given an image and the corresponding caption, the encoder-decoder model directly maximizes the following objective:
|
| 43 |
+
|
| 44 |
+
<!-- formula-not-decoded -->
|
| 45 |
+
|
| 46 |
+
where θ are the parameters of the model, I is the image, and y = { y 1 , . . . , y t } is the corresponding caption. Using the chain rule, the log likelihood of the joint probability distribution can be decomposed into ordered conditionals:
|
| 47 |
+
|
| 48 |
+
<!-- formula-not-decoded -->
|
| 49 |
+
|
| 50 |
+
where we drop the dependency on model parameters for convenience.
|
| 51 |
+
|
| 52 |
+
In the encoder-decoder framework, with recurrent neural network (RNN), each conditional probability is modeled as:
|
| 53 |
+
|
| 54 |
+
<!-- formula-not-decoded -->
|
| 55 |
+
|
| 56 |
+
where f is a nonlinear function that outputs the probability of y t . c t is the visual context vector at time t extracted from image I . h t is the hidden state of the RNN at time t . In this paper, we adopt Long-Short Term Memory (LSTM) instead of a vanilla RNN. The former have demonstrated state-of-the-art performance on a variety of sequence modeling tasks. h t is modeled as:
|
| 57 |
+
|
| 58 |
+
<!-- formula-not-decoded -->
|
| 59 |
+
|
| 60 |
+
where x t is the input vector. m t -1 is the memory cell vector at time t -1 .
|
| 61 |
+
|
| 62 |
+
Commonly, context vector, c t is an important factor in the neural encoder-decoder framework, which provides visual evidence for caption generation [18, 27, 30, 34]. These different ways of modeling the context vector fall into two categories: vanilla encoder-decoder and attentionbased encoder-decoder frameworks:
|
| 63 |
+
|
| 64 |
+
- First, in the vanilla framework, c t is only dependent on the encoder, a Convolutional Neural Network (CNN). The input image I is fed into the CNN, which extracts the last fully connected layer as a global image feature [18, 27]. Across generated words, the context vector c t keeps constant, and does not depend on the hidden state of the decoder.
|
| 65 |
+
- Second, in the attention-based framework, c t is dependent on both encoder and decoder. At time t , based on the hidden state, the decoder would attend to the specific regions of the image and compute c t using the spatial image features from a convolution layer of a CNN. In [30, 34], they show that attention models can significantly improve the performance of image captioning.
|
| 66 |
+
|
| 67 |
+
To compute the context vector c t , we first propose our spatial attention model in Sec. 2.2, then extend the model to an adaptive attention model in Sec. 2.3.
|
| 68 |
+
|
| 69 |
+
## 2.2. Spatial Attention Model
|
| 70 |
+
|
| 71 |
+
First, we propose a spatial attention model for computing the context vector c t which is defined as:
|
| 72 |
+
|
| 73 |
+
<!-- formula-not-decoded -->
|
| 74 |
+
|
| 75 |
+
where g is the attention function, V = [ v 1 , . . . , v k ] , v i ∈ R d is the spatial image features, each of which is a d dimensional representation corresponding to a part of the image. h t is the hidden state of RNN at time t .
|
| 76 |
+
|
| 77 |
+
Given the spatial image feature V ∈ R d × k and hidden state h t ∈ R d of the LSTM, we feed them through a single layer neural network followed by a softmax function to generate the attention distribution over the k regions of the image:
|
| 78 |
+
|
| 79 |
+
<!-- formula-not-decoded -->
|
| 80 |
+
|
| 81 |
+
Figure 2: A illustration of soft attention model from [30] (a) and our proposed spatial attention model (b).
|
| 82 |
+
|
| 83 |
+
<!-- image -->
|
| 84 |
+
|
| 85 |
+
where ✶ ∈ R k is a vector with all elements set to 1. W v , W g ∈ R k × d and w h ∈ R k are parameters to be learnt. α ∈ R k is the attention weight over features in V . Based on the attention distribution, the context vector c t can be obtained by:
|
| 86 |
+
|
| 87 |
+
<!-- formula-not-decoded -->
|
| 88 |
+
|
| 89 |
+
where c t and h t are combined to predict next word y t +1 as in Equation 3.
|
| 90 |
+
|
| 91 |
+
Different from [30], shown in Fig. 2, we use the current hidden state h t to analyze where to look (i.e., generating the context vector c t ), then combine both sources of information to predict the next word. Our motivation stems from the superior performance of residual network [10]. The generated context vector c t could be considered as the residual visual information of current hidden state h t , which diminishes the uncertainty or complements the informativeness of the current hidden state for next word prediction. We also empirically find our spatial attention model performs better, as illustrated in Table 1.
|
| 92 |
+
|
| 93 |
+
## 2.3. Adaptive Attention Model
|
| 94 |
+
|
| 95 |
+
While spatial attention based decoders have proven to be effective for image captioning, they cannot determine when to rely on visual signal and when to rely on the language model. In this section, motivated from Merity et al . [19], we introduce a new concept - 'visual sentinel', which is a latent representation of what the decoder already knows. With the 'visual sentinel', we extend our spatial attention model, and propose an adaptive model that is able to determine whether it needs to attend the image to predict next word.
|
| 96 |
+
|
| 97 |
+
What is visual sentinel? The decoder's memory stores both long and short term visual and linguistic information. Our model learns to extract a new component from this that the model can fall back on when it chooses to not attend to the image. This new component is called the visual sentinel. And the gate that decides whether to attend to the image or to the visual sentinel is the sentinel gate. When the decoder RNNis an LSTM, we consider those information preserved in its memory cell. Therefore, we extend the LSTM to obtain the 'visual sentinel' vector s t by:
|
| 98 |
+
|
| 99 |
+
Figure 3: An illustration of the proposed model generating the t -th target word y t given the image.
|
| 100 |
+
|
| 101 |
+
<!-- image -->
|
| 102 |
+
|
| 103 |
+
<!-- formula-not-decoded -->
|
| 104 |
+
|
| 105 |
+
<!-- formula-not-decoded -->
|
| 106 |
+
|
| 107 |
+
where W x and W h are weight parameters to be learned, x t is the input to the LSTM at time step t , and g t is the gate applied on the memory cell m t . ⊙ represents the elementwise product and σ is the logistic sigmoid activation.
|
| 108 |
+
|
| 109 |
+
Based on the visual sentinel, we propose an adaptive attention model to compute the context vector. In our proposed architecture (see Fig. 3), our new adaptive context vector is defined as ˆ c t , which is modeled as a mixture of the spatially attended image features (i.e. context vector of spatial attention model) and the visual sentinel vector. This trades off how much new information the network is considering from the image with what it already knows in the decoder memory (i.e., the visual sentinel ). The mixture model is defined as follows:
|
| 110 |
+
|
| 111 |
+
<!-- formula-not-decoded -->
|
| 112 |
+
|
| 113 |
+
where β t is the new sentinel gate at time t . In our mixture model, β t produces a scalar in the range [0 , 1] . A value of 1 implies that only the visual sentinel information is used and 0 means only spatial image information is used when generating the next word.
|
| 114 |
+
|
| 115 |
+
To compute the new sentinel gate β t , we modified the spatial attention component. In particular, we add an additional element to z , the vector containing attention scores as defined in Equation 6. This element indicates how much 'attention' the network is placing on the sentinel (as opposed to the image features). The addition of this extra element is summarized by converting Equation 7 to:
|
| 116 |
+
|
| 117 |
+
<!-- formula-not-decoded -->
|
| 118 |
+
|
| 119 |
+
where [ · ; · ] indicates concatenation. W s and W g are weight parameters. Notably, W g is the same weight parameter as in Equation 6. ˆ α t ∈ R k +1 is the attention distribution over both the spatial image feature as well as the visual sentinel vector. We interpret the last element of this vector to be the gate value: β t = α t [ k +1] .
|
| 120 |
+
|
| 121 |
+
The probability over a vocabulary of possible words at time t can be calculated as:
|
| 122 |
+
|
| 123 |
+
<!-- formula-not-decoded -->
|
| 124 |
+
|
| 125 |
+
where W p is the weight parameters to be learnt.
|
| 126 |
+
|
| 127 |
+
This formulation encourages the model to adaptively attend to the image vs. the visual sentinel when generating the next word. The sentinel vector is updated at each time step. With this adaptive attention model, we call our framework the adaptive encoder-decoder image captioning framework.
|
| 128 |
+
|
| 129 |
+
## 3. Implementation Details
|
| 130 |
+
|
| 131 |
+
In this section, we describe the implementation details of our model and how we train our network.
|
| 132 |
+
|
| 133 |
+
Encoder-CNN. The encoder uses a CNN to get the representation of images. Specifically, the spatial feature outputs of the last convolutional layer of ResNet [10] are used, which have a dimension of 2048 × 7 × 7 . We use A = { a 1 , . . . , a k } , a i ∈ R 2048 to represent the spatial CNN features at each of the k grid locations. Following [10], the global image feature can be obtained by:
|
| 134 |
+
|
| 135 |
+
<!-- formula-not-decoded -->
|
| 136 |
+
|
| 137 |
+
where a g is the global image feature. For modeling convenience, we use a single layer perceptron with rectifier activation function to transform the image feature vector into new vectors with dimension d :
|
| 138 |
+
|
| 139 |
+
<!-- formula-not-decoded -->
|
| 140 |
+
|
| 141 |
+
<!-- formula-not-decoded -->
|
| 142 |
+
|
| 143 |
+
where W a and W g are the weight parameters. The transformed spatial image feature form V = [ v 1 , . . . , v k ] .
|
| 144 |
+
|
| 145 |
+
Decoder-RNN. We concatenate the word embedding vector w t and global image feature vector v g to get the input vector x t = [ w t ; v g ] . We use a single layer neural network to transform the visual sentinel vector s t and LSTM output vector h t into new vectors that have the dimension d .
|
| 146 |
+
|
| 147 |
+
Training details. In our experiments, we use a single layer LSTM with hidden size of 512. We use the Adam optimizer with base learning rate of 5e-4 for the language model and 1e-5 for the CNN. The momentum and weightdecay are 0.8 and 0.999 respectively. We finetune the CNN network after 20 epochs. We set the batch size to be 80 and train for up to 50 epochs with early stopping if the validation CIDEr [26] score had not improved over the last 6 epochs. Our model can be trained within 30 hours on a single Titan X GPU. We use beam size of 3 when sampling the caption for both COCO and Flickr30k datasets.
|
| 148 |
+
|
| 149 |
+
## 4. Related Work
|
| 150 |
+
|
| 151 |
+
Image captioning has many important applications ranging from helping visually impaired users to human-robot interaction. As a result, many different models have been developed for image captioning. In general, those methods can be divided into two categories: template-based [9, 13, 14, 20] and neural-based [12, 18, 6, 3, 27, 7, 11, 30, 8, 34, 32, 33].
|
| 152 |
+
|
| 153 |
+
Template-based approaches generate caption templates whose slots are filled in based on outputs of object detection, attribute classification, and scene recognition. Farhadi et al . [9] infer a triplet of scene elements which is converted to text using templates. Kulkarni et al . [13] adopt a Conditional Random Field (CRF) to jointly reason across objects, attributes, and prepositions before filling the slots. [14, 20] use more powerful language templates such as a syntactically well-formed tree, and add descriptive information from the output of attribute detection.
|
| 154 |
+
|
| 155 |
+
Neural-based approaches are inspired by the success of sequence-to-sequence encoder-decoder frameworks in machine translation [4, 24, 2] with the view that image captioning is analogous to translating images to text. Kiros et al . [12] proposed a feed forward neural network with a multimodal log-bilinear model to predict the next word given the image and previous word. Other methods then replaced the feed forward neural network with a recurrent neural network [18, 3]. Vinyals et al . [27] use an LSTM instead of a vanilla RNN as the decoder. However, all these approaches represent the image with the last fully connected layer of a CNN. Karpathy et al . [11] adopt the result of object detection from R-CNN and output of a bidirectional RNN to learn a joint embedding space for caption ranking and generation.
|
| 156 |
+
|
| 157 |
+
Recently, attention mechanisms have been introduced to encoder-decoder neural frameworks in image captioning. Xu et al . [30] incorporate an attention mechanism to learn a latent alignment from scratch when generating corresponding words. [28, 34] utilize high-level concepts or attributes and inject them into a neural-based approach as semantic attention to enhance image captioning. Yang et al . [32] extend current attention encoder-decoder frameworks using a review network, which captures the global properties in a compact vector representation and are usable by the attention mechanism in the decoder. Yao et al . [33] present variants of architectures for augmenting high-level attributes from images to complement image representation for sentence generation.
|
| 158 |
+
|
| 159 |
+
To the best of our knowledge, ours is the first work to reason about when a model should attend to an image when generating a sequence of words.
|
| 160 |
+
|
| 161 |
+
Table 1: Performance on Flickr30k and COCO test splits. † indicates ensemble models. B-n is BLEU score that uses up to n-grams. Higher is better in all columns. For future comparisons, our ROUGE-L/SPICE Flickr30k scores are 0.467/0.145 and the COCO scores are 0.549/0.194.
|
| 162 |
+
|
| 163 |
+
| Flickr30k MS-COCO Method B-1 B-2 B-3 B-4 METEOR CIDEr B-1 B-2 B-3 B-4 METEOR CIDEr DeepVS [11] 0.573 0.369 0.240 0.157 0.153 0.247 0.625 0.450 0.321 0.230 0.195 0.660 Hard-Attention [30] 0.669 0.439 0.296 0.199 0.185 - 0.718 0.504 0.357 0.250 0.230 - ATT-FCN † [34] 0.647 0.460 0.324 0.230 0.189 - 0.709 0.537 0.402 0.304 0.243 - ERD [32] - - - - - - - - - 0.298 0.240 0.895 MSM † [33] - - - - - - 0.730 0.565 0.429 0.325 0.251 0.986 Ours-Spatial 0.644 0.462 0.327 0.231 0.202 0.493 0.734 0.566 0.418 0.304 0.257 1.029 Ours-Adaptive 0.677 0.494 0.354 0.251 0.204 0.531 0.742 0.580 0.439 0.332 0.266 1.085 |
|
| 164 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 165 |
+
|
| 166 |
+
Table 2: Leaderboard of the published state-of-the-art image captioning models on the online COCO testing server. Our submission is a ensemble of 5 models trained with different initialization.
|
| 167 |
+
|
| 168 |
+
| B-1 B-2 B-3 B-4 METEOR ROUGE-L CIDEr Method c5 c40 c5 c40 c5 c40 c5 c40 c5 c40 c5 c40 c5 c40 Google NIC [27] 0.713 0.895 0.542 0.802 0.407 0.694 0.309 0.587 0.254 0.346 0.530 0.682 0.943 0.946 MS Captivator [8] 0.715 0.907 0.543 0.819 0.407 0.710 0.308 0.601 0.248 0.339 0.526 0.680 0.931 0.937 m-RNN [18] 0.716 0.890 0.545 0.798 0.404 0.687 0.299 0.575 0.242 0.325 0.521 0.666 0.917 0.935 LRCN [7] 0.718 0.895 0.548 0.804 0.409 0.695 0.306 0.585 0.247 0.335 0.528 0.678 0.921 0.934 Hard-Attention [30] 0.705 0.881 0.528 0.779 0.383 0.658 0.277 0.537 0.241 0.322 0.516 0.654 0.865 0.893 ATT-FCN [34] 0.731 0.900 0.565 0.815 0.424 0.709 0.316 0.599 0.250 0.335 0.535 0.682 0.943 0.958 ERD [32] 0.720 0.900 0.550 0.812 0.414 0.705 0.313 0.597 0.256 0.347 0.533 0.686 0.965 0.969 MSM[33] 0.739 0.919 0.575 0.842 0.436 0.740 0.330 0.632 0.256 0.350 0.542 0.700 0.984 1.003 Ours-Adaptive 0.748 0.920 0.584 0.845 0.444 0.744 0.336 0.637 0.264 0.359 0.550 0.705 1.042 1.059 |
|
| 169 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 170 |
+
|
| 171 |
+
## 5. Results
|
| 172 |
+
|
| 173 |
+
## 5.1. Experiment Settings
|
| 174 |
+
|
| 175 |
+
We experiment with two datasets: Flickr30k [35] and COCO [16].
|
| 176 |
+
|
| 177 |
+
Flickr30k contains 31,783 images collected from Flickr. Most of these images depict humans performing various activities. Each image is paired with 5 crowd-sourced captions. We use the publicly available splits 1 containing 1,000 images for validation and test each.
|
| 178 |
+
|
| 179 |
+
COCO is the largest image captioning dataset, containing 82,783, 40,504 and 40,775 images for training, validation and test respectively. This dataset is more challenging, since most images contain multiple objects in the context of complex scenes. Each image has 5 human annotated captions. For offline evaluation, we use the same data split as in [11, 30, 34] containing 5000 images for validation and test each. For online evaluation on the COCO evaluation server, we reserve 2000 images from validation for development and the rest for training.
|
| 180 |
+
|
| 181 |
+
Pre-processing. We truncate captions longer than 18
|
| 182 |
+
|
| 183 |
+
1 https://github.com/karpathy/neuraltalk
|
| 184 |
+
|
| 185 |
+
words for COCO and 22 for Flickr30k. We then build a vocabulary of words that occur at least 5 and 3 times in the training set, resulting in 9567 and 7649 words for COCO and Flickr30k respectively.
|
| 186 |
+
|
| 187 |
+
Compared Approaches: For offline evaluation on Flickr30k and COCO, we first compare our full model ( Ours-Adaptive ) with an ablated version ( Ours-Spatial ), which only performs the spatial attention. The goal of this comparison is to verify that our improvements are not the result of orthogonal contributions (e.g. better CNN features or better optimization). We further compare our method with DeepVS [11], Hard-Attention [30] and recently proposed ATT [34], ERD [32] and best performed method (LSTM-A 5 ) of MSM [33]. For online evaluation, we compare our method with Google NIC [27], MS Captivator [8], m-RNN [18], LRCN [7], Hard-Attention [30], ATTFCN [34], ERD [32] and MSM [33].
|
| 188 |
+
|
| 189 |
+
## 5.2. Quantitative Analysis
|
| 190 |
+
|
| 191 |
+
We report results using the COCO captioning evaluation tool [16], which reports the following metrics: BLEU [21], Meteor [5], Rouge-L [15] and CIDEr [26]. We also report results using the new metric SPICE [1], which was found to better correlate with human judgments.
|
| 192 |
+
|
| 193 |
+
Table 1 shows results on the Flickr30k and COCO datasets. Comparing the full model w.r.t ablated versions without visual sentinel verifies the effectiveness of the proposed framework. Our adaptive attention model significantly outperforms spatial attention model, which improves the CIDEr score from 0.493/1.029 to 0.531/1.085 on Flickr30k and COCO respectively. When comparing with previous methods, we can see that our single model significantly outperforms all previous methods in all metrics. On COCO, our approach improves the state-of-the-art on BLEU-4 from 0.325 (MSM † ) to 0.332, METEOR from 0.251 (MSM † ) to 0.266, and CIDEr from 0.986 (MSM † ) to 1.085. Similarly, on Flickr30k, our model improves the state-of-the-art with a large margin.
|
| 194 |
+
|
| 195 |
+
Figure 4: Visualization of generated captions and image attention maps on the COCO dataset. Different colors show a correspondence between attended regions and underlined words. First 2 columns are success cases, last columns are failure examples. Best viewed in color.
|
| 196 |
+
|
| 197 |
+
<!-- image -->
|
| 198 |
+
|
| 199 |
+
We compare our model to state-of-the-art systems on the COCO evaluation server in Table 2. We can see that our approach achieves the best performance on all metrics among the published systems. Notably, Google NIC, ERDand MSM use Inception-v3 [25] as the encoder, which has similar or better classification performance compared to ResNet-152 [10] (which is what our model uses).
|
| 200 |
+
|
| 201 |
+
## 5.3. Qualitative Analysis
|
| 202 |
+
|
| 203 |
+
To better understand our model, we first visualize the spatial attention weight α for different words in the generated caption. We simply upsample the attention weight to the image size ( 224 × 224 ) using bilinear interpolation. Fig. 4 shows generated captions and the spatial attention maps for specific words in the caption. First two columns are success examples and the last one column shows failure examples. We see that our model learns alignments that correspond strongly with human intuition. Note that even in cases where the model produces inaccurate captions, we see that our model does look at reasonable regions in the image - it just seems to not be able to count or recognize texture and fine-grained categories. We provide a more extensive list of visualizations in supplementary material.
|
| 204 |
+
|
| 205 |
+
We further visualize the sentinel gate as a caption is generated. For each word, we use 1 -β as its visual grounding probability. In Fig. 5, we visualize the generated caption, the visual grounding probability and the spatial attention map generated by our model for each word. Our model successfully learns to attend to the image less when generating non-visual words such as 'of' and 'a'. For visual words like 'red', 'rose', 'doughnuts', 'woman' and 'snowboard', our model assigns a high visual grounding probabilities (over 0.9). Note that the same word may be assigned different visual grounding probabilities when generated in different contexts. For example, the word 'a' usually has a high visual grounding probability at the beginning of a sentence, since without any language context, the model needs the visual information to determine plurality (or not). On the other hand, the visual grounding probability of 'a' in the phrase 'on a table' is much lower. Since it is unlikely for something to be on more than one table.
|
| 206 |
+
|
| 207 |
+
Figure 5: Visualization of generated captions, visual grounding probabilities of each generated word, and corresponding spatial attention maps produced by our model.
|
| 208 |
+
|
| 209 |
+
<!-- image -->
|
| 210 |
+
|
| 211 |
+
Figure 6: Rank-probability plots on COCO (left) and Flickr30k (right) indicating how likely a word is to be visually grounded when it is generated in a caption.
|
| 212 |
+
|
| 213 |
+
<!-- image -->
|
| 214 |
+
|
| 215 |
+
## 5.4. Adaptive Attention Analysis
|
| 216 |
+
|
| 217 |
+
In this section, we analysis the adaptive attention generated by our methods. We visualize the sentinel gate to understand 'when' our model attends to the image as a caption is generated. We also perform a weakly-supervised localization on COCO categories by using the generated attention maps. This can help us to get an intuition of 'where' our model attends, and whether it attends to the correct regions.
|
| 218 |
+
|
| 219 |
+
## 5.4.1 Learning 'when' to attend
|
| 220 |
+
|
| 221 |
+
In order to assess whether our model learns to separate visual words in captions from non-visual words, we visualize the visual grounding probability. For each word in the vocabulary, we average the visual grounding probability over all the generated captions containing that word. Fig. 6 shows the rank-probability plot on COCO and Flickr30k.
|
| 222 |
+
|
| 223 |
+
We find that our model attends to the image more when generating object words like 'dishes', 'people', 'cat', 'boat'; attribute words like 'giant', 'metal', 'yellow' and number words like 'three'. When the word is non-visual, our model learns to not attend to the image such as for 'the', 'of', 'to' etc. For more abstract notions such as 'crossing', 'during' etc., our model leans to attend less than the visual words and attend more than the non-visual words. Note that our model does not rely on any syntactic features or external knowledge. It discovers these trends automatically.
|
| 224 |
+
|
| 225 |
+
Figure 7: Localization accuracy over generated captions for top 45 most frequent COCO object categories. 'Spatial Attention' and 'Adaptive Attention' are our proposed spatial attention model and adaptive attention model, respectively. The COCO categories are ranked based on the align results of our adaptive attention, which cover 93.8% and 94.0% of total matched regions for spatial attention and adaptive attention, respectively.
|
| 226 |
+
|
| 227 |
+
<!-- image -->
|
| 228 |
+
|
| 229 |
+
Our model cannot distinguish between words that are truly non-visual from the ones that are technically visual but have a high correlation with other words and hence chooses to not rely on the visual signal. For example, words such as 'phone' get a relatively low visual grounding probability in our model. This is because it has a large language correlation with the word 'cell'. We can also observe some interesting trends in what the model learns on different datasets. For example, when generating 'UNK' words, our model learns to attend less to the image on COCO, but more on Flickr30k. Same words with different forms can also results in different visual grounding probabilities. For example, 'crossing', 'cross' and 'crossed' are cognate words which have similar meaning. However, in terms of the visual grounding probability learnt by our model, there is a large variance. Our model learns to attend to images more when generating 'crossing', followed by 'cross' and attend least on image when generating 'crossed'.
|
| 230 |
+
|
| 231 |
+
## 5.4.2 Learning 'where' to attend
|
| 232 |
+
|
| 233 |
+
Wenowassess whether our model attends to the correct spatial image regions. We perform weakly-supervised localization [22, 36] using the generated attention maps. To the best of our best knowledge, no previous works have used weakly supervised localization to evaluate spatial attention for image captioning. Given the word w t and attention map α t , we first segment the regions of of the image with attention values larger than th (after map is normalized to have the largest value be 1), where th is a per-class threshold estimated using the COCO validation split. Then we take the bounding box that covers the largest connected component in the segmentation map. We use intersection over union (IOU) of the generated and ground truth bounding box as the localization accuracy.
|
| 234 |
+
|
| 235 |
+
For each of the COCO object categories, we do a word- by-word match to align the generated words with the ground truth bounding box. For the object categories which has multiple words, such as 'teddy bear', we take the maximum IOU score over the multiple words as its localization accuracy. We are able to align 5981 and 5924 regions for captions generated by the spatial and adaptive attention models respectively. The average localization accuracy for our spatial attention model is 0.362 , and 0.373 for our adaptive attention model. This demonstrates that as a byproduct, knowing when to attend also helps where to attend.
|
| 236 |
+
|
| 237 |
+
Fig. 7 shows the localization accuracy over the generated captions for top 45 most frequent COCO object categories. We can see that our spatial attention and adaptive attention models share similar trends. We observe that both models perform well on categories such as 'cat', 'bed', 'bus' and 'truck'. On smaller objects, such as 'sink', 'surfboard', 'clock' and 'frisbee', both models perform relatively poorly. This is because our spatial attention maps are directly rescaled from a coarse 7 × 7 feature map, which looses a lot of spatial resolution and detail. Using a larger feature map may improve the performance.
|
| 238 |
+
|
| 239 |
+
## 6. Conclusion
|
| 240 |
+
|
| 241 |
+
In this paper, we present a novel adaptive attention encoder-decoder framework, which provides a fallback option to the decoder. We further introduce a new LSTM extension, which produces an additional 'visual sentinel'. Our model achieves state-of-the-art performance across standard benchmarks on image captioning. We perform extensive attention evaluation to analysis our adaptive attention. Though our model is evaluated on image captioning, it can have useful applications in other domains.
|
| 242 |
+
|
| 243 |
+
Acknowledgements This work was funded in part by an NSF CAREER award, ONR YIP award, Sloan Fellowship, ARO YIP award, Allen Distinguished Investigrator award from the Paul G. Allen Family Foundation, Google Faculty Research Award, Amazon Academic Research Award to DP
|
| 244 |
+
|
| 245 |
+
## References
|
| 246 |
+
|
| 247 |
+
- [1] P. Anderson, B. Fernando, M. Johnson, and S. Gould. Spice: Semantic propositional image caption evaluation. In ECCV , 2016.
|
| 248 |
+
- [2] D. Bahdanau, K. Cho, and Y. Bengio. Neural machine translation by jointly learning to align and translate. arXiv preprint arXiv:1409.0473 , 2014.
|
| 249 |
+
- [3] X. Chen and C. Lawrence Zitnick. Mind's eye: A recurrent visual representation for image caption generation. In CVPR , 2015.
|
| 250 |
+
- [4] K. Cho, B. Van Merri¨ enboer, C. Gulcehre, D. Bahdanau, F. Bougares, H. Schwenk, and Y. Bengio. Learning phrase representations using rnn encoder-decoder for statistical machine translation. arXiv preprint arXiv:1406.1078 , 2014.
|
| 251 |
+
- [5] M. Denkowski and A. Lavie. Meteor universal: Language specific translation evaluation for any target language. In EACL 2014 Workshop on Statistical Machine Translation , 2014.
|
| 252 |
+
- [6] J. Devlin, S. Gupta, R. Girshick, M. Mitchell, and C. L. Zitnick. Exploring nearest neighbor approaches for image captioning. arXiv preprint arXiv:1505.04467 , 2015.
|
| 253 |
+
- [7] J. Donahue, L. Anne Hendricks, S. Guadarrama, M. Rohrbach, S. Venugopalan, K. Saenko, and T. Darrell. Long-term recurrent convolutional networks for visual recognition and description. In CVPR , 2015.
|
| 254 |
+
- [8] H. Fang, S. Gupta, F. Iandola, R. K. Srivastava, L. Deng, P. Doll´ ar, J. Gao, X. He, M. Mitchell, J. C. Platt, et al. From captions to visual concepts and back. In CVPR , 2015.
|
| 255 |
+
- [9] A. Farhadi, M. Hejrati, M. A. Sadeghi, P. Young, C. Rashtchian, J. Hockenmaier, and D. Forsyth. Every picture tells a story: Generating sentences from images. In ECCV , 2010.
|
| 256 |
+
- [10] K. He, X. Zhang, S. Ren, and J. Sun. Deep residual learning for image recognition. In CVPR , 2016.
|
| 257 |
+
- [11] A. Karpathy and L. Fei-Fei. Deep visual-semantic alignments for generating image descriptions. In CVPR , 2015.
|
| 258 |
+
- [12] R. Kiros, R. Salakhutdinov, and R. S. Zemel. Multimodal neural language models. In ICML , 2014.
|
| 259 |
+
- [13] G. Kulkarni, V. Premraj, V. Ordonez, S. Dhar, S. Li, Y. Choi, A. C. Berg, and T. L. Berg. Babytalk: Understanding and generating simple image descriptions. In CVPR , 2011.
|
| 260 |
+
- [14] P. Kuznetsova, V. Ordonez, A. C. Berg, T. L. Berg, and Y. Choi. Collective generation of natural image descriptions. In ACL , 2012.
|
| 261 |
+
- [15] C.-Y. Lin. Rouge: A package for automatic evaluation of summaries. In ACL 2004 Workshop , 2004.
|
| 262 |
+
- [16] T.-Y. Lin, M. Maire, S. Belongie, J. Hays, P. Perona, D. Ramanan, P. Doll´ ar, and C. L. Zitnick. Microsoft coco: Common objects in context. In ECCV , 2014.
|
| 263 |
+
- [17] J. Lu, J. Yang, D. Batra, and D. Parikh. Hierarchical question-image co-attention for visual question answering. In NIPS , 2016.
|
| 264 |
+
- [18] J. Mao, W. Xu, Y. Yang, J. Wang, Z. Huang, and A. Yuille. Deep captioning with multimodal recurrent neural networks (m-rnn). In ICLR , 2015.
|
| 265 |
+
- [19] S. Merity, C. Xiong, J. Bradbury, and R. Socher. Pointer sentinel mixture models. arXiv preprint arXiv:1609.07843 , 2016.
|
| 266 |
+
- [20] M. Mitchell, X. Han, J. Dodge, A. Mensch, A. Goyal, A. Berg, K. Yamaguchi, T. Berg, K. Stratos, and H. Daum´ e III. Midge: Generating image descriptions from computer vision detections. In EACL , 2012.
|
| 267 |
+
- [21] K. Papineni, S. Roukos, T. Ward, and W.-J. Zhu. Bleu: a method for automatic evaluation of machine translation. In ACL , 2002.
|
| 268 |
+
- [22] R. R.Selvaraju, A. Das, R. Vedantam, M. Cogswell, D. Parikh, and D. Batra. Grad-cam: Why did you say that? visual explanations from deep networks via gradient-based localization. arXiv:1611.01646 , 2016.
|
| 269 |
+
- [23] R. Socher, A. Karpathy, Q. V. Le, C. D. Manning, and A. Y. Ng. Grounded compositional semantics for finding and describing images with sentences. 2014.
|
| 270 |
+
- [24] I. Sutskever, O. Vinyals, and Q. V. Le. Sequence to sequence learning with neural networks. In NIPS , 2014.
|
| 271 |
+
- [25] C. Szegedy, V. Vanhoucke, S. Ioffe, J. Shlens, and Z. Wojna. Rethinking the inception architecture for computer vision. arXiv preprint arXiv:1512.00567 , 2015.
|
| 272 |
+
- [26] R. Vedantam, C. Lawrence Zitnick, and D. Parikh. Cider: Consensus-based image description evaluation. In CVPR , 2015.
|
| 273 |
+
- [27] O. Vinyals, A. Toshev, S. Bengio, and D. Erhan. Show and tell: A neural image caption generator. In CVPR , 2015.
|
| 274 |
+
- [28] Q. Wu, C. Shen, L. Liu, A. Dick, and A. v. d. Hengel. What value do explicit high level concepts have in vision to language problems? arXiv preprint arXiv:1506.01144 , 2015.
|
| 275 |
+
- [29] C. Xiong, S. Merity, and R. Socher. Dynamic memory networks for visual and textual question answering. In ICML , 2016.
|
| 276 |
+
- [30] K. Xu, J. Ba, R. Kiros, K. Cho, A. Courville, R. Salakhutdinov, R. Zemel, and Y. Bengio. Show, attend and tell: Neural image caption generation with visual attention. In ICML , 2015.
|
| 277 |
+
- [31] Z. Yang, X. He, J. Gao, L. Deng, and A. Smola. Stacked attention networks for image question answering. In CVPR , 2016.
|
| 278 |
+
- [32] Z. Yang, Y. Yuan, Y. Wu, R. Salakhutdinov, and W. W. Cohen. Encode, review, and decode: Reviewer module for caption generation. In NIPS , 2016.
|
| 279 |
+
- [33] T. Yao, Y. Pan, Y. Li, Z. Qiu, and T. Mei. Boosting image captioning with attributes. arXiv preprint arXiv:1611.01646 , 2015.
|
| 280 |
+
- [34] Q. You, H. Jin, Z. Wang, C. Fang, and J. Luo. Image captioning with semantic attention. In CVPR , 2016.
|
| 281 |
+
- [35] P. Young, A. Lai, M. Hodosh, and J. Hockenmaier. From image descriptions to visual denotations: New similarity metrics for semantic inference over event descriptions. In ACL , 2014.
|
| 282 |
+
- [36] B. Zhou, A. Khosla, A. Lapedriza, A. Oliva, and A. Torralba. Learning deep features for discriminative localization. arXiv preprint arXiv:1512.04150 , 2015.
|
| 283 |
+
|
| 284 |
+
## 7. Supplementary
|
| 285 |
+
|
| 286 |
+
## 7.1. COCO Categories Mapping List for WeaklySupervised Localization
|
| 287 |
+
|
| 288 |
+
We first use WordNetLemmatizer from NLTK 2 to lemmatize each word of the caption. Then we map 'people', 'woman', 'women', 'boy', 'girl', 'man', 'men', 'player','baby' to COCO ' person ' category; 'plane', 'jetliner', 'jet' to COCO ' airplane ' category; 'bike' to COCO ' bicycle ' category; 'taxi' to COCO ' car ' category. We also change the COCO category name from ' dining table ' to 'table' while evaluation. For the rest categories, we keep their original names. We show the visualization of bounding box in Fig. 8
|
| 289 |
+
|
| 290 |
+
## 7.2. Analysis on the gradient of non-visual words
|
| 291 |
+
|
| 292 |
+
In the experiments in Table 1 in the main paper, we show the effectiveness of visual sentinel in the ablation study comparing spatial attention (no visual sentinel) vs. spatial attention+visual sentinel. To further demonstrate the intuition, we have run additional experiments. In Fig. 8 we see that without visual sentinel, the attention for the non-visual word 'of' spreads around the boundary (corner) of image. Clearly, this would result in a noisy signal being propagated through the network. Interestingly, the visual grounding probability for 'of' in our model (with visual sentinel) is small. This restricts the noisy signal from Fig. 8 from backpropagating to the visual attention model.
|
| 293 |
+
|
| 294 |
+
Figure 8: Image attention visualization of word 'of' on several images. For each image pair, left: output of spatial attention model (no visual sentinel), right: output of our adaptive attention model (with visual sentinel).
|
| 295 |
+
|
| 296 |
+
<!-- image -->
|
| 297 |
+
|
| 298 |
+
## 7.3. Adaptive attention across different datasets
|
| 299 |
+
|
| 300 |
+
We show the visual grounding probability for the same words across COCO and Flickr30 datasets in Table 3. Trends are generally similar between the two datasets. To quantify this, we sort all common words between the two datasets by their visual grounding probabilities from both datasets. The rank correlation is 0.483. Words like 'sheep' and 'railing' have high visual grounding in COCO but not in Flickr30K, while 'hair' and 'run' are the reverse. Apart from different distributions of visual entities present in the dataset, some differences may be a consequence of different amounts of training data. Will add this to the paper.
|
| 301 |
+
|
| 302 |
+
## 7.4. More Visualization of Attention
|
| 303 |
+
|
| 304 |
+
Fig 9 and Fig 10 show additional visualization of spatial and temporal attention.
|
| 305 |
+
|
| 306 |
+
2 http://www.nltk.org/
|
| 307 |
+
|
| 308 |
+
Table 3: Visual grounding probabilities of the same word on COCO and Flickr30K datasets.
|
| 309 |
+
|
| 310 |
+
<!-- image -->
|
| 311 |
+
|
| 312 |
+
| Dataset giant people bus metal umbrella lake yellow on the UNK full says of up COCO 0.921 0.917 0.868 0.856 0.843 0.837 0.827 0.713 0.685 0.654 0.622 0.612 0.541 0.527 Flickr30K 0.947 0.856 0.914 0.889 0.830 0.791 0.869 0.702 0.726 0.803 0.445 0.586 0.510 0.652 |
|
| 313 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 314 |
+
|
| 315 |
+
## 7.5. Visualization of Weakly Supervised Localization
|
| 316 |
+
|
| 317 |
+
Fig 11 shows the visualization of weakly supervised localization.
|
| 318 |
+
|
| 319 |
+
Figure 9: Visualization of generated captions and image attention maps on the COCO dataset. Different colors show a correspondence between attended regions and underlined words.
|
| 320 |
+
|
| 321 |
+
<!-- image -->
|
| 322 |
+
|
| 323 |
+
Figure 10: Example of generated caption, spatial attention and visual grounding probability.
|
| 324 |
+
|
| 325 |
+
<!-- image -->
|
| 326 |
+
|
| 327 |
+
<!-- image -->
|
| 328 |
+
|
| 329 |
+
a man sitting on top of a wooden bench.
|
| 330 |
+
|
| 331 |
+
<!-- image -->
|
| 332 |
+
|
| 333 |
+
a herd of elephants standing next to each other.
|
| 334 |
+
|
| 335 |
+
<!-- image -->
|
| 336 |
+
|
| 337 |
+
a red and white us parked in front of a building.
|
| 338 |
+
|
| 339 |
+
<!-- image -->
|
| 340 |
+
|
| 341 |
+
a man laying on a couch holding a remote control.
|
| 342 |
+
|
| 343 |
+
<!-- image -->
|
| 344 |
+
|
| 345 |
+
a piece of cake sitting on top of a white plate.
|
| 346 |
+
|
| 347 |
+
<!-- image -->
|
| 348 |
+
|
| 349 |
+
a boat sitting on top of a sandy beach.
|
| 350 |
+
|
| 351 |
+
<!-- image -->
|
| 352 |
+
|
| 353 |
+
a man riding skis down a snow covered slope.
|
| 354 |
+
|
| 355 |
+
<!-- image -->
|
| 356 |
+
|
| 357 |
+
a man riding a skateboard up the side of a ramp.
|
| 358 |
+
|
| 359 |
+
a parking meter sitting on the side of a road.
|
| 360 |
+
|
| 361 |
+
<!-- image -->
|
| 362 |
+
|
| 363 |
+
a black bird sitting on top of a wooden bench.
|
| 364 |
+
|
| 365 |
+
<!-- image -->
|
| 366 |
+
|
| 367 |
+
Figure 11: Visualization of generated captions and weakly supervised localization result. Red bounding box is the ground truth annotation, blue bounding box is the predicted location using spatial attention map.
|
text-versions/attention-markdown/1704.06567_Attention Strategies for MultiSource Seq.md
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1704.06567 Attention Strategies For Multisource Seq
|
| 2 |
+
|
| 3 |
+
## Attention Strategies for Multi-Source Sequence-to-Sequence Learning
|
| 4 |
+
|
| 5 |
+
Jindˇ rich Libovick´ y and Jindˇ rich Helcl
|
| 6 |
+
|
| 7 |
+
Charles University, Faculty of Mathematics and Physics Institute of Formal and Applied Linguistics Malostransk´ e n´ amˇ est´ ı 25, 118 00 Prague, Czech Republic
|
| 8 |
+
|
| 9 |
+
{ libovicky, helcl } @ufal.mff.cuni.cz
|
| 10 |
+
|
| 11 |
+
## Abstract
|
| 12 |
+
|
| 13 |
+
Modeling attention in neural multi-source sequence-to-sequence learning remains a relatively unexplored area, despite its usefulness in tasks that incorporate multiple source languages or modalities. We propose two novel approaches to combine the outputs of attention mechanisms over each source sequence, fl at and hierarchical . We compare the proposed methods with existing techniques and present results of systematic evaluation of those methods on the WMT16 Multimodal Translation and Automatic Post-editing tasks. We show that the proposed methods achieve competitive results on both tasks.
|
| 14 |
+
|
| 15 |
+
## 1 Introduction
|
| 16 |
+
|
| 17 |
+
Sequence-to-sequence (S2S) learning with attention mechanism recently became the most successful paradigm with state-of-the-art results in machine translation (MT) (Bahdanau et al., 2014; Sennrich et al., 2016a), image captioning (Xu et al., 2015; Lu et al., 2016), text summarization (Rush et al., 2015) and other NLP tasks.
|
| 18 |
+
|
| 19 |
+
All of the above applications of S2S learning make use of a single encoder. Depending on the modality, it can be either a recurrent neural network (RNN) for textual input data, or a convolutional network for images.
|
| 20 |
+
|
| 21 |
+
In this work, we focus on a special case of S2S learning with multiple input sequences of possibly different modalities and a single output-generating recurrent decoder. We explore various strategies the decoder can employ to attend to the hidden states of the individual encoders.
|
| 22 |
+
|
| 23 |
+
The existing approaches to this problem do not explicitly model different importance of the inputs to the decoder (Firat et al., 2016; Zoph and Knight,
|
| 24 |
+
|
| 25 |
+
2016). In multimodal MT (MMT), where an image and its caption are on the input, we might expect the caption to be the primary source of information, whereas the image itself would only play a role in output disambiguation. In automatic post-editing (APE), where a sentence in a source language and its automatically generated translation are on the input, we might want to attend to the source text only in case the model decides that there is an error in the translation.
|
| 26 |
+
|
| 27 |
+
We propose two interpretable attention strategies that take into account the roles of the individual source sequences explicitly-flat and hierarchical attention combination.
|
| 28 |
+
|
| 29 |
+
This paper is organized as follows: In Section 2, we review the attention mechanism in single-source S2S learning. Section 3 introduces new attention combination strategies. In Section 4, we evaluate the proposed models on the MMT and APEtasks. We summarize the related work in Section 5, and conclude in Section 6.
|
| 30 |
+
|
| 31 |
+
## 2 Attentive S2S Learning
|
| 32 |
+
|
| 33 |
+
The attention mechanism in S2S learning allows an RNN decoder to directly access information about the input each time before it emits a symbol. Inspired by content-based addressing in Neural Turing Machines (Graves et al., 2014), the attention mechanism estimates a probability distribution over the encoder hidden states in each decoding step. This distribution is used for computing the context vector-the weighted average of the encoder hidden states-as an additional input to the decoder.
|
| 34 |
+
|
| 35 |
+
The standard attention model as described by Bahdanau et al. (2014) defines the attention energies e ij , attention distribution α ij , and the con- text vector c i in i -th decoder step as:
|
| 36 |
+
|
| 37 |
+
<!-- formula-not-decoded -->
|
| 38 |
+
|
| 39 |
+
<!-- formula-not-decoded -->
|
| 40 |
+
|
| 41 |
+
<!-- formula-not-decoded -->
|
| 42 |
+
|
| 43 |
+
<!-- formula-not-decoded -->
|
| 44 |
+
|
| 45 |
+
The trainable parameters W a and U a are projection matrices that transform the decoder and encoder states s i and h j into a common vector space and v a is a weight vector over the dimensions of this space. T x denotes the length of the input sequence. For the sake of clarity, bias terms (applied every time a vector is linearly projected using a weight matrix) are omitted.
|
| 46 |
+
|
| 47 |
+
Recently, Lu et al. (2016) introduced sentinel gate , an extension of the attentive RNN decoder with LSTM units (Hochreiter and Schmidhuber, 1997). We adapt the extension for gated recurrent units (GRU) (Cho et al., 2014), which we use in our experiments:
|
| 48 |
+
|
| 49 |
+
<!-- formula-not-decoded -->
|
| 50 |
+
|
| 51 |
+
where W y and W s are trainable parameters, y i is the embedded decoder input, and s i -1 is the previous decoder state.
|
| 52 |
+
|
| 53 |
+
Analogically to Equation 1, we compute a scalar energy term for the sentinel:
|
| 54 |
+
|
| 55 |
+
<!-- formula-not-decoded -->
|
| 56 |
+
|
| 57 |
+
where W a , U ( ψ ) a are the projection matrices, v a is the weight vector, and ψ i ⊙ s i is the sentinel vector. Note that the sentinel energy term does not depend on any hidden state of any encoder. The sentinel vector is projected to the same vector space as the encoder state h j in Equation 1. The term e ψ i is added as an extra attention energy term to Equation 2 and the sentinel vector ψ i ⊙ s i is used as the corresponding vector in the summation in Equation 3.
|
| 58 |
+
|
| 59 |
+
This technique should allow the decoder to choose whether to attend to the encoder or to focus on its own state and act more like a language model. This can be beneficial if the encoder does not contain much relevant information for the current decoding step.
|
| 60 |
+
|
| 61 |
+
## 3 Attention Combination
|
| 62 |
+
|
| 63 |
+
In S2S models with multiple encoders, the decoder needs to be able to combine the attention information collected from the encoders.
|
| 64 |
+
|
| 65 |
+
Awidely adopted technique for combining multiple attention models in a decoder is concatenation of the context vectors c (1) i , . . . , c ( N ) i (Zoph and Knight, 2016; Firat et al., 2016). As mentioned in Section 1, this setting forces the model to attend to each encoder independently and lets the attention combination to be resolved implicitly in the subsequent network layers.
|
| 66 |
+
|
| 67 |
+
In this section, we propose two alternative strategies of combining attentions from multiple encoders. We either let the decoder learn the α i distribution jointly over all encoder hidden states (fl at attention combination) or factorize the distribution over individual encoders ( hierarchical combination).
|
| 68 |
+
|
| 69 |
+
Both of the alternatives allow us to explicitly compute distribution over the encoders and thus interpret how much attention is paid to each encoder at every decoding step.
|
| 70 |
+
|
| 71 |
+
## 3.1 Flat Attention Combination
|
| 72 |
+
|
| 73 |
+
Flat attention combination projects the hidden states of all encoders into a shared space and then computes an arbitrary distribution over the projections. The difference between the concatenation of the context vectors and the flat attention combination is that the α i coefficients are computed jointly for all encoders:
|
| 74 |
+
|
| 75 |
+
<!-- formula-not-decoded -->
|
| 76 |
+
|
| 77 |
+
where T ( n ) x is the length of the input sequence of the n -th encoder and e ( k ) ij is the attention energy of the j -th state of the k -th encoder in the i -th decoding step. These attention energies are computed as in Equation 1. The parameters v a and W a are shared among the encoders, and U a is different for each encoder and serves as an encoder-specific projection of hidden states into a common vector space.
|
| 78 |
+
|
| 79 |
+
The states of the individual encoders occupy different vector spaces and can have a different dimensionality, therefore the context vector cannot be computed as their weighted sum. We project them into a single space using linear projections:
|
| 80 |
+
|
| 81 |
+
<!-- formula-not-decoded -->
|
| 82 |
+
|
| 83 |
+
where U ( k ) c are additional trainable parameters.
|
| 84 |
+
|
| 85 |
+
The matrices U ( k ) c project the hidden states into a common vector space. This raises a question whether this space can be the same as the one that is projected into in the energy computation using matrices U ( k ) a in Equation 1, i.e., whether U ( k ) c = U ( k ) a . In our experiments, we explore both options. We also try both adding and not adding the sentinel α ( ψ ) i U ( ψ ) c ( ψ i ⊙ s i ) to the context vector.
|
| 86 |
+
|
| 87 |
+
## 3.2 Hierarchical Attention Combination
|
| 88 |
+
|
| 89 |
+
The hierarchical attention combination model computes every context vector independently, similarly to the concatenation approach. Instead of concatenation, a second attention mechanism is constructed over the context vectors.
|
| 90 |
+
|
| 91 |
+
We divide the computation of the attention distribution into two steps: First, we compute the context vector for each encoder independently using Equation 3. Second, we project the context vectors (and optionally the sentinel) into a common space (Equation 8), we compute another distribution over the projected context vectors (Equation 9) and their corresponding weighted average (Equation 10):
|
| 92 |
+
|
| 93 |
+
<!-- formula-not-decoded -->
|
| 94 |
+
|
| 95 |
+
<!-- formula-not-decoded -->
|
| 96 |
+
|
| 97 |
+
<!-- formula-not-decoded -->
|
| 98 |
+
|
| 99 |
+
where c ( k ) i is the context vector of the k -th encoder, additional trainable parameters v b and W b are shared for all encoders, and U ( k ) b and U ( k ) c are encoder-specific projection matrices, that can be set equal and shared, similarly to the case of flat attention combination.
|
| 100 |
+
|
| 101 |
+
## 4 Experiments
|
| 102 |
+
|
| 103 |
+
We evaluate the attention combination strategies presented in Section 3 on the tasks of multimodal translation (Section 4.1) and automatic post-editing (Section 4.2).
|
| 104 |
+
|
| 105 |
+
Figure 1: Learning curves on validation data for context vector concatenation (blue), flat (green) and hierarchical (red) attention combination without sentinel and without sharing the projection matrices.
|
| 106 |
+
|
| 107 |
+
<!-- image -->
|
| 108 |
+
|
| 109 |
+
The models were implemented using the Neural Monkey sequence-to-sequence learning toolkit (Helcl and Libovick´ y, 2017). 1 In both setups, we process the textual input with bidirectional GRU network (Cho et al., 2014) with 300 units in the hidden state in each direction and 300 units in embeddings. For the attention projection space, we use 500 hidden units. We optimize the network to minimize the output cross-entropy using the Adam algorithm (Kingma and Ba, 2014) with learning rate 10 -4 .
|
| 110 |
+
|
| 111 |
+
## 4.1 Multimodal Translation
|
| 112 |
+
|
| 113 |
+
The goal of multimodal translation (Specia et al., 2016) is to generate target-language image captions given both the image and its caption in the source language.
|
| 114 |
+
|
| 115 |
+
We train and evaluate the model on the Multi30k dataset (Elliott et al., 2016). It consists of 29,000 training instances (images together with English captions and their German translations), 1,014 validation instances, and 1,000 test instances. The results are evaluated using the BLEU (Papineni et al., 2002) and METEOR (Denkowski and Lavie, 2011).
|
| 116 |
+
|
| 117 |
+
In our model, the visual input is processed with a pre-trained VGG 16 network (Simonyan and Zisserman, 2014) without further fine-tuning. Attention distribution over the visual input is computed from the last convolutional layer of the network.
|
| 118 |
+
|
| 119 |
+
[1 http://github.com/ufal/neuralmonkey](http://github.com/ufal/neuralmonkey)
|
| 120 |
+
|
| 121 |
+
The decoder is an RNN with 500 conditional GRU units (Firat and Cho, 2016) in the recurrent layer. Weuse byte-pair encoding (Sennrich et al., 2016b) with a vocabulary of 20,000 subword units shared between the textual encoder and the decoder.
|
| 122 |
+
|
| 123 |
+
The results of our experiments in multimodal MT are shown in Table 1. We achieved the best results using the hierarchical attention combination without the sentinel mechanism, which also showed the fastest convergence. The flat combination strategy achieves similar results eventually. Sharing the projections for energy and context vector computation does not improve over the concatenation baseline and slows the training almost prohibitively. Multimodal models were not able to surpass the textual baseline (BLEU 33.0).
|
| 124 |
+
|
| 125 |
+
Using the conditional GRU units brought an improvement of about 1.5 BLEU points on average, with the exception of the concatenation scenario where the performance dropped by almost 5 BLEU points. We hypothesize this is caused by the fact the model has to learn the implicit attention combination on multiple places - once in the output projection and three times inside the conditional GRU unit (Firat and Cho, 2016, Equations 10-12). We thus report the scores of the introduced attention combination techniques trained with conditional GRU units and compare them with the concatenation baseline trained with plain GRU units.
|
| 126 |
+
|
| 127 |
+
## 4.2 Automatic MT Post-editing
|
| 128 |
+
|
| 129 |
+
Automatic post-editing is a task of improving an automatically generated translation given the source sentence where the translation system is treated as a black box.
|
| 130 |
+
|
| 131 |
+
We used the data from the WMT16 APE Task (Bojar et al., 2016; Turchi et al., 2016), which consists of 12,000 training, 2,000 validation, and 1,000 test sentence triplets from the IT domain. Each triplet contains an English source sentence, an automatically generated German translation of the source sentence, and a manually post-edited German sentence as a reference. In case of this dataset, the MT outputs are almost perfect in and only little effort was required to post-edit the sentences. The results are evaluated using the humantargeted error rate (HTER) (Snover et al., 2006) and BLEU score (Papineni et al., 2002).
|
| 132 |
+
|
| 133 |
+
Following Libovick´ y et al. (2016), we encode the target sentence as a sequence of edit operations transforming the MT output into the reference. By this technique, we prevent the model from paraphrasing the input sentences. The decoder is a GRU network with 300 hidden units. Unlike in the MMT setup (Section 4.1), we do not use the conditional GRU because it is prone to overfitting on the small dataset we work with.
|
| 134 |
+
|
| 135 |
+
Table 1: Results of our experiments on the test sets of Multi30k dataset and the APE dataset. The column 'share' denotes whether the projection matrix is shared for energies and context vector computation, 'sent.' indicates whether the sentinel vector has been used or not.
|
| 136 |
+
|
| 137 |
+
| share sent. MMT APE BLEU METEOR BLEU HTER concat. 31.4 ± .8 48.0 ± .7 62.3 ± .5 24.4 ± .4 flat × × 30.2 ± .8 46.5 ± .7 62.6 ± .5 24.2 ± .4 × ✓ 29.3 ± .8 45.4 ± .7 62.3 ± .5 24.3 ± .4 ✓ × 30.9 ± .8 47.1 ± .7 62.4 ± .6 24.4 ± .4 ✓ ✓ 29.4 ± .8 46.9 ± .7 62.5 ± .6 24.2 ± .4 hierarchical × × 32.1 ± .8 49.1 ± .7 62.3 ± .5 24.1 ± .4 × ✓ 28.1 ± .8 45.5 ± .7 62.6 ± .6 24.1 ± .4 ✓ × 26.1 ± .7 42.4 ± .7 62.4 ± .5 24.3 ± .4 ✓ ✓ 22.0 ± .7 38.5 ± .6 62.5 ± .5 24.1 ± .4 |
|
| 138 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 139 |
+
|
| 140 |
+
The models were able to slightly, but significantly improve over the baseline - leaving the MT output as is (HTER 24.8). The differences between the attention combination strategies are not significant.
|
| 141 |
+
|
| 142 |
+
## 5 Related Work
|
| 143 |
+
|
| 144 |
+
Attempts to use S2S models for APE are relatively rare (Bojar et al., 2016). Niehues et al. (2016) concatenate both inputs into one long sequence, which forces the encoder to be able to work with both source and target language. Their attention is then similar to our flat combination strategy; however, it can only be used for sequential data.
|
| 145 |
+
|
| 146 |
+
The best system from the WMT'16 competition (Junczys-Dowmunt and Grundkiewicz, 2016) trains two separate S2S models, one translating from MT output to post-edited targets and the second one from source sentences to post-edited targets. The decoders average their output distributions similarly to decoder ensembling. The biggest source of improvement in this state-of-theart posteditor came from additional training data generation, rather than from changes in the network architecture.
|
| 147 |
+
|
| 148 |
+
Caglayan et al. (2016) used an architecture very similar to ours for multimodal translation. They Source: a man sleeping in a green room on a couch .
|
| 149 |
+
|
| 150 |
+
<!-- image -->
|
| 151 |
+
|
| 152 |
+
Reference: ein Mann schl¨ aft in einem gr¨ unen Raum auf einem Sofa .
|
| 153 |
+
|
| 154 |
+
## Output with attention:
|
| 155 |
+
|
| 156 |
+
Figure 2: Visualization of hierarchical attention in MMT. Each column in the diagram corresponds to the weights of the encoders and sentinel. Note that the despite the overall low importance of the image encoder, it gets activated for the content words.
|
| 157 |
+
|
| 158 |
+
<!-- image -->
|
| 159 |
+
|
| 160 |
+
made a strong assumption that the network can be trained in such a way that the hidden states of the encoder and the convolutional network occupy the same vector space and thus sum the context vectors from both modalities. In this way, their multimodal MT system (BLEU 27.82) remained far bellow the text-only setup (BLEU 32.50).
|
| 161 |
+
|
| 162 |
+
New state-of-the-art results on the Multi30k dataset were achieved very recently by Calixto et al. (2017). The best-performing architecture uses the last fully-connected layer of VGG-19 network (Simonyan and Zisserman, 2014) as decoder initialization and only attends to the text encoder hidden states. With a stronger monomodal baseline (BLEU 33.7), their multimodal model achieved a BLEU score of 37.1. Similarly to Niehues et al. (2016) in the APE task, even further improvement was achieved by synthetically extending the dataset.
|
| 163 |
+
|
| 164 |
+
## 6 Conclusions
|
| 165 |
+
|
| 166 |
+
We introduced two new strategies of combining attention in a multi-source sequence-to-sequence setup. Both methods are based on computing a joint distribution over hidden states of all encoders.
|
| 167 |
+
|
| 168 |
+
We conducted experiments with the proposed strategies on multimodal translation and automatic post-editing tasks, and we showed that the flat and hierarchical attention combination can be applied to these tasks with maintaining competitive score to previously used techniques.
|
| 169 |
+
|
| 170 |
+
Unlike the simple context vector concatenation, the introduced combination strategies can be used with the conditional GRU units in the decoder. On top of that, the hierarchical combination strategy exhibits faster learning than than the other strategies.
|
| 171 |
+
|
| 172 |
+
## Acknowledgments
|
| 173 |
+
|
| 174 |
+
We would like to thank Ondˇ rej Duˇ sek, Rudolf Rosa, Pavel Pecina, and Ondˇ rej Bojar for a fruitful discussions and comments on the draft of the paper.
|
| 175 |
+
|
| 176 |
+
This research has been funded by the Czech Science Foundation grant no. P103/12/G084, the EU grant no. H2020-ICT-2014-1-645452 (QT21), and Charles University grant no. 52315/2014 and SVV project no. 260 453. This work has been using language resources developed and/or stored and/or distributed by the LINDAT-Clarin project of the Ministry of Education of the Czech Republic (project LM2010013).
|
| 177 |
+
|
| 178 |
+
## References
|
| 179 |
+
|
| 180 |
+
Dzmitry Bahdanau, Kyunghyun Cho, and Yoshua Bengio. 2014. Neural machine translation by jointly learning to align and translate. CoRR abs/1409.0473. http://arxiv.org/abs/1409.0473.
|
| 181 |
+
|
| 182 |
+
Ondˇ rej Bojar, Rajen Chatterjee, Christian Federmann, Yvette Graham, Barry Haddow, Matthias Huck, Antonio Yepes, Philipp Koehn, Varvara Logacheva, Christof Monz, Matteo Negri, Aurelie N´ ev´ eol, Mariana Neves, Martin Popel, Matt Post, Raphael Rubino, Carolina Scarton, Lucia Specia, Marco Turchi, Karin Verspoor, and Marcos Zampieri. 2016. Findings of the 2016 conference on machine translation (WMT16). In Proceedings of the First Conference on Machine Translation (WMT). Volume 2: Shared Task Papers . Association for Computational Linguistics, Association for Computational Linguistics, Stroudsburg, PA, USA, volume 2, pages 131198.
|
| 183 |
+
|
| 184 |
+
Ozan Caglayan, Walid Aransa, Yaxing Wang, Marc Masana, Mercedes Garc´ ıa-Mart´ ınez, Fethi Bougares, Lo¨ ıc Barrault, and Joost van de Weijer. 2016. Does multimodality help human and machine for translation and image captioning? In Proceedings of the First Conference on Machine Translation . Association for Computational Linguistics, Berlin, Germany, pages 627-633. http://www.aclweb.org/anthology/W16-2358.
|
| 185 |
+
|
| 186 |
+
- [Iacer Calixto, Qun Liu, and Nick Campbell. 2017. Incorporating global visual features into attention-based neural machine translation. CoRR abs/1701.06521. http://arxiv.org/abs/1701.06521.](http://arxiv.org/abs/1701.06521)
|
| 187 |
+
- Kyunghyun Cho, Bart van Merrienboer, Dzmitry Bahdanau, and Yoshua Bengio. 2014. On the properties of neural machine translation: Encoder-decoder approaches. In Proceedings of SSST-8, Eighth Workshop on Syntax, Semantics and Structure in Statistical Translation . Association for Computational Linguistics, Doha, Qatar, pages 103-111. http://www.aclweb.org/anthology/W14-4012.
|
| 188 |
+
- Michael Denkowski and Alon Lavie. 2011. Meteor 1.3: Automatic metric for reliable optimization and evaluation of machine translation systems. In Proceedings of the Sixth Workshop on Statistical Machine Translation . Association for Computational Linguistics, Edinburgh, United Kingdom, pages 8591. http://www.aclweb.org/anthology/W11-2107.
|
| 189 |
+
- Desmond Elliott, Stella Frank, Khalil Sima'an, and Lucia Specia. 2016. Multi30k: Multilingual englishgerman image descriptions. CoRR abs/1605.00459. http://arxiv.org/abs/1605.00459.
|
| 190 |
+
- Orhan Firat and Kyunghyun Cho. 2016. Conditional gated recurrent unit with attention mechanism. https://github.com/nyu-dl/dl4mttutorial/blob/master/docs/cgru.pdf. Published online, version adbaeea .
|
| 191 |
+
- Orhan Firat, Kyunghyun Cho, and Yoshua Bengio. 2016. Multi-way, multilingual neural machine translation with a shared attention mechanism. In Proceedings of the 2016 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies . Association for Computational Linguistics, San Diego, CA, USA, pages 866-875. http://www.aclweb.org/anthology/N16-1101.
|
| 192 |
+
- Alex Graves, Greg Wayne, and Ivo Danihelka. 2014. Neural turing machines. CoRR abs/1410.5401. http://arxiv.org/abs/1410.5401.
|
| 193 |
+
- Jindˇ rich Helcl and Jindˇ rich Libovick´ y. 2017. Neural monkey: An open-source tool for sequence learning. The Prague Bulletin of Mathematical Linguistics (107):5-17. https://doi.org/10.1515/pralin2017-0001.
|
| 194 |
+
- Sepp Hochreiter and J¨ urgen Schmidhuber. 1997. Long short-term memory. Neural Comput. 9:1735-1780. https://doi.org/10.1162/neco.1997.9.8.1735.
|
| 195 |
+
- Marcin Junczys-Dowmunt and Roman Grundkiewicz. 2016. Log-linear combinations of monolingual and bilingual neural machine translation models for automatic post-editing. In Proceedings of the First Conference on Machine Translation . Association for Computational Linguistics, Berlin, Germany, pages 751-758. http://www.aclweb.org/anthology/W/W16/W162378.
|
| 196 |
+
- Diederik P. Kingma and Jimmy Ba. 2014. Adam: A method for stochastic optimization. CoRR abs/1412.6980. http://arxiv.org/abs/1412.6980.
|
| 197 |
+
- Jindˇ rich Libovick´ y, Jindˇ rich Helcl, Marek Tlust´ y, Ondˇ rej Bojar, and Pavel Pecina. 2016. CUNI system for WMT16 automatic post-editing and multimodal translation tasks. In Proceedings of the First Conference on Machine Translation . Association for Computational Linguistics, Berlin, Germany, pages 646-654. http://www.aclweb.org/anthology/W/W16/W162361.
|
| 198 |
+
- Jiasen Lu, Caiming Xiong, Devi Parikh, and Richard Socher. 2016. Knowing when to look: Adaptive attention via a visual sentinel for image captioning. CoRR abs/1612.01887. http://arxiv.org/abs/1612.01887.
|
| 199 |
+
- Jan Niehues, Eunah Cho, Thanh-Le Ha, and Alex Waibel. 2016. Pre-translation for neural machine translation. CoRR abs/1610.05243. http://arxiv.org/abs/1610.05243.
|
| 200 |
+
- Kishore Papineni, Salim Roukos, Todd Ward, and Wei-Jing Zhu. 2002. Bleu: a method for automatic evaluation of machine translation. In Proceedings of 40th Annual Meeting of the Association for Computational Linguistics . Association for Computational Linguistics, Philadelphia, Pennsylvania, USA, pages 311-318. https://doi.org/10.3115/1073083.1073135.
|
| 201 |
+
- Alexander M. Rush, Sumit Chopra, and Jason Weston. 2015. A neural attention model for abstractive sentence summarization. In Proceedings of the 2015 Conference on Empirical Methods in Natural Language Processing . Association for Computational Linguistics, Lisbon, Portugal, pages 379-389. https://aclweb.org/anthology/D/D15/D15-1044.
|
| 202 |
+
- Rico Sennrich, Barry Haddow, and Alexandra Birch. 2016a. Edinburgh neural machine translation systems for WMT 16. In Proceedings of the First Conference on Machine Translation . Association for Computational Linguistics, Berlin, Germany, pages 371-376. http://www.aclweb.org/anthology/W/W16/W162323.
|
| 203 |
+
- Rico Sennrich, Barry Haddow, and Alexandra Birch. 2016b. Neural machine translation of rare words with subword units. In Proceedings of the 54th Annual Meeting of the Association for Computational Linguistics (Volume
|
| 204 |
+
|
| 205 |
+
1: Long Papers) . Association for Computational Linguistics, Berlin, Germany, pages 1715-1725. http://www.aclweb.org/anthology/P16-1162.
|
| 206 |
+
|
| 207 |
+
- [Karen Simonyan and Andrew Zisserman. 2014. Very deep convolutional networks for largescale image recognition. CoRR abs/1409.1556. http://arxiv.org/abs/1409.1556.](http://arxiv.org/abs/1409.1556)
|
| 208 |
+
- Matthew Snover, Bonnie Dorr, Richard Schwartz, Linnea Micciulla, and John Makhoul. 2006. A study of translation edit rate with targeted human annotation. In Proceedings of association for machine translation in the Americas . volume 200.
|
| 209 |
+
- Lucia Specia, Stella Frank, Khalil Sima'an, and Desmond Elliott. 2016. A shared task on multimodal machine translation and crosslingual image description. In Proceedings of the First Conference on Machine Translation . Association for Computational Linguistics, Berlin, Germany, pages 543-553. http://www.aclweb.org/anthology/W16-2346.
|
| 210 |
+
- Marco Turchi, Rajen Chatterjee, and Matteo Negri. 2016. WMT16 APE shared task data. LINDAT/CLARIN digital library at the Institute of Formal and Applied Linguistics, Charles University in Prague. http://hdl.handle.net/11372/LRT-1632.
|
| 211 |
+
- Kelvin Xu, Jimmy Ba, Ryan Kiros, Kyunghyun Cho, Aaron Courville, Ruslan Salakhudinov, Rich Zemel, and Yoshua Bengio. 2015. Show, attend and tell: Neural image caption generation with visual attention. In David Blei and Francis Bach, editors, Proceedings of the 32nd International Conference on Machine Learning (ICML-15) . JMLR Workshop and Conference Proceedings, Lille, France, pages 2048-2057. http://jmlr.org/proceedings/papers/v37/xuc15.pdf.
|
| 212 |
+
- Barret Zoph and Kevin Knight. 2016. Multi-source neural translation. In Proceedings of the 2016 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies . Association for Computational Linguistics, San Diego, CA, USA, pages 30-34. http://www.aclweb.org/anthology/N16-1004.
|
text-versions/attention-markdown/1706.03762_Attention Is All You Need.md
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1706.03762 Attention Is All You Need
|
| 2 |
+
|
| 3 |
+
Provided proper attribution is provided, Google hereby grants permission to reproduce the tables and figures in this paper solely for use in journalistic or scholarly works.
|
| 4 |
+
|
| 5 |
+
## Attention Is All You Need
|
| 6 |
+
|
| 7 |
+
Ashish Vaswani ∗ Google Brain avaswani@google.com Noam Shazeer ∗ Google Brain noam@google.com
|
| 8 |
+
|
| 9 |
+
Llion Jones ∗ Google Research llion@google.com Niki Parmar ∗ Google Research nikip@google.com Aidan N. Gomez ∗ † University of Toronto aidan@cs.toronto.edu Jakob Uszkoreit ∗ Google Research usz@google.com Łukasz Kaiser ∗ Google Brain lukaszkaiser@google.com Illia Polosukhin ∗ ‡
|
| 10 |
+
|
| 11 |
+
illia.polosukhin@gmail.com
|
| 12 |
+
|
| 13 |
+
## Abstract
|
| 14 |
+
|
| 15 |
+
The dominant sequence transduction models are based on complex recurrent or convolutional neural networks that include an encoder and a decoder. The best performing models also connect the encoder and decoder through an attention mechanism. We propose a new simple network architecture, the Transformer, based solely on attention mechanisms, dispensing with recurrence and convolutions entirely. Experiments on two machine translation tasks show these models to be superior in quality while being more parallelizable and requiring significantly less time to train. Our model achieves 28.4 BLEU on the WMT 2014 Englishto-German translation task, improving over the existing best results, including ensembles, by over 2 BLEU. On the WMT 2014 English-to-French translation task, our model establishes a new single-model state-of-the-art BLEU score of 41.8 after training for 3.5 days on eight GPUs, a small fraction of the training costs of the best models from the literature. We show that the Transformer generalizes well to other tasks by applying it successfully to English constituency parsing both with large and limited training data.
|
| 16 |
+
|
| 17 |
+
∗ Equal contribution. Listing order is random. Jakob proposed replacing RNNs with self-attention and started the effort to evaluate this idea. Ashish, with Illia, designed and implemented the first Transformer models and has been crucially involved in every aspect of this work. Noam proposed scaled dot-product attention, multi-head attention and the parameter-free position representation and became the other person involved in nearly every detail. Niki designed, implemented, tuned and evaluated countless model variants in our original codebase and tensor2tensor. Llion also experimented with novel model variants, was responsible for our initial codebase, and efficient inference and visualizations. Lukasz and Aidan spent countless long days designing various parts of and implementing tensor2tensor, replacing our earlier codebase, greatly improving results and massively accelerating our research.
|
| 18 |
+
|
| 19 |
+
† Work performed while at Google Brain.
|
| 20 |
+
|
| 21 |
+
‡ Work performed while at Google Research.
|
| 22 |
+
|
| 23 |
+
## 1 Introduction
|
| 24 |
+
|
| 25 |
+
Recurrent neural networks, long short-term memory [13] and gated recurrent [7] neural networks in particular, have been firmly established as state of the art approaches in sequence modeling and transduction problems such as language modeling and machine translation [35, 2, 5]. Numerous efforts have since continued to push the boundaries of recurrent language models and encoder-decoder architectures [38, 24, 15].
|
| 26 |
+
|
| 27 |
+
Recurrent models typically factor computation along the symbol positions of the input and output sequences. Aligning the positions to steps in computation time, they generate a sequence of hidden states h t , as a function of the previous hidden state h t -1 and the input for position t . This inherently sequential nature precludes parallelization within training examples, which becomes critical at longer sequence lengths, as memory constraints limit batching across examples. Recent work has achieved significant improvements in computational efficiency through factorization tricks [21] and conditional computation [32], while also improving model performance in case of the latter. The fundamental constraint of sequential computation, however, remains.
|
| 28 |
+
|
| 29 |
+
Attention mechanisms have become an integral part of compelling sequence modeling and transduction models in various tasks, allowing modeling of dependencies without regard to their distance in the input or output sequences [2, 19]. In all but a few cases [27], however, such attention mechanisms are used in conjunction with a recurrent network.
|
| 30 |
+
|
| 31 |
+
In this work we propose the Transformer, a model architecture eschewing recurrence and instead relying entirely on an attention mechanism to draw global dependencies between input and output. The Transformer allows for significantly more parallelization and can reach a new state of the art in translation quality after being trained for as little as twelve hours on eight P100 GPUs.
|
| 32 |
+
|
| 33 |
+
## 2 Background
|
| 34 |
+
|
| 35 |
+
The goal of reducing sequential computation also forms the foundation of the Extended Neural GPU [16], ByteNet [18] and ConvS2S [9], all of which use convolutional neural networks as basic building block, computing hidden representations in parallel for all input and output positions. In these models, the number of operations required to relate signals from two arbitrary input or output positions grows in the distance between positions, linearly for ConvS2S and logarithmically for ByteNet. This makes it more difficult to learn dependencies between distant positions [12]. In the Transformer this is reduced to a constant number of operations, albeit at the cost of reduced effective resolution due to averaging attention-weighted positions, an effect we counteract with Multi-Head Attention as described in section 3.2.
|
| 36 |
+
|
| 37 |
+
Self-attention, sometimes called intra-attention is an attention mechanism relating different positions of a single sequence in order to compute a representation of the sequence. Self-attention has been used successfully in a variety of tasks including reading comprehension, abstractive summarization, textual entailment and learning task-independent sentence representations [4, 27, 28, 22].
|
| 38 |
+
|
| 39 |
+
End-to-end memory networks are based on a recurrent attention mechanism instead of sequencealigned recurrence and have been shown to perform well on simple-language question answering and language modeling tasks [34].
|
| 40 |
+
|
| 41 |
+
To the best of our knowledge, however, the Transformer is the first transduction model relying entirely on self-attention to compute representations of its input and output without using sequencealigned RNNs or convolution. In the following sections, we will describe the Transformer, motivate self-attention and discuss its advantages over models such as [17, 18] and [9].
|
| 42 |
+
|
| 43 |
+
## 3 Model Architecture
|
| 44 |
+
|
| 45 |
+
Most competitive neural sequence transduction models have an encoder-decoder structure [5, 2, 35]. Here, the encoder maps an input sequence of symbol representations ( x 1 , ..., x n ) to a sequence of continuous representations z = ( z 1 , ..., z n ) . Given z , the decoder then generates an output sequence ( y 1 , ..., y m ) of symbols one element at a time. At each step the model is auto-regressive [10], consuming the previously generated symbols as additional input when generating the next.
|
| 46 |
+
|
| 47 |
+
Figure 1: The Transformer - model architecture.
|
| 48 |
+
|
| 49 |
+
<!-- image -->
|
| 50 |
+
|
| 51 |
+
The Transformer follows this overall architecture using stacked self-attention and point-wise, fully connected layers for both the encoder and decoder, shown in the left and right halves of Figure 1, respectively.
|
| 52 |
+
|
| 53 |
+
## 3.1 Encoder and Decoder Stacks
|
| 54 |
+
|
| 55 |
+
Encoder: The encoder is composed of a stack of N = 6 identical layers. Each layer has two sub-layers. The first is a multi-head self-attention mechanism, and the second is a simple, positionwise fully connected feed-forward network. We employ a residual connection [11] around each of the two sub-layers, followed by layer normalization [1]. That is, the output of each sub-layer is LayerNorm( x +Sublayer( x )) , where Sublayer( x ) is the function implemented by the sub-layer itself. To facilitate these residual connections, all sub-layers in the model, as well as the embedding layers, produce outputs of dimension d model = 512 .
|
| 56 |
+
|
| 57 |
+
Decoder: The decoder is also composed of a stack of N = 6 identical layers. In addition to the two sub-layers in each encoder layer, the decoder inserts a third sub-layer, which performs multi-head attention over the output of the encoder stack. Similar to the encoder, we employ residual connections around each of the sub-layers, followed by layer normalization. We also modify the self-attention sub-layer in the decoder stack to prevent positions from attending to subsequent positions. This masking, combined with fact that the output embeddings are offset by one position, ensures that the predictions for position i can depend only on the known outputs at positions less than i .
|
| 58 |
+
|
| 59 |
+
## 3.2 Attention
|
| 60 |
+
|
| 61 |
+
An attention function can be described as mapping a query and a set of key-value pairs to an output, where the query, keys, values, and output are all vectors. The output is computed as a weighted sum
|
| 62 |
+
|
| 63 |
+
## Scaled Dot-Product Attention
|
| 64 |
+
|
| 65 |
+
<!-- image -->
|
| 66 |
+
|
| 67 |
+
Figure 2: (left) Scaled Dot-Product Attention. (right) Multi-Head Attention consists of several attention layers running in parallel.
|
| 68 |
+
|
| 69 |
+
<!-- image -->
|
| 70 |
+
|
| 71 |
+
of the values, where the weight assigned to each value is computed by a compatibility function of the query with the corresponding key.
|
| 72 |
+
|
| 73 |
+
## 3.2.1 Scaled Dot-Product Attention
|
| 74 |
+
|
| 75 |
+
We call our particular attention "Scaled Dot-Product Attention" (Figure 2). The input consists of queries and keys of dimension d k , and values of dimension d v . We compute the dot products of the query with all keys, divide each by √ d k , and apply a softmax function to obtain the weights on the values.
|
| 76 |
+
|
| 77 |
+
In practice, we compute the attention function on a set of queries simultaneously, packed together into a matrix Q . The keys and values are also packed together into matrices K and V . We compute the matrix of outputs as:
|
| 78 |
+
|
| 79 |
+
<!-- formula-not-decoded -->
|
| 80 |
+
|
| 81 |
+
The two most commonly used attention functions are additive attention [2], and dot-product (multiplicative) attention. Dot-product attention is identical to our algorithm, except for the scaling factor of 1 √ d k . Additive attention computes the compatibility function using a feed-forward network with a single hidden layer. While the two are similar in theoretical complexity, dot-product attention is much faster and more space-efficient in practice, since it can be implemented using highly optimized matrix multiplication code.
|
| 82 |
+
|
| 83 |
+
While for small values of d k the two mechanisms perform similarly, additive attention outperforms dot product attention without scaling for larger values of d k [3]. We suspect that for large values of d k , the dot products grow large in magnitude, pushing the softmax function into regions where it has extremely small gradients 4 . To counteract this effect, we scale the dot products by 1 √ d k .
|
| 84 |
+
|
| 85 |
+
## 3.2.2 Multi-Head Attention
|
| 86 |
+
|
| 87 |
+
Instead of performing a single attention function with d model-dimensional keys, values and queries, we found it beneficial to linearly project the queries, keys and values h times with different, learned linear projections to d k , d k and d v dimensions, respectively. On each of these projected versions of queries, keys and values we then perform the attention function in parallel, yielding d v -dimensional output values. These are concatenated and once again projected, resulting in the final values, as depicted in Figure 2.
|
| 88 |
+
|
| 89 |
+
4 To illustrate why the dot products get large, assume that the components of q and k are independent random variables with mean 0 and variance 1 . Then their dot product, q · k = ∑ d k i =1 q i k i , has mean 0 and variance d k .
|
| 90 |
+
|
| 91 |
+
Multi-head attention allows the model to jointly attend to information from different representation subspaces at different positions. With a single attention head, averaging inhibits this.
|
| 92 |
+
|
| 93 |
+
<!-- formula-not-decoded -->
|
| 94 |
+
|
| 95 |
+
Where the projections are parameter matrices W Q i ∈ R d model × d k , W i K ∈ R d model × d k , W V i ∈ R d model × d v and W O ∈ R hd v × d model .
|
| 96 |
+
|
| 97 |
+
In this work we employ h = 8 parallel attention layers, or heads. For each of these we use d k = d v = d model /h = 64 . Due to the reduced dimension of each head, the total computational cost is similar to that of single-head attention with full dimensionality.
|
| 98 |
+
|
| 99 |
+
## 3.2.3 Applications of Attention in our Model
|
| 100 |
+
|
| 101 |
+
The Transformer uses multi-head attention in three different ways:
|
| 102 |
+
|
| 103 |
+
- In "encoder-decoder attention" layers, the queries come from the previous decoder layer, and the memory keys and values come from the output of the encoder. This allows every position in the decoder to attend over all positions in the input sequence. This mimics the typical encoder-decoder attention mechanisms in sequence-to-sequence models such as [38, 2, 9].
|
| 104 |
+
- The encoder contains self-attention layers. In a self-attention layer all of the keys, values and queries come from the same place, in this case, the output of the previous layer in the encoder. Each position in the encoder can attend to all positions in the previous layer of the encoder.
|
| 105 |
+
- Similarly, self-attention layers in the decoder allow each position in the decoder to attend to all positions in the decoder up to and including that position. We need to prevent leftward information flow in the decoder to preserve the auto-regressive property. We implement this inside of scaled dot-product attention by masking out (setting to -∞ ) all values in the input of the softmax which correspond to illegal connections. See Figure 2.
|
| 106 |
+
|
| 107 |
+
## 3.3 Position-wise Feed-Forward Networks
|
| 108 |
+
|
| 109 |
+
In addition to attention sub-layers, each of the layers in our encoder and decoder contains a fully connected feed-forward network, which is applied to each position separately and identically. This consists of two linear transformations with a ReLU activation in between.
|
| 110 |
+
|
| 111 |
+
<!-- formula-not-decoded -->
|
| 112 |
+
|
| 113 |
+
While the linear transformations are the same across different positions, they use different parameters from layer to layer. Another way of describing this is as two convolutions with kernel size 1. The dimensionality of input and output is d model = 512 , and the inner-layer has dimensionality d ff = 2048 .
|
| 114 |
+
|
| 115 |
+
## 3.4 Embeddings and Softmax
|
| 116 |
+
|
| 117 |
+
Similarly to other sequence transduction models, we use learned embeddings to convert the input tokens and output tokens to vectors of dimension d model. We also use the usual learned linear transformation and softmax function to convert the decoder output to predicted next-token probabilities. In our model, we share the same weight matrix between the two embedding layers and the pre-softmax linear transformation, similar to [30]. In the embedding layers, we multiply those weights by √ d model.
|
| 118 |
+
|
| 119 |
+
Table 1: Maximum path lengths, per-layer complexity and minimum number of sequential operations for different layer types. n is the sequence length, d is the representation dimension, k is the kernel size of convolutions and r the size of the neighborhood in restricted self-attention.
|
| 120 |
+
|
| 121 |
+
| Layer Type Complexity per Layer Sequential Maximum Path Length Operations Self-Attention O ( n 2 · d ) O (1) O (1) Recurrent O ( n · d 2 ) O ( n ) O ( n ) Convolutional O ( k · n · d 2 ) O (1) O ( log k ( n )) Self-Attention (restricted) O ( r · n · d ) O (1) O ( n/r ) |
|
| 122 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 123 |
+
|
| 124 |
+
## 3.5 Positional Encoding
|
| 125 |
+
|
| 126 |
+
Since our model contains no recurrence and no convolution, in order for the model to make use of the order of the sequence, we must inject some information about the relative or absolute position of the tokens in the sequence. To this end, we add "positional encodings" to the input embeddings at the bottoms of the encoder and decoder stacks. The positional encodings have the same dimension d model as the embeddings, so that the two can be summed. There are many choices of positional encodings, learned and fixed [9].
|
| 127 |
+
|
| 128 |
+
In this work, we use sine and cosine functions of different frequencies:
|
| 129 |
+
|
| 130 |
+
<!-- formula-not-decoded -->
|
| 131 |
+
|
| 132 |
+
where pos is the position and i is the dimension. That is, each dimension of the positional encoding corresponds to a sinusoid. The wavelengths form a geometric progression from 2 π to 10000 · 2 π . We chose this function because we hypothesized it would allow the model to easily learn to attend by relative positions, since for any fixed offset k , PE pos + k can be represented as a linear function of PE pos .
|
| 133 |
+
|
| 134 |
+
We also experimented with using learned positional embeddings [9] instead, and found that the two versions produced nearly identical results (see Table 3 row (E)). We chose the sinusoidal version because it may allow the model to extrapolate to sequence lengths longer than the ones encountered during training.
|
| 135 |
+
|
| 136 |
+
## 4 Why Self-Attention
|
| 137 |
+
|
| 138 |
+
In this section we compare various aspects of self-attention layers to the recurrent and convolutional layers commonly used for mapping one variable-length sequence of symbol representations ( x 1 , ..., x n ) to another sequence of equal length ( z 1 , ..., z n ) , with x i , z i ∈ R d , such as a hidden layer in a typical sequence transduction encoder or decoder. Motivating our use of self-attention we consider three desiderata.
|
| 139 |
+
|
| 140 |
+
One is the total computational complexity per layer. Another is the amount of computation that can be parallelized, as measured by the minimum number of sequential operations required.
|
| 141 |
+
|
| 142 |
+
The third is the path length between long-range dependencies in the network. Learning long-range dependencies is a key challenge in many sequence transduction tasks. One key factor affecting the ability to learn such dependencies is the length of the paths forward and backward signals have to traverse in the network. The shorter these paths between any combination of positions in the input and output sequences, the easier it is to learn long-range dependencies [12]. Hence we also compare the maximum path length between any two input and output positions in networks composed of the different layer types.
|
| 143 |
+
|
| 144 |
+
As noted in Table 1, a self-attention layer connects all positions with a constant number of sequentially executed operations, whereas a recurrent layer requires O ( n ) sequential operations. In terms of computational complexity, self-attention layers are faster than recurrent layers when the sequence length n is smaller than the representation dimensionality d , which is most often the case with sentence representations used by state-of-the-art models in machine translations, such as word-piece [38] and byte-pair [31] representations. To improve computational performance for tasks involving very long sequences, self-attention could be restricted to considering only a neighborhood of size r in the input sequence centered around the respective output position. This would increase the maximum path length to O ( n/r ) . We plan to investigate this approach further in future work.
|
| 145 |
+
|
| 146 |
+
A single convolutional layer with kernel width k < n does not connect all pairs of input and output positions. Doing so requires a stack of O ( n/k ) convolutional layers in the case of contiguous kernels, or O ( log k ( n )) in the case of dilated convolutions [18], increasing the length of the longest paths between any two positions in the network. Convolutional layers are generally more expensive than recurrent layers, by a factor of k . Separable convolutions [6], however, decrease the complexity considerably, to O ( k · n · d + n · d 2 ) . Even with k = n , however, the complexity of a separable convolution is equal to the combination of a self-attention layer and a point-wise feed-forward layer, the approach we take in our model.
|
| 147 |
+
|
| 148 |
+
As side benefit, self-attention could yield more interpretable models. We inspect attention distributions from our models and present and discuss examples in the appendix. Not only do individual attention heads clearly learn to perform different tasks, many appear to exhibit behavior related to the syntactic and semantic structure of the sentences.
|
| 149 |
+
|
| 150 |
+
## 5 Training
|
| 151 |
+
|
| 152 |
+
This section describes the training regime for our models.
|
| 153 |
+
|
| 154 |
+
## 5.1 Training Data and Batching
|
| 155 |
+
|
| 156 |
+
We trained on the standard WMT 2014 English-German dataset consisting of about 4.5 million sentence pairs. Sentences were encoded using byte-pair encoding [3], which has a shared sourcetarget vocabulary of about 37000 tokens. For English-French, we used the significantly larger WMT 2014 English-French dataset consisting of 36M sentences and split tokens into a 32000 word-piece vocabulary [38]. Sentence pairs were batched together by approximate sequence length. Each training batch contained a set of sentence pairs containing approximately 25000 source tokens and 25000 target tokens.
|
| 157 |
+
|
| 158 |
+
## 5.2 Hardware and Schedule
|
| 159 |
+
|
| 160 |
+
We trained our models on one machine with 8 NVIDIA P100 GPUs. For our base models using the hyperparameters described throughout the paper, each training step took about 0.4 seconds. We trained the base models for a total of 100,000 steps or 12 hours. For our big models,(described on the bottom line of table 3), step time was 1.0 seconds. The big models were trained for 300,000 steps (3.5 days).
|
| 161 |
+
|
| 162 |
+
## 5.3 Optimizer
|
| 163 |
+
|
| 164 |
+
We used the Adam optimizer [20] with β 1 = 0 . 9 , β 2 = 0 . 98 and ϵ = 10 -9 . We varied the learning rate over the course of training, according to the formula:
|
| 165 |
+
|
| 166 |
+
<!-- formula-not-decoded -->
|
| 167 |
+
|
| 168 |
+
This corresponds to increasing the learning rate linearly for the first warmup \_ steps training steps, and decreasing it thereafter proportionally to the inverse square root of the step number. We used warmup \_ steps = 4000 .
|
| 169 |
+
|
| 170 |
+
## 5.4 Regularization
|
| 171 |
+
|
| 172 |
+
We employ three types of regularization during training:
|
| 173 |
+
|
| 174 |
+
Table 2: The Transformer achieves better BLEU scores than previous state-of-the-art models on the English-to-German and English-to-French newstest2014 tests at a fraction of the training cost.
|
| 175 |
+
|
| 176 |
+
| Model BLEU Training Cost (FLOPs) EN-DE EN-FR EN-DE EN-FR ByteNet [18] 23.75 Deep-Att + PosUnk [39] 39.2 1 . 0 · 10 20 GNMT + RL [38] 24.6 39.92 2 . 3 · 10 19 1 . 4 · 10 20 ConvS2S [9] 25.16 40.46 9 . 6 · 10 18 1 . 5 · 10 20 MoE [32] 26.03 40.56 2 . 0 · 10 19 1 . 2 · 10 20 Deep-Att + PosUnk Ensemble [39] 40.4 8 . 0 · 10 20 GNMT + RL Ensemble [38] 26.30 41.16 1 . 8 · 10 20 1 . 1 · 10 21 ConvS2S Ensemble [9] 26.36 41.29 7 . 7 · 10 19 1 . 2 · 10 21 Transformer (base model) 27.3 38.1 3 . 3 · 10 18 Transformer (big) 28.4 41.8 2 . 3 · 10 19 |
|
| 177 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 178 |
+
|
| 179 |
+
Residual Dropout We apply dropout [33] to the output of each sub-layer, before it is added to the sub-layer input and normalized. In addition, we apply dropout to the sums of the embeddings and the positional encodings in both the encoder and decoder stacks. For the base model, we use a rate of P drop = 0 . 1 .
|
| 180 |
+
|
| 181 |
+
Label Smoothing During training, we employed label smoothing of value ϵ ls = 0 . 1 [36]. This hurts perplexity, as the model learns to be more unsure, but improves accuracy and BLEU score.
|
| 182 |
+
|
| 183 |
+
## 6 Results
|
| 184 |
+
|
| 185 |
+
## 6.1 Machine Translation
|
| 186 |
+
|
| 187 |
+
On the WMT 2014 English-to-German translation task, the big transformer model (Transformer (big) in Table 2) outperforms the best previously reported models (including ensembles) by more than 2 . 0 BLEU, establishing a new state-of-the-art BLEU score of 28 . 4 . The configuration of this model is listed in the bottom line of Table 3. Training took 3 . 5 days on 8 P100 GPUs. Even our base model surpasses all previously published models and ensembles, at a fraction of the training cost of any of the competitive models.
|
| 188 |
+
|
| 189 |
+
On the WMT 2014 English-to-French translation task, our big model achieves a BLEU score of 41 . 0 , outperforming all of the previously published single models, at less than 1 / 4 the training cost of the previous state-of-the-art model. The Transformer (big) model trained for English-to-French used dropout rate P drop = 0 . 1 , instead of 0 . 3 .
|
| 190 |
+
|
| 191 |
+
For the base models, we used a single model obtained by averaging the last 5 checkpoints, which were written at 10-minute intervals. For the big models, we averaged the last 20 checkpoints. We used beam search with a beam size of 4 and length penalty α = 0 . 6 [38]. These hyperparameters were chosen after experimentation on the development set. We set the maximum output length during inference to input length + 50 , but terminate early when possible [38].
|
| 192 |
+
|
| 193 |
+
Table 2 summarizes our results and compares our translation quality and training costs to other model architectures from the literature. We estimate the number of floating point operations used to train a model by multiplying the training time, the number of GPUs used, and an estimate of the sustained single-precision floating-point capacity of each GPU 5 .
|
| 194 |
+
|
| 195 |
+
## 6.2 Model Variations
|
| 196 |
+
|
| 197 |
+
To evaluate the importance of different components of the Transformer, we varied our base model in different ways, measuring the change in performance on English-to-German translation on the development set, newstest2013. We used beam search as described in the previous section, but no checkpoint averaging. We present these results in Table 3.
|
| 198 |
+
|
| 199 |
+
5 We used values of 2.8, 3.7, 6.0 and 9.5 TFLOPS for K80, K40, M40 and P100, respectively.
|
| 200 |
+
|
| 201 |
+
Table 3: Variations on the Transformer architecture. Unlisted values are identical to those of the base model. All metrics are on the English-to-German translation development set, newstest2013. Listed perplexities are per-wordpiece, according to our byte-pair encoding, and should not be compared to per-word perplexities.
|
| 202 |
+
|
| 203 |
+
| N d model dff h d k d v P drop ϵ ls train PPL BLEU params steps (dev) (dev) × 10 6 base 6 512 2048 8 64 64 0.1 0.1 100K 4.92 25.8 65 (A) 1 512 512 5.29 24.9 4 128 128 5.00 25.5 16 32 32 4.91 25.8 32 16 16 5.01 25.4 (B) 16 5.16 25.1 58 32 5.01 25.4 60 (C) 2 6.11 23.7 36 4 5.19 25.3 50 8 4.88 25.5 80 256 32 32 5.75 24.5 28 1024 128 128 4.66 26.0 168 1024 5.12 25.4 53 4096 4.75 26.2 90 (D) 0.0 5.77 24.6 0.2 4.95 25.5 0.0 4.67 25.3 0.2 5.47 25.7 (E) positional embedding instead of sinusoids 4.92 25.7 big 6 1024 4096 16 0.3 300K 4.33 26.4 213 |
|
| 204 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 205 |
+
|
| 206 |
+
In Table 3 rows (A), we vary the number of attention heads and the attention key and value dimensions, keeping the amount of computation constant, as described in Section 3.2.2. While single-head attention is 0.9 BLEU worse than the best setting, quality also drops off with too many heads.
|
| 207 |
+
|
| 208 |
+
In Table 3 rows (B), we observe that reducing the attention key size d k hurts model quality. This suggests that determining compatibility is not easy and that a more sophisticated compatibility function than dot product may be beneficial. We further observe in rows (C) and (D) that, as expected, bigger models are better, and dropout is very helpful in avoiding over-fitting. In row (E) we replace our sinusoidal positional encoding with learned positional embeddings [9], and observe nearly identical results to the base model.
|
| 209 |
+
|
| 210 |
+
## 6.3 English Constituency Parsing
|
| 211 |
+
|
| 212 |
+
To evaluate if the Transformer can generalize to other tasks we performed experiments on English constituency parsing. This task presents specific challenges: the output is subject to strong structural constraints and is significantly longer than the input. Furthermore, RNN sequence-to-sequence models have not been able to attain state-of-the-art results in small-data regimes [37].
|
| 213 |
+
|
| 214 |
+
We trained a 4-layer transformer with d model = 1024 on the Wall Street Journal (WSJ) portion of the Penn Treebank [25], about 40K training sentences. We also trained it in a semi-supervised setting, using the larger high-confidence and BerkleyParser corpora from with approximately 17M sentences [37]. We used a vocabulary of 16K tokens for the WSJ only setting and a vocabulary of 32K tokens for the semi-supervised setting.
|
| 215 |
+
|
| 216 |
+
We performed only a small number of experiments to select the dropout, both attention and residual (section 5.4), learning rates and beam size on the Section 22 development set, all other parameters remained unchanged from the English-to-German base translation model. During inference, we increased the maximum output length to input length + 300 . We used a beam size of 21 and α = 0 . 3 for both WSJ only and the semi-supervised setting.
|
| 217 |
+
|
| 218 |
+
Table 4: The Transformer generalizes well to English constituency parsing (Results are on Section 23 of WSJ)
|
| 219 |
+
|
| 220 |
+
| Parser Training WSJ 23 F1 Vinyals & Kaiser el al. (2014) [37] WSJ only, discriminative 88.3 Petrov et al. (2006) [29] WSJ only, discriminative 90.4 Zhu et al. (2013) [40] WSJ only, discriminative 90.4 Dyer et al. (2016) [8] WSJ only, discriminative 91.7 Transformer (4 layers) WSJ only, discriminative 91.3 Zhu et al. (2013) [40] semi-supervised 91.3 Huang & Harper (2009) [14] semi-supervised 91.3 McClosky et al. (2006) [26] semi-supervised 92.1 Vinyals & Kaiser el al. (2014) [37] semi-supervised 92.1 Transformer (4 layers) semi-supervised 92.7 Luong et al. (2015) [23] multi-task 93.0 Dyer et al. (2016) [8] generative 93.3 |
|
| 221 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 222 |
+
|
| 223 |
+
Our results in Table 4 show that despite the lack of task-specific tuning our model performs surprisingly well, yielding better results than all previously reported models with the exception of the Recurrent Neural Network Grammar [8].
|
| 224 |
+
|
| 225 |
+
In contrast to RNN sequence-to-sequence models [37], the Transformer outperforms the BerkeleyParser [29] even when training only on the WSJ training set of 40K sentences.
|
| 226 |
+
|
| 227 |
+
## 7 Conclusion
|
| 228 |
+
|
| 229 |
+
In this work, we presented the Transformer, the first sequence transduction model based entirely on attention, replacing the recurrent layers most commonly used in encoder-decoder architectures with multi-headed self-attention.
|
| 230 |
+
|
| 231 |
+
For translation tasks, the Transformer can be trained significantly faster than architectures based on recurrent or convolutional layers. On both WMT 2014 English-to-German and WMT 2014 English-to-French translation tasks, we achieve a new state of the art. In the former task our best model outperforms even all previously reported ensembles.
|
| 232 |
+
|
| 233 |
+
We are excited about the future of attention-based models and plan to apply them to other tasks. We plan to extend the Transformer to problems involving input and output modalities other than text and to investigate local, restricted attention mechanisms to efficiently handle large inputs and outputs such as images, audio and video. Making generation less sequential is another research goals of ours.
|
| 234 |
+
|
| 235 |
+
The code we used to train and evaluate our models is available at https://github.com/ tensorflow/tensor2tensor .
|
| 236 |
+
|
| 237 |
+
Acknowledgements We are grateful to Nal Kalchbrenner and Stephan Gouws for their fruitful comments, corrections and inspiration.
|
| 238 |
+
|
| 239 |
+
## References
|
| 240 |
+
|
| 241 |
+
- [1] Jimmy Lei Ba, Jamie Ryan Kiros, and Geoffrey E Hinton. Layer normalization. arXiv preprint arXiv:1607.06450 , 2016.
|
| 242 |
+
- [2] Dzmitry Bahdanau, Kyunghyun Cho, and Yoshua Bengio. Neural machine translation by jointly learning to align and translate. CoRR , abs/1409.0473, 2014.
|
| 243 |
+
- [3] Denny Britz, Anna Goldie, Minh-Thang Luong, and Quoc V. Le. Massive exploration of neural machine translation architectures. CoRR , abs/1703.03906, 2017.
|
| 244 |
+
- [4] Jianpeng Cheng, Li Dong, and Mirella Lapata. Long short-term memory-networks for machine reading. arXiv preprint arXiv:1601.06733 , 2016.
|
| 245 |
+
|
| 246 |
+
- [5] Kyunghyun Cho, Bart van Merrienboer, Caglar Gulcehre, Fethi Bougares, Holger Schwenk, and Yoshua Bengio. Learning phrase representations using rnn encoder-decoder for statistical machine translation. CoRR , abs/1406.1078, 2014.
|
| 247 |
+
- [6] Francois Chollet. Xception: Deep learning with depthwise separable convolutions. arXiv preprint arXiv:1610.02357 , 2016.
|
| 248 |
+
- [7] Junyoung Chung, Çaglar Gülçehre, Kyunghyun Cho, and Yoshua Bengio. Empirical evaluation of gated recurrent neural networks on sequence modeling. CoRR , abs/1412.3555, 2014.
|
| 249 |
+
- [8] Chris Dyer, Adhiguna Kuncoro, Miguel Ballesteros, and Noah A. Smith. Recurrent neural network grammars. In Proc. of NAACL , 2016.
|
| 250 |
+
- [9] Jonas Gehring, Michael Auli, David Grangier, Denis Yarats, and Yann N. Dauphin. Convolutional sequence to sequence learning. arXiv preprint arXiv:1705.03122v2 , 2017.
|
| 251 |
+
- [10] Alex Graves. Generating sequences with recurrent neural networks. arXiv preprint arXiv:1308.0850 , 2013.
|
| 252 |
+
- [11] Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep residual learning for image recognition. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , pages 770-778, 2016.
|
| 253 |
+
- [12] Sepp Hochreiter, Yoshua Bengio, Paolo Frasconi, and Jürgen Schmidhuber. Gradient flow in recurrent nets: the difficulty of learning long-term dependencies, 2001.
|
| 254 |
+
- [13] Sepp Hochreiter and Jürgen Schmidhuber. Long short-term memory. Neural computation , 9(8):1735-1780, 1997.
|
| 255 |
+
- [14] Zhongqiang Huang and Mary Harper. Self-training PCFG grammars with latent annotations across languages. In Proceedings of the 2009 Conference on Empirical Methods in Natural Language Processing , pages 832-841. ACL, August 2009.
|
| 256 |
+
- [15] Rafal Jozefowicz, Oriol Vinyals, Mike Schuster, Noam Shazeer, and Yonghui Wu. Exploring the limits of language modeling. arXiv preprint arXiv:1602.02410 , 2016.
|
| 257 |
+
- [16] Łukasz Kaiser and Samy Bengio. Can active memory replace attention? In Advances in Neural Information Processing Systems, (NIPS) , 2016.
|
| 258 |
+
- [17] Łukasz Kaiser and Ilya Sutskever. Neural GPUs learn algorithms. In International Conference on Learning Representations (ICLR) , 2016.
|
| 259 |
+
- [18] Nal Kalchbrenner, Lasse Espeholt, Karen Simonyan, Aaron van den Oord, Alex Graves, and Koray Kavukcuoglu. Neural machine translation in linear time. arXiv preprint arXiv:1610.10099v2 , 2017.
|
| 260 |
+
- [19] Yoon Kim, Carl Denton, Luong Hoang, and Alexander M. Rush. Structured attention networks. In International Conference on Learning Representations , 2017.
|
| 261 |
+
- [20] Diederik Kingma and Jimmy Ba. Adam: A method for stochastic optimization. In ICLR , 2015.
|
| 262 |
+
- [21] Oleksii Kuchaiev and Boris Ginsburg. Factorization tricks for LSTM networks. arXiv preprint arXiv:1703.10722 , 2017.
|
| 263 |
+
- [22] Zhouhan Lin, Minwei Feng, Cicero Nogueira dos Santos, Mo Yu, Bing Xiang, Bowen Zhou, and Yoshua Bengio. A structured self-attentive sentence embedding. arXiv preprint arXiv:1703.03130 , 2017.
|
| 264 |
+
- [23] Minh-Thang Luong, Quoc V. Le, Ilya Sutskever, Oriol Vinyals, and Lukasz Kaiser. Multi-task sequence to sequence learning. arXiv preprint arXiv:1511.06114 , 2015.
|
| 265 |
+
- [24] Minh-Thang Luong, Hieu Pham, and Christopher D Manning. Effective approaches to attentionbased neural machine translation. arXiv preprint arXiv:1508.04025 , 2015.
|
| 266 |
+
|
| 267 |
+
- [25] Mitchell P Marcus, Mary Ann Marcinkiewicz, and Beatrice Santorini. Building a large annotated corpus of english: The penn treebank. Computational linguistics , 19(2):313-330, 1993.
|
| 268 |
+
- [26] David McClosky, Eugene Charniak, and Mark Johnson. Effective self-training for parsing. In Proceedings of the Human Language Technology Conference of the NAACL, Main Conference , pages 152-159. ACL, June 2006.
|
| 269 |
+
- [27] Ankur Parikh, Oscar Täckström, Dipanjan Das, and Jakob Uszkoreit. A decomposable attention model. In Empirical Methods in Natural Language Processing , 2016.
|
| 270 |
+
- [28] Romain Paulus, Caiming Xiong, and Richard Socher. A deep reinforced model for abstractive summarization. arXiv preprint arXiv:1705.04304 , 2017.
|
| 271 |
+
- [29] Slav Petrov, Leon Barrett, Romain Thibaux, and Dan Klein. Learning accurate, compact, and interpretable tree annotation. In Proceedings of the 21st International Conference on Computational Linguistics and 44th Annual Meeting of the ACL , pages 433-440. ACL, July 2006.
|
| 272 |
+
- [30] Ofir Press and Lior Wolf. Using the output embedding to improve language models. arXiv preprint arXiv:1608.05859 , 2016.
|
| 273 |
+
- [31] Rico Sennrich, Barry Haddow, and Alexandra Birch. Neural machine translation of rare words with subword units. arXiv preprint arXiv:1508.07909 , 2015.
|
| 274 |
+
- [32] Noam Shazeer, Azalia Mirhoseini, Krzysztof Maziarz, Andy Davis, Quoc Le, Geoffrey Hinton, and Jeff Dean. Outrageously large neural networks: The sparsely-gated mixture-of-experts layer. arXiv preprint arXiv:1701.06538 , 2017.
|
| 275 |
+
- [33] Nitish Srivastava, Geoffrey E Hinton, Alex Krizhevsky, Ilya Sutskever, and Ruslan Salakhutdinov. Dropout: a simple way to prevent neural networks from overfitting. Journal of Machine Learning Research , 15(1):1929-1958, 2014.
|
| 276 |
+
- [34] Sainbayar Sukhbaatar, Arthur Szlam, Jason Weston, and Rob Fergus. End-to-end memory networks. In C. Cortes, N. D. Lawrence, D. D. Lee, M. Sugiyama, and R. Garnett, editors, Advances in Neural Information Processing Systems 28 , pages 2440-2448. Curran Associates, Inc., 2015.
|
| 277 |
+
- [35] Ilya Sutskever, Oriol Vinyals, and Quoc VV Le. Sequence to sequence learning with neural networks. In Advances in Neural Information Processing Systems , pages 3104-3112, 2014.
|
| 278 |
+
- [36] Christian Szegedy, Vincent Vanhoucke, Sergey Ioffe, Jonathon Shlens, and Zbigniew Wojna. Rethinking the inception architecture for computer vision. CoRR , abs/1512.00567, 2015.
|
| 279 |
+
- [37] Vinyals & Kaiser, Koo, Petrov, Sutskever, and Hinton. Grammar as a foreign language. In Advances in Neural Information Processing Systems , 2015.
|
| 280 |
+
- [38] Yonghui Wu, Mike Schuster, Zhifeng Chen, Quoc V Le, Mohammad Norouzi, Wolfgang Macherey, Maxim Krikun, Yuan Cao, Qin Gao, Klaus Macherey, et al. Google's neural machine translation system: Bridging the gap between human and machine translation. arXiv preprint arXiv:1609.08144 , 2016.
|
| 281 |
+
- [39] Jie Zhou, Ying Cao, Xuguang Wang, Peng Li, and Wei Xu. Deep recurrent models with fast-forward connections for neural machine translation. CoRR , abs/1606.04199, 2016.
|
| 282 |
+
- [40] Muhua Zhu, Yue Zhang, Wenliang Chen, Min Zhang, and Jingbo Zhu. Fast and accurate shift-reduce constituent parsing. In Proceedings of the 51st Annual Meeting of the ACL (Volume 1: Long Papers) , pages 434-443. ACL, August 2013.
|
| 283 |
+
|
| 284 |
+
## Attention Visualizations Input-Input Layer5
|
| 285 |
+
|
| 286 |
+
Figure 3: An example of the attention mechanism following long-distance dependencies in the encoder self-attention in layer 5 of 6. Many of the attention heads attend to a distant dependency of the verb 'making', completing the phrase 'making...more difficult'. Attentions here shown only for the word 'making'. Different colors represent different heads. Best viewed in color.
|
| 287 |
+
|
| 288 |
+
<!-- image -->
|
| 289 |
+
|
| 290 |
+
Input-Input Layer5
|
| 291 |
+
|
| 292 |
+
Figure 4: Two attention heads, also in layer 5 of 6, apparently involved in anaphora resolution. Top: Full attentions for head 5. Bottom: Isolated attentions from just the word 'its' for attention heads 5 and 6. Note that the attentions are very sharp for this word.
|
| 293 |
+
|
| 294 |
+
<!-- image -->
|
| 295 |
+
|
| 296 |
+
Input-Input Layer5
|
| 297 |
+
|
| 298 |
+
Figure 5: Many of the attention heads exhibit behaviour that seems related to the structure of the sentence. We give two such examples above, from two different heads from the encoder self-attention at layer 5 of 6. The heads clearly learned to perform different tasks.
|
| 299 |
+
|
| 300 |
+
<!-- image -->
|
text-versions/attention-markdown/1710.03743_Confidence through Attention.md
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1710.03743 Confidence Through Attention
|
| 2 |
+
|
| 3 |
+
## Confidence through Attention
|
| 4 |
+
|
| 5 |
+
## Mat¯ ıss Rikters
|
| 6 |
+
|
| 7 |
+
matiss@lielakeda.lv
|
| 8 |
+
|
| 9 |
+
Faculty of Computing, University of Latvia
|
| 10 |
+
|
| 11 |
+
## Mark Fishel
|
| 12 |
+
|
| 13 |
+
fishel@ut.ee
|
| 14 |
+
|
| 15 |
+
Institute of Computer Science, University of Tartu, Estonia
|
| 16 |
+
|
| 17 |
+
## Abstract
|
| 18 |
+
|
| 19 |
+
Attention distributions of the generated translations are a useful bi-product of attention-based recurrent neural network translation models and can be treated as soft alignments between the input and output tokens. In this work, we use attention distributions as a confidence metric for output translations. We present two strategies of using the attention distributions: filtering out bad translations from a large back-translated corpus, and selecting the best translation in a hybrid setup of two different translation systems. While manual evaluation indicated only a weak correlation between our confidence score and human judgments, the use-cases showed improvements of up to 2.22 BLEU points for filtering and 0.99 points for hybrid translation, tested on English ↔ German and English ↔ Latvian translation.
|
| 20 |
+
|
| 21 |
+
## 1 Introduction
|
| 22 |
+
|
| 23 |
+
Neural machine translation (NMT) has recently redefined the state-of-the-art in machine translation (Sennrich et al., 2016a; Wu et al., 2016a), with one of the ground-breaking innovations that enabled this being the introduction of the attention mechanism (Bahdanau et al., 2014). It enables the model to find parts of a source sentence that are relevant to predicting a target word (pay attention), without the need to form these parts as a hard segment explicitly. Decoding sentences with the attention-based model resulted in a useful by-product - soft alignments between tokens of source and target sentences. These can be used for many purposes, such as replacing unknown words with back-off translations from a dictionary (Jean et al., 2015) and visualizing the soft alignments (Rikters et al., 2017).
|
| 24 |
+
|
| 25 |
+
In this paper, we propose using the attention alignments as an indicator of the translation output quality and the confidence of the decoder. We define metrics of confidence that detect and penalize under-translation and over-translation (Tu et al., 2016) as well as input and output tokens with no clear alignment, assuming that all these cases most likely mean that the quality of the translation output is bad.
|
| 26 |
+
|
| 27 |
+
We apply these attention-based metrics to two use-cases: scoring translations of an NMT system and filtering out the seemingly unsuccessful ones, and comparing translations from two different NMT systems, in order to select the best one.
|
| 28 |
+
|
| 29 |
+
The structure of this paper is as follows: Section 2 summarizes related work in backtranslating with NMT, machine translation combination approaches and confidence estimation. Section 3 introduces the problem of faulty attention distributions and a way to quantify it as a confidence score. Sections 4 and 5 outline the two use-cases for this score - translation filtering and hybrid selections. Finally, we conclude in Section 6 and mention directions for future work in Section 7.
|
| 30 |
+
|
| 31 |
+
## 2 Related Work
|
| 32 |
+
|
| 33 |
+
## Back-translation of Monolingual Data
|
| 34 |
+
|
| 35 |
+
One of the first uses of back-translation of monolingual data as an additional source of training data was reported by (Sennrich et al., 2016a) in their submission for the WMT16 news translation shared task. They translated target-language monolingual corpora into the source language of the respective language pair, and then used the resulting synthetic parallel corpus as additional training data. They performed experiments in ranges from 2 million to 10 million back-translated sentences and reported an increase of 2.2 - 7.7 BLEU (Papineni et al., 2002) for translating between English and Czech, German, Romanian and Russian. The authors also experimented with different amounts of back-translated data and found that adding more data gradually improves performance.
|
| 36 |
+
|
| 37 |
+
In a later paper Sennrich et al. (2016b) explored other methods of using monolingual data. They experimented with adding an enormous amount of monolingual sentences as targets without any sources to the parallel corpus and compared that to performing back-translation on a part of the monolingual data. While both methods outperform using just parallel data, the back-translated synthetic parallel corpus is a much more powerful addition than the mono data alone.
|
| 38 |
+
|
| 39 |
+
Pinnis et al. (2017) experimented with using large and even larger amounts of backtranslated data and came to a conclusion that any amount is an improvement, but using double the amount gives lower results, while still better than not using any at all. These results hint that it may be possible to get even better results when using only the part of the data selected with some criterion. One of the aims of our work is to provide one such criterion.
|
| 40 |
+
|
| 41 |
+
## Machine Translation System Combination
|
| 42 |
+
|
| 43 |
+
Zhou et al. (2017) used attention to combine outputs from NMT and SMT systems. The authors first trained intermediate NMT, SMT and hierarchical SMT systems with one-half of the training data. Afterwards, they used each system to translate the target side of the other half of the training data. Finally, the three translated parts as source sentence variants along side the clean target sentence were used for training the combination neural network. This approach gave the network more choices of where to pay attention and which parts should be ignored in the training process. They perform experiments on Chinese → English and report BLEU score improvement by 5.3 points over the best single system and 3.4 points over traditional MT combination methods.
|
| 44 |
+
|
| 45 |
+
Peter et al. (2016) perform MT system combination in a more traditional manner - using confusion networks. They use 12 different SMT and NMT systems to generate hypothesis translations, align and reorder each hypothesis to match one skeleton hypothesis, creating a confusion network. For the final output is generated by finding the best path in the network. The authors report an improvement of 1.0 BLEU compared to the best single system, translating from English into Romanian.
|
| 46 |
+
|
| 47 |
+
## Translation Confidence Metrics
|
| 48 |
+
|
| 49 |
+
Lately the idea of modeling coverage in NMT was introduced, for example, Tu et al. (2016) integrate it directly into the attention mechanism and report improved translation quality as a result. On the simpler side of things, Wu et al. (2016b) perform tests with a baseline attention that uses an additional coverage penalty at decoding time; they report no improvement compared to the common length normalization. Our metrics are partially motivated by the coverage penalty, though we apply them at the post-translation stage to determine the confidence of the decoder and the quality of the already made translation, which makes it applicable regardless of which software or approach were used.
|
| 50 |
+
|
| 51 |
+
Another closely related task is quality estimation. The dominating approach there is collecting post-edits and training a machine learning model to predict the quality score or classify translations into usable/not, near-perfect/not, etc (Bach et al., 2011; Felice and Specia, 2012). The main similarity between our work and quality estimation is their usage of glass-box features (i.e. information about the MT system or the decoder's internal parameters). While our approach does not cover all aspects of quality estimation, it requires no data or training and can be applied to any language and neural machine translation system.
|
| 52 |
+
|
| 53 |
+
## 3 Penalizing Attention Disorders
|
| 54 |
+
|
| 55 |
+
Before describing the confidence metrics based on attention weights, here is a brief overview of the NMT architecture where the attention weights come from.
|
| 56 |
+
|
| 57 |
+
## 3.1 Source of Attention
|
| 58 |
+
|
| 59 |
+
Our work is built around the encoder-decoder machine translation approach (Sutskever et al., 2014; Cho et al., 2014) with an attention mechanism (Bahdanau et al., 2014). In this approach the source tokens are learned to be represented by an encoder, which consists of an embedding layer and a bi-directional LSTM or GRU layer (or 8, Wu et al., 2016b), the outputs of which serve as the learned representation.
|
| 60 |
+
|
| 61 |
+
There is also a decoder that consists of another layer (or 8, ibid.) of LSTM/GRU cells, with an output layer for predicting the softmax-encoded raw probability distribution of each output word, one at a time. The state of the decoder layer(s) and thus the output distribution depends on the previous recurrent states, the previously produced output word and a weighted sum of the representations of the source sentence tokens. The weights in this sum are generated for every output word by the attention mechanism, which is a feed-forward neural network with the previous state of the decoder and each input word representation as input and the raw weight of that word for the next state as output. Finally, the attention weights are normalized as follows:
|
| 62 |
+
|
| 63 |
+
<!-- formula-not-decoded -->
|
| 64 |
+
|
| 65 |
+
where e ij is the raw predicted weight and α ij - the final attention weight between the input token j and output token i .
|
| 66 |
+
|
| 67 |
+
Once the encoder-decoder network has been trained, it can be used to produce translations by predicting the probability for each next word, which can serve as the basis for sampling, greedy search or beam search (Sennrich et al., 2017). We refer the reader for a complete description to (Bahdanau et al., 2014) and ourselves turn on to the main topic of the paper that uses the weights α ij to estimate the confidence of the translations.
|
| 68 |
+
|
| 69 |
+
Together with the translation, it is also possible to save the attention values between the input tokens and each produced output token. These values can be interpreted as the influence of the input token on the output token, or the strength of the connection between them. Thus, weak or dispersed connections should intuitively indicate a translation with low confidence, while high values and strong connections between one or two tokens on both sides should indicate higher confidence. Next, we present our take at formalizing this intuition.
|
| 70 |
+
|
| 71 |
+
## 3.2 Measuring Attention
|
| 72 |
+
|
| 73 |
+
Figure 1 shows an example of a translation that has little or nothing to do with the input, a frequent occurrence in NMT. Besides the text of the translation, it is clear already by looking at the attention weights of this pair that the translation is weak:
|
| 74 |
+
|
| 75 |
+
- some input tokens (like the sentence-final full-stop) are most strongly connected to several unrelated output tokens, in other words, their coverage is too high,
|
| 76 |
+
- most of the input token attentions, as well as some output token attentions, are highly dispersed, without one or two clear associations on the counterpart.
|
| 77 |
+
|
| 78 |
+
Figure 1: Attention alignment visualization of a bad translation. Reference translation: 71 traffic accidents in which 16 persons were injured have happened in Latvia during the last 24 hours. , hypothesis translation: the latest , in the last few days , the EU has been in the final day of the EU 's ' European Year of Intercultural Dialogue ' . CDP = -0 . 900 , AP out = -2 . 809 , AP in = -2 . 137 , Total = -5 . 846 .
|
| 79 |
+
|
| 80 |
+
<!-- image -->
|
| 81 |
+
|
| 82 |
+
On the other hand, a picture like Figure 2 intuitively corresponds to a good translation, with strongly focused alignments. It is this intuition that our metrics formalize: penalizing translations with tokens with a total coverage of not just below but much higher than 1.0, as well as tokens with a dispersed attention distribution.
|
| 83 |
+
|
| 84 |
+
## Coverage Deviation Penalty
|
| 85 |
+
|
| 86 |
+
Previous work (Wu et al., 2016b) defines a coverage penalty, which is meant to punish translations for not paying enough attention to input tokens:
|
| 87 |
+
|
| 88 |
+
<!-- formula-not-decoded -->
|
| 89 |
+
|
| 90 |
+
where i is the output token index, j - the input token index, β is used to control the influence of the metric and CP - the coverage penalty.
|
| 91 |
+
|
| 92 |
+
The first part of our metric draws inspiration from the coverage penalty; however, it penalizes not just lacking attention but also too much attention per input token. The aim is to penalize the sum of attentions per input token for going too far from 1.0 1 , so tokens with total attention of 1.0 should get a score of 0.0 on the logarithmic scale, while tokens with less attention (like 0.2) or more attention (like 2.5) should get lower values. We thus define the coverage deviation penalty:
|
| 93 |
+
|
| 94 |
+
<!-- formula-not-decoded -->
|
| 95 |
+
|
| 96 |
+
where J is the length of the input sentence. The metric is on a logarithmic scale, and it is normalized by the length of the input sentence in order to avoid assigning higher scores to shorter sentences 2 . See examples of the CDP metric's values on Figures 1 and 2.
|
| 97 |
+
|
| 98 |
+
1 This could be replaced with the token's expected fertility, which we leave for future work
|
| 99 |
+
|
| 100 |
+
2 This is not required for choosing translations of the same sentence by the same system, but is required in our
|
| 101 |
+
|
| 102 |
+
Figure 2: Attention alignment visualization of a good translation. Reference translation: He was a kind spirit with a big heart. , hypothesis translation: he was a good man with a broad heart . CDP = -0 . 099 , AP out = -1 . 077 , AP in = -0 . 847 , Total = -2 . 024 .
|
| 103 |
+
|
| 104 |
+
<!-- image -->
|
| 105 |
+
|
| 106 |
+
## Absentmindedness Penalty
|
| 107 |
+
|
| 108 |
+
However, it is not enough to simply cover the input, we conjecture that more confident output tokens will allocate most of their attention probability mass to one or a small number of input tokens. Thus the second part of our metric is called the absentmindedness penalty and targets scattered attention per output token, where the dispersion is evaluated via the entropy of the predicted attention distribution. Again, we want the penalty value to be 1.0 for the lowest entropy and head towards 0.0 for higher entropies.
|
| 109 |
+
|
| 110 |
+
<!-- formula-not-decoded -->
|
| 111 |
+
|
| 112 |
+
The values are again on the log-scale and normalized by the source sentence length I .
|
| 113 |
+
|
| 114 |
+
The absentmindedness penalty can also be applied to the input tokens after normalizing the distribution of attention per input token, resulting in the counter-part metric AP in . This is based on the assumption that it is not enough to cover the input token, but rather the input token should be used to produce a small number of outputs. See examples of both metric's values on Figures 1 and 2.
|
| 115 |
+
|
| 116 |
+
Finally, we combine the coverage deviation penalty with both the input and output absentmindedness penalties into a joint metric via summation:
|
| 117 |
+
|
| 118 |
+
<!-- formula-not-decoded -->
|
| 119 |
+
|
| 120 |
+
Next, we evaluate the metrics directly against human judgments and indirectly by applying them to filtering translations and plugging them into a sentence-level hybrid translation scheme.
|
| 121 |
+
|
| 122 |
+
## 3.3 Human Evaluation
|
| 123 |
+
|
| 124 |
+
It is clear that the defined metrics only paint a partial picture, since they rely on the attention weights only. For instance, they do not evaluate the lexical correspondence between the source and hypothesis, and more generally, being confident does not mean being right. We wanted to find out how much confidence in our case correlates with translation quality.
|
| 125 |
+
|
| 126 |
+
experiments described in the next sections.
|
| 127 |
+
|
| 128 |
+
To do so we asked human volunteers to perform pairwise ranking of translations from two baseline NMT systems: one done with Nematus (Sennrich et al., 2017) and the other - with Neural Monkey (Helcl and Libovick` y, 2017). The translations and measurements were done for English-Latvian and Latvian-English, using corpora from the news translation shared task of WMT'2017; further details can be found in Section 4. We selected 200 random sentences for both translation directions and these were given to native Latvian speakers for evaluation. The MT-EQuAl (Girardi et al., 2014) tool was used for the evaluation task. The evaluators were shown one source sentence at a time along with the two different translations. They were instructed to assign one of five categories for each translation: 'worst', 'bad', 'ok', 'good' or 'best', noting that both may be categorized as equally 'good' or 'bad', etc. Differing judgments for the same sentence were averaged. All 200 sentences were annotated by at least one human annotator.
|
| 129 |
+
|
| 130 |
+
It makes more sense to treat the results as relative comparisons, not absolute scores, as the annotators only see two translations at a time. We use these comparisons to compute the Kendall rank correlation coefficient (Kendall, 1938) by only looking at the pairs where human scores differ. Since we only have comparisons for each pair and not between different sentences, the coefficient is computed as
|
| 131 |
+
|
| 132 |
+
<!-- formula-not-decoded -->
|
| 133 |
+
|
| 134 |
+
where pos is the number of pairs where the metric agrees with the human judgment and neg is the number of pairs where they disagree.
|
| 135 |
+
|
| 136 |
+
The results are presented in Table 1, and as we can see they indicate weak correlation, with the absolute values of τ between 0 . 012 and 0 . 200 .
|
| 137 |
+
|
| 138 |
+
Table 1: The Kendall's Tau correlation between human judgments and the confidence scores.
|
| 139 |
+
|
| 140 |
+
| Language pair CDP AP in AP out Overall En → Lv 0.099 0.074 0.123 0.086 Lv → En -0.012 -0.153 -0.200 -0.153 |
|
| 141 |
+
|----------------------------------------------------------------------------------------------------------------------------------|
|
| 142 |
+
|
| 143 |
+
Let us look closer at where the metrics disagree with human judgments. Figure 3 shows an example of a translation which was rated highly by human annotators but poorly with our metrics. While the sentence is a good translation, it does not follow the source word-by-word. Some subword units and functional words do not have a clear alignment, even though they are understood/generated correctly. This means that one problem with our metrics is that they might be over-penalizing translations that deviate from a direct literal translation.
|
| 144 |
+
|
| 145 |
+
Next, we continue with the experiments of using our metrics to filter synthetic data and to select translations in a hybrid MT scenario.
|
| 146 |
+
|
| 147 |
+
Figure 3: Attention alignment visualization of a bad translation. Reference translation: a 28year-old chef who had recently moved to San Francisco was found dead in the stairwell of a local mall this week . , hypothesis translation: a 28-year-old old man who has recently moved to San Francisco has died this week . , CDP = -0 . 250 , AP out = -1 . 740 , AP in = -1 . 46 , Total = -3 . 45 .
|
| 148 |
+
|
| 149 |
+
<!-- image -->
|
| 150 |
+
|
| 151 |
+
## 4 Filtering Back-translated Data
|
| 152 |
+
|
| 153 |
+
## 4.1 Baseline Systems and Data
|
| 154 |
+
|
| 155 |
+
Our baseline systems were trained with two NMT frameworks - Nematus (NT) (Sennrich et al., 2017) and Neural Monkey (NM) (Helcl and Libovick` y, 2017). For all NMT models we used a shared subword unit vocabulary (Sennrich et al., 2016c) of 35000 tokens, clip the gradient norm to 1.0 (Pascanu et al., 2013), dropout of 0.2, trained the models with Adadelta (Zeiler, 2012) and performed early stopping after 7 days of training. For models with each NMT framework we used the default settings as mentioned in the frameworks documentation:
|
| 156 |
+
|
| 157 |
+
- For NT models we used a maximum sentence length of 50, word embeddings of size 512, and hidden layers of size 1000. For decoding with NT we used beam search with a beam size of 12.
|
| 158 |
+
- For NM models we used a maximum sentence length of 70, word embeddings and hidden layers of size 600. For decoding with NM a greedy decoder was used.
|
| 159 |
+
|
| 160 |
+
Training, development and test data for all systems in both language pairs and translation directions was used from the WMT17 news translation task 3 . For the baseline systems, we used all available parallel data, which is 5.8 million sentences for En ↔ De and 4.5 million sentences for En ↔ Lv.
|
| 161 |
+
|
| 162 |
+
## 4.2 Back-translating and Filtering
|
| 163 |
+
|
| 164 |
+
Weused our baseline En → Lv and Lv → En NM and NT systems to translate all available Latvian monolingual news domain data - 6.3 million sentences in total from News Crawl: articles from 2014, 2015, 2016 , and the first 6 million sentences from the English News Crawl 2016 . Much more monolingual data was available from other domains aside from news. Since the development and test data was of the news domain, we only used that, considering it as indomain data for our systems.
|
| 165 |
+
|
| 166 |
+
3 EMNLP 2017 Second Conference on Machine Translation - http://www.statmt.org/wmt17/
|
| 167 |
+
|
| 168 |
+
For each translation, we used the attention provided from the NMT system to calculate our confidence score, sorted all translations according to the score and selected the top half of the translations along with the corresponding source sentences as the synthetic parallel corpus. We used only the full confidence score (combination of CDP, AP out and AP in ) for filtering instead of each individual score due to its smoother overall correlation with human judgments. In between, we also removed any translation that contained any < unk > tokens.
|
| 169 |
+
|
| 170 |
+
To compare attention-based filtering with a different method, we trained a CharRNN 4 language model (LM) with 4 million news sentences from each of the target languages. We used these LMs to get perplexity scores for all translations, order them and get the better half . Table 2 summarizes how much human evaluation overlaps with each of the filtering methods. The final row indicates how much both filtering methods overlap with each other. While results from either approach don't look overly convincing, the LM-based approach has been proven to correlate with human judgments close to the BLEU score and is a good evaluation method for MT without reference translations (Gamon et al., 2005). Therefore the attention-based approach that does not require training of an additional model and overlaps with human judgments to approximately the same level should be more desirable.
|
| 171 |
+
|
| 172 |
+
Table 2: Human judgment overlap results on 200 random sentences from the newsdev2017 dataset compared to filtering methods.
|
| 173 |
+
|
| 174 |
+
| Filtering Method En → Lv Lv → En LM-based overlap with human 58% 56% Attention-based overlap with human 52% 60% LM-based overlap with Attention-based 34% 22% |
|
| 175 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 176 |
+
|
| 177 |
+
## 4.3 NMTwith Filtered Synthetic Data
|
| 178 |
+
|
| 179 |
+
Figure 4: Automatic evaluation progression of Lv → En experiments on validation data. Orange - baseline; dark blue - with full back-translated data; green - with LM-filtered back-translated data; light blue - with attention-filtered back-translated data.
|
| 180 |
+
|
| 181 |
+
<!-- image -->
|
| 182 |
+
|
| 183 |
+
We shuffled each synthetic parallel corpus with the baseline parallel corpora and used them to train NMT systems. In addition to the baseline and two types of filtered BT synthetic data, we also trained a system with the full BT data for each translation direction. Figure 4
|
| 184 |
+
|
| 185 |
+
4 Multi-layer Recurrent Neural Networks (LSTM, GRU, RNN) for character - level language models in Torch https://github.com/karpathy/char-rnn
|
| 186 |
+
|
| 187 |
+
shows a combined training progress chart for Lv → En on the full newsdev2017 dataset that was used as the development set for training. Here the differences between all four approaches are clearly visible. Further results on a subset of newsdev2017 and the full newstest2017 dataset are summarized in Table 3. While for Lv → En and En ↔ De the attention-based approach is the clear leader, for En → Lv it falls behind the LM filtered version. We were not able to identify a clear reason for this and leave it for the future work. As expected, adding BT synthetic training data allows to get higher BLEU scores in all cases. It can be observed that filtering out half of the badly translated data and keeping only the best translations either does not decrease the final output quality in some cases or even further increase the quality in others, when using the LM. With filtering by attention, the results are more inconsistent - even higher in one direction while deterioration in the other. A reason for this could be that for Lv → En attention-based filtering the similarity with human judgments was higher than for En → Lv (Table 2), and it was also more different from the LM-based one. While for the other direction it is the other way around.
|
| 188 |
+
|
| 189 |
+
Table 3: Experiment results in BLEU for translating between English ↔ Latvian with different types of back-translated data using development (200 random sentences from newsdev2017 ) and test ( newstest2017 ) datasets.
|
| 190 |
+
|
| 191 |
+
| BLEU Dataset Dev Test Dev Test Dev Test Dev Test System En → Lv Lv → En En → De De → En Baseline 8.36 11.90 8.64 12.40 25.84 20.11 30.18 26.26 + Full Synthetic 9.42 13.50 9.01 13.81 28.97 22.68 34.82 29.35 + LM-Filtered Synthetic 9.75 13.52 9.45 14.30 29.59 23.48 34.47 29.42 + Attn.-Filtered Synth. 8.99 12.76 11.23 14.83 30.19 23.16 35.19 29.47 |
|
| 192 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 193 |
+
|
| 194 |
+
## 5 Attention-based Hybrid Decisions
|
| 195 |
+
|
| 196 |
+
We translated the development set with both baseline systems for each language pair in each direction. The hybrid selection of the best translation was performed similarly to filtering, where we discarded the worst-scoring half of the translations. In the hybrid selection, we used the same score to compare both translations of a source sentence and choose the better one. Results of the hybrid selection experiments are summarized in Table 4. For translating between En ↔ Lv, where the difference between the baseline systems is not that high (0.06 and 1.55 BLEU), the hybrid method achieves some meaningful improvements. However, for En ↔ De, where differences between the baseline systems are bigger (3.46 and 4.46 BLEU), the hybrid drags both scores down.
|
| 197 |
+
|
| 198 |
+
Table 4: Hybrid selection experiment results in BLEU on the development dataset (200 random sentences from newsdev2017 ).
|
| 199 |
+
|
| 200 |
+
| BLEU System En → De De → En En → Lv Lv → En Neural Monkey 18.89 26.07 13.74 11.09 Nematus 22.35 30.53 13.80 12.64 Hybrid 20.19 27.06 14.79 12.65 Human 23.86 34.26 15.12 13.24 |
|
| 201 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 202 |
+
|
| 203 |
+
The last row of the results Table 4 shows BLEU scores for the scenario when human an- notator preferences were used to select each output sentence. An overview of human evaluator preferred translation selections is visible in Table 5. The results show that out of all translations the human evaluators deliberately prefer one or the other system. Aside from En → Lv, where a slight tendency towards Neural Monkey translations can be observed, all others look more or less equal. This highly contrasts with the BLEU scores from Table 4, where in both translation directions from English human evaluators prefer the lower-scoring system more often than the higher-scoring one. The final row of Table 5 shows how much our attention-based score matches the human judgments in selecting the best translation.
|
| 204 |
+
|
| 205 |
+
Table 5: Human evaluation results on 200 random sentences from the newsdev2017 dataset compared to attention-hybrid selection.
|
| 206 |
+
|
| 207 |
+
| System En → De De → En En → Lv Lv → En Neural Monkey 54% 42% 61.5% 47% Nematus 46% 58% 38.5% 53% Overlaps with hybrid selection 57% 47% 62.5% 51% |
|
| 208 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 209 |
+
|
| 210 |
+
## 6 Conclusions
|
| 211 |
+
|
| 212 |
+
In this paper, we described how attentional data from neural machine translation systems can be useful for more than just visualizations or replacing specific tokens in the output. We introduced an attention-based confidence score that can be used for judging NMT output. Two applications of using attentional data were investigated and compared to similar approaches. We used a smaller dataset to perform manual evaluation and compared that to all automatically obtained results. Our experiments showed interesting results and some increases in automated evaluation, as well as a good correlation with human judgments.
|
| 213 |
+
|
| 214 |
+
In addition to the methods described in this paper, we release open-source scripts 5 for (1) scoring, ordering and filtering NMT translations, (2) performing hybrid selections between two different NMT outputs of the same source, and (3) software for inspecting attention alignments that the NMT systems produce in the translation process (used for Figures 1 and 2). We also provide all development subsets that we used for manual evaluation with anonymized human annotations.
|
| 215 |
+
|
| 216 |
+
## 7 Future Work
|
| 217 |
+
|
| 218 |
+
This paper introduced the first steps in using NMT attention for less obvious intentions. It seemed that the attention score can complement the LM perplexity score in distinguishing good from bad translations. An idea for future experiments could be combining these scores to achieve a higher correlation with human judgments.
|
| 219 |
+
|
| 220 |
+
Additional improvements can be made to the hybrid decisions as well. Since the score represents the systems confidence , a badly trained NMT system can be more confident about a bad translation than a good system about a decent translation. While a hybrid combination of two similar quality NMT systems did put the attention score to good use, in the case with different quality systems the confidence of the weaker one was a pitfall. This indicates that the confidence score could be used in ensemble with a quality estimation score or used as a feature in training an MT quality estimation system.
|
| 221 |
+
|
| 222 |
+
For filtering synthetic back-translated data we dropped the worst-scoring 50% of the data, but this threshold may not be optimal for all scenarios. Several paths worth more exploration include exploring the effects of different static thresholds (e.g. 30% or 70%) or clustering the data by confidence score and dropping the lowest-scoring one or two clusters. Another path worth exploring for filtering would be to see how filtering by each individual score (CDP, AP in , AP out ) compares to filtering by confidence.
|
| 223 |
+
|
| 224 |
+
5 Confidence Through Attention - https://github.com/M4t1ss/ConfidenceThroughAttention
|
| 225 |
+
|
| 226 |
+
In the near future, we also plan to supplement an attention inspection tool so that it displays confidence metrics and additional visualizations based on these scores.
|
| 227 |
+
|
| 228 |
+
## References
|
| 229 |
+
|
| 230 |
+
- Bach, N., Huang, F., and Al-Onaizan, Y. (2011). Goodness: A method for measuring machine translation confidence. In Proceedings of the 49th Annual Meeting of the Association for Computational Linguistics: Human Language Technologies , pages 211-219, Portland, Oregon, USA. Association for Computational Linguistics.
|
| 231 |
+
- Bahdanau, D., Cho, K., and Bengio, Y. (2014). Neural machine translation by jointly learning to align and translate. CoRR , abs/1409.0473.
|
| 232 |
+
- Cho, K., van Merrienboer, B., Gulcehre, C., Bahdanau, D., Bougares, F., Schwenk, H., and Bengio, Y. (2014). Learning phrase representations using rnn encoder-decoder for statistical machine translation. In Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing (EMNLP) , pages 1724-1734, Doha, Qatar. Association for Computational Linguistics.
|
| 233 |
+
- Felice, M. and Specia, L. (2012). Linguistic features for quality estimation. In Proceedings of the Seventh Workshop on Statistical Machine Translation , pages 96-103, Montr´ eal, Canada.
|
| 234 |
+
- Gamon, M., Aue, A., and Smets, M. (2005). Sentence-level mt evaluation without reference translations: Beyond language modeling. In Proceedings of EAMT , pages 103-111.
|
| 235 |
+
- Girardi, C., Bentivogli, L., Farajian, M. A., and Federico, M. (2014). MT-EQuAl: a Toolkit for Human Assessment of Machine Translation Output. In Proceedings of COLING 2014, the 25th International Conference on Computational Linguistics: System Demonstrations , pages 120-123.
|
| 236 |
+
- Helcl, J. and Libovick` y, J. (2017). Neural monkey: An open-source tool for sequence learning. The Prague Bulletin of Mathematical Linguistics , 107(1):5-17.
|
| 237 |
+
- Jean, S., Cho, K., Memisevic, R., and Bengio, Y. (2015). On using very large target vocabulary for neural machine translation. In Proceedings of the 53rd Annual Meeting of the Association for Computational Linguistics and the 7th International Joint Conference on Natural Language Processing (Volume 1: Long Papers) , pages 1-10, Beijing, China. Association for Computational Linguistics.
|
| 238 |
+
- Kendall, M. (1938). A new measure of rank correlation. Biometrika , 30(1-2):81-89.
|
| 239 |
+
- Papineni, K., Roukos, S., Ward, T., and Zhu, W.-J. (2002). Bleu: a method for automatic evaluation of machine translation. In Proceedings of the 40th annual meeting on association for computational linguistics , pages 311-318. Association for Computational Linguistics.
|
| 240 |
+
- Pascanu, R., Mikolov, T., and Bengio, Y. (2013). On the difficulty of training recurrent neural networks. ICML (3) , 28:1310-1318.
|
| 241 |
+
- Peter, J.-T., Alkhouli, T., Ney, H., Huck, M., Braune, F., Fraser, A., Tamchyna, A., Bojar, O., Haddow, B., Sennrich, R., Blain, F., Specia, L., Niehues, J., Waibel, A., Allauzen, A., Aufrant, L., Burlot, F., Knyazeva, E., Lavergne, T., Yvon, F., Frank, S., Daiber, J., and Pinnis, M. (2016). The QT21/HimL Combined Machine Translation System. Proceedings of the First Conference on Machine Translation (WMT 2016), Volume 2: Shared Task Papers , 2:344--355.
|
| 242 |
+
- Pinnis, M., Krislauks, R., Deksne, D., and Miks, T. (2017). Neural machine translation for morphologically rich languages with improved sub-word units and synthetic data. In International Conference on Text, Speech, and Dialogue , pages 20-27. Springer.
|
| 243 |
+
- Rikters, M., Fishel, M., and Bojar, O. (2017). Visualizing neural machine translation attention and confidence. The Prague Bulletin of Mathematical Linguistics , 109(3):in print.
|
| 244 |
+
- Sennrich, R., Firat, O., Cho, K., Birch, A., Haddow, B., Hitschler, J., Junczys-Dowmunt, M., L¨ aubli, S., Miceli Barone, A. V ., Mokry, J., and Nadejde, M. (2017). Nematus: a toolkit for neural machine translation. In Proceedings of the Software Demonstrations of the 15th Conference of the European Chapter of the Association for Computational Linguistics , pages 65-68, Valencia, Spain. Association for Computational Linguistics.
|
| 245 |
+
- Sennrich, R., Haddow, B., and Birch, A. (2016a). Edinburgh neural machine translation systems for wmt 16. In Proceedings of the First Conference on Machine Translation , pages 371376, Berlin, Germany. Association for Computational Linguistics.
|
| 246 |
+
- Sennrich, R., Haddow, B., and Birch, A. (2016b). Improving neural machine translation models with monolingual data. In Proceedings of the 54th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers) , pages 86-96, Berlin, Germany. Association for Computational Linguistics.
|
| 247 |
+
- Sennrich, R., Haddow, B., and Birch, A. (2016c). Neural Machine Translation of Rare Words with Subword Units. In In Proceedings of the 54th Annual Meeting of the Association for Computational Linguistics (ACL 2016) , pages 1715-1725, Berlin, Germany. Association for Computational Linguistics.
|
| 248 |
+
- Sutskever, I., Vinyals, O., and Le, Q. V. (2014). Sequence to sequence learning with neural networks. In Advances in neural information processing systems , pages 3104-3112, Montreal, Canada.
|
| 249 |
+
- Tu, Z., Lu, Z., Liu, Y ., Liu, X., and Li, H. (2016). Modeling coverage for neural machine translation. In Proceedings of the 54th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers) , pages 76-85, Berlin, Germany.
|
| 250 |
+
- Wu, Y., Schuster, M., Chen, Z., Le, Q. V., Norouzi, M., Macherey, W., Krikun, M., Cao, Y., Gao, Q., Macherey, K., et al. (2016a). Google's neural machine translation system: Bridging the gap between human and machine translation. arXiv preprint arXiv:1609.08144 .
|
| 251 |
+
- Wu, Y., Schuster, M., Chen, Z., Le, Q. V., Norouzi, M., Macherey, W., Krikun, M., Cao, Y., Gao, Q., Macherey, K., Klingner, J., Shah, A., Johnson, M., Liu, X., Kaiser, L., Gouws, S., Kato, Y., Kudo, T., Kazawa, H., Stevens, K., Kurian, G., Patil, N., Wang, W., Young, C., Smith, J., Riesa, J., Rudnick, A., Vinyals, O., Corrado, G., Hughes, M., and Dean, J. (2016b). Google's neural machine translation system: Bridging the gap between human and machine translation. CoRR , abs/1609.08144.
|
| 252 |
+
- Zeiler, M. D. (2012). Adadelta: an adaptive learning rate method. arXiv preprint arXiv:1212.5701 .
|
| 253 |
+
- Zhou, L., Hu, W., Zhang, J., and Zong, C. (2017). Neural System Combination for Machine Translation.
|
text-versions/attention-markdown/1803.08475_Attention Learn to Solve Routing Problem.md
ADDED
|
@@ -0,0 +1,572 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1803.08475 Attention Learn To Solve Routing Problem
|
| 2 |
+
|
| 3 |
+
## ATTENTION, LEARN TO SOLVE ROUTING PROBLEMS!
|
| 4 |
+
|
| 5 |
+
Wouter Kool University of Amsterdam ORTEC
|
| 6 |
+
|
| 7 |
+
w.w.m.kool@uva.nl Herke van Hoof University of Amsterdam h.c.vanhoof@uva.nl
|
| 8 |
+
|
| 9 |
+
## ABSTRACT
|
| 10 |
+
|
| 11 |
+
The recently presented idea to learn heuristics for combinatorial optimization problems is promising as it can save costly development. However, to push this idea towards practical implementation, we need better models and better ways of training. We contribute in both directions: we propose a model based on attention layers with benefits over the Pointer Network and we show how to train this model using REINFORCE with a simple baseline based on a deterministic greedy rollout, which we find is more efficient than using a value function. We significantly improve over recent learned heuristics for the Travelling Salesman Problem (TSP), getting close to optimal results for problems up to 100 nodes. With the same hyperparameters, we learn strong heuristics for two variants of the Vehicle Routing Problem (VRP), the Orienteering Problem (OP) and (a stochastic variant of) the Prize Collecting TSP (PCTSP), outperforming a wide range of baselines and getting results close to highly optimized and specialized algorithms.
|
| 12 |
+
|
| 13 |
+
## 1 INTRODUCTION
|
| 14 |
+
|
| 15 |
+
Imagine yourself travelling to a scientific conference. The field is popular, and surely you do not want to miss out on anything. You have selected several posters you want to visit, and naturally you must return to the place where you are now: the coffee corner. In which order should you visit the posters, to minimize your time walking around? This is the Travelling Scientist Problem (TSP).
|
| 16 |
+
|
| 17 |
+
You realize that your problem is equivalent to the Travelling Salesman Problem (conveniently also TSP). This seems discouraging as you know the problem is (NP-)hard (Garey & Johnson, 1979). Fortunately, complexity theory analyzes the worst case, and your Bayesian view considers this unlikely. In particular, you have a strong prior: the posters will probably be laid out regularly. You want a special algorithm that solves not any, but this type of problem instance. You have some months left to prepare. As a machine learner, you wonder whether your algorithm can be learned?
|
| 18 |
+
|
| 19 |
+
Motivation Machine learning algorithms have replaced humans as the engineers of algorithms to solve various tasks. A decade ago, computer vision algorithms used hand-crafted features but today they are learned end-to-end by Deep Neural Networks (DNNs). DNNs have outperformed classic approaches in speech recognition, machine translation, image captioning and other problems, by learning from data (LeCun et al., 2015). While DNNs are mainly used to make predictions , Reinforcement Learning (RL) has enabled algorithms to learn to make decisions , either by interacting with an environment, e.g. to learn to play Atari games (Mnih et al., 2015), or by inducing knowledge through look-ahead search: this was used to master the game of Go (Silver et al., 2017).
|
| 20 |
+
|
| 21 |
+
The world is not a game, and we desire to train models that make decisions to solve real problems. These models must learn to select good solutions for a problem from a combinatorially large set of potential solutions. Classically, approaches to this problem of combinatorial optimization can be divided into exact methods , that guarantee finding optimal solutions, and heuristics , that trade off optimality for computational cost, although exact methods can use heuristics internally and vice versa. Heuristics are typically expressed in the form of rules, which can be interpreted as policies to make decisions. We believe that these policies can be parameterized using DNNs, and be trained to obtain new and stronger algorithms for many different combinatorial optimization problems, similar to the way DNNs have boosted performance in the applications mentioned before. In this paper, we focus on routing problems: an important class of practical combinatorial optimization problems.
|
| 22 |
+
|
| 23 |
+
Max Welling University of Amsterdam CIFAR
|
| 24 |
+
|
| 25 |
+
m.welling@uva.nl The promising idea to learn heuristics has been tested on TSP (Bello et al., 2016). In order to push this idea, we need better models and better ways of training. Therefore, we propose to use a powerful model based on attention and we propose to train this model using REINFORCE with a simple but effective greedy rollout baseline. The goal of our method is not to outperform a nonlearned, specialized TSP algorithm such as Concorde (Applegate et al., 2006). Rather, we show the flexibility of our approach on multiple (routing) problems of reasonable size, with a single set of hyperparameters . This is important progress towards the situation where we can learn strong heuristics to solve a wide range of different practical problems for which no good heuristics exist.
|
| 26 |
+
|
| 27 |
+
## 2 RELATED WORK
|
| 28 |
+
|
| 29 |
+
The application of Neural Networks (NNs) for optimizing decisions in combinatorial optimization problems dates back to Hopfield & Tank (1985), who applied a Hopfield-network for solving small TSP instances. NNs have been applied to many related problems (Smith, 1999), although in most cases in an online manner, starting 'from scratch' and 'learning' a solution for every instance. More recently, (D)NNs have also been used offline to learn about an entire class of problem instances.
|
| 30 |
+
|
| 31 |
+
Vinyals et al. (2015) introduce the Pointer Network (PN) as a model that uses attention to output a permutation of the input, and train this model offline to solve the (Euclidean) TSP, supervised by example solutions. Upon test time, their beam search procedure filters invalid tours. Bello et al. (2016) introduce an Actor-Critic algorithm to train the PN without supervised solutions. They consider each instance as a training sample and use the cost (tour length) of a sampled solution for an unbiased Monte-Carlo estimate of the policy gradient. They introduce extra model depth in the decoder by an additional glimpse (Vinyals et al., 2016) at the embeddings, masking nodes already visited. For small instances ( n = 20 ), they get close to the results by Vinyals et al. (2015), they improve for n = 50 and additionally include results for n = 100 . Nazari et al. (2018) replace the LSTM encoder of the PN by element-wise projections, such that the updated embeddings after state-changes can be effectively computed. They apply this model on the Vehicle Routing Problem (VRP) with split deliveries and a stochastic variant.
|
| 32 |
+
|
| 33 |
+
Dai et al. (2017) do not use a separate encoder and decoder, but a single model based on graph embeddings. They train the model to output the order in which nodes are inserted into a partial tour, using a helper function to insert at the best possible location. Their 1-step DQN (Mnih et al., 2015) training method trains the algorithm per step and incremental rewards provided to the agent at every step effectively encourage greedy behavior. As mentioned in their appendix, they use the negative of the reward, which combined with discounting encourages the agent to insert the farthest nodes first, which is known to be an effective heuristic (Rosenkrantz et al., 2009).
|
| 34 |
+
|
| 35 |
+
Nowak et al. (2017) train a Graph Neural Network in a supervised manner to directly output a tour as an adjacency matrix, which is converted into a feasible solution by a beam search. The model is non-autoregressive, so cannot condition its output on the partial tour and the authors report an optimality gap of 2 . 7% for n = 20 , worse than autoregressive approaches mentioned in this section. Kaempfer & Wolf (2018) train a model based on the Transformer architecture (Vaswani et al., 2017) that outputs a fractional solution to the multiple TSP (mTSP). The result can be seen as a solution to the linear relaxation of the problem and they use a beam search to obtain a feasible integer solution.
|
| 36 |
+
|
| 37 |
+
Independently of our work, Deudon et al. (2018) presented a model for TSP using attention in the OR community. They show performance can improve using 2OPT local search, but do not show benefit of their model in direct comparison to the PN. We use a different decoder and improved training algorithm, both contributing to significantly improved results, without 2OPT and additionally show application to different problems. For a full discussion of the differences, we refer to Appendix B.4.
|
| 38 |
+
|
| 39 |
+
## 3 ATTENTION MODEL
|
| 40 |
+
|
| 41 |
+
Wedefine the Attention Model in terms of the TSP. For other problems, the model is the same but the input, mask and decoder context need to be defined accordingly, which is discussed in the Appendix. We define a problem instance s as a graph with n nodes, where node i ∈ { 1 , . . . , n } is represented by features x i . For TSP, x i is the coordinate of node i and the graph is fully connected (with selfconnections) but in general, the model can be considered a Graph Attention Network (Velickovic
|
| 42 |
+
|
| 43 |
+
̸
|
| 44 |
+
|
| 45 |
+
̸
|
| 46 |
+
|
| 47 |
+
et al., 2018) and take graph structure into account by a masking procedure (see Appendix A). We define a solution (tour) π = ( π 1 , . . . , π n ) as a permutation of the nodes, so π t ∈ { 1 , . . . n } and π t = π t ′ ∀ t = t ′ . Our attention based encoder-decoder model defines a stochastic policy p ( π | s ) for selecting a solution π given a problem instance s . It is factorized and parameterized by θ as
|
| 48 |
+
|
| 49 |
+
<!-- formula-not-decoded -->
|
| 50 |
+
|
| 51 |
+
The encoder produces embeddings of all input nodes. The decoder produces the sequence π of input nodes, one node at a time. It takes as input the encoder embeddings and a problem specific mask and context. For TSP, when a partial tour has been constructed, it cannot be changed and the remaining problem is to find a path from the last node, through all unvisited nodes, to the first node. The order and coordinates of other nodes already visited are irrelevant. To know the first and last node, the decoder context consists (next to the graph embedding) of embeddings of the first and last node. Similar to Bello et al. (2016), the decoder observes a mask to know which nodes have been visited.
|
| 52 |
+
|
| 53 |
+
## 3.1 ENCODER
|
| 54 |
+
|
| 55 |
+
The encoder that we use (Figure 1) is similar to the encoder used in the Transformer architecture by Vaswani et al. (2017), but we do not use positional encoding such that the resulting node embeddings are invariant to the input order. From the d x-dimensional input features x i (for TSP d x = 2), the encoder computes initial d h-dimensional node embeddings h (0) i (we use d h = 128 ) through a learned linear projection with parameters W x and b x : h (0) i = W x x i + b x . The embeddings are updated using N attention layers, each consisting of two sublayers. We denote with h ( ℓ ) i the node embeddings produced by layer ℓ ∈ { 1 , .., N }
|
| 56 |
+
|
| 57 |
+
Figure 1: Attention based encoder. Input nodes are embedded and processed by N sequential layers, each consisting of a multi-head attention (MHA) and node-wise feed-forward (FF) sublayer. The graph embedding is computed as the mean of node embeddings. Best viewed in color.
|
| 58 |
+
|
| 59 |
+
<!-- image -->
|
| 60 |
+
|
| 61 |
+
. The encoder computes an aggregated embedding ¯ h ( N ) of the input graph as the mean of the final node embeddings h ( N ) i : ¯ h ( N ) = 1 n ∑ n i =1 h ( N ) i . Both the node embeddings h ( N ) i and the graph embedding ¯ h ( N ) are used as input to the decoder.
|
| 62 |
+
|
| 63 |
+
Attention layer Following the Transformer architecture (Vaswani et al., 2017), each attention layer consist of two sublayers: a multi-head attention (MHA) layer that executes message passing between the nodes and a node-wise fully connected feed-forward (FF) layer. Each sublayer adds a skip-connection (He et al., 2016) and batch normalization (BN) (Ioffe & Szegedy, 2015) (which we found to work better than layer normalization (Ba et al., 2016)):
|
| 64 |
+
|
| 65 |
+
<!-- formula-not-decoded -->
|
| 66 |
+
|
| 67 |
+
<!-- formula-not-decoded -->
|
| 68 |
+
|
| 69 |
+
The layer index ℓ indicates that the layers do not share parameters. The MHA sublayer uses M = 8 heads with dimensionality d h M = 16 , and the FF sublayer has one hidden (sub)sublayer with dimension 512 and ReLu activation. See Appendix A for details.
|
| 70 |
+
|
| 71 |
+
## 3.2 DECODER
|
| 72 |
+
|
| 73 |
+
Decoding happens sequentially, and at timestep t ∈ { 1 , . . . n } , the decoder outputs the node π t based on the embeddings from the encoder and the outputs π t ′ generated at time t ′ < t . During decoding, we augment the graph with a special context node ( c ) to represent the decoding context. The decoder computes an attention (sub)layer on top of the encoder, but with messages only to the context node for efficiency. 1 The final probabilities are computed using a single-head attention mechanism. See Figure 2 for an illustration of the decoding process.
|
| 74 |
+
|
| 75 |
+
1 n × n attention between all nodes is expensive to compute in every step of the decoding process.
|
| 76 |
+
|
| 77 |
+
Figure 2: Attention based decoder for the TSP problem. The decoder takes as input the graph embedding and node embeddings. At each time step t , the context consist of the graph embedding and the embeddings of the first and last (previously output) node of the partial tour, where learned placeholders are used if t = 1 . Nodes that cannot be visited (since they are already visited) are masked. The example shows how a tour π = (3 , 1 , 2 , 4) is constructed. Best viewed in color.
|
| 78 |
+
|
| 79 |
+
<!-- image -->
|
| 80 |
+
|
| 81 |
+
Context embedding The context of the decoder at time t comes from the encoder and the output up to time t . As mentioned, for the TSP it consists of the embedding of the graph, the previous (last) node π t -1 and the first node π 1 . For t = 1 we use learned d h-dimensional parameters v l and v f as input placeholders:
|
| 82 |
+
|
| 83 |
+
<!-- formula-not-decoded -->
|
| 84 |
+
|
| 85 |
+
Here [ · , · , · ] is the horizontal concatenation operator and we write the (3 · d h ) -dimensional result vector as h ( N ) ( c ) to indicate we interpret it as the embedding of the special context node ( c ) and use the superscript ( N ) to align with the node embeddings h ( N ) i . We could project the embedding back to d h dimensions, but we absorb this transformation in the parameter W Q in equation 5.
|
| 86 |
+
|
| 87 |
+
Now we compute a new context node embedding h ( N +1) ( c ) using the ( M -head) attention mechanism described in Appendix A. The keys and values come from the node embeddings h ( N ) i , but we only compute a single query q ( c ) (per head) from the context node (we omit the ( N ) for readability):
|
| 88 |
+
|
| 89 |
+
<!-- formula-not-decoded -->
|
| 90 |
+
|
| 91 |
+
We compute the compatibility of the query with all nodes, and mask (set u ( c ) j = -∞ ) nodes which cannot be visited at time t . For TSP, this simply means we mask the nodes already visited:
|
| 92 |
+
|
| 93 |
+
̸
|
| 94 |
+
|
| 95 |
+
<!-- formula-not-decoded -->
|
| 96 |
+
|
| 97 |
+
Here d k = d h M is the query/key dimensionality (see Appendix A). Again, we compute u ( c ) j and v i for M = 8 heads and compute the final multi-head attention value for the context node using equations 12-14 from Appendix A, but with ( c ) instead of i . This mechanism is similar to our encoder, but does not use skip-connections, batch normalization or the feed-forward sublayer for maximal efficiency. The result h ( N +1) ( c ) is similar to the glimpse described by Bello et al. (2016).
|
| 98 |
+
|
| 99 |
+
Calculation of log-probabilities To compute output probabilities p θ ( π t | s, π 1: t -1 ) in equation 1, we add one final decoder layer with a single attention head ( M = 1 so d k = d h). For this layer, we only compute the compatibilities u ( c ) j using equation 6, but following Bello et al. (2016) we clip the result (before masking!) within [ -C, C ] (C = 10) using tanh :
|
| 100 |
+
|
| 101 |
+
̸
|
| 102 |
+
|
| 103 |
+
<!-- formula-not-decoded -->
|
| 104 |
+
|
| 105 |
+
We interpret these compatibilities as unnormalized log-probabilities (logits) and compute the final output probability vector p using a softmax (similar to equation 12 in Appendix A):
|
| 106 |
+
|
| 107 |
+
<!-- formula-not-decoded -->
|
| 108 |
+
|
| 109 |
+
## 4 REINFORCE WITH GREEDY ROLLOUT BASELINE
|
| 110 |
+
|
| 111 |
+
Section 3 defined our model that given an instance s defines a probability distribution p θ ( π | s ) , from which we can sample to obtain a solution (tour) π | s . In order to train our model, we define the loss L ( θ | s ) = E p θ ( π | s ) [ L ( π )] : the expectation of the cost L ( π ) (tour length for TSP). We optimize L by gradient descent, using the REINFORCE (Williams, 1992) gradient estimator with baseline b ( s ) :
|
| 112 |
+
|
| 113 |
+
<!-- formula-not-decoded -->
|
| 114 |
+
|
| 115 |
+
A good baseline b ( s ) reduces gradient variance and therefore increases speed of learning. A simple example is an exponential moving average b ( s ) = M with decay β . Here M = L ( π ) in the first iteration and gets updated as M ← βM +(1 -β ) L ( π ) in subsequent iterations. A popular alternative is the use of a learned value function (critic) ˆ v ( s, w ) , where the parameters w are learned from the observations ( s, L ( π )) . However, getting such actor-critic algorithms to work is non-trivial.
|
| 116 |
+
|
| 117 |
+
We propose to use a rollout baseline in a way that is similar to self-critical training by Rennie et al. (2017), but with periodic updates of the baseline policy. It is defined as follows: b ( s ) is the cost of a solution from a deterministic greedy rollout of the policy defined by the best model so far.
|
| 118 |
+
|
| 119 |
+
Motivation The goal of a baseline is to estimate the difficulty of the instance s , such that it can relate to the cost L ( π ) to estimate the advantage of the solution π selected by the model. We make the following key observation: The difficulty of an instance can (on average) be estimated by the performance of an algorithm applied to it. This follows from the assumption that (on average) an algorithm will have a higher cost on instances that are more difficult. Therefore we form a baseline by applying (rolling out) the algorithm defined by our model during training. To eliminate variance we force the result to be deterministic by selecting greedily the action with maximum probability.
|
| 120 |
+
|
| 121 |
+
Determining the baseline policy As the model changes during training, we stabilize the baseline by freezing the greedy rollout policy p θ BL for a fixed number of steps (every epoch), similar to freezing of the target Q-network in DQN (Mnih et al., 2015). A stronger algorithm defines a stronger baseline, so we compare (with greedy decoding) the current training policy with the baseline policy at the end of every epoch, and replace the parameters θ BL of the baseline policy only if the improvement is significant according to a paired t-test ( α = 5% ), on 10000 separate (evaluation) instances. If the baseline policy is updated, we sample new evaluation instances to prevent overfitting.
|
| 122 |
+
|
| 123 |
+
Analysis With the greedy rollout as baseline b ( s ) , the function L ( π ) -b ( s ) is negative if the sampled solution π is better than the greedy rollout, causing actions to be reinforced, and vice versa. This way the model is trained to improve over its (greedy) self. We see similarities with selfplay improvement (Silver et al., 2017): sampling replaces tree search for exploration and the model is rewarded if it yields improvement ('wins') compared to the best model. Similar to AlphaGo, the evaluation at the end of each epoch ensures that we are always challenged by the best model.
|
| 124 |
+
|
| 125 |
+
Algorithm We use Adam (Kingma & Ba, 2015) as optimizer resulting in Algorithm 1.
|
| 126 |
+
|
| 127 |
+
Efficiency Each rollout constitutes an additional forward pass, increasing computation by 50% . However, as the baseline policy is fixed for an epoch, we can sample the data and compute baselines per epoch using larger batch sizes, allowed by the reduced memory requirement as the computations can run in pure inference mode. Empirically we find that it adds only 25% (see Appendix B.5), taking up 20% of total time. If desired, the baseline rollout can be computed in parallel such that there is no increase in time per iteration, as an easy way to benefit from an additional GPU.
|
| 128 |
+
|
| 129 |
+
```
|
| 130 |
+
Algorithm 1 REINFORCE with Rollout Baseline 1: Input: number of epochs E , steps per epoch T , batch size B , significance α 2: Init θ , θ BL ← θ 3: for epoch = 1 , . . . , E do 4: for step = 1 , . . . , T do 5: s i ← RandomInstance() ∀ i ∈ { 1 , . . . , B } 6: π i ← SampleRollout ( s i , p θ ) ∀ i ∈ { 1 , . . . , B } 7: π BL i ← GreedyRollout ( s i , p θ BL ) ∀ i ∈ { 1 , . . . , B } 8: ∇L ← ∑ B i =1 ( L ( π i ) -L ( π BL i ) ) ∇ θ log p θ ( π i ) 9: θ ← Adam ( θ , ∇L ) 10: end for 11: if OneSidedPairedTTest ( p θ , p θ BL ) < α then 12: θ BL ← θ 13: end if 14: end for
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
## 5 EXPERIMENTS
|
| 134 |
+
|
| 135 |
+
We focus on routing problems: we consider the TSP, two variants of the VRP, the Orienteering Problem and the (Stochastic) Prize Collecting TSP. These provide a range of different challenges, constraints and objectives and are traditionally solved by different algorithms . For the Attention Model (AM), we adjust the input, mask, decoder context and objective function for each problem (see Appendix for details and data generation) and train on problem instances of n = 20 , 50 and 100 nodes. For all problems, we use the same hyperparameters : those we found to work well on TSP.
|
| 136 |
+
|
| 137 |
+
√
|
| 138 |
+
|
| 139 |
+
Hyperparameters Weinitialize parameters Uniform ( -1 / d, 1 / d ) , with d the input dimension. Every epoch we process 2500 batches of 512 instances (except for VRP with n = 100 , where we use 2500 × 256 for memory constraints). For TSP, an epoch takes 5:30 minutes for n = 20 , 16:20 for n = 50 (single GPU 1080Ti) and 27:30 for n = 100 (on 2 1080Ti's). We train for 100 epochs using training data generated on the fly. We found training to be stable and results to be robust against different seeds, where only in one case (PCTSP with n = 20 ) we had to restart training with a different seed because the run diverged. We use N = 3 layers in the encoder, which we found is a good trade-off between quality of the results and computational complexity. We use a constant learning rate η = 10 -4 . Training with a higher learning rate η = 10 -3 is possible and speeds up initial learning, but requires decay ( 0 . 96 per epoch) to converge and may be a bit more unstable. See Appendix B.5. With the rollout baseline, we use an exponential baseline ( β = 0 . 8 ) during the first epoch, to stabilize initial learning, although in many cases learning also succeeds without this 'warmup'. Our code in PyTorch (Paszke et al., 2017) is publicly available. 2
|
| 140 |
+
|
| 141 |
+
√
|
| 142 |
+
|
| 143 |
+
Decoding strategy and baselines For each problem, we report performance on 10000 test instances. At test time we use greedy decoding, where we select the best action (according to the model) at each step, or sampling , where we sample 1280 solutions (in < 1 s on a single GPU) and report the best. More sampling improves solution quality at increased computation. In Table 1 we compare greedy decoding against baselines that also construct a single solution, and compare sampling against baselines that also consider multiple solutions, either via sampling or (local) search. For each problem, we also report the 'best possible solution': either optimal via Gurobi (2018) (intractable for n > 20 except for TSP) or a problem specific state-of-the-art algorithm.
|
| 144 |
+
|
| 145 |
+
Runtimes Run times are important but hard to compare: they can vary by two orders of magnitude as a result of implementation (Python vs C++) and hardware (GPU vs CPU). We take a practical view and report the time it takes to solve the test set of 10000 instances, either on a single GPU (1080Ti) or 32 instances in parallel on a 32 virtual CPU system (2 × Xeon E5-2630). This is conservative: our model is parallelizable while most of the baselines are single thread CPU implementations which cannot parallelize when running individually. Also we note that after training our run time can likely be reduced by model compression (Hinton et al., 2015). In Table 1 we do not report running times for the results which were reported by others as they are not directly comparable but we note that in general our model and implementation is fast: for instance Bello et al. (2016) report 10.3s for sampling 1280 TSP solutions (K80 GPU) which we do in less than one second (on a 1080Ti). For most algorithms it is possible to trade off runtime for performance. As reporting full trade-off curves is impractical we tried to pick reasonable spots, reporting the fastest if results were similar or reporting results with different time limits (for example we use Gurobi with time limits as heuristic).
|
| 146 |
+
|
| 147 |
+
## 5.1 PROBLEMS
|
| 148 |
+
|
| 149 |
+
Travelling Salesman Problem (TSP) For the TSP, we report optimal results by Gurobi, as well as by Concorde (Applegate et al., 2006) (faster than Gurobi as it is specialized for TSP) and LKH3 (Helsgaun, 2017), a state-of-the-art heuristic solver that empirically also finds optimal solutions in time comparable to Gurobi. We compare against Nearest, Random and Farthest Insertion, as well as Nearest Neighbor, which is the only non-learned baseline algorithm that also constructs a tour directly in order (i.e. is structurally similar to our model). For details, see Appendix B.3. Additionally we compare against the learned heuristics in Section 2, most importantly Bello et al. (2016), as well as OR Tools reported by Bello et al. (2016) and Christofides + 2OPT local search reported by Vinyals et al. (2015). Results for Dai et al. (2017) are (optimistically) computed from the optimality gaps they report on 15-20, 40-50 and 50-100 node graphs, respectively. Using a single greedy construction we outperform traditional baselines and we are able to achieve significantly closer to optimal results than previous learned heuristics (from around 1.5% to 0.3% above optimal for n = 20 ). Naturally, the difference with Bello et al. (2016) gets diluted when sampling many solutions (as with many samples even a random policy performs well), but we still obtain significantly better results, without tuning the softmax temperature. For completeness, we also report results from running the Encode-Attend-Navigate (EAN) code 3 which is concurrent work by Deudon et al. (2018) (for details see Appendix B.4). Our model outperforms EAN, even if EAN is improved with 2OPT local search. Appendix B.5 presents the results visually, including generalization results for different n .
|
| 150 |
+
|
| 151 |
+
[2 https://github.com/wouterkool/attention-learn-to-route](https://github.com/wouterkool/attention-learn-to-route)
|
| 152 |
+
|
| 153 |
+
Table 1: Attention Model (AM) vs baselines. The gap % is w.r.t. the best value across all methods.
|
| 154 |
+
|
| 155 |
+
| n = 20 n = 50 n = 100 Method Obj. Gap Time Obj. Gap Time Obj. Gap Time TSP Concorde 3 . 84 0 . 00% (1m) 5 . 70 0 . 00% (2m) 7 . 76 0 . 00% (3m) LKH3 3 . 84 0 . 00% (18s) 5 . 70 0 . 00% (5m) 7 . 76 0 . 00% (21m) Gurobi 3 . 84 0 . 00% (7s) 5 . 70 0 . 00% (2m) 7 . 76 0 . 00% (17m) Gurobi (1s) 3 . 84 0 . 00% (8s) 5 . 70 0 . 00% (2m) - Nearest Insertion 4 . 33 12 . 91% (1s) 6 . 78 19 . 03% (2s) 9 . 46 21 . 82% (6s) Random Insertion 4 . 00 4 . 36% (0s) 6 . 13 7 . 65% (1s) 8 . 52 9 . 69% (3s) Farthest Insertion 3 . 93 2 . 36% (1s) 6 . 01 5 . 53% (2s) 8 . 35 7 . 59% (7s) Nearest Neighbor 4 . 50 17 . 23% (0s) 7 . 00 22 . 94% (0s) 9 . 68 24 . 73% (0s) Vinyals et al. (gr.) 3 . 88 1 . 15% 7 . 66 34 . 48% - Bello et al. (gr.) 3 . 89 1 . 42% 5 . 95 4 . 46% 8 . 30 6 . 90% Dai et al. 3 . 89 1 . 42% 5 . 99 5 . 16% 8 . 31 7 . 03% Nowak et al. 3 . 93 2 . 46% - - EAN (greedy) 3 . 86 0 . 66% (2m) 5 . 92 3 . 98% (5m) 8 . 42 8 . 41% (8m) AM(greedy) 3 . 85 0 . 34 % (0s) 5 . 80 1 . 76 % (2s) 8 . 12 4 . 53 % (6s) OR Tools 3 . 85 0 . 37% 5 . 80 1 . 83% 7 . 99 2 . 90% Chr.f. + 2OPT 3 . 85 0 . 37% 5 . 79 1 . 65% - Bello et al. (s.) - 5 . 75 0 . 95% 8 . 00 3 . 03% EAN (gr. + 2OPT) 3 . 85 0 . 42% (4m) 5 . 85 2 . 77% (26m) 8 . 17 5 . 21% (3h) EAN (sampling) 3 . 84 0 . 11% (5m) 5 . 77 1 . 28% (17m) 8 . 75 12 . 70% (56m) EAN (s. + 2OPT) 3 . 84 0 . 09% (6m) 5 . 75 1 . 00% (32m) 8 . 12 4 . 64% (5h) AM(sampling) 3 . 84 0 . 08 % (5m) 5 . 73 0 . 52 % (24m) 7 . 94 2 . 26 % (1h) CVRP Gurobi 6 . 10 0 . 00% - - LKH3 6 . 14 0 . 58% (2h) 10 . 38 0 . 00% (7h) 15 . 65 0 . 00% (13h) RL (greedy) 6 . 59 8 . 03% 11 . 39 9 . 78% 17 . 23 10 . 12% AM(greedy) 6 . 40 4 . 97 % (1s) 10 . 98 5 . 86 % (3s) 16 . 80 7 . 34 % (8s) RL (beam 10) 6 . 40 4 . 92% 11 . 15 7 . 46% 16 . 96 8 . 39% Random CW 6 . 81 11 . 64% 12 . 25 18 . 07% 18 . 96 21 . 18% Random Sweep 7 . 08 16 . 07% 12 . 96 24 . 91% 20 . 33 29 . 93% OR Tools 6 . 43 5 . 41% 11 . 31 9 . 01% 17 . 16 9 . 67% AM(sampling) 6 . 25 2 . 49 % (6m) 10 . 62 2 . 40 % (28m) 16 . 23 3 . 72 % (2h) SDVRP RL (greedy) 6 . 51 4 . 19% 11 . 32 6 . 88% 17 . 12 5 . 23% AM(greedy) 6 . 39 2 . 34 % (1s) 10 . 92 3 . 08 % (4s) 16 . 83 3 . 42 % (11s) RL (beam 10) 6 . 34 1 . 47% 11 . 08 4 . 61% 16 . 86 3 . 63% AM(sampling) 6 . 25 0 . 00 % (9m) 10 . 59 0 . 00 % (42m) 16 . 27 0 . 00 % (3h) OP (distance) Gurobi 5 . 39 0 . 00% (16m) - - Gurobi (1s) 4 . 62 14 . 22% (4m) 1 . 29 92 . 03% (6m) 0 . 58 98 . 25% (7m) Gurobi (10s) 5 . 37 0 . 33% (12m) 10 . 96 32 . 20% (51m) 1 . 34 95 . 97% (53m) Gurobi (30s) 5 . 38 0 . 05% (14m) 13 . 57 16 . 09% (2h) 3 . 23 90 . 28% (3h) Compass 5 . 37 0 . 36% (2m) 16 . 17 0 . 00% (5m) 33 . 19 0 . 00% (15m) Tsili (greedy) 4 . 08 24 . 25% (4s) 12 . 46 22 . 94% (4s) 25 . 69 22 . 59% (5s) AM(greedy) 5 . 19 3 . 64 % (0s) 15 . 64 3 . 23 % (1s) 31 . 62 4 . 75 % (5s) GA (Python) 5 . 12 4 . 88% (10m) 10 . 90 32 . 59% (1h) 14 . 91 55 . 08% (5h) OR Tools (10s) 4 . 09 24 . 05% (52m) - - Tsili (sampling) 5 . 30 1 . 62% (28s) 15 . 50 4 . 14% (2m) 30 . 52 8 . 05% (6m) AM(sampling) 5 . 30 1 . 56 % (4m) 16 . 07 0 . 60 % (16m) 32 . 68 1 . 55 % (53m) PCTSP Gurobi 3 . 13 0 . 00% (2m) - - Gurobi (1s) 3 . 14 0 . 07% (1m) - - Gurobi (10s) 3 . 13 0 . 00% (2m) 4 . 54 1 . 36% (32m) - Gurobi (30s) 3 . 13 0 . 00% (2m) 4 . 48 0 . 03% (54m) - AM(greedy) 3 . 18 1 . 62 % (0s) 4 . 60 2 . 66 % (2s) 6 . 25 4 . 46 % (5s) ILS (C++) 3 . 16 0 . 77% (16m) 4 . 50 0 . 36% (2h) 5 . 98 0 . 00 % (12h) OR Tools (10s) 3 . 14 0 . 05% (52m) 4 . 51 0 . 70% (52m) 6 . 35 6 . 21% (52m) OR Tools (60s) 3 . 13 0 . 01 % (5h) 4 . 48 0 . 00 % (5h) 6 . 07 1 . 56% (5h) ILS (Python 10x) 5 . 21 66 . 19% (4m) 12 . 51 179 . 05% (3m) 23 . 98 300 . 95% (3m) AM(sampling) 3 . 15 0 . 45% (5m) 4 . 52 0 . 74% (19m) 6 . 08 1 . 67% (1h) SPCTSP REOPT (all) 3 . 34 2 . 38% (17m) 4 . 68 1 . 04% (2h) 6 . 22 1 . 10% (12h) REOPT (half) 3 . 31 1 . 38% (25m) 4 . 64 0 . 00 % (3h) 6 . 16 0 . 00 % (16h) REOPT (first) 3 . 31 1 . 60% (1h) 4 . 66 0 . 44% (22h) - AM(greedy) 3 . 26 0 . 00 % (0s) 4 . 65 0 . 33% (2s) 6 . 32 2 . 69% (5s) |
|
| 156 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 157 |
+
|
| 158 |
+
Vehicle Routing Problem (VRP) In the Capacitated VRP (CVRP) (Toth & Vigo, 2014), each node has a demand and multiple routes should be constructed (starting and ending at the depot), such that the total demand of the nodes in each route does not exceed the vehicle capacity. We also consider the Split Delivery VRP (SDVRP), which allows to split customer demands over multiple routes. We implement the datasets described by Nazari et al. (2018) and compare against their Reinforcement Learning (RL) framework and the strongest baselines they report. Comparing greedy decoding, we obtain significantly better results. We cannot directly compare our sampling (1280 samples) to their beam search with size 10 (they do not report sampling or larger beam sizes), but note that our greedy method also outperforms their beam search in most (larger) cases, getting (in < 1 second/instance) much closer to LKH3 (Helsgaun, 2017), a state-of-the-art algorithm which found best known solutions to CVRP benchmarks. See Appendix C.4 for greedy example solution plots.
|
| 159 |
+
|
| 160 |
+
Orienteering Problem (OP) The OP (Golden et al., 1987) is an important problem used to model many real world problems. Each node has an associated prize , and the goal is to construct a single tour (starting and ending at the depot) that maximizes the sum of prizes of nodes visited while being shorter than a maximum (given) length. We consider the prize distributions proposed in Fischetti et al. (1998): constant , uniform (in Appendix D.4), and increasing with the distance to the depot, which we report here as this is the hardest problem. As 'best possible solution' we report Gurobi (intractable for n > 20 ) and Compass , the recent state-of-the-art Genetic Algorithm (GA) by Kobeaga et al. (2018), which is only 2% better than sampling 1280 solutions with our method (objective is maximization). We outperform a Python GA 4 (which seems not to scale), as well the construction phase of the heuristic by Tsiligirides (1984) (comparing greedy or 1280 samples) which is structurally similar to the one learned by our model. OR Tools fails to find feasible solutions in a few percent of the cases for n > 20 .
|
| 161 |
+
|
| 162 |
+
Prize Collecting TSP (PCTSP) In the PCTSP (Balas, 1989), each node has not only an associated prize, but also an associated penalty. The goal is to collect at least a minimum total prize, while minimizing the total tour length plus the sum of penalties of unvisited nodes. This problem is difficult as an algorithm has to trade off the penalty for not visiting a node with the marginal cost/tour length of visiting (which depends on the other nodes visited), while also satisfying the minimum total prize constraint. We compare against OR Tools with 10 or 60 seconds of local search, as well as open source C++ 5 and Python 6 implementations of Iterated Local Search (ILS). Although the Attention Model does not find better solutions than OR Tools with 60s of local search, it finds almost equally good results in significantly less time. The results are also within 2% of the C++ ILS algorithm (but obtained much faster), which was the best open-source algorithm for PCTSP we could find.
|
| 163 |
+
|
| 164 |
+
Stochastic PCTSP (SPCTSP) The Stochastic variant of the PCTSP (SPCTSP) we consider shows how our model can deal with uncertainty naturally. In the SPCTSP, the expected node prize is known upfront, but the real collected prize only becomes known upon visitation. With penalties, this problem is a generalization of the stochastic k-TSP (Ene et al., 2018). Since our model constructs a tour one node at the time, we only need to use the real prizes to compute the remaining prize constraint. By contrast, any algorithm that selects a fixed tour may fail to satisfy the prize constraint so an algorithm must be adaptive. As a baseline, we implement an algorithm that plans a tour, executes part of it and then re-optimizes using the C++ ILS algorithm. We either execute all node visits (so planning additional nodes if the result does not satisfy the prize constraint), half of the planned node visits (for O (log n ) replanning iterations) or only the fi rst node visit, for maximum adaptivity. We observe that our model outperforms all baselines for n = 20 . We think that failure to account for uncertainty (by the baselines) in the prize might result in the need to visit one or two additional nodes, which is relatively costly for small instances but relatively cheap for larger n . Still, our method is beneficial as it provides competitive solutions at a fraction of the computational cost, which is important in online settings.
|
| 165 |
+
|
| 166 |
+
[3 https://github.com/MichelDeudon/encode-attend-navigate](https://github.com/MichelDeudon/encode-attend-navigate)
|
| 167 |
+
|
| 168 |
+
[4 https://github.com/mc-ride/orienteering](https://github.com/mc-ride/orienteering)
|
| 169 |
+
|
| 170 |
+
[5 https://github.com/jordanamecler/PCTSP](https://github.com/jordanamecler/PCTSP)
|
| 171 |
+
|
| 172 |
+
[6 https://github.com/rafael2reis/salesman](https://github.com/rafael2reis/salesman)
|
| 173 |
+
|
| 174 |
+
## 5.2 ATTENTION MODEL VS. POINTER NETWORK AND DIFFERENT BASELINES
|
| 175 |
+
|
| 176 |
+
Figure 3 compares the performance of the TSP20 Attention Model (AM) and our implementation of the Pointer Network (PN) during training. We use a validation set of size 10000 with greedy decoding, and compare to using an exponential ( β = 0 . 8 ) and a critic (see Appendix B.1) baseline. We used two random seeds and a decaying learning rate of η = 10 -3 × 0 . 96 epoch . This performs best for the PN, while for the AM results are similar to using η = 10 -4 (see Appendix B.5). This clearly illustrates how the improvement we obtain is the result of both the AM and the rollout baseline: the AM outperforms the PN using any baseline and the rollout baseline improves the quality and convergence speed for both AM and PN. For the PN with critic
|
| 177 |
+
|
| 178 |
+
Figure 3: Held-out validation set optimality gap as a function of the number of epochs for the Attention Model (AM) and Pointer Network (PN) with different baselines (two different seeds).
|
| 179 |
+
|
| 180 |
+
<!-- image -->
|
| 181 |
+
|
| 182 |
+
baseline, we are unable to reproduce the 1 . 5% reported by Bello et al. (2016) (also when using an LSTMbased critic), but our reproduction is closer than others have reported (Dai et al., 2017; Nazari et al., 2018). In Table 1 we compare against the original results. Compared to the rollout baseline, the exponential baseline is around 20% faster per epoch, whereas the critic baseline is around 13% slower (see Appendix B.5), so the picture does not change significantly if time is used as x-axis.
|
| 183 |
+
|
| 184 |
+
## 6 DISCUSSION
|
| 185 |
+
|
| 186 |
+
In this work we have introduced a model and training method which both contribute to significantly improved results on learned heuristics for TSP and additionally learned strong (single construction) heuristics for multiple routing problems, which are traditionally solved by problem-specific approaches. We believe that our method is a powerful starting point for learning heuristics for other combinatorial optimization problems defined on graphs, if their solutions can be described as sequential decisions. In practice, operational constraints often lead to many variants of problems for which no good (human-designed) heuristics are available such that the ability to learn heuristics could be of great practical value.
|
| 187 |
+
|
| 188 |
+
Compared to previous works, by using attention instead of recurrence (LSTMs) we introduce invariance to the input order of the nodes, increasing learning efficiency. Also this enables parallelization, for increased computational efficiency. The multi-head attention mechanism can be seen as a message passing algorithm that allows nodes to communicate relevant information over different channels, such that the node embeddings from the encoder can learn to include valuable information about the node in the context of the graph . This information is important in our setting where decisions relate directly to the nodes in a graph. Being a graph based method, our model has increased scaling potential (compared to LSTMs) as it can be applied on a sparse graph and operate locally.
|
| 189 |
+
|
| 190 |
+
Scaling to larger problem instances is an important direction for future research, where we think we have made an important first step by using a graph based method, which can be sparsified for improved computational efficiency. Another challenge is that many problems of practical importance have feasibility constraints that cannot be satisfied by a simple masking procedure, and we think it is promising to investigate if these problems can be addressed by a combination of heuristic learning and backtracking. This would unleash the potential of our method, already highly competitive to the popular Google OR Tools project, to an even larger class of difficult practical problems.
|
| 191 |
+
|
| 192 |
+
## ACKNOWLEDGEMENTS
|
| 193 |
+
|
| 194 |
+
This research was funded by ORTEC Optimization Technology. We thank Thomas Kipf for helpful discussions and anonymous reviewers for comments that helped improve the paper. We thank DAS5 (Bal et al., 2016) for computational resources and we thank SURFsara (www.surfsara.nl) for the support in using the Lisa Compute Cluster.
|
| 195 |
+
|
| 196 |
+
## REFERENCES
|
| 197 |
+
|
| 198 |
+
- David Applegate, Robert Bixby, Vasek Chvatal, and William Cook. Concorde TSP solver, 2006. URL http://www.math.uwaterloo.ca/tsp/concorde/m .
|
| 199 |
+
- Jimmy Lei Ba, Jamie Ryan Kiros, and Geoffrey E Hinton. Layer normalization. arXiv preprint arXiv:1607.06450 , 2016.
|
| 200 |
+
- Henri Bal, Dick Epema, Cees de Laat, Rob van Nieuwpoort, John Romein, Frank Seinstra, Cees Snoek, and Harry Wijshoff. A medium-scale distributed system for computer science research: Infrastructure for the long term. Computer , (5):54-63, 2016.
|
| 201 |
+
- Egon Balas. The prize collecting traveling salesman problem. Networks , 19(6):621-636, 1989.
|
| 202 |
+
- Irwan Bello, Hieu Pham, Quoc V Le, Mohammad Norouzi, and Samy Bengio. Neural combinatorial optimization with reinforcement learning. arXiv preprint arXiv:1611.09940 , 2016.
|
| 203 |
+
- Hanjun Dai, Elias B Khalil, Yuyu Zhang, Bistra Dilkina, and Le Song. Learning combinatorial optimization algorithms over graphs. In Advances in Neural Information Processing Systems 30 , pp. 6348-6358, 2017.
|
| 204 |
+
- Michel Deudon, Pierre Cournut, Alexandre Lacoste, Yossiri Adulyasak, and Louis-Martin Rousseau. Learning heuristics for the TSP by policy gradient. In International Conference on the Integration of Constraint Programming, Artificial Intelligence, and Operations Research , pp. 170-181. Springer, 2018.
|
| 205 |
+
- Alina Ene, Viswanath Nagarajan, and Rishi Saket. Approximation algorithms for stochastic kTSP. In 37th IARCS Annual Conference on Foundations of Software Technology and Theoretical Computer Science , 2018.
|
| 206 |
+
- Matteo Fischetti, Juan Jose Salazar Gonzalez, and Paolo Toth. Solving the orienteering problem through branch-and-cut. INFORMS Journal on Computing , 10(2):133-148, 1998.
|
| 207 |
+
- Michael R Garey and David S Johnson. Computers and intractability: A guide to the theory of npcompleteness (series of books in the mathematical sciences), ed. Computers and Intractability , pp. 340, 1979.
|
| 208 |
+
- Paul Glasserman and David D Yao. Some guidelines and guarantees for common random numbers. Management Science , 38(6):884-908, 1992.
|
| 209 |
+
- Bruce L Golden, Larry Levy, and Rakesh Vohra. The orienteering problem. Naval Research Logistics (NRL) , 34(3):307-318, 1987.
|
| 210 |
+
- Gurobi Optimization, LLC. Gurobi optimizer reference manual, 2018. URL http://www. gurobi.com .
|
| 211 |
+
- Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep residual learning for image recognition. In Proceedings of the IEEE conference on computer vision and pattern recognition , pp. 770-778, 2016.
|
| 212 |
+
- Keld Helsgaun. An extension of the Lin-Kernighan-Helsgaun TSP solver for constrained traveling salesman and vehicle routing problems: Technical report. 2017.
|
| 213 |
+
- Geoffrey Hinton, Oriol Vinyals, and Jeffrey Dean. Distilling the knowledge in a neural network. In NIPS Deep Learning and Representation Learning Workshop , 2015. URL http://arxiv. org/abs/1503.02531 .
|
| 214 |
+
|
| 215 |
+
- John J Hopfield and David W Tank. 'Neural' computation of decisions in optimization problems. Biological cybernetics , 52(3):141-152, 1985.
|
| 216 |
+
- Sergey Ioffe and Christian Szegedy. Batch normalization: Accelerating deep network training by reducing internal covariate shift. In International Conference on Machine Learning , pp. 448-456, 2015.
|
| 217 |
+
- Yoav Kaempfer and Lior Wolf. Learning the multiple traveling salesmen problem with permutation invariant pooling networks. arXiv preprint arXiv:1803.09621 , 2018.
|
| 218 |
+
- Diederik P Kingma and Jimmy Ba. Adam: A method for stochastic optimization. In International Conference on Learning Representations , 2015.
|
| 219 |
+
- Gorka Kobeaga, Mar´ ıa Merino, and Jose A Lozano. An efficient evolutionary algorithm for the orienteering problem. Computers & Operations Research , 90:42-59, 2018.
|
| 220 |
+
- Yann LeCun, Yoshua Bengio, and Geoffrey Hinton. Deep learning. Nature , 521(7553):436, 2015.
|
| 221 |
+
- Volodymyr Mnih, Koray Kavukcuoglu, David Silver, Andrei A Rusu, Joel Veness, Marc G Bellemare, Alex Graves, Martin Riedmiller, Andreas K Fidjeland, Georg Ostrovski, et al. Human-level control through deep reinforcement learning. Nature , 518(7540):529, 2015.
|
| 222 |
+
- MohammadReza Nazari, Afshin Oroojlooy, Lawrence Snyder, and Martin Takac. Reinforcement learning for solving the vehicle routing problem. In Advances in Neural Information Processing Systems , pp. 9860-9870, 2018.
|
| 223 |
+
- Alex Nowak, Soledad Villar, Afonso S Bandeira, and Joan Bruna. A note on learning algorithms for quadratic assignment with graph neural networks. arXiv preprint arXiv:1706.07450 , 2017.
|
| 224 |
+
- Adam Paszke, Sam Gross, Soumith Chintala, Gregory Chanan, Edward Yang, Zachary DeVito, Zeming Lin, Alban Desmaison, Luca Antiga, and Adam Lerer. Automatic differentiation in PyTorch. 2017.
|
| 225 |
+
- Steven J Rennie, Etienne Marcheret, Youssef Mroueh, Jerret Ross, and Vaibhava Goel. Self-critical sequence training for image captioning. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , pp. 7008-7024, 2017.
|
| 226 |
+
- Daniel J Rosenkrantz, Richard E Stearns, and Philip M Lewis. An analysis of several heuristics for the traveling salesman problem. In Fundamental Problems in Computing , pp. 45-69. Springer, 2009.
|
| 227 |
+
- David Silver, Julian Schrittwieser, Karen Simonyan, Ioannis Antonoglou, Aja Huang, Arthur Guez, Thomas Hubert, Lucas Baker, Matthew Lai, Adrian Bolton, et al. Mastering the game of go without human knowledge. Nature , 550(7676):354, 2017.
|
| 228 |
+
- Kate A Smith. Neural networks for combinatorial optimization: a review of more than a decade of research. INFORMS Journal on Computing , 11(1):15-34, 1999.
|
| 229 |
+
- Paolo Toth and Daniele Vigo. Vehicle routing: problems, methods, and applications . SIAM, 2014.
|
| 230 |
+
- Theodore Tsiligirides. Heuristic methods applied to orienteering. Journal of the Operational Research Society , 35(9):797-809, 1984.
|
| 231 |
+
- Pieter Vansteenwegen, Wouter Souffriau, and Dirk Van Oudheusden. The orienteering problem: A survey. European Journal of Operational Research , 209(1):1-10, 2011.
|
| 232 |
+
- Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin. Attention is all you need. In Advances in Neural Information Processing Systems , pp. 5998-6008, 2017.
|
| 233 |
+
- Petar Velickovic, Guillem Cucurull, Arantxa Casanova, Adriana Romero, Pietro Li, and Yoshua Bengio. Graph attention networks. In International Conference on Learning Representations , 2018.
|
| 234 |
+
|
| 235 |
+
- Oriol Vinyals, Meire Fortunato, and Navdeep Jaitly. Pointer networks. In Advances in Neural Information Processing Systems , pp. 2692-2700, 2015.
|
| 236 |
+
- Oriol Vinyals, Samy Bengio, and Manjunath Kudlur. Order matters: Sequence to sequence for sets. In International Conference on Learning Representations , 2016.
|
| 237 |
+
- Ronald J Williams. Simple statistical gradient-following algorithms for connectionist reinforcement learning. Machine learning , 8(3-4):229-256, 1992.
|
| 238 |
+
- David H Wolpert and William G Macready. No free lunch theorems for optimization. IEEE transactions on evolutionary computation , 1(1):67-82, 1997.
|
| 239 |
+
|
| 240 |
+
## A ATTENTION MODEL DETAILS
|
| 241 |
+
|
| 242 |
+
Figure 4: Illustration of weighted message passing using a dot-attention mechanism. Only computation of messages received by node 1 are shown for clarity. Best viewed in color.
|
| 243 |
+
|
| 244 |
+
<!-- image -->
|
| 245 |
+
|
| 246 |
+
Attention mechanism We interpret the attention mechanism by Vaswani et al. (2017) as a weighted message passing algorithm between nodes in a graph. The weight of the message value that a node receives from a neighbor depends on the compatibility of its query with the key of the neighbor, as illustrated in Figure 4. Formally, we define dimensions d k and d v and compute the key k i ∈ R d k , value v i ∈ R d v and query q i ∈ R d k for each node by projecting the embedding h i :
|
| 247 |
+
|
| 248 |
+
<!-- formula-not-decoded -->
|
| 249 |
+
|
| 250 |
+
Here parameters W Q and W K are ( d k × d h ) matrices and W V has size ( d v × d h ) . From the queries and keys, we compute the compatibility u ij ∈ R of the query q i of node i with the key k j of node j as the (scaled, see Vaswani et al. (2017)) dot-product:
|
| 251 |
+
|
| 252 |
+
<!-- formula-not-decoded -->
|
| 253 |
+
|
| 254 |
+
In a general graph, defining the compatibility of non-adjacent nodes as -∞ prevents message passing between these nodes. From the compatibilities u ij , we compute the attention weights a ij ∈ [0 , 1] using a softmax:
|
| 255 |
+
|
| 256 |
+
<!-- formula-not-decoded -->
|
| 257 |
+
|
| 258 |
+
Finally, the vector h ′ i that is received by node i is the convex combination of messages v j :
|
| 259 |
+
|
| 260 |
+
<!-- formula-not-decoded -->
|
| 261 |
+
|
| 262 |
+
Multi-head attention As was noted by Vaswani et al. (2017) and Velickovic et al. (2018), it is beneficial to have multiple attention heads. This allows nodes to receive different types of messages from different neighbors. Especially, we compute the value in equation 13 M = 8 times with different parameters, using d k = d v = d h M = 16 . We denote the result vectors by h ′ im for m ∈ 1 , . . . , M . These are projected back to a single d h-dimensional vector using ( d h × d v ) parameter matrices W O m . The final multi-head attention value for node i is a function of h 1 , . . . , h n through h ′ im :
|
| 263 |
+
|
| 264 |
+
<!-- formula-not-decoded -->
|
| 265 |
+
|
| 266 |
+
Feed-forward sublayer The feed-forward sublayer computes node-wise projections using a hidden (sub)sublayer with dimension d ff = 512 and a ReLu activation:
|
| 267 |
+
|
| 268 |
+
<!-- formula-not-decoded -->
|
| 269 |
+
|
| 270 |
+
Batch normalization We use batch normalization with learnable d h-dimensional affine parameters w bn and b bn :
|
| 271 |
+
|
| 272 |
+
<!-- formula-not-decoded -->
|
| 273 |
+
|
| 274 |
+
Here ⊙ denotes the element-wise product and BN refers to batch normalization without affine transformation.
|
| 275 |
+
|
| 276 |
+
## B TRAVELLING SALESMAN PROBLEM
|
| 277 |
+
|
| 278 |
+
## B.1 CRITIC ARCHITECTURE
|
| 279 |
+
|
| 280 |
+
The critic network architecture uses 3 attention layers similar to our encoder, after which the node embeddings are averaged and processed by an MLP with one hidden layer with 128 neurons and ReLu activation and a single output. We used the same learning rate as for the AM/PN in all experiments.
|
| 281 |
+
|
| 282 |
+
## B.2 INSTANCE GENERATION
|
| 283 |
+
|
| 284 |
+
For all TSP instances, the n node locations are sampled uniformly at random in the unit square. This distribution is chosen to be neither easy nor artificially hard and to be able to compare to other learned heuristics.
|
| 285 |
+
|
| 286 |
+
## B.3 DETAILS OF BASELINES
|
| 287 |
+
|
| 288 |
+
This section describes details of the heuristics implemented for the TSP. All of the heuristics construct a single tour in a single pass, by extending a partial solution one node at the time.
|
| 289 |
+
|
| 290 |
+
Nearest neighbor The nearest neighbor heuristic represents the partial solution as a path with a start and end node. The initial path is formed by a single node, selected randomly, which becomes the start node but also the end node of the initial path. In each iteration, the next node is selected as the node nearest to the end node of the partial path. This node is added to the path and becomes the new end node. Finally, after all nodes are added this way, the end node is connected with the start node to form a tour. In our implementation, for deterministic results we always start with the first node in the input, which can be considered random as the instances are generated randomly.
|
| 291 |
+
|
| 292 |
+
Farthest/nearest/random insertion The insertion heuristics represent a partial solution as a tour , and extends it by inserting nodes one node at the time. In our implementation, we always insert the node using the cheapest insertion cost. This means that when node i is inserted, the place of insertion (between adjacent nodes j and k in the tour) is selected such that it minimizes the insertion costs d ji + d ik -d jk , where d ji , d ik and d jk represent the distances from node j to i , i to k and j to k , respectively.
|
| 293 |
+
|
| 294 |
+
The different variants of the insertion heuristic vary in the way in which the node which is inserted is selected. Let S be the set of nodes in the partial tour. Nearest insertion inserts the node i that is nearest to (any node in) the tour:
|
| 295 |
+
|
| 296 |
+
<!-- formula-not-decoded -->
|
| 297 |
+
|
| 298 |
+
Farthest insertion inserts the node i such that the distance to the tour (i.e. the distance from i to the nearest node j in the tour) is maximized:
|
| 299 |
+
|
| 300 |
+
<!-- formula-not-decoded -->
|
| 301 |
+
|
| 302 |
+
Random insertion inserts a random node. Similar to nearest neighbor, we consider the input order random so we simply insert the nodes in this order.
|
| 303 |
+
|
| 304 |
+
## B.4 COMPARISON TO CONCURRENT WORK
|
| 305 |
+
|
| 306 |
+
Independently of our work, Deudon et al. (2018) also developed a model for TSP based on the Transformer (Vaswani et al., 2017). There are important differences to this paper:
|
| 307 |
+
|
| 308 |
+
- As 'context' for the decoder, Deudon et al. (2018) use the embeddings of the last K = 3 visited nodes. We use only the last (e.g. K = 1 ) node but add the fi rst visited node (as well as the graph embedding), since the first node is important (it is the destination) while the order of the other nodes is irrelevant as we explain in Section 3.
|
| 309 |
+
- Deudon et al. (2018) use a critic as baseline (which also uses the Transformer architecture). We also experiment with using a critic (based on the Transformer architecture), but found that using a rollout baseline is much more effective (see Section 5).
|
| 310 |
+
|
| 311 |
+
- Deudon et al. (2018) report results with sampling 128 solutions, with and without 2OPT local search. We report results without 2OPT, using either a single greedy solution or sampling 1280 solutions and additionally show how this directly improves performance compared to Bello et al. (2016).
|
| 312 |
+
- By adding 2OPT on top of the best sampled solution, Deudon et al. (2018) show that the model does not produce a local optimum and results can improve by using a 'hybrid' approach of a learned algorithm with local search. This is a nice example of combining learned and traditional heuristics, but it is not compared against using the Pointer Network (Bello et al., 2016) with 2OPT.
|
| 313 |
+
- The model of Deudon et al. (2018) uses a higher dimensionality internally in the decoder (for details see their paper). Training is done with 20000 steps with a batch size of 256.
|
| 314 |
+
- Deudon et al. (2018) apply Principal Component Analysis (PCA) on the input coordinates to eliminate rotation symmetry whereas we directly input node coordinates.
|
| 315 |
+
- Additionally to TSP, we also consider two variants of VRP, the OP with different prize distributions and the (stochastic) PCTSP.
|
| 316 |
+
|
| 317 |
+
We want to emphasize that this is independent work, but for completeness we include a full emperical comparison of performance. Since the results presented in the paper by Deudon et al. (2018) are not directly comparable, we ran their code 7 and report results under the same circumstances: using greedy decoding and sampling 1280 solutions on our test dataset (which has exactly the same generative procedure, e.g. uniform in the unit square). Additionally, we include results of their model with 2OPT, showing that (even without 2OPT) final performance of our model is better. We use the hyperparameters in their code, but increase the batch size to 512 and number of training steps to 100 × 2500 = 250000 for a fair comparison (this increased the performance of their model). As training with n = 100 gave out-of-memory errors, we train only on n = 20 and n = 50 and (following Deudon et al. (2018)) report results for n = 100 using the model trained for n = 50 . The training time as well as test run times are comparable.
|
| 318 |
+
|
| 319 |
+
## B.5 EXTENDED RESULTS
|
| 320 |
+
|
| 321 |
+
Hyperparameters We found in general that using a larger learning rate of 10 -3 works better with decay but may be unstable in some cases. A smaller learning rate 10 -4 is more stable and does not require decay. This is illustrated in Figure 6, which shows validation results over time using both 10 -3 and 10 -4 with and without decay for TSP20 and TSP50 (2 seeds). As can be seen, without decay the method has not yet fully converged after 100 epochs and results may improve even further with longer training.
|
| 322 |
+
|
| 323 |
+
Table 2 shows the results in absolute terms as well as the relative optimality gap compared to Gurobi, for all runs using seeds 1234 and 1235 with the two different learning rate schedules. We did not run final experiments for n = 100 with the larger learning rate as we found training with the smaller learning rate to be more stable. It can be seen that in most cases the end results with different learning rate schedules are similar, except for the larger models ( N = 5 , N = 8 ) where some of the runs diverged using the larger learning rate. Experiments with different number of layers N show that N = 3 and N = 5 achieve best performance, and we find N = 3 is a good trade-off between quality of the results and computational complexity (runtime) of the model.
|
| 324 |
+
|
| 325 |
+
Generalization We test generalization performance on different n than trained for, which we plot in Figure 5 in terms of the relative optimality gap compared to Gurobi. The train sizes are indicated with vertical marker bars. The models generalize when tested on different sizes, although quality degrades as the difference becomes bigger, which can be expected as there is no free lunch (Wolpert & Macready, 1997). Since the architectures are the same, these differences mean the models learn to specialize on the problem sizes trained for. We can make a strong overall algorithm by selecting the trained model with highest validation performance for each instance size n (marked in Figure 5 by the red bar). For reference, we also include the baselines, where for the methods that perform search or sampling we do not connect the dots to prevent cluttering and to make the distinction with methods that consider only a single solution clear.
|
| 326 |
+
|
| 327 |
+
[7 https://github.com/MichelDeudon/encode-attend-navigate](https://github.com/MichelDeudon/encode-attend-navigate)
|
| 328 |
+
|
| 329 |
+
Table 2: Epoch durations and results and with different seeds and learning rate schedules for TSP.
|
| 330 |
+
|
| 331 |
+
| epoch η = 10 - 4 η = 10 - 3 × 0 . 96 epoch time seed = 1234 seed = 1235 seed = 1234 seed = 1235 TSP20 5:30 3 . 85 (0 . 34%) 3 . 85 (0 . 29%) 3 . 85 (0 . 33%) 3 . 85 (0 . 32%) TSP50 16:20 5 . 80 (1 . 76%) 5 . 79 (1 . 66%) 5 . 81 (2 . 02%) 5 . 81 (2 . 00%) TSP100 (2GPUs) 27:30 8 . 12 (4 . 53%) 8 . 10 (4 . 34%) - - N = 0 3:10 4 . 24 (10 . 50%) 4 . 26 (10 . 95%) 4 . 25 (10 . 79%) 4 . 24 (10 . 55%) N = 1 3:50 3 . 87 (0 . 97%) 3 . 87 (1 . 01%) 3 . 87 (0 . 90%) 3 . 87 (0 . 89%) N = 2 5:00 3 . 85 (0 . 40%) 3 . 85 (0 . 44%) 3 . 85 (0 . 38%) 3 . 85 (0 . 39%) N = 3 5:30 3 . 85 (0 . 34%) 3 . 85 (0 . 29%) 3 . 85 (0 . 33%) 3 . 85 (0 . 32%) N = 5 7:00 3 . 85 (0 . 25%) 3 . 85 (0 . 28%) 3 . 85 (0 . 30%) 10 . 43 (171 . 82%) N = 8 10:10 3 . 85 (0 . 28%) 3 . 85 (0 . 33%) 10 . 43 (171 . 82%) 10 . 43 (171 . 82%) AM/ Exponential 4:20 3 . 87 (0 . 95%) 3 . 87 (0 . 93%) 3 . 87 (0 . 90%) 3 . 87 (0 . 87%) AM/ Critic 6:10 3 . 87 (0 . 96%) 3 . 87 (0 . 97%) 3 . 87 (0 . 88%) 3 . 87 (0 . 88%) AM/ Rollout 5:30 3 . 85 (0 . 34%) 3 . 85 (0 . 29%) 3 . 85 (0 . 33%) 3 . 85 (0 . 32%) PN / Exponential 5:10 3 . 95 (2 . 94%) 3 . 94 (2 . 80%) 3 . 92 (2 . 09%) 3 . 93 (2 . 37%) PN / Critic 7:30 3 . 95 (3 . 00%) 3 . 95 (2 . 93%) 3 . 91 (2 . 01%) 3 . 94 (2 . 84%) PN / Rollout 6:40 3 . 93 (2 . 46%) 3 . 93 (2 . 36%) 3 . 90 (1 . 63%) 3 . 90 (1 . 78%) |
|
| 332 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 333 |
+
|
| 334 |
+
<!-- image -->
|
| 335 |
+
|
| 336 |
+
Figure 5: Optimality gap of different methods as a function of problem size n ∈ { 5 , 10 , 15 , 20 , 25 , 30 , 40 , 50 , 60 , 75 , 100 , 125 } . General baselines are drawn using dashed lines while learned algorithms are drawn with a solid line. Algorithms (general and learned) that perform search or sampling are plotted without connecting lines for clarity. The *, **, *** and **** indicate that values are reported from Bello et al. (2016), Vinyals et al. (2015), Dai et al. (2017) and Nowak et al. (2017) respectively. Best viewed in color.
|
| 337 |
+
|
| 338 |
+
Figure 6: Validation set optimality gap as a function of the number of epochs for different η .
|
| 339 |
+
|
| 340 |
+
<!-- image -->
|
| 341 |
+
|
| 342 |
+
## C VEHICLE ROUTING PROBLEM
|
| 343 |
+
|
| 344 |
+
The Capacitated Vehicle Routing Problem (CVRP) is a generalization of the TSP in which case there is a depot and multiple routes should be created, each starting and ending at the depot. In our graph based formulation, we add a special depot node with index 0 and coordinates x 0 . A vehicle (route) has capacity D > 0 and each (regular) node i ∈ { 1 , . . . n } has a demand 0 < δ i ≤ D . Each route starts and ends at the depot and the total demand in each route should not exceed the capacity, so ∑ i ∈ R j δ i ≤ D , where R j is the set of node indices assigned to route j . Without loss of generality, we assume a normalized ˆ D = 1 as we can use normalized demands ˆ δ i = δ i D .
|
| 345 |
+
|
| 346 |
+
The Split Delivery VRP (SDVRP) is a generalization of CVRP in which every node can be visited multiple times, and only a subset of the demand has to be delivered at each visit. Instances for both CVRP and SDVRP are specified in the same way: an instance with size n as a depot location x 0 , n node locations x i , i = 1 . . . n and (normalized) demands 0 < ˆ δ i ≤ 1 , i = 1 . . . n .
|
| 347 |
+
|
| 348 |
+
## C.1 INSTANCE GENERATION
|
| 349 |
+
|
| 350 |
+
We follow Nazari et al. (2018) in the generation of instances for n = 20 , 50 , 100 , but normalize the demands by the capacities. The depot location as well as n node locations are sampled uniformly at random in the unit square. The demands are defined as ˆ δ i = δ i D n where δ i is discrete and sampled uniformly from { 1 , . . . , 9 } and D 20 = 30 , D 50 = 40 and D 100 = 50.
|
| 351 |
+
|
| 352 |
+
## C.2 ATTENTION MODEL FOR THE VRP
|
| 353 |
+
|
| 354 |
+
Encoder In order to allow our Attention Model to distinguish the depot node from the regular nodes, we use separate parameters W x 0 and b x 0 to compute the initial embedding h (0) 0 of the depot node. Additionally, we provide the normalized demand δ i as input feature (and adjust the size of parameter W x accordingly):
|
| 355 |
+
|
| 356 |
+
<!-- formula-not-decoded -->
|
| 357 |
+
|
| 358 |
+
Capacity constraints To facilitate the capacity constraints, we keep track of the remaining demands ˆ δ i,t for the nodes i ∈ { 1 , . . . n } and remaining vehicle capacity ˆ D t at time t . At t = 1 , these are initialized as ˆ δ i,t = ˆ δ i and ˆ D t = 1 , after which they are updated as follows (recall that π t is the index of the node selected at decoding step t ):
|
| 359 |
+
|
| 360 |
+
̸
|
| 361 |
+
|
| 362 |
+
<!-- formula-not-decoded -->
|
| 363 |
+
|
| 364 |
+
̸
|
| 365 |
+
|
| 366 |
+
<!-- formula-not-decoded -->
|
| 367 |
+
|
| 368 |
+
If we do not allow split deliveries, ˆ δ i,t will be either 0 or ˆ δ i for all t .
|
| 369 |
+
|
| 370 |
+
Decoder context The context for the decoder for the VRP at time t is the current/last location π t -1 and the remaining capacity ˆ D t . Compared to TSP, we do not need placeholders if t = 1 as the route starts at the depot and we do not need to provide information about the first node as the route should end at the depot:
|
| 371 |
+
|
| 372 |
+
<!-- formula-not-decoded -->
|
| 373 |
+
|
| 374 |
+
Masking The depot can be visited multiple times, but we do not allow it to be visited at two subsequent timesteps. Therefore, in both layers of the decoder, we change the masking for the depot j = 0 and define u ( c )0 = -∞ if (and only if) t = 1 or π t -1 = 0 . The masking for the nodes
|
| 375 |
+
|
| 376 |
+
̸
|
| 377 |
+
|
| 378 |
+
depends on whether we allow split deliveries. Without split deliveries, we do not allow nodes to be visited if their remaining demand is 0 (if the node was already visited) or exceeds the remaining capacity, so for j = 0 we define u ( c ) j = -∞ if (and only if) ˆ δ i,t = 0 or ˆ δ i,t > ˆ D t . With split deliveries, we only forbid delivery when the remaining demand is 0, so we define u ( c ) j = -∞ if (and only if) ˆ �� i,t = 0 .
|
| 379 |
+
|
| 380 |
+
Split deliveries Without split deliveries, the remaining demand ˆ δ i,t is either 0 or ˆ δ i , corresponding to whether the node has been visited or not, and this information is conveyed to the model via the masking of the nodes already visited. However, when split deliveries are allowed, the remaining demand ˆ δ i,t can take any value 0 ≤ ˆ δ i,t ≤ ˆ δ i . This information cannot be included in the context node as it corresponds to individual nodes. Therefore we include it in the computation of the keys and values in both the attention layer (glimpse) and the output layer of the decoder, such that we compute queries, keys and values using:
|
| 381 |
+
|
| 382 |
+
<!-- formula-not-decoded -->
|
| 383 |
+
|
| 384 |
+
Here we W K d and W V d are ( d k × 1) parameter matrices and we define ˆ δ i,t = 0 for the depot i = 0 . Summing the projection of both h i and ˆ δ i,t is equivalent to projecting the concatenation [ h i , ˆ δ i,t ] with a single (( d h +1) × d k ) matrix W K . However, using this formulation we only need to compute the first term once (instead for every t ) and by the weight initialization this puts more importance on ˆ δ i,t initially (which is otherwise just 1 of d h +1 = 129 input values).
|
| 385 |
+
|
| 386 |
+
Training For the VRP, the length of the output of the model depends on the number of times the depot is visited. In general, the depot is visited multiple times, and in the case of SDVRP also some regular nodes are visited twice. Therefore the length of the solution is larger than n , which requires more memory such that we find it necessary to limit the batch size B to 256 for n = 100 (on 2 GPUs). To keep training times tractable and the total number of parameter updates equal, we still process 2500 batches per epoch, for a total of 0.64M training instances per epoch.
|
| 387 |
+
|
| 388 |
+
## C.3 DETAILS OF BASELINES
|
| 389 |
+
|
| 390 |
+
For LKH3 8 by Helsgaun (2017) we build and run their code with the SPECIAL parameter as specified in their CVRP runscript 9 . We perform 1 run with a maximum of 10000 trials, as we found performing 10 runs only marginally improves the quality of the results while taking much more time.
|
| 391 |
+
|
| 392 |
+
## C.4 EXAMPLE SOLUTIONS
|
| 393 |
+
|
| 394 |
+
Figure 7 shows example solutions for the CVRP with n = 100 that were obtained by a single construction using the model with greedy decoding. These visualizations give insight in the heuristic that the model has learned. In general we see that the model constructs the routes from the bottom to the top, starting below the depot. Most routes are densely packed, except for the last route that has to serve some remaining (close to each other) customers. In most cases, the node in the route that is farthest from the depot is somewhere in the middle of the route, such that customers are served on the way to and from the farthest nodes. In some cases, we see that the order of stops within some individual routes is suboptimal, which means that the method will likely benefit from simple further optimizations on top, such as a beam search, a post-processing procedure based on local search (e.g. 2OPT) or solving the individual routes using a TSP solver.
|
| 395 |
+
|
| 396 |
+
[8 http://akira.ruc.dk/˜keld/research/LKH-3/](http://akira.ruc.dk/~keld/research/LKH-3/)
|
| 397 |
+
|
| 398 |
+
[9 run CVRP in http://akira.ruc.dk/˜keld/research/LKH-3/BENCHMARKS/CVRP.tgz](http://akira.ruc.dk/~keld/research/LKH-3/BENCHMARKS/CVRP.tgz)
|
| 399 |
+
|
| 400 |
+
Figure 7: Example greedy solutions for the CVRP ( n = 100 ). Edges from and to depot omitted for clarity. Legend order/coloring and arcs indicate the order in which the solution was generated. Legends indicate the number of stops, the used and available capacity and the distance per route.
|
| 401 |
+
|
| 402 |
+
<!-- image -->
|
| 403 |
+
|
| 404 |
+
## D ORIENTEERING PROBLEM
|
| 405 |
+
|
| 406 |
+
In the Orienteering Problem (OP) each node has a prize ρ i and the goal is to maximize the total prize of nodes visited, while keeping the total length of the route below a maximum length T . This problem is different from the TSP and the VRP because visiting each node is optional. Similar to the VRP, we add a special depot node with index 0 and coordinates x 0 . If the model selects the depot, we consider the route to be finished. In order to prevent infeasible solutions, we only allow to visit a node if after visiting that node a return to the depot is still possible within the maximum length constraint. Note that it is always suboptimal to visit the depot if additional nodes can be visited, but we do not enforce this knowledge.
|
| 407 |
+
|
| 408 |
+
## D.1 INSTANCE GENERATION
|
| 409 |
+
|
| 410 |
+
The depot location as well as n node locations are sampled uniformly at random in the unit square. For the distribution of the prizes, we consider three different variants described by Fischetti et al. (1998), but we normalize the prizes ρ i such that the normalized prizes ˆ ρ i are between 0 and 1.
|
| 411 |
+
|
| 412 |
+
Constant ρ i = ˆ ρ i = 1 . Every node has the same prize so the goal becomes to visit as many nodes as possible within the length constraint.
|
| 413 |
+
|
| 414 |
+
Uniform ρ i ∼ DiscreteUniform (1 , 100) , ˆ ρ i = ρ i 100 . Every node has a prize that is (discretized) uniform.
|
| 415 |
+
|
| 416 |
+
Distance ρ i = 1+ ⌊ 99 · d 0 i max n j =1 d 0 j ⌋ , ˆ ρ i = ρ i 100 , where d 0 i is the distance from the depot to node i . Every node has a (discretized) prize that is proportional to the distance to the depot. This is designed to be challenging as the largest prizes are furthest away from the depot (Fischetti et al., 1998).
|
| 417 |
+
|
| 418 |
+
The maximum length T n for instances with n nodes (and a depot) is chosen to be (on average) approximately half of the length of the average TSP tour for uniform TSP instances with n nodes 10 . This idea is that this way approximately (a little more than) half of the nodes can be visited, which results in the most difficult problem instances (Vansteenwegen et al., 2011). This is because the number of possible node selections ( n k ) is maximized if k = n 2 and additionally determining the actual path is harder with more nodes selected. We set fixed maximum lengths T 20 = 2 , T 50 = 3 and T 100 = 4 instead of adjusting the constraint per instance, such that for some instances more or less nodes can be visited. Note that T n has the same unit as the node coordinates x i , so we do not normalize them.
|
| 419 |
+
|
| 420 |
+
## D.2 ATTENTION MODEL FOR THE OP
|
| 421 |
+
|
| 422 |
+
Encoder Similar to the VRP, we use separate parameters for the depot node embedding. Additionally, we provide the node prize ˆ ρ i as input feature:
|
| 423 |
+
|
| 424 |
+
<!-- formula-not-decoded -->
|
| 425 |
+
|
| 426 |
+
Max length constraint In order to satisfy the max length constraint, we keep track of the remaining max length T t at time t . Starting at t = 1 , T 1 = T . Then for t > 0 , T is updated as
|
| 427 |
+
|
| 428 |
+
<!-- formula-not-decoded -->
|
| 429 |
+
|
| 430 |
+
Here d π t -1 ,π t is the distance from node π t -1 to π t and we conveniently define π 0 = 0 as we start at the depot.
|
| 431 |
+
|
| 432 |
+
Decoder context The context for the decoder for the OP at time t is the current/last location π t -1 and the remaining max length T t . Similar to VRP, we do not need placeholders if t = 1 as the route starts at the depot and we do not need to provide information about the first node as the route should end at the depot. We do not need to provide information on the prizes gathered as this is irrelevant for the remaining decisions. The context is defined as:
|
| 433 |
+
|
| 434 |
+
10 The average length of the optimal TSP tour is 3.84, 5.70 and 7.76 for n = 20 , 50 , 100 .
|
| 435 |
+
|
| 436 |
+
<!-- formula-not-decoded -->
|
| 437 |
+
|
| 438 |
+
Masking In the OP, the depot node can always be visited so is never masked. Regular nodes are masked (i.e. cannot be visited) if either they are already visited or if they cannot be visited within the remaining length constraint:
|
| 439 |
+
|
| 440 |
+
<!-- formula-not-decoded -->
|
| 441 |
+
|
| 442 |
+
## D.3 DETAILS OF BASELINES
|
| 443 |
+
|
| 444 |
+
For Compass 11 by Kobeaga et al. (2018), we compile their code and run it with default parameters, only adding --op --op-ea4op to indicate that the Genetic Algorithm for the Orienteering Problem should be used. As Compass uses integer coordinates and prizes, we multiply all floats by 10 7 and round to integers. We run the Python Genetic Algorithm 12 with default parameters.
|
| 445 |
+
|
| 446 |
+
Tsiligirides Tsiligirides (1984) describes a heuristic procedure for solving the OP. It consists of sampling 3000 tours through a randomized construction procedure and applies local search on top. The randomized construction part of the heuristic is structurally exactly the same as the heuristic learned by our model, but with a manually engineered function to define the node probabilities. We implement the construction part of the heuristic and compare it to our model (either greedy or sampling 1280 solutions), without the local search (as this can also be applied on top of our model). The final heuristic used by Tsiligirides (1984) uses a formula with multiple terms to define the probability that a node should be selected, but by tuning the weights the form with only one simple term works best, showing the difficulty of manually defining a good probability distribution. In our terms, the heuristic defines a score s i for each node at time t as the prize divided by the distance from the current node π t -1 , raised to the 4th power:
|
| 447 |
+
|
| 448 |
+
<!-- formula-not-decoded -->
|
| 449 |
+
|
| 450 |
+
Let S be the set with the min(4 , n -( t -1)) unvisited nodes with maximum score s i . Then the node probabilities p i at time t are defined as
|
| 451 |
+
|
| 452 |
+
<!-- formula-not-decoded -->
|
| 453 |
+
|
| 454 |
+
OR Tools For the Google OR Tools implementation, we modify the formulation for the CVRP 13 :
|
| 455 |
+
|
| 456 |
+
- We replace the Manhattan distance by the Euclidian distance.
|
| 457 |
+
- We set the number of vehicles to 1.
|
| 458 |
+
- For each individual node i , we add a Disjunction constraint with { i } as the set of nodes, and a penalty equal to the prize ˆ ρ i . This allows OR tools to skip node i at a cost ˆ ρ i .
|
| 459 |
+
- We replace the capacity constraint by a maximum distance. constraint
|
| 460 |
+
- We remove the objective to minimize the length.
|
| 461 |
+
|
| 462 |
+
We multiply all float inputs by 10 7 and round to integers. Note that OR Tools computes penalties for skipped nodes rather than gains for nodes that are visited. The problem is equivalent, but in order to compare the objective value against our method, we need to add the constant sum of all penalties ∑ i ˆ ρ i to the OR Tools objective.
|
| 463 |
+
|
| 464 |
+
[11 https://github.com/bcamath-ds/compass](https://github.com/bcamath-ds/compass)
|
| 465 |
+
|
| 466 |
+
[12 https://github.com/mc-ride/orienteering](https://github.com/mc-ride/orienteering)
|
| 467 |
+
|
| 468 |
+
[13 https://github.com/google/or-tools/blob/master/examples/python/cvrp.py](https://github.com/google/or-tools/blob/master/examples/python/cvrp.py)
|
| 469 |
+
|
| 470 |
+
## D.4 EXTENDED RESULTS
|
| 471 |
+
|
| 472 |
+
Table 3 displays the results for the OP with constant and uniform prize distributions. The results are similar to the results for the prize distribution based on the distance to the depot, although by the calculation time for Gurobi it is confirmed that indeed constant and uniform prize distributions are easier.
|
| 473 |
+
|
| 474 |
+
## E PRIZE COLLECTING TSP
|
| 475 |
+
|
| 476 |
+
In the Prize Collecting TSP (PCTSP) each node has a prize ρ i and an associated penalty β i . The goal is to minimize the total length of the tour plus the sum of penalties for nodes which are not visited, while collecting at least a given minimum total prize. W.l.o.g. we assume the minimum total prize is equal to 1 (as
|
| 477 |
+
|
| 478 |
+
Table 3: Additional results for the OP
|
| 479 |
+
|
| 480 |
+
| Method 20 50 100 OP (constant) Gurobi 10 . 57 (4m) - - Compass 10 . 56 (55s) 29 . 58 (3m) 59 . 35 (8m) Tsili (greedy) 8 . 82 (5s) 23 . 89 (4s) 47 . 65 (5s) AM(greedy) 10 . 27 (0s) 28 . 31 (2s) 55 . 81 (5s) GA (Python) 9 . 72 (10m) 18 . 52 (1h) 25 . 68 (5h) OR Tools (10s) 8 . 54 (52m) - - Tsili (sampling) 10 . 48 (28s) 28 . 26 (2m) 54 . 27 (6m) AM(sampling) 10 . 49 (4m) 29 . 36 (17m) 58 . 33 (56m) OP (uniform) Gurobi 5 . 85 (7m) - - Compass 5 . 84 (1m) 16 . 46 (5m) 33 . 30 (14m) Tsili (greedy) 4 . 85 (4s) 12 . 80 (4s) 25 . 48 (5s) AM(greedy) 5 . 60 (0s) 15 . 62 (2s) 31 . 03 (5s) GA (Python) 5 . 53 (10m) 10 . 81 (1h) 14 . 89 (5h) OR Tools (10s) 4 . 69 (52m) - - Tsili (sampling) 5 . 70 (26s) 15 . 28 (2m) 29 . 54 (5m) AM(sampling) 5 . 76 (4m) 16 . 25 (16m) 32 . 41 (51m) |
|
| 481 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 482 |
+
|
| 483 |
+
prizes can be normalized). This problem is related to the OP but inverts the goal (minimizing tour length given a minimum total prize to collect instead of maximizing total prize given a maximum tour length) and additionally adds penalties. Again, we add a special depot node with index 0 and coordinates x 0 and if the model selects the depot, the route is finished. In the PCTSP, it can be beneficial to visit additional nodes, even if the minimum total prize constraint is already satisfied, in order to avoid penalties.
|
| 484 |
+
|
| 485 |
+
## E.1 INSTANCE GENERATION
|
| 486 |
+
|
| 487 |
+
The depot location as well as n node locations are sampled uniformly at random in the unit square. Similar to the OP, we select the distribution for the prizes and penalties with the idea that for difficult instances approximately half of the nodes should be visited. Additionally, neither the prize nor the penalty should dominate the node selection process.
|
| 488 |
+
|
| 489 |
+
Prizes We consider uniformly distributed prizes. If we sample prizes ρ i ∼ Uniform (0 , 1) , then E ( ρ i ) = 1 2 , and the expected total prize of any subset of n 2 nodes (i.e. half of the nodes) would be n 4 . Therefore, if S is the set of nodes that is visited, we require that ∑ i ∈ S ρ i ≥ n 4 , or equivalently ∑ i ∈ S ˆ ρ i ≥ 1 where ˆ ρ i = ρ i · 4 n is the normalized prize. Note that it can be the case that ∑ n i =1 ˆ ρ i < 1 , in which case the prize constraint may be violated but it is only allowed to return to the depot after all nodes have been visited.
|
| 490 |
+
|
| 491 |
+
Penalties If penalties are too small, then node selection is determined almost entirely by the minimum total prize constraint. If penalties are too large, we will always visit all nodes, making the minimum total prize constraint obsolete. We argue that in order for the penalties to be meaningful, they should contribute a term in the objective approximately equal to the total length of the tour. If L n is the expected TSP tour length with n nodes, we try to achieve this by sampling β i ∼ Uniform (0 , 2 · L n n ) such that E ( β i ) = L n n and the expected total penalty for a subset of n 2 nodes is L n 2 . Following the numbers we use for the OP, we roughly define L n 2 ≈ K n = 2 , 3 , 4 for n = 20 , 50 , 100 14 . This means that we should sample β i ∼ Uniform (0 , 4 · K n n ) , but empirically we find that ˆ β i ∼ Uniform (0 , 3 · K n n ) works better, which means that the prizes and penalties are balanced as the minimum total prize constraint is sometimes binding and sometimes not.
|
| 492 |
+
|
| 493 |
+
14 The average length of the optimal TSP tour is 3.84, 5.70 and 7.76 for n = 20 , 50 , 100 .
|
| 494 |
+
|
| 495 |
+
## E.2 ATTENTION MODEL FOR THE PCTSP
|
| 496 |
+
|
| 497 |
+
Encoder Again, we use separate parameters for the depot node embedding. Additionally, we provide the node prize ˆ ρ i and the penalty ˆ β i as input features:
|
| 498 |
+
|
| 499 |
+
<!-- formula-not-decoded -->
|
| 500 |
+
|
| 501 |
+
Minimum prize constraint In order to satisfy the minimum total prize constraint, we keep track of the remaining total prize P t to collect at time t . At t = 1 , P 1 = 1 (as we normalized prizes). Then for t > 0 , P is updated as
|
| 502 |
+
|
| 503 |
+
<!-- formula-not-decoded -->
|
| 504 |
+
|
| 505 |
+
If the constraint is satisfied after visiting π t is visited at time t , then P t +1 will be 0.
|
| 506 |
+
|
| 507 |
+
Decoder context The context for the decoder for the PCTSP at time t is the current/last location π t -1 and the remaining prize to collect P t . Again, we do not need placeholders if t = 1 as the route starts at the depot and we do not need to provide information about the first node as the route should end at the depot. The information about the prizes collected is implicitly provided to the model in the form of P t and we do not need to provide any information about the penalties as this is irrelevant for the remaining decisions:
|
| 508 |
+
|
| 509 |
+
<!-- formula-not-decoded -->
|
| 510 |
+
|
| 511 |
+
Masking In the PCTSP, the depot node cannot be visited if the remaining prize to collect P t is larger than 0 and not yet all nodes have been visited (so t ≤ n ):
|
| 512 |
+
|
| 513 |
+
<!-- formula-not-decoded -->
|
| 514 |
+
|
| 515 |
+
Regular nodes are masked (i.e. cannot be visited) only if they are already visited:
|
| 516 |
+
|
| 517 |
+
<!-- formula-not-decoded -->
|
| 518 |
+
|
| 519 |
+
## E.3 DETAILS OF BASELINES
|
| 520 |
+
|
| 521 |
+
For the C++ Iterated Local Search (ILS) algorithm 15 , we perform 1 run as this takes already 2 minutes per instance (single thread) on average. For the Python ILS algorithm 16 we perform 10 runs as this algorithm is fast. This improved results somewhat for n = 20 .
|
| 522 |
+
|
| 523 |
+
OR Tools For the Google OR Tools implementation, we modify the formulation for the CVRP 17 :
|
| 524 |
+
|
| 525 |
+
- We replace the Manhattan distance by the Euclidian distance.
|
| 526 |
+
- We set the number of vehicles to 1.
|
| 527 |
+
- For each individual node i , we add a Disjunction constraint with { i } as the set of nodes, and a penalty equal to the penalty ˆ β i . This allows OR tools to skip node i at a cost ˆ β i .
|
| 528 |
+
- We replace the capacity constraint by a minimum total prize constraint by adding the prizes as a Dimension .
|
| 529 |
+
|
| 530 |
+
Wemultiply all float inputs by 10 7 and round to integers. Note that we keep the total length objective from the CVRP and add the Disjunction constraint with penalties to obtain the right objective.
|
| 531 |
+
|
| 532 |
+
[15 https://github.com/jordanamecler/PCTSP](https://github.com/jordanamecler/PCTSP)
|
| 533 |
+
|
| 534 |
+
[16 https://github.com/rafael2reis/salesman](https://github.com/rafael2reis/salesman)
|
| 535 |
+
|
| 536 |
+
[17 https://github.com/google/or-tools/blob/master/examples/python/cvrp.py](https://github.com/google/or-tools/blob/master/examples/python/cvrp.py)
|
| 537 |
+
|
| 538 |
+
## F STOCHASTIC PCTSP (SPCTSP)
|
| 539 |
+
|
| 540 |
+
For the SPCTSP, we assume that the real prize collected ˆ ρ ∗ i at each node only becomes known when visiting the node, and ˆ ρ i = E [ ˆ ρ ∗ i ] is the expected prize. We assume the real prizes follow a uniform distribution, so ˆ ρ ∗ i ∼ Uniform (0 , 2ˆ ρ i ) .
|
| 541 |
+
|
| 542 |
+
## F.1 ATTENTION MODEL FOR THE SPCTSP
|
| 543 |
+
|
| 544 |
+
In order to apply the Attention Model to the Stochastic PCTSP, the only change we need is that we use the real ˆ ρ ∗ i to update the remaining prize to collect P t in equation 31:
|
| 545 |
+
|
| 546 |
+
<!-- formula-not-decoded -->
|
| 547 |
+
|
| 548 |
+
We could theoretically use the model trained for PCTSP without retraining, but we choose to retrain. This way the model could (for example) learn that if it needs to gather a remaining (normalized) prize of 0 . 1 , it might prefer to visit a node with expected prize 0 . 2 over a node with expected prize 0 . 1 as the first real prize will be ≥ 0 . 1 with probability 75% (uniform prizes) whereas the latter only with 50% and thus has a probability of 50% to not satisfy the constraint.
|
| 549 |
+
|
| 550 |
+
## F.2 ROLLOUT BASELINE IN THE STOCHASTIC SETTING
|
| 551 |
+
|
| 552 |
+
Instead of sampling the real prizes online, we already sample them when creating the dataset but keep them hidden to the algorithm. This way, when using a rollout baseline, both the greedy rollout baseline as well as the sample (rollout) from the model use the same real prizes, such that any difference between the two is not a result of stochasticity. This can be seen as a variant of using Common Random Numbers for variance reduction (Glasserman & Yao, 1992).
|
| 553 |
+
|
| 554 |
+
## F.3 DETAILS OF BASELINES
|
| 555 |
+
|
| 556 |
+
For the SPCTSP, it is not possible to formulate an exact model that constructs a tour offline (as any tour can be infeasible with nonzero probability) and an algorithm that computes the optimal decision online should take into account an infinite number of scenarios. As a baseline we implement a strategy that:
|
| 557 |
+
|
| 558 |
+
1. Plans a tour using the expected prizes ˆ ρ i
|
| 559 |
+
2. Executes part of the tour (not returning to the depot), observing the real prizes ˆ ρ ∗ i
|
| 560 |
+
3. Computes the remaining total prize that needs to be collected
|
| 561 |
+
4. Computes a new tour (again using expected prizes ˆ ρ i ), starting from the last node that was visited, through nodes that have not yet been visited and ending at the depot
|
| 562 |
+
5. Repeats the steps (2) - (4) above until the minimum total prize has been collected or all nodes have been visited
|
| 563 |
+
6. Returns to the depot
|
| 564 |
+
|
| 565 |
+
Planning of the tours using deterministic prizes means we need to solve a (deterministic) PCTSP, for which we use the ILS C++ algorithm as this was the strongest algorithm for PCTSP (for large n ). Note that in (4), we have a variant of the PCTSP where we do not have a single depot, but rather separate start and end points, whereas the ILS C++ implementation assumes starting and ending at a single depot. However, as the ILS C++ implementation uses a distance matrix, we can effectively plan with a start and end node by defining the distance from the 'depot' to node j as the distance from the start node (the last visited node) to node j , whereas we leave the distance from node j to the depot/end node unchanged (so the distance matrix becomes asymmetrical). Additionally, we remove all nodes (rows/columns in the distance matrix) that have already been visited from the problem.
|
| 566 |
+
|
| 567 |
+
We consider three variants that differ in the number of nodes that are visited before replanning the tour, for a tradeoff between adaptivity and run time:
|
| 568 |
+
|
| 569 |
+
1. All nodes in the planned tour are visited (except the final return to the depot). We only need to replan and visit additional nodes if the constraint is not satisfied, otherwise we return to the depot.
|
| 570 |
+
|
| 571 |
+
2. Half of the nodes in the planned tour are visited, where we visit k nodes if there are 2 k +1 nodes (excluding the return to the depot), so we round down if an odd number of visits is planned. This way, we will have O (log n ) replanning iterations, while being more adaptive when we are closer to satisfying the total prize constraint. This is a trade-off of adaptivity vs computation time.
|
| 572 |
+
3. Only the fi rst node is visited, after which we directly replan. This allows the algorithm to take new online information about the real prizes into account directly, but is very expensive to compute as it requires O ( n ) iterations.
|
text-versions/attention-markdown/1804.03999_Attention UNet Learning Where to Look fo.md
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1804.03999 Attention Unet Learning Where To Look Fo
|
| 2 |
+
|
| 3 |
+
## Attention U-Net: Learning Where to Look for the Pancreas
|
| 4 |
+
|
| 5 |
+
Ozan Oktay 1,5 , Jo Schlemper 1 , Loic Le Folgoc 1 , Matthew Lee 4 , Mattias Heinrich 3 , Kazunari Misawa 2 , Kensaku Mori 2 , Steven McDonagh 1 , Nils Y Hammerla 5 , Bernhard Kainz 1 , Ben Glocker 1 , and Daniel Rueckert 1
|
| 6 |
+
|
| 7 |
+
1 Biomedical Image Analysis Group, Imperial College London, London, UK 2 Dept. of Media Science, Nagoya University & Aichi Cancer Center, JP 3 Medical Informatics, University of Luebeck, DE, 4 HeartFlow, California, USA 5 Babylon Health, London, UK
|
| 8 |
+
|
| 9 |
+
## Abstract
|
| 10 |
+
|
| 11 |
+
We propose a novel attention gate (AG) model for medical imaging that automatically learns to focus on target structures of varying shapes and sizes. Models trained with AGs implicitly learn to suppress irrelevant regions in an input image while highlighting salient features useful for a specific task. This enables us to eliminate the necessity of using explicit external tissue/organ localisation modules of cascaded convolutional neural networks (CNNs). AGs can be easily integrated into standard CNN architectures such as the U-Net model with minimal computational overhead while increasing the model sensitivity and prediction accuracy. The proposed Attention U-Net architecture is evaluated on two large CT abdominal datasets for multi-class image segmentation. Experimental results show that AGs consistently improve the prediction performance of U-Net across different datasets and training sizes while preserving computational efficiency. The source code for the proposed architecture is publicly available.
|
| 12 |
+
|
| 13 |
+
## 1 Introduction
|
| 14 |
+
|
| 15 |
+
Automated medical image segmentation has been extensively studied in the image analysis community due to the fact that manual, dense labelling of large amounts of medical images is a tedious and error-prone task. Accurate and reliable solutions are desired to increase clinical work flow efficiency and support decision making through fast and automatic extraction of quantitative measurements.
|
| 16 |
+
|
| 17 |
+
With the advent of convolutional neural networks (CNNs), near-radiologist level performance can be achieved in automated medical image analysis tasks including cardiac MR segmentation [3] and cancerous lung nodule detection [17]. High representation power, fast inference, and filter sharing properties have made CNNs the de facto standard for image segmentation. Fully convolutional networks (FCNs) [18] and the U-Net [24] are two commonly used architectures. Despite their good representational power, these architectures rely on multi-stage cascaded CNNs when the target organs show large inter-patient variation in terms of shape and size. Cascaded frameworks extract a region of interest (ROI) and make dense predictions on that particular ROI. The application areas include cardiac MRI [14], cardiac CT [23], abdominal CT [26, 27] segmentation, and lung CT nodule detection [17]. However, this approach leads to excessive and redundant use of computational resources and model parameters; for instance, similar low-level features are repeatedly extracted by all models within the cascade. To address this general problem, we propose a simple and yet effective solution, namely attention gates (AGs). CNN models with AGs can be trained from scratch in a standard way similar to the training of a FCN model, and AGs automatically learn to focus on target structures without additional supervision. At test time, these gates generate soft region proposals implicitly on-the-fly and highlight salient features useful for a specific task. Moreover, they do not introduce significant computational overhead and do not require a large number of model parameters as in the case of multi-model frameworks. In return, the proposed AGs improve model sensitivity and accuracy for dense label predictions by suppressing feature activations in irrelevant regions. In this way, the necessity of using an external organ localisation model can be eliminated while maintaining the high prediction accuracy. Similar attention mechanisms have been proposed for natural image classification [11] and captioning [1] to perform adaptive feature pooling, where model predictions are conditioned only on a subset of selected image regions. In this paper, we generalise this design and propose image-grid based gating that allows attention coefficients to be specific to local regions. Moreover, our approach can be used for attention-based dense predictions.
|
| 18 |
+
|
| 19 |
+
We demonstrate the implementation of AG in a standard U-Net architecture ( Attention U-Net ) and apply it to medical images. We choose the challenging CT pancreas segmentation problem to provide experimental evidence for our proposed contributions. This problem constitutes a difficult task due to low tissue contrast and large variability in organ shape and size. We evaluate our implementation on two commonly used benchmarks: TCIA Pancreas CT -82 [25] and multi-class abdominal CT -150 . The results show that AGs consistenly improve prediction accuracy across different datasets and training sizes while achieving state-of-the-art performance without requiring multiple CNN models.
|
| 20 |
+
|
| 21 |
+
## 1.1 Related Work
|
| 22 |
+
|
| 23 |
+
CT Pancreas Segmentation: Early work on pancreas segmentation from abdominal CT used statistical shape models [5, 28] or multi-atlas techniques [22, 34]. In particular, atlas approaches benefit from implicit shape constraints enforced by propagation of manual annotations. However, in public benchmarks such as the TCIA dataset [25], Dice similarity coefficients (DSC) for atlas-based frameworks ranges from 69 . 6% to 73 . 9% [22, 34]. In [39] a classification based framework is proposed to remove the dependency of atlas to image registration. Recently, cascaded multi-stage CNN models [26, 27, 38] have been proposed to address the problem. Here, an initial coarse-level model (e.g. U-Net or Regression Forest) is used to obtain a ROI and then a cropped ROI is used for segmentation refinement by a second model. Similarly, combinations of 2D-FCN and recurrent neural network (RNN) models are utilised in [4] to exploit dependencies between adjacent axial slices. These approaches achieve state-of-the-art performance in the TCIA benchmark ( 81 . 2% -82 . 4% DSC). Without using a cascaded framework, the performance drops between 2 . 0% and 4 . 4% . Recent work [37] proposed an iterative two-stage model that recursively updates local and global predictions, and both models are trained end-to-end. Besides standard FCNs, dense connections [6] and sparse convolutions [8, 9] have been applied to the CT pancreas segmentation problem. Dense connections and sparse kernels reduce computational complexity by requiring less number of non-zero parameters.
|
| 24 |
+
|
| 25 |
+
Attention Gates: AGs are commonly used in natural image analysis, knowledge graphs, and language processing (NLP) for image captioning [1], machine translation [2, 30], and classification [11, 31, 32] tasks. Initial work has explored attention-maps by interpreting gradient of output class scores with respect to the input image. Trainable attention, on the other hand, is enforced by design and categorised as hard- and soft-attention. Hard attention [21], e.g. iterative region proposal and cropping, is often non-differentiable and relies on reinforcement learning for parameter updates, which makes model training more difficult. Recursive hard-attention is used in [36] to detect anomalies in chest X-ray scans. Contrarily, soft attention is probabilistic and utilises standard back-propagation without need for Monte Carlo sampling. For instance, additive soft attention is used in sentence-to-sentence translation [2, 29] and more recently applied to image classification [11, 32]. In [10], channel-wise attention is used to highlight important feature dimensions, which was the top-performer in the ILSVRC 2017 image classification challenge. Self-attention techniques [11, 33] have been proposed to remove the dependency on external gating information. For instance, non-local self attention is used in [33] to capture long range dependencies. In [11, 32] self-attention is used to perform class-specific pooling, which results in more accurate and robust image classification performance.
|
| 26 |
+
|
| 27 |
+
## 1.2 Contributions
|
| 28 |
+
|
| 29 |
+
In this paper, we propose a novel self-attention gating module that can be utilised in CNN based standard image analysis models for dense label predictions. Moreover, we explore the benefit of AGs to medical image analysis, in particular, in the context of image segmentation. The contributions of this work can be summarised as follows:
|
| 30 |
+
|
| 31 |
+
Figure 1: A block diagram of the proposed Attention U-Net segmentation model. Input image is progressively filtered and downsampled by factor of 2 at each scale in the encoding part of the network (e.g. H 4 = H 1 / 8 ). N c denotes the number of classes. Attention gates (AGs) filter the features propagated through the skip connections. Schematic of the AGs is shown in Figure 2. Feature selectivity in AGs is achieved by use of contextual information (gating) extracted in coarser scales.
|
| 32 |
+
|
| 33 |
+
<!-- image -->
|
| 34 |
+
|
| 35 |
+
- We take the attention approach proposed in [11] a step further by proposing grid-based gating that allows attention coefficients to be more specific to local regions. This improves performance compared to gating based on a global feature vector. Moreover, our approach can be used for dense predictions since we do not perform adaptive pooling.
|
| 36 |
+
- We propose one of the first use cases of soft-attention technique in a feed-forward CNN model applied to a medical imaging task. The proposed attention gates can replace hardattention approaches used in image classification [36] and external organ localisation models in image segmentation frameworks [14, 22, 26, 27].
|
| 37 |
+
- An extension to the standard U-Net model is proposed to improve model sensitivity to foreground pixels without requiring complicated heuristics. Accuracy improvements over U-Net are experimentally observed to be consistent across different imaging datasets.
|
| 38 |
+
|
| 39 |
+
## 2 Methodology
|
| 40 |
+
|
| 41 |
+
Fully Convolutional Network (FCN): Convolutional neural networks (CNNs) outperform traditional approaches in medical image analysis on public benchmark datasets [14, 17] while being an order of magnitude faster than, e.g., graph-cut and multi-atlas segmentation techniques [34]. This is mainly attributed to the fact that (I) domain specific image features are learnt using stochastic gradient descent (SGD) optimisation, (II) learnt kernels are shared across all pixels, and (III) image convolution operations exploit the structural information in medical images well. In particular, fully convolutional networks (FCN) [18] such as U-Net [24], DeepMedic [13] and holistically nested networks [16, 35] have been shown to achieve robust and accurate performance in various tasks including cardiac MR [3], brain tumours [12] and abdominal CT [26, 27] image segmentation tasks.
|
| 42 |
+
|
| 43 |
+
Convolutional layers progressively extract higher dimensional image representations ( x l ) by processing local information layer by layer. Eventually, this separates pixels in a high dimensional space according to their semantics. Through this sequential process, model predictions are conditioned on information collected from a large receptive field. Hence, feature-map x l is obtained at the output of layer l by sequentially applying a linear transformation followed by a non-linear activation function. It is often chosen as rectified linear unit: σ 1 ( x l i,c ) = max (0 , x l i,c ) where i and c denote spatial and channel dimensions respectively. Feature activations can be formulated as: x l c = σ 1 (∑ c ′ ∈ F l x l -1 c ′ ∗ k c ′ ,c ) where ∗ denotes the convolution operation, and the spatial subscript ( i ) is omitted in the formulation for notational clarity. The function f ( x l ; Φ l ) = x ( l +1) applied in convolution layer l is characterised by trainable kernel parameters Φ l . The parameters are learnt by Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
| 44 |
+
|
| 45 |
+
Figure 2: Schematic of the proposed additive attention gate (AG). Input features ( x l ) are scaled with attention coefficients ( α ) computed in AG. Spatial regions are selected by analysing both the activations and contextual information provided by the gating signal ( g ) which is collected from a coarser scale. Grid resampling of attention coefficients is done using trilinear interpolation.
|
| 46 |
+
|
| 47 |
+
<!-- image -->
|
| 48 |
+
|
| 49 |
+
minimising a training objective, e.g. cross-entropy loss, using stochastic gradient descent (SGD). In this paper, we build our attention model on top of a standard U-Net architecture. U-Nets are commonly used for image segmentation tasks because of their good performance and efficient use of GPU memory. The latter advantage is mainly linked to extraction of image features at multiple image scales. Coarse feature-maps capture contextual information and highlight the category and location of foreground objects. Feature-maps extracted at multiple scales are later merged through skip connections to combine coarse- and fine-level dense predictions as shown in Figure 1.
|
| 50 |
+
|
| 51 |
+
Attention Gates for Image Analysis: To capture a sufficiently large receptive field and thus, semantic contextual information, the feature-map grid is gradually downsampled in standard CNN architectures. In this way, features on the coarse spatial grid level model location and relationship between tissues at global scale. However, it remains difficult to reduce false-positive predictions for small objects that show large shape variability. In order to improve the accuracy, current segmentation frameworks [14, 26, 27] rely on additional preceding object localisation models to simplify the task into separate localisation and subsequent segmentation steps. Here, we demonstrate that the same objective can be achieved by integrating attention gates (AGs) in a standard CNN model. This does not require the training of multiple models and a large number of extra model parameters. In contrast to the localisation model in multi-stage CNNs, AGs progressively suppress feature responses in irrelevant background regions without the requirement to crop a ROI between networks.
|
| 52 |
+
|
| 53 |
+
Attention coefficients, α i ∈ [0 , 1] , identify salient image regions and prune feature responses to preserve only the activations relevant to the specific task as shown in Figure 3a. The output of AGs is the element-wise multiplication of input feature-maps and attention coefficients: ˆ x l i,c = x l i,c · α l i . In a default setting, a single scalar attention value is computed for each pixel vector x l i ∈ R F l where F l corresponds to the number of feature-maps in layer l . In case of multiple semantic classes, we propose to learn multi-dimensional attention coefficients. This is inspired by [29], where multidimensional attention coefficients are used to learn sentence embeddings. Thus, each AG learns to focus on a subset of target structures. As shown in Figure 2, a gating vector g i ∈ R F g is used for each pixel i to determine focus regions. The gating vector contains contextual information to prune lower-level feature responses as suggested in [32], which uses AGs for natural image classification. We use additive attention [2] to obtain the gating coefficient. Although this is computationally more expensive, it has experimentally shown to achieve higher accuracy than multiplicative attention [19]. Additive attention is formulated as follows:
|
| 54 |
+
|
| 55 |
+
<!-- formula-not-decoded -->
|
| 56 |
+
|
| 57 |
+
<!-- formula-not-decoded -->
|
| 58 |
+
|
| 59 |
+
where σ 2 ( x i,c ) = 1 1+ exp ( -x i,c ) correspond to sigmoid activation function. AG is characterised by a set of parameters Θ att containing: linear transformations W x ∈ R F l × F int , W g ∈ R F g × F int , ψ ∈ R F int × 1 and bias terms b ψ ∈ R , b g ∈ R F int . The linear transformations are computed using channel-wise 1x1x1 convolutions for the input tensors. In other contexts [33], this is referred to as vector concatenation-based attention , where the concatenated features x l and g are linearly mapped to a R F int dimensional intermediate space. In image captioning [1] and classification [11] tasks, the softmax activation function is used to normalise the attention coefficients ( σ 2 ); however, sequential use of softmax yields sparser activations at the output. For this reason, we choose a sigmoid activation function. This results experimentally in better training convergence for the AG parameters. In contrast to [11] we propose a grid-attention technique. In this case, gating signal is not a global single vector for all image pixels but a grid signal conditioned to image spatial information. More importantly, the gating signal for each skip connection aggregates information from multiple imaging scales, as shown in Figure 1, which increases the grid-resolution of the query signal and achieve better performance. Lastly, we would like to note that AG parameters can be trained with the standard back-propagation updates without a need for sampling based update methods used in hard-attention [21].
|
| 60 |
+
|
| 61 |
+
Figure 3(a): From left to right (a-e, f-j): Axial and sagittal views of a 3D abdominal CT scan, attention coefficients, feature activations of a skip connection before and after gating. Similarly, (k-n) visualise the gating on a coarse scale skip connection. The filtered feature activations (d-e, i-j) are collected from multiple AGs, where a subset of organs is selected by each gate. Activations shown in (d-e, i-j) consistently correspond to specific structures across different scans.
|
| 62 |
+
|
| 63 |
+
<!-- image -->
|
| 64 |
+
|
| 65 |
+
Figure 3(b): The ground-truth pancreas segmentation (a) is highlighted in blue (b). Similarly, U-Net model prediction (c) and the predictions obtained with Attention U-Net (d) are shown. The missed dense predictions by U-Net are highlighted with red arrows.
|
| 66 |
+
|
| 67 |
+
<!-- image -->
|
| 68 |
+
|
| 69 |
+
Attention Gates in U-Net Model: The proposed AGs are incorporated into the standard U-Net architecture to highlight salient features that are passed through the skip connections, see Figure 1. Information extracted from coarse scale is used in gating to disambiguate irrelevant and noisy responses in skip connections. This is performed right before the concatenation operation to merge only relevant activations. Additionally, AGs filter the neuron activations during the forward pass as well as during the backward pass. Gradients originating from background regions are down weighted during the backward pass. This allows model parameters in shallower layers to be updated mostly based on spatial regions that are relevant to a given task. The update rule for convolution parameters in layer l -1 can be formulated as follows:
|
| 70 |
+
|
| 71 |
+
<!-- formula-not-decoded -->
|
| 72 |
+
|
| 73 |
+
The first gradient term on the right-hand side is scaled with α l i . In case of multi-dimensional AGs, α l i corresponds to a vector at each grid scale. In each sub-AG, complementary information is extracted and fused to define the output of skip connection. To reduce the number of trainable parameters and computational complexity of AGs, the linear transformations are performed without any spatial support (1x1x1 convolutions) and input feature-maps are downsampled to the resolution of gating signal, similar to non-local blocks [33]. The corresponding linear transformations decouple the feature-maps and map them to lower dimensional space for the gating operation. As suggested in [11], low-level feature-maps, i.e. the first skip connections, are not used in the gating function since they do not represent the input data in a high dimensional space. We use deep-supervision [16] to force the intermediate feature-maps to be semantically discriminative at each image scale. This helps to ensure that attention units, at different scales, have an ability to influence the responses to a large range of image foreground content. We therefore prevent dense predictions from being reconstructed from small subsets of skip connections.
|
| 74 |
+
|
| 75 |
+
## 3 Experiments and Results
|
| 76 |
+
|
| 77 |
+
The proposed AG model is modular and independent of application type; as such it can be easily adapted for classification and regression tasks. To demonstrate its applicability to image segmentation, we evaluate the Attention U-Net model on a challenging abdominal CT multi-label segmentation problem. In particular, pancreas boundary delineation is a difficult task due to shape-variability and poor tissue contrast. Our model is compared against the standard 3D U-Net in terms of segmentation performance, model capacity, computation time, and memory requirements.
|
| 78 |
+
|
| 79 |
+
Figure 4: The figure shows the attention coefficients ( α l s 2 , α l s 3 ) across different training epochs ( 3 , 6 , 10 , 60 , 150 ). The images are extracted from sagittal and axial planes of a 3D abdominal CT scan from the testing dataset. The model gradually learns to focus on the pancreas, kidney, and spleen.
|
| 80 |
+
|
| 81 |
+
<!-- image -->
|
| 82 |
+
|
| 83 |
+
Evaluation Datasets: For the experiments, two different CT abdominal datasets are used: (I) 150 abdominal 3D CT scans acquired from patients diagnosed with gastric cancer ( CT -150 ). In all images, the pancreas, liver, and spleen boundaries were semi-automatically delineated by three trained researchers and manually verified by a clinician. The same dataset is used in [27] to benchmark the U-Net model in pancreas segmentation. (II) The second dataset 1 ( CT -82 ) consists of 82 contrast enhanced 3D CT scans with pancreas manual annotations performed slice-by-slice. This dataset (NIH-TCIA) [25] is publicly available and commonly used to benchmark CT pancreas segmentation frameworks. The images from both datasets are downsampled to isotropic 2 . 00 mmresolution due to the large image size and hardware memory limitations.
|
| 84 |
+
|
| 85 |
+
Implementation Details: In contrast to the state-of-the-art CNN segmentation frameworks [4, 26], we propose a 3D-model to capture sufficient semantic context. Gradient updates are computed using small batch sizes of 2 to 4 samples. For larger networks, gradient averaging is used over multiple forward and backward passes. All models are trained using the Adam optimiser [15], batch-normalisation, deep-supervision [16], and standard data-augmentation techniques (affine transformations, axial flips, random crops). Intensity values are linearly scaled to obtain a normal distribution N (0 , 1) . The models are trained using the Sorensen-Dice loss [20] defined over all semantic classes, which is experimentally shown to be less sensitive to class imbalance. Gating parameters are initialised so that attention gates pass through feature vectors at all spatial locations. Moreover, we do not require multiple training stages as in hard-attention based approaches therefore simplifying the training procedure. Our implementation using PyTorch is publicly available 2 .
|
| 86 |
+
|
| 87 |
+
Attention Map Analysis: The attention coefficients obtained from test images are visualised with respect to training epochs (see Figure 4). We commonly observe that AGs initially have a uniform distribution and pass features at all locations. This is gradually updated and localised towards the targeted organ boundaries. Additionally, at coarser scales AGs provide a rough outline of organs which are gradually refined at finer resolutions. Moreover, by training multiple AGs at each image scale, we observe that each AG learns to focus on a particular subset of organs.
|
| 88 |
+
|
| 89 |
+
Segmentation Experiments : The proposed Attention U-Net model is benchmarked against the standard U-Net on multi-class abdominal CT segmentation. We use CT -150 dataset for both training ( 120 ) and testing ( 30 ). The corresponding Dice scores (DSC) and surface distances (S2S) are given in Table 1. The results on pancreas predictions demonstrate that attention gates (AGs) increase recall values ( p = . 005 ) by improving the model's expression power as it relies on AGs to localise foreground pixels. The difference between predictions obtained with these two models are qualitatively compared in Figure 3b. In the second experiment, the same models are trained with fewer training images ( 30 ) to show that the performance improvement is consistent and significant for different sizes of training data ( p = . 01 ). For both approaches, we observe a performance drop on spleen DSC as the training size is reduced. The drop is less significant with the proposed framework. For kidney segmentation, the models achieve similar accuracy since the tissue contrast is higher.
|
| 90 |
+
|
| 91 |
+
[1 https://wiki.cancerimagingarchive.net/display/Public/Pancreas-CT](https://wiki.cancerimagingarchive.net/display/Public/Pancreas-CT)
|
| 92 |
+
|
| 93 |
+
[2 https://github.com/ozan-oktay/Attention-Gated-Networks](https://github.com/ozan-oktay/Attention-Gated-Networks)
|
| 94 |
+
|
| 95 |
+
Table 1: Multi-class CT abdominal segmentation results obtained on the CT -150 dataset: The results are reported in terms of Dice score (DSC) and mesh surface to surface distances (S2S). These distances are reported only for the pancreas segmentations. The proposed Attention U-Net model is benchmarked against the standard U-Net model for different training and testing splits. Inference time (forward pass) of the models are computed for input tensor of size 160 × 160 × 96 . Statistically significant results are highlighted in bold font.
|
| 96 |
+
|
| 97 |
+
| Method (Train/Test Split) U-Net (120/30) Att U-Net (120/30) U-Net (30/120) Att U-Net (30/120) Pancreas DSC 0.814 ± 0.116 0.840 ± 0.087 0.741 ± 0.137 0.767 ± 0.132 Pancreas Precision 0.848 ± 0.110 0.849 ± 0.098 0.789 ± 0.176 0.794 ± 0.150 Pancreas Recall 0.806 ± 0.126 0.841 ± 0.092 0.743 ± 0.179 0.762 ± 0.145 Pancreas S2S Dist (mm) 2.358 ± 1.464 1.920 ± 1.284 3.765 ± 3.452 3.507 ± 3.814 Spleen DSC 0.962 ± 0.013 0.965 ± 0.013 0.935 ± 0.095 0.943 ± 0.092 Kidney DSC 0.963 ± 0.013 0.964 ± 0.016 0.951 ± 0.019 0.954 ± 0.021 Number of Params 5.88 M 6.40 M 5.88 M 6.40 M Inference Time 0.167 s 0.179 s 0.167 s 0.179 s |
|
| 98 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 99 |
+
|
| 100 |
+
Table 2: Segmentation experiments on CT -150 dataset are repeated with higher capacity U-Net models to demonstrate the efficieny of the attention models with similar or less network capacity. The additional filters in the U-Net model are distributed uniformly across all the layers.
|
| 101 |
+
|
| 102 |
+
| Method Panc. DSC Panc. Precision Panc. Recall S2S Dist (mm) # of Pars Run Time U-Net (120/30) 0.821 ± .119 0.849 ± .111 0.814 ± .125 2.383 ± 1.918 6.44 M 0.191 s U-Net (120/30) 0.825 ± .104 0.861 ± .082 0.807 ± .121 2.202 ± 1.144 10.40 M 0.222 s |
|
| 103 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 104 |
+
|
| 105 |
+
Table 3: Pancreas segmentation results obtained on the TCIA Pancreas-CT Dataset [25]. The dataset contains in total 82 scans which are split into training (61) and testing (21) sets. The corresponding results are obtained before (BFT) and after fine tuning (AFT) and also training the models from scratch (SCR). Statistically significant results are highlighted in bold font.
|
| 106 |
+
|
| 107 |
+
| Method Dice Score Precision Recall S2S Dist (mm) BFT U-Net [24] 0.690 ± 0.132 0.680 ± 0.109 0.733 ± 0.190 6.389 ± 3.900 Attention U-Net 0.712 ± 0.110 0.693 ± 0.115 0.751 ± 0.149 5.251 ± 2.551 AFT U-Net [24] 0.820 ± 0.043 0.824 ± 0.070 0.828 ± 0.064 2.464 ± 0.529 Attention U-Net 0.831 ± 0.038 0.825 ± 0.073 0.840 ± 0.053 2.305 ± 0.568 SCR U-Net [24] 0.815 ± 0.068 0.815 ± 0.105 0.826 ± 0.062 2.576 ± 1.180 Attention U-Net 0.821 ± 0.057 0.815 ± 0.093 0.835 ± 0.057 2.333 ± 0.856 |
|
| 108 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 109 |
+
|
| 110 |
+
In Table 1, we also report the number of trainable parameters for both models. We observe that by adding 8% extra capacity to the standard U-Net, the performance can be improved by 2-3% in terms of DSC. For a fair comparison, we also train higher capacity U-Net models and compare against the proposed model with smaller network size. The results shown in Table 2 demonstrate that the addition of AGs contributes more than simply increasing model capacity (uniformly) across all layers of the network ( p = . 007 ). Therefore, additional capacity should be used for AGs to localise tissues, in cases when AGs are used to reduce the redundancy of training multiple, individual models.
|
| 111 |
+
|
| 112 |
+
Comparison to State-of-the-Art: The proposed architecture is evaluated on the public TCIA CT Pancreas benchmark to compare its performance with state-of-the-art methods. Initially, the models trained on CT -150 dataset are directly applied to CT -82 dataset to observe the applicability of the two models on different datasets. The corresponding results (BFT) are given in Table 3. U-Net model outperforms traditional atlas techniques [34] although it was trained on a disjoint dataset. Moreover, the attention model performs consistently better in pancreas segmentation across different datasets. These models are later fine-tuned (AFT) on a subset of TCIA dataset ( 61 train, 21 test). The output nodes corresponding to spleen and kidney are excluded from the output softmax computation, and the gradient updates are computed only for the background and pancreas labels. The results in Table 3 and
|
| 113 |
+
|
| 114 |
+
Table 4: State-of-the-art CT pancreas segmentation methods that are based on single and multiple CNN models. The listed segmentation frameworks are evaluated on the same public benchmark ( CT -82 ) using different number of training and testing images. Similarly, the FCN approach proposed in [27] is benchmarked on CT -150 although it is trained on an external dataset (Ext).
|
| 115 |
+
|
| 116 |
+
| Method Dataset Pancreas DSC Train/Test # Folds Hierarchical 3D FCN [27] CT - 150 82 . 2 ± 10 . 2 Ext/ 150 - Dense-Dilated FCN [6] CT - 82 &Synapse 3 66 . 0 ± 10 . 0 63 / 9 5-CV 2D U-Net [8] CT - 82 75 . 7 ± 9 . 0 66/16 5-CV Holistically Nested 2D FCN Stage-1[26] CT - 82 76 . 8 ± 11 . 1 62/20 4-CV Holistically Nested 2D FCN Stage-2[26] CT - 82 81 . 2 ± 7 . 3 62/20 4-CV 2D FCN [4] CT - 82 80 . 3 ± 9 . 0 62/20 4-CV 2D FCN + Recurrent Network [4] CT - 82 82 . 3 ± 6 . 7 62/20 4-CV Single Model 2D FCN [38] CT - 82 75 . 7 ± 10 . 5 62/20 4-CV Multi-Model 2D FCN [38] CT - 82 82 . 2 ± 5 . 7 62/20 4-CV |
|
| 117 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 118 |
+
|
| 119 |
+
4 show improved performance compared to concatenated multi-model CNN approaches [4, 26, 38] due to additional training data and richer semantic information (e.g. spleen labels). Additionally, we trained the two models from scratch (SCR) with 61 training images randomly selected from the CT -82 dataset. Similar to the results on CT -150 dataset, AGs improve the segmentation accuracy and lower the surface distances ( p = . 03 ) due to increased recall rate of pancreas pixels ( p = . 09 ).
|
| 120 |
+
|
| 121 |
+
Results from state-of-the-art CT pancreas segmentation models are summarised in Table 4 for comparison purposes. Since the models are trained on the same training dataset, this comparison gives an insight on how the attention model compares to the relevant literature. It is important to note that, post-processing (e.g. conditional random field) is not utilised in our framework as the experiments mainly focus on quantification of performance improvement brought by AGs in an isolated setting. Similarly, residual and dense connections can be used as in [6] in conjunction with AGs to improve the segmentation results. In that regard, our 3D Attention U-Net model performs similar to the state-of-the-art, despite the input images are downsampled to lower resolution. More importantly, our approach significantly improves the results compared to single-model based segmentation frameworks (see Table 4). We do not require multiple CNN models to localise and segment object boundaries. Lastly, we performed 5 -fold cross-validation on the CT -82 dataset using the Attention U-Net for a better comparison, which achieved 81 . 48 ± 6 . 23 DSC for pancreas labels.
|
| 122 |
+
|
| 123 |
+
## 4 Discussion and Conclusion
|
| 124 |
+
|
| 125 |
+
In this paper, we presented a novel attention gate model applied to medical image segmentation. Our approach eliminates the necessity of applying an external object localisation model. The proposed approach is generic and modular as such it can be easily applied to image classification and regression problems as in the examples of natural image analysis and machine translation. Experimental results demonstrate that the proposed AGs are highly beneficial for tissue/organ identification and localisation. This is particularly true for variable small size organs such as the pancreas, and similar behaviour is expected for global classification tasks.
|
| 126 |
+
|
| 127 |
+
Training behaviour of the AGs can benefit from transfer learning and multi-stage training schemes. For instance, pre-trained U-Net weights can be used to initialise the attention network, and gates can be trained accordingly in the fine-tuning stage. Similarly, there is a vast body of literature in machine learning exploring different gating architectures. For example, highway networks [7] make use of residual connections around the gate block to allow better gradient backpropagation and slightly softer attention mechanisms. Although our experiments with residual connections have not provided any significant performance improvement, future research will focus on this aspect to obtain a better training behaviour. Lastly, we note that with the advent of improved GPU computation power and memory, larger capacity 3D models can be trained with larger batch sizes without the need for image downsampling. In this way, we would not need to utilise ad-hoc post-processing techniques to further improve the state-of-the-art results. Similarly, the performance of Attention U-Net can be further enhanced by utilising fine resolution input batches without additional heuristics. Lastly, we would like to thank to Salim Arslan and Dan Busbridge for their helpful comments on this work.
|
| 128 |
+
|
| 129 |
+
## References
|
| 130 |
+
|
| 131 |
+
- [1] Anderson, P., He, X., Buehler, C., Teney, D., Johnson, M., Gould, S., Zhang, L.: Bottom-up and top-down attention for image captioning and vqa. arXiv preprint arXiv:1707.07998 (2017)
|
| 132 |
+
- [2] Bahdanau, D., Cho, K., Bengio, Y.: Neural machine translation by jointly learning to align and translate. arXiv preprint arXiv:1409.0473 (2014)
|
| 133 |
+
- [3] Bai, W., Sinclair, M., Tarroni, G., Oktay, O., Rajchl, M., Vaillant, G., Lee, A.M., Aung, N., Lukaschuk, E., Sanghvi, M.M., et al.: Human-level CMR image analysis with deep fully convolutional networks. arXiv preprint arXiv:1710.09289 (2017)
|
| 134 |
+
- [4] Cai, J., Lu, L., Xie, Y ., Xing, F., Yang, L.: Improving deep pancreas segmentation in CT and MRI images via recurrent neural contextual learning and direct loss function. In: MICCAI (2017)
|
| 135 |
+
- [5] Cerrolaza, J.J., Summers, R.M., Linguraru, M.G.: Soft multi-organ shape models via generalized PCA: A general framework. In: MICCAI. pp. 219-228. Springer (2016)
|
| 136 |
+
- [6] Gibson, E., Giganti, F., Hu, Y ., Bonmati, E., Bandula, S., Gurusamy, K., Davidson, B.R., Pereira, S.P., Clarkson, M.J., Barratt, D.C.: Towards image-guided pancreas and biliary endoscopy: Automatic multi-organ segmentation on abdominal CT with dense dilated networks. In: MICCAI. pp. 728-736. Springer (2017)
|
| 137 |
+
- [7] Greff, K., Srivastava, R.K., Schmidhuber, J.: Highway and residual networks learn unrolled iterative estimation. arXiv preprint arXiv:1612.07771 (2016)
|
| 138 |
+
- [8] Heinrich, M.P., Blendowski, M., Oktay, O.: TernaryNet: Faster deep model inference without GPUs for medical 3D segmentation using sparse and binary convolutions. arXiv preprint arXiv:1801.09449 (2018)
|
| 139 |
+
- [9] Heinrich, M.P., Oktay, O.: BRIEFnet: Deep pancreas segmentation using binary sparse convolutions. In: MICCAI. pp. 329-337. Springer (2017)
|
| 140 |
+
- [10] Hu, J., Shen, L., Sun, G.: Squeeze-and-excitation networks. arXiv:1709.01507 (2017)
|
| 141 |
+
- [11] Jetley, S., Lord, N.A., Lee, N., Torr, P.: Learn to pay attention. In: International Conference on Learning Representations (2018), https://openreview.net/forum?id=HyzbhfWRW
|
| 142 |
+
- [12] Kamnitsas, K., Bai, W., Ferrante, E., McDonagh, S., Sinclair, M., Pawlowski, N., Rajchl, M., Lee, M., Kainz, B., Rueckert, D., Glocker, B.: Ensembles of multiple models and architectures for robust brain tumour segmentation. In: Brainlesion: Glioma, Multiple Sclerosis, Stroke and Traumatic Brain Injuries. pp. 450-462. Cham (2018)
|
| 143 |
+
- [13] Kamnitsas, K., Ledig, C., Newcombe, V.F., Simpson, J.P., Kane, A.D., Menon, D.K., Rueckert, D., Glocker, B.: Efficient multi-scale 3D CNN with fully connected CRF for accurate brain lesion segmentation. Medical image analysis 36, 61-78 (2017)
|
| 144 |
+
- [14] Khened, M., Kollerathu, V.A., Krishnamurthi, G.: Fully convolutional multi-scale residual densenets for cardiac segmentation and automated cardiac diagnosis using ensemble of classifiers. arXiv preprint arXiv:1801.05173 (2018)
|
| 145 |
+
- [15] Kingma, D.P., Ba, J.: Adam: A method for stochastic optimization. arXiv preprint arXiv:1412.6980 (2014)
|
| 146 |
+
- [16] Lee, C.Y., Xie, S., Gallagher, P., Zhang, Z., Tu, Z.: Deeply-supervised nets. In: Artificial Intelligence and Statistics. pp. 562-570 (2015)
|
| 147 |
+
- [17] Liao, F., Liang, M., Li, Z., Hu, X., Song, S.: Evaluate the malignancy of pulmonary nodules using the 3D deep leaky noisy-or network. arXiv preprint arXiv:1711.08324 (2017)
|
| 148 |
+
- [18] Long, J., Shelhamer, E., Darrell, T.: Fully convolutional networks for semantic segmentation. In: IEEE CVPR. pp. 3431-3440 (2015)
|
| 149 |
+
|
| 150 |
+
- [19] Luong, M.T., Pham, H., Manning, C.D.: Effective approaches to attention-based neural machine translation. arXiv preprint arXiv:1508.04025 (2015)
|
| 151 |
+
- [20] Milletari, F., Navab, N., Ahmadi, S.A.: V-net: Fully convolutional neural networks for volumetric medical image segmentation. In: 3D Vision. pp. 565-571. IEEE (2016)
|
| 152 |
+
- [21] Mnih, V., Heess, N., Graves, A., et al.: Recurrent models of visual attention. In: Advances in neural information processing systems. pp. 2204-2212 (2014)
|
| 153 |
+
- [22] Oda, M., Shimizu, N., Roth, H.R., Karasawa, K., Kitasaka, T., Misawa, K., Fujiwara, M., Rueckert, D., Mori, K.: 3D FCN feature driven regression forest-based pancreas localization and segmentation. In: DLMI, pp. 222-230. Springer (2017)
|
| 154 |
+
- [23] Payer, C., Štern, D., Bischof, H., Urschler, M.: Multi-label whole heart segmentation using CNNs and anatomical label configurations. In: STACOM. pp. 190-198. Springer (2017)
|
| 155 |
+
- [24] Ronneberger, O., Fischer, P., Brox, T.: U-net: Convolutional networks for biomedical image segmentation. In: MICCAI. pp. 234-241. Springer (2015)
|
| 156 |
+
- [25] Roth, H., Farag, A., Turkbey, E.B., Lu, L., Liu, J., Summers, R.M.: Data from Pancreas-CT. The Cancer Imaging Archive (2016), http://doi.org/10.7937/K9/TCIA.2016.tNB1kqBU
|
| 157 |
+
- [26] Roth, H.R., Lu, L., Lay, N., Harrison, A.P., Farag, A., Sohn, A., Summers, R.M.: Spatial aggregation of holistically-nested convolutional neural networks for automated pancreas localization and segmentation. Medical Image Analysis 45, 94 - 107 (2018)
|
| 158 |
+
- [27] Roth, H.R., Oda, H., Hayashi, Y., Oda, M., Shimizu, N., Fujiwara, M., Misawa, K., Mori, K.: Hierarchical 3D fully convolutional networks for multi-organ segmentation. arXiv preprint arXiv:1704.06382 (2017)
|
| 159 |
+
- [28] Saito, A., Nawano, S., Shimizu, A.: Joint optimization of segmentation and shape prior from level-set-based statistical shape model, and its application to the automated segmentation of abdominal organs. Medical image analysis 28, 46-65 (2016)
|
| 160 |
+
- [29] Shen, T., Zhou, T., Long, G., Jiang, J., Pan, S., Zhang, C.: Disan: Directional self-attention network for rnn/cnn-free language understanding. arXiv preprint arXiv:1709.04696 (2017)
|
| 161 |
+
- [30] Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A.N., Kaiser, Ł., Polosukhin, I.: Attention is all you need. In: NIPS. pp. 6000-6010 (2017)
|
| 162 |
+
- [31] Veliˇ ckovi´ c, P., Cucurull, G., Casanova, A., Romero, A., Liò, P., Bengio, Y.: Graph attention networks. arXiv preprint arXiv:1710.10903 (2017)
|
| 163 |
+
- [32] Wang, F., Jiang, M., Qian, C., Yang, S., Li, C., Zhang, H., Wang, X., Tang, X.: Residual attention network for image classification. In: IEEE CVPR. pp. 3156-3164 (2017)
|
| 164 |
+
- [33] Wang, X., Girshick, R., Gupta, A., He, K.: Non-local neural networks. arXiv preprint arXiv:1711.07971 (2017)
|
| 165 |
+
- [34] Wolz, R., Chu, C., Misawa, K., Fujiwara, M., Mori, K., Rueckert, D.: Automated abdominal multi-organ segmentation with subject-specific atlas generation. IEEE TMI 32(9) (2013)
|
| 166 |
+
- [35] Xie, S., Tu, Z.: Holistically-nested edge detection. In: Proceedings of the IEEE international conference on computer vision. pp. 1395-1403 (2015)
|
| 167 |
+
- [36] Ypsilantis, P.P., Montana, G.: Learning what to look in chest X-rays with a recurrent visual attention model. arXiv preprint arXiv:1701.06452 (2017)
|
| 168 |
+
- [37] Yu, Q., Xie, L., Wang, Y., Zhou, Y., Fishman, E.K., Yuille, A.L.: Recurrent saliency transformation network: Incorporating multi-stage visual cues for small organ segmentation. arXiv preprint arXiv:1709.04518 (2017)
|
| 169 |
+
- [38] Zhou, Y., Xie, L., Shen, W., Wang, Y., Fishman, E.K., Yuille, A.L.: A fixed-point model for pancreas segmentation in abdominal CT scans. In: MICCAI. pp. 693-701. Springer (2017)
|
| 170 |
+
- [39] Zografos, V., Valentinitsch, A., Rempfler, M., Tombari, F., Menze, B.: Hierarchical multi-organ segmentation without registration in 3D abdominal CT images. In: International MICCAI Workshop on Medical Computer Vision. pp. 37-46. Springer (2015)
|
text-versions/attention-markdown/1805.03294_Improved training of endtoend attention .md
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1805.03294 Improved Training Of Endtoend Attention
|
| 2 |
+
|
| 3 |
+
## Improved training of end-to-end attention models for speech recognition
|
| 4 |
+
|
| 5 |
+
Albert Zeyer 1 , 2 , 3 , Kazuki Irie 1 , Ralf Schl¨ uter 1 , Hermann Ney 1 , 2
|
| 6 |
+
|
| 7 |
+
1
|
| 8 |
+
|
| 9 |
+
Human Language Technology and Pattern Recognition, Computer Science Department,
|
| 10 |
+
|
| 11 |
+
RWTH Aachen University, 52062 Aachen, Germany,
|
| 12 |
+
|
| 13 |
+
[2 AppTek, USA, http://www.apptek.com/ ,](http://www.apptek.com/)
|
| 14 |
+
|
| 15 |
+
[3 NNAISENSE, Switzerland, https://nnaisense.com/](https://nnaisense.com/)
|
| 16 |
+
|
| 17 |
+
{ zeyer, irie, schlueter, ney } @cs.rwth-aachen.de
|
| 18 |
+
|
| 19 |
+
## Abstract
|
| 20 |
+
|
| 21 |
+
Sequence-to-sequence attention-based models on subword units allow simple open-vocabulary end-to-end speech recognition. In this work, we show that such models can achieve competitive results on the Switchboard 300h and LibriSpeech 1000h tasks. In particular, we report the state-of-the-art word error rates (WER) of 3.54% on the dev-clean and 3.82% on the testclean evaluation subsets of LibriSpeech. We introduce a new pretraining scheme by starting with a high time reduction factor and lowering it during training, which is crucial both for convergence and final performance. In some experiments, we also use an auxiliary CTC loss function to help the convergence. In addition, we train long short-term memory (LSTM) language models on subword units. By shallow fusion, we report up to 27% relative improvements in WER over the attention baseline without a language model.
|
| 22 |
+
|
| 23 |
+
Index Terms : attention, end-to-end, speech recognition
|
| 24 |
+
|
| 25 |
+
## 1. Introduction
|
| 26 |
+
|
| 27 |
+
Conventional speech recognition systems [1] with neural network (NN) based acoustic models using the hybrid hidden Markov models (HMM) / NN approach [2, 3] usually operate on the phone level, given a phonetic pronunciation lexicon (from phones to words). They require a pretraining scheme with HMM and Gaussian mixture models (GMM) as emission probabilities to bootstrap good alignments of the HMM states. Context-independent phones are used initially because contextdependent phones need a good clustering, which is usually created on good existing alignments (via a Classification And Regression Tree (CART) clustering [4]). This boot-strapping process is iterated a few times. Then a hybrid HMM / NN is trained with frame-wise cross entropy. Recognition with such a model requires a sophisticated beam search decoder. Handling out-ofvocabulary words is also not straightforward and increases the complexity. There was certain work to remove the GMM dependency in the pretraining [5], or to be able to train without an existing alignment [6-8], or to avoid the lexicon [9], which simplifies the pretraining procedure but still is not end-to-end.
|
| 28 |
+
|
| 29 |
+
An end-to-end model in speech recognition generally denotes a simple single model which can be trained from scratch, and usually directly operates on words, sub-words or characters/graphemes. This removes the need for a pronunciation lexicon and the whole explicit modeling of phones, and it greatly simplifies the decoding.
|
| 30 |
+
|
| 31 |
+
Connectionist temporal classification (CTC) [10] has been often used as an end-to-end model for speech recognition, often on characters/graphemes [11-16] or on sub-words [17] but also directly on words [18, 19].
|
| 32 |
+
|
| 33 |
+
The encoder-decoder framework with attention has become the standard approach for machine translation [20-22] and many other domains such as images [23]. Recent investigations have shown promising results by applying the same approach for speech recognition [24-28]. In this work, we also investigate techniques to improve recurrent encoder-attentiondecoder based systems for speech recognition. We use long short-term memory (LSTM) neural networks [29] for the encoder and the decoder. Our model is similar to the architecture used in machine translation [30], except of encoder time reduction. This generality of the model and the simplicity is its strength. Although a valid argument against this model for speech recognition is that it is in fact too powerful because it does not require monotonicity in its implicit alignments. There are attempts to restrict the attention to become monotonic in various ways [31-38]. In this work, our models are without these modifications and extensions.
|
| 34 |
+
|
| 35 |
+
Recently, alternative models for end-to-end modeling were also suggested, such as inverted HMMs [39], the recurrent transducer [40-42], or the recurrent neural aligner [43]. In many ways, these can all be interpreted in the same encoderdecoder-attention framework, but these approaches often use some variant of hard latent monotonic attention instead of soft attention.
|
| 36 |
+
|
| 37 |
+
Our models operate on subword units which are created via byte-pair encoding (BPE) [44]. We introduce a pretraining scheme applied on the encoder, which grows the encoder in layer depth, as well as decreases the initial high encoder time reduction factor. To the best of our knowledge, we are the first to apply pretraining for encoder-attention-decoder models. We use RETURNN [30,45] based on TensorFlow [46] for its computation. We have implemented our own flexible and efficient beam search decoder and efficient LSTM kernels in native CUDA. In addition, we train subword-level LSTM language models [47], which we integrate in the beam search by shallow fusion [48]. The source code is fully open 1 , as well as all the setups of the experiments in this paper 2 . Wereport competitive results on the 300h-Switchboard and LibriSpeech [49]. In particular on Librispeech, our system achieves WERs of 3.54% on the dev-clean and 3.82% on the test-clean evaluation subsets, which are the best results obtained on this task to the best of our knowledge.
|
| 38 |
+
|
| 39 |
+
## 2. Pretraining
|
| 40 |
+
|
| 41 |
+
Compared to machine translation, the input sequences are much longer in speech recognition, relatively to the output sequence (e.g. with BPE 10K subword units, and audio feature frames every 10ms, more than 30 times longer on Switchboard on average). However, as the original input is continuous, some sort of downscaling in the time dimension works, such as concatenation in the feature dimension of consecutive time-frames
|
| 42 |
+
|
| 43 |
+
[1 https://github.com/rwth-i6/returnn](https://github.com/rwth-i6/returnn)
|
| 44 |
+
|
| 45 |
+
[2 https://github.com/rwth-i6/returnn-experiments/tree/master/2018-asr-attention](https://github.com/rwth-i6/returnn-experiments/tree/master/2018-asr-attention)
|
| 46 |
+
|
| 47 |
+
[7,24,42,50]. We use max-pooling in the time-dimension which is simpler. The time reduction can be done directly on the features or alternatively at multiple steps inside the encoder, e.g. after every encoder layer [24]. This is also what we do. This allows the encoder to better compress any necessary information.
|
| 48 |
+
|
| 49 |
+
We observed that a high time reduction factor makes the training much simpler. In fact, without careful tuning, usually the model will not converge without a high time reduction factor (16 or 32), as it was also observed in the literature [24]. However, we also observed that a low time reduction factor (e.g. 8) can perform better after all, when pretrained with a high time reduction factor.
|
| 50 |
+
|
| 51 |
+
Also, it has been shown that deep LSTM models can benefit from layer-wise pretraining, by starting with 1 or 2 layers and adding more and more layers [1]. We apply the same pretraining.
|
| 52 |
+
|
| 53 |
+
To improve the convergence further, we disable label smoothing during pretraining and only enable it after pretraining. Also, we disable dropout during the first few pretraining epochs in the encoder.
|
| 54 |
+
|
| 55 |
+
## 3. Model
|
| 56 |
+
|
| 57 |
+
Weuse a deep bidirectional LSTM encoder network, and LSTM decoder network. After every layer in the encoder, we optionally do max-pooling in the time dimension to reduce the encoder length. I.e. for the input sequence x T 1 , we end up with the encoder state
|
| 58 |
+
|
| 59 |
+
<!-- formula-not-decoded -->
|
| 60 |
+
|
| 61 |
+
where T ′ = red · T for the time reduction factor red , and #enc is the number of encoder layers, with #enc ≥ 2 . We use the MLPattention [20,21,31,32,51]. Our model closely follows the machine translation model presented by Bahar et al. [51] and Bahdanau et al. [20] and we use a variant of attention weight / fertility feedback [52], which is inverse in our case, to use a multiplication instead of a division, for better numerical stability. More specifically, the attention energies e i,t ∈ R for encoder time-step t and decoder step i are defined as
|
| 62 |
+
|
| 63 |
+
<!-- formula-not-decoded -->
|
| 64 |
+
|
| 65 |
+
where v is a trainable vector, W a trainable matrix, s i the current decoder state, h t the encoder state, and β i,t is the attention weight feedback, defined as
|
| 66 |
+
|
| 67 |
+
<!-- formula-not-decoded -->
|
| 68 |
+
|
| 69 |
+
where v β is a trainable vector. Then the attention weights are defined as
|
| 70 |
+
|
| 71 |
+
<!-- formula-not-decoded -->
|
| 72 |
+
|
| 73 |
+
and the attention context vector is given as
|
| 74 |
+
|
| 75 |
+
<!-- formula-not-decoded -->
|
| 76 |
+
|
| 77 |
+
The decoder state is recurrent function implemented as
|
| 78 |
+
|
| 79 |
+
<!-- formula-not-decoded -->
|
| 80 |
+
|
| 81 |
+
and the final prediction probability for the output symbol y i is given as
|
| 82 |
+
|
| 83 |
+
<!-- formula-not-decoded -->
|
| 84 |
+
|
| 85 |
+
In our case we use MLP readout = linear ◦ maxout ◦ linear .
|
| 86 |
+
|
| 87 |
+
## 4. Sub-word units
|
| 88 |
+
|
| 89 |
+
Characters/graphemes are probably the most generic and simple output units for generating texts but it has been shown that sub-word units can perform better [26] and they can be just as generic since the characters can be included in the set of subword units. Using words as output units is also possible but it does not allow to recognize out-of-vocabulary words and it requires a large softmax output and thus is computational expensive. An inhomogeneous length distribution as well as an imbalance in the label occurence can also make training harder.
|
| 90 |
+
|
| 91 |
+
In all the experiments, we use byte-pair encoding (BPE) [44] to create subword units, which are the output targets of the decoder. The beam search decoding will go over these BPE units, and then select the best hypothesis. Therefore, our system is open-vocabulary. At the end of decoding, the BPE units are merged into words in order to obtain the best hypothesis on word level. In addition, we add the special tokens from the transcriptions which denote noise, vocalized-noise and laughter in our BPE vocabulary set. Our recognizer can also potentially recognize these special events.
|
| 92 |
+
|
| 93 |
+
## 5. Language model combination
|
| 94 |
+
|
| 95 |
+
We also improve the recognition accuracy of our recognizer using external language models. We train LSTM language models [47] on the same BPE vocabulary set as the end-to-end model, using RETURNN with TensorFlow. For Switchboard, the training set of 27M words concatenating Switchboard and Fisher parts of transcriptions was used. For LibriSpeech, we use the 800M-word dataset officially available 3 for training language models. It can be noted that in the case of Switchboard, there is some overlap between the training data for language models and the transcription used to train the end-to-end model: 3M out of 27M words are used to train the end-to-end system. While for the LispriSpeech, 800M-word data is fully external to the end-to-end models. Our experiments show that this difference in amount of external data directly affects the performance improvements by the use of external language model. For both tasks, we use a LSTM LM with one input projection layer size of 512 dimension and two LSTM layers with 2048 nodes. We apply dropout at the input of all hidden layers with the rate of 0.2. The standard stochastic gradient descent with global gradient clipping is used for optimization to train all LSTM LMs.
|
| 96 |
+
|
| 97 |
+
We integrate the external language model in the beam search by shallow fusion [48]. The weight for the language model has been optimized by grid search on the development set WER. We found 0.23 and 0.36 to be optimal respectively for Switchboard and LibriSpeech (the weight on the attention model is 1).
|
| 98 |
+
|
| 99 |
+
For LibriSpeech, we also train Kneser-Ney smoothed n -gram count based language models [53] on the same BPE vocabulary set using SRILM toolkit [54]. The comparison of perplexities can be found in Table 1. We also report WERs using the 4-gram count model by shallow fusion with a weight of 0.01, for comparison to the performance of LSTM LM.
|
| 100 |
+
|
| 101 |
+
Table 1: Perplexities (PPL) on the concatenation of dev-clean and dev-other sets of LibriSpeech. All models have the same vocabulary of 10K BPE.
|
| 102 |
+
|
| 103 |
+
| LM 3-gram 4-gram 5-gram LSTM PPL 104.6 88.2 85.1 65.9 |
|
| 104 |
+
|----------------------------------------------------------------|
|
| 105 |
+
|
| 106 |
+
## 6. Experiments
|
| 107 |
+
|
| 108 |
+
All attention models and neural network language models were trained and decoded with RETURNN. For both Switchboard and LibriSpeech, we first used the BPE vocabulary of 10K subword units to tune the hyperparameters of the model, then trained the models with 1K and 5K BPE units. We found 1K and 10K to be optimal for Switchboard and LibriSpeech respectively. We use label smoothing [55], dropout [56], Adam [57], learning rate warmup [26], and automatic learning rate scheduling according to a cross-validation set ('Newbob') [1].
|
| 109 |
+
|
| 110 |
+
## 6.1. Pretraining
|
| 111 |
+
|
| 112 |
+
In all cases we use layer-wise pretraining for the encoder, where we start with two encoder layers and a single max-pool in between with factor 32. Then we add a LSTM layer and a maxpool in between, and we reduce the first max-pool to factor 16 and the new one with factor 2 such that we always keep the same total encoder time reduction factor of 32. Only when we end up at 6 layers, we remove some of the max-pooling ops to get a final total time reduction factor of e.g. 8. Directly starting with a time reduction factor of 8 with and with 2 layers did not work for us. Also directly starting with 6 layers and time reduction factor of 32 did not work for us. Similar experiments for translation converged also without pretraining, however with much worse performance compared when layer-wise pretraining was used [30]. With more careful tuning or more training data, it might have worked without pretraining as it is seen in the literature, however, that is not necessary with pretraining.
|
| 113 |
+
|
| 114 |
+
We were interested in the optimal final total time reduction factor, after the pretraining with time reduction factor 32. We tried factor 8, 16 and 32, and ended up with 20.4, 21.0 and 21.9 WER% respectively, on the full Hub5'00 set (Switchboard + Callhome). Thus we continue to use a final reduction factor of 8 in all further experiments. Note that a lower factor requires more memory and more computation for the global attention and was not feasible with our hardware and computational resources.
|
| 115 |
+
|
| 116 |
+
## 6.2. Switchboard 300h
|
| 117 |
+
|
| 118 |
+
Switchboard consists of about 300 hours of training data. There is also the additional Fisher training dataset, so combined it makes the total of about 2000h. In this work, we only use the 300h-Switchboard training data. We use 40-dimensional Gammatone features [58], and the feature extraction was done with RASR [59]. Results are shown in Table 2. We observe that our attention model performs better on the easier Switchboard subset of the dev set Hub5'00, where it is the best end-to-end model we know. On the harder Callhome part, it also performs well compared to other end-to-end models but the relative difference is not as high.
|
| 119 |
+
|
| 120 |
+
## 6.3. LibriSpeech 1000h
|
| 121 |
+
|
| 122 |
+
LibriSpeech training dataset consist of about 1000 hours of read audio books. The dev and test sets were split into simple ('clean') and harder ('other') subsets [49]. We do 40-dim. MFCC feature extraction on-the-fly in RETURNN, based on librosa [62]. We use CTC as an additional loss function applied on top of the decoder to help the convergence, although this is not used in decoding [63]. We initially trained only using the train-clean set and restricting it to sequences not longer than 75 characters in the orthography. Results are shown in Table 3. Our end-to-end system achieves competitive performance even without using language models. We observed that the shallow fusion with LSTM LM brings from 17% to 27% relative improvements in terms of WER on different subsets. This improvement is much larger than in the case of Switchboard. The amount of data is most likely the reason for this observation. For Librispeech, the external data of 800M words is used to train the language models, which is 80 times larger than the 10M words corresponding to the transcription of 1000 hours of audio. In addition, this 10M transcription is not part of the language model training data. In case of Switchboard, the LM is trained only on about 27M words, including 3M of transcription used to train the end-to-end system. Text data for conversational speech is not as readily available as for read speech. The WER of 3.54% on the dev-clean and 3.82% on the test-clean subsets are the best performance on this task to the best of our knowledge for systems trained only using LibriSpeech data.
|
| 123 |
+
|
| 124 |
+
Table 2: Comparisons on Switchboard 300h. The hybrid HMM/NNmodel is a 6 layer deep bidirectional LSTM. The attention model has a 6 layer deep bidirectional LSTM encoder and a 1 layer LSTM decoder. CDp are (clustered) context-dependend phones. Byte-pair encoding (BPE) are sub-word units. SWB and CH are from Hub5'00. 1 added noise from external data. 2 added the lexicon, i.e. also additional data.
|
| 125 |
+
|
| 126 |
+
| model LM label WER[%] unit SWB CH Hub5'01 LF MMI, 2016 [7] 4-gram CDp 9.6 19.3 hybrid 4-gram CDp 9.8 19.0 14.7 hybrid LSTM CDp 8.3 17.3 12.9 CTC 1 , 2014 [12] RNN chars 20.0 31.8 CTC, 2015 [60] none chars 38.0 56.1 CTC, 2015 [60] RNN chars 21.4 40.2 attention, 2016 [61] none chars 32.8 52.7 attention, 2016 [61] 5-gram chars 30.5 50.4 attention, 2016 [61] none words 26.8 48.2 attention, 2016 [61] 3-gram words 25.8 46.0 CTC, 2017 [16] none chars 24.7 37.1 CTC, 2017 [16] n -gram chars 19.8 32.1 CTC 2 , 2017 [16] word RNN chars 14.0 25.3 attention, 2017 [28] none chars 23.1 40.8 attention none BPE 10K 13.5 27.1 19.9 BPE 1K 13.1 26.1 19.7 LSTM BPE 1K 11.8 25.7 18.1 |
|
| 127 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 128 |
+
|
| 129 |
+
## 6.4. Beam search prune error analysis
|
| 130 |
+
|
| 131 |
+
Beam search is an approximation for the decision rule
|
| 132 |
+
|
| 133 |
+
<!-- formula-not-decoded -->
|
| 134 |
+
|
| 135 |
+
The approximation is the pruning we apply due to the beam size. Beam search decoding for hybrid models is very sophisticated and uses a dynamic beam size based on the partial hypothesis scores which can become very large (on the order of thousands) [66]. The beam search for attention models works directly on the labels, i.e. on the BPE units in our case, and usually a static fixed very low beam size (e.g. 10) is used. It has been shown that increasing the beam size much more does not help in increasing the overal performance. This indicates that we do not have a search problem but we wanted to analyze this in more detail. Specifically, we are interested in how much errors we are making due to the pruning for our attention models, and we can count that by calculating the search score of the real target sequence, and compare it to the search score of the decoded sequence. If the decoded sequence has a higher score than the real target sequence, we have not made a search error but it is a model error. We count the number of sequences where the decoded sequence has a lower score than the real target sequence. We report our results in Table 4. We observe that for our standard beam size 12, the number of search errors are well below 1%, and also the WER will not noticeably improve with a larger beam size. Note that we only analyzed the search errors regarding reaching the real target sequence. We did not count search errors regarding reaching any sequence with lower WER. However, our results still suggest that we do not seem to have a search problem but a model problem.
|
| 136 |
+
|
| 137 |
+
Table 3: Comparisons on LibriSpeech 1000h. The attention model has a 6 layer deep bidirectional LSTM encoder and a 1 layer LSTM decoder. CDp are (clustered) context-dependend phones. Byte-pair encoding (BPE) are sub-word units. Latticefree (LF) maximum mutual information (MMI) [7] is a sequence criterion to train a hybrid HMM/NN model. Auto SeGmentation (ASG) [64] can be seen as a variant of the CTC criterion and model. Policy learning is a sequence training method, applied here on a CTC model [15]. If not specified, the official 4-gram word LM is used. The remaining attention models are all our models.
|
| 138 |
+
|
| 139 |
+
| model LM label WER[%] unit dev test clean other clean other hybrid, FFNN, 2015 [49] 4-gram CDp 4.90 12.98 5.51 13.97 LF MMI, LSTM, 2016 [7] 4-gram CDp 4.28 CTC, 2015 [65] 4-gram chars 5.33 13.25 ASG (CTC), 2017 [64] 4-gram chars 4.80 14.50 ASG (CTC), 2017 [64] none chars 6.70 20.80 CTC, PL, 2017 [15] 4-gram chars 5.10 14.26 5.42 14.70 attention none BPE 4.87 14.37 4.87 15.39 4-gram BPE 4.79 14.31 4.82 15.30 LSTM BPE 3.54 11.52 3.82 12.76 |
|
| 140 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 141 |
+
|
| 142 |
+
Table 4: Beam search error analysis, performed on LibriSpeech, without language model. We provide both the number of reference-related search errors, relative to the number of sequences, and also the corresponding WER.
|
| 143 |
+
|
| 144 |
+
| beam search errors [%] (WER [%]) size dev test clean other clean other 4 1.52 (4.87) 1.68 (14.53) 1.07 (4.87) 1.70 (15.49) 8 0.96 (4.88) 0.98 (14.40) 0.76 (4.87) 1.02 (15.39) 12 0.81 (4.87) 0.59 (14.37) 0.61 (4.86) 0.71 (15.39) 16 0.70 (4.87) 0.52 (14.36) 0.50 (4.86) 0.58 (15.37) 32 0.26 (4.87) 0.14 (14.34) 0.19 (4.86) 0.20 (15.34) |
|
| 145 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 146 |
+
|
| 147 |
+
## 7. Conclusions
|
| 148 |
+
|
| 149 |
+
Wepresentented an encoder-decoder-attention model for speech recognition operating on BPE subword units. We introduced a new method for pretraining the encoder, which was crucial for both convergence and the performance in terms of WER. We further improved our recognition accuracy by a joint beam search with a LSTM LM trained on the same subword vocabulary. We carried out experiments on two standard datasets. On the 300h-Switchboard, we achieved competitve results compared to the previously reported end-to-end models, while the WERsare still higher than the conventional hybrid systems. On the 1000h-LibriSpeech task, we obtained competitive results across different evaluation subsets. To the best of our knowl- edge, the WERs of 3.54% on the dev-clean and 3.82% on the test-clean subsets are the best results reported on this task, when only the official LibriSpeech training data is used.
|
| 150 |
+
|
| 151 |
+
## 8. Acknowledgements
|
| 152 |
+
|
| 153 |
+
This work has received funding from the European Research Council (ERC) under the European Union's Horizon 2020 research and innovation programme (grant agreement No 694537, project 'SEQCLAS'). The work reflects only the authors' views and the ERC Executive Agency is not responsible for any use that may be made of the information it contains. The GPU cluster used for the experiments was partially funded by Deutsche Forschungsgemeinschaft (DFG) Grant INST 222/1168-1.
|
| 154 |
+
|
| 155 |
+
## 9. References
|
| 156 |
+
|
| 157 |
+
- [1] A. Zeyer, P. Doetsch, P. Voigtlaender, R. Schl¨ uter, and H. Ney, 'A comprehensive study of deep bidirectional LSTM RNNs for acoustic modeling in speech recognition,' in ICASSP , New Orleans, LA, USA, Mar. 2017, pp. 2462-2466.
|
| 158 |
+
- [2] H. Bourlard and N. Morgan, Connectionist speech recognition: a hybrid approach . Springer, 1994, vol. 247.
|
| 159 |
+
- [3] A. J. Robinson, 'An application of recurrent nets to phone probability estimation,' Neural Networks, IEEE Transactions on , vol. 5, no. 2, pp. 298-305, 1994.
|
| 160 |
+
- [4] S. J. Young, J. J. Odell, and P. C. Woodland, 'Tree-based state tying for high accuracy acoustic modelling,' in Proceedings of the workshop on Human Language Technology . Association for Computational Linguistics, 1994, pp. 307-312.
|
| 161 |
+
- [5] A. Senior, G. Heigold, M. Bacchiani, and H. Liao, 'GMM-free DNN acoustic model training,' in ICASSP , 2014.
|
| 162 |
+
- [6] A. Zeyer, E. Beck, R. Schl¨ uter, and H. Ney, 'CTC in the context of generalized full-sum HMM training,' in Interspeech , Stockholm, Sweden, Aug. 2017, pp. 944-948.
|
| 163 |
+
- [7] D. Povey, V. Peddinti, D. Galvez, P. Ghahremani, V. Manohar, X. Na, Y. Wang, and S. Khudanpur, 'Purely sequence-trained neural networks for ASR based on lattice-free MMI,' in Interspeech , 2016, pp. 2751-2755.
|
| 164 |
+
- [8] H. Sak, A. Senior, K. Rao, and F. Beaufays, 'Fast and accurate recurrent neural network acoustic models for speech recognition,' in Interspeech , 2015.
|
| 165 |
+
- [9] S. Kanthak and H. Ney, 'Context-dependent acoustic modeling using graphemes for large vocabulary speech recognition,' in ICASSP , Orlando, FL, USA, May 2002, pp. 845-848.
|
| 166 |
+
- [10] A. Graves, S. Fern´ andez, F. Gomez, and J. Schmidhuber, 'Connectionist temporal classification: labelling unsegmented sequence data with recurrent neural networks,' in ICML . ACM, 2006, pp. 369-376.
|
| 167 |
+
- [11] A. Graves and N. Jaitly, 'Towards end-to-end speech recognition with recurrent neural networks,' in ICML , T. Jebara and E. P. Xing, Eds. JMLRWorkshop and Conference Proceedings, 2014, pp. 1764-1772.
|
| 168 |
+
- [12] A. Hannun, C. Case, J. Casper, B. Catanzaro, G. Diamos, E. Elsen, R. Prenger, S. Satheesh, S. Sengupta, A. Coates et al. , 'DeepSpeech: Scaling up end-to-end speech recognition,' arXiv preprint arXiv:1412.5567 , 2014.
|
| 169 |
+
- [13] Y. Miao, M. Gowayyed, and F. Metze, 'Eesen: End-to-end speech recognition using deep rnn models and wfst-based decoding,' in ASRU . IEEE, 2015, pp. 167-174.
|
| 170 |
+
- [14] R. Collobert, C. Puhrsch, and G. Synnaeve, 'Wav2letter: an endto-end convnet-based speech recognition system,' arXiv preprint arXiv:1609.03193 , 2016.
|
| 171 |
+
- [15] Y. Zhou, C. Xiong, and R. Socher, 'Improving end-toend speech recognition with policy learning,' arXiv preprint arXiv:1712.07101 , 2017.
|
| 172 |
+
- [16] G. Zweig, C. Yu, J. Droppo, and A. Stolcke, 'Advances in allneural speech recognition,' in ICASSP . IEEE, 2017, pp. 48054809.
|
| 173 |
+
- [17] H. Liu, Z. Zhu, X. Li, and S. Satheesh, 'Gram-ctc: Automatic unit selection and target decomposition for sequence labelling,' arXiv preprint arXiv:1703.00096 , 2017.
|
| 174 |
+
- [18] H. Soltau, H. Liao, and H. Sak, 'Neural speech recognizer:
|
| 175 |
+
|
| 176 |
+
Acoustic-to-word LSTM model for large vocabulary speech recognition,' in Proc. Interspeech , 2017, pp. 3707-3711.
|
| 177 |
+
|
| 178 |
+
- [19] K. Audhkhasi, B. Ramabhadran, G. Saon, M. Picheny, and D. Nahamoo, 'Direct acoustics-to-word models for english conversational speech recognition,' in Proc. Interspeech , 2017, pp. 959963.
|
| 179 |
+
- [20] D. Bahdanau, K. Cho, and Y. Bengio, 'Neural machine translation by jointly learning to align and translate,' arXiv preprint arXiv:1409.0473 , 2014.
|
| 180 |
+
- [21] M.-T. Luong, H. Pham, and C. D. Manning, 'Effective approaches to attention-based neural machine translation,' arXiv preprint arXiv:1508.04025 , 2015.
|
| 181 |
+
- [22] Y. Wu, M. Schuster, Z. Chen, Q. V. Le, M. Norouzi, W. Macherey, M. Krikun, Y. Cao, Q. Gao, K. Macherey et al. , 'Google's neural machine translation system: Bridging the gap between human and machine translation,' arXiv preprint arXiv:1609.08144 , 2016.
|
| 182 |
+
- [23] J. Ba, V . Mnih, and K. Kavukcuoglu, 'Multiple object recognition with visual attention,' arXiv preprint arXiv:1412.7755 , 2014.
|
| 183 |
+
- [24] W. Chan, N. Jaitly, Q. V. Le, and O. Vinyals, 'Listen, attend and spell: A neural network for large vocabulary conversational speech recognition,' in ICASSP , 2016.
|
| 184 |
+
- [25] P. Doetsch, A. Zeyer, and H. Ney, 'Bidirectional decoder networks for attention-based end-to-end offline handwriting recognition,' in International Conference on Frontiers in Handwriting Recognition , Shenzhen, China, Oct. 2016, pp. 361-366.
|
| 185 |
+
- [26] C.-C. Chiu, T. N. Sainath, Y. Wu, R. Prabhavalkar, P. Nguyen, Z. Chen, A. Kannan, R. J. Weiss, K. Rao, K. Gonina et al. , 'Stateof-the-art speech recognition with sequence-to-sequence models,' arXiv preprint arXiv:1712.01769 , 2017.
|
| 186 |
+
- [27] E. Battenberg, J. Chen, R. Child, A. Coates, Y . Gaur, Y . Li, H. Liu, S. Satheesh, A. Sriram, and Z. Zhu, 'Exploring neural transducers for end-to-end speech recognition,' in ASRU , Okinawa, Japan, Dec. 2017, pp. 206-213.
|
| 187 |
+
- [28] S. Toshniwal, H. Tang, L. Lu, and K. Livescu, 'Multitask learning with low-level auxiliary tasks for encoder-decoder based speech recognition,' in Proc. Interspeech , 2017, pp. 3532-3536.
|
| 188 |
+
- [29] S. Hochreiter and J. Schmidhuber, 'Long short-term memory,' Neural computation , vol. 9, no. 8, pp. 1735-1780, 1997.
|
| 189 |
+
- [30] 'RETURNN as a generic flexible neural toolkit with application to translation and speech recognition,' anonymous authors, submitted to ACL , 2018.
|
| 190 |
+
- [31] J. Chorowski, D. Bahdanau, K. Cho, and Y. Bengio, 'End-to-end continuous speech recognition using attention-based recurrent nn: first results,' arXiv preprint arXiv:1412.1602 , 2014.
|
| 191 |
+
- [32] N. Jaitly, Q. V. Le, O. Vinyals, I. Sutskever, D. Sussillo, and S. Bengio, 'An online sequence-to-sequence model using partial conditioning,' in Advances in Neural Information Processing Systems , 2016, pp. 5067-5075.
|
| 192 |
+
- [33] R. Aharoni and Y. Goldberg, 'Morphological inflection generation with hard monotonic attention,' arXiv preprint arXiv:1611.01487 , 2016.
|
| 193 |
+
- [34] C. Raffel, T. Luong, P. J. Liu, R. J. Weiss, and D. Eck, 'Online and linear-time attention by enforcing monotonic alignments,' arXiv preprint arXiv:1704.00784 , 2017.
|
| 194 |
+
- [35] C.-C. Chiu and C. Raffel, 'Monotonic chunkwise attention,' arXiv preprint arXiv:1712.05382 , 2017.
|
| 195 |
+
- [36] A. Tjandra, S. Sakti, and S. Nakamura, 'Local monotonic attention mechanism for end-to-end speech and language processing,' in Proceedings of the Eighth International Joint Conference on Natural Language Processing (Volume 1: Long Papers) , vol. 1, 2017, pp. 431-440.
|
| 196 |
+
- [37] R. Prabhavalkar, T. N. Sainath, B. Li, K. Rao, and N. Jaitly, 'An analysis of 'attention' in sequence-to-sequence models,',' in Proc. of Interspeech , 2017.
|
| 197 |
+
- [38] J. Hou, S. Zhang, and L. Dai, 'Gaussian prediction based attention for online end-to-end speech recognition,' in Proc. Interspeech , 2017, pp. 3692-3696.
|
| 198 |
+
- [39] P. Doetsch, M. Hannemann, R. Schlueter, and H. Ney, 'Inverted alignments for end-to-end automatic speech recognition,' IEEE Journal of Selected Topics in Signal Processing , vol. 11, no. 8, pp. 1265-1273, Dec. 2017.
|
| 199 |
+
- [40] K. Rao, H. Sak, and R. Prabhavalkar, 'Exploring architectures,
|
| 200 |
+
23. data and units for streaming end-to-end speech recognition with RNN-transducer,' in ASRU . IEEE, 2017, pp. 193-199.
|
| 201 |
+
- [41] E. Battenberg, J. Chen, R. Child, A. Coates, Y . Gaur, Y . Li, H. Liu, S. Satheesh, D. Seetapun, A. Sriram et al. , 'Exploring neural transducers for end-to-end speech recognition,' arXiv preprint arXiv:1707.07413 , 2017.
|
| 202 |
+
- [42] R. Prabhavalkar, K. Rao, T. N. Sainath, B. Li, L. Johnson, and N. Jaitly, 'A comparison of sequence-to-sequence models for speech recognition,' in Proc. Interspeech , 2017, pp. 939-943.
|
| 203 |
+
- [43] H. Sak, M. Shannon, K. Rao, and F. Beaufays, 'Recurrent neural aligner: An encoder-decoder neural network model for sequence to sequence mapping,' in Proc. of Interspeech , 2017.
|
| 204 |
+
- [44] R. Sennrich, B. Haddow, and A. Birch, 'Neural machine translation of rare words with subword units,' in ACL , Berlin, Germany, August 2016, pp. 1715-1725.
|
| 205 |
+
- [45] P. Doetsch, A. Zeyer, P. Voigtlaender, I. Kulikov, R. Schl¨ uter, and H. Ney, 'RETURNN: the RWTH extensible training framework for universal recurrent neural networks,' in ICASSP , New Orleans, LA, USA, Mar. 2017, pp. 5345-5349.
|
| 206 |
+
- [46] TensorFlow Development Team, 'TensorFlow: Large-scale machine learning on heterogeneous systems,' 2015, software available from tensorflow.org. [Online]. Available: https://www.tensorflow.org/
|
| 207 |
+
- [47] M. Sundermeyer, R. Schl¨ uter, and H. Ney, 'LSTM neural networks for language modeling.' in Interspeech , Portland, OR, USA, Sep. 2012, pp. 194-197.
|
| 208 |
+
- [48] C. Gulcehre, O. Firat, K. Xu, K. Cho, L. Barrault, H.-C. Lin, F. Bougares, H. Schwenk, and Y. Bengio, 'On using monolingual corpora in neural machine translation,' arXiv preprint arXiv:1503.03535 , 2015.
|
| 209 |
+
- [49] V. Panayotov, G. Chen, D. Povey, and S. Khudanpur, 'LibriSpeech: an ASR corpus based on public domain audio books,' in ICASSP . IEEE, 2015, pp. 5206-5210.
|
| 210 |
+
- [50] G. Pundak and T. N. Sainath, 'Lower frame rate neural network acoustic models.' in Interspeech , 2016, pp. 22-26.
|
| 211 |
+
- [51] P. Bahar, J. Rosendahl, N. Rossenbach, and H. Ney, 'The RWTH Aachen machine translation systems for IWSLT 2017,' in Int. Workshop on Spoken Language Translation , Tokyo, Japan, Dec. 2017, pp. 29-34.
|
| 212 |
+
- [52] Z. Tu, Z. Lu, Y. Liu, X. Liu, and H. Li, 'Modeling coverage for neural machine translation,' in ACL , 2016.
|
| 213 |
+
- [53] R. Kneser and H. Ney, 'Improved backing-off for m-gram language modeling,' in ICASSP , Detroit, MI, USA, May 1995, pp. 181-184.
|
| 214 |
+
- [54] A. Stolcke, 'SRILM-an extensible language modeling toolkit.' in Interspeech , Denver, CO, USA, Sep. 2002.
|
| 215 |
+
- [55] C. Szegedy, V. Vanhoucke, S. Ioffe, J. Shlens, and Z. Wojna, 'Rethinking the inception architecture for computer vision,' in Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , 2016, pp. 2818-2826.
|
| 216 |
+
- [56] N. Srivastava, G. Hinton, A. Krizhevsky, I. Sutskever, and R. Salakhutdinov, 'Dropout: A simple way to prevent neural networks from overfitting,' The Journal of Machine Learning Research , vol. 15, no. 1, pp. 1929-1958, 2014.
|
| 217 |
+
- [57] D. P. Kingma and J. Ba, 'Adam: A method for stochastic optimization,' arXiv preprint arXiv:1412.6980 , 2014.
|
| 218 |
+
- [58] R. Schl¨ uter, I. Bezrukov, H. Wagner, and H. Ney, 'Gammatone features and feature combination for large vocabulary speech recognition,' in ICASSP , Honolulu, HI, USA, Apr. 2007, pp. 649652.
|
| 219 |
+
- [59] S. Wiesler, A. Richard, P. Golik, R. Schl¨ uter, and H. Ney, 'RASR/NN: The RWTH neural network toolkit for speech recognition,' in ICASSP , Florence, Italy, May 2014, pp. 3313-3317.
|
| 220 |
+
- [60] A. L. Maas, Z. Xie, D. Jurafsky, and A. Y. Ng, 'Lexicon-free conversational speech recognition with neural networks,' in Proc. NAACL , 2015.
|
| 221 |
+
- [61] L. Lu, X. Zhang, and S. Renais, 'On training the recurrent neural network encoder-decoder for large vocabulary end-to-end speech recognition,' in ICASSP . IEEE, 2016, pp. 5060-5064.
|
| 222 |
+
- [62] librosa Development Team, 'librosa 0.5.0,' Feb. 2017. [Online]. Available: https://doi.org/10.5281/zenodo.293021
|
| 223 |
+
- [63] T. Hori, S. Watanabe, Y. Zhang, and W. Chan, 'Advances in joint
|
| 224 |
+
|
| 225 |
+
CTC-attention based end-to-end speech recognition with a deep CNN encoder and RNN-LM,' in Interspeech , 2017.
|
| 226 |
+
|
| 227 |
+
- [64] V. Liptchinsky, G. Synnaeve, and R. Collobert, 'Letterbased speech recognition with gated convnets,' arXiv preprint arXiv:1712.09444 , 2017.
|
| 228 |
+
- [65] D. Amodei, R. Anubhai, E. Battenberg, C. Case, J. Casper, B. Catanzaro, J. Chen, M. Chrzanowski, A. Coates, G. Diamos et al. , 'Deep speech 2: End-to-end speech recognition in english and mandarin,' arXiv preprint arXiv:1512.02595 , 2015.
|
| 229 |
+
- [66] D. Nolden, 'Progress in decoding for large vocabulary continuous speech recognition,' Ph.D. dissertation, RWTH Aachen University, Computer Science Department, RWTH Aachen University, Aachen, Germany, Apr. 2017.
|
text-versions/attention-markdown/1805.12307_AttentionBased LSTM for Psychological St.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1805.12307 Attentionbased Lstm For Psychological St
|
| 2 |
+
|
| 3 |
+
## ATTENTION-BASED LSTM FOR PSYCHOLOGICAL STRESS DETECTION FROM SPOKEN LANGUAGE USING DISTANT SUPERVISION
|
| 4 |
+
|
| 5 |
+
Genta Indra Winata, Onno Pepijn Kampman, Pascale Fung
|
| 6 |
+
|
| 7 |
+
Human Language Technology Center Department of Electronic and Computer Engineering Hong Kong University of Science and Technology, Clear Water Bay, Hong Kong { giwinata, opkampman } @connect.ust.hk, pascale@ece.ust.hk
|
| 8 |
+
|
| 9 |
+
## ABSTRACT
|
| 10 |
+
|
| 11 |
+
We propose a Long Short-Term Memory (LSTM) with attention mechanism to classify psychological stress from selfconducted interview transcriptions. We apply distant supervision by automatically labeling tweets based on their hashtag content, which complements and expands the size of our corpus. This additional data is used to initialize the model parameters, and which it is fine-tuned using the interview data. This improves the model's robustness, especially by expanding the vocabulary size. The bidirectional LSTM model with attention is found to be the best model in terms of accuracy (74.1%) and f-score (74.3%). Furthermore, we show that distant supervision fine-tuning enhances the model's performance by 1.6% accuracy and 2.1% f-score. The attention mechanism helps the model to select informative words.
|
| 12 |
+
|
| 13 |
+
Index Terms -Psychological Stress Detection, LSTM, Natural Language Processing, Distant Supervision, Attention Mechanism
|
| 14 |
+
|
| 15 |
+
## 1. INTRODUCTION
|
| 16 |
+
|
| 17 |
+
Psychological stress has a serious effect on mental health and is often a precursor for more severe conditions. Although stress is a natural stimulant, persistent increased levels yield adverse effects, such as heart attacks [1], hypertension [2], and addiction [3]. Prolonged stress is also linked to mental health issues like anxiety [4] and depression [5]. Its prevalence has been increasing in the past decade [6] and affects the way people speak and their choice of spoken language. Emotional support is known to alleviate stress, yet less than 50% of the stressed population receives enough support from friends, family and professionals [6]. Linguistic studies have shown that language choice contains pointers to levels of stress and mental health [7]. The potential of text data from social media and Twitter for predicting major depression occurrence has also been demonstrated [8, 9].
|
| 18 |
+
|
| 19 |
+
This work is partially funded by CERG16214415 of the Hong Kong Research Grants Council and ITS170 of the Innovation and Technology Commission.
|
| 20 |
+
|
| 21 |
+
Research on sentence-level stress detection has been mostly focused on written text collected from social media such as micro-blogs [10, 11]. The authors of these two works used a framework that combines linguistic, visual and social attributes in classifying stress categories. Lin et al. explored tweets to find stressors and stressful events, by building a stressors and stress subject dictionary. They collected thousands of written Weibo tweets and manually categorized them into 10 groups [11]. On word-level stress detection, a simple bidirectional RNN can achieve good results on Russian speech transcriptions [12].
|
| 22 |
+
|
| 23 |
+
In this work, we propose to build attention-based Long Short-Term Memory (LSTM) models fed with word embeddings for detecting psychological stress on sentence-level from interview transcriptions. It takes a long dependency across words in an utterance. Then, the attention mechanism weighs the importance of every word and chooses what to retrieve from the memory. It outputs the weighted combination of all words to the network for predicting the stress level. We apply distant supervision by adding unlabeled tweets from Twitter to our training set. This technique refers to extracting noisy signals from text as label [13]. In our case, we manually pick hashtags that indicate either a stressed or unstressed state of mind of the author, and use them to scrape stressed (positive labels) and unstressed (negative labels) tweets. We need to include more data during training because our interview corpus is relatively small and covers a limited number of topics, mostly related to academia. The major contribution of this paper is to show that unlabeled data collected from Twitter can improve the classification performance on our interview transcriptions corpus, and that applying an attention mechanism helps the model to effectively choose important words.
|
| 24 |
+
|
| 25 |
+
## 2. METHODOLOGY
|
| 26 |
+
|
| 27 |
+
Our objective is to determine whether someone is stressed or not, given an utterance as input. We explore several different models. For the LSTM and bidirectional LSTM (BLSTM)
|
| 28 |
+
|
| 29 |
+
Fig. 1 . Attention-based LSTM architecture
|
| 30 |
+
|
| 31 |
+
<!-- image -->
|
| 32 |
+
|
| 33 |
+
models, we use a trainable embedding layer whose vectors should eventually form stressed and unstressed term clusters. LSTMs can capture temporal dynamics of words in a sentence.
|
| 34 |
+
|
| 35 |
+
## 2.1. Long Short-Term Memory (LSTM)
|
| 36 |
+
|
| 37 |
+
First, we build a unidirectional LSTM [14] taking word embedding as input. We denote V as the number of unique words in our corpus and k as the dimension of the word embedding vectors. Each word is a one-hot vector x ��� R | V | and performs a multiplication with the embedding layer A ∈ R | V |· k , where k = 100 . The resulting vector is b ∈ R k
|
| 38 |
+
|
| 39 |
+
<!-- formula-not-decoded -->
|
| 40 |
+
|
| 41 |
+
The model architecture is shown in Figure 1. The LSTM consists of one recurrent layer that propagates the embedding vector b t for the word at time t (i.e. a column of b ) through the LSTM network to find hidden state h t
|
| 42 |
+
|
| 43 |
+
<!-- formula-not-decoded -->
|
| 44 |
+
|
| 45 |
+
All hidden states are fed into a subsequent attention layer [15]. We added this layer because not all words contribute equally to the stress classifier. The word importance vector u t is calculated with Equation 3. The normalized word weight α t is obtained through a softmax function (Equation 4). The aggregate of all the information in the sentence v is the weighted sum of each h t with α t as corresponding weights.
|
| 46 |
+
|
| 47 |
+
Fig. 2 . Attention-based BLSTM architecture
|
| 48 |
+
|
| 49 |
+
<!-- image -->
|
| 50 |
+
|
| 51 |
+
<!-- formula-not-decoded -->
|
| 52 |
+
|
| 53 |
+
<!-- formula-not-decoded -->
|
| 54 |
+
|
| 55 |
+
<!-- formula-not-decoded -->
|
| 56 |
+
|
| 57 |
+
This vector v is then fed to a fully connected layer with softmax activation to perform the final classification. The prediction is a vector y ∈ R 2 with the probabilities of being unstressed and stressed. We choose the highest probability by using argmax as the model's prediction.
|
| 58 |
+
|
| 59 |
+
## 2.2. Bidirectional Long Short-Term Memory (BLSTM)
|
| 60 |
+
|
| 61 |
+
We train a BLSTM model in identical fashion to process the word sequence in both forward ( - → h t ) and backward direction ( ← -h t ). This recurrent neural network uses two LSTMs, one for each direction. The architecture is shown in Figure 2.
|
| 62 |
+
|
| 63 |
+
## 2.3. Support Vector Machine (SVM)
|
| 64 |
+
|
| 65 |
+
As a baseline, we build an SVM [16] with a Radial Basis Function (RBF) kernel. We extract word2vec [17] vector embeddings for each word in a given sentence. The embeddings have dimensionality of k = 300 and were pre-trained
|
| 66 |
+
|
| 67 |
+
## # stressed
|
| 68 |
+
|
| 69 |
+
amstressed, busylife, collegestress, distress, distressed, familystress, feelingbusy, feelingfrustrated, feelingoverwhelmed, feelingstress, feelstress, feelstressed, frustrated, frustrating, frustration, iamstressed, ifrustrated, imstressed, overwhelm, overwhelmed, overwhelming, panic, sostress, sostressed, sostressful, stress, stressed, stressedlife, stressedout, stresses, stressful, stressfulllife, stressingout, stresslife, stressor, stressors, stresss, stressss, stresssss, verystressed, workstress
|
| 70 |
+
|
| 71 |
+
## # unstressed
|
| 72 |
+
|
| 73 |
+
blessed, comfort, feelingrelax, feelingrelaxed, grateful, iamblessed, iamgrateful, iamrelaxed, imblessed, imgrateful, nostress, peaceful, relax, relaxed, relaxing
|
| 74 |
+
|
| 75 |
+
Table 2 . Interview Corpus statistics.
|
| 76 |
+
|
| 77 |
+
| utterances tokens speakers vocab size 2,272 36,538 38 3,127 |
|
| 78 |
+
|----------------------------------------------------------------------|
|
| 79 |
+
|
| 80 |
+
Table 3 . Twitter Corpus statistics.
|
| 81 |
+
|
| 82 |
+
| tweets tokens stressed unstressed vocab size 367,312 5,439,427 59,768 307,544 135,463 |
|
| 83 |
+
|--------------------------------------------------------------------------------------------------|
|
| 84 |
+
|
| 85 |
+
on Google News data (around 100 billion words with around 3 million unique words). Since the utterances have a variable number of words, we compute the average sentence vector for each embedding feature and train on the remaining feature space. We average the sum of all vectors to get a new word embedding vector, such that
|
| 86 |
+
|
| 87 |
+
<!-- formula-not-decoded -->
|
| 88 |
+
|
| 89 |
+
where a i,j is the word embedding vector of word i in sentence j , and b j is the sentence vector. Thus, for the SVM, the input is represented as an input matrix consisting of N utterance vectors.
|
| 90 |
+
|
| 91 |
+
## 3. EXPERIMENTS
|
| 92 |
+
|
| 93 |
+
## 3.1. Corpora
|
| 94 |
+
|
| 95 |
+
For our experiments, we used two different corpora: an interview corpus, the Natural Stress Emotion corpus [18], and the Stress Twitter Corpus. The former corpus contains 25 students (13 females) answering the same set of 12 interview questions. The questions were designed to be progressively stress provoking. Additionally, we expanded the dataset by conducting 13 more interviews (3 with females) with identical setup. All answers were binary labeled for stress by three judges, from which we took the majority vote. It has four hours of recordings in total with 36,538 word tokens (see Figure 2). For the text-based models described here, we only used the English transcriptions. Because this corpus is small, we collected more data from Twitter and selected tweets with a set of filtering heuristics based on [19]. We only kept tweets with the hashtag at the end, and having less than four hashtags in total. We filtered out tweets containing URLs and images, and applied distant supervision [13] to label the unlabeled tweets. That is, we manually chose hashtags that indicate either stressed or unstressed state of mind of the author (See Figure 1), and used these to automatically label our scraped tweets. Not all text is created equally and it's important here to be aware of the differences between spoken language and written language on social media.
|
| 96 |
+
|
| 97 |
+
Table 1 . Twitter hashtags.
|
| 98 |
+
|
| 99 |
+
Table 4 . Model performance.
|
| 100 |
+
|
| 101 |
+
| method accu. prec. recall f-score SVM 68.7 72.0 61.2 66.2 LSTM 70.0 70.3 68.1 69.2 LSTM w/ attention 73.8 74.7 71.9 73.2 BLSTM 72.2 74.5 67.5 70.8 BLSTM w/ attention 72.5 73.1 71.2 72.2 |
|
| 102 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 103 |
+
|
| 104 |
+
Table 5 . Fine-tuning performance.
|
| 105 |
+
|
| 106 |
+
| method accu. prec. recall f-score LSTM 73.4 73.6 73.1 73.4 LSTM w/ attention 73.8 74.4 72.5 73.4 BLSTM 73.8 74.7 71.9 73.2 BLSTM w/ attention 74.1 73.6 75.0 74.3 |
|
| 107 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 108 |
+
|
| 109 |
+
## 3.2. Setup
|
| 110 |
+
|
| 111 |
+
For the LSTM and BLSTM experiments, the recurrent layer consists of 64 units. In order to regularize the model, a dropout layer [20] with probability of 0.2 is inserted between the recurrent and attention layers. We use batch gradient descent using Adam [21] as optimizer, with batches of 128 samples. We also run both the LSTM and BLSTM without attention mechanism for comparison.
|
| 112 |
+
|
| 113 |
+
We take 160 random samples from each class from the interview corpus as our test set, as we want to evaluate on spoken language. The remainder is used as training set. All sentences are padded to 35 words. In order to balance the distribution of our training set, we oversample the minority class (stressed) within the training set. We validate the model to find the best setting. For two iterations, the model is trained only with twitter data and afterwards, the model subsequently fine-tuned with interview data. Twitter data is inherently different from spoken transcripts, and both are noisy (absence of correct grammar) in their own way. Since the Twitter corpus is imbalanced, we random sample and take 49,000 tweets from each class every iteration.
|
| 114 |
+
|
| 115 |
+
Fig. 3 . Heatmap of attention layer weights for stressed utterances.
|
| 116 |
+
|
| 117 |
+
<!-- image -->
|
| 118 |
+
|
| 119 |
+
## 3.3. Results
|
| 120 |
+
|
| 121 |
+
Relevant evaluation results on the test set are shown in Tables 4 and 5. The performance of the BLSTM with attention outperforms the other classifiers in terms of accuracy and fscore. The fine-tuning process helps the model to classify sentences related to stress better, but significantly increases the recall. Models with attention mechanism are slightly better.
|
| 122 |
+
|
| 123 |
+
## 3.4. Discussion
|
| 124 |
+
|
| 125 |
+
To visualize the attention mechanism, we extract the attention weights from the best trained model and evaluate several stressed and unstressed utterances (see Figures 3 and 4). The figures show the contribution of each word in the classification task. Darker colors represent stronger word contributions to the classification task. Interestingly, the added attention layer captures key terms related to stress. For instance, in the first stressed example, words such as 'employment' and 'graduation' weigh heavier than others. These words have stronger relation with stress. Furthermore, we can see from other stressed samples that words such as 'employment', 'pressure', 'difficult', 'stressed', and 'anxious' have similar weights. Conversely, words such as 'my', 'Number', 'I', and 'And' are least considered for the classification because they are not related to stress.
|
| 126 |
+
|
| 127 |
+
Distant supervision seems to slightly improve the performance, especially the recall (i.e. false negatives are turned to true positive). This is likely due to the interview corpus covering a limited domain (mainly academic issues), and all interviewees answering the same questions. The domain of the Twitter corpus is more general because it includes other domains and is approximately 40 times larger than the interview corpus, thus adding it makes the model more robust. However, the model did not learn more complicated grammatical structures. For example, from Figure 3 we can see that 'I am not stressed' is classified as stressed. The observation that the model does not learn the semantic meaning of negation, could be caused by a lack of data. Also, we believe tweets are not a great source for models to learn proper grammatical structures.
|
| 128 |
+
|
| 129 |
+
Fig. 4 . Heatmap of attention layer weights for unstressed utterances.
|
| 130 |
+
|
| 131 |
+
<!-- image -->
|
| 132 |
+
|
| 133 |
+
Our models learn statistical characteristics of language choice under stressed psyche. That is, they learn which word combinations and sequences are expressed more often when someone is stressed. It is showed more explicitly in Figure 3. Obviously, a person can talk about stressful topics, yet still remain calm, and vice versa. Although there is an obvious signal, not all stress information is encoded in language choice. This inherently limits our model. The interview corpus only contains transcribed spoken language. A more complete stress detection framework would also include context and prosodic features of spoken utterances.
|
| 134 |
+
|
| 135 |
+
## 4. CONCLUSION
|
| 136 |
+
|
| 137 |
+
We have presented methods for classifying interviewee stress level from interview transcriptions. The best performance was found for our bidirectional LSTM model, which outperformed the other models in terms of accuracy and f-score. The two-phase training method with the out-of-domain stress tweets dataset improves the learning performance. Future work includes multi-modal learning using linguistic and acoustic features. We are also interested in gathering more grammatically correct sentences for transfer learning purposes, so the model may learn how to deal with negation (among others). Furthermore, we will incorporate the model described here into our virtual therapist platform [22], where it is fed with Automatic Speech Recognition output. This makes the system aware of user stress, to which it responds with appropriate stress management advice and exercises.
|
| 138 |
+
|
| 139 |
+
## 5. REFERENCES
|
| 140 |
+
|
| 141 |
+
- [1] John S Yudkin, Meena Kumari, Steve E Humphries, and Vidya Mohamed-Ali, 'Inflammation, obesity, stress and coronary heart disease: is interleukin-6 the link?,' Atherosclerosis , vol. 148, no. 2, pp. 209-214, 2000.
|
| 142 |
+
- [2] Karen A Matthews, Charles R Katholi, Heather McCreath, Mary A Whooley, David R Williams, Sha Zhu, and Jerry H Markovitz, 'Blood pressure reactivity to psychological stress predicts hypertension in the cardia study,' Circulation , vol. 110, no. 1, pp. 74-78, 2004.
|
| 143 |
+
- [3] Natalie Slopen, Emily Z Kontos, Carol D Ryff, John Z Ayanian, Michelle A Albert, and David R Williams, 'Psychosocial stress and cigarette smoking persistence, cessation, and relapse over 9-10 years: a prospective study of middle-aged adults in the united states,' Cancer Causes & Control , vol. 24, no. 10, pp. 1849-1863, 2013.
|
| 144 |
+
- [4] Carlo Faravelli and Stefano Pallanti, 'Recent life events and panic disorder,' Am J Psychiatry , vol. 146, no. 5, pp. 622-6, 1989.
|
| 145 |
+
- [5] Naomi Breslau, Lonni Schultz, and Edward Peterson, 'Sex differences in depression: a role for preexisting anxiety,' Psychiatry research , vol. 58, no. 1, pp. 1-12, 1995.
|
| 146 |
+
- [6] APA, 'Stress in america, coping with change 2017,' American Psychology Association , 2017.
|
| 147 |
+
- [7] Bridianne O'Dea, Mark E Larsen, Philip J Batterham, Alison L Calear, and Helen Christensen, 'A linguistic analysis of suicide-related twitter posts,' Crisis , 2017.
|
| 148 |
+
- [8] MunmunDeChoudhury, Michael Gamon, Scott Counts, and Eric Horvitz, 'Predicting depression via social media.,' in ICWSM , 2013, p. 2.
|
| 149 |
+
- [9] Patricia A Cavazos-Rehg, Melissa J Krauss, Shaina Sowles, Sarah Connolly, Carlos Rosas, Meghana Bharadwaj, and Laura J Bierut, 'A content analysis of depression-related tweets,' Computers in human behavior , vol. 54, pp. 351-357, 2016.
|
| 150 |
+
- [10] Huijie Lin, Jia Jia, Quan Guo, Yuanyuan Xue, Jie Huang, Lianhong Cai, and Ling Feng, 'Psychological stress detection from cross-media microblog data using deep sparse neural network,' in Multimedia and Expo (ICME), 2014 IEEE International Conference on . IEEE, 2014, pp. 1-6.
|
| 151 |
+
- [11] Huijie Lin, Jia Jia, Liqiang Nie, Guangyao Shen, and Tat-Seng Chua, 'What does social media say about your stress?.,' in IJCAI , 2016, pp. 3775-3781.
|
| 152 |
+
- [12] Maria Ponomareva, Kirill Milintsevich, Ekaterina Chernyak, and Anatoly Starostin, 'Automated word stress detection in russian,' in Proceedings of the First Workshop on Subword and Character Level Models in NLP , 2017, pp. 31-35.
|
| 153 |
+
- [13] Micol Marchetti-Bowick and Nathanael Chambers, 'Learning for microblogs with distant supervision: Political forecasting with twitter,' in Proceedings of the 13th Conference of the European Chapter of the Association for Computational Linguistics . Association for Computational Linguistics, 2012, pp. 603-612.
|
| 154 |
+
- [14] Sepp Hochreiter and J¨ urgen Schmidhuber, 'Long shortterm memory,' Neural computation , vol. 9, no. 8, pp. 1735-1780, 1997.
|
| 155 |
+
- [15] Zichao Yang, Diyi Yang, Chris Dyer, Xiaodong He, Alexander J Smola, and Eduard H Hovy, 'Hierarchical attention networks for document classification.,' in HLT-NAACL , 2016, pp. 1480-1489.
|
| 156 |
+
- [16] Corinna Cortes and Vladimir Vapnik, 'Support-vector networks,' Machine learning , vol. 20, no. 3, pp. 273297, 1995.
|
| 157 |
+
- [17] Tomas Mikolov, Ilya Sutskever, Kai Chen, Greg S Corrado, and Jeff Dean, 'Distributed representations of words and phrases and their compositionality,' in Advances in neural information processing systems , 2013, pp. 3111-3119.
|
| 158 |
+
- [18] Xin Zuo, L Lin, and Pascale Fung, 'A multilingual database of natural stress emotion,' in Proceedings of the Eight International Conference on Language Resources and Evaluation (LREC12) , 2012, pp. 11741178.
|
| 159 |
+
- [19] Wenbo Wang, Lu Chen, Krishnaprasad Thirunarayan, and Amit P Sheth, 'Harnessing twitter' big data' for automatic emotion identification,' in Privacy, Security, Risk and Trust (PASSAT), 2012 International Conference on and 2012 International Confernece on Social Computing (SocialCom) . IEEE, 2012, pp. 587-592.
|
| 160 |
+
- [20] Nitish Srivastava, Geoffrey E Hinton, Alex Krizhevsky, Ilya Sutskever, and Ruslan Salakhutdinov, 'Dropout: a simple way to prevent neural networks from overfitting.,' Journal of machine learning research , vol. 15, no. 1, pp. 1929-1958, 2014.
|
| 161 |
+
- [21] Diederik P Kingma and Jimmy Lei Ba, 'Adam: Amethod for stochastic optimization,' .
|
| 162 |
+
- [22] Genta Indra Winata, Onno Kampman, Yang Yang, Anik Dey, and Pascale Fung, 'Nora the empathetic psychologist,' Proc. Interspeech 2017 , pp. 3437-3438, 2017.
|
text-versions/attention-markdown/1807.03756_Latent Alignment and Variational Attenti.md
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1807.03756 Latent Alignment And Variational Attenti
|
| 2 |
+
|
| 3 |
+
## Latent Alignment and Variational Attention
|
| 4 |
+
|
| 5 |
+
Yuntian Deng ∗
|
| 6 |
+
|
| 7 |
+
Yoon Kim ∗
|
| 8 |
+
|
| 9 |
+
Justin Chiu
|
| 10 |
+
|
| 11 |
+
Demi Guo
|
| 12 |
+
|
| 13 |
+
Alexander M. Rush
|
| 14 |
+
|
| 15 |
+
{dengyuntian@seas,yoonkim@seas,justinchiu@g,dguo@college,srush@seas}.harvard.edu
|
| 16 |
+
|
| 17 |
+
School of Engineering and Applied Sciences Harvard University Cambridge, MA, USA
|
| 18 |
+
|
| 19 |
+
## Abstract
|
| 20 |
+
|
| 21 |
+
Neural attention has become central to many state-of-the-art models in natural language processing and related domains. Attention networks are an easy-to-train and effective method for softly simulating alignment; however, the approach does not marginalize over latent alignments in a probabilistic sense. This property makes it difficult to compare attention to other alignment approaches, to compose it with probabilistic models, and to perform posterior inference conditioned on observed data. A related latent approach, hard attention, fixes these issues, but is generally harder to train and less accurate. This work considers variational attention networks, alternatives to soft and hard attention for learning latent variable alignment models, with tighter approximation bounds based on amortized variational inference. We further propose methods for reducing the variance of gradients to make these approaches computationally feasible. Experiments show that for machine translation and visual question answering, inefficient exact latent variable models outperform standard neural attention, but these gains go away when using hard attention based training. On the other hand, variational attention retains most of the performance gain but with training speed comparable to neural attention.
|
| 22 |
+
|
| 23 |
+
## 1 Introduction
|
| 24 |
+
|
| 25 |
+
Attention networks [6] have quickly become the foundation for state-of-the-art models in natural language understanding, question answering, speech recognition, image captioning, and more [15, 81, 16, 14, 63, 80, 71, 62]. Alongside components such as residual blocks and long-short term memory networks, soft attention provides a rich neural network building block for controlling gradient flow and encoding inductive biases. However, more so than these other components, which are often treated as black-boxes, researchers use intermediate attention decisions directly as a tool for model interpretability [43, 1] or as a factor in final predictions [25, 68]. From this perspective, attention plays the role of a latent alignment variable [10, 37]. An alternative approach, hard attention [80], makes this connection explicit by introducing a latent variable for alignment and then optimizing a bound on the log marginal likelihood using policy gradients. This approach generally performs worse (aside from a few exceptions such as [80]) and is used less frequently than its soft counterpart.
|
| 26 |
+
|
| 27 |
+
Still the latent alignment approach remains appealing for several reasons: (a) latent variables facilitate reasoning about dependencies in a probabilistically principled way, e.g. allowing composition with other models, (b) posterior inference provides a better basis for model analysis and partial predictions than strictly feed-forward models, which have been shown to underperform on alignment in machine translation [38], and finally (c) directly maximizing marginal likelihood may lead to better results.
|
| 28 |
+
|
| 29 |
+
∗ Equal contribution.
|
| 30 |
+
|
| 31 |
+
The aim of this work is to quantify the issues with attention and propose alternatives based on recent developments in variational inference. While the connection between variational inference and hard attention has been noted in the literature [4, 41], the space of possible bounds and optimization methods has not been fully explored and is growing quickly. These tools allow us to better quantify whether the general underperformance of hard attention models is due to modeling issues (i.e. soft attention imbues a better inductive bias) or optimization issues.
|
| 32 |
+
|
| 33 |
+
Our main contribution is a variational attention approach that can effectively fit latent alignments while remaining tractable to train. We consider two variants of variational attention: categorical and relaxed . The categorical method is fit with amortized variational inference using a learned inference network and policy gradient with a soft attention variance reduction baseline. With an appropriate inference network (which conditions on the entire source/target), it can be used at training time as a drop-in replacement for hard attention. The relaxed version assumes that the alignment is sampled from a Dirichlet distribution and hence allows attention over multiple source elements.
|
| 34 |
+
|
| 35 |
+
Experiments describe how to implement this approach for two major attention-based models: neural machine translation and visual question answering (Figure 1 gives an overview of our approach for machine translation). We first show
|
| 36 |
+
|
| 37 |
+
Figure 1: Sketch of variational attention applied to machine translation. Two alignment distributions are shown, the blue prior p , and the red variational posterior q taking into account future observations. Our aim is to use q to improve estimates of p and to support improved inference of z .
|
| 38 |
+
|
| 39 |
+
<!-- image -->
|
| 40 |
+
|
| 41 |
+
that maximizing exact marginal likelihood can increase performance over soft attention. We further show that with variational (categorical) attention, alignment variables significantly surpass both soft and hard attention results without requiring much more difficult training. We further explore the impact of posterior inference on alignment decisions, and how latent variable models might be employed. Our code is available at https://github.com/harvardnlp/var-attn/ .
|
| 42 |
+
|
| 43 |
+
Related Work Latent alignment has long been a core problem in NLP, starting with the seminal IBM models [11], HMM-based alignment models [75], and a fast log-linear reparameterization of the IBM 2 model [20]. Neural soft attention models were originally introduced as an alternative approach for neural machine translation [6], and have subsequently been successful on a wide range of tasks (see [15] for a review of applications). Recent work has combined neural attention with traditional alignment [18, 72] and induced structure/sparsity [48, 33, 44, 85, 54, 55, 49], which can be combined with the variational approaches outlined in this paper.
|
| 44 |
+
|
| 45 |
+
In contrast to soft attention models, hard attention [80, 3] approaches use a single sample at training time instead of a distribution. These models have proven much more difficult to train, and existing works typically treat hard attention as a black-box reinforcement learning problem with log-likelihood as the reward [80, 3, 53, 26, 19]. Two notable exceptions are [4, 41]: both utilize amortized variational inference to learn a sampling distribution which is used obtain importance-sampled estimates of the log marginal likelihood [12]. Our method uses uses different estimators and targets the single sample approach for efficiency, allowing the method to be employed for NMT and VQA applications.
|
| 46 |
+
|
| 47 |
+
There has also been significant work in using variational autoencoders for language and translation application. Of particular interest are those that augment an RNN with latent variables (typically Gaussian) at each time step [17, 22, 66, 23, 40] and those that incorporate latent variables into sequence-to-sequence models [84, 7, 70, 64]. Our work differs by modeling an explicit model component (alignment) as a latent variable instead of auxiliary latent variables (e.g. topics). The term "variational attention" has been used to refer to a different component the output from attention (commonly called the context vector) as a latent variable [7], or to model both the memory and the alignment as a latent variable [9]. Finally, there is some parallel work [78, 67] which also performs exact/approximate marginalization over latent alignments for sequence-to-sequence learning.
|
| 48 |
+
|
| 49 |
+
## 2 Background: Latent Alignment and Neural Attention
|
| 50 |
+
|
| 51 |
+
We begin by introducing notation for latent alignment, and then show how it relates to neural attention. For clarity, we are careful to use alignment to refer to this probabilistic model (Section 2.1), and soft and hard attention to refer to two particular inference approaches used in the literature to estimate alignment models (Section 2.2).
|
| 52 |
+
|
| 53 |
+
## 2.1 Latent Alignment
|
| 54 |
+
|
| 55 |
+
Figure 2(a) shows a latent alignment model. Let x be an observed set with associated members { x 1 , . . . , x i , . . . , x T } . Assume these are vector-valued (i.e. x i ∈ R d ) and can be stacked to form a matrix X ∈ R d × T . Let the observed ˜ x be an arbitrary 'query'. These generate a discrete output variable y ∈ Y . This process is mediated through a latent alignment variable z , which indicates which member (or mixture of members) of x generates y . The generative process we consider is:
|
| 56 |
+
|
| 57 |
+
<!-- formula-not-decoded -->
|
| 58 |
+
|
| 59 |
+
where a produces the parameters for an alignment distribution D . The function f gives a distribution over the output, e.g. an exponential family. To fit this model to data, we set the model parameters θ by maximizing the log marginal likelihood of training examples ( x, ˜ x, ˆ y ) : 2
|
| 60 |
+
|
| 61 |
+
<!-- formula-not-decoded -->
|
| 62 |
+
|
| 63 |
+
Directly maximizing this log marginal likelihood in the presence of the latent variable z is often difficult due to the expectation (though tractable in certain cases).
|
| 64 |
+
|
| 65 |
+
For this to represent an alignment, we restrict the variable z to be in the simplex ∆ T -1 over source indices { 1 , . . . , T } . We consider two distributions for this variable: first, let D be a categorical where z is a one-hot vector with z i = 1 if x i is selected. For example, f ( x, z ) could use z to pick from x and apply a softmax layer to predict y , i.e. f ( x, z ) = softmax( W Xz ) and W ∈ R |Y|× d ,
|
| 66 |
+
|
| 67 |
+
Figure 2: Models over observed set x , query ˜ x , and alignment z . (a) Latent alignment model, (b) Soft attention with z absorbed into prediction network.
|
| 68 |
+
|
| 69 |
+
<!-- image -->
|
| 70 |
+
|
| 71 |
+
<!-- formula-not-decoded -->
|
| 72 |
+
|
| 73 |
+
This computation requires a factor of O ( T ) additional runtime, and introduces a major computational factor into already expensive deep learning models. 3
|
| 74 |
+
|
| 75 |
+
Second we consider a relaxed alignment where z is a mixture taken from the interior of the simplex by letting D be a Dirichlet. This objective looks similar to the categorical case, i.e. log p ( y = ˆ y | x, ˜ x ) = log E z [softmax( W Xz ) ˆ y ] , but the resulting expectation is intractable to compute exactly.
|
| 76 |
+
|
| 77 |
+
## 2.2 Attention Models: Soft and Hard
|
| 78 |
+
|
| 79 |
+
When training deep learning models with gradient methods, it can be difficult to use latent alignment directly. As such, two alignment-like approaches are popular: soft attention replaces the probabilistic model with a deterministic soft function and hard attention trains a latent alignment model by maximizing a lower bound on the log marginal likelihood (obtained from Jensen's inequality) with policy gradient-style training. We briefly describe how these methods fit into this notation.
|
| 80 |
+
|
| 81 |
+
2 When clear from context, the random variable is dropped from E [ · ] . We also interchangeably use p (ˆ y | x, ˜ x ) and f ( x, z ; θ ) ˆ y to denote p ( y = ˆ y | x, ˜ x ) .
|
| 82 |
+
|
| 83 |
+
3 Although not our main focus, explicit marginalization is sometimes tractable with efficient matrix operations on modern hardware, and we compare the variational approach to explicit enumeration in the experiments. In some cases it is also possible to efficiently perform exact marginalization with dynamic programming if one imposes additional constraints (e.g. monotonicity) on the alignment distribution [83, 82, 58].
|
| 84 |
+
|
| 85 |
+
Soft Attention Soft attention networks use an altered model shown in Figure 2b. Instead of using a latent variable, they employ a deterministic network to compute an expectation over the alignment variable. We can write this model using the same functions f and a from above,
|
| 86 |
+
|
| 87 |
+
<!-- formula-not-decoded -->
|
| 88 |
+
|
| 89 |
+
A major benefit of soft attention is efficiency. Instead of paying a multiplicative penalty of O ( T ) or requiring integration, the soft attention model can compute the expectation before f . While formally a different model, soft attention has been described as an approximation of alignment [80]. Since E [ z ] ∈ ∆ T -1 , soft attention uses a convex combination of the input representations X E [ z ] (the context vector ) to obtain a distribution over the output. While also a 'relaxed' decision, this expression differs from both the latent alignment models above. Depending on f , the gap between E [ f ( x, z )] and f ( x, E [ z ]) may be large.
|
| 90 |
+
|
| 91 |
+
However there are some important special cases. In the case where p ( z | x, ˜ x ) is deterministic, we have E [ f ( x, z )] = f ( x, E [ z ]) , and p ( y | x, ˜ x ) = p soft ( y | x, ˜ x ) . In general we can bound the absolute difference based on the maximum curvature of f , as shown by the following proposition.
|
| 92 |
+
|
| 93 |
+
Proposition 1. Define g x, ˆ y : ∆ T -1 ↦→ [0 , 1] to be the function given by g x, ˆ y ( z ) = f ( x, z ) ˆ y (i.e. g x, ˆ y ( z ) = p ( y = ˆ y | x, ˜ x, z )) for a twice differentiable function f . Let H g x, ˆ y ( z ) be the Hessian of g x, ˆ y ( z ) evaluated at z , and further suppose ‖ H g x, ˆ y ( z ) ‖ 2 ≤ c for all z ∈ ∆ T -1 , ˆ y ∈ Y , and x , where ‖ · ‖ 2 is the spectral norm. Then for all ˆ y ∈ Y ,
|
| 94 |
+
|
| 95 |
+
<!-- formula-not-decoded -->
|
| 96 |
+
|
| 97 |
+
The proof is given in Appendix A. 4 Empirically the soft approximation works remarkably well, and often moves towards a sharper distribution with training. Alignment distributions learned this way often correlate with human intuition (e.g. word alignment in machine translation) [38]. 5
|
| 98 |
+
|
| 99 |
+
Hard Attention Hard attention is an approximate inference approach for latent alignment (Figure 2a) [80, 4, 53, 26]. Hard attention takes a single hard sample of z (as opposed to a soft mixture) and then backpropagates through the model. The approach is derived by two choices: First apply Jensen's inequality to get a lower bound on the log marginal likelihood, log E z [ p ( y | x, z )] ≥ E z [log p ( y | x, z )] , then maximize this lower-bound with policy gradients/REINFORCE [76] to obtain unbiased gradient estimates,
|
| 100 |
+
|
| 101 |
+
<!-- formula-not-decoded -->
|
| 102 |
+
|
| 103 |
+
where B is a baseline that can be used to reduce the variance of this estimator. To implement this approach efficiently, hard attention uses Monte Carlo sampling to estimate the expectation in the gradient computation. For efficiency, a single sample from p ( z | x, ˜ x ) is used, in conjunction with other tricks to reduce the variance of the gradient estimator (discussed more below) [80, 50, 51].
|
| 104 |
+
|
| 105 |
+
## 3 Variational Attention for Latent Alignment Models
|
| 106 |
+
|
| 107 |
+
Amortized variational inference (AVI, closely related to variational auto-encoders) [36, 61, 50] is a class of methods to efficiently approximate latent variable inference, using learned inference networks. In this section we explore this technique for deep latent alignment models, and propose methods for variational attention that combine the benefits of soft and hard attention.
|
| 108 |
+
|
| 109 |
+
First note that the key approximation step in hard attention is to optimize a lower bound derived from Jensen's inequality. This gap could be quite large, contributing to poor performance. 6 Variational inference methods directly aim to tighten this gap. In particular, the evidence lower bound (ELBO) is a parameterized bound over a family of distributions q ( z ) ∈ Q (with the constraint that the supp q ( z ) ⊆ supp p ( z | x, ˜ x, y ) ),
|
| 110 |
+
|
| 111 |
+
4 It is also possible to study the gap in finer detail by considering distributions over the inputs of f that have high probability under approximately linear regions of f , leading to the notion of approximately expectationlinear functions, which was originally proposed and studied in the context of dropout [46].
|
| 112 |
+
|
| 113 |
+
5 Another way of viewing soft attention is as simply a non-probabilistic learned function. While it is possible that such models encode better inductive biases, our experiments show that when properly optimized, latent alignment attention with explicit latent variables do outperform soft attention.
|
| 114 |
+
|
| 115 |
+
6 Prior works on hard attention have generally approached the problem as a black-box reinforcement learning problem where the rewards are given by log f ( x, z ) . Ba et al. (2015) [4] and Lawson et al. (2017) [41] are the notable exceptions, and both works utilize the framework from [51] which obtains multiple samples from a learned sampling distribution to optimize the IWAE bound [12] or a reweighted wake-sleep objective.
|
| 116 |
+
|
| 117 |
+
| ## Algorithm 1 Variational Attention λ ← enc( x, ˜ x, y ; φ ) ▷ Compute var. params z ∼ q ( z ; λ ) ▷ Sample var. attention log f ( x, z ) ▷ Compute output dist z ′ ← E p ( z ′ | x, ˜ x ) [ z ′ ] ▷ Compute soft atten. B = log f ( x, z ′ ) ▷ Compute baseline dist Backprop ∇ θ and ∇ φ based on eq. 1 and KL ## Algorithm 2 Variational Relaxed Attention max θ E z ∼ p [log p ( y | x, z )] ▷ Pretrain fixed θ . . . u ∼ U ▷ Sample unparam. z ← g φ ( u ) ▷ Reparam sample log f ( x, z ) ▷ Compute output dist Backprop ∇ θ and ∇ φ , reparam and KL |
|
| 118 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 119 |
+
|
| 120 |
+
<!-- formula-not-decoded -->
|
| 121 |
+
|
| 122 |
+
This allows us to search over variational distributions q to improve the bound. It is tight when the variational distribution is equal to the posterior, i.e. q ( z ) = p ( z | x, ˜ x, y ) . Hard attention is a special case of the ELBO with q ( z ) = p ( z | x, ˜ x ) .
|
| 123 |
+
|
| 124 |
+
There are many ways to optimize the evidence lower bound; an effective choice for deep learning applications is to use amortized variational inference . AVI uses an inference network to produce the parameters of the variational distribution q ( z ; λ ) . The inference network takes in the input, query, and the output, i.e. λ = enc ( x, ˜ x, y ; φ ) . The objective aims to reduce the gap with the inference network φ while also training the generative model θ ,
|
| 125 |
+
|
| 126 |
+
<!-- formula-not-decoded -->
|
| 127 |
+
|
| 128 |
+
With the right choice of optimization strategy and inference network this form of variational attention can provide a general method for learning latent alignment models. In the rest of this section, we consider strategies for accurately and efficiently computing this objective; in the next section, we describe instantiations of enc for specific domains.
|
| 129 |
+
|
| 130 |
+
Algorithm 1: Categorical Alignments First consider the case where D , the alignment distribution, and Q , the variational family, are categorical distributions. Here the generative assumption is that y is generated from a single index of x . Under this setup, a low-variance estimator of ∇ θ ELBO, is easily obtained through a single sample from q ( z ) . For ∇ φ ELBO, the gradient with respect to the KL portion is easily computable, but there is an optimization issue with the gradient with respect to the first term E z ∼ q ( z ) [log f ( x, z ))] .
|
| 131 |
+
|
| 132 |
+
Many recent methods target this issue, including neural estimates of baselines [50, 51], RaoBlackwellization [59], reparameterizable relaxations [31, 47], and a mix of various techniques [73, 24]. We found that an approach using REINFORCE [76] along with a specialized baseline was effective. However, note that REINFORCE is only one of the inference choices we can select, and as we will show later, alternative approaches such as reparameterizable relaxations work as well. Formally, we first apply the likelihood-ratio trick to obtain an expression for the gradient with respect to the inference network parameters φ ,
|
| 133 |
+
|
| 134 |
+
<!-- formula-not-decoded -->
|
| 135 |
+
|
| 136 |
+
As with hard attention, we take a single Monte Carlo sample (now drawn from the variational distribution). Variance reduction of this estimate falls to the baseline term B . The ideal (and intuitive) baseline would be E z ∼ q ( z ) [log f ( x, z )] , analogous to the value function in reinforcement learning. While this term cannot be easily computed, there is a natural, cheap approximation: soft attention (i.e. log f ( x, E [ z ]) ). Then the gradient is
|
| 137 |
+
|
| 138 |
+
<!-- formula-not-decoded -->
|
| 139 |
+
|
| 140 |
+
Effectively this weights gradients to q based on the ratio of the inference network alignment approach to a soft attention baseline. Notably the expectation in the soft attention is over p (and not over q ), and therefore the baseline is constant with respect to φ . Note that a similar baseline can also be used for hard attention, and we apply it to both variational/hard attention models in our experiments.
|
| 141 |
+
|
| 142 |
+
Algorithm 2: Relaxed Alignments Next consider treating both D and Q as Dirichlets, where z represents a mixture of indices. This model is in some sense closer to the soft attention formulation which assigns mass to multiple indices, though fundamentally different in that we still formally treat alignment as a latent variable. Again the aim is to find a low variance gradient estimator. Instead of using REINFORCE, certain continuous distributions allow the use reparameterization [36], where sampling z ∼ q ( z ) can be done by first sampling from a simple unparameterized distribution U , and then applying a transformation g φ ( · ) , yielding an unbiased estimator,
|
| 143 |
+
|
| 144 |
+
<!-- formula-not-decoded -->
|
| 145 |
+
|
| 146 |
+
The Dirichlet distribution is not directly reparameterizable. While transforming the standard uniform distribution with the inverse CDF of Dirichlet would result in a Dirichlet distribution, the inverse CDF does not have an analytical solution. However, we can use rejection based sampling to get a sample, and employ implicit differentiation to estimate the gradient of the CDF [32].
|
| 147 |
+
|
| 148 |
+
Empirically, we found the random initialization would result in convergence to uniform Dirichlet parameters for λ . (We suspect that it is easier to find low KL local optima towards the center of the simplex). In experiments, we therefore initialize the latent alignment model by first minimizing the Jensen bound, E z ∼ p ( z | x, ˜ x ) [log p ( y | x, z )] , and then introducing the inference network.
|
| 149 |
+
|
| 150 |
+
## 4 Models and Methods
|
| 151 |
+
|
| 152 |
+
We experiment with variational attention in two different domains where attention-based models are essential and widely-used: neural machine translation and visual question answering.
|
| 153 |
+
|
| 154 |
+
Neural Machine Translation Neural machine translation (NMT) takes in a source sentence and predicts each word of a target sentence y j in an auto-regressive manner. The model first contextually embeds each source word using a bidirectional LSTM to produce the vectors x 1 . . . x T . The query ˜ x consists of an LSTM-based representation of the previous target words y 1: j -1 . Attention is used to identify which source positions should be used to predict the target. The parameters of D are generated from an MLP between the query and source [6], and f concatenates the selected x i with the query ˜ x and passes it to an MLP to produce the distribution over the next target word y j .
|
| 155 |
+
|
| 156 |
+
For variational attention, the inference network applies a bidirectional LSTM over the source and the target to obtain the hidden states x 1 , . . . , x T and h 1 , . . . , h S , and produces the alignment scores at the j -th time step via a bilinear map, s ( j ) i = exp( h ⊤ j U x i ) . For the categorical case, the scores are normalized, q ( z ( j ) i = 1) ∝ s ( j ) i ; in the relaxed case the parameters of the Dirichlet are α ( j ) i = s ( j ) i . Note, the inference network sees the entire target (through bidirectional LSTMs). The word embeddings are shared between the generative/inference networks, but other parameters are separate.
|
| 157 |
+
|
| 158 |
+
Visual Question Answering Visual question answering (VQA) uses attention to locate the parts of an image that are necessary to answer a textual question. We follow the recently-proposed 'bottom-up top-down' attention approach [2], which uses Faster R-CNN [60] to obtain object bounding boxes and performs mean-pooling over the convolutional features (from a pretrained ResNet-101 [27]) in each bounding box to obtain object representations x 1 , . . . , x T . The query ˜ x is obtained by running an LSTM over the question, the attention function a passes the query and the object representation through an MLP. The prediction function f is also similar to the NMT case: we concatenate the chosen x i with the query ˜ x to use as input to an MLP which produces a distribution over the output. The inference network enc uses the answer embedding h y and combines it with x i and ˜ x to produce the variational (categorical) distribution,
|
| 159 |
+
|
| 160 |
+
<!-- formula-not-decoded -->
|
| 161 |
+
|
| 162 |
+
where ⊙ is the element-wise product. This parameterization worked better than alternatives. We did not experiment with the relaxed case in VQA, as the object bounding boxes already give us the ability to attend to larger portions of the image.
|
| 163 |
+
|
| 164 |
+
Inference Alternatives For categorical alignments we described maximizing a particular variational lower bound with REINFORCE. Note that other alternatives exist, and we briefly discuss them here: 1) instead of the single-sample variational bound we can use a multiple-sample importance sampling based approach such as Reweighted Wake-Sleep (RWS) [4] or VIMCO [52]; 2) instead of REINFORCE we can approximate sampling from the discrete categorical distribution with GumbelSoftmax [30]; 3) instead of using an inference network we can directly apply Stochastic Variational Inference (SVI) [28] to learn the local variational parameters in the posterior.
|
| 165 |
+
|
| 166 |
+
Predictive Inference At test time, we need to marginalize out the latent variables, i.e. E z [ p ( y | x, ˜ x, z )] using p ( z | x, ˜ x ) . In the categorical case, if speed is not an issue then enumerating alignments is preferable, which incurs a multiplicative cost of O ( T ) (but the enumeration is parallelizable). Alternatively we experimented with a K -max renormalization, where we only take the topK attention scores to approximate the attention distribution (by re-normalizing). This makes the multiplicative cost constant with respect to T . For the relaxed case, sampling is necessary.
|
| 167 |
+
|
| 168 |
+
## 5 Experiments
|
| 169 |
+
|
| 170 |
+
Setup For NMT we mainly use the IWSLT dataset [13]. This dataset is relatively small, but has become a standard benchmark for experimental NMT models. We follow the same preprocessing as in [21] with the same Byte Pair Encoding vocabulary of 14k tokens [65]. To show that variational attention scales to large datasets, we also experiment on the WMT 2017 English-German dataset [8], following the preprocessing in [74] except that we use newstest2017 as our test set. For VQA, we use the VQA 2.0 dataset. As we are interested in intrinsic evaluation (i.e. log-likelihood) in addition to the standard VQA metric, we randomly select half of the standard validation set as the test set (since we need access to the actual labels). 7 (Therefore the numbers provided are not strictly comparable to existing work.) While the preprocessing is the same as [2], our numbers are worse than previously reported as we do not apply any of the commonly-utilized techniques to improve performance on VQA such as data augmentation and label smoothing.
|
| 171 |
+
|
| 172 |
+
Experiments vary three components of the systems: (a) training objective and model, (b) training approximations, comparing enumeration or sampling, 8 (c) test inference. All neural models have the same architecture and the exact same number of parameters θ (the inference network parameters φ vary, but are not used at test). When training hard and variational attention with sampling both use the same baseline, i.e the output from soft attention. The full architectures/hyperparameters for both NMT and VQA are given in Appendix B.
|
| 173 |
+
|
| 174 |
+
Results and Discussion Table 1 shows the main results. We first note that hard attention underperforms soft attention, even when its expectation is enumerated. This indicates that Jensen's inequality alone is a poor bound. On the other hand, on both experiments, exact marginal likelihood outperforms soft attention, indicating that when possible it is better to have latent alignments.
|
| 175 |
+
|
| 176 |
+
For NMT, on the IWSLT 2014 German-English task, variational attention with enumeration and sampling performs comparably to optimizing the log marginal likelihood, despite the fact that it is optimizing a lower bound. We believe that this is due to the use of q ( z ) , which conditions on the entire source/target and therefore potentially provides better training signal to p ( z | x, ˜ x ) through the KL term. Note that it is also possible to have q ( z ) come from a pretrained external model, such as a traditional alignment model [20]. Table 3 (left) shows these results in context compared to the best reported values for this task. Even with sampling, our system improves on the state-of-the-art. On the larger WMT 2017 English-German task, the superior performance of variational attention persists: our baseline soft attention reaches 24.10 BLEU score, while variational attention reaches 24.98. Note that this only reflects a reasonable setting without exhaustive tuning, yet we show that we can train variational attention at scale. For VQA the trend is largely similar, and results for NLL with variational attention improve on soft attention and hard attention. However the task-specific evaluation metrics are slightly worse.
|
| 177 |
+
|
| 178 |
+
Table 2 (left) considers test inference for variational attention, comparing enumeration to K -max with K = 5 . For all methods exact enumeration is better, however K -max is a reasonable approximation.
|
| 179 |
+
|
| 180 |
+
7 VQA eval metric is defined as min { # humans that said answer 3 , 1 } . Also note that since there are sometimes multiple answers for a given question, in such cases we sample (where the sampling probability is proportional to the number of humans that said the answer) to get a single label.
|
| 181 |
+
|
| 182 |
+
8 Note that enumeration does not imply exact if we are enumerating an expectation on a lower bound.
|
| 183 |
+
|
| 184 |
+
Table 1: Evaluation on NMT and VQA for the various models. E column indicates whether the expectation is calculated via enumeration (Enum) or a single sample (Sample) during training. For NMT we evaluate intrinsically on perplexity (PPL) (lower is better) and extrinsically on BLEU (higher is better), where for BLEU we perform beam search with beam size 10 and length penalty (see Appendix B for further details). For VQA we evaluate intrinsically on negative log-likelihood (NLL) (lower is better) and extrinsically on VQA evaluation metric (higher is better). All results except for relaxed attention use enumeration at test time.
|
| 185 |
+
|
| 186 |
+
| NMT VQA Model Objective E PPL BLEU NLL Eval Soft Attention log p ( y | E [ z ]) - 7.17 32.77 1.76 58.93 Marginal Likelihood log E [ p ] Enum 6.34 33.29 1.69 60.33 Hard Attention E p [log p ] Enum 7.37 31.40 1.78 57.60 Hard Attention E p [log p ] Sample 7.38 31.00 1.82 56.30 Variational Relaxed Attention E q [log p ] - KL Sample 7.58 30.05 - - Variational Attention E q [log p ] - KL Enum 6.08 33.68 1.69 58.44 Variational Attention E q [log p ] - KL Sample 6.17 33.30 1.75 57.52 |
|
| 187 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 188 |
+
|
| 189 |
+
Table 2: (Left) Performance change on NMT from exact decoding to K -Max decoding with K = 5 . (see section 5 for definition of K-max decoding). (Right) Test perplexity of different approaches while varying K to estimate E z [ p ( y | x, ˜ x )] . Dotted lines compare soft baseline and variational with full enumeration.
|
| 190 |
+
|
| 191 |
+
| PPL BLEU Model Exact K -Max Exact K -Max Marginal Likelihood 6.34 6.90 33.29 33.31 Hard + Enum 7.37 7.37 31.40 31.37 Hard + Sample 7.38 7.38 31.00 31.04 Variational + Enum 6.08 6.42 33.68 33.69 Variational + Sample 6.17 6.51 33.30 33.27 |
|
| 192 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 193 |
+
|
| 194 |
+
<!-- image -->
|
| 195 |
+
|
| 196 |
+
Table 2 (right) shows the PPL of different models as we increase K . Good performance requires K > 1 , but we only get marginal benefits for K > 5 . Finally, we observe that it is possible to train with soft attention and test using K -Max with a small performance drop ( Soft KMax in Table 2 (right)). This possibly indicates that soft attention models are approximating latent alignment models. On the other hand, training with latent alignments and testing with soft attention performed badly.
|
| 197 |
+
|
| 198 |
+
Table 3 (lower right) looks at the entropy of the prior distribution learned by the different models. Note that hard attention has very low entropy (high certainty) whereas soft attention is quite high. The variational attention model falls in between. Figure 3 (left) illustrates the difference in practice.
|
| 199 |
+
|
| 200 |
+
Table 3 (upper right) compares inference alternatives for variational attention. RWS reaches a comparable performance as REINFORCE, but at a higher memory cost as it requires multiple samples. Gumbel-Softmax reaches nearly the same performance and seems like a viable alternative; although we found its performance is sensitive to its temperature parameter. We also trained a non-amortized SVI model, but found that at similar runtime it was not able to produce satisfactory results, likely due to insufficient updates of the local variational parameters. A hybrid method such as semi-amortized inference [39, 34] might be a potential future direction worth exploring.
|
| 201 |
+
|
| 202 |
+
Despite extensive experiments, we found that variational relaxed attention performed worse than other methods. In particular we found that when training with a Dirichlet KL, it is hard to reach low-entropy regions of the simplex, and the attentions are more uniform than either soft or variational categorical attention. Table 3 (lower right) quantifies this issue. We experimented with other distributions such as Logistic-Normal and Gumbel-Softmax [31, 47] but neither fixed this issue. Others have also noted difficulty in training Dirichlet models with amortized inference [69].
|
| 203 |
+
|
| 204 |
+
Besides performance, an advantage of these models is the ability to perform posterior inference, since the q function can be used directly to obtain posterior alignments. Contrast this with hard attention where q = p ( z | x, ˜ x ) , i.e. the variational posterior is independent of the future information. Figure 3 shows the alignments of p and q for variational attention over a fixed sentence (see Appendix C for more examples). We see that q is able to use future information to correct alignments. We note that the inability of soft and hard attention to produce good alignments has been noted as a major issue in NMT [38]. While q is not used directly in left-to-right NMT decoding, it could be employed for other applications such as in an iterative refinement approach [56, 42].
|
| 205 |
+
|
| 206 |
+
Figure 3: (Left) An example demonstrating the difference between the prior alignment (red) and the variational posterior (blue) when translating from DE-EN (left-to-right). Note the improved blue alignments for actually and violent which benefit from seeing the next word. (Right) Comparison of soft attention (green) with the p of variational attention (red). Both models imply a similar alignment, but variational attention has lower entropy.
|
| 207 |
+
|
| 208 |
+
<!-- image -->
|
| 209 |
+
|
| 210 |
+
Table 3: (Left) Comparison against the best prior work for NMT on the IWSLT 2014 German-English test set. (Upper Right) Comparison of inference alternatives of variational attention on IWSLT 2014. (Lower Right) Comparison of different models in terms of implied discrete entropy (lower = more certain alignment).
|
| 211 |
+
|
| 212 |
+
| IWSLT Model BLEU Beam Search Optimization [77] 26.36 Actor-Critic [5] 28.53 Neural PBMT + LM [29] 30.08 Minimum Risk Training [21] 32.84 Soft Attention 32.77 Marginal Likelihood 33.29 Hard Attention + Enum 31.40 Hard Attention + Sample 30.42 Variational Relaxed Attention 30.05 Variational Attention + Enum 33.69 Variational Attention + Sample 33.30 Inference Method #Samples PPL BLEU REINFORCE 1 6.17 33.30 RWS 5 6.41 32.96 Gumbel-Softmax 1 6.51 33.08 Entropy Model NMT VQA Soft Attention 1.24 2.70 Marginal Likelihood 0.82 2.66 Hard Attention + Enum 0.05 0.73 Hard Attention + Sample 0.07 0.58 Variational Relaxed Attention 2.02 - Variational Attention + Enum 0.54 2.07 Variational Attention + Sample 0.52 2.44 |
|
| 213 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 214 |
+
|
| 215 |
+
Potential Limitations While this technique is a promising alternative to soft attention, there are some practical limitations: (a) Variational/hard attention needs a good baseline estimator in the form of soft attention. We found this to be a necessary component for adequately training the system. This may prevent this technique from working when T is intractably large and soft attention is not an option. (b) For some applications, the model relies heavily on having a good posterior estimator. In VQA we had to utilize domain structure for the inference network construction. (c) Recent models such as the Transformer [74], utilize many repeated attention models. For instance the current best translation models have the equivalent of 150 different attention queries per word translated. It is unclear if this approach can be used at that scale as predictive inference becomes combinatorial.
|
| 216 |
+
|
| 217 |
+
## 6 Conclusion
|
| 218 |
+
|
| 219 |
+
Attention methods are ubiquitous tool for areas like natural language processing; however they are difficult to use as latent variable models. This work explores alternative approaches to latent alignment, through variational attention with promising result. Future work will experiment with scaling the method on larger-scale tasks and in more complex models, such as multi-hop attention models, transformer models, and structured models, as well as utilizing these latent variables for interpretability and as a way to incorporate prior knowledge.
|
| 220 |
+
|
| 221 |
+
## Acknowledgements
|
| 222 |
+
|
| 223 |
+
We are grateful to Sam Wiseman and Rachit Singh for insightful comments and discussion, as well as Christian Puhrsch for help with translations. This project was supported by a Facebook Research Award (Low Resource NMT). YK is supported by a Google AI PhD Fellowship. YD is supported by a Bloomberg Research Award. AMR gratefully acknowledges the support of NSF CCF-1704834 and an Amazon AWS Research award.
|
| 224 |
+
|
| 225 |
+
## References
|
| 226 |
+
|
| 227 |
+
- [1] David Alvarez-Melis and Tommi S Jaakkola. A Causal Framework for Explaining the Predictions of Black-Box Sequence-to-Sequence Models. In Proceddings of EMNLP , 2017.
|
| 228 |
+
- [2] Peter Anderson, Xiaodong He, Chris Buehler, Damien Teney, Mark Johnson, Stephen Gould, and Lei Zhang. Bottom-up and Top-Down Attention for Image Captioning and Visual Question Answering. In Proceedings of CVPR , 2018.
|
| 229 |
+
- [3] Jimmy Ba, Volodymyr Mnih, and Koray Kavukcuoglu. Multiple Object Recognition with Visual Attention. In Proceedings of ICLR , 2015.
|
| 230 |
+
- [4] Jimmy Ba, Ruslan R Salakhutdinov, Roger B Grosse, and Brendan J Frey. Learning Wake-Sleep Recurrent Attention Models. In Proceedings of NIPS , 2015.
|
| 231 |
+
- [5] Dzmitry Bahdanau, Philemon Brakel, Kelvin Xu, Anirudh Goyal, Ryan Lowe, Joelle Pineau, Aaron Courville, and Yoshua Bengio. An Actor-Critic Algorithm for Sequence Prediction. In Proceedings of ICLR , 2017.
|
| 232 |
+
- [6] Dzmitry Bahdanau, Kyunghyun Cho, and Yoshua Bengio. Neural Machine Translation by Jointly Learning to Align and Translate. In Proceedings of ICLR , 2015.
|
| 233 |
+
- [7] Hareesh Bahuleyan, Lili Mou, Olga Vechtomova, and Pascal Poupart. Variational Attention for Sequenceto-Sequence Models. arXiv:1712.08207 , 2017.
|
| 234 |
+
- [8] Ondˇ rej Bojar, Christian Buck, Rajen Chatterjee, Christian Federmann, Yvette Graham, Barry Haddow, Matthias Huck, Antonio Jimeno Yepes, Philipp Koehn, and Julia Kreutzer. Proceedings of the second conference on machine translation. In Proceedings of the Second Conference on Machine Translation . Association for Computational Linguistics, 2017.
|
| 235 |
+
- [9] Jorg Bornschein, Andriy Mnih, Daniel Zoran, and Danilo J. Rezende. Variational Memory Addressing in Generative Models. In Proceedings of NIPS , 2017.
|
| 236 |
+
- [10] Peter F Brown, Vincent J Della Pietra, Stephen A Della Pietra, and Robert L Mercer. The Mathematics of Statistical Machine Translation: Parameter Estimation. Computational linguistics , 19(2):263-311, 1993.
|
| 237 |
+
- [11] Peter F. Brown, Vincent J. Della Pietra, Stephen A. Della Pietra, and Robert L. Mercer. The mathematics of statistical machine translation: Parameter estimation. Comput. Linguist. , 19(2):263-311, June 1993.
|
| 238 |
+
- [12] Yuri Burda, Roger Grosse, and Ruslan Salakhutdinov. Importance Weighted Autoencoders. In Proceedings of ICLR , 2015.
|
| 239 |
+
- [13] Mauro Cettolo, Jan Niehues, Sebastian Stuker, Luisa Bentivogli, and Marcello Federico. Report on the 11th IWSLT evaluation campaign. In Proceedings of IWSLT , 2014.
|
| 240 |
+
- [14] William Chan, Navdeep Jaitly, Quoc Le, and Oriol Vinyals. Listen, Attend and Spell. arXiv:1508.01211 , 2015.
|
| 241 |
+
- [15] Kyunghyun Cho, Aaron Courville, and Yoshua Bengio. Describing Multimedia Content using Attentionbased Encoder-Decoder Networks. In IEEE Transactions on Multimedia , 2015.
|
| 242 |
+
- [16] Jan Chorowski, Dzmitry Bahdanau, Dmitriy Serdyuk, Kyunghyun Cho, and Yoshua Bengio. AttentionBased Models for Speech Recognition. In Proceedings of NIPS , 2015.
|
| 243 |
+
- [17] Junyoung Chung, Kyle Kastner, Laurent Dinh, Kratarth Goel, Aaron Courville, and Yoshua Bengio. A Recurrent Latent Variable Model for Sequential Data. In Proceedings of NIPS , 2015.
|
| 244 |
+
- [18] Trevor Cohn, Cong Duy Vu Hoang, Ekaterina Vymolova, Kaisheng Yao, Chris Dyer, and Gholamreza Haffari. Incorporating Structural Alignment Biases into an Attentional Neural Translation Model. In Proceedings of NAACL , 2016.
|
| 245 |
+
|
| 246 |
+
- [19] Yuntian Deng, Anssi Kanervisto, Jeffrey Ling, and Alexander M Rush. Image-to-Markup Generation with Coarse-to-Fine Attention. In Proceedings of ICML , 2017.
|
| 247 |
+
- [20] Chris Dyer, Victor Chahuneau, and Noah A. Smith. A Simple, Fast, and Effective Reparameterization of IBM Model 2. In Proceedings of NAACL , 2013.
|
| 248 |
+
- [21] Sergey Edunov, Myle Ott, Michael Auli, David Grangier, and Marc'Aurelio Ranzato. Classical Structured Prediction Losses for Sequence to Sequence Learning. In Proceedings of NAACL , 2018.
|
| 249 |
+
- [22] Marco Fraccaro, Soren Kaae Sonderby, Ulrich Paquet, and Ole Winther. Sequential Neural Models with Stochastic Layers. In Proceedings of NIPS , 2016.
|
| 250 |
+
- [23] Anirudh Goyal, Alessandro Sordoni, Marc-Alexandre Cote, Nan Rosemary Ke, and Yoshua Bengio. Z-Forcing: Training Stochastic Recurrent Networks. In Proceedings of NIPS , 2017.
|
| 251 |
+
- [24] Will Grathwohl, Dami Choi, Yuhuai Wu, Geoffrey Roeder, and David Duvenaud. Backpropagation through the Void: Optimizing control variates for black-box gradient estimation. In Proceedings of ICLR , 2018.
|
| 252 |
+
- [25] Jiatao Gu, Zhengdong Lu, Hang Li, and Victor OK Li. Incorporating Copying Mechanism in Sequence-toSequence Learning. 2016.
|
| 253 |
+
- [26] Caglar Gulcehre, Sarath Chandar, Kyunghyun Cho, and Yoshua Bengio. Dynamic Neural Turing Machine with Soft and Hard Addressing Schemes. arXiv:1607.00036 , 2016.
|
| 254 |
+
- [27] Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep Residual Learning for Image Recognition. In Proceedings of CVPR , 2016.
|
| 255 |
+
- [28] Matthew D Hoffman, David M Blei, Chong Wang, and John Paisley. Stochastic variational inference. The Journal of Machine Learning Research , 14(1):1303-1347, 2013.
|
| 256 |
+
- [29] Po-Sen Huang, Chong Wang, Sitao Huang, Dengyong Zhou, and Li Deng. Towards neural phrase-based machine translation. In Proceedings of ICLR , 2018.
|
| 257 |
+
- [30] Eric Jang, Shixiang Gu, and Ben Poole. Categorical reparameterization with gumbel-softmax. arXiv preprint arXiv:1611.01144 , 2016.
|
| 258 |
+
- [31] Eric Jang, Shixiang Gu, and Ben Poole. Categorical Reparameterization with Gumbel-Softmax. In Proceedings of ICLR , 2017.
|
| 259 |
+
- [32] Martin Jankowiak and Fritz Obermeyer. Pathwise Derivatives Beyond the Reparameterization Trick. In Proceedings of ICML , 2018.
|
| 260 |
+
- [33] Yoon Kim, Carl Denton, Luong Hoang, and Alexander M. Rush. Structured Attention Networks. In Proceedings of ICLR , 2017.
|
| 261 |
+
- [34] Yoon Kim, Sam Wiseman, Andrew C Miller, David Sontag, and Alexander M Rush. Semi-amortized variational autoencoders. arXiv preprint arXiv:1802.02550 , 2018.
|
| 262 |
+
- [35] Diederik P. Kingma and Jimmy Ba. Adam: A Method for Stochastic Optimization. In Proceedings of ICLR , 2015.
|
| 263 |
+
- [36] Diederik P. Kingma and Max Welling. Auto-Encoding Variational Bayes. In Proceedings of ICLR , 2014.
|
| 264 |
+
- [37] Philipp Koehn, Hieu Hoang, Alexandra Birch, Chris Callison-Burch, Marcello Federico, Nicola Bertoldi, Brooke Cowan, Wade Shen, Christine Moran, Richard Zens, et al. Moses: Open source toolkit for statistical machine translation. In Proceedings of the 45th annual meeting of the ACL on interactive poster and demonstration sessions , pages 177-180. Association for Computational Linguistics, 2007.
|
| 265 |
+
- [38] Philipp Koehn and Rebecca Knowles. Six Challenges for Neural Machine Translation. arXiv:1706.03872 , 2017.
|
| 266 |
+
- [39] Rahul G. Krishnan, Dawen Liang, and Matthew Hoffman. On the Challenges of Learning with Inference Networks on Sparse, High-dimensional Data. In Proceedings of AISTATS , 2018.
|
| 267 |
+
- [40] Rahul G. Krishnan, Uri Shalit, and David Sontag. Structured Inference Networks for Nonlinear State Space Models. In Proceedings of AAAI , 2017.
|
| 268 |
+
- [41] Dieterich Lawson, Chung-Cheng Chiu, George Tucker, Colin Raffel, Kevin Swersky, and Navdeep Jaitly. Learning Hard Alignments in Variational Inference. In Proceedings of ICASSP , 2018.
|
| 269 |
+
|
| 270 |
+
- [42] Jason Lee, Elman Mansimov, and Kyunghyun Cho. Deterministic Non-Autoregressive Neural Sequence Modeling by Iterative Refinement. arXiv:1802.06901 , 2018.
|
| 271 |
+
- [43] Tao Lei, Regina Barzilay, and Tommi Jaakkola. Rationalizing Neural Rredictions. In Proceedings of EMNLP , 2016.
|
| 272 |
+
- [44] Yang Liu and Mirella Lapata. Learning Structured Text Representations. In Proceedings of TACL , 2017.
|
| 273 |
+
- [45] Minh-Thang Luong, Hieu Pham, and Christopher D. Manning. Effective Approaches to Attention-based Neural Machine Translation. In Proceedings of EMNLP , 2015.
|
| 274 |
+
- [46] Xuezhe Ma, Yingkai Gao, Zhiting Hu, Yaoliang Yu, Yuntian Deng, and Eduard Hovy. Dropout with Expectation-linear Regularization. In Proceedings of ICLR , 2017.
|
| 275 |
+
- [47] Chris J. Maddison, Andriy Mnih, and Yee Whye Teh. The Concrete Distribution: A Continuous Relaxation of Discrete Random Variables. In Proceedings of ICLR , 2017.
|
| 276 |
+
- [48] André F. T. Martins and Ramón Fernandez Astudillo. From Softmax to Sparsemax: A Sparse Model of Attention and Multi-Label Classification. In Proceedings of ICML , 2016.
|
| 277 |
+
- [49] Arthur Mensch and Mathieu Blondel. Differentiable Dynamic Programming for Structured Prediction and Attention. In Proceedings of ICML , 2018.
|
| 278 |
+
- [50] Andriy Mnih and Karol Gregor. Neural Variational Inference and Learning in Belief Networks. In Proceedings of ICML , 2014.
|
| 279 |
+
- [51] Andriy Mnih and Danilo J. Rezende. Variational Inference for Monte Carlo Objectives. In Proceedings of ICML , 2016.
|
| 280 |
+
- [52] Andriy Mnih and Danilo J Rezende. Variational inference for monte carlo objectives. arXiv preprint arXiv:1602.06725 , 2016.
|
| 281 |
+
- [53] Volodymyr Mnih, Nicola Heess, Alex Graves, and Koray Kavukcuoglu. Recurrent Models of Visual Attention. In Proceedings of NIPS , 2015.
|
| 282 |
+
- [54] Vlad Niculae and Mathieu Blondel. A Regularized Framework for Sparse and Structured Neural Attention. In Proceedings of NIPS , 2017.
|
| 283 |
+
- [55] Vlad Niculae, André F. T. Martins, Mathieu Blondel, and Claire Cardie. SparseMAP: Differentiable Sparse Structured Inference. In Proceedings of ICML , 2018.
|
| 284 |
+
- [56] Roman Novak, Michael Auli, and David Grangier. Iterative Refinement for Machine Translation. arXiv:1610.06602 , 2016.
|
| 285 |
+
- [57] Jeffrey Pennington, Richard Socher, and Christopher D. Manning. GloVe: Global Vectors for Word Representation. In Proceedings of EMNLP , 2014.
|
| 286 |
+
- [58] Colin Raffel, Minh-Thang Luong, Peter J Liu, Ron J Weiss, and Douglas Eck. Online and Linear-Time Attention by Enforcing Monotonic Alignments. In Proceedings of ICML , 2017.
|
| 287 |
+
- [59] Rajesh Ranganath, Sean Gerrish, and David M. Blei. Black Box Variational Inference. In Proceedings of AISTATS , 2014.
|
| 288 |
+
- [60] Shaoqing Ren, Kaiming He, Ross Girshick, and Jian Sun. Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks. In Proceedings of NIPS , 2015.
|
| 289 |
+
- [61] Danilo Jimenez Rezende, Shakir Mohamed, and Daan Wierstra. Stochastic Backpropagation and Approximate Inference in Deep Generative Models. In Proceedings of ICML , 2014.
|
| 290 |
+
- [62] Tim Rocktäschel, Edward Grefenstette, Karl Moritz Hermann, Tomas Kocisky, and Phil Blunsom. Reasoning about Entailment with Neural Attention. In Proceedings of ICLR , 2016.
|
| 291 |
+
- [63] Alexander M. Rush, Sumit Chopra, and Jason Weston. A Neural Attention Model for Abstractive Sentence Summarization. In Proceedings of EMNLP , 2015.
|
| 292 |
+
- [64] Philip Schulz, Wilker Aziz, and Trevor Cohn. A Stochastic Decoder for Neural Machine Translation. In Proceedings of ACL , 2018.
|
| 293 |
+
- [65] Rico Sennrich, Barry Haddow, and Alexandra Birch. Neural Machine Translation of Rare Words with Subword Units. In Proceedings of ACL , 2016.
|
| 294 |
+
|
| 295 |
+
- [66] Iulian Vlad Serban, Alessandro Sordoni, Laurent Charlin Ryan Lowe, Joelle Pineau, Aaron Courville, and Yoshua Bengio. A Hierarchical Latent Variable Encoder-Decoder Model for Generating Dialogues. In Proceedings of AAAI , 2017.
|
| 296 |
+
- [67] Shiv Shankar, Siddhant Garg, and Sunita Sarawagi. Surprisingly Easy Hard-Attention for Sequence to Sequence Learning. In Proceedings of EMNLP , 2018.
|
| 297 |
+
- [68] Bonggun Shin, Falgun H Chokshi, Timothy Lee, and Jinho D Choi. Classification of Radiology Reports Using Neural Attention Models. In Proceedings of IJCNN , 2017.
|
| 298 |
+
- [69] Akash Srivastava and Charles Sutton. Autoencoding Variational Inference for Topic Models. In Proceedings of ICLR , 2017.
|
| 299 |
+
- [70] Jinsong Su, Shan Wu, Deyi Xiong, Yaojie Lu, Xianpei Han, and Biao Zhang. Variational Recurrent Neural Machine Translation. In Proceedings of AAAI , 2018.
|
| 300 |
+
- [71] Sainbayar Sukhbaatar, Arthur Szlam, Jason Weston, and Rob Fergus. End-To-End Memory Networks. In Proceedings of NIPS , 2015.
|
| 301 |
+
- [72] Zhaopeng Tu, Zhengdong Lu, Yang Liu, Xiaohua Liu, and Hang Li. Modeling Coverage for Neural Machine Translation. In Proceedings of ACL , 2016.
|
| 302 |
+
- [73] George Tucker, Andriy Mnih, Chris J. Maddison, Dieterich Lawson, and Jascha Sohl-Dickstein. REBAR: Low-variance, Unbiased Gradient Estimates for Discrete Latent Variable Models. In Proceedings of NIPS , 2017.
|
| 303 |
+
- [74] Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin. Attention is All You Need. In Proceedings of NIPS , 2017.
|
| 304 |
+
- [75] Stephan Vogel, Hermann Ney, and Christoph Tillmann. HMM-based Word Alignment in Statistical Translation. In Proceedings of COLING , 1996.
|
| 305 |
+
- [76] Ronald J. Williams. Simple Statistical Gradient-following Algorithms for Connectionist Reinforcement Learning. Machine Learning , 8, 1992.
|
| 306 |
+
- [77] Sam Wiseman and Alexander M. Rush. Sequence-to-Sequence learning as Beam Search Optimization. In Proceedings of EMNLP , 2016.
|
| 307 |
+
- [78] Shijie Wu, Pamela Shapiro, and Ryan Cotterell. Hard Non-Monotonic Attention for Character-Level Transduction. In Proceedings of EMNLP , 2018.
|
| 308 |
+
- [79] Yonghui Wu, Mike Schuster, Zhifeng Chen, Quoc V. Le, Mohammad Norouzi, Wolfgang Macherey, Maxim Krikun, Yuan Cao, Klaus Macherey Qin Gao, Jeff Klingner, Apurva Shah, Melvin Johnson, Xiaobing Liu, Lukasz Kaiser, Stephan Gouws, Yoshikiyo Kato, Taku Kudo, Hideto Kazawa, Keith Stevens, Nishant Patil George Kurian, Wei Wang, Cliff Young, Jason Smith, Jason Riesa, Alex Rudnick, Oriol Vinyals, Greg Corrado, Macduff Hughes, and Jeffrey Dean. Google's Neural Machine Translation System: Bridging the Gap between Human and Machine Translation. arXiv:1609.08144 , 2016.
|
| 309 |
+
- [80] Kelvin Xu, Jimmy Ba, Ryan Kiros, Kyunghyun Cho, Aaron Courville, Ruslan Salakhudinov, Rich Zemel, and Yoshua Bengio. Show, Attend and Tell: Neural Image Caption Generation with Visual Attention. In Proceedings of ICML , 2015.
|
| 310 |
+
- [81] Zichao Yang, Kiaodong He, Jianfeng Gao, Li Deng, and Alex Smola. Stacked Attention Networks for Image Question Answering. In Proceedings of CVPR , 2016.
|
| 311 |
+
- [82] Lei Yu, Phil Blunsom, Chris Dyer, Edward Grefenstette, and Tomas Kocisky. The Neural Noisy Channel. In Proceedings of ICLR , 2017.
|
| 312 |
+
- [83] Lei Yu, Jan Buys, and Phil Blunsom. Online Segment to Segment Neural Transduction. In Proceedings of EMNLP , 2016.
|
| 313 |
+
- [84] Biao Zhang, Deyi Xiong, Jinsong Su, Hong Duan, and Min Zhang. Variational Neural Machine Translation. In Proceedings of EMNLP , 2016.
|
| 314 |
+
- [85] Chen Zhu, Yanpeng Zhao, Shuaiyi Huang, Kewei Tu, and Yi Ma. Structured Attentions for Visual Question Answering. In Proceedings of ICCV , 2017.
|
| 315 |
+
|
| 316 |
+
## Supplementary Materials for Latent Alignment and Variational Attention
|
| 317 |
+
|
| 318 |
+
## Appendix A: Proof of Proposition 1
|
| 319 |
+
|
| 320 |
+
Proposition. Define g x, ˆ y : ∆ T -1 ↦→ [0 , 1] to be the function given by g x, ˆ y ( z ) = f ( x, z ) ˆ y (i.e. g x, ˆ y ( z ) = p ( y = ˆ y | x, ˜ x, z )) for a twice differentiable function f . Let H g x, ˆ y ( z ) be the Hessian of g x, ˆ y ( z ) evaluated at z , and further suppose ‖ H g x, ˆ y ( z ) ‖ 2 ≤ c for all z ∈ ∆ T -1 , ˆ y ∈ Y , and x , where ‖ · ‖ 2 is the spectral norm. Then for all ˆ y ∈ Y ,
|
| 321 |
+
|
| 322 |
+
<!-- formula-not-decoded -->
|
| 323 |
+
|
| 324 |
+
Proof. We begin by performing Taylor's expansion of g x, ˆ y at E [ z ] :
|
| 325 |
+
|
| 326 |
+
<!-- formula-not-decoded -->
|
| 327 |
+
|
| 328 |
+
for some ˆ z = λz +(1 -λ ) E [ z ] , λ ∈ [0 , 1] . Then letting u = z -E [ z ] , we have
|
| 329 |
+
|
| 330 |
+
<!-- formula-not-decoded -->
|
| 331 |
+
|
| 332 |
+
where c = max {| λ max | , | λ min |} is the largest absolute eigenvalue of H g x, ˆ y (ˆ z ) . (Here λ max and λ min are maximum/minimum eigenvalues of H g X,q (ˆ z ) ). Note that c is also equal to the spectral norm ‖ H g X,q (ˆ z ) ‖ 2 since the Hessian is symmetric.
|
| 333 |
+
|
| 334 |
+
Then,
|
| 335 |
+
|
| 336 |
+
<!-- formula-not-decoded -->
|
| 337 |
+
|
| 338 |
+
<!-- formula-not-decoded -->
|
| 339 |
+
|
| 340 |
+
Here the first inequality follows due to the convexity of the absolute value function and the last inequality follows since
|
| 341 |
+
|
| 342 |
+
<!-- formula-not-decoded -->
|
| 343 |
+
|
| 344 |
+
where the last two inequalities are due to the fact that z, E [ z ] ∈ ∆ T -1 . Then putting it all together we have,
|
| 345 |
+
|
| 346 |
+
<!-- formula-not-decoded -->
|
| 347 |
+
|
| 348 |
+
## Appendix B: Experimental Setup
|
| 349 |
+
|
| 350 |
+
## Neural Machine Translation
|
| 351 |
+
|
| 352 |
+
For data processing we closely follow the setup in [21], which uses Byte Pair Encoding over the combined source/target training set to obtain a vocabulary size of 14,000 tokens. However, different from [21] which uses maximum sequence length of 175, for faster training we only train on sequences of length up to 125.
|
| 353 |
+
|
| 354 |
+
The encoder is a two-layer bi-directional LSTM with 512 units in each direction, and the decoder as a two-layer LSTM with with 768 units. For the decoder, the convex combination of source hidden states at each time step from the attention distribution is used as additional input at the next time step. Word embedding is 512-dimensional.
|
| 355 |
+
|
| 356 |
+
The inference network consists of two bi-directional LSTMs (also two-layer and 512-dimensional each) which is run over the source/target to obtain the hidden states at each time step. These hidden states are combined using bilinear attention [45] to produce the variational parameters. (In contrast the generative model uses MLP attention from [6], though we saw little difference between the two parameterizations). Only the word embedding is shared between the inference network and the generative model.
|
| 357 |
+
|
| 358 |
+
Other training details include: batch size of 6, dropout rate of 0.3, parameter initialization over a uniform distribution U [ -0 . 1 , 0 . 1] , gradient norm clipping at 5, and training for 30 epochs with Adam (learning rate = 0.0003, β 1 = 0.9, β 2 = 0.999) [35] with a learning rate decay schedule which starts halving the learning rate if validation perplexity does not improve. Most models converged well before 30 epochs.
|
| 359 |
+
|
| 360 |
+
For decoding we use beam search with beam size 10 and length penalty α = 1 , from [79]. The length penalty added about 0.5 BLEU points across all the models.
|
| 361 |
+
|
| 362 |
+
## Visual Question Answering
|
| 363 |
+
|
| 364 |
+
The model first obtains object features by mean-pooling the pretrained ResNet-101 features [27] (which are 2048-dimensional) over object regions given by Faster R-CNN [60].The ResNet features are kept fixed and not fine-tuned during training. We fix the maximum number of possible regions to be 36. For the question embedding we use a one-layer LSTM with 1024 units over word embeddings. The word embeddings are 300-dimensional and initialized with GloVe [57]. The generative model produces a distribution over the possible objects via applying MLP attention, i.e.
|
| 365 |
+
|
| 366 |
+
<!-- formula-not-decoded -->
|
| 367 |
+
|
| 368 |
+
The selected image region is concatenated with the question embedding and fed to a one-layer MLP with ReLU non-linearity and 1024 hidden units.
|
| 369 |
+
|
| 370 |
+
The inference network produces a categorical distribution over the image regions by interacting the answer embedding h y (which are 256-dimensional and initialized randomly) with the question embedding ˜ x and the image regions x i ,
|
| 371 |
+
|
| 372 |
+
<!-- formula-not-decoded -->
|
| 373 |
+
|
| 374 |
+
where ⊙ denotes element-wise multiplication. The generative/inference attention MLPs have 1024 hidden units each (i.e. w,u ∈ R 1024 ).
|
| 375 |
+
|
| 376 |
+
Other training details include: batch size of 512, dropout rate of 0.5 on the penultimate layer (i.e. before affine transformation into answer vocabulary), and training for 50 epochs with with Adam (learning rate = 0.0005, β 1 = 0.9, β 2 = 0.999) [35].
|
| 377 |
+
|
| 378 |
+
In cases where there is more than one answer for a given question/image pair, we randomly sample the answer, where the sampling probability is proportional to the number of humans who gave the answer.
|
| 379 |
+
|
| 380 |
+
## Appendix C: Additional Visualizations
|
| 381 |
+
|
| 382 |
+
Figure 4: (Left Column) Further examples highlighting the difference between the prior alignment (red) and the variational posterior (blue) when translating from DE-EN (left-to-right). The variational posterior is able to better handle reordering; in (a) the variational posterior successfully aligns 'turning' to 'verwandelt', in (c) we see a similar pattern with the alignment of the clause 'that's my brand' to 'das ist meine marke'. In (e) the prior and posterior both are confused by the '-ial' in 'territor-ial', however the posterior still remains more accurate overall and correctly aligns the rest of 'revierverhalten' to 'territorial behaviour'. (Right Column) Additional comparisons between soft attention (green) and the prior alignments of variational attention (red). Alignments from both models are similar, but variational attention is lower entropy. Both soft and variational attention rely on aligning the inserted English word 'orientation' to the comma in (b) since a direct translation does not appear in the German source.
|
| 383 |
+
|
| 384 |
+
<!-- image -->
|
text-versions/attention-markdown/1808.03867_Pervasive Attention 2D Convolutional Neu.md
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1808.03867 Pervasive Attention 2D Convolutional Neu
|
| 2 |
+
|
| 3 |
+
## Pervasive Attention: 2D Convolutional Neural Networks for Sequence-to-Sequence Prediction
|
| 4 |
+
|
| 5 |
+
Maha Elbayad 1,2
|
| 6 |
+
|
| 7 |
+
Laurent Besacier 1
|
| 8 |
+
|
| 9 |
+
Jakob Verbeek 2
|
| 10 |
+
|
| 11 |
+
Univ. Grenoble Alpes, CNRS, Grenoble INP, Inria, LIG, LJK, F-38000 Grenoble France
|
| 12 |
+
|
| 13 |
+
1 firstname.lastname@univ-grenoble-alpes.fr 2 firstname.lastname@inria.fr
|
| 14 |
+
|
| 15 |
+
## Abstract
|
| 16 |
+
|
| 17 |
+
Current state-of-the-art machine translation systems are based on encoder-decoder architectures, that first encode the input sequence, and then generate an output sequence based on the input encoding. Both are interfaced with an attention mechanism that recombines a fixed encoding of the source tokens based on the decoder state. We propose an alternative approach which instead relies on a single 2D convolutional neural network across both sequences. Each layer of our network re-codes source tokens on the basis of the output sequence produced so far. Attention-like properties are therefore pervasive throughout the network. Our model yields results that are competitive with state-of-the-art encoder-decoder systems, while being conceptually simpler and having fewer parameters.
|
| 18 |
+
|
| 19 |
+
## 1 Introduction
|
| 20 |
+
|
| 21 |
+
Deep neural networks have made a profound impact on natural language processing technology in general, and machine translation in particular (Kalchbrenner and Blunsom, 2013; Sutskever et al., 2014; Cho et al., 2014; Jean et al., 2015; LeCun et al., 2015). Machine translation (MT) can be seen as a sequence-to-sequence prediction problem, where the source and target sequences are of different and variable length. Current state-of-the-art approaches are based on encoderdecoder architectures (Kalchbrenner and Blunsom, 2013; Sutskever et al., 2014; Cho et al., 2014; Bahdanau et al., 2015). The encoder 'reads' the variable-length source sequence and maps it into a vector representation. The decoder takes this vector as input and 'writes' the target sequence, updating its state each step with the most recent word that it generated. The basic encoder-decoder model is generally equipped with an attention model (Bahdanau et al., 2015), which repetitively re-accesses the source sequence during the decoding process. Given the current state of the decoder, a probability distribution over the elements in the source sequence is computed, which is then used to select or aggregate features of these elements into a single 'context' vector that is used by the decoder. Rather than relying on the global representation of the source sequence, the attention mechanism allows the decoder to 'look back' into the source sequence and focus on salient positions. Besides this inductive bias, the attention mechanism bypasses the problem of vanishing gradients that most recurrent architectures encounter.
|
| 22 |
+
|
| 23 |
+
However, the current attention mechanisms have limited modeling abilities and are generally a simple weighted sum of the source representations (Bahdanau et al., 2015; Luong et al., 2015), where the weights are the result of a shallow matching between source and target elements. The attention module re-combines the same source token codes and is unable to re-encode or re-interpret the source sequence while decoding.
|
| 24 |
+
|
| 25 |
+
To address these limitations, we propose an alternative neural MT architecture, based on deep 2D convolutional neural networks (CNNs). The product space of the positions in source and target sequences defines the 2D grid over which the network is defined. The convolutional filters are masked to prohibit accessing information derived from future tokens in the target sequence, obtaining an autoregressive model akin to generative models for images and audio waveforms (Oord et al., 2016a,b). See Figure 1 for an illustration.
|
| 26 |
+
|
| 27 |
+
This approach allows us to learn deep feature hierarchies based on a stack of 2D convolutional layers, and benefit from parallel computation during training. Every layer of our network computes features of the the source tokens, based on the target sequence produced so far, and uses these to predict the next output token. Our model therefore has attention-like capabilities by construction, that are pervasive throughout the layers of the network, rather than using an 'add-on' attention model.
|
| 28 |
+
|
| 29 |
+
Figure 1: Convolutional layers in our model use masked 3 × 3 fi lters so that features are only computed from previous output symbols. Illustration of the receptive fields after one (dark blue) and two layers (light blue), together with the masked part of the field of view of a normal 3 × 3 fi lter (gray).
|
| 30 |
+
|
| 31 |
+
<!-- image -->
|
| 32 |
+
|
| 33 |
+
We validate our model with experiments on the IWSLT 2014 German-to-English (De-En) and English-to-German(En-De) tasks. We improve on state-of-the-art encoder-decoder models with attention, while being conceptually simpler and having fewer parameters.
|
| 34 |
+
|
| 35 |
+
In the next section we will discuss related work, before presenting our approach in detail in Section 3. We present our experimental evaluation results in Section 4, and conclude in Section 5.
|
| 36 |
+
|
| 37 |
+
## 2 Related work
|
| 38 |
+
|
| 39 |
+
The predominant neural architectures in machine translation are recurrent encoder-decoder networks (Graves, 2012; Sutskever et al., 2014; Cho et al., 2014). The encoder is a recurrent neural network (RNN) based on gated recurrent units (Hochreiter and Schmidhuber, 1997; Cho et al., 2014) to map the input sequence into a vector representation. Often a bi-directional RNN (Schuster and Paliwal, 1997) is used, which consists of two RNNsthat process the input in opposite directions, and the final states of both RNNs are concatenated as the input encoding. The decoder consists of a second RNN, which takes the input encoding, and sequentially samples the output sequence one token at a time whilst updating its state.
|
| 40 |
+
|
| 41 |
+
While best known for their use in visual recognition models, (Oord et al., 2016a; Salimans et al., 2017; Reed et al., 2017; Oord et al., 2016c). Recent works also introduced convolutional networks to natural language processing. The first convolutional apporaches to encoding variablelength sequences consist of stacking word vectors, applying 1D convolutions then aggregating with a max-pooling operator over time (Collobert and Weston, 2008; Kalchbrenner et al., 2014; Kim, 2014). For sequence generation, the works of Ranzato et al. (2016); Bahdanau et al. (2017); Gehring et al. (2017a) mix a convolutional encoder with an RNN decoder. The first entirely convolutional encoder-decoder models where introduced by Kalchbrenner et al. (2016b), but they did not improve over state-of-the-art recurrent architectures. Gehring et al. (2017b) outperformed deep LSTMs for machine translation 1D CNNs with gated linear units (Meng et al., 2015; Oord et al., 2016c; Dauphin et al., 2017) in both the encoder and decoder modules.
|
| 42 |
+
|
| 43 |
+
Such CNN-based models differ from their RNN-based counterparts in that temporal connections are placed between layers of the network, rather than within layers. See Figure 2 for a conceptual illustration. This apparently small difference in connectivity has two important consequences. First, it makes the field of view grow linearly across layers in the convolutional network, while it is unbounded within layers in the recurrent network. Second, while the activations in the RNN can only be computed in a sequential manner, they can be computed in parallel across the temporal dimension in the convolutional case.
|
| 44 |
+
|
| 45 |
+
In all the recurrent or convolutional models mentioned above, each of the input and output sequences are processed separately as a onedimensional sequence by the encoder and decoder respectively. Attention mechanisms (Bahdanau et al., 2015; Luong et al., 2015; Xu et al., 2015) were introduced as an interface between the encoder and decoder modules. During encoding, the attention model finds which hidden states from the source code are the most salient for generating the next target token. This is achieved by evaluating a 'context vector' which, in its most basic form, is a weighted average of the source features. The weights of the summation are predicted by a small neural network that scores these features conditioning on the current decoder state.
|
| 46 |
+
|
| 47 |
+
Figure 2: Illustration of decoder network topology with two hidden layers, nodes at bottom and top represent input and output respectively. Horizontal connections are used for RNNs, diagonal connections for convolutional networks. Vertical connections are used in both cases. Parameters are shared across time-steps (horizontally), but not across layers (vertically).
|
| 48 |
+
|
| 49 |
+
<!-- image -->
|
| 50 |
+
|
| 51 |
+
Vaswani et al. (2017) propose an architecture relying entirely on attention. Positional input coding together with self-attention (Parikh et al., 2016; Lin et al., 2017) replaces recurrent and convolutional layers. Huang et al. (2018) use an attentionlike gating mechanism to alleviate an assumption of monotonic alignment in the phrase-based translation model of Wang et al. (2017). Deng et al. (2018) treat the sentence alignment as a latent variable which they infer using a variational inference network during training to optimize a variational lower-bound on the log-likelihood.
|
| 52 |
+
|
| 53 |
+
Beyond uni-dimensional encoding/decoding. The idea of building a 2D grid from parallel sequences (as in Figure 1) is used in different NLP tasks especially for scoring parallel texts. This includes works on semantic matching, paraphrase identification and machine translation. ARC-II of Hu et al. (2014) has 1D convolutions applied to each sequence separately before a series of 2D convolutions and max-poolings are followed by an MLP to estimate the matching score. They interestingly highlighted the desirable property of letting the sequences 'meet' before their representations mature. He and Lin (2016); Wan et al. (2016) first encode the sequences with Bi-LSTMs then evaluate pairwise similarities between the words of the two sequences to build an interaction grid. While He and Lin (2016) process the grid with a two-dimensional CNN, Wan et al. (2016) directly use k-max pooling to aggregate and then score the pair. Similarly, for sequence alignment, Levy and Wolf (2017) use LSTM hidden states as tokens representations and, similar to our work, concatenate pairwise representations and feed their input grid to a 2D convolutional network followed by a soft-max to estimate soft-alignment probablities. Recently in question-answering, Raison et al. (2018) weaved two Bi-LSTMs, one along the context dimension and the other along the question dimension in order to identify a response span in the context.
|
| 54 |
+
|
| 55 |
+
More related to our work on machine translation, Kalchbrenner et al. (2016a) proposed the 'reencoder' network where a Grid LSTM processes both sequences along its first and second dimension, allowing the model to re-encode the source sequence as it advances along the target dimension. They also observed that such a structure implements an implicit form of attention. Wu et al. (2017) used a CNN over the 2D sourcetarget representation, but only as a discriminator in an adversarial training setup. Similar to semantic matching models, they do not use masked convolutions, since their CNN is used to predict if a given source-target pair is a human or machine translation. Concurrently with our work, Bahar et al. (2018) used a 2DLSTM layer to jointly process the source and target sequences with a similar two-dimensional layout.
|
| 56 |
+
|
| 57 |
+
## 3 Translation by 2D Convolution
|
| 58 |
+
|
| 59 |
+
In this section we present our 2D CNN translation model in detail.
|
| 60 |
+
|
| 61 |
+
Input source-target tensor. Given the source and target pair ( s , t ) of lengths | s | and | t | respectively, we first embed the tokens in d s and d t dimensional spaces via look-up tables. The word embeddings { x 1 , . . . , x | s | } and { y 1 , . . . , y | t | } are then concatenated to form a 3D tensor X ∈ R | t |×| s |× f 0 , with f 0 = d t + d s , where
|
| 62 |
+
|
| 63 |
+
<!-- formula-not-decoded -->
|
| 64 |
+
|
| 65 |
+
This joint unigram encoding is the input to our convolutional network.
|
| 66 |
+
|
| 67 |
+
Convolutional layers. We use the DenseNet (Huang et al., 2017) convolutional architecture, which is the state of the art for image classification tasks. Layers are densely connected, meaning that each layer takes as input the activations of all the preceding layers, rather than just the last one, to produce its g feature maps. The parameter g is called the 'growth rate' as it is the number of appended channels to the network's output at each layer. The long-distance connections in the network improve gradient flow to early network layers during training, which is beneficial for deeper networks.
|
| 68 |
+
|
| 69 |
+
Figure 3: Architecture of the DenseNet at block level (top), and within each block (bottom).
|
| 70 |
+
|
| 71 |
+
<!-- image -->
|
| 72 |
+
|
| 73 |
+
Each layer first batch-normalizes (Ioffe and Szegedy, 2015) its input and apply a ReLU (Nair and Hinton, 2010) non-linearity. To reduce the computation cost, each layer first computes 4 g channels using a 1 × 1 convolution from the f 0 + ( l -1) g input channels to layer l ∈ { 1 , . . . , L } . This is followed by a second batch-normalization and ReLU non-linearity. The second convolution has ( k × ⌈ k 2 ⌉ ) kernels, i.e . masked as illustrated in Figure 1, and generates the g output features maps to which we apply dropout (Srivastava et al., 2014). The architecture of the densely connected network is illustrated in Figure 3.
|
| 74 |
+
|
| 75 |
+
We optionally use gated linear units (Dauphin et al., 2017) in both convolutions, these double the number of output channels, and we use half of them to gate the other half.
|
| 76 |
+
|
| 77 |
+
Target sequence prediction. Starting from the initial f 0 feature maps, each layer l ∈ { 1 , . . . , L } of our DenseNet produces a tensor H l of size | t | × | s | × f l , where f l is the number of output channels of that layer. To compute a distribution over the tokens in the output vocabulary, we need to collapse the second dimension of the tensor, which is given by the variable length of the input sequence, to retrieve a unique encoding for each target position.
|
| 78 |
+
|
| 79 |
+
The simplest aggregation approach is to apply max-pooling over the input sequence to obtain a tensor H pool ∈ R | t |× f L , i.e .
|
| 80 |
+
|
| 81 |
+
<!-- formula-not-decoded -->
|
| 82 |
+
|
| 83 |
+
Alternatively, we can use average-pooling over the input sequence:
|
| 84 |
+
|
| 85 |
+
<!-- formula-not-decoded -->
|
| 86 |
+
|
| 87 |
+
The scaling with the inverse square-root of the source length acts as a variance stabilization term, which we find to be more effective in practice than a simple averaging.
|
| 88 |
+
|
| 89 |
+
The pooled features are then transformed to predictions over the output vocabulary V , by linearly mapping them with a matrix E ∈ R |V|× f L to the vocabulary dimension |V| , and then applying a soft-max. Thus the probability distribution over V for the i -th output token is obtained as
|
| 90 |
+
|
| 91 |
+
<!-- formula-not-decoded -->
|
| 92 |
+
|
| 93 |
+
Alternatively, we can use E to project to dimension d t , and then multiply with the target word embedding matrix used to define the input tensor. This reduces the number of parameters and generally improves the performance.
|
| 94 |
+
|
| 95 |
+
Implicit sentence alignment. For a given output token position i , the max-pooling operator of Eq. (2) partitions the f L channels by assigning them across the source tokens j . Let us define
|
| 96 |
+
|
| 97 |
+
<!-- formula-not-decoded -->
|
| 98 |
+
|
| 99 |
+
as the channels assigned to source token j for output token i . The energy that enters into the softmax to predict token w ∈ V for the i -th output position is given by
|
| 100 |
+
|
| 101 |
+
<!-- formula-not-decoded -->
|
| 102 |
+
|
| 103 |
+
<!-- formula-not-decoded -->
|
| 104 |
+
|
| 105 |
+
The total contribution of the j -th input token is thus given by
|
| 106 |
+
|
| 107 |
+
<!-- formula-not-decoded -->
|
| 108 |
+
|
| 109 |
+
where we dropped the dependence on w for simplicity. As we will show experimentally in the next section, visualizing the values α ij for the groundtruth output tokens, we can recover an implicit sentence alignment used by the model.
|
| 110 |
+
|
| 111 |
+
Self attention. Besides pooling we can collapse the source dimension of the feature tensor with an attention mechanism. This mechanism will generate a tensor H att that can be used instead of, or concatenated with, H Pool .
|
| 112 |
+
|
| 113 |
+
We use the self-attention approach of Lin et al. (2017), which for output token i computes the attention vector ρ i ∈ R | s | from the activations H L i :
|
| 114 |
+
|
| 115 |
+
<!-- formula-not-decoded -->
|
| 116 |
+
|
| 117 |
+
where w ∈ R f L and b ∈ R are parameters of the attention mechanism. Scaling of attention vectors with the square-root of the source length was also used by Gehring et al. (2017b), and we found it effective here as well as in the average-pooling case.
|
| 118 |
+
|
| 119 |
+
## 4 Experimental evaluation
|
| 120 |
+
|
| 121 |
+
In this section, we present our experimental setup, followed by quantitative results, qualitative examples of implicit sentence alignments from our model, and a comparison to the state of the art.
|
| 122 |
+
|
| 123 |
+
## 4.1 Experimental setup
|
| 124 |
+
|
| 125 |
+
Data and pre-processing. We experiment with the IWSLT 2014 bilingual dataset (Cettolo et al., 2014), which contains transcripts of TED talks aligned at sentence level, and translate between German (De) and English (En) in both directions. Following the setup of (Edunov et al., 2018), sentences longer than 175 words and pairs with length ratio exceeding 1.5 were removed from the original data. There are 160+7K training sentence pairs, 7K of which are separated and used for validation/development. We report results on a test set of 6,578 pairs obtained by concatenating TED.dev2010, TEDX.dev2012 and TED.tst20102012. We tokenized and lower-cased all data using the standard scripts from the Moses toolkit (Koehn et al., 2007).
|
| 126 |
+
|
| 127 |
+
For open-vocabulary translation, we segment sequences using byte pair encoding (Sennrich et al., 2016) with 14K merge operations following two approaches. The first (V1), similar to Edunov et al. (2018); Deng et al. (2018), is a joint encoding i.e. applied to the concatenation of source and target texts. This results in a German and English vocabularies of around 12K and 8.8K types respectively. The second approach (V2) encodes each language independently resulting in a German and English vocabularies of 13.3K and 13.8K respectively.
|
| 128 |
+
|
| 129 |
+
Implementation details. Unless stated otherwise, we use DenseNets with masked convolutional filters of size 5 × 3 , as given by the light blue area in Figure 1. To train our models for the ablation study, we use maximum likelihood estimation (MLE) with Adam ( β 1 = 0 . 9 , β 2 = 0 . 999 , ϵ = 1 e -8 ) starting with a learning rate of 5 e -4 that we scale by a factor of 0.8 if no improvement is noticed on the validation loss after three evaluations; we evaluate every 8K updates. For faster training and due to the increased computational requirements, from O ( | x | + | y | ) of encoder-decoder models to O ( | x | . | y | ) , we only read sequences up to 80 positions. We also downsample the initial grid channels by half to reduce the number of input channels to every dense block, thus requiring less memory. After training all models for 40 epochs, the best performing model on the validation set is usd to decode with a beam-search of width 5. We measure translation quality using the BLEU metric (Papineni et al., 2002).
|
| 130 |
+
|
| 131 |
+
Baselines. For comparison with state-of-theart architectures, we implemented a bidirectional LSTM encoder-decoder model with dotproduct attention (Bahdanau et al., 2015; Luong et al., 2015) using PyTorch (Paszke et al., 2017), and used Facebook AI Research Sequence-toSequence Toolkit (Gehring et al., 2017b) to train the ConvS2S and Transformer (Vaswani et al., 2017) models on our data.
|
| 132 |
+
|
| 133 |
+
For the Bi-LSTM encoder-decoder, the encoder is a single layer bidirectional LSTM with input embeddings of size 128 and a hidden state of size 256 (128 in each direction). The decoder is a single layer LSTM with similar input size and a hidden size of 256, the target input embeddings are also used in the pre-softmax projection. For regularization, we apply a dropout of rate 0.2 to the inputs of both encoder and decoder and to the output of the decoder prior to softmax. As in (Bahdanau et al., 2015), we refer to this model as RNNsearch.
|
| 134 |
+
|
| 135 |
+
The ConvS2S model we trained has embeddings of dimension 256, a 16-layers encoder and 12-layers decoder. Each convolution uses 3 × 1 fi lters and is followed by a gated linear unit with a total of 2 × 256 channels. Residual connections link the input of a convolutional block to its output. We first trained the default architecture for this dataset as suggested in FairSeq (Gehring et al., 2017b), which has only 4 layers in the encoder and 3 in the decoder, but achieved better results with the deeper version described above. The model is trained with label-smoothed crossentropy ( ϵ = 0 . 1) using Nesterov accelerated gradient with a momentum of 0.99 and an initial learning rate of 0.25 decaying by a factor of 0.1 every epoch. ConvS2S is also regularized with a dropout rate of 0.2.
|
| 136 |
+
|
| 137 |
+
Figure 4: The impact of token embedding size, number of layers ( L ), and growth rate ( g ) on the validation set BLEU scores. In blue the results with beam search (width=5) and in gray with greedy decoding. The bars show the total number of parameters (in millions) for each setup.
|
| 138 |
+
|
| 139 |
+
<!-- image -->
|
| 140 |
+
|
| 141 |
+
For the transformer model, we use token embeddings of dimension 512, and the encoder and decoder have 6 layers and 4 attention heads. For the inner layer in the per-position feed-forawrd network we use dff = 1024 . We optimize the label-smoothed ( ϵ = 0 . 1) cross-entropy loss with Adam ( β 1 = 0 . 9 , β 2 = 0 . 98 , ϵ = 1 e -8 ) (Kingma and Ba, 2015). The learning rate starts from 1 e -7 and is increased during 4,000 warmup steps. Afterwards, the learning rate is set to 5 e -4 and follows an inverse-square-root schedule (Vaswani et al., 2017). For the transformer we set the dropout to 0 . 3 .
|
| 142 |
+
|
| 143 |
+
## 4.2 Experimental results
|
| 144 |
+
|
| 145 |
+
Architecture evaluation. In this section we explore the impact of several parameters of our model: the token embedding dimension, depth, growth rate and filter sizes. We also evaluate different aggregation mechanisms across the source dimension: max-pooling, average-pooling, and attention.
|
| 146 |
+
|
| 147 |
+
In each chosen setting, we train five models with different initializations and report the mean and standard deviation of the validation set BLEU scores. We also state the number of parameters of each model and the computational cost of training, estimated in a similar way as Vaswani et al. (2017), based on the wall clock time of training and the GPU single precision specs.
|
| 148 |
+
|
| 149 |
+
Table 1: BLEU scores of our model ( L =24 , g = 32 , d s = d t =128 ) on the validation set with different pooling operators and using gated convolutional units.
|
| 150 |
+
|
| 151 |
+
| Model BLEU Flops × 10 5 #params Average 30.89 ± 0.18 3.63 7.18M Max 33.25 ± 0.1 3.44 7.18M Attn 31.55 ± 0.11 3.61 7.24M Max, gated 32.99 ± 0.17 3.49 9.64M [Max, Attn] 33.29 ± 0.14 3.51 7.24M |
|
| 152 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 153 |
+
|
| 154 |
+
In Table 1 we see that using max-pooling instead average-pooling across the source dimension increases the performance with around 2.3 BLEU points. Scaling the average representation with √ | s | Eq. (3) helped improving the performance but it is still largely outperformed by the max-pooling. Adding gated linear units on top of each convolutional layer does not improve the BLEU scores, but increases the variance due to the additional parameters. Stand-alone selfattention i.e . weighted average-pooling is slightly better than uniform average-pooling but it is still outperformed by max-pooling. Concatenating the max-pooled features (Eq. (2)) with the represen- tation obtained with self-attention (Eq. (9)) leads to a small increase in performance, from 33.25 to 33.29. In the remainder of our experiments we only use max-pooling for simplicity, unless stated otherwise.
|
| 155 |
+
|
| 156 |
+
Table 2: Performance of our model ( g =32 , d s = d t =128 ) for different filter sizes k and depths L and filter sizes k on the validation set.
|
| 157 |
+
|
| 158 |
+
| k L BLEU Flops × 10 5 #params 3 16 32.40 ± 0.08 2.47 4.32M 3 20 32.57 ± 0.23 3.03 4.92M 5 8 31.14 ± 0.04 0.63 3.88M 5 12 32.13 ± 0.11 2.61 4.59M 5 16 32.78 ± 0.16 3.55 5.37M 5 20 33.01 ± 0.03 3.01 6.23M 5 24 33.25 ± 0.1 3.44 7.18M 5 28 32.99 ± 0.3 5.35 8.21M 7 12 31.81 ± 0.2 2.76 5.76M 7 16 32.43 ± 0.36 3.13 6.94M |
|
| 159 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 160 |
+
|
| 161 |
+
In Figure 4 we consider the effect of the token embedding size, the growth rate of the network, and its depth. The token embedding size together with the growth rate g control the dimension of the final feature used for estimating the emission probability. We generaly use the same embedding dimension for both languages i.e. d = d t = d s , thus the final representation is of size f L = 2 d + gL . In Figure 4 we see that a minimal dimension is required, in this case d = 128 , in order for the model to be complex enough and capture the training data statistics. For embedding sizes between 128 and 256, the BLEU score slowly increases from 33 to 33.6
|
| 162 |
+
|
| 163 |
+
The depth of the network is of similar impact. Training deeper networks (from 4 to 24 layers) increases the BLEU score by about 5 points. An argument similar to the one about the growth rate can be made in this case too for networks with more than 24 layers.
|
| 164 |
+
|
| 165 |
+
The receptive field of our model is controlled by its depth and the filter size. In Table 2, we note that narrower receptive fields are better than larger ones with less layers at equivalent complextities e.g . comparing ( k =3 , L =20 ) to ( k =5 , L =12 ), and ( k =5 , L =16 ) with ( k =7 , L =12 ).
|
| 166 |
+
|
| 167 |
+
Comparison to the state of the art. We compare our results to the state of the art in Table 3 for both directions German-English (De-En) and English-German (En-De).
|
| 168 |
+
|
| 169 |
+
Figure 5: BLEU scores across sentence lengths.
|
| 170 |
+
|
| 171 |
+
<!-- image -->
|
| 172 |
+
|
| 173 |
+
In this section, the parameters of our models are trained using label-smoothed cross-entropy ( ϵ = 0 . 1 ) similarly to the ConvS2S and Transformer baselines. To successfuly train our models with large embeddings ( d = 512 ) we increase the dropout ( p = 0 . 4 ) and normalize the initial 2D grid. For decodig we use a beam-search of width 5 enhaced with length and coverage penalties (Wu et al., 2016).
|
| 174 |
+
|
| 175 |
+
Our model has about the same number of parameters as RNNsearch (with V1 vocbaularies), yet improves performance by 3.88 BLEU points. It is also better than the recent work of Deng et al. (2018) on recurrent architectures with variational attention.
|
| 176 |
+
|
| 177 |
+
Our model outperforms its 1D convolutional counterpart Gehring et al. (2017b) in both translation directions and is competitive with transformer (0.3 points behind) while having about 2 to 4 times fewer parameters.
|
| 178 |
+
|
| 179 |
+
Performance across sequence lengths. In Figure 5 we consider translation quality as a function of sentence length, and compare our model to RNNsearch, ConvS2S and Transformer. Our model gives the best results across all sentence lengths, except for the longest ones where ConvS2S and Transformer are better. Overall, our model combines the strong performance of RNNsearch on short sentences with good performance of ConvS2S and Transformer on longer ones.
|
| 180 |
+
|
| 181 |
+
Implicit sentence alignments. Following the method described in Section 3, we illustrate in Figure 6 the implicit sentence alignments the maxpooling operator produces in our model. For reference we also show the alignment produced by our model using self-attention. We see that with both max-pooling and attention qualitatively similar implicit sentence alignments emerge.
|
| 182 |
+
|
| 183 |
+
Figure 6: Implicit BPE token-level alignments produced by our Pervasive Attention model. For the maxpooling aggregation we visualize α obtained with Eq. (7) and for self-attention the weights ρ of Eq. (8).
|
| 184 |
+
|
| 185 |
+
<!-- image -->
|
| 186 |
+
|
| 187 |
+
Table 3: Comparison to state-of-the art results on IWSLT German-English translation. (*): results obtained using our implementation. (**): results obtained using FairSeq (Gehring et al., 2017b).
|
| 188 |
+
|
| 189 |
+
| Word-based De-En Flops ( × 10 5 ) # prms En-De # prms Conv-LSTM (MLE) (Bahdanau et al., 2017) 27.56 Bi-GRU (MLE+SLE) (Bahdanau et al., 2017) 28.53 Conv-LSTM (deep+pos) (Gehring et al., 2017a) 30.4 NPMT + language model (Huang et al., 2018) 30.08 25.36 BPE-based ConvS2S (MLE+SLE) (Edunov et al., 2018) 32.84 Varational attention (Deng et al., 2018) 33.10 RNNsearch* (Bahdanau et al., 2015), V1 29.98 1.79 13M 25.04 15M ConvS2S** (MLE) (Gehring et al., 2017b), V1 32.31 1.35 21M 26.73 22M Transformer** (Vaswani et al., 2017), V1 34.42 46M 28.23 48M Transformer** (Vaswani et al., 2017), V2 34.44 52M 28.07 52M Pervasive Attention (this paper), V1 33.86 11M 27.21 11M Pervasive Attention (this paper), V2 34.18 22M 27.99 22M |
|
| 190 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 191 |
+
|
| 192 |
+
Notice in the first example how the max-pool model, when writing I've been working , looks at arbeite but also at seit which indicates the past tense of the former. Also notice some cases of non-monotonic alignment. In the first example for some time occurs at the end of the English sentence, but seit einiger zeit appears earlier in the German source. For the second example there is non-monotonic alignment around the negation at the start of the sentence. The first example illustrates the ability of the model to translate proper names by breaking them down into BPE units. In the second example the German word Karriereweg is broken into the four BPE units karri,er,e,weg . The first and the fourth are mainly used to produce the English a carreer , while for the subsequent path the model looks at weg .
|
| 193 |
+
|
| 194 |
+
Finally, we can observe an interesting pattern in the alignment map for several phrases across the three examples. A rough lower triangular pattern is observed for the English phrases for some time , and it's fantastic , and it's not , a little step , and in that direction . In all these cases the phrase seems to be decoded as a unit, where features are first taken across the entire corresponding source phrase, and progressively from the part of the source phrase that remains to be decoded.
|
| 195 |
+
|
| 196 |
+
## 5 Conclusion
|
| 197 |
+
|
| 198 |
+
We presented a novel neural machine translation architecture that departs from the encoder-decoder paradigm. Our model jointly encodes the source and target sequence into a deep feature hierarchy in which the source tokens are embedded in the context of a partial target sequence. Max-pooling over this joint-encoding along the source dimension is used to map the features to a prediction for the next target token. The model is implemented as 2D CNN based on DenseNet, with masked convolutions to ensure a proper autoregressive factorization of the conditional probabilities.
|
| 199 |
+
|
| 200 |
+
Since each layer of our model re-encodes the input tokens in the context of the target sequence generated so far, the model has attention-like properties in every layer of the network by construction. Adding an explicit self-attention module therefore has a very limited, but positive, effect. Nevertheless, the max-pooling operator in our model generates implicit sentence alignments that are qualitatively similar to the ones generated by attention mechanisms. We evaluate our model on the IWSLT'14 dataset, translation German to English and vice-versa. We obtain excellent BLEU scores that compare favorably with the state of the art, while using a conceptually simpler model with fewer parameters.
|
| 201 |
+
|
| 202 |
+
We hope that our alternative joint source-target encoding sparks interest in other alternatives to the encoder-decoder model. In the future, we plan to explore hybrid approaches in which the input to our joint encoding model is not provided by tokenembedding vectors, but the output of 1D source and target embedding networks, e.g . (bi-)LSTM or 1D convolutional. We also want to explore how our model can be used to translate across multiple language pairs.
|
| 203 |
+
|
| 204 |
+
Our PyTorch-based implementation is available at https://github.com/elbayadm/ attn2d .
|
| 205 |
+
|
| 206 |
+
Acknowledgment. This work has been partially supported by the grant ANR-16-CE23-0006 'Deep in France' and ANR-11-LABX-0025-01 'LabEx PERSYVAL'.
|
| 207 |
+
|
| 208 |
+
## References
|
| 209 |
+
|
| 210 |
+
Parnia Bahar, Christopher Brix, and Hermann Ney. 2018. Towards two-dimensional sequence to sequence model in neural machine translation. In EMNLP .
|
| 211 |
+
|
| 212 |
+
- D. Bahdanau, P. Brakel, K. Xu, A. Goyal, R. Lowe, J. Pineau, A. Courville, and Y. Bengio. 2017. An actor-critic algorithm for sequence prediction. In ICLR .
|
| 213 |
+
- D. Bahdanau, K. Cho, and Y. Bengio. 2015. Neural machine translation by jointly learning to align and translate. In ICLR .
|
| 214 |
+
- M. Cettolo, J. Niehues, S. Stüker, L. Bentivogli, and M. Federico. 2014. Report on the 11th IWSLT evaluation campaign. In IWSLT .
|
| 215 |
+
- K. Cho, B. van Merrienboer, Ç. Gülçehre, D. Bahdanau, F. Bougares, H. Schwenk, and Y. Bengio. 2014. Learning phrase representations using RNN encoder-decoder for statistical machine translation. In EMNLP .
|
| 216 |
+
- R. Collobert and J. Weston. 2008. A unified architecture for natural language processing: Deep neural networks with multitask learning. In ICML .
|
| 217 |
+
- Y. Dauphin, A. Fan, M. Auli, and D. Grangier. 2017. Language modeling with gated convolutional networks. In ICML .
|
| 218 |
+
- Y. Deng, Y. Kim, J. Chiu, D. Guo, and A. Rush. 2018. Latent alignment and variational attention. arXiv preprint arXiv:1807.03756 .
|
| 219 |
+
- S. Edunov, M. Ott, M. Auli, D. Grangier, and M. Ranzato. 2018. Classical structured prediction losses for sequence to sequence learning. In NAACL .
|
| 220 |
+
- J. Gehring, M. Auli, D. Grangier, and Y. Dauphin. 2017a. A convolutional encoder model for neural machine translation. In ACL .
|
| 221 |
+
- J. Gehring, M. Auli, D. Grangier, D. Yarats, and Y. Dauphin. 2017b. Convolutional sequence to sequence learning. In ICML .
|
| 222 |
+
- A. Graves. 2012. Sequence transduction with recurrent neural networks. arXiv preprint arXiv:1211.3711 .
|
| 223 |
+
12. Hua He and Jimmy Lin. 2016. Pairwise word interaction modeling with deep neural networks for semantic similarity measurement. In NAACL , pages 937-948.
|
| 224 |
+
- S. Hochreiter and J. Schmidhuber. 1997. Long shortterm memory. Neural Computation , 9(8):17351780.
|
| 225 |
+
|
| 226 |
+
Baotian Hu, Zhengdong Lu, Hang Li, and Qingcai Chen. 2014. Convolutional neural network architectures for matching natural language sentences. In NIPS , pages 2042-2050.
|
| 227 |
+
|
| 228 |
+
- G. Huang, Z. Liu, L. van der Maaten, and K. Weinberger. 2017. Densely connected convolutional networks. In CVPR .
|
| 229 |
+
- P. Huang, C. Wang, S. Huang, D. Zhou, and L. Deng. 2018. Towards neural phrase-based machine translation. In ICLR .
|
| 230 |
+
- S. Ioffe and C. Szegedy. 2015. Batch normalization: Accelerating deep network training by reducing internal covariate shift. In ICML .
|
| 231 |
+
- S. Jean, K. Cho, R. Memisevic, and Y. Bengio. 2015. On using very large target vocabulary for neural machine translation. In ACL .
|
| 232 |
+
- N. Kalchbrenner and P. Blunsom. 2013. Recurrent continuous translation models. In ACL .
|
| 233 |
+
- N. Kalchbrenner, I. Danihelka, and A. Graves. 2016a. Grid long short-term memory. In ICLR .
|
| 234 |
+
- N. Kalchbrenner, L. Espeholt, K. Simonyan, A. van den Oord, A. Graves, and K. Kavukcuoglu. 2016b. Neural machine translation in linear time. arXiv , arXiv:1610.10099.
|
| 235 |
+
- N. Kalchbrenner, E. Grefenstette, and P. Blunsom. 2014. A convolutional neural network for modelling sentences. In ACL .
|
| 236 |
+
- Y. Kim. 2014. Convolutional neural networks for sentence classification. In ACL .
|
| 237 |
+
- D. Kingma and J. Ba. 2015. Adam: A method for stochastic optimization. In ICLR .
|
| 238 |
+
- P. Koehn, H. Hoang, A. Birch, C. Callison-Burch, M. Federico, N. Bertoldi, B. Cowan, W. Shen, C. Moran, R. Zens, C. Dyer, O. Bojar, A. Constantin, and E. Herbst. 2007. Moses: Open source toolkit for statistical machine translation. In ACL .
|
| 239 |
+
- Y. LeCun, Y. Bengio, and G. Hinton. 2015. Deep learning. Nature , 52:436-444.
|
| 240 |
+
|
| 241 |
+
- D. Levy and L. Wolf. 2017. Learning to align the source code to the compiled object code. In ICML .
|
| 242 |
+
- Z. Lin, M. Feng, C. dos Santos, M. Yu, B. Xiang, B. Zhou, and Y. Bengio. 2017. A structured selfattentive sentence embedding. In ICLR .
|
| 243 |
+
- T. Luong, H. Pham, and C. Manning. 2015. Effective approaches to attention-based neural machine translation. In EMNLP .
|
| 244 |
+
- F. Meng, Z. Lu, M. Wang, H. Li, W. Jiang, and Q. Liu. 2015. Encoding source language with convolutional neural network for machine translation. In ACL .
|
| 245 |
+
- V. Nair and G. Hinton. 2010. Rectified linear units improve restricted Boltzmann machines. In ICML .
|
| 246 |
+
- A. van den Oord, S. Dieleman, H. Zen, K. Simonyan, O. Vinyals, A. Graves, N. Kalchbrenner, A. Senior, and K. Kavukcuoglu. 2016a. Wavenet: a generative model for raw audio. In ISCA Speech Syntesis Workshop .
|
| 247 |
+
- A. van den Oord, N. Kalchbrenner, and K. Kavukcuoglu. 2016b. Pixel recurrent neural networks. In ICML .
|
| 248 |
+
- A. van den Oord, N. Kalchbrenner, O. Vinyals, L. Espeholt, A. Graves, and K. Kavukcuoglu. 2016c. Conditional image generation with PixelCNN decoders. In NIPS .
|
| 249 |
+
- K. Papineni, S. Roukos, T. Ward, and W.-J. Zhu. 2002. BLEU: a method for automatic evaluation of machine translation. In ACL .
|
| 250 |
+
- A. Parikh, O. Täckström, D. Das, and J. Uszkoreit. 2016. A decomposable attention model for natural language inference. In EMNLP .
|
| 251 |
+
- A. Paszke, S. Gross, S. Chintala, G. Chanan, E. Yang, Z. DeVito, Z. Lin, A. Desmaison L. Antiga, and A. Lerer. 2017. Automatic differentiation in pytorch. In NIPS Autodiff Workshop .
|
| 252 |
+
12. Martin Raison, Pierre-Emmanuel Mazaré, Rajarshi Das, and Antoine Bordes. 2018. Weaver: Deep coencoding of questions and documents for machine reading. arXiv preprint arXiv:1804.10490 .
|
| 253 |
+
- M. Ranzato, S. Chopra, M. Auli, and W. Zaremba. 2016. Sequence level training with recurrent neural networks. In ICLR .
|
| 254 |
+
- S. Reed, A. van den Oord, N. Kalchbrenner, S. Gómez Colmenarejo, Z. Wang, D. Belov, and N. de Freitas. 2017. Parallel multiscale autoregressive density estimation. In ICML .
|
| 255 |
+
- T. Salimans, A. Karpathy, X. Chen, and D. Kingma. 2017. PixelCNN++: Improving the PixelCNN with discretized logistic mixture likelihood and other modifications. In ICLR .
|
| 256 |
+
- M. Schuster and K. Paliwal. 1997. Bidirectional recurrent neural networks. Signal Processing , 45(11):2673-2681.
|
| 257 |
+
- R. Sennrich, B. Haddow, and A. Birch. 2016. Neural machine translation of rare words with subword units. In ACL .
|
| 258 |
+
- N. Srivastava, G. Hinton, A. Krizhevsky, I. Sutskever, and R. Salakhutdinov. 2014. Dropout: A simple way to prevent neural networks from overfitting. JMLR .
|
| 259 |
+
- I. Sutskever, O. Vinyals, and Q. Le. 2014. Sequence to sequence learning with neural networks. In NIPS .
|
| 260 |
+
- A. Vaswani, N. Shazeer, N. Parmar, J. Uszkoreit, L. Jones, A. Gomez, L. Kaiser, and I. Polosukhin. 2017. Attention is all you need. In NIPS .
|
| 261 |
+
21. Shengxian Wan, Yanyan Lan, Jiafeng Guo, Jun Xu, Liang Pang, and Xueqi Cheng. 2016. A deep architecture for semantic matching with multiple positional sentence representations. In AAAI , volume 16, pages 2835-2841.
|
| 262 |
+
- C. Wang, Y. Wang, P.-S. Huang, A. Mohamed, D. Zhou, and L. Deng. 2017. Sequence modeling via segmentations. In ICML .
|
| 263 |
+
- L. Wu, Y. Xia, L. Zhao, F. Tian, T. Qin, J. Lai, and T.-Y . Liu. 2017. Adversarial neural machine translation. arXiv , arXiv:1704.06933.
|
| 264 |
+
24. Yonghui Wu, Mike Schuster, Zhifeng Chen, Quoc V Le, Mohammad Norouzi, Wolfgang Macherey, Maxim Krikun, Yuan Cao, Qin Gao, Klaus Macherey, et al. 2016. Google's neural machine translation system: Bridging the gap between human and machine translation. arXiv preprint arXiv:1609.08144 .
|
| 265 |
+
- K. Xu, J. Ba, R. Kiros, K. Cho, A. Courville, R. Salakhutdinov, R. Zemel, and Y. Bengio. 2015. Show, attend and tell: Neural image caption generation with visual attention. In ICML .
|
text-versions/attention-markdown/1904.02874_An Attentive Survey of Attention Models.md
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
text-versions/attention-markdown/1905.07289_Conversion Prediction Using Multitask Co.md
ADDED
|
@@ -0,0 +1,365 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1905.07289 Conversion Prediction Using Multitask Co
|
| 2 |
+
|
| 3 |
+
## Conversion Prediction Using Multi-task Conditional Attention Networks to Support the Creation of Effective Ad Creatives
|
| 4 |
+
|
| 5 |
+
Shunsuke Kitada Hosei University Tokyo, Japan shunsuke.kitada.8y@stu.hosei.ac.jp
|
| 6 |
+
|
| 7 |
+
## ABSTRACT
|
| 8 |
+
|
| 9 |
+
Accurately predicting conversions in advertisements is generally a challenging task, because such conversions do not occur frequently. In this paper, we propose a new framework to support creating high-performing ad creatives, including the accurate prediction of ad creative text conversions before delivering to the consumer. The proposed framework includes three key ideas: multi-task learning, conditional attention, and attention highlighting. Multi-task learning is an idea for improving the prediction accuracy of conversion, which predicts clicks and conversions simultaneously, to solve the difficulty of data imbalance. Furthermore, conditional attention focuses attention of each ad creative with the consideration of its genre and target gender, thus improving conversion prediction accuracy. Attention highlighting visualizes important words and/or phrases based on conditional attention. We evaluated the proposed framework with actual delivery history data (14,000 creatives displayed more than a certain number of times from Gunosy Inc.), and confirmed that these ideas improve the prediction performance of conversions, and visualize noteworthy words according to the creatives' attributes.
|
| 10 |
+
|
| 11 |
+
## CCS CONCEPTS
|
| 12 |
+
|
| 13 |
+
· Information systems → Online advertising ; · Computing methodologies → Multi-task learning ; Neural networks .
|
| 14 |
+
|
| 15 |
+
## KEYWORDS
|
| 16 |
+
|
| 17 |
+
Online Advertising, Supporting Ad Creative Creation, Recurrent Neural Network, Multi-task Learning, Attention Mechanism
|
| 18 |
+
|
| 19 |
+
## ACMReference Format:
|
| 20 |
+
|
| 21 |
+
Shunsuke Kitada, Hitoshi Iyatomi, and Yoshifumi Seki. 2019. Conversion Prediction Using Multi-task Conditional Attention Networks to Support the Creation of Effective Ad Creatives. In The 25th ACM SIGKDD Conference on Knowledge Discovery and Data Mining (KDD '19), August 48, 2019, Anchorage, AK, USA. ACM, New York, NY, USA, 9 pages. https: //doi.org/10.1145/3292500.3330789
|
| 22 |
+
|
| 23 |
+
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from permissions@acm.org.
|
| 24 |
+
|
| 25 |
+
KDD '19, August 4-8, 2019, Anchorage, AK, USA
|
| 26 |
+
|
| 27 |
+
© 2019 Association for Computing Machinery.
|
| 28 |
+
|
| 29 |
+
ACM ISBN 978-1-4503-6201-6/19/08...$15.00
|
| 30 |
+
|
| 31 |
+
https://doi.org/10.1145/3292500.3330789
|
| 32 |
+
|
| 33 |
+
Hitoshi Iyatomi Hosei University Tokyo, Japan iyatomi@hosei.ac.jp Yoshifumi Seki Gunosy Inc Tokyo, Japan yoshifumi.seki@gunosy.com
|
| 34 |
+
|
| 35 |
+
Figure 1: An example of an ad creative in digital advertising: an ad creative is constructed with an image and two short texts. These short texts are called the title and the description.
|
| 36 |
+
|
| 37 |
+
<!-- image -->
|
| 38 |
+
|
| 39 |
+
## 1 INTRODUCTION
|
| 40 |
+
|
| 41 |
+
In display advertisements, ad creatives, such as images and texts, play an important role in delivering product information to customers efficiently [6]. Figure 1 shows an example of an ad creative which is constructed by two short texts and an image. The performance of these advertisements is generally defined by the revenue of conversions per the cost of the advertisement . Conversions are user actions, such as the purchase of an item or the download of an application, and they represent a known metric that advertisers try to maximize through their ad creatives. The costs of advertisements are generally calculated by the cost per click (CPC), where an advertiser pays for the number of times their advertisement has been clicked. Therefore, the high performance of an ad is determined by minimizing the amount paid for the maximum number of conversions. Creating high-performing ad creatives is a difficult but crucial task for advertisers.
|
| 42 |
+
|
| 43 |
+
The purpose of this study is to supporting the creation of ad creatives with many conversions, and we propose a new framework to support creating high-performing ad creatives, including accurate prediction of ad creative text conversions before delivery to the consumer 1 . If conversions of ad creatives can be predicted before delivery to consumers, advertisers can avoid the losses incurred by the high cost of ineffective advertisements. Moreover, because ad creatives with high click-through rates (CTRs), and low conversions have a tendency to deceive users, we also expect to improve the user experience on media displaying those ads. As a result, advertisers will be able to focus on improving the CTR of ad creatives.
|
| 44 |
+
|
| 45 |
+
∗ This work was conducted while the first author was doing an internship at Gunosy Inc. We thank the ad engineering team who provided useful comments.
|
| 46 |
+
|
| 47 |
+
1 We have also improved the CVR prediction using the result of conversion prediction.
|
| 48 |
+
|
| 49 |
+
Some attempts to support the creation of high-performing creatives by predicting ad creative conversions have been reported in the industry 2,3,4 , but as far as we know, no academic research has been published in this area. Thomaidou et al. [34, 35] proposed a framework for generating ad creatives automatically. However, this framework focuses on search ads, and generates ad text according to set rules. Thus, this framework cannot be applied for our purpose. Some studies have reported that ad creatives affect the CTR of advertisements [1, 3, 8], but they do not predict the conversions. Prediction of a user's CTR or conversion rate (CVR) is a general task undertaken by many studies in this research area, but there are no studies that have predicted these rates for ad creatives. The prediction of an ad creative's performance is another important issue, but to the best of our knowledge, no study has examined this issue.
|
| 50 |
+
|
| 51 |
+
Although ad creatives are mainly image and text, we focus on the latter, and predicting its conversions. Because it is difficult to replace ad images, but easy to replace text, in this work, we propose a recurrent neural network (RNN)-based framework that predicts the performance of an ad creative text before delivery. The proposed framework includes three key ideas, namely, multi-task learning, conditional attention, and attention highlighting. Multi-task learning is an idea for improving the prediction accuracy of conversion, which predicts clicks and conversions simultaneously, to solve the difficulty of data imbalance. Conditional attention focuses on the feature representation of each creative based on its genre and target gender, thus improving conversion prediction accuracy. Attention highlighting visualizes important words and/or phrases based on conditional attention. We confirm that the proposed framework outperforms some baselines, and the proposed ideas are valid for conversion prediction. These ideas are expected to be useful for supporting the creation of ad creatives.
|
| 52 |
+
|
| 53 |
+
This research is motivated to support the creation of high performing creative text. The contributions are summarized as follows:
|
| 54 |
+
|
| 55 |
+
- (1) We propose a new framework that accurately predicts ad creative performance.
|
| 56 |
+
|
| 57 |
+
To realize this, we propose two key strategies to improve the prediction performance of advertisement conversion.
|
| 58 |
+
|
| 59 |
+
- (a) Multi-task learning predicts conversion, together with previous click actions, by learning common feature representations.
|
| 60 |
+
- (b) The Conditional attention mechanism focuses attention on the feature representation of each creative text considering the target gender and genre.
|
| 61 |
+
- (2) We propose attention highlighting that offers important words and/or phrases using conditional attention.
|
| 62 |
+
|
| 63 |
+
A prototype implementation of the proposed framework with Chainer [36] has been released on GitHub 5 .
|
| 64 |
+
|
| 65 |
+
[2 https://www.facebook.com/business/m/facebook-dynamic-creative-ads](https://www.facebook.com/business/m/facebook-dynamic-creative-ads)
|
| 66 |
+
|
| 67 |
+
[3 https://www.adobe.com/en/advertising/creative-management.html](https://www.adobe.com/en/advertising/creative-management.html)
|
| 68 |
+
|
| 69 |
+
[4 https://support.google.com/google-ads/answer/2404190?hl=en](https://support.google.com/google-ads/answer/2404190?hl=en)
|
| 70 |
+
|
| 71 |
+
[5 https://github.com/shunk031/Multi-task-Conditional-Attention-Networks](https://github.com/shunk031/Multi-task-Conditional-Attention-Networks)
|
| 72 |
+
|
| 73 |
+
## 2 RELATED WORK
|
| 74 |
+
|
| 75 |
+
This study focuses on ad creatives. First, we describe existing studies that analyze high-performing ad creatives, and discuss how to generate them. Many studies on advertising creatives focus on images, and offer few results for texts. Furthermore, these studies focus on the CTR, rather than conversions. Second, we introduce studies on performance prediction for ads. In contrast to this study, which aims to predict the performance of new ads, these studies focus on images. Finally, highlighting studies related to our ideas, we introduce multi-task learning and RNN-based attention mechanisms.
|
| 76 |
+
|
| 77 |
+
## 2.1 Analysis and Generation of Effective Advertisements
|
| 78 |
+
|
| 79 |
+
Because ad creatives play an important role in the performance of ads, some studies analyzed ad creative performance [1, 3, 8]. For example, Azimi et al. [1] tried to predict some features of the CTR using ad creative images, and evaluated the effectiveness of visual features. The motivation of their study is similar to ours, but we focus on text instead of images in ad creatives and predict conversions rather than the CTR. Cheng et al. [8] proposed a model for predicting the CTR of new ads, and reported some knowledge using feature importance, but the text features of that study were based on fixed rules. With the development of deep learning, especially convolutional neural networks (CNNs) [21], visual features can be easily and effectively used for machine learning. Chen et al. [7] proposed Deep CTR, showing that using the features of ad images can significantly improve CTR prediction.
|
| 80 |
+
|
| 81 |
+
Thomaidou et al. [34] developed GrammaAds, which automatically generates keywords for search ads. In addition, they proposed an integrated framework for the automated development and optimization of search ads [35]. These studies support the creation of text ad creatives, but because these methods are rule-based, focusing only on search ads, the methods cannot be applied to display advertising.
|
| 82 |
+
|
| 83 |
+
## 2.2 CTR and Conversion Prediction in Display Advertising
|
| 84 |
+
|
| 85 |
+
CTR prediction of display advertising is important not only in the industry but also in academia. In [5, 31], a CTR prediction model was proposed using logistic regression (LR), and factorization machines (FMs) have been proposed to predict advertising performance [18, 19, 30]. In industry, LR and FMs are mainly used, because in display advertising, the prediction response time needs to be short to display an advertisement smoothly. In recent years, deep neural networks (DNNs) have been applied for predicting the advertisement CTR [7, 9, 13, 14, 23], and especially, some models combining DNNs with FMs have been proposed, and have improved predictions [9, 14, 23, 26]. The improvements achieved by these models show that explicit interaction between variables is important for advertisement performance prediction, so we adopted explicit interaction in our idea as a conditional attention mechanism.
|
| 86 |
+
|
| 87 |
+
There are several studies on CVR prediction [27, 29, 39], but there are not as many as the studies on CTR prediction. CVR prediction is difficult, because the number of conversions is imbalanced data that almost ad creative's conversions are zero. Existing studies tackled this difficulty. Yang et al. [40] adopted dynamic transfer learning for predicting the CVR, and demonstrating feature importance. Punjobi et al. [29] proposed robust FMs for overcoming user response noise. In this study, we tackle this difficulty using multi-task learning.
|
| 88 |
+
|
| 89 |
+
## 2.3 Background of the Proposed Strategies
|
| 90 |
+
|
| 91 |
+
In this paper, we propose two key strategies for improving the prediction performance of advertisement conversion, namely, multitask learning and a conditional attention mechanism. As the background of these strategies, we describe multi-task learning and the RNN-based attention mechanism.
|
| 92 |
+
|
| 93 |
+
Multi-task Learning . Multi-task learning [4] is a method that involves learning multiple related tasks. It improves the prediction performance by learning common feature representations. Recently, multi-task learning has been used in various research areas, especially natural language processing (NLP) [12, 28] and computer vision [10, 25, 41], and has achieved significant improvements. Conversions represent extremely imbalanced data, so conversion prediction is difficult. Because ad click actions represent a pre-action of conversion actions, click prediction may be related to conversion prediction. Therefore, we adopt multi-task learning, which predicts clicks and conversions simultaneously.
|
| 94 |
+
|
| 95 |
+
RNN-based Attention Mechanism . For supporting the creation of ad creative text, we use the knowledge of NLP. RNN-based models, such as long short-term memory (LSTM) [16], gated recurrent unit (GRU) [11], and attention mechanisms [2] have made breakthroughs in various NLP tasks, for example, machine translation [2], document classification [24, 40], and image captioning [38]. An RNN is a deep learning model for learning sequential data, and in NLP, this model can learn word order. Attention mechanisms compute an alignment score between two sources, and make significant improvements in some NLP tasks. Recently, self-attention [24], which computes alignment in a single source, was proposed. In addition, visual analysis using attention can highlight important phrases and/or words using the attention result, so the attention mechanism is also attractive for interpretability. In this study, we adopt a self-attention mechanism for improving conversion prediction performance and visualizing word importance.
|
| 96 |
+
|
| 97 |
+
## 3 METHODOLOGY
|
| 98 |
+
|
| 99 |
+
The outline of the proposed framework for evaluating ad creatives is shown in Figure 2. In the framework, we propose two strategies: multi-task learning, which simultaneously predicts conversions and clicks, and a conditional attention mechanism, which detects important representations in ad creative text according to the text's attributes.
|
| 100 |
+
|
| 101 |
+
Conversion prediction using ad creatives with an imbalanced number of conversions is a challenging task. Therefore, in multitask learning, we expect to improve the model accuracy by predicting conversions along with clicks. The conditional attention mechanism makes it possible to dynamically compute attention according to the attributes of the ad creatives, its genre, and the target gender.
|
| 102 |
+
|
| 103 |
+
## 3.1 Framework Overview
|
| 104 |
+
|
| 105 |
+
The input of the proposed framework is ad creative text and ad creative attribute values. Figure 1 shows an example of an ad creative, and these are two short texts which are called titles and descriptions. The ad attribute values are the gender of the delivery target and the genre of the ad creative, and they are related to the ad creatives.
|
| 106 |
+
|
| 107 |
+
Figure 2: Outline of the proposed framework. In the framework, we propose two strategies: multi-task learning, which simultaneously predicts conversions and clicks, and a conditional attention mechanism, which detects important representations in ad creative text according to the text's attributes.
|
| 108 |
+
|
| 109 |
+
<!-- image -->
|
| 110 |
+
|
| 111 |
+
Specifically, the input of the proposed framework is an ad creative text S = { w 1 , w 2 , · · · , w n } consisting of n word embeddings, where w i ∈ R d w represents the word vector at the i -th position in the ad creative text. Therefore, S ∈ R n × d w is a two-dimensional matrix of the word sequence.
|
| 112 |
+
|
| 113 |
+
Incidentally, in the practical situation, a number of ad creative texts that have title and description texts are created for the target product. These texts often have different contexts for maximizing the amount of information empirically. Therefore, the proposed framework uses two text encoders , which learn the individual context from the title and the description.
|
| 114 |
+
|
| 115 |
+
As a text encoder , we adopted the GRU, which can extract features from ad creative text considering word order. Specifically, title text S title = { w title 1 , w title 2 , · · · , w title n } and description text S desc = { w desc 1 , w desc 2 , · · · , w desc n } are input from the ad creative into title and description encoders, respectively, and are encoded into feature representations as h title t ∈ R u title and h desc t ∈ R u desc ; t = 1 , 2 , · · · , n :
|
| 116 |
+
|
| 117 |
+
<!-- formula-not-decoded -->
|
| 118 |
+
|
| 119 |
+
Let u title and u desc be the number of hidden units of the title and description encoders obtained here. The n hidden states can be expressed as H title = { h title 1 , · · · , h title n } and H desc = { h desc 1 , · · · , h desc n } , respectively. Compute a vector x feats that concatenates these hidden states, H title , H desc , one-hot vectors of gender features x gender ∈ R d gender , and genre features x genre ∈ R d genre :
|
| 120 |
+
|
| 121 |
+
<!-- formula-not-decoded -->
|
| 122 |
+
|
| 123 |
+
Note, x feats ∈ R d feats ; d feats = n × ( u title + u desc ) + d gender + d genre. These concatenated vectors are inputted in a multi-layer perceptron (MLP) which is an output layer of the proposed framework. To predict conversions ˆ y (cv) and clicks ˆ y (click) , multi-task learning described later predicted ˆ y multi = { ˆ y (cv) , ˆ y (click) } through the MLP:
|
| 124 |
+
|
| 125 |
+
<!-- formula-not-decoded -->
|
| 126 |
+
|
| 127 |
+
To improve the performance of the model robustness, we use wildcard training [32] with dropout [15] for the input word embeddings.
|
| 128 |
+
|
| 129 |
+
## 3.2 Multi-task Learning
|
| 130 |
+
|
| 131 |
+
Conversion prediction is difficult, due to the imbalanced data, so we use the strategy of multi-task learning. Multi-task learning is a method that solves multiple tasks related to each other, and that improves the prediction performance by learning common feature representations. We adapt multi-task learning, and predict clicks and conversions prediction simultaneously. Because click prediction may be related to conversion prediction, we expect to improve the prediction performance by learning common feature representations using multi-task learning.
|
| 132 |
+
|
| 133 |
+
In multi-task learning, the input is a feature vector of a training sample denoted by x , and the ground truth is y . For training samples x = { x 1 , x 2 , · · · , x N } , a single model, f , learns to generate predictions ˆ y = { ˆ y 1 , ˆ y 2 , · · · , ˆ y N } :
|
| 134 |
+
|
| 135 |
+
<!-- formula-not-decoded -->
|
| 136 |
+
|
| 137 |
+
We minimize the mean squared error (MSE) over all samples, N , in l = 1 N ˝ N i = 1 ( y i -ˆ y i ) 2 . In K supervised tasks, the multi-task model, F = { f 1 , f 2 , · · · , f K } , learns to generate predictions ˆ y = { ˆ y ( 1 ) , ˆ y ( 2 ) , · · · , ˆ y ( K ) } :
|
| 138 |
+
|
| 139 |
+
<!-- formula-not-decoded -->
|
| 140 |
+
|
| 141 |
+
The total loss is calculated from the sum of loss in each task,
|
| 142 |
+
|
| 143 |
+
<!-- formula-not-decoded -->
|
| 144 |
+
|
| 145 |
+
In this task, for ground truth of y (cv) and y (click) , we minimize losses for predicted conversions ˆ y (cv) and clicks ˆ y (click) :
|
| 146 |
+
|
| 147 |
+
<!-- formula-not-decoded -->
|
| 148 |
+
|
| 149 |
+
where λ > 0 is the hyper-parameter to control the effect of the click loss.
|
| 150 |
+
|
| 151 |
+
## 3.3 Conditional Attention
|
| 152 |
+
|
| 153 |
+
We propose the strategy of the conditional attention mechanism. Supporting the creation of ad creatives by considering attribute values is useful, but the conventional attention mechanism learns keywords or key phrases, by calculating the alignment score using only the input sentence.
|
| 154 |
+
|
| 155 |
+
In this paper, we propose a conditional attention mechanism to calculate self-attention, using feature vectors obtained from the attribute values of the ad creative. Figure 3 illustrates the conditional attention mechanism. It can consider ad creative attributes against the conventional attention mechanism.
|
| 156 |
+
|
| 157 |
+
The conditional attention mechanism is calculated from the attention of the text encoder and the feature vector obtained from the attribute values of the ad creative text. Each word in the word sequence S is independent of the others. To capture these word order relations, we apply a text encoder to the text, to obtain the hidden state h t ∈ R u . The n hidden states of these u × n dimensions can be expressed as H = { h 1 , h 2 , · · · , h n } .
|
| 158 |
+
|
| 159 |
+
Figure 3: Example of the conditional attention mechanism. Conditional attention is calculated from the element-wise product of the attention matrix A and the feature vector c consisting of the gender and the genre.
|
| 160 |
+
|
| 161 |
+
<!-- image -->
|
| 162 |
+
|
| 163 |
+
To consider ad attribute values, a conditional vector, c ∈ R n , is calculated by performing a linear combination of x feats ∈ R d feats and trainable parameters W prj ∈ R n × d feats :
|
| 164 |
+
|
| 165 |
+
<!-- formula-not-decoded -->
|
| 166 |
+
|
| 167 |
+
Here, we use self-attention [24] for computing the linear combination. The attention mechanism takes the entire hidden state H of the text encoder as the input and outputs attention vector a :
|
| 168 |
+
|
| 169 |
+
<!-- formula-not-decoded -->
|
| 170 |
+
|
| 171 |
+
where W s 1 ∈ R n × u and w s 2 ∈ R n are trainable parameters. Because H is an n × u dimension, the size of attention vector a is n . The softmax (·) is calculated so that the sum of all the weight is 1.
|
| 172 |
+
|
| 173 |
+
Furthermore, we calculate the conditional attention vector using the attributes given to the ad creative. The conditional attention vector, a cnd , is calculated using conditional vector c and attention vector a :
|
| 174 |
+
|
| 175 |
+
<!-- formula-not-decoded -->
|
| 176 |
+
|
| 177 |
+
Here, ⊙ is an element-wise product. We want r different parts to be extracted from the ad creative texts. Thus, the conditional attention vector a cnd becomes conditional attention matrix A cnd ∈ R n × r . Therefore, sentence vector m with the embedded ad creative text becomes sentence matrix M ∈ R u × r . The conditional attention matrix, A cnd , is multiplied by hidden state H of the text encoder , and the r -weighted sentence matrices are calculated as follows:
|
| 178 |
+
|
| 179 |
+
<!-- formula-not-decoded -->
|
| 180 |
+
|
| 181 |
+
In the proposed framework, the model makes predictions based on the calculated M and ad creative attributes, such as x gender and x genre.
|
| 182 |
+
|
| 183 |
+
Table 1: Features included in the ad creative dataset. It contains 1,694 campaigns, some of which were part of campaigns delivered by Gunosy. The average lengths of the title and description texts are about 15 and, 32 characters, respectively. The Campaign ID feature is not directly inputted in the model, because the ID is used for evaluations with crossvalidation based on the ID.
|
| 184 |
+
|
| 185 |
+
| Features Feature Description Details Campaign ID Campaign ID in Gunosy Ads 1,694 campaigns Texts Title Title texts Avg. 15.44 ± 3.16 chars Description Description texts Avg. 32.69 ± 5.43 chars Attrs Genre Genre of the creatives 20 types Gender Gender of delivery target 3 types |
|
| 186 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 187 |
+
|
| 188 |
+
## 4 EXPERIMENTS
|
| 189 |
+
|
| 190 |
+
## 4.1 Dataset
|
| 191 |
+
|
| 192 |
+
We use real-world data from the Japanese digital advertising program Gunosy Ads 6 , provided by Gunosy Inc. 7 . Gunosy Inc. is a provider of several news delivery applications, and Gunosy Ads delivers digital advertisements for these applications. Gunosy is a news delivery application that achieved more than 24 million downloads in January 2019.
|
| 193 |
+
|
| 194 |
+
For evaluation, we used 14,000 ad creatives delivered by Gunosy Ads from August 2017 to August 2018. In digital advertising, the cost of acquiring a conversion is called the cost per acquisition (CPA). Advertisers set target CPAs for a product, and manage its ad creatives to improve their performance. When the target CPAs for creatives are different, the trend of conversions may also vary, and for this reason, the dataset we selected comprises ad creatives where the target CPA was within a certain range. In addition, we removed creatives with a low number of impressions 8 from the dataset. As shown in Table 1, the title, description, and genre of the ad creative, as well as the gender to which the ad is delivered, are used as input features. Note that the Campaign ID is not a feature directly used as an input in the model, because the ID is used for evaluating with cross-validation based on the ID.
|
| 195 |
+
|
| 196 |
+
Creative texts written in Japanese are split into words using MeCab [22], a morphological analysis engine for Japanese texts, and mecab-ipadic-neologd [37], which is a customized system dictionary that includes many neologisms for MeCab. The number of clicks and conversions is log-normalized.
|
| 197 |
+
|
| 198 |
+
Figure 4 shows a histogram of the number of clicks and conversions. The number of conversions is concentrated on zero, and in relation, the number of clicks is a long-tailed distribution. Therefore, the ad creative dataset is definitely imbalanced. Figure 5 shows the distribution between the number of clicks and conversions in the dataset. The correlation coefficient between the number of clicks and conversions is 0.816, which is a strong correlation. As a reminder, we hide the number of clicks and conversions, also their frequencies, for confidentiality reasons.
|
| 199 |
+
|
| 200 |
+
[6 https://gunosy.co.jp/ad/](https://gunosy.co.jp/ad/)
|
| 201 |
+
|
| 202 |
+
[7 https://gunosy.co.jp/en/](https://gunosy.co.jp/en/)
|
| 203 |
+
|
| 204 |
+
8 Anoccasion when a particular advertisement is seen by someone using the application.
|
| 205 |
+
|
| 206 |
+
<!-- image -->
|
| 207 |
+
|
| 208 |
+
Figure 4: Distribution of clicks and conversions in the dataset. The number of conversions is concentrated on zero. Compared with the number of conversions, the number of clicks indicates a long-tail distribution.
|
| 209 |
+
|
| 210 |
+
<!-- image -->
|
| 211 |
+
|
| 212 |
+
Figure 5: The linear relation between the clicks and conversions in the dataset (correlation coefficient r = 0 . 816 ).
|
| 213 |
+
|
| 214 |
+
## 4.2 Experimental Settings
|
| 215 |
+
|
| 216 |
+
In these experiments, support vector regression (SVR) and an MLPbased text encoder were used as a baseline model. When inputting creative text in the SVR model, we used average-pooled sentence representations computed from word representations, using pretrained word2vec (w2v) [33]. The same pre-trained w2v was used as word embedding for the proposed model.
|
| 217 |
+
|
| 218 |
+
We compared and examined the following models: MLP (not considering word order) and GRU (considering word order) as the text encoder in the proposed framework. LSTM was also considered as a candidate for the baseline model; however, it showed no improvement in performance, so it was excluded from the experiment. In addition, CNNs are known to be capable of training at high speed, because they can perform parallel calculations, compared with LSTM and GRU, and their performances are also known to be equal. Nevertheless, these methods were excluded in these experiments, because we were targeting an RNN-based model that can apply attention for visualizing the contributions of words to ad creative evaluation.
|
| 219 |
+
|
| 220 |
+
Table 2: Comparison of the prediction performance of CVs in mean squared error (MSE) criteria. The proposed multi-task learning and conditional attention reduced MSE in almost all the categories, especially estimating cases where the number of conversions (#CV) is one or more ( #CV > 0 ). However, 'All predicted as zero' showed sufficiently low MSE in this category, due to too many CV = 0 in this dataset. Therefore, we conclude using MSE as an evaluation metric is not suitable in this study.
|
| 221 |
+
|
| 222 |
+
| Model MSE All #CV >0 Single-task Multi-task Single-task Multi-task MLP 0.01712 0.01698 0.04735 0.03199 GRU Vanilla 0.01696 0.01695 0.04657 0.04355 Attention 0.01685 0.01688 0.04695 0.03105 Conditional attention 0.01683 0.01675 0.04641 0.02825 All predicted as zero 0.02148 - |
|
| 223 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 224 |
+
|
| 225 |
+
We compared the proposed models used in the proposed framework. The following models were compared and examined, to confirm the effect of multi-task learning in conversion prediction:
|
| 226 |
+
|
| 227 |
+
- Single-task: A commonly known model that predicts conversions only; and
|
| 228 |
+
- Multi-task: A model that simultaneously predicts the number of clicks and the number of conversions.
|
| 229 |
+
|
| 230 |
+
To confirm the effect of the conditional attention mechanism, we compared the following models:
|
| 231 |
+
|
| 232 |
+
- Vanilla: A simple text encoder without an attention mechanism. It is a baseline in the proposed model;
|
| 233 |
+
- Attention: A mechanism that introduces self-attention to the text encoder . It makes it possible to visualize which word contributed to prediction during creative evaluation; and
|
| 234 |
+
- Conditional Attention: A mechanism introduced to the text encoder of the proposed method. Conditional attention can be computed and visualized considering the attribute values of the ad creative. Different attentions can be visualized by changing the attribute value for the same creative text.
|
| 235 |
+
|
| 236 |
+
In addition, the hyper-parameter setting is described below. The mini-batch size was set to be 64, and the number of epochs was set to be 50. For multi-task learning, we used a fixed value of λ = 1. In the text encoder , the number of hidden units was set to be 200 for u title and u desc . For all models, we use Adam [20], with a weight decay of 1e -4 , for parameter optimization.
|
| 237 |
+
|
| 238 |
+
## 4.3 Evaluation Metrics
|
| 239 |
+
|
| 240 |
+
First, as evaluation metrics, we adopt not only MSE but also normalized discounted cumulative gain (NDCG) [17], which is evaluation metrics for ranking. MSE measures the average of the squares of the errors, which is the average squared difference between the estimated values and what is estimated. We adopted ranking evaluation metrics because the number of conversions is imbalanced. As shown in Figure 4, most ad creative conversions are zero and imbalanced. A high evaluation score can be achieved by an overfit model that predicts all outputs as zero when such metrics are used. For the creation of high-performing ad creatives, rather than predicting zero conversions, we would like to accurately predict high-conversion creatives as such.
|
| 241 |
+
|
| 242 |
+
NDCG is mainly used in the experiments. NDCG is the discounted cumulative gain (DCG) normalized score. In DCG, the score decreases as the evaluation of an advertisement declines, so a penalty is imposed if a low effect is predicted for highly effective creatives. At the time of the NDCG calculation, after obtaining the rank of the ground truth, and its predicted value, respectively, evaluation scores are calculated for all the evaluation data, as well as those restricted to the top 1% of conversions.
|
| 243 |
+
|
| 244 |
+
For ad creative evaluation, the metrics are computed with crossvalidation. In most advertising systems, advertisements are delivered in units of campaigns. In a campaign, the target gender and its genre are set, and multiple ad creatives are developed.
|
| 245 |
+
|
| 246 |
+
In this paper, we predict the number of conversions for ad creative text in unknown campaigns, and confirm the generalization performance of the proposed framework. Therefore, at the time of the evaluation, five-fold cross-validation was performed in such a manner that the delivered campaigns did not overlap.
|
| 247 |
+
|
| 248 |
+
## 4.4 Experimental Results
|
| 249 |
+
|
| 250 |
+
For confirming the accuracy of the proposed framework compared with the baselines, we compared single-task and multi-task learning, and the results of the application of the conditional attention mechanism are described. Through almost all the results, the proposed framework applying multi-task learning and the conditional attention mechanism achieved a better performance than the other methods. Especially, when focusing on ad creatives with many conversions, the proposed framework achieved high prediction accuracy.
|
| 251 |
+
|
| 252 |
+
Table 2 shows the MSE score with all the evaluations in each model, and with one or more conversions in each model. Almost all the results show that the model applying the multi-task learning and conditional attention mechanism had a smaller MSE score than the other models did. Overall, the RNN-based GRU showed better performance than the baseline models. Therefore, the results suggest that it is important to properly capture word order when evaluating creative texts. Compared with vanilla and attention , in the proposed model, conditional attention showed a better performance.
|
| 253 |
+
|
| 254 |
+
Although the improvement of all datasets is weak, because as shown in Figure 4, the number of conversions of many ad creatives is zero, the MSE is small, even if the conversion of most ad creatives is predicted to be zero. Therefore, we evaluated data with conversions other than zero. As a result, we found that the proposed model exhibits much better performance than the baseline model for data with one or more conversions. The proposed model was able to predict creatives with more conversions than the baseline models.
|
| 255 |
+
|
| 256 |
+
Table 3: Comparison of the normalized discounted cumulative gain (NDCG) in the proposed model. When calculating NDCG scores, the results for all data and the scores restricted to the top 1% of conversions (#CV) were calculated.
|
| 257 |
+
|
| 258 |
+
| Model NDCG [%] All #CV top 1 % single multi-task single multi-task SVM 96.72 83.73 MLP 96.68 97.18 82.97 84.12 GRU Vanilla 96.54 97.00 76.39 78.51 Attention 96.76 97.11 83.00 85.49 Conditional Attention 96.77 97.20 87.11 87.14 |
|
| 259 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 260 |
+
|
| 261 |
+
Table 4: Comparison of NDCG between the CVR directly predicted by the single-task model and the CVR (#conversions / #clicks) calculated from the multi-task GRU model's predicted conversions and clicks. The threshold value for calculating NDCG is assumed to be a CVR of 0.5 or more.
|
| 262 |
+
|
| 263 |
+
| Model NDCG [%] Single-task Vanilla 80.54 Attention 82.58 Conditional attention 83.89 Multi-task Vanilla 82.63 Attention 84.27 Conditional attention 85.61 |
|
| 264 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 265 |
+
|
| 266 |
+
To evaluate ad creatives with many conversions as such, we used the ranking algorithm NDCG. The NDCG result in the proposed model is shown in Table 3 9 . The NDCG score (regarded as All in Table 3) for all the datasets is shown for reference, because as noted above, most samples have zero conversions. The performance of the GRU model that considers word order compared with the baseline model improved by an average of approximately 3-5%, with many conversions.
|
| 267 |
+
|
| 268 |
+
In the NDCG result (Table 3), the multi-task model realized higher prediction accuracy than the single-task model predicting only conversions did. A score improvement of approximately 12% was confirmed when compared with the baselines. Because clicks are highly correlated with target ad conversions, as shown in Figure 5, rather than predicting conversions alone, training the model to multi-task by predicting clicks simultaneously can improve prediction accuracy. By training clicks and conversions, the proposed model seems to implicitly learn features that contribute to conversion prediction.
|
| 269 |
+
|
| 270 |
+
9 The same tendency was observed even when mean average precision (MAP) was used as an evaluation metric.
|
| 271 |
+
|
| 272 |
+
Table 5: Comparison of GRU models for creative texts and their attribute value interactions. Performance is improved using conditional attention rather than giving attribute values directly to word vectors.
|
| 273 |
+
|
| 274 |
+
| Model NDCG [%] Single-task Multi-task w2v + attributes Vanilla 77.84 78.03 Attention 80.39 83.52 w2v Conditional attention 87.11 87.14 |
|
| 275 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 276 |
+
|
| 277 |
+
Because several previous studies predicted the CVR directly, we also calculated it, using the prediction of the multi-task learning model, and compared the accuracy. In a multi-task model, the CVR can be calculated by dividing conversions by clicks. In Table 4, the multi-task model is compared with the single-task model by directly estimating the CVR. The prediction performance of the multi-task model is higher than that of the single-task model. Although the number of clicks and conversions predicted by multi-task learning may not always be close to the ground truth, the ratio of the number of clicks to the conversion number is captured properly.
|
| 278 |
+
|
| 279 |
+
In Table 3, the conditional attention mechanism achieved better results the NDCG metric. In particular, the conditional attention mechanism showed better results than the conventional attention mechanism did. In the conventional attention mechanism, the training was focused solely on the co-occurrence relation between words in the input text, but the conditional attention mechanism can predict conversion by using the attribute value.
|
| 280 |
+
|
| 281 |
+
Table 5 shows the result comparing feature interaction between w2v-based embeddings and ad attribute values. In the proposed framework, this interaction is realized with the conditional attention mechanism, explicitly. Because attention is computed by the input variables, this interaction is implicitly expressed by inputting both variables in the text encoder . For confirming the effect of this explicit interaction in the conditional attention mechanism, we compared the model that inputted both variables in the text encoder with the conditional attention mechanism. The conditional attention mechanism showed the best performance in the singletask and multi-task model. Introducing the vanilla model and the conventional attention model to the word representation with ad attribute values resulted in a poor performance, mainly because the duplicate interactions were calculated excessively. It is suggested that it is better to introduce the explicit interaction of attribute values.
|
| 282 |
+
|
| 283 |
+
## 5 DISCUSSION
|
| 284 |
+
|
| 285 |
+
## 5.1 Advantages of the Proposed Framework
|
| 286 |
+
|
| 287 |
+
The proposed framework aimed to predict not the CVR but conversions. However, in CVR prediction, we also achieved high performance using multi-task learning results. From the business perspective, we assume that predicting conversions can evaluate highperforming ad creatives, rather than predicting the CVR. In the process of advertising management, advertisers stop low-performing creatives and focus cost on high-performing creatives, so there are few conversions of low-performing creatives, and many conversions of high-performing creatives. For that reason, the number of conversions seems to be a good metric for evaluating ad creatives, and conversion prediction may be learn good representation of high-performing ad creatives.
|
| 288 |
+
|
| 289 |
+
We proposed an RNN-based framework, and achieved highperformance conversion prediction. Normally, when advertisers create the creative text, words are selected in such a way as to change the word order or emphasize the characteristics of the product. We let the model learn feature representation so that it could properly capture the features between words in creative text.
|
| 290 |
+
|
| 291 |
+
Weachieved high-performance conversion prediction by predicting the clicks and conversions simultaneously; this method is called multi-task learning. Many ad creative conversions are zero, which is imbalanced data, so predicting this number correctly is a difficult task. Multi-task learning is a method that learns multiple tasks related to each other, and improves prediction performance. Because ad click actions represent the pre-action of conversion actions, we assumed that click prediction may be related to conversion prediction, and that improved conversion prediction would be obtained using multi-task learning. We expect that this achievement can be applied to various prediction tasks with imbalanced data.
|
| 292 |
+
|
| 293 |
+
High accuracy was achieved by conditional attention in the experiment. When predicting the CTR or CVR of advertisements, it is important to properly capture the explicit feature interactions [23]. The conditional attention mechanism seems to capture the explicit interactions between the attention gained from creative text and feature representations consisting of the text's attribute values. It is also possible to visualize different forms of attention by controlling different attribute values in the same creative texts. This can greatly support ad creative creation.
|
| 294 |
+
|
| 295 |
+
## 5.2 Visualization for High-Performance Ad Creative Creation
|
| 296 |
+
|
| 297 |
+
We attempt to highlight important words using attention. If the words contributing to conversions are clarified, advertisers will be able to easily create high-performing ad creatives. Attention is a mechanism that focuses on words contributing to prediction, and the results predicted by these mechanisms are useful for creating ad creatives. The proposed conditional attention mechanism can compute attention based on ad creative attributes, as well as the genre and target gender, so conditional attention highlights important words according to their attribute values.
|
| 298 |
+
|
| 299 |
+
(a) Title text: "Chosen by 10 million people! The 10 games played by everyone." Description text: "Exclusively introducing free games that you will want to install on mobile phone."
|
| 300 |
+
|
| 301 |
+
(b) Title text: "Success in -10 kg weight loss! This is the reason for getting slim." Description text: "Realizing the effects popular among girls."
|
| 302 |
+
|
| 303 |
+
(c) Title text: "Supervised by a famous celebrity; easy cookbook." Description text: "Recommended for men living alone!"
|
| 304 |
+
|
| 305 |
+
Figure 6: Heatmap showing the change in conditional attention when the distribution target is changed.
|
| 306 |
+
|
| 307 |
+
Figure 6 shows examples of the visualization of attention when modifying the attributes of gender for three Japanese ad creative texts for different groups (for all audiences, for women, and for men). Different types of attention were gained using conditional attention mechanism.
|
| 308 |
+
|
| 309 |
+
Figure 6a shows an ad creative for a mobile game. The word '1000 万 ' ( 10 million ), a concrete numerical value, and the word ' 限 定 ' ( exclusively ) contribute to predicting conversion. Especially for men, the word ' 限 定 ' contributes more to the prediction than it does for women.
|
| 310 |
+
|
| 311 |
+
Figure 6b is an ad creative in the beauty genre for women. The word ' 女性 ' ( girls ) contributes to the conversion prediction. More attention is also given to ' ダイエット ' ( weight loss ) for women than men. When setting the delivery target to men in this ad creative, the attention score and the number of predicted conversions are smaller than that of all targets or female targets.
|
| 312 |
+
|
| 313 |
+
Figure 6c is an ad creative in the health food genre for men. The words ' 一 人 暮 らし ' ( living alone ) and ' 監 修 ' ( supervised by ) are closely highlighted. The word 'lived alone' is an expression that narrows down the delivery target. When proposing ad creative text, the term 'supervised by' is often used in conjunction with the names of celebrities, and the effect is high. Moreover, it was confirmed that the word ' 男 性 ' ( men ) is an important factor when the delivery target is male.
|
| 314 |
+
|
| 315 |
+
Overall, most words that are highlighted by attention are concrete numerical values and expressions focusing on the delivery target. We believe that this knowledge is also empirically correct. In this way, visualization of important words using the conditional attention mechanism of the proposed method can be expected to greatly contribute to supporting the creation of ad creatives. This result is a good example of interpretability.
|
| 316 |
+
|
| 317 |
+
## 6 CONCLUSION
|
| 318 |
+
|
| 319 |
+
In this paper, we propose a new framework to support the creation of high-performing ad creative text. The proposed framework includes three key ideas, multi-task learning and conditional attention improve prediction performance of advertisement conversion, and attention highlighting offers important words and/or phrases in text creatives. We confirmed that the proposed framework realizes an excellent performance thanks to these ideas, through experiments with actual delivery history data.
|
| 320 |
+
|
| 321 |
+
In the future, we will build a framework that simultaneously uses images attached to ad creatives, and aim to improve the accuracy of conversion prediction.
|
| 322 |
+
|
| 323 |
+
## REFERENCES
|
| 324 |
+
|
| 325 |
+
- [1] Javad Azimi, Ruofei Zhang, Yang Zhou, Vidhya Navalpakkam, Jianchang Mao, and Xiaoli Fern. 2012. Visual Appearance of Display Ads and Its Effect on Click Through Rate. In Proceedings of the 21st ACM International Conference on Information and Knowledge Management . 495-504.
|
| 326 |
+
- [2] Dzmitry Bahdanau, Kyunghyun Cho, and Yoshua Bengio. 2014. Neural machine translation by jointly learning to align and translate. International Conference on Learning Representations (2014).
|
| 327 |
+
- [3] Norris I Bruce, BPS Murthi, and Ram C Rao. 2017. A dynamic model for digital advertising: The effects of creative format, message content, and targeting on engagement. Journal of marketing research 54, 2 (2017), 202-218.
|
| 328 |
+
- [4] Rich Caruana. 1997. Multitask learning. Machine learning 28, 1 (1997), 41-75.
|
| 329 |
+
- [5] Deepayan Chakrabarti, Deepak Agarwal, and Vanja Josifovski. 2008. Contextual advertising by combining relevance with click feedback. In Proceedings of the 17th international conference on World Wide Web . 417-426.
|
| 330 |
+
- [6] Olivier Chapelle, Eren Manavoglu, and Romer Rosales. 2015. Simple and scalable response prediction for display advertising. ACM Transactions on Intelligent Systems and Technology (TIST) 5, 4 (2015), 61.
|
| 331 |
+
- [7] Junxuan Chen, Baigui Sun, Hao Li, Hongtao Lu, and Xian-Sheng Hua. 2016. Deep ctr prediction in display advertising. In Proceedings of the 2016 ACM on Multimedia Conference . 811-820.
|
| 332 |
+
- [8] Haibin Cheng, Roelof van Zwol, Javad Azimi, Eren Manavoglu, Ruofei Zhang, Yang Zhou, and Vidhya Navalpakkam. 2012. Multimedia features for click prediction of new ads in display advertising. In Proceedings of the 18th ACM SIGKDD international conference on Knowledge discovery and data mining . 777-785.
|
| 333 |
+
- [9] Heng-Tze Cheng, Levent Koc, Jeremiah Harmsen, Tal Shaked, Tushar Chandra, Hrishi Aradhye, Glen Anderson, Greg Corrado, Wei Chai, Mustafa Ispir, et al. 2016. Wide & deep learning for recommender systems. In Proc. of the 1st Workshop on Deep Learning for Recommender Systems . 7-10.
|
| 334 |
+
- [10] Xiao Chu, Wanli Ouyang, Wei Yang, and Xiaogang Wang. 2015. Multi-task recurrent neural network for immediacy prediction. In Proc. of the IEEE international conference on computer vision . 3352-3360.
|
| 335 |
+
- [11] Junyoung Chung, Caglar Gulcehre, KyungHyun Cho, and Yoshua Bengio. 2014. Empirical evaluation of gated recurrent neural networks on sequence modeling. In Advances in neural information processing systems Workshop .
|
| 336 |
+
- [12] Ronan Collobert, Jason Weston, Léon Bottou, Michael Karlen, Koray Kavukcuoglu, and Pavel Kuksa. 2011. Natural language processing (almost) from scratch. Journal of Machine Learning Research 12, 8 (2011), 2493-2537.
|
| 337 |
+
- [13] Paul Covington, Jay Adams, and Emre Sargin. 2016. Deep neural networks for youtube recommendations. In Proc. of the 10th ACM Conference on Recommender Systems . 191-198.
|
| 338 |
+
- [14] Huifeng Guo, Ruiming Tang, Yunming Ye, Zhenguo Li, and Xiuqiang He. 2014. Deepfm: a factorization-machine based neural network for ctr prediction. CoRR arXiv:1703.04247 (2014).
|
| 339 |
+
- [15] Geoffrey E Hinton, Nitish Srivastava, Alex Krizhevsky, Ilya Sutskever, and Ruslan R Salakhutdinov. 2012. Improving neural networks by preventing coadaptation of feature detectors. CoRR arXiv:1207.0580 (2012).
|
| 340 |
+
- [16] Sepp Hochreiter and Jürgen Schmidhuber. 1997. Long short-term memory. Neural computation 9, 8 (1997), 1735-1780.
|
| 341 |
+
- [17] Kalervo Järvelin and Jaana Kekäläinen. 2002. Cumulated Gain-based Evaluation of IR Techniques. ACM Trans. Inf. Syst. 20, 4 (2002), 422-446.
|
| 342 |
+
- [18] Yuchin Juan, Damien Lefortier, and Olivier Chapelle. 2017. Field-aware factorization machines in a real-world online advertising system. In Proc. of the 26th International Conference on World Wide Web Companion . 680-688.
|
| 343 |
+
- [19] Yuchin Juan, Yong Zhuang, Wei-Sheng Chin, and Chih-Jen Lin. 2016. Field-aware factorization machines for CTR prediction. In Proc. of the 10th ACM Conference on Recommender Systems . 43-50.
|
| 344 |
+
- [20] Diederik P Kingma and Jimmy Ba. 2014. Adam: A method for stochastic optimization. CoRR arXiv:1412.6980 (2014).
|
| 345 |
+
- [21] Alex Krizhevsky, Ilya Sutskever, and Geoffrey E Hinton. 2012. Imagenet classification with deep convolutional neural networks. In Advances in neural information processing systems . 1097-1105.
|
| 346 |
+
- [22] Taku Kudo. 2006. Mecab: Yet another part-of-speech and morphological analyzer. http://mecab.sourceforge.jp .
|
| 347 |
+
- [23] Jianxun Lian, Xiaohuan Zhou, Fuzheng Zhang, Zhongxia Chen, Xing Xie, and Guangzhong Sun. 2018. xDeepFM: Combining Explicit and Implicit Feature Interactions for Recommender Systems. In Proc. of the 24th ACM SIGKDD International Conference on Knowledge Discovery and Data Mining .
|
| 348 |
+
- [24] Zhouhan Lin, Minwei Feng, Cicero Nogueira dos Santos, Mo Yu, Bing Xiang, Bowen Zhou, and Yoshua Bengio. 2017. A structured self-attentive sentence embedding. International Conference on Learning Representations (2017).
|
| 349 |
+
- [25] Wu Liu, Tao Mei, Yongdong Zhang, Cherry Che, and Jiebo Luo. 2015. Multi-task deep visual-semantic embedding for video thumbnail selection. In Proc. of the IEEE Conference on Computer Vision and Pattern Recognition . 3707-3715.
|
| 350 |
+
- [26] Weiwen Liu, Ruiming Tang, Jiajin Li, Jinkai Yu, Huifeng Guo, Xiuqiang He, and Shengyu Zhang. 2018. Field-aware Probabilistic Embedding Neural Network for CTR Prediction. In Proc. of the 12th ACM Conference on Recommender Systems . 412-416.
|
| 351 |
+
- [27] Quan Lu, Shengjun Pan, Liang Wang, Junwei Pan, Fengdan Wan, and Hongxia Yang. 2017. A Practical Framework of Conversion Rate Prediction for Online Display Advertising. In Proc. of the ADKDD'17 . 9:1-9:9.
|
| 352 |
+
- [28] Thang Luong, Quoc V. Le, Ilya Sutskever, Oriol Vinyals, and Lukasz Kaiser. 2016. Multi-task Sequence to Sequence Learning. In International Conference on Learning Representations .
|
| 353 |
+
- [29] Surabhi Punjabi and Priyanka Bhatt. 2018. Robust Factorization Machines for User Response Prediction. In Proc. of the 2018 World Wide Web Conference . 669-678.
|
| 354 |
+
- [30] Steffen Rendle. 2010. Factorization machines. In Data Mining (ICDM), 2010 IEEE 10th International Conference on . 995-1000.
|
| 355 |
+
- [31] Matthew Richardson, Ewa Dominowska, and Robert Ragno. 2007. Predicting Clicks: Estimating the Click-Through Rate for New Ads. In Proc. of the 16th International World Wide Web Conference(WWW-2007) .
|
| 356 |
+
- [32] Daiki Shimada, Ryunosuke Kotani, and Hitoshi Iyatomi. 2016. Document classification through image-based character embedding and wildcard training. In Big Data (Big Data), 2016 IEEE International Conference on . 3922-3927.
|
| 357 |
+
- [33] Masatoshi Suzuki, Koji Matsuda, Satoshi Sekine, Naoaki Okazaki, and Kentaro Inui. 2018. A Joint Neural Model for Fine-Grained Named Entity Classification of Wikipedia Articles. IEICE Transactions on Information and Systems E101.D, 1 (2018), 73-81.
|
| 358 |
+
- [34] Stamatina Thomaidou, Konstantinos Leymonis, and Michalis Vazirgiannis. 2013. GrammAds: Keyword and ad creative generator for online advertising campaigns. In Digital Enterprise Design and Management 2013 . 33-44.
|
| 359 |
+
- [35] Stamatina Thomaidou, Kyriakos Liakopoulos, and Michalis Vazirgiannis. 2014. Toward an integrated framework for automated development and optimization of online advertising campaigns. Intelligent Data Analysis 18, 6 (2014), 1199-1227.
|
| 360 |
+
- [36] Seiya Tokui, Kenta Oono, Shohei Hido, and Justin Clayton. 2015. Chainer: a Next-Generation Open Source Framework for Deep Learning. In Proceedings of Workshop on Machine Learning Systems (LearningSys) in The Twenty-ninth Annual Conference on Neural Information Processing Systems (NIPS) . http://learningsys. org/papers/LearningSys\_2015\_paper\_33.pdf
|
| 361 |
+
- [37] Sato Toshinori. 2015. Neologism dictionary based on the language resources on the Web for Mecab. https://github.com/neologd/mecab-ipadic-neologd
|
| 362 |
+
- [38] Kelvin Xu, Jimmy Ba, Ryan Kiros, Kyunghyun Cho, Aaron Courville, Ruslan Salakhudinov, Rich Zemel, and Yoshua Bengio. [n. d.]. Show, attend and tell: Neural image caption generation with visual attention. In International conference on machine learning . 2048-2057.
|
| 363 |
+
- [39] Hongxia Yang, Quan Lu, Angus Xianen Qiu, and Chun Han. 2016. Large Scale CVRPrediction through Dynamic Transfer Learning of Global and Local Features. In Proc. of the 5th International Workshop on Big Data, Streams and Heterogeneous Source Mining: Algorithms, Systems, Programming Models and Applications at KDD 2016 . 103-119.
|
| 364 |
+
- [40] Zichao Yang, Diyi Yang, Chris Dyer, Xiaodong He, Alex Smola, and Eduard Hovy. 2016. Hierarchical attention networks for document classification. In Proc. of the 2016 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies . 1480-1489.
|
| 365 |
+
- [41] Zhanpeng Zhang, Ping Luo, Chen Change Loy, and Xiaoou Tang. 2014. Facial landmark detection by deep multi-task learning. In European Conference on Computer Vision . 94-108.
|
text-versions/attention-markdown/1905.13497_Attention Is not All You Need for Common.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1905.13497 Attention Is Not All You Need For Common
|
| 2 |
+
|
| 3 |
+
## Attention Is (not) All You Need for Commonsense Reasoning
|
| 4 |
+
|
| 5 |
+
Tassilo Klein 1 , Moin Nabi 1
|
| 6 |
+
|
| 7 |
+
1 SAP Machine Learning Research, Berlin, Germany
|
| 8 |
+
|
| 9 |
+
{ tassilo.klein, m.nabi } @sap.com
|
| 10 |
+
|
| 11 |
+
## Abstract
|
| 12 |
+
|
| 13 |
+
The recently introduced BERT model exhibits strong performance on several language understanding benchmarks. In this paper, we describe a simple re-implementation of BERT for commonsense reasoning. We show that the attentions produced by BERT can be directly utilized for tasks such as the Pronoun Disambiguation Problem and Winograd Schema Challenge . Our proposed attention-guided commonsense reasoning method is conceptually simple yet empirically powerful. Experimental analysis on multiple datasets demonstrates that our proposed system performs remarkably well on all cases while outperforming the previously reported state of the art by a margin. While results suggest that BERT seems to implicitly learn to establish complex relationships between entities, solving commonsense reasoning tasks might require more than unsupervised models learned from huge text corpora.
|
| 14 |
+
|
| 15 |
+
## 1 Introduction
|
| 16 |
+
|
| 17 |
+
Recently, neural models pre-trained on a language modeling task, such as ELMo (Peters et al., 2018b), OpenAI GPT (Radford et al., 2018), and BERT (Devlin et al., 2018), have achieved impressive results on various natural language processing tasks such as question-answering and natural language inference. The success of BERT can largely be associated to the notion of context-aware word embeddings, which differentiate it from common approaches such as word2vec (Mikolov et al., 2013) that establish a static semantic embedding. Since the introduction of BERT, the NLP community continues to be impressed by the amount of ideas produced on top of this powerful language representation model. However, despite its success, it remains unclear whether the representations produced by BERT can be utilized for tasks such as commonsense reasoning. Particularly, it is not clear whether BERT shed light on solving tasks such as the Pronoun Disambiguation Problem (PDP) and Winograd Schema Challenge (WSC). These tasks have been proposed as potential alternatives to the Turing Test, because they are formulated to be robust to statistics of word co-occurrence (Levesque et al., 2012).
|
| 18 |
+
|
| 19 |
+
Below is a popular example from the binarychoice pronoun coreference problem (Lee et al., 2017) of WSC:
|
| 20 |
+
|
| 21 |
+
Sentence: The trophy doesn't fit in the suitcase because it is too small.
|
| 22 |
+
|
| 23 |
+
Answers: A) the trophy B) the suitcase
|
| 24 |
+
|
| 25 |
+
Humans resolve the pronoun 'it' to 'the suitcase' with no difficulty, whereas a system without commonsense reasoning would be unable to distinguish 'the suitcase' from the otherwise viable candidate, 'the trophy'.
|
| 26 |
+
|
| 27 |
+
Previous attempts at solving WSC usually involve heavy utilization of annotated knowledge bases (KB), rule-based reasoning, or hand-crafted features (Peng et al., 2015; Bailey et al., 2015; Sch¨ uller, 2014; Sharma et al., 2015; Morgenstern et al., 2016). There are also some empirical works towards solving WSC making use of learning (Rahman and Ng, 2012; Tang et al., 2018; Radford et al., 2018). Recently, (Trinh and Le, 2018) proposed to use a language model (LM) to score the two sentences obtained when replacing the pronoun by the two candidates. The sentence that is assigned higher probability under the model designates the chosen candidate. Probability is calculated via the chain rule, as the product of the probabilities assigned to each word in the sentence. Very recently, (Emami et al., 2018) proposed the knowledge hunting method, which is a rule-based system that uses search engines to gather evidence for the candidate resolutions without relying on the entities themselves. Although these methods are interesting, they need fine-tuning, or explicit substitution or heuristicbased rules. See also (Trichelair et al., 2018) for a discussion.
|
| 28 |
+
|
| 29 |
+
Figure 1: Maximum Attention Score (MAS) for a particular sentence, where colors show attention maps for different words (best shown in color). Squares with blue/red frames correspond to specific sliced attentions A c for candidates c , establishing the relationship to the reference pronoun indicated with green. Attention is color-coded in blue/ red for candidates 'trophy'/ 'suitcase'; the associated pronoun 'it' is indicated in green. Attention values are compared elementwise (black double arrow), and retain only the maximum achieved by a masking operation. Matrices on the outside with red background elements correspond to the masked attentions A c ◦ M c .
|
| 30 |
+
|
| 31 |
+
<!-- image -->
|
| 32 |
+
|
| 33 |
+
The BERT model is based on the 'Transformer' architecture (Vaswani et al., 2017), which relies purely on attention mechanisms, and does not have an explicit notion of word order beyond marking each word with its absolute-position embedding. This reliance on attention may lead one to expect decreased performance on commonsense reasoning tasks (Roemmele et al., 2011; Zellers et al., 2018) compared to RNN (LSTM) models (Hochreiter and Schmidhuber, 1997) that do model word order directly, and explicitly track states across the sentence. However, the work of (Peters et al., 2018a) suggests that bidirectional language models such as BERT implicitly capture some notion of coreference resolution.
|
| 34 |
+
|
| 35 |
+
In this paper, we show that the attention maps created by an out-of-the-box BERT can be directly exploited to resolve coreferences in long sentences. As such, they can be simply repurposed for the sake of commonsense reasoning tasks while achieving state-of-the-art results on the multiple task. On both PDP and WSC, our method outperforms previous state-of-the-art methods, without using expensive annotated knowledge bases or hand-engineered features. On a Pronoun Disambiguation dataset, PDP-60, our method achieves 68.3% accuracy, which is better than the state-ofart accuracy of 66.7%. On a WSC dataset, WSC273, our method achieves 60.3%. As of today, state-of-the-art accuracy on the WSC-273 for single model performance is around 57%, (Emami et al., 2018) and (Trinh and Le, 2018). These results suggest that BERT implicitly learns to establish complex relationships between entities such as coreference resolution. Although this helps in commonsense reasoning, solving this task requires more than employing a language model learned from large text corpora.
|
| 36 |
+
|
| 37 |
+
## 2 Attention Guided Reasoning
|
| 38 |
+
|
| 39 |
+
In this section we first review the main aspects of the BERT approach, which are important to understand our proposal and we introduce notations used in the rest of the paper. Then, we introduce Maximum Attention Score (MAS), and explain how it can be utilized for commonsense reasoning.
|
| 40 |
+
|
| 41 |
+
## 2.1 BERT and Notation
|
| 42 |
+
|
| 43 |
+
The concept of BERT is built upon two key ingredients: (a) the transformer architecture and (b) unsupervised pre-training.
|
| 44 |
+
|
| 45 |
+
The transformer architecture consists of two main building blocks, stacked encoders and de- coders, which are connected in a cascaded fashion. The encoder is further divided into two components, namely a self-attention layer and a feedforward neural network. The self-attention allows for attending to specific words during encoding and therefore establishing a focus context w.r.t. to each word. In contrast to that, the decoder has an additional encoder-decoder layer that switches between self-attention and a feed-forward network. It allows the decoder to attend to specific parts of the input sequence. As attention allows for establishing a relationship between words, it is very important for tasks such as coreference resolution and finding associations. In the specific context of pronouns, attention gives rise to links to m candidate nouns, which we denote in the following as C = { c 1 , .., c m } . The concept of self-attention is further expanded within BERT by the idea of so called multi-head outputs that are incorporated in each layer. In the following, we will denote heads and layers with h ∈ H and l ∈ L , respectively. Multi-heads serve several purposes. On the one hand, they allow for dispersing the focus on multiple positions. On the other hand, they constitute an enriched representation by expanding the embedding space. Leveraging the nearly unlimited amount of data available, BERT learns two novel unsupervised prediction tasks during training. One of the tasks is to predict tokens that were randomly masked given the context, notably with the context being established in a bi-directional manner. The second task constitutes next sentence prediction, whereby BERT learns the relationship between two sentences, and classifies whether they are consecutive.
|
| 46 |
+
|
| 47 |
+
Table 1: Pronoun Disambiguation Problem: Results on (top) Unsupervised method performance on PDP-60 and (bottom) Supervised method performance on PDP-60. Results other than ours are taken from (Trinh and Le, 2018).
|
| 48 |
+
|
| 49 |
+
| Method Accuracy Unsupervised Semantic Similarity Method (USSM) 48.3 % USSM + Cause-Effect Knowledge Base (Liu et al., 2016) 55.0 % USSM + Cause-Effect + WordNet (Miller, 1995) + ConceptNet (Liu and Singh, 2004) KB 56.7 % Subword-level Transformer LM (Vaswani et al., 2017) 58.3 % Single LM (partial) (Trinh and Le, 2018) 53.3 % Single LM (full) (Trinh and Le, 2018) 60.0 % Patric Dhondt (WS Challenge 2016) 45.0 % Nicos Issak (WS Challenge 2016) 48.3 % Quan Liu (WS Challenge 2016 - winner ) 58.3 % USSM + Supervised Deepnet 53.3 % USSM + Supervised Deepnet + 3 Knowledge Bases 66.7 % Our Proposed Method 68.3 % |
|
| 50 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 51 |
+
|
| 52 |
+
Table 2: Results for Winograd Schema Challenge. The other results are taken from (Trichelair et al., 2018) and (Trinh and Le, 2018).
|
| 53 |
+
|
| 54 |
+
| Method Accuracy Random guess 50.0 % USSM + KB 52.0% USSM + Supervised DeepNet + KB 52.8 % Single LM (Trinh and Le, 2018) 54.5 % Transformer (Vaswani et al., 2017) 54.1 % Know. Hunter (Emami et al., 2018) 57.1 % Our Proposed Method 60.3 % |
|
| 55 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 56 |
+
|
| 57 |
+
## 2.2 Maximum Attention Score (MAS)
|
| 58 |
+
|
| 59 |
+
In order to exploit the associative leverage of selfattention, the computation of MAS follows the notion of max-pooling on attention level between a reference word s (e.g. pronoun) and candidate words c (e.g. multiple choice pronouns). The proposed approach takes as input the BERT attention tensor and produces for each candidate word a score, which indicates the strength of association. To this end, the BERT attention tensor A ∈ R H × L ×|C| is sliced into several matrices A c ∈ R H × L , each of them corresponding to the attention between the reference word and a candidate c . Each A c is associated with a binary mask matrix M c . The mask values of M c are obtained at each location tuple ( l, h ) , according to:
|
| 60 |
+
|
| 61 |
+
Figure 2: Maximum Attention Score (MAS) for some sample questions from WSC-273: The last example is an example of failure of the method, where the coreference is predicted incorrectly.
|
| 62 |
+
|
| 63 |
+
<!-- image -->
|
| 64 |
+
|
| 65 |
+
<!-- formula-not-decoded -->
|
| 66 |
+
|
| 67 |
+
Mask entries are non-zero only at locations where the candidate word c is associated with maximum attention. Limiting the impact of attention by masking allows to accommodate for the most salient parts. Given the A c and M c matrix pair for each candidate c , the MAS can be computed. For this purpose, the sum of the Hadamard product for each pair is calculated first. Next, the actual score is obtained by computing the ratio of each Hadamard sum w.r.t. all others according to,
|
| 68 |
+
|
| 69 |
+
<!-- formula-not-decoded -->
|
| 70 |
+
|
| 71 |
+
Thus MAS retains the attention of each candidate only where it is most dominant, coupling it with the notion of frequency of occurrence to weight the importance. See Fig. 1 for a schematic illustration of the computation of MAS, and the matrices involved.
|
| 72 |
+
|
| 73 |
+
## 3 Experimental Results
|
| 74 |
+
|
| 75 |
+
Weevaluate our method on two commonsense reasoning tasks, PDP and WSC.
|
| 76 |
+
|
| 77 |
+
On the former task, we use the original set of 60 questions (PDP-60) as the main benchmark. The second task (WSC-273) is qualitatively much more difficult. The recent best reported result are not much above random guess. This task consists of 273 questions and is designed to work against traditional linguistic techniques, common heuristics or simple statistical tests over text corpora (Levesque et al., 2012).
|
| 78 |
+
|
| 79 |
+
## 3.1 BERT Model Details
|
| 80 |
+
|
| 81 |
+
In all our experiments, we used the out-of-thebox BERT models without any task-specific finetuning. Specifically, we use the PyTorch implementation of pre-trained bert -base -uncased models supplied by Google 1 . This model has 12 layers (i.e., Transformer blocks), a hidden size of 768, and 12 self-attention heads. In all cases we set the feed-forward/filter size to be 3072 for the hidden size of 768. The total number of parameters of the model is 110M.
|
| 82 |
+
|
| 83 |
+
## 3.2 Pronoun Disambiguation Problem
|
| 84 |
+
|
| 85 |
+
We first examine our method on PDP-60 for the Pronoun Disambiguation task. In Tab. 1 (top), our method outperforms all previous unsupervised results sharply. Next, we allow other systems to take in necessary components to maximize their test performance. This includes making use of supervised training data that maps commonsense reasoning questions to their correct answer. As reported in Tab. 1 (bottom), our method outperforms the best system in the 2016 competition (58.3%) by a large margin. Specifically, we achieve 68.3% accuracy, better than the more recently reported results from (Liu et al., 2017) (66.7%), who makes use of three KBs and a supervised deep network.
|
| 86 |
+
|
| 87 |
+
## 3.3 Winograd Schema Challenge
|
| 88 |
+
|
| 89 |
+
Onthe harder task WSC-273, our method also outperforms the current state-of-the-art, as shown in Tab. 2. Namely, our method achieves an accuracy of 60.3%, nearly 3% of accuracy above the previous best result. This is a drastic improvement considering the best system based on language models outperforms random guess by only 4% in accuracy. This task is more difficult than PDP-60. First, the overall performance of all competing systems are much lower than that of PDP60. Second, incorporating supervised learning and expensive annotated KBs to USSM provides insignificant gain this time (+3%), comparing to the large gain on PDP-60 (+19%). Finally, for the sake of completeness, (Trinh and Le, 2018) report that their single language model trained on a customized dataset built from CommonCrawl based on questions used in comonsense reasoning achieves an higher accuracy than the proposed approach with 62.6%.
|
| 90 |
+
|
| 91 |
+
1 https://github.com/huggingface/pytorch-pretrainedBERT
|
| 92 |
+
|
| 93 |
+
We visualize the MAS to have more insights into the decisions of our resolvers. Fig. 2 displays some samples of correct and incorrect decisions made by our proposed method. MAS score of different words are indicated with colors, where the gradient from blue to red represents the score transition from low to high.
|
| 94 |
+
|
| 95 |
+
## 4 Discussion
|
| 96 |
+
|
| 97 |
+
Pursuing commonsense reasoning in a purely unsupervised way seems very attractive for several reasons. On the one hand, this implies tapping the nearly unlimited resources of unannotated text and leveraging the wealth of information therein. On the other hand, tackling the commonsense reasoning objective in a (more) supervised fashion typically seems to boost performance for very a specific task as concurrent work shows (Kocijan et al., 2019). However, the latter approach is unlikely to generalize well beyond this task. That is because covering the complete set of commonsense entities is at best extremely hard to achieve, if possible at all. The data-driven paradigm entails that the derived model can only make generalizations based on the data it has observed. Consequently, a supervised machine learning approach will have to be exposed to all combinations, i.e. replacing lexical items with semantically similar items in order to derive various concept notions. Generally, this is prohibitively expensive and therefore not viable. In contrast, in the proposed (unsupervised self-attention guided) approach this problem is alleviated. This can be largely attributed to the nearly unlimited text corpora on which the model originally learns, which makes it likely to cover a multitude of concept relations, and the fact that attention implicitly reduces the search space. However, all these approaches require the answer to explicitly exist in the text. That is, they are unable to resolve pronouns in light of abstract/implicit referrals that require background knowledge - see (Saba, 2018) for more detail. However, this is beyond the task of WSC. Last, the presented results suggest that BERT models the notion of complex relationship between entities, facilitating commonsense reasoning to a certain degree.
|
| 98 |
+
|
| 99 |
+
## 5 Conclusion
|
| 100 |
+
|
| 101 |
+
Attracted by the success of recently proposed language representation model BERT, in this paper, we introduce a simple yet effective reimplementation of BERT for commonsense reasoning. Specifically, we propose a method which exploits the attentions produced by BERT for the challenging tasks of PDP and WSC . The experimental analysis demonstrates that our proposed system outperforms the previous state of the art on multiple datasets. However, although BERT seems to implicitly establish complex relationships between entities facilitating tasks such as coreference resolution, the results also suggest that solving commonsense reasoning tasks might require more than leveraging a language model trained on huge text corpora. Future work will entail adaption of the attentions, to further improve the performance.
|
| 102 |
+
|
| 103 |
+
## References
|
| 104 |
+
|
| 105 |
+
Daniel Bailey, Amelia J Harrison, Yuliya Lierler, Vladimir Lifschitz, and Julian Michael. 2015. The winograd schema challenge and reasoning about correlation. In 2015 AAAI Spring Symposium Series .
|
| 106 |
+
|
| 107 |
+
Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. 2018. Bert: Pre-training of deep bidirectional transformers for language understanding. arXiv preprint arXiv:1810.04805 .
|
| 108 |
+
|
| 109 |
+
Ali Emami, Noelia De La Cruz, Adam Trischler, Kaheer Suleman, and Jackie Chi Kit Cheung. 2018. A knowledge hunting framework for common sense reasoning. In Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing , pages 1949-1958, Brussels, Belgium. Association for Computational Linguistics.
|
| 110 |
+
|
| 111 |
+
Sepp Hochreiter and J¨ urgen Schmidhuber. 1997.
|
| 112 |
+
|
| 113 |
+
- Long short-term memory. Neural computation , 9(8):1735-1780.
|
| 114 |
+
- Vid Kocijan, Ana-Maria Cretu, Oana-Maria Camburu, Yordan Yordanov, and Thomas Lukasiewicz. 2019. A surprisingly robust trick for the winograd schema challenge. In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics, ACL 2019, Florence, Italy, July 28 - August 2, 2019 . Association for Computational Linguistics.
|
| 115 |
+
- Kenton Lee, Luheng He, Mike Lewis, and Luke Zettlemoyer. 2017. End-to-end neural coreference resolution. In Proceedings of the 2017 Conference on Empirical Methods in Natural Language Processing , pages 188-197, Copenhagen, Denmark. Association for Computational Linguistics.
|
| 116 |
+
- Hector Levesque, Ernest Davis, and Leora Morgenstern. 2012. The winograd schema challenge. In Thirteenth International Conference on the Principles of Knowledge Representation and Reasoning .
|
| 117 |
+
- Hugo Liu and Push Singh. 2004. Conceptneta practical commonsense reasoning tool-kit. BT technology journal , 22(4):211-226.
|
| 118 |
+
- Quan Liu, Hui Jiang, Andrew Evdokimov, Zhen-Hua Ling, Xiaodan Zhu, Si Wei, and Yu Hu. 2016. Probabilistic reasoning via deep learning: Neural association models. arXiv preprint arXiv:1603.07704 .
|
| 119 |
+
- Quan Liu, Hui Jiang, Zhen-Hua Ling, Xiaodan Zhu, Si Wei, and Yu Hu. 2017. Combing context and commonsense knowledge through neural networks for solving winograd schema problems. In 2017 AAAI Spring Symposium Series .
|
| 120 |
+
- Tomas Mikolov, Kai Chen, Greg Corrado, and Jeffrey Dean. 2013. Efficient estimation of word representations in vector space. CoRR , abs/1301.3781.
|
| 121 |
+
- George A Miller. 1995. Wordnet: a lexical database for english. Communications of the ACM , 38(11):3941.
|
| 122 |
+
- Leora Morgenstern, Ernest Davis, and Charles L Ortiz. 2016. Planning, executing, and evaluating the winograd schema challenge. AI Magazine , 37(1):50-54.
|
| 123 |
+
- Haoruo Peng, Daniel Khashabi, and Dan Roth. 2015. Solving hard coreference problems. In Proceedings of the 2015 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies , pages 809-819.
|
| 124 |
+
- Matthew Peters, Mark Neumann, Luke Zettlemoyer, and Wen-tau Yih. 2018a. Dissecting contextual word embeddings: Architecture and representation. In Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing , pages 1499-1509, Brussels, Belgium. Association for Computational Linguistics.
|
| 125 |
+
- Matthew E Peters, Mark Neumann, Mohit Iyyer, Matt Gardner, Christopher Clark, Kenton Lee, and Luke Zettlemoyer. 2018b. Deep contextualized word representations. arXiv preprint arXiv:1802.05365 .
|
| 126 |
+
- Alec Radford, Karthik Narasimhan, Tim Salimans, and Ilya Sutskever. 2018. Improving language understanding by generative pre-training. URL https://s3us-west-2. amazonaws. com/openai-assets/researchcovers/languageunsupervised/language understanding paper. pdf .
|
| 127 |
+
- Altaf Rahman and Vincent Ng. 2012. Resolving complex cases of definite pronouns: the winograd schema challenge. In Proceedings of the 2012 Joint Conference on Empirical Methods in Natural Language Processing and Computational Natural Language Learning , pages 777-789. Association for Computational Linguistics.
|
| 128 |
+
- Melissa Roemmele, Cosmin Adrian Bejan, and Andrew S Gordon. 2011. Choice of plausible alternatives: An evaluation of commonsense causal reasoning. In 2011 AAAI Spring Symposium Series .
|
| 129 |
+
- [Walid S. Saba. 2018. A simple machine learning method for commonsense reasoning? A short commentary on trinh & le (2018). CoRR , abs/1810.00521.](http://arxiv.org/abs/1810.00521)
|
| 130 |
+
- Peter Sch¨ uller. 2014. Tackling winograd schemas by formalizing relevance theory in knowledge graphs. In Fourteenth International Conference on the Principles of Knowledge Representation and Reasoning .
|
| 131 |
+
- Arpit Sharma, Nguyen H Vo, Somak Aditya, and Chitta Baral. 2015. Towards addressing the winograd schema challengebuilding and using a semantic parser and a knowledge hunting module. In TwentyFourth International Joint Conference on Artificial Intelligence .
|
| 132 |
+
- Gongbo Tang, Mathias M¨ uller, Annette Rios, and Rico Sennrich. 2018. Why self-attention? a targeted evaluation of neural machine translation architectures. arXiv preprint arXiv:1808.08946 .
|
| 133 |
+
- Paul Trichelair, Ali Emami, Jackie Chi Kit Cheung, Adam Trischler, Kaheer Suleman, and Fernando Diaz. 2018. On the evaluation of common-sense reasoning in natural language understanding. arXiv preprint arXiv:1811.01778 .
|
| 134 |
+
- Trieu H Trinh and Quoc V Le. 2018. A simple method for commonsense reasoning. arXiv preprint arXiv:1806.02847 .
|
| 135 |
+
- Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin. 2017. Attention is all you need. In Advances in Neural Information Processing Systems , pages 5998-6008.
|
| 136 |
+
- Rowan Zellers, Yonatan Bisk, Roy Schwartz, and Yejin Choi. 2018. Swag: A large-scale adversarial dataset for grounded commonsense inference. arXiv preprint arXiv:1808.05326 .
|
text-versions/attention-markdown/1906.02792_Attention is all you need for Videos Sel.md
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1906.02792 Attention Is All You Need For Videos Sel
|
| 2 |
+
|
| 3 |
+
1
|
| 4 |
+
|
| 5 |
+
A generic video captioning pipeline consists of a Video feature extraction network. This network reduces the video dimensions from hundreds of thousands of pixels to only a few thousand floating-point numbers. More on this is covered in Section 2.1 and our implementation of the same is covered in Section 3.1. Then, a prediction model is used to generate the captions. Historically, it consisted of Recurrent Neural Network architectures like Vanilla RNNs, GRUs and LSTMs or their variants [1, 2, 3, 4]. With the recent advances in Attention based mechanisms, soft, hard and self-attention had become the state-of-the-art methods for Video Captioning [5, 6, 7, 8, 9]. A generic video captioning pipeline is shown in Figure 2.
|
| 6 |
+
|
| 7 |
+
## ATTENTION IS ALL YOU NEED FOR VIDEOS: SELF-ATTENTION BASED VIDEO SUMMARIZATION USING UNIVERSAL TRANSFORMERS
|
| 8 |
+
|
| 9 |
+
mbilkhu@ucsd.edu
|
| 10 |
+
|
| 11 |
+
Manjot Bilkhu UC San Diego Siyang Wang siw030@ucsd.edu UC San Diego
|
| 12 |
+
|
| 13 |
+
## ABSTRACT
|
| 14 |
+
|
| 15 |
+
Video Captioning and Summarization have become very popular in the recent years due to advancements in Sequence Modelling, with the resurgence of Long-Short Term Memory networks (LSTMs) and introduction of Gated Recurrent Units (GRUs). Existing architectures extract spatio-temporal features using CNNs and utilize either GRUs or LSTMs to model dependencies with soft attention layers. These attention layers do help in attending to the most prominent features and improve upon the recurrent units, however, these models suffer from the inherent drawbacks of the recurrent units themselves. The introduction of the Transformer model has driven the Sequence Modelling field into a new direction. In this project, we implement a Transformer-based model for Video captioning, utilizing 3D CNN architectures like C3D and Two-stream I3D for video extraction. We also apply certain dimensionality reduction techniques so as to keep the overall size of the model within limits. We finally present our results on the MSVD and ActivityNet datasets for Single and Dense video captioning tasks respectively.
|
| 16 |
+
|
| 17 |
+
## 1 Introduction
|
| 18 |
+
|
| 19 |
+
Videos have become synonymous with Information exchange. Every minute, 400 hours of video is uploaded to YouTube, and 46,000 years of video is watched annually. When the number of videos become so huge in size, it becomes a necessity to automatically process these videos. One such way to process these videos is to automatically understand what is the content within them. This would help in automatically tagging them without the need for human effort.
|
| 20 |
+
|
| 21 |
+
Video Captioning/Summarization is the process of describing a video in one or more sentences. When more than one sentence is used, it is termed as Dense Video Captioning. A sample is shown in Figure 1.
|
| 22 |
+
|
| 23 |
+
Figure 1: Video Captioning and Dense Video Captioning Example
|
| 24 |
+
|
| 25 |
+
<!-- image -->
|
| 26 |
+
|
| 27 |
+
tdobhal@ucsd.edu
|
| 28 |
+
|
| 29 |
+
Tushar Dobhal UC San Diego This report is presented as follows: Section 2 goes in depth into the various Video captioning techniques that have given promising results, Section 3 describes in detail our proposed model, while Section 4 describes the implementation details of our model, the training and testing procedure used. We then present our results in Section 5, and Section 6 dives into the limitations we noticed with the model and where this project could be heading in the near future.
|
| 30 |
+
|
| 31 |
+
Figure 2: Generic Video Captioning Pipeline
|
| 32 |
+
|
| 33 |
+
<!-- image -->
|
| 34 |
+
|
| 35 |
+
## 2 Literature Review
|
| 36 |
+
|
| 37 |
+
Our Literature review is structured as follows - Section 2.1 dives into various networks for video features extraction, Section 2.2 compares vanilla transformers and other augmented networks used for various Sequence Modelling tasks, and Section 2.3 explains in detail the different ideas and architectures that have been used for Video Captioning.
|
| 38 |
+
|
| 39 |
+
## 2.1 Video Feature Extraction
|
| 40 |
+
|
| 41 |
+
The first step in many video analysis tasks including video captioning is extracting features from the raw video input. Because a video can be seen as an ordered collection of images, the majority of video feature extraction methods have been derived from image feature extraction methods. These methods can be divided into three categories, (1) low-level and/or hand-crafted, (2) 2d-CNN, and (3) 3d-CNN.
|
| 42 |
+
|
| 43 |
+
Prior to 2013, researches in video feature extraction have focused on adapting handcrafted image feature extraction methods to videos. Among these works, [10] extended 2d Harris detector to 3d with time as the third dimension to detect interest points that is conspicuous both independently in each frame and sequentially in time. This method achieved good performance at that time in human action analysis. Another line of methods [11] adapts optical flow which is pixel-level gradient aggregated over a local window as a feature extractor for higher level video analysis. In the object tracking community, basic feature extractors are combined with movement modeling to achieve good performance. One prominent example is tracking an object that is known to appear as a "blob" in some form of imaging, either RGB or heatmap, by detecting the largest group of connected bright pixels. Other successful image feature extractors have been adapted to be applied on videos, such as 3d-SIFT [12], and 3d-HOG [13]. More recently, [14] showed that densely sampling 2d-features combined with optical flow performs well in action recognition. Improved Dense Trajectories(iDT) [15] which improves upon method proposed in [14] by eliminating camera motion in the calculated optical flows thus removing the mismatch between camera motion and object movement. This is the state-of-the-art method in this category of feature extractors. The major drawback of low-level hand-crafted features is their lack of high-level semantic information that is crucial in many video analysis tasks especially video summarization. Moreover, most of such feature extractors are not made to be easily differentiable making it difficult to incorporate them into an end-to-end learning system without sacrificing trainability.
|
| 44 |
+
|
| 45 |
+
The success of deep convolutional neural networks (CNN) in various computer vision tasks in 2d settings especially object recognition [16] spurred the use of CNNs as frame-wise 2d feature extractors in video analysis. A typical CNN consists of several convolutional layers each producing a feature map which captures the hierarchical features of the input image. Variants of CNNs have been proposed to improve performance [17] [18] [19]. A key aspect of CNNs is that the feature maps produced by a task-specific CNN often works well on other tasks, a phenomenon known as transfer learning studied by the machine learning community. Thus, a pre-trained CNN on a related image analysis task can be used as a feature extractor for video analysis tasks. For example, a pre-trained CNN encodes each frame of the video into a feature vector and a sequence modeler such as Recurrent Neural Network (RNN) takes this sequence of features as input. A key characteristic of such approaches is that they extract features from frames independently as CNN is a 2d feature extractor. They do not take into account the relation between several connecting frames [20].
|
| 46 |
+
|
| 47 |
+
Some methods did attempt to utilize CNN's ability of processing 2d images in the form of multiple channels by expanding the input channels from RGB of one frame to multiple RGBs of connecting frames. But the problem with such framework is that the sequential information is lost after one layer, as the convolutional operation squashes input channels from previous layer into one new channel of the current layer. [20] proposes to overcome this issue by adapting 3D-CNN to the problem. 3D-CNN expands the same convolutional operation in 2D-CNN to three dimensional space. A sequence of video frames can be seen as a three-dimensional input, 2d in each frame and time as the third dimension. The advantage of 3D-CNN over 2D-CNN is that the convolutional operation produces 3d feature maps which in the context of this problem means that the time dependency between frames is not only retained and modeled over convolutional layers in 3D-CNN. [20] shows that their proposed 3D-CNN based video feature extractor C3D outperforms other video feature extractors including 2D-CNN-based feature extractors in action recognition and video object recognition.
|
| 48 |
+
|
| 49 |
+
## 2.2 Sequence to Sequence models using self-attention
|
| 50 |
+
|
| 51 |
+
Recurrent Neural Networks (RNN's) and Long Short Term Memory cells have been posed for sequence to sequence tasks for a long time. While RNN's and LSTM's are naturally suited for these tasks, they fail to capture long-term dependencies or adapt to sequence lengths not encountered in training. Machine Translation systems use an encoderdecoder architecture, in which, the outputs of the decoder at each time step are conditioned on the encoder. The inability of RNN's or LSTM's to capture long-term dependencies is well exposed in these encoder-decoder based translation system. The encoded context vector generated by the encoder fails to capture information about the tokens seen in the beginning of the sequence, especially when the sequences are long. This then makes vanilla RNN's and LSTM's unsuitable for modeling translation based tasks having long sequences.
|
| 52 |
+
|
| 53 |
+
Bengio et al. [21] introduced the scaled-dot-product attention mechanism which saw an improvement over the encoderdecoder based architectures. The key idea behind their success was rather than using just the context vector generated by the encoder, soft-attention can help improve the performance of the decoder, by providing it the hidden states of the encoder. In a way, the decoder peeks at the input sequence using an attention distribution to decode the sequence. Several other improvements over this architecture have been proposed, but all of these rely on using either RNN's and LSTM's, and hence, are unable to capture long-term dependencies and cannot be parallelized across training examples.
|
| 54 |
+
|
| 55 |
+
The transformer model [22] addressed the shortcomings of recurrent machine translation systems by proposing an architecture that relies only on self-attention. Since they take recurrence completely out of the picture, the Transformer model allows parallelization across training samples and generates a feature representation in a fixed number of steps, which are chosen empirically. They also use the scaled dot product attention mechanism over the Keys K, Queries Q and Values V and compute the representation using softmax as:
|
| 56 |
+
|
| 57 |
+
<!-- formula-not-decoded -->
|
| 58 |
+
|
| 59 |
+
Vaswani et al. [22] use N = 8 attention heads and concatenate the outputs of each of these heads to compute the self-attention representation of the inputs. These representations are then fed to a point-wise feed forward neural network to generate the final encoded context vectors. Their complete architecture thus uses self-attention for the inputs, encoder-decoder attention for the decoder and masked self-attention to generate the outputs.
|
| 60 |
+
|
| 61 |
+
<!-- formula-not-decoded -->
|
| 62 |
+
|
| 63 |
+
While the Transformer improves upon the vanilla RNN and LSTM based models, it fails to generalize to unseen input lengths or learn simple tasks like Copying and Repeat copying. The Universal Transformer[23] model aims to address these issues by weight sharing across the encoder and decoder units and by using Adaptive Computation Time [24] to learn the number of steps required to learn the encoder representation. Adaptive Computation Time is an approach using which sequence models can dynamically learn the number of computation steps required to process an input. Earlier, these steps had to be explicitly defined by the architecture or were dependent on the input lengths. The Universal Transformer model uses ACT not between inputs, but across depth, and refine their self-attention distributions dynamically.
|
| 64 |
+
|
| 65 |
+
The Universal Transformer uses 4 attention heads instead of the 8 as proposed in the original architecture, and achieve significant improvements over the vanilla transformer. Their adaptation of the ACT method can indeed prove to be significant when dealing with videos of large and varying lengths. The number of parameters for both these models is the same, which has prompted us to believe that this architecture can indeed do better for tasks like video summarization, under the same computational constraints.
|
| 66 |
+
|
| 67 |
+
There have been a few other notable improvements over the vanilla transformer architecture. Transformer-XL networks [25] bring back recurrence in the transformer models and counter the problem of fixed-length context in the Transformer. They use recurrence at a segment-level and show that the Transformer-XL model can capture long-term dependencies. They also demonstrate that by doing this, they achieve a 1800% improvement in the evaluation time when compared to the Transformer model. BERT [26] uses bidirectional Transformers and condition the representations on both left and right context, for all layers. They propose a pre-training scheme which yields state-of-the-art results across a wide variety of language modeling tasks.
|
| 68 |
+
|
| 69 |
+
## 2.3 Video Captioning
|
| 70 |
+
|
| 71 |
+
Video Captioning has always been seen as a Sequence Modelling problem. Before Recurrent Neural Networks came into prominence, Hidden Markov Models were popular for tackling such tasks. [27] used an object detector to detect objects within the scene and track them from one frame to another. They also detected pose, shape and view-point specific features within the video and extracted colour, shape and size specific features for each frame. With the help of these features, they try to model lexicons like nouns, verbs, adjectives and adverbs using Hidden Markov Model. For example, verbs like jump and pick-up are represented as a two state HMM over velocity features; nouns like person is represented as a one state HMM over image features; and adjectives like red and big are modelled with a one state HMMover the relative position of the objects. The authors have also given examples of sentences modelled together by the above defined HMMs. Once the features are available, HMMs determine the lexicons in the available words and frame the sentence. The authors conducted real-world, albeit limited experiments consisting of a person, backpack, a chair and a trash-can, and the models output the sentence from the lexicons pairings it had learned.
|
| 72 |
+
|
| 73 |
+
By 2015, with the resurgence of LSTMs, and introduction of GRUs and Attention mechanism, RNNs had become synonymous with video captioning. Yao et. al [5] used a 3D CNN-RNN encoder-decoder architecture to capture spatio-temporal information. Work prior to this had used an object detector like VGG-16 to extract features and a 2 layer LSTM network for caption prediction [1]. [5] proposed to use a 3D convolutional network on a cuboid of feature block obtained by computing the Histograms of Oriented Gradients, Optical Flow and Motion Boundary. This pre-processing was done so as to reduce the execution time of the 3D CNNs, which consisted of three 3D convolution layers followed by ReLU activation, pooling and fully connected layers. A soft attention is applied to the output of the fully connected layer which is then passed to a single layer LSTM network for caption prediction. The authors tested their model on the Youtube2Text dataset and achieved state of the art BLEU, METEOR, CIDEr and Perplexity scores on the dataset. The authors, however, did not test on the more complex COCO dataset which they have proposed as their future work.
|
| 74 |
+
|
| 75 |
+
While the above paper [5] introduced the concept of using 3D convolutions to extract spatio-temporal features from video, it still relied on hand-crafted features like HOGs, HOFs and MBH. Another similar, but equally influential paper in this field is [2]. They proposed multiple models based on the encoder-decoder architecture consisting of a 2-layer LSTM network. The input to the encoder was computed from, (1) a pre-trained VGG network with RGB frames as input, (2) AlexNet with optical flow images as the input which is pre-trained on the UCF-101 dataset, and (3) VGG model with both RGB frames and optical flow images as the input. The output of the decoder predicts the caption of the incoming video. The optical flow images were computed using a classical technique described in [28]. The model which uses both RGB and Optical flow images gave state of the art METEOR score on the MSVD dataset, thus concluding that spatio-temporal features are better at capturing video features. They also evaluated their model on the more challenging MPII-MD and M-VAD movie description datasets and achieved promising results.
|
| 76 |
+
|
| 77 |
+
Both the previous papers were not end-to-end trainable due to the pre-processing done in extracting HOG, HOF, MBH and optical flow features. [4] introduced a recurrent convolutional network, an end-to-end deep network based on feature extracting convolutional network to account for the spatial domain, and a recurrent network based on LSTMs to model the time domain. The authors claimed that their model posses long-term memory and can be adapted to a variety of sequence modelling tasks. They tested their model on Activity Recognition, Image and Video Captioning datasets. For Video captioning specifically, they used CRF to model various components of the input video. These CRF features are then one-hot encoded and fed into, (1) LSTM based encoder-decoder network or, (2) LSTM based decoder only network, for video description. The authors have shown their model to achieve a better BLEU score than other comparable models on the TACoS multilevel dataset. Their main contribution is designing a network which gives promising results for three diverse sequence modelling tasks, however, they have noted that incorporating temporal features from the video and using an attention model could significantly improve the performance.
|
| 78 |
+
|
| 79 |
+
Donnahue et al. [4] have shown how merged deep CNN and RNN architectures can be utilized for this task. [6] followed a similar approach in their a Heirarchial RNN network, which consisted of the following parts - (1) A video descriptor network for modelling the spatio-temporal features, (2) An attention mechanism for selecting the most suitable video features, and (3) A multimodal layer to incorporate both video and text features. For the video descriptor layer, they proposed three methods. The first method included using a pre-trained VGG network to extract features, the second method involved using a pre-trained C3D network for spatio-temporal features and the last method was to compute optical flow images from the input video and then use a pre-trained VGG to extract the features. These video features were then fed into a soft attention layer after which they are combined with the hidden layer of the GRU network to which an embedding of the text served as the input. After the combination in the multimodal layer, which multiplies each of the input with separate weight matrices, a hidden and a softmax layer is used to generate the words. The authors have also modelled another GRU layer, which they call paragraph generator. The role of this layer is to receive the context vector and the word embeddings, and maintain a semantic context, which will be used to initialize the first recurrent network on arrival of the next input. Their optical flow based h-RNN has given state of the art performance on the YouTubeClips and TACoS multilevel datasets on BLUE, CIDEr and METEOR scores, closely followed by the C3D based model. The authors have also pointed out that they used C3D model trained on the Sports-1M dataset which has videos that are quite different from the ones they trained and tested the model on. Also, they have noted that their method failed to incorporate objects that were very small in size. Another drawback of this model is that since the paragraph generator which captured the context is used to initialize the main recurrent sentence generator, any error in this would be propagated through the network.
|
| 80 |
+
|
| 81 |
+
Inspired by the above approaches of (1) using CNN-RNN hybrid architecture and (2) using text input as well, [3] have proposed an LSTM based Transferred Semantic Attributes model (LSTM-TSA) which learns semantic attributes from the videos and image frames and inputs them to the LSTM layer for caption generation. They adopt the image semantic attributes detection framework of [29] to videos and generate words that lie in the ground truth caption of the video. Such image and video attributes respectively are computed from pre-trained VGG network on the ImageNet dataset and C3D network pre-trained on the Sports-1M dataset. Then these individual attributes are passed through gated function, the output of which is multiplied with these individual attributes, and then passed to an LSTM layer. Their LSTM-TSA model has given the best BLEU, CIDEr and METEOR scores on the MSVD dataset. They have also compared their model with others on the M-VAD and MPII-MD datasets, on which they have shown very promising results. As a future work, the authors have noted that they want to incorporate attention mechanism into their framework to focus on essential parts, which they believe can achieve better results.
|
| 82 |
+
|
| 83 |
+
Some of the previous work described here have either demonstrated or noted that attention mechanism can significantly improve Video captioning results. Therefore, most of the research happening currently use some form of attention mechanism. As a result, most of the research has been focused extensively on incorporating attention with video captioning. [7] have used multi-modal keyless attention for video classification with (1) input RBG frames features, (2) optical flow images, and (3) acoustic features by formulating Mel-spectrogram images. The features of all the three types of inputs are extracted using VGG which was pre-trained on the ImageNet dataset. All these features are 1D max pooled to obtain a lower dimensional set of attributes which are then passed onto a 2-layer Bi-directional LSTM network. The output of this network is then fed into an attention mechanism, which they call keyless attention, similar to a 2-layer feed forward network with a softmax layer at the end, to compute the attention weights. The output of their Keyless Attention is fed into a feedforward network to compute the video class probabilities. They have tested their model on the YouTube-8M dataset and predicted multiple tags for each of the videos in the dataset. Although this paper did not directly use the model for video captioning, this paper was included due to their novelty in incorporating sound along with the video information and usage of attention mechanism.
|
| 84 |
+
|
| 85 |
+
Same authors of the previous paper have also proposed another model based on multi-modal attention mechanism for video captioning [8]. In this paper, instead of audio features, the features used consisted of embeddings from text, frame-level features extracted from a pre-trained ResNet-152 model and video level motion features from a pre-trained C3D model. All these features are passed into separate attention layers so as to focus on important features individually; then the concatenated output is made to pass through a single-layer LSTM network whose hidden state is then attended to and passed to a softmax layer to predict the captions. The authors compared their model on MSVD and MSR-VTT datasets. These datasets do not contain any semantic information. To deal with this, the authors trained a ResNet-152 network on the COCO dataset predicting multiple labels for the captions which is then fed as input text to their attention network. Therefore, the previous three papers have shown that incorporating features other than video, like audio or text can significantly improve the model's performance.
|
| 86 |
+
|
| 87 |
+
All the above papers which relied on attention, used a soft attention model or a feedforward model. [9] have used an augmented vanilla transformer with self attention, which consists of one encoder and two decoders. The input to the encoder is the features extracted from RGB images and optical flow images computed using a ResNet-200 network which is pre-trained on ActivityNet dataset. This forms the input to the encoder of the multi-headed self-attention layer in the transformer. The first decoder, which the authors term as proposal decoder is based on ProcNets [30] and outputs regions of a video comprising of similar context which can be explained by a single sentence. It uses anchor boxes concept of Object Detection applied in the temporal direction, to output such segments of the video which are deemed as important. Next, this input, along with the self-attended output of the encoder is passed to a second decoder, named captioning decoder. Using self-attention, it captures the important information from the encoder output for each of the proposed segment by maintaining a masking function. The output of this decoder are the captions to be predicted. The authors tested their model on the ActivityNet Captioning and YouCookII datasets obtaining encouraging results, which were significantly better than the RNN counterparts, thus demonstrating the advantages of using transformer over recurrent networks.
|
| 88 |
+
|
| 89 |
+
## 3 Architecture
|
| 90 |
+
|
| 91 |
+
## 3.1 Video Feature Extraction
|
| 92 |
+
|
| 93 |
+
Instead of using frame-level feature extractors, we use networks which give us spatio-temporal features directly from videos. These architectures use 3D convolutions to encode spatial as well as temporal information present in videos. As highlighted in Figure 3, using 2D convolutions on an image or a video (set of frames) result in a single feature map. However, using 3D convolutions on a set of frames result in a set of feature maps. The number of feature maps depend on the size of the temporal kernel and the strides used.
|
| 94 |
+
|
| 95 |
+
Figure 3: 3D convolutions preserving spatial as well as temporal information present in a video
|
| 96 |
+
|
| 97 |
+
<!-- image -->
|
| 98 |
+
|
| 99 |
+
Recent advancements in the field of activity recognition have brought about various architectures which can serve as good spatio-temporal feature extractors. We look at architectures that can provide temporal information directly, instead of relying on a recurrent network to encode information from each time step. For this specific feature extraction task, we use C3D (3D Convolutional Neural Networks, Figure 4) and I3D (Inflated 3D Convolutional Neural Networks for Activity Recognition, Figure 5) to extract features for the Transformer model. I3D was inspired by the popular two-stream architecture for video classification, which has two similar networks running on the RGB stream and the Optical Flow stream. For I3D, we take the output from Mixed 5 c layer, which gives a feature vector of length 1024 for each 8 frames. For the C3D architecture, we take the output from fc 6 layer which gives a feature vector of length 4096 for each 16 frames.
|
| 100 |
+
|
| 101 |
+
Figure 4: C3D architecture as introduced by Tran et al. [20]
|
| 102 |
+
|
| 103 |
+
<!-- image -->
|
| 104 |
+
|
| 105 |
+
Figure 5: I3D architecture uses two ConvNets running in parallel over the RGB stream and the Optical Flow stream
|
| 106 |
+
|
| 107 |
+
<!-- image -->
|
| 108 |
+
|
| 109 |
+
## 3.2 Transformers
|
| 110 |
+
|
| 111 |
+
The transformer architecture is a rich and expressive model capable of producing state-of-the-art results on a wide variety of language modeling tasks. However, to the best of our knowledge, this is the first work which explores the capability of transformers to learn captions including full paragraphs. In order to apply self-attention for videos, we had to make a few notable changes from the original architecture. Since we already have feature representations for each time step, we skip the embedding layer used in transformers. Note that the original transformer model learns this embedding layer during training, which as one would guess, results in significant improvements compared to using a frozen representation. For a task like video summarization, this would mean learning or fine-tuning the feature extraction layers as well. However, due to limited compute resources, this was not done for now and remains as an essential improvement to explore for us in the future. A detailed explanation of the architectural changes from the original model is presented in the next section.
|
| 112 |
+
|
| 113 |
+
## 3.3 Universal Transformers
|
| 114 |
+
|
| 115 |
+
Transformers, being such a rich and expressive model, require a lot of data to train. Hence, it is not surprising to see that they fail in a lot of simple algorithmic and memory tasks, as pointed out by Dehghani et al [23]. Since we want to experiment with a few datasets which are not that large in size, Universal Transformers are a natural choice. They tie weights of all the encoder and decoder layers present in the transformer model, and use dynamic halting by introducing Adaptive Computation Time [24]. A detailed explanation of the architectural changes made for this specific task is provided in the following section.
|
| 116 |
+
|
| 117 |
+
The detailed architecture incorporating the above networks is shown in Figure 6.
|
| 118 |
+
|
| 119 |
+
Figure 6: Pipeline for Video Summarization using C3D and I3D as feature extractors and Transformers as a sequence 2 sequence model
|
| 120 |
+
|
| 121 |
+
<!-- image -->
|
| 122 |
+
|
| 123 |
+
## 4 Implementation Details
|
| 124 |
+
|
| 125 |
+
This section provides the procedure used for training and testing our model. We tested our model on the MSVD dataset, which is used to generate a single caption for each video, and the ActivityNet dataset, which is used to generate dense video captions. Each of the following sub-sections describe the dataset in detail along with the implementation details. We coded the models in PyTorch by partially adapting a publicly available PyTorch implementation of the original Transformer model (https://github.com/SamLynnEvans/Transformer).
|
| 126 |
+
|
| 127 |
+
## 4.1 MSVD
|
| 128 |
+
|
| 129 |
+
## 4.1.1 Dataset
|
| 130 |
+
|
| 131 |
+
The Microsoft Video Description dataset (MSVD) consists of 1970 video clips of length 10s to 25s obtained from YouTube with subjects being humans and animals. Out of the total, 1300 videos are used for training and the rest 670 are used for evaluation. This is a fairly small dataset with near constant semantics, with most videos consisting of humans performing some activities. The descriptions are produced by humans in multiple languages, with an average of 41 descriptions generated per video. Out of the total descriptions, there are 85,000 descriptions in total for English. These English descriptions together constitute a vocabulary of length 14,000 words. This is a commonly used dataset for video captioning and BLEU is the most common metric used for evaluation.
|
| 132 |
+
|
| 133 |
+
## 4.1.2 Data Preprocessing
|
| 134 |
+
|
| 135 |
+
As discussed in Section 3.1, we use C3D and I3D as our feature extraction networks.
|
| 136 |
+
|
| 137 |
+
In the case of C3D, the fc 6 layer of the network pre-trained on the UCF-101 [31] was used. For the input, the number of frames to be used was capped at 500, since it was not possible to load more than 500 frames for generating the features on a single GPU. The batch size was taken to be 1, which means that all the frames from a single video served as the input in each iteration of the extraction procedure. C3D generates 4096 feature vector per 16 frames input to the network, hence, in our case, the maximum dimension of the features was 31 x 4096. Finally, Principal Component Analysis, a technique used to reduce the feature size for videos [32], was used to reduce the feature dimension to 512. This was then stored as a numpy file to be used for caption prediction.
|
| 138 |
+
|
| 139 |
+
In the case of I3D, the Mixed 5 c layer was taken as the feature extraction layer, followed by an average pool. The network was pre-trained on the Kinetics dataset [33]. To reduce the memory footprint on the GPU, the number of frames were capped to 400. This is smaller than 500 frames used for C3D as I3D is a bigger and deeper network. The batch size was again taken to be 1, and the output generated were 1024 feature vector for every 8 frames. Again PCA was applied to reduce the dimension of the features to 512. Hence, the maximum feature size stored as a numpy file was 50 x 512. I3D, as stated before, can be used as a two-stream network as well. Therefore, we also extracted Optical FLow features using Farneback's dense optical flow features [34]. Although the original Kinetics dataset used TV-L1 method for flow estimation [35], we found that without CUDA support in OpenCV, it was taking 15s to 20s to compute for a single pair of image, hence, we went with the former method. Similar to RGB feature extraction, 400 flow frames of channel depth 2, were used for extraction. This resulted in a maximum feature vector of 50 x 512 size after application PCA.
|
| 140 |
+
|
| 141 |
+
In both the above cases, the input images were normalized and center-cropped before feeding into the network.
|
| 142 |
+
|
| 143 |
+
## 4.2 ActivityNet
|
| 144 |
+
|
| 145 |
+
## 4.2.1 Dataset
|
| 146 |
+
|
| 147 |
+
The ActivityNet dataset [32] consists of 20,000 videos obtained from YouTube with people performing certain activities. These activities involve dancing, cooking, speaking, among others and on an average are 180s in length. ActivityNet is widely used for (1) Activity Classification, (2) Event proposal detection, and (3) Dense Video Captioning. We have used it for the latter, wherein a paragraph comprising of 3 to 4 sentences is generated per video. The dataset on an average consists of 100,000 video descriptions with an average of 13.68 words per sentence and 3.65 such sentences per video, with the total length of vocabulary being 13,300 words. The authors also split the dataset into training, validation and testing sets, however, for dense video captioning, the validation set is used for evaluating the network as done in [9]. This is because the testing script provided by the authors expects the localization as well, and the testing ground truths are not made available in the dataset. Finally, BLEU score is the most popular metric for caption prediction quality estimation.
|
| 148 |
+
|
| 149 |
+
## 4.2.2 Data Preprocessing
|
| 150 |
+
|
| 151 |
+
The ActivityNet dataset provides C3D features which they compute on the videos of the dataset. These C3D features have a feature dimension of 500, and the features are extracted from the fc 6 layer to which PCA is applied. Since, there is no video available in the dataset, only C3D features were used for dense video captioning.
|
| 152 |
+
|
| 153 |
+
## 4.3 Caption Prediction
|
| 154 |
+
|
| 155 |
+
For both the above datasets and feature inputs, similar configurations for the Transformer and the Universal Transformer were used. For the MSVD dataset, since the number of descriptions per video was high, the pairing of the video was done randomly with one of the available captions. This was done to increase the number of available pairs of videos and captions. For AcivityNet, only one paragraph was available for training. In all the combination of features and models, the batch size used was 64.
|
| 156 |
+
|
| 157 |
+
In both the cases of Transformers and Universal Transformers, the embedding layer of the Encoder was removed since the inputs to the networks were no longer the semantic words. Other changes made included the altering of the learning rate schedule. Both of the transformer models used a learning rate schedule called 'CosineWithRestarts'. This scheduler basically increased the learning rate linearly during the warm-up stage, and then reduced proportionately with increasing number of epochs. The default learning rate proved to be too large for our type of input and hence, as a result, the model diverged after a certain number of epochs. Therefore, we used a uniformly reducing learning rate with the decreasing factor of 0.98, which helped in better learning without causing any divergence.
|
| 158 |
+
|
| 159 |
+
For the MSVD dataset, the number of layers used for the transformer was 6, with the dimension of the model being 512 and the number of multi-attention heads being 8. In case of Universal transformers, the number of layers used were 8 of 512 dimensional each, with 8 multi-attention heads forming the self-attention layer. Since we used features extracted by I3D and C3D networks, and not the learned embedding representations during training, this made the task a bit more challenging. We noticed that by incorporating adaptive computation time, the universal transformer was halting way too early for both short and longer videos. This greatly reduced the capacity of the model and we decided not to incorporate ACT in Universal Transformers. Even without ACT, the universal transformers took considerably shorter time and memory to train.
|
| 160 |
+
|
| 161 |
+
Seeing the qualitative results by inspecting the captions, we felt that Universal Transformers gave more diverse results. Hence, we decided to train the ActivityNet only using the Universal Transformer model. Due to the size and complexity of the ActivityNet dataset, a number of changes were made to the model. The models' dimension was changed to 500 to match with the number of input features of ActivityNet C3D extractor, and the multi-attention heads were also changed to 10 so as to make it perfectly divisible with the dimension of the model. Also, 8 Encoder-Decoder layers were used instead of the 4 used in the original paper.
|
| 162 |
+
|
| 163 |
+
## 4.4 Image Attributes Generator
|
| 164 |
+
|
| 165 |
+
As detailed in Section 5 we faced the problem with the nouns getting mixed up in the MSVD dataset, and hence, taking cues from previous research [3, 7, 8], we implemented an image annotation network which predicted the annotations for an image. These annotations would serve as the text features to the transformer network. For this, we trained a ResNet-50 model and a VGG-19 model, both pre-trained on the COCO and the ImageNet dataset respectively. For the training, we selected the 10 most frequently occurring words among the descriptions available, which would serve as the ground truth words for the input video frames. A fully connected layer was added at the end whose input was the attended weights across all frames. Let v i be the features from the individual frames, then the input to the last fully connected layer ( fc last ) was -
|
| 166 |
+
|
| 167 |
+
<!-- formula-not-decoded -->
|
| 168 |
+
|
| 169 |
+
However, our findings were in contrast to the papers cited above. Both the ResNet-50 and VGG-19 failed to generate diverse set of words for the validation set. The words generated were those that were already predicted well by the transformer model. So, adding this generator did not prove to be of any help. It had also failed to capture the nuances in the dataset.
|
| 170 |
+
|
| 171 |
+
## 5 Results
|
| 172 |
+
|
| 173 |
+
We present both quantitative and qualitative results of our model on the two datasets. It is standard to use BLEU score as a quantitative measure for video summarization tasks [36]. BLEU is originally developed for machine translation but has adapted over the years to similar text generation tasks such as image captioning and video summarization. Evaluating machine generated text quantitatively is still a problem to this day, but since BLEU is a widely used metric reported by state-of-the-art methods that we compare against, we calculated BLEU score on the results of our model as a quantitative evaluation. We also take a qualitative look at the results and showcase some examples where our model performed poorly to uncover the limitations of our model.
|
| 174 |
+
|
| 175 |
+
## 5.1 MSVD
|
| 176 |
+
|
| 177 |
+
Our model is able to achieve very promising BLEU scores on MSVD dataset. Table 1 shows that our model performs at the same level as the state-of-the-art models at the widely used BLEU-4 metric while outperforming the state-of-the-art models at BLEU-1 and BLEU-2. BLEU-1 and BLEU-2 mostly represent correctness at word and 2-word phrase level while BLEU-4 characterizes average correctness at word level and up to 4-word phrases. Our model has higher BLEU-1 and BLEU-2 indicating that it is better at producing the correct words for captions, especially nouns and verbs which are key to video summarization. This could be the effect of Transformer model in general where it can selectively pay attention to any frame of video feature while generating any word regardless of position. Furthermore, our model's BLEU-4 score that is at the same level as state-of-the-art shows that not only can our model generates the correct words, it can also produce correct meaningful phrases and sentences.
|
| 178 |
+
|
| 179 |
+
The results are obtained by giving the model visual inputs only. The Attributes Generator model did not help us in improving the performance, as discussed in Section 4.4. We still feel that it is important to compare our model with other state of the art methods which used both visual inputs and semantic inputs. Both the LSTM-TSA proposed in [3] and Multi-faceted Attention model proposed in [7] have noted that they are able to significant increase performance of their model by combining semantic features. However, same was not observed in our case.
|
| 180 |
+
|
| 181 |
+
Table 1: MSVD BLEU scores. Our model outperforms the state-of-the-art models on MSVD dataset in BLEU-1 and BLEU-2. Our model performs a the same level as the state-of-the-art models in BLEU-3 and BLEU-4.
|
| 182 |
+
|
| 183 |
+
| Model BLEU-1 BLEU-2 BLEU-3 BLEU-4 LSTM-TSA [3] 0.828 0.720 0.628 0.528 Multi-faceted Attention [8] 0.830 0.719 0.630 0.520 C3D + Transformer (Ours) 0.906 0.762 0.621 0.517 I3D + Transformer (Ours) 0.889 0.731 0.564 0.442 C3D + Universal Transformer (Ours) 0.901 0.765 0.587 0.501 I3D + Universal Transformer (Ours) 0.910 0.782 0.521 0.460 |
|
| 184 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 185 |
+
|
| 186 |
+
We also conducted qualitative examination of the results. Figure 7 shows some examples from the test set where our model (C3D + Universal Transformer) performs reasonably well. Both the subject present in the video and the activity of that subject are correctly identified and output in a semantically correct sentence. However, we also observed some examples where our model did not perform so well as shown in Figure 8. Either the subject or the activity is not identified completely correct. However, the model is still able to extract some meaningful information from the videos. For example, in the walking turtle video, the subject, i.e. turtle, is not correctly identified, but its action, i.e. walking, is correctly identified.
|
| 187 |
+
|
| 188 |
+
We observed that MSVD dataset lacks diversity. As mentioned earlier, the pre-processed vocabulary from description texts reaches 14,000 while the dataset only contains less than 1,970 videos. This means that many objects and activities only appear in one video, which often forces the model to overfit as we have observed. For example, the turtle video in Figure 8 is the only video in the dataset that contains a turtle. Some of our models did also output the same sentence many times to similar looking videos, which shows that the model only learned the text semantics or just memorized descriptions and not the task we intended to solve, which is to somewhat understand and describe videos with texts. Such results would still obtain a moderate BLEU score due to the text semantics present in the generated texts. It raises the question of whether or not the results obtained on the MSVD dataset can be generalized. To further test our model, we used a much more complex dataset, namely, ActivityNet.
|
| 189 |
+
|
| 190 |
+
## 5.2 ActivityNet
|
| 191 |
+
|
| 192 |
+
Our model gives promising paragraph-wise BLEU score on the ActivityNet dataset as shown in Table 2. It should be noted that our results for the ActivityNet Dense captioning cannot be directly compared with [9]. The purpose of our task was to demonstrate that our model can also be used to generate a multi-sentence summary of the video, rather than just a single line caption, without any modifications to the network. By this we felt that we would be really pushing the boundaries of our model by allowing it to learn on its own the important aspects of the video. Hence, we do not make use of any other information other than the video features provided in the dataset. In comparison, [9] have used the ground-truth event proposals to generate a single caption from a particular proposal, and they are able to generate a paragraph based on 3 to 4 ground-truth event proposals given for each video. This distinction is important because generating multiple sentences sequentially to describe a long video without any additional input is a relatively difficult task in the video summarization realm. This could be an important topic for future research. To our best knowledge, our model provides the first BLEU score benchmark in this task.
|
| 193 |
+
|
| 194 |
+
Table 2: ActivityNet BLEU scores. Our model gives state-of-the-art paragraphwise BLEU score on the ActivityNet dataset.
|
| 195 |
+
|
| 196 |
+
| Model BLEU-1 BLEU-2 BLEU-3 BLEU-4 I3D + Universal Transformer (Ours) 0.710 0.659 0.577 0.490 |
|
| 197 |
+
|---------------------------------------------------------------------------------------------------------|
|
| 198 |
+
|
| 199 |
+
Some examples where our model (I3D + Universal Transformer) performs reasonably well are shown in Figure 9. The model is able to identify the subject correctly and the sequence of actions the subject took. It is important to note that in the gymnast example, at lest 50 percent of the video does not contain any meaningful information. Many examples are similar where a substantial portion of frames do not contain activity information to be described, so our model learned to both pay attention to frames that need to be described along with how to describe. This evidently shows the advantage of Transformer models in video summarization when a relatively large portion of the video is irrelevant. Some examples where our model performs poorly are shown in Figure 10. The model can correctly identify the subject and the activity, but could not put the activity sequence into meaningful sentences and form a coherent paragraph.
|
| 200 |
+
|
| 201 |
+
From qualitative examination of both datasets, we conclude that Universal Transformers gives a diverse set of captions than Transformers, despite similar BLEU scores, probably due to its simpler structure due to weight sharing that prevents overfitting to ground-truth text descriptions.
|
| 202 |
+
|
| 203 |
+
<!-- image -->
|
| 204 |
+
|
| 205 |
+
<!-- image -->
|
| 206 |
+
|
| 207 |
+
Figure 7: Positive Examples from MSVD
|
| 208 |
+
|
| 209 |
+
<!-- image -->
|
| 210 |
+
|
| 211 |
+
<!-- image -->
|
| 212 |
+
|
| 213 |
+
## 6 Limitations and Future Work
|
| 214 |
+
|
| 215 |
+
Some notable limitations of our model include nouns getting mixed up, activities not correctly identified, and the the failure to form coherent paragraphs after identifying the nouns and activities. However, it's unclear to what degree can these drawbacks be improved by hyper-parameter tuning and fine-tuning on pre-trained networks. Another major drawback of our models are their inability to incorporate image attributes which might require proper hyper-parameter tuning and/or exploration of other networks for this task. Thus, as a short-term plan (2 weeks), we would want to focus our immediate attention on hyper-parameter tuning and fine-tuning the networks which include, C3D and I3D feature extraction networks, the Image Attribute Generator, as well as the Transformer and Universal Transformer models themselves. Fine-tuning C3D and I3D feature extraction networks with the task training set instead of using the trained networks as they are provided has shown to improve performance on various other video tasks in the past. This would require slightly more powerful or another GPU due to the size of these 3D CNN networks. We also plan to further refine the model so as to be able to capture the nuances, particularly in the dataset like the MSVD which has constant temporal semantics. Hence, as a long-term goal (4 weeks+), we would like to try ACT in Universal transformer to improve the halting process, which have been halting very early during the training process. Another thing we would want to try is to explore other Image Attributes Generator networks, especially the ones that go beyond the conventional CNN networks, as proposed in [37, 38]. The predicted attributes, if generated correctly, could help in capturing the nuances in any dataset, as it has been explained by other authors.
|
| 216 |
+
|
| 217 |
+
<!-- image -->
|
| 218 |
+
|
| 219 |
+
<!-- image -->
|
| 220 |
+
|
| 221 |
+
<!-- image -->
|
| 222 |
+
|
| 223 |
+
Figure 8: Negative Examples from MSVD
|
| 224 |
+
|
| 225 |
+
<!-- image -->
|
| 226 |
+
|
| 227 |
+
<!-- image -->
|
| 228 |
+
|
| 229 |
+
<!-- image -->
|
| 230 |
+
|
| 231 |
+
Figure 9: Positive Examples from ActivityNet
|
| 232 |
+
|
| 233 |
+
<!-- image -->
|
| 234 |
+
|
| 235 |
+
## 7 Conclusion
|
| 236 |
+
|
| 237 |
+
In this project, after first reviewing the various methods that have been used for Video Captioning, we presented a model based on Transformers for the same. Our implementation makes use of C3D and Two-stream I3D feature extraction networks which serve as the input to the caption prediction network. We then demonstrated the usefulness of our modified Transformer and Universal Transformer models for the video caption prediction task. After showing the success of our model on the MSVD dataset, we further tried to push the limits by testing it on the more complex Dense Video Captioning task and on the much larger ActivityNet dataset. The results of our experiments show that Transformer-based networks, along with the 3D spatio-temporal video feature extraction networks, can achieve great results without the need for any other form of input, and in some cases can even beat the previously attained BLEU
|
| 238 |
+
|
| 239 |
+
<!-- image -->
|
| 240 |
+
|
| 241 |
+
Figure 10: Negative Examples from ActivityNet
|
| 242 |
+
|
| 243 |
+
<!-- image -->
|
| 244 |
+
|
| 245 |
+
scores. We feel that with the ideas presented in Section 6, our model can achieve even more promising results for both single and dense video caption prediction tasks.
|
| 246 |
+
|
| 247 |
+
## References
|
| 248 |
+
|
| 249 |
+
- [1] Subhashini Venugopalan, Huijuan Xu, Jeff Donahue, Marcus Rohrbach, Raymond Mooney, and Kate Saenko. Translating videos to natural language using deep recurrent neural networks. In NAACL HLT
|
| 250 |
+
- [2] Subhashini Venugopalan, Marcus Rohrbach, Jeffrey Donahue, Raymond Mooney, Trevor Darrell, and Kate Saenko. Sequence to sequence - video to text. In Proceedings of the 2015 IEEE International Conference on Computer Vision (ICCV) , ICCV '15, pages 4534-4542, Washington, DC, USA, 2015. IEEE Computer Society
|
| 251 |
+
- [3] Yingwei Pan, Ting Yao, Houqiang Li, and Tao Mei. Video captioning with transferred semantic attributes. 2017 IEEE Conference on Computer Vision and Pattern Recognition (CVPR) , pages 984-992.
|
| 252 |
+
- [4] Jeff Donahue, Lisa Anne Hendricks, Marcus Rohrbach, Subhashini Venugopalan, Sergio Guadarrama, Kate Saenko, and Trevor Darrell. Long-term recurrent convolutional networks for visual recognition and description. IEEE Trans. Pattern Anal. Mach. Intell. , 39(4):677-691, April.
|
| 253 |
+
- [5] Li Yao, Atousa Torabi, Kyunghyun Cho, Nicolas Ballas, Christopher Joseph Pal, Hugo Larochelle, and Aaron C. Courville. Describing videos by exploiting temporal structure. 2015 IEEE International Conference on Computer Vision (ICCV) , pages 4507-4515, 2015.
|
| 254 |
+
- [6] Haonan Yu, Jiang Wang, Zhiheng Huang, Yi Yang, and Wei Xu. Video paragraph captioning using hierarchical recurrent neural networks. CoRR , abs/1510.07712, 2015.
|
| 255 |
+
- [7] Xiang Long, Chuang Gan, Gerard de Melo, Xiao Liu, Yandong Li, Fu Li, and Shilei Wen. Multimodal keyless attention fusion for video classification. In AAAI , 2018.
|
| 256 |
+
- [8] Xiang Long, Chuang Gan, and Gerard de Melo. Video captioning with multi-faceted attention. Transactions of the Association of Computational Linguistics , 06:173-184, 2018.
|
| 257 |
+
- [9] Luowei Zhou, Yingbo Zhou, Jason J. Corso, Richard Socher, and Caiming Xiong. End-to-end dense video captioning with masked transformer. 2018 IEEE/CVF Conference on Computer Vision and Pattern Recognition , pages 8739-8748, 2018.
|
| 258 |
+
- [10] Ivan Laptev. On space-time interest points. International journal of computer vision , 64(2-3):107-123, 2005.
|
| 259 |
+
- [11] John L Barron, David J Fleet, and Steven S Beauchemin. Performance of optical flow techniques. International journal of computer vision , 12(1):43-77, 1994.
|
| 260 |
+
|
| 261 |
+
- [12] Paul Scovanner, Saad Ali, and Mubarak Shah. A 3-dimensional sift descriptor and its application to action recognition. In Proceedings of the 15th ACM international conference on Multimedia , pages 357-360. ACM, 2007.
|
| 262 |
+
- [13] Alexander Klaser, Marcin Marszałek, and Cordelia Schmid. A spatio-temporal descriptor based on 3d-gradients. In BMVC 2008-19th British Machine Vision Conference , pages 275-1. British Machine Vision Association, 2008.
|
| 263 |
+
- [14] Heng Wang, Alexander Kläser, Cordelia Schmid, and Cheng-Lin Liu. Dense trajectories and motion boundary descriptors for action recognition. International journal of computer vision , 103(1):60-79, 2013.
|
| 264 |
+
- [15] Heng Wang and Cordelia Schmid. Action recognition with improved trajectories. In Proceedings of the IEEE international conference on computer vision , pages 3551-3558, 2013.
|
| 265 |
+
- [16] Alex Krizhevsky, Ilya Sutskever, and Geoffrey E Hinton. Imagenet classification with deep convolutional neural networks. In Advances in neural information processing systems , pages 1097-1105, 2012.
|
| 266 |
+
- [17] Karen Simonyan and Andrew Zisserman. Very deep convolutional networks for large-scale image recognition. arXiv preprint arXiv:1409.1556 , 2014.
|
| 267 |
+
- [18] Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep residual learning for image recognition. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 770-778, 2016.
|
| 268 |
+
- [19] Gao Huang, Zhuang Liu, Laurens Van Der Maaten, and Kilian Q Weinberger. Densely connected convolutional networks. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 4700-4708, 2017.
|
| 269 |
+
- [20] Du Tran, Lubomir Bourdev, Rob Fergus, Lorenzo Torresani, and Manohar Paluri. Learning spatiotemporal features with 3d convolutional networks. In Proceedings of the IEEE international conference on computer vision , pages 4489-4497, 2015.
|
| 270 |
+
- [21] Dzmitry Bahdanau, Kyunghyun Cho, and Yoshua Bengio. Neural machine translation by jointly learning to align and translate. CoRR , abs/1409.0473, 2014.
|
| 271 |
+
- [22] Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser, and Illia Polosukhin. Attention is all you need. CoRR , abs/1706.03762, 2017.
|
| 272 |
+
- [23] Mostafa Dehghani, Stephan Gouws, Oriol Vinyals, Jakob Uszkoreit, and Lukasz Kaiser. Universal transformers. CoRR , abs/1807.03819, 2018.
|
| 273 |
+
- [24] Alex Graves. Adaptive computation time for recurrent neural networks. CoRR , abs/1603.08983, 2016.
|
| 274 |
+
- [25] Zihang Dai, Zhilin Yang, Yiming Yang, Jaime G. Carbonell, Quoc V. Le, and Ruslan Salakhutdinov. Transformerxl: Attentive language models beyond a fixed-length context. CoRR , abs/1901.02860, 2019.
|
| 275 |
+
- [26] Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. BERT: pre-training of deep bidirectional transformers for language understanding. CoRR , abs/1810.04805, 2018.
|
| 276 |
+
- [27] Haonan Yu and Jeffrey Mark Siskind. Grounded language learning from video described with sentences. In ACL , 2013.
|
| 277 |
+
- [28] Thomas Brox, Andrés Bruhn, Nils Papenberg, and Joachim Weickert. High accuracy optical flow estimation based on a theory for warping. In ECCV , 2004.
|
| 278 |
+
- [29] Quanzeng You, Hailin Jin, Zhaowen Wang, Chen Fang, and Jiebo Luo. Image captioning with semantic attention. 2016 IEEE Conference on Computer Vision and Pattern Recognition (CVPR) , pages 4651-4659, 2016.
|
| 279 |
+
- [30] Luowei Zhou, Chenliang Xu, and Jason J Corso. Towards automatic learning of procedures from web instructional videos. In AAAI Conference on Artificial Intelligence , 2018.
|
| 280 |
+
- [31] Khurram Soomro, Amir Roshan Zamir, and Mubarak Shah. Ucf101: A dataset of 101 human actions classes from videos in the wild. CoRR , abs/1212.0402, 2012.
|
| 281 |
+
- [32] Bernard Ghanem Fabian Caba Heilbron, Victor Escorcia and Juan Carlos Niebles. Activitynet: A large-scale video benchmark for human activity understanding. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , pages 961-970, 2015.
|
| 282 |
+
|
| 283 |
+
- [33] Will Kay, João Carreira, Karen Simonyan, Brian Zhang, Chloe Hillier, Sudheendra Vijayanarasimhan, Fabio Viola, Tim Green, Trevor Back, Paul Natsev, Mustafa Suleyman, and Andrew Zisserman. The kinetics human action video dataset. CoRR , abs/1705.06950, 2017.
|
| 284 |
+
- [34] Gunnar Farnebäck. Two-frame motion estimation based on polynomial expansion. In SCIA , 2003.
|
| 285 |
+
- [35] Javier Sánchez Pérez, Enric Meinhardt, and Gabriele Facciolo. Tv-l1 optical flow estimation. IPOL Journal , 3:137-150, 2013.
|
| 286 |
+
- [36] Kishore Papineni, Salim Roukos, Todd Ward, and Wei-Jing Zhu. Bleu: a method for automatic evaluation of machine translation. In Proceedings of the 40th annual meeting on association for computational linguistics , pages 311-318. Association for Computational Linguistics, 2002.
|
| 287 |
+
- [37] Jiajun Wu, Yinan Yu, Chang Huang, and Kai Yu. Deep multiple instance learning for image classification and auto-annotation. 2015 IEEE Conference on Computer Vision and Pattern Recognition (CVPR) , pages 3460-3469, 2015.
|
| 288 |
+
- [38] Dong Liu, Yizhou Zhou, Xiaoyan Sun, Zheng-Jun Zha, and Wenjun Zeng. Adaptive pooling in multi-instance learning for web video annotation. 2017 IEEE International Conference on Computer Vision Workshops (ICCVW) , pages 318-327, 2017.
|
text-versions/attention-markdown/1906.03674_Attentionbased Conditioning Methods for .md
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1906.03674 Attentionbased Conditioning Methods For
|
| 2 |
+
|
| 3 |
+
## Attention-based Conditioning Methods for External Knowledge Integration
|
| 4 |
+
|
| 5 |
+
Katerina Margatina 1 , Christos Baziotis 2 ∗ , Alexandros Potamianos 1 , 3 , 4
|
| 6 |
+
|
| 7 |
+
1 School of ECE, National Technical University of Athens, Athens, Greece
|
| 8 |
+
|
| 9 |
+
2 School of Informatics, University of Edinburgh, UK 3 Signal Analysis and Interpretation Laboratory (SAIL), USC, Los Angeles, USA 4 Behavioral Signal Technologies, Los Angeles, USA
|
| 10 |
+
|
| 11 |
+
el12108@central.ntua.gr, c.baziotis@sms.ed.ac.uk,
|
| 12 |
+
|
| 13 |
+
potam@central.ntua.gr
|
| 14 |
+
|
| 15 |
+
## Abstract
|
| 16 |
+
|
| 17 |
+
In this paper, we present a novel approach for incorporating external knowledge in Recurrent Neural Networks (RNNs). We propose the integration of lexicon features into the self-attention mechanism of RNN-based architectures. This form of conditioning on the attention distribution, enforces the contribution of the most salient words for the task at hand. We introduce three methods, namely attentional concatenation, feature-based gating and affine transformation. Experiments on six benchmark datasets show the effectiveness of our methods. Attentional feature-based gating yields consistent performance improvement across tasks. Our approach is implemented as a simple add-on module for RNN-based models with minimal computational overhead and can be adapted to any deep neural architecture.
|
| 18 |
+
|
| 19 |
+
## 1 Introduction
|
| 20 |
+
|
| 21 |
+
Modern deep learning algorithms often do away with feature engineering and learn latent representations directly from raw data that are given as input to Deep Neural Networks (DNNs) (Mikolov et al., 2013; McCann et al., 2017; Peters et al., 2018). However, it has been shown that linguistic knowledge (manually or semi-automatically encoded into lexicons and knowledge bases) can significantly improve DNN performance for Natural Language Processing (NLP) tasks, such as natural language inference (Mrkši´ c et al., 2017), language modelling (Ahn et al., 2016), named entity recognition (Ghaddar and Langlais, 2018) and relation extraction (Vashishth et al., 2018).
|
| 22 |
+
|
| 23 |
+
For NLP tasks, external sources of information are typically incorporated into deep neural architectures by processing the raw input in the context of such external linguistic knowledge. In machine learning, this contextual processing is known as conditioning ; the computation carried out by a model is conditioned or modulated by information extracted from an auxiliary input. The most commonly-used method of conditioning is concatenating a representation of the external information to the input or hidden network layers.
|
| 24 |
+
|
| 25 |
+
∗ The research was conducted when the author was a researcher at School of ECE, NTUA in Athens, Greece.
|
| 26 |
+
|
| 27 |
+
Attention mechanisms (Bahdanau et al., 2015; Vaswani et al., 2017; Lin et al., 2017) are a key ingredient for achieving state-of-the-art performance in tasks such as textual entailment (Rocktäschel et al., 2016), question answering (Xiong et al., 2017), and neural machine translation (Wu et al., 2016). Often task-specific attentional architectures are proposed in the literature to further improve DNN performance (Dhingra et al., 2017; Xu et al., 2015; Barrett et al., 2018).
|
| 28 |
+
|
| 29 |
+
In this work, we propose a novel way of utilizing word-level prior information encoded in linguistic, sentiment, and emotion lexicons, to improve classification performance. Usually, lexicon features are concatenated to word-level representations (Wang et al., 2016; Yang et al., 2017; Trotzek et al., 2018), as additional features to the embedding of each word or the hidden states of the model. By contrast, we propose to incorporate them into the self-attention mechanism of RNNs. Our goal is to enable the self-attention mechanism to identify the most informative words, by directly conditioning on their additional lexicon features.
|
| 30 |
+
|
| 31 |
+
Our contributions are the following: (1) we propose an alternative way for incorporating external knowledge to RNN-based architectures, (2) we present empirical results that our proposed approach consistently outperforms strong baselines, and (3) we report state-of-the-art performance in two datasets. We make our source code publicly available 1 .
|
| 32 |
+
|
| 33 |
+
[1 https://github.com/mourga/ affective-attention](https://github.com/mourga/affective-attention)
|
| 34 |
+
|
| 35 |
+
## 2 Related Work
|
| 36 |
+
|
| 37 |
+
In the traditional machine learning literature where statistical models are based on sparse features, affective lexicons have been shown to be highly effective for tasks such as sentiment analysis, as they provide additional information not captured in the raw training data (Hu and Liu, 2004; Kim and Hovy, 2004; Ding et al., 2008; Yu and Dredze, 2014; Taboada et al., 2011). After the emergence of pretrained word representations (Mikolov et al., 2013; Pennington et al., 2014), the use of lexicons is no longer common practice, since word embeddings can also capture some of the affective meaning of these words.
|
| 38 |
+
|
| 39 |
+
Recently, there have been notable contributions towards integrating linguistic knowledge into DNNs for various NLP tasks. For sentiment analysis, Teng et al. (2016) integrate lexicon features to an RNN-based model with a custom weightedsum calculation of word features. Shin et al. (2017) propose three convolutional neural network specific methods of lexicon integration achieving state-of-the-art performance on two datasets. Kumar et al. (2018) concatenate features from a knowledge base to word representations in an attentive bidirectional LSTM architecture, also reporting state-of-the-art results. For sarcasm detection, Yang et al. (2017) incorporate psycholinguistic, stylistic, structural, and readability features by concatenating them to paragraph and documentlevel representations.
|
| 40 |
+
|
| 41 |
+
Furthermore, there is limited literature regarding the development and evaluation of methods for combining representations in deep neural networks. Peters et al. (2017) claim that concatenation, non-linear mapping and attention-like mechanisms are unexplored methods for including language model representations in their sequence model. They employ simple concatenation, leaving the exploration of other methods to future work. Dumoulin et al. (2018) provide an overview of feature-wise transformations such as concatenation-based conditioning, conditional biasing and gating mechanisms. They review the effectiveness of conditioning methods in tasks such as visual question answering (Strub et al., 2018), style transfer (Dumoulin et al., 2017) and language modeling (Dauphin et al., 2017). They also extend the work by Perez et al. (2017), which proposes the Feature-wise Linear Modulation (FiLM) framework, and investigate its applications in vi- sual reasoning tasks. Balazs and Matsuo (2019) provide an empirical study showing the effects of different ways of combining character and word representations in word-level and sentence-level evaluation tasks. Some of the reported findings are that gating conditioning performs consistently better across a variety of word similarity and relatedness tasks.
|
| 42 |
+
|
| 43 |
+
## 3 Proposed Model
|
| 44 |
+
|
| 45 |
+
## 3.1 Network Architecture
|
| 46 |
+
|
| 47 |
+
Word Embedding Layer . The input sequence of words w 1 , w 2 , ..., w T is projected to a lowdimensional vector space R W , where W is the size of the embedding layer and T the number of words in a sentence. We initialize the weights of the embedding layer with pretrained word embeddings.
|
| 48 |
+
|
| 49 |
+
LSTM Layer . A Long Short-Term Memory unit (LSTM) (Hochreiter and Schmidhuber, 1997) takes as input the words of a sentence and produces the word annotations h 1 , h 2 , ..., h T , where h i is the hidden state of the LSTM at time-step i , summarizing all sentence information up to w i .
|
| 50 |
+
|
| 51 |
+
Self-Attention Layer . We use a self-attention mechanism (Cheng et al., 2016) to find the relative importance of each word for the task at hand. The attention mechanism assigns a score a i to each word annotation h i . We compute the fixed representation r of the input sequence, as the weighted sum of all the word annotations. Formally:
|
| 52 |
+
|
| 53 |
+
<!-- formula-not-decoded -->
|
| 54 |
+
|
| 55 |
+
<!-- formula-not-decoded -->
|
| 56 |
+
|
| 57 |
+
where f ( . ) corresponds to a non-linear transformation tanh ( W a h i + b a ) and W a , b a , v a are the parameters of the attention layer.
|
| 58 |
+
|
| 59 |
+
Table 1: The lexicons used as external knowledge.
|
| 60 |
+
|
| 61 |
+
| Lexicons Annotations # dim. # words LIWC psycho-linguistic 73 18,504 Bing Liu valence 1 2,477 AFINN sentiment 1 6,786 MPQA sentiment 4 6,886 SemEval15 sentiment 1 1,515 Emolex emotion 19 14,182 |
|
| 62 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 63 |
+
|
| 64 |
+
## 3.2 External Knowledge
|
| 65 |
+
|
| 66 |
+
In this work, we augment our models with existing linguistic and affective knowledge from human experts. Specifically, we leverage lexica containing psycho-linguistic, sentiment and emotion annotations. We construct a feature vector c ( w i ) for every word in the vocabulary by concatenating the word's annotations from the lexicons shown in Table 1. For missing words we append zero in the corresponding dimension(s) of c ( w i ) .
|
| 67 |
+
|
| 68 |
+
## 3.3 Conditional Attention Mechanism
|
| 69 |
+
|
| 70 |
+
We extend the standard self-attention mechanism (Eq. 1, 2), in order to condition the attention distribution of a given sentence, on each word's prior lexical information. To this end, we use as input to the self-attention layer both the word annotation h i , as well as the lexicon feature c ( w i ) of each word. Therefore, we replace f ( h i ) in Eq. 1 with f ( h i , c ( w i )) . Specifically, we explore three conditioning methods, which are illustrated in Figure 1. We refer to the conditioning function as f i ( . ) , the weight matrix as W i and the biases as b i , where i is an indicative letter for each method. We present our results in Section 5 (Table 3) and we denote the three conditioning methods as 'conc.' , 'gate' and 'affine' respectively.
|
| 71 |
+
|
| 72 |
+
Attentional Concatenation. In this approach, as illustrated in Fig. 1(a), we learn a function of the concatenation of each word annotation h i with its lexicon features c ( w i ) . The intuition is that by adding extra dimensions to h i , learned representations are more discriminative. Concretely:
|
| 73 |
+
|
| 74 |
+
<!-- formula-not-decoded -->
|
| 75 |
+
|
| 76 |
+
where ‖ denotes the concatenation operation and W c , b c are learnable parameters.
|
| 77 |
+
|
| 78 |
+
Attentional Feature-based Gating. The second approach, illustrated in Fig. 1(b), learns a feature mask, which is applied on each word annotation h i . Specifically, a gate mechanism with a sigmoid activation function, generates a mask-vector from each c ( w i ) with values between 0 and 1 (black and white dots in Fig. 1(b)). Intuitively, this gating mechanism selects salient dimensions (i.e. features) of h i , conditioned on the lexical information. Formally:
|
| 79 |
+
|
| 80 |
+
<!-- formula-not-decoded -->
|
| 81 |
+
|
| 82 |
+
where ⊙ denotes element-wise multiplication and W g , b g are learnable parameters.
|
| 83 |
+
|
| 84 |
+
<!-- image -->
|
| 85 |
+
|
| 86 |
+
(c) Attentional Affine Transformation
|
| 87 |
+
|
| 88 |
+
Figure 1: The proposed conditioning methods of the self-attention mechanism.
|
| 89 |
+
|
| 90 |
+
Attentional Affine Transformation. The third approach, shown in Fig. 1(c), is adopted from the work of Perez et al. (2017) and applies a featurewise affine transformation to the latent space of the hidden states. Specifically, we use the lexicon features c ( w i ) , in order to conditionally generate the corresponding scaling γ ( · ) and shifting β ( · ) vectors. Concretely:
|
| 91 |
+
|
| 92 |
+
<!-- formula-not-decoded -->
|
| 93 |
+
|
| 94 |
+
<!-- formula-not-decoded -->
|
| 95 |
+
|
| 96 |
+
where W γ , W β , b γ , b β are learnable parameters.
|
| 97 |
+
|
| 98 |
+
## 3.4 Baselines
|
| 99 |
+
|
| 100 |
+
We employ two baselines: The first baseline is an LSTM-based architecture augmented with a selfattention mechanism (Sec. 3.1) with no external knowledge. The second baseline incorporates lexicon information by concatenating the c ( w i ) vec- tors to the word representations in the embedding layer. In Table 3 we use the abbreviations 'baseline' and 'emb. conc.' for the two baseline models respectively.
|
| 101 |
+
|
| 102 |
+
Table 2: Description of benchmark datasets. We split 10% of the train set to serve as the validation set.
|
| 103 |
+
|
| 104 |
+
| Dataset Study Task Domain Classes N train N test SST-5 Socher et al. (2013) Sentiment Movie Reviews 5 9,645 2,210 Sent17 Rosenthal et al. (2017) Sentiment Twitter 3 49,570 12,284 PhychExp Wallbott and Scherer (1986) Emotion Experiences 7 1000 6480 Irony18 Van Hee et al. (2018) Irony Twitter 4 3,834 784 SCv1 Lukin and Walker (2013) Sarcasm Debate Forums 2 1000 995 SCv2 Oraby et al. (2016) Sarcasm Debate Forums 2 1000 2260 |
|
| 105 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 106 |
+
|
| 107 |
+
Table 3: Comparison across benchmark datasets. Reported values are averaged across ten runs. All reported measures are F 1 scores, apart from SST -5 which is evaluated with Accuracy .
|
| 108 |
+
|
| 109 |
+
| Model SST-5 Sent17 PhychExp Irony18 SCv1 SCv2 baseline 43 . 5 ± 0 . 5 68 . 3 ± 0 . 2 53 . 2 ± 0 . 8 46 . 3 ± 1 . 4 64 . 1 ± 0 . 5 74 . 0 ± 0 . 7 emb. conc. 43 . 3 ± 0 . 6 68 . 4 ± 0 . 2 57 . 1 ± 1 . 2 48 . 1 ± 1 . 2 64 . 2 ± 0 . 7 74 . 2 ± 0 . 7 conc. 44 . 0 ± 0 . 7 68 . 6 ± 0 . 3 54 . 3 ± 0 . 6 47 . 4 ± 0 . 9 65.1 ± 0 . 6 74 . 3 ± 1 . 2 gate 44 . 2 ± 0 . 4 68 . 7 ± 0 . 3 53 . 4 ± 1 . 0 48.5 ± 0 . 7 64 . 7 ± 0 . 7 74 . 3 ± 1 . 2 affine 43 . 2 ± 0 . 7 68 . 5 ± 0 . 3 53 . 1 ± 0 . 9 45 . 3 ± 1 . 5 60 . 3 ± 0 . 8 74 . 0 ± 1 . 0 gate+emb.conc. 46.2 ± 0 . 5 68.9 ± 0 . 3 57.2 ± 1 . 1 48.4 ± 1 . 0 64.9 ± 0 . 6 74.4 ± 0 . 9 state-of-the-art 51 . 7 68 . 5 57 . 0 53 . 6 69 . 0 76 . 0 Shen et al. (2018) Cliche (2017) Felbo et al. (2017) Baziotis et al. (2018) Felbo et al. (2017) Ili´ c et al. (2018) |
|
| 110 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 111 |
+
|
| 112 |
+
## 4 Experiments
|
| 113 |
+
|
| 114 |
+
Lexicon Features . As prior knowledge, we leverage the lexicons presented in Table 1. We selected widely-used lexicons that represent different facets of affective and psycho-linguistic features, namely; LIWC (Tausczik and Pennebaker, 2010), Bing Liu Opinion Lexicon (Hu and Liu, 2004), AFINN (Nielsen, 2011), Subjectivity Lexicon (Wilson et al., 2005), SemEval 2015 English Twitter Lexicon (Svetlana Kiritchenko and Mohammad, 2014), and NRC Emotion Lexicon (EmoLex) (Mohammad and Turney, 2013).
|
| 115 |
+
|
| 116 |
+
Datasets . The proposed framework can be applied to different domains and tasks. In this paper, we experiment with sentiment analysis, emotion recognition, irony, and sarcasm detection. Details of the benchmark datasets are shown in Table 2.
|
| 117 |
+
|
| 118 |
+
Preprocessing . To preprocess the words, we use the tool Ekphrasis (Baziotis et al., 2017). After tokenization, we map each word to the corresponding pretrained word representation: Twitterspecific word2vec embeddings (Chronopoulou et al., 2018) for the Twitter datasets, and fasttext (Bojanowski et al., 2017) for the rest.
|
| 119 |
+
|
| 120 |
+
Experimental Setup . For all methods, we employ a single-layer LSTM model with 300 neurons augmented with a self-attention mechanism, as described in Section 3. As regularization techniques, we apply early stopping, Gaussian noise N (0 , 0 . 1) to the word embedding layer, and dropout to the LSTM layer with p = 0 . 2 . We use Adam to optimize our networks (Kingma and Ba, 2014) with mini-batches of size 64 and clip the norm of the gradients (Pascanu et al., 2013) at 0.5, as an extra safety measure against exploding gradients. We also use PyTorch (Paszke et al., 2017) and scikitlearn (Pedregosa et al., 2011).
|
| 121 |
+
|
| 122 |
+
## 5 Results & Analysis
|
| 123 |
+
|
| 124 |
+
We compare the performance of the three proposed conditioning methods with the two baselines and the state-of-the-art in Table 3. We also provide results for the combination of our best method, attentional feature-based gating, and the second baseline model ( emb. conc. ).
|
| 125 |
+
|
| 126 |
+
The results show that incorporating external knowledge in RNN-based architectures consistently improves performance over the baseline for all datasets. Furthermore, feature-based gating im- proves upon baseline concatenation in the embedding layer across benchmarks, with the exception of PsychExp dataset.
|
| 127 |
+
|
| 128 |
+
Figure 2: Attention heatmap of a PsychExp random test sample. The first attention distribution is created with the baseline model without lexicon feature integration, while the second with the combination of our attentional feature-based gating method and the concatenation to word embeddings baseline ( gate+emb.conc. ).
|
| 129 |
+
|
| 130 |
+
<!-- image -->
|
| 131 |
+
|
| 132 |
+
For the Sent17 dataset we achieve state-ofthe-art F 1 score using the feature-based gating method; we further improve performance when combining gating with the emb. conc. method. For SST-5 , we observe a significant performance boost with combined attentional gating and embedding conditioning ( gate + emb. conc. ). For PsychExp , we marginally outperform the state-ofthe-art also with the combined method, while for Irony 18 , feature-based gating yields the best results. Finally, concatenation based conditioning is the top method for SCv 1 , and the combination method for SCv 2 .
|
| 133 |
+
|
| 134 |
+
Overall, attentional feature-based gating is the best performing conditioning method followed by concatenation. Attentional affine transformation underperforms, especially, for smaller datasets; this is probably due to the higher capacity of this model. This is particularly interesting since gating (Eq. 4) is a special case of the affine transformation method (Eq. 5), where the shifting vector β is zero and the scaling vector γ is bounded to the range [0 , 1] (Eq. 6). Interestingly, the combination of gating with traditional embedding-layer concatenation gives additional performance gains for most tasks, indicating that there are synergies to exploit in various conditioning methods.
|
| 135 |
+
|
| 136 |
+
In addition to the performance improvements, we can visually evaluate the effect of conditioning the attention distribution on prior knowledge and improve the interpretability of our approach. As we can see in Figure 2, lexicon features guide the model to attend to more salient words and thus predict the correct class.
|
| 137 |
+
|
| 138 |
+
## 6 Conclusions & Future work
|
| 139 |
+
|
| 140 |
+
We introduce three novel attention-based conditioning methods and compare their effectiveness with traditional concatenation-based conditioning. Our methods are simple, yet effective, achieving consistent performance improvement for all datasets. Our approach can be applied to any RNN-based architecture as a extra module to further improve performance with minimal computational overhead.
|
| 141 |
+
|
| 142 |
+
In the future, we aim to incorporate more elaborate linguistic resources (e.g. knowledge bases) and to investigate the performance of our methods on more complex NLP tasks, such as named entity recognition and sequence labelling, where prior knowledge integration is an active area of research.
|
| 143 |
+
|
| 144 |
+
## Acknowledgements
|
| 145 |
+
|
| 146 |
+
We would like to thank our colleagues Alexandra Chronopoulou and Georgios Paraskevopoulos for their helpful suggestions and comments. This work has been partially supported by computational timegranted from the Greek Research & Technology Network (GR-NET) in the National HPC facility - ARIS. We thank NVIDIA for supporting this work by donating a TitanX GPU.
|
| 147 |
+
|
| 148 |
+
## References
|
| 149 |
+
|
| 150 |
+
Sungjin Ahn, Heeyoul Choi, Tanel Pärnamaa, and Yoshua Bengio. 2016. A neural knowledge language model. arXiv preprint arXiv:1608.00318 .
|
| 151 |
+
|
| 152 |
+
Dzmitry Bahdanau, Kyunghyun Cho, and Yoshua Bengio. 2015. Neural machine translation by jointly learning to align and translate. In Proceedings of the International Conference on Learning Representations .
|
| 153 |
+
|
| 154 |
+
Jorge Balazs and Yutaka Matsuo. 2019. Gating mechanisms for combining character and word-level word representations: an empirical study. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Student Research Workshop , pages 110124, Minneapolis, Minnesota. Association for Computational Linguistics.
|
| 155 |
+
|
| 156 |
+
- Maria Barrett, Joachim Bingel, Nora Hollenstein, Marek Rei, and Anders Søgaard. 2018. Sequence classification with human attention. In Proceedings of the Conference on Computational Natural Language Learning , pages 302-312.
|
| 157 |
+
- Christos Baziotis, Athanasiou Nikolaos, Pinelopi Papalampidi, Athanasia Kolovou, Georgios Paraskevopoulos, Nikolaos Ellinas, and Alexandros Potamianos. 2018. Ntua-slp at semeval-2018 task 3: Tracking ironic tweets using ensembles of word and character level attentive rnns. In Proceedings of the International Workshop on Semantic Evaluation , pages 613-621.
|
| 158 |
+
- Christos Baziotis, Nikos Pelekis, and Christos Doulkeridis. 2017. Datastories at semeval-2017 task 4: Deep lstm with attention for message-level and topic-based sentiment analysis. In Proceedings of the International Workshop on Semantic Evaluation , pages 747-754.
|
| 159 |
+
- Piotr Bojanowski, Edouard Grave, Armand Joulin, and Tomas Mikolov. 2017. Enriching word vectors with subword information. Transactions of the Association for Computational Linguistics , 5:135-146.
|
| 160 |
+
- Jianpeng Cheng, Li Dong, and Mirella Lapata. 2016. Long short-term memory-networks for machine reading. In Proceedings of the Conference on Empirical Methods in Natural Language Processing , pages 551-561.
|
| 161 |
+
- Alexandra Chronopoulou, Aikaterini Margatina, Christos Baziotis, and Alexandros Potamianos. 2018. Ntua-slp at iest 2018: Ensemble of neural transfer methods for implicit emotion classification. In Proceedings of the Workshop on Computational Approaches to Subjectivity, Sentiment and Social Media Analysis , pages 57-64.
|
| 162 |
+
- Mathieu Cliche. 2017. Bb\_twtr at semeval-2017 task 4: Twitter sentiment analysis with cnns and lstms. In Proceedings of the International Workshop on Semantic Evaluation , pages 573-580.
|
| 163 |
+
- Yann N. Dauphin, Angela Fan, Michael Auli, and David Grangier. 2017. Language modeling with gated convolutional networks. In Proceedings of the 34th International Conference on Machine Learning - Volume 70 , ICML'17, pages 933-941. JMLR.org.
|
| 164 |
+
- Bhuwan Dhingra, Hanxiao Liu, Zhilin Yang, William Cohen, and Ruslan Salakhutdinov. 2017. Gatedattention readers for text comprehension. In Proceedings of the Annual Meeting of the Association for Computational Linguistics , pages 1832-1846.
|
| 165 |
+
- Xiaowen Ding, Bing Liu, and Philip S. Yu. 2008. A holistic lexicon-based approach to opinion mining. In Proceedings of the International Conference on Web Search and Data Mining , pages 231-240.
|
| 166 |
+
- Vincent Dumoulin, Ethan Perez, Nathan Schucher, Florian Strub, Harm de Vries, Aaron Courville, and Yoshua Bengio. 2018. Feature-wise transformations. Distill .
|
| 167 |
+
- Vincent Dumoulin, Jonathon Shlens, and Manjunath Kudlur. 2017. A learned representation for artistic style. International Conference on Learning Representations .
|
| 168 |
+
- Bjarke Felbo, Alan Mislove, Anders Søgaard, Iyad Rahwan, and Sune Lehmann. 2017. Using millions of emoji occurrences to learn any-domain representations for detecting sentiment, emotion and sarcasm. In Proceedings of the Conference on Empirical Methods in Natural Language Processing , pages 1615-1625.
|
| 169 |
+
- Abbas Ghaddar and Phillippe Langlais. 2018. Robust lexical features for improved neural network named-entity recognition. In Proceedings of the International Conference on Computational Linguistics , pages 1896-1907.
|
| 170 |
+
- Sepp Hochreiter and JÃijrgen Schmidhuber. 1997. Long short-term memory. Neural Computation , 9:1735-1780.
|
| 171 |
+
- Minqing Hu and Bing Liu. 2004. Mining and summarizing customer reviews. In Proceedings of the International Conference on Knowledge Discovery and Data Mining , pages 168-177.
|
| 172 |
+
- Suzana Ili´ c, Edison Marrese-Taylor, Jorge Balazs, and Yutaka Matsuo. 2018. Deep contextualized word representations for detecting sarcasm and irony. In Proceedings of the Workshop on Computational Approaches to Subjectivity, Sentiment and Social Media Analysis , pages 2-7.
|
| 173 |
+
- Soo-Min Kim and Eduard H. Hovy. 2004. Determining the sentiment of opinions. In Proceedings of the International Conference on Computational Linguistics .
|
| 174 |
+
- Diederik Kingma and Jimmy Ba. 2014. Adam: A method for stochastic optimization. arXiv preprint arXiv:1412.6980 .
|
| 175 |
+
- Abhishek Kumar, Daisuke Kawahara, and Sadao Kurohashi. 2018. Knowledge-enriched two-layered attention network for sentiment analysis. In Proceedings of the Conference of the North American Chapter of the Association for Computational Linguistics , pages 253-258.
|
| 176 |
+
- Zhouhan Lin, Minwei Feng, Cicero Nogueira dos Santos, Mo Yu, Bing Xiang, Bowen Zhou, and Yoshua Bengio. 2017. A structured self-attentive sentence embedding. In Proceedings of the International Conference on Learning Representations .
|
| 177 |
+
- Stephanie Lukin and Marilyn Walker. 2013. Really? well. apparently bootstrapping improves the performance of sarcasm and nastiness classifiers for online dialogue. In Proceedings of the Workshop on Language Analysis in Social Media , pages 30-40.
|
| 178 |
+
- Bryan McCann, James Bradbury, Caiming Xiong, and Richard Socher. 2017. Learned in translation: Contextualized word vectors. In Advances in Neural Information Processing Systems , pages 6294-6305.
|
| 179 |
+
- Tomas Mikolov, Ilya Sutskever, Kai Chen, Greg Corrado, and Jeffrey Dean. 2013. Distributed representations of words and phrases and their compositionality. In Proceedings of the International Conference on Neural Information Processing Systems , pages 3111-3119.
|
| 180 |
+
- Saif M. Mohammad and Peter D. Turney. 2013. Crowdsourcing a word-emotion association lexicon. 29(3):436-465.
|
| 181 |
+
- Nikola Mrkši´ c, Ivan Vuli´ c, Diarmuid Ó Séaghdha, Ira Leviant, Roi Reichart, Milica Gaši´ c, Anna Korhonen, and Steve Young. 2017. Semantic specialization of distributional word vector spaces using monolingual and cross-lingual constraints. 5:309324.
|
| 182 |
+
- F. Å. Nielsen. 2011. Afinn.
|
| 183 |
+
- Shereen Oraby, Vrindavan Harrison, Lena Reed, Ernesto Hernandez, Ellen Riloff, and Marilyn Walker. 2016. Creating and characterizing a diverse corpus of sarcasm in dialogue. In Proceedings of the Annual Meeting of the Special Interest Group on Discourse and Dialogue , pages 31-41.
|
| 184 |
+
- Razvan Pascanu, Tomas Mikolov, and Yoshua Bengio. 2013. On the difficulty of training recurrent neural networks. International Conference on Machine Learning , 28:1310-1318.
|
| 185 |
+
- Adam Paszke, Sam Gross, Soumith Chintala, Gregory Chanan, Edward Yang, Zachary DeVito, Zeming Lin, Alban Desmaison, Luca Antiga, and Adam Lerer. 2017. Automatic differentiation in pytorch.
|
| 186 |
+
- Fabian Pedregosa, Gaël Varoquaux, Alexandre Gramfort, Vincent Michel, Bertrand Thirion, Olivier Grisel, Mathieu Blondel, Peter Prettenhofer, Ron Weiss, Vincent Dubourg, and others. 2011. Scikitlearn: Machine learning in Python. Journal of Machine Learning Research , 12:2825-2830.
|
| 187 |
+
- Jeffrey Pennington, Richard Socher, and Christopher D Manning. 2014. Glove: Global vectors for word representation. In Proceedings of the Conference on Empirical Methods in Natural Language Processing , pages 1532-1543.
|
| 188 |
+
- Ethan Perez, Florian Strub, Harm de Vries, Vincent Dumoulin, and Aaron C. Courville. 2017. Film: Visual reasoning with a general conditioning layer. CoRR , abs/1709.07871.
|
| 189 |
+
- Matthew Peters, Mark Neumann, Mohit Iyyer, Matt Gardner, Christopher Clark, Kenton Lee, and Luke Zettlemoyer. 2018. Deep contextualized word representations. In Proceedings of the Conference of the North American Chapter of the Association for Computational Linguistics , pages 2227-2237.
|
| 190 |
+
- Matthew E. Peters, Waleed Ammar, Chandra Bhagavatula, and Russell Power. 2017. Semi-supervised sequence tagging with bidirectional language models. CoRR , abs/1705.00108.
|
| 191 |
+
- Tim Rocktäschel, Edward Grefenstette, Karl Moritz Hermann, Tomás Kociský, and Phil Blunsom. 2016. Reasoning about entailment with neural attention. In Proceedings of the International Conference on Learning Representations .
|
| 192 |
+
- Sara Rosenthal, Noura Farra, and Preslav Nakov. 2017. Semeval-2017 task 4: Sentiment analysis in twitter. In Proceedings of the International Workshop on Semantic Evaluation , pages 502-518.
|
| 193 |
+
- Tao Shen, Tianyi Zhou, Guodong Long, Jing Jiang, Shirui Pan, and Chengqi Zhang. 2018. Disan: Directional self-attention network for rnn/cnn-free language understanding. In Association for the Advancement of Artificial Intelligence .
|
| 194 |
+
- Bonggun Shin, Timothy Lee, and Jinho D. Choi. 2017. Lexicon integrated cnn models with attention for sentiment analysis. In Proceedings of the Workshop on Computational Approaches to Subjectivity, Sentiment and Social Media Analysis , pages 149-158.
|
| 195 |
+
- Richard Socher, Alex Perelygin, Jean Wu, Jason Chuang, Christopher D. Manning, Andrew Ng, and Christopher Potts. 2013. Recursive deep models for semantic compositionality over a sentiment treebank. In Proceedings of the Conference on Empirical Methods in Natural Language Processing , pages 1631-1642.
|
| 196 |
+
- Florian Strub, Mathieu Seurin, Ethan Perez, Harm de Vries, Jeremie Mary, Philippe Preux, and Aaron CourvilleOlivier Pietquin. 2018. Visual reasoning with multi-hop feature modulation. In The European Conference on Computer Vision (ECCV) .
|
| 197 |
+
- Xiaodan Zhu Svetlana Kiritchenko and Saif M. Mohammad. 2014. Sentiment analysis of short informal texts. 50:723-762.
|
| 198 |
+
- Maite Taboada, Julian Brooke, Milan Tofiloski, Kimberly Voll, and Manfred Stede. 2011. Lexicon-based methods for sentiment analysis. Comput. Linguist. , 37(2):267-307.
|
| 199 |
+
- Yla R. Tausczik and James W. Pennebaker. 2010. The psychological meaning of words: Liwc and computerized text analysis methods. Journal of Language and Social Psychology , 29(1):24-54.
|
| 200 |
+
- Zhiyang Teng, Duy-Tin Vo, and Yue Zhang. 2016. Context-sensitive lexicon features for neural sentiment analysis. In Proceedings of the 2016 Conference on Empirical Methods in Natural Language Processing , pages 1629-1638, Austin, Texas. Association for Computational Linguistics.
|
| 201 |
+
- [Marcel Trotzek, Sven Koitka, and Christoph M. Friedrich. 2018. Utilizing neural networks and linguistic metadata for early detection of depression indications in text sequences. CoRR , abs/1804.07000.](http://arxiv.org/abs/1804.07000)
|
| 202 |
+
- Cynthia Van Hee, Els Lefever, and Veronique Hoste. 2018. Semeval-2018 task 3: Irony detection in english tweets. In Proceedings of The International Workshop on Semantic Evaluation , pages 39-50.
|
| 203 |
+
- Shikhar Vashishth, Rishabh Joshi, Sai Suman Prayaga, Chiranjib Bhattacharyya, and Partha Talukdar. 2018. Reside: Improving distantly-supervised neural relation extraction using side information. In Proceedings of the Conference on Empirical Methods in Natural Language Processing , pages 1257-1266.
|
| 204 |
+
- Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Ł ukasz Kaiser, and Illia Polosukhin. 2017. Attention is all you need. In Advances in Neural Information Processing Systems , pages 5998-6008.
|
| 205 |
+
- Harald G. Wallbott and Klaus R. Scherer. 1986. How universal and specific is emotional experience? evidence from 27 countries on five continents. Information (International Social Science Council) , 25:763-795.
|
| 206 |
+
- Bingning Wang, Shangmin Guo, Kang Liu, Shizhu He, and Jun Zhao. 2016. Employing external rich knowledge for machine comprehension. In Proceedings of the Twenty-Fifth International Joint Conference on Artificial Intelligence , IJCAI'16, pages 2929-2935. AAAI Press.
|
| 207 |
+
- Theresa Wilson, Paul Hoffmann, Swapna Somasundaran, Jason Kessler, Janyce Wiebe, Yejin Choi, Claire Cardie, Ellen Riloff, and Siddharth Patwardhan. 2005. Opinionfinder: A system for subjectivity analysis. In Proceedings of HLT/EMNLP on Interactive Demonstrations . Association for Computational Linguistics.
|
| 208 |
+
- Yonghui Wu, Mike Schuster, Zhifeng Chen, Quoc V. Le, Mohammad Norouzi, Wolfgang Macherey, Maxim Krikun, Yuan Cao, Qin Gao, Klaus Macherey, Jeff Klingner, Apurva Shah, Melvin Johnson, Xiaobing Liu, Lukasz Kaiser, Stephan Gouws, Yoshikiyo Kato, Taku Kudo, Hideto Kazawa, Keith Stevens, George Kurian, Nishant Patil, Wei Wang, Cliff Young, Jason Smith, Jason Riesa, Alex Rudnick, Oriol Vinyals, Greg Corrado, Macduff Hughes, and Jeffrey Dean. 2016. Google's neural machine translation system: Bridging the gap between human and machine translation. CoRR , abs/1609.08144.
|
| 209 |
+
- Caiming Xiong, Victor Zhong, and Richard Socher. 2017. Dynamic coattention networks for question answering. In International Conference on Learning Representations .
|
| 210 |
+
- Kelvin Xu, Jimmy Ba, Ryan Kiros, Kyunghyun Cho, Aaron Courville, Ruslan Salakhudinov, Rich Zemel, and Yoshua Bengio. 2015. Show, attend and tell: Neural image caption generation with visual attention. In Proceedings of the International Conference on Machine Learning , pages 2048-2057.
|
| 211 |
+
- Fan Yang, Arjun Mukherjee, and Eduard Dragut. 2017. Satirical news detection and analysis using attention mechanism and linguistic features. In Proceedings of the Conference on Empirical Methods in Natural Language Processing , pages 1979-1989.
|
| 212 |
+
- Mo Yu and Mark Dredze. 2014. Improving lexical embeddings with semantic knowledge. In Proceedings of the Annual Meeting of the Association for Computational Linguistics , pages 545-550.
|
text-versions/attention-markdown/1908.05819_Mixed HighOrder Attention Network for Pe.md
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1908.05819 Mixed Highorder Attention Network For Pe
|
| 2 |
+
|
| 3 |
+
## Mixed High-Order Attention Network for Person Re-Identification
|
| 4 |
+
|
| 5 |
+
Binghui Chen, Weihong Deng ∗
|
| 6 |
+
|
| 7 |
+
, Jiani Hu
|
| 8 |
+
|
| 9 |
+
Beijing University of Posts and Telecommunications
|
| 10 |
+
|
| 11 |
+
chenbinghui@bupt.edu.cn, whdeng@bupt.edu.cn, jnhu@bupt.edu.cn
|
| 12 |
+
|
| 13 |
+
## Abstract
|
| 14 |
+
|
| 15 |
+
Attention has become more attractive in person reidentification (ReID) as it is capable of biasing the allocation of available resources towards the most informative parts of an input signal. However, state-of-the-art works concentrate only on coarse or first-order attention design, e.g. spatial and channels attention, while rarely exploring higher-order attention mechanism. We take a step towards addressing this problem. In this paper, we first propose the High-Order Attention (HOA) module to model and utilize the complex and high-order statistics information in attention mechanism, so as to capture the subtle differences among pedestrians and to produce the discriminative attention proposals. Then, rethinking person ReID as a zero-shot learning problem, we propose the Mixed High-Order Attention Network (MHN) to further enhance the discrimination and richness of attention knowledge in an explicit manner. Extensive experiments have been conducted to validate the superiority of our MHN for person ReID over a wide variety of state-of-the-art methods on three large-scale datasets, including Market-1501, DukeMTMC-ReID and CUHK03-NP. Code is available at http://www.bhchen.cn/.
|
| 16 |
+
|
| 17 |
+
## 1. Introduction
|
| 18 |
+
|
| 19 |
+
Since the quest for algorithms that enable cognitive abilities is an important part of machine learning, person reidentification (ReID) has become more attractive, where the model is requested to be capable of correctly matching images of pedestrians across videos captured from different cameras. This task has drawn increasing attention in many computer vision applications, such as surveillance [49], activity analysis [31, 32] and people tracking [55, 44]. It is also challenging because the images of pedestrians are captured from disjoint views, the lighting-conditions/personposes differ across cameras, and occlusions are frequent in real-world scenarios.
|
| 20 |
+
|
| 21 |
+
Affected by the aforementioned factors, the discrimina- tion of feature representations of pedestrian images actually is not good enough. In order to obtain discriminative feature representations, many research works [30, 27, 25, 52, 21, 58, 45] resort to attention mechanism so as to highlight the informative parts (e.g. spatial locations) of convolutional responses and suppress the noisy patterns (e.g. background). Specifically, spatial attention [25, 27, 52] is a form of visual attention that involves directing attention to a location in space, it allows CNN to selectively process visual information of an area within the visual field. While, in spatial attention, the processing strategy of spatial masking is coarse and has no intrinsic effect on modulating the finegrained channel-knowledge. Recently, channel attention [10, 19, 27] is proposed to adaptively recalibrates channelwise convolutional responses by explicitly modelling interdependencies among channels. And the combination of spatial and channel attention has also been successfully applied in person ReID [27]. However, we emphasize that these commonly used attention methods (i.e. spatial and channel attention) are either coarse or first-order, being confined to mining only simple and coarse information, in person ReID cases, they are insufficiently rich to capture the complex/high-order interactions of visual parts and the subtle differences among pedestrians caused by various viewpoints/person poses, as a result, the produced attention maps are neither discriminative or detailed. To this end, we dedicate to modeling the attention mechanism via high-order statistics of convolutional activations so as to capture more complex and high-order relationships among parts and to produce powerful attention proposals.
|
| 22 |
+
|
| 23 |
+
∗ Corresponding author
|
| 24 |
+
|
| 25 |
+
Figure 1. Attention comparison. (1) Spatial attention uses softmax-like gated functions to produce a spatial mask. (2) Channel attention [19] uses global average pooling and fully connected layers to produce a scale vector. (3) Our high-order attention uses high-order polynomial predictor to produce scale maps that contain high-order statistics of convolutional activations.
|
| 26 |
+
|
| 27 |
+
<!-- image -->
|
| 28 |
+
|
| 29 |
+
Moreover, we rethink the problem of person ReID as a zero-shot learning (ZSL) task where there is no intersection of pedestrian identities between training and testing sets. Zero-shot learning has large gap with conventional full-shot learning (e.g. classification on CIFAR [8, 7], Imagenet [38]), and in zero-shot settings, the phenomenon of ' partial/biased learning behavior of deep model ' [5] largely affects the embedding performance, i.e. the deep model will only focus on the biased visual knowledges that only benefit to the seen identities and ignore the other helpful ones that might be useful for identifying the unseen identities. In other words, deep models easily learn to focus on surface statistical regularities rather than more general abstract concepts. However, many ReID works ignore this intrinsic problem of zero-shot learning. To this end, proposing detail-preserving attention framework remains important.
|
| 30 |
+
|
| 31 |
+
In this paper, we first propose High-Order Attention (HOA) module, a novel and powerful attention mechanism, to model the complex and high-order relationships among visual parts via high-order polynomial predictor, such that the subtle differences among pedestrian can be captured and discriminative attention results can be produced. Then, rethinking person ReID as a zero-shot problem, we propose Mixed High-Order Attention Network (MHN) to prevent the problem of 'biased learning behavior of deep model' [5] and to encourage the richness of attention information. It is mainly achieved by employing multiple HOA modules with different orders to model diverse high-order statistics, such that all-sided attention knowledge can be preserved and thus the unseen pedestrian identity can be successfully recognized. Additionally, we introduce the adversarial learning constraint for MHN to further prevent the order collapse problem during training 1 , so as to explicitly enhance the discrimination of MHN. Our contributions can be summarized as follows:
|
| 32 |
+
|
| 33 |
+
- The High-Order Attention (HOA) module is proposed to capture and use high-order attention distributions. To our knowledge, it is the first work to propose and apply high-order attention module in Person-ReID.
|
| 34 |
+
- We rethink ReID as zero-shot learning task and propose the Mixed High-Order Attention Network
|
| 35 |
+
|
| 36 |
+
1 Although, the proposed high-order attention module has ability to capture complex and high-order statistics, but suffering from 'biased learning behavior of deep model', in zero-shot settings, the high-order module might collapse to lower-order module.
|
| 37 |
+
|
| 38 |
+
(MHN) to efficiently utilize multiple HOA modules, so as to enhance the richness of attention by explicitly suppressing the 'biased learning behavior of deep model'. And adversary learning constraint is introduced to further prevent the problem of order collapse.
|
| 39 |
+
|
| 40 |
+
- MHN is a generally applicable and model-agnostic framework, it can be easily applied in the popular baseline architectures, such as IDE [63] and PCB [43].
|
| 41 |
+
- Extensive experiments demonstrate the superiority of the proposed MHN over a wide range of state-ofthe-art ReID models on three large benchmarks, i.e. Market-1501 [61], DukeMTMC-ReID [37, 65] and CUHK03-NP [26, 66].
|
| 42 |
+
|
| 43 |
+
## 2. Related work
|
| 44 |
+
|
| 45 |
+
Person ReID & Attention Mechanism : Person ReID intends to correctly match images of pedestrians across videos captured from different cameras, it has been widely studied, such as ranking by pairwise constraints [34, 48], metric learning [54, 51], deep embedding learning [63, 43], re-ranking [62, 16] and attributes learning [40, 60]. Recently, attention methods [10, 53, 19, 46] in deep community are more attractive, in this paper, we focus on improving the performance of ReID via attention strategy.
|
| 46 |
+
|
| 47 |
+
Attention serves as a tool to bias the allocation of available resources towards the most informative parts of an input. Li et al. [24] propose a part-aligning CNN network for locating latent regions (i.e. hard attention) and then extract and exploit these regional features for ReID. Zhao et at. [59] employ the Spatial Transformer Network [20] as the hard attention model for finding discriminative image parts. Except hard attention methods, soft attention strategies are also proposed to enhance the performance of ReID. For example, Li et at. [25] use multiple spatial attention modules (by softmax function) to extract features at different spatial locations. Xu et al. [52] propose to mask the convolutional maps via pose-guided attention module. Li et al. [27] employ both the softmax-based spatial attention module and channel-wise attention module [19] to enhance the convolutional response maps. However, spatial attention and channel attention are coarse and first-order respectively, and are not capable of modeling the complex and high-order relationships among parts, resulting in loss of fine-grained information. Thus, to capture detailed and complex information, we propose High-Order Attention (HOA) module.
|
| 48 |
+
|
| 49 |
+
High-order statistics : It has been widely studied in traditional machine learning due to its powerful representation ability. And recently, the progresses of challenging finegrained visual categorization task demonstrates integration of high-order pooling representations with deep CNNs can bring promising improvements. For example, Lin et al. [29] proposed bilinear pooling to aggregate the pairwise feature interactions. Gao et al. [15] proposed to approximate the second-order statistics via Tensor Sketch [35]. Yin et al. [12] aggregated higher-order statistics by iteratively applying the Tensor Sketch compression to the features. Cai et al. [2] used high-order pooling to aggregate hierarchical convolutional responses. Moreover, the bilinear pooling and highorder pooling methods are also applied in Visual-QuestionAnswering task, such as [14, 22, 56, 57]. However, different from these above methods which mainly focus on using high-order statistics on top of feature pooling, resulting in high-dimensional feature representations that are not suitable for efficient/fast pedestrian search, we instead intend to enhance the feature discrimination by attention learning. We model high-order attention mechanism to capture the high-order and subtle differences among pedestrians, and to produce the discriminative attention proposals.
|
| 50 |
+
|
| 51 |
+
Zero-Shot Learning : In ZSL, the model is required to learn from the seen classes and then to be capable of utilizing the learned knowledge to distinguish the unseen classes. It has been studied in image classification [28, 4], video recognition [13] and image retrieval/clustering [5]. Interestingly, person ReID matches the setting of ZSL well where training identities have no intersection with testing identities, but most the existing ReID works ignore the problem of ZSL. To this end, we propose Mixed High-Order Attention Network (MHN) to explicitly depress the problem of 'biased learning behavior of deep model' [5, 6] caused by ZSL, allowing the learning of all-sided attention information which might be useful for unseen identities, preventing the learning of biased attention information that only benefits to the seen identities.
|
| 52 |
+
|
| 53 |
+
## 3. Proposed Approach
|
| 54 |
+
|
| 55 |
+
In this section, we will first provide the formulation of the general attention mechanism in Sec. 3.1, then detail the proposed High-Order Attention (HOA) module in Sec. 3.2, finally show the overall framework of our Mixed HighOrder Attention Network (MHN) in Sec. 3.3.
|
| 56 |
+
|
| 57 |
+
## 3.1. Problem Formulation
|
| 58 |
+
|
| 59 |
+
Attention acts as a tool to bias the allocation of available resources towards the most informative parts of an input. In convolutional neural network (CNN), it is commonly used to reweight the convolutional response maps so as to highlight the important parts and suppress the uninformative ones, such as spatial attention [25, 27] and channel attention [19, 27]. We extend these two attention methods to a general case. Specifically, for a convolutional activation output, a 3D tensor X , encoded by CNN and coming from the given input image. We have X ∈ R C × H × W , where C, H, W indicate the number of channel, height and width, resp . As aforementioned, the goal of attention is to reweight the convolutional output, we thus formulate this process as:
|
| 60 |
+
|
| 61 |
+
<!-- formula-not-decoded -->
|
| 62 |
+
|
| 63 |
+
where A ( X ) ∈ R C × H × W is the attention proposal output by a certain attention module, ⊙ is the Hadamard Product (element-wise product). As A ( X ) serves as a reweighting term, the value of each element of A ( X ) should be in the interval [0 , 1] . Based on the above general formulation of attention, A ( X ) can take many different forms. For example, if A ( X ) = rep [ M ] | C where M ∈ R H × W is a spatial mask and rep [ M ] | C means replicate this spatial mask M along channel dimension by C times, Eq. 1 thus is the implementation of spatial attention . And if A ( X ) = rep [ V ] | H,W where V ∈ R C is a scale vector and rep [ V ] | H,W means replicate this scale vector along height and width dimensions by H and W times resp , Eq. 1 thus is the implementation of channel attention .
|
| 64 |
+
|
| 65 |
+
However, in spatial attention or channel attention , A ( X ) is coarse and unable to capture the high-order and complex interactions among parts, resulting in less discriminative attention proposals and failing in capturing the subtle differences among pedestrians. To this end, we dedicate to modeling A ( X ) with high-order statistics.
|
| 66 |
+
|
| 67 |
+
## 3.2. High-Order Attention Module
|
| 68 |
+
|
| 69 |
+
To model the complex and high-order interactions within attention, we first define a linear polynomial predictor on top of the high-order statistics of x , where x ∈ R C denotes a local descriptor at a specific spatial location of X :
|
| 70 |
+
|
| 71 |
+
<!-- formula-not-decoded -->
|
| 72 |
+
|
| 73 |
+
where 〈· , ·〉 indicates the inner product of two same-sized tensors, R is the number of order, ⊗ r x is the r-th order outer-product of x that comprises all the degree-r monomials in x , and w r is the r-th order tensor to be learned that contains the weights of degree-r variable combinations in x .
|
| 74 |
+
|
| 75 |
+
Considering w r with large r will introduce excessive parameters and incur the problem of overfitting, we suppose that when r > 1 , w r can be approximated by D r rank-1 tensors by Tensor Decomposition [23], i.e. w r = ∑ D r d =1 α r,d u r,d 1 ⊗ · · · ⊗ u r,d r when r > 1 , where u r,d 1 ∈ R C , . . . , u r,d r ∈ R C are vectors, ⊗ is the outer-product, α r,d is the weight for d -th rank-1 tensor. Then according to the tensor algebra, Eq. 2 can be reformulated as:
|
| 76 |
+
|
| 77 |
+
<!-- formula-not-decoded -->
|
| 78 |
+
|
| 79 |
+
where α r = [ α r, 1 , · · · , α r,D r ] T is the weight vector, z r = [ z r, 1 , · · · , z r,D r ] T with z r,d = ∏ r s =1 〈 u r,d s , x 〉 . For later convenience, Eq. 3 can also be written as:
|
| 80 |
+
|
| 81 |
+
<!-- formula-not-decoded -->
|
| 82 |
+
|
| 83 |
+
where ⊙ is Hadamard Product and 1 T is a row vector of ones. Then, to obtain a vector-like predictor a ( x ) ∈ R C , Eq. 4 is generalized by introducing the auxiliary matrixes P r :
|
| 84 |
+
|
| 85 |
+
<!-- formula-not-decoded -->
|
| 86 |
+
|
| 87 |
+
where P 1 ∈ R C × C , P r ∈ R D r × C with r > 1 . Since all P r , w 1 , α r are parameters to be learned, for implementation convenience, we can integrate { P 1 , w 1 } into a new single matrix ̂ w 1 ∈ R C × C according to matrix algebra, and { P r , α r } into ̂ α r ∈ R D r × C (simple proof is in Supplementary file). Then Eq. 5 can be expressed as:
|
| 88 |
+
|
| 89 |
+
<!-- formula-not-decoded -->
|
| 90 |
+
|
| 91 |
+
The above equation contains two terms, for clarity, we intend to formulate it into a more general case. Suppose ̂ w 1 can be approximated by the multiplication of two matrixes ̂ v ∈ R C × D 1 and ̂ α 1 ∈ R D 1 × C , i.e. ̂ w 1 = ̂ v ̂ α 1 . then Eq. 6 can be reformulated as:
|
| 92 |
+
|
| 93 |
+
<!-- formula-not-decoded -->
|
| 94 |
+
|
| 95 |
+
where z 1 = ̂ v T x , and when r > 1 , z r is the same as in Eq. 3. ̂ α r ∈ R D r × C are the trainable parameters.
|
| 96 |
+
|
| 97 |
+
In Eq.7, a ( x ) is capable of modeling and using the highorder statistics of the local descriptor x , thus, we can obtain the high-order vector-like attention 'map' by performing Sigmoid function on Eq. 7:
|
| 98 |
+
|
| 99 |
+
<!-- formula-not-decoded -->
|
| 100 |
+
|
| 101 |
+
where A ( x ) ∈ R C and the value of each element in A ( x ) is in the interval [0 , 1] .
|
| 102 |
+
|
| 103 |
+
Nonlinearity : Moreover, in order to further improve the representation capacity of this high-order attention 'map', inspired by the common design of CNN, we provide a variation of Eq.8 by introducing nonlinearity as follows:
|
| 104 |
+
|
| 105 |
+
<!-- formula-not-decoded -->
|
| 106 |
+
|
| 107 |
+
where σ denotes an arbitrary non-linear activation function, here, we use ReLU [33] function. A ( x ) in Eq.9 is finally employed as the required high-order attention 'map' for the corresponding local descriptor x . The experimental comparisons between Eq.8 and Eq.9 are in Sec. 4.
|
| 108 |
+
|
| 109 |
+
Full module : As aforementioned, A ( x ) is defined on a local descriptor x , to obtain A ( X ) which is defined on 3D
|
| 110 |
+
|
| 111 |
+
Figure 2. Illustration of High-Order Attention (HOA) modules.
|
| 112 |
+
|
| 113 |
+
<!-- image -->
|
| 114 |
+
|
| 115 |
+
tensor X , we generalize Eq.9. Specifically, we share the learnable weights in A ( x ) among different spatial locations of X and let A ( X ) = { A ( x (1 , 1) ) , · · · , A ( x ( H,W ) ) } , where x ( h,w ) indicates a local descriptor at spatial location point ( h, w ) of X . Employing this attention map A ( X ) in CNN has two benefits. (1) sharing weights among different spatial locations will not incur excessive parameters. (2) A ( X ) can be easily implemented by 1x1 convolution layers. After obtaining the high-order attention map A ( X ) , our HighOrder Attention (HOA) module can be formulated in the same way as Eq. 1, i.e. Y = A ( X ) ⊙X .
|
| 116 |
+
|
| 117 |
+
Implementation : Since the learnable parameters are shared among spatial locations, all operations in A ( X ) can be implemented by Convolution. As illustrated in Fig. 2.(a), when R = 1 , matrixes { ̂ v , ̂ α 1 } are implemented by 1x1 convolution layers with D 1 and C output channels, resp . When R > 1 , r > 1 , we first employ { u r,d s } d =1 , ··· ,D r as a set of D r 1x1 convolutional filters on X so as to produce a set of feature maps Z r s with channels D r , then feature maps {Z r s } s =1 , ··· ,r are combined by element-wise product to obtain Z r = Z r 1 ⊙··· ⊙ Z r r , where Z r = { z r } , and ̂ α r can also be implemented by 1x1 convolution layer. A toy example of HOA when R = 3 is illustrated in Fig.2.(b).
|
| 118 |
+
|
| 119 |
+
Remark : The proposed HOA module can be easily implemented by the commonly used operations, such as 1x1 convolution and element-wise product/addition. Equipped by the powerful high-order predictor, the attention proposals could be more discriminative and is capable of modeling the complex and high-order relationships among parts. Moreover, the channel attention module in [19, 27] is called to be fi rst-order because (1) GAP layer only collects firstorder statistics while neglecting richer higher-order ones, suffering from limited representation ability [11] (2) fullyconnected layers can be regarded as 1x1 convolution layers and thus the two cascaded fully-connected layers used in channel-attention [19] are equivalent to our HOA module when R = 1 (regardless of the spatial dimensions and see Fig.2.(a)). In summary, the full channel attention module can only collect and utilize the first-order information, being insufficiently rich to capture the complex interactions and to produce the discriminative attention maps. And if without using GAP, the channel attention module can be regarded as a special case of our HOA with R = 1 , further demonstrating it indeed is first-order.
|
| 120 |
+
|
| 121 |
+
Figure 3. Illustration of Mixed High-Order Attention Network (MHN). Our MHN is model-agnostic, it can be applied in both IDE [63] and PCB [43] architectures, here for clarity, we take ResNet50 [18] based IDE for example. The adversary constraint is used to regularize the order of HOA modules.
|
| 122 |
+
|
| 123 |
+
<!-- image -->
|
| 124 |
+
|
| 125 |
+
## 3.3. Mixed High-Order Attention Network
|
| 126 |
+
|
| 127 |
+
Considering that Person ReID essentially pertains to zero-shot learning (ZSL), where there is no intersection between training identities and testing identities, we should explicitly suppress the problem of 'biased learning behavior of deep model' caused by zero-shot settings [5]. Specifically, in ZSL, the deep model easily learn to focus on surface statistical regularities rather than more general abstract concepts, in other words, deep model will selectively learn the biased knowledge that are only useful to distinguish the seen identities, while ignore the knowledge that might be useful for unseen ones. Therefore, to correctly recognize the unseen identities, we propose Mixed High-Order Attention Network (MHN) to utilize multiple HOA modules with different orders such that the diverse and complementary high-order information can be explicitly used, encouraging the richness of the learned features and preventing the learning of partial/biased visual information.
|
| 128 |
+
|
| 129 |
+
For a toy example as shown in Fig. 3, the proposed MHN is constituted by several different HOA modules such that the diverse statistics of visual knowledge could be modeled and used. In particular, ResNet50 is first decomposed into two parts, i.e. P 1 (from conv1 to layer2 2 ) and P 2 (from layer3 to GAP ). P 1 is used to encode the given image from raw pixel space to mid-level feature space, P 2 is used to encode the attentional information to the high-level feature space where the data can be classified. HOA modules with different orders (e.g. { R = 1 , 2 , 3 } ) are placed between P 1 and P 2 so as to produce the diverse high-order attention maps and intensify the richness within learned knowledge. Worthy of mention is that our MHN won't introduce excessive parameters since P 2 modules share the same weights across different attention streams.
|
| 130 |
+
|
| 131 |
+
2 Named in pytorch [36] manner.
|
| 132 |
+
|
| 133 |
+
However, simply employing multiple HOA modules with different orders won't lead the best performance of MHN, since one HOA module with higher order might collapse to a relatively lower order module due to 'the partial/biased learning behavior of deep model'. Specifically, from Eq. 7, one can observe that for a k -th order HOA module, a ( x ) also contains the l -th order sub-term (where l < k ). In theory, HOA module with R = k can capture and use the k -th order statistics of local descriptor x , but in actual, especially in zero-shot learning settings, due to the fact that the deep model will selectively learn surface statistical regularities that are the easiest ones to distinguish the seen classes [5], the k -th order attention module might collapse to a lower-order counterpart as lower-order statistics are common and are much easier to collect than higher-order statistics. Therefore, these HOA modules with different R s actually collapse to some similar lower-order counterparts, and the wanted diverse higher-order attention information are not captured. To this end, inspired by GAN [17], we introduce the adversary constraint for regularizing the order of HOA to be different, as shown in Fig. 3, it can be formulated as:
|
| 134 |
+
|
| 135 |
+
̸
|
| 136 |
+
|
| 137 |
+
where HOA | R = k R =1 means there are k HOA modules (from first-order to k -th order) in MHN, F indicates the encoding function parameterized by the adversary network which contains two fully-connected layers, f j is the feature representation vector learned from the corresponding HOA module with R = j . In Eq. 10, the adversary network F tries to minimize the discrepancies among features f j while HOA modules try to maximize these discrepancies. After obtaining the Nash Equilibrium, the orders of HOA modules will be different with each other, since during the optimization of Eq.10, P 2 shares across streams and the only differentiating parts in MHN are HOA modules, when maximizing the feature discrepancies, the only solution is to make the HOA modules have different orders and produce diverse attention knowledge. In other words, only diverse HOA modules will make L adv large. Thus the problem of order collapse can be suppressed.
|
| 138 |
+
|
| 139 |
+
<!-- formula-not-decoded -->
|
| 140 |
+
|
| 141 |
+
Then, the overall objective function of MHN is as:
|
| 142 |
+
|
| 143 |
+
<!-- formula-not-decoded -->
|
| 144 |
+
|
| 145 |
+
where L ide indicates the identity loss based on Softmax classifier, λ is the coefficient.
|
| 146 |
+
|
| 147 |
+
Remark : From Eq.11, one can observe that we regularize the order/diversity of HOA modules by imposing constraint on the encoded feature vectors, instead of directly on the high-order attention maps, since these attention maps come from the complex high-order statistics and the definition of the order difference of HOA modules in the attention space is too hard to be artificially made. Thus, the order constraint is imposed on the feature vectors. Moreover, it seems that using Hinge loss based constraint instead of the adversary strategy to maximize the feature discrepancies is also feasible. However, we want to emphasize that in Hinge loss based function there is another margin-controller 'm' which needs extra tuning, and the discrepancies between features that coming from different HOA modules will be heterogeneous, thus to determine the optimal margin 'm', many redundant experiments must be executed. To this end, we employ the adversary constraint so as to allow the automatic learning of the optimal discrepancies.
|
| 148 |
+
|
| 149 |
+
By preventing the problem of order collapse, the HOA modules are explicitly regularized to model the wanted high-order attention distributions and thus can produce the discriminative and diverse attention maps which could be benefit for recognizing the unseen identities.
|
| 150 |
+
|
| 151 |
+
## 4. Experiments
|
| 152 |
+
|
| 153 |
+
Datasets : We use three popular benchmark datasets based on zero-shot learning (ZSL) settings, i.e. Market1501 [61], DukeMTMC-ReID [37, 65] and CUHK03-NP [26, 66]. Market-1501 have 12,936 training images with 751 different identities. Gallery and query sets have 19,732 and 3,368 images respectively with another 750 identities. DukeMTMC-ReID includes 16,522 training images of 702 identities, 2,228 query and 17,661 gallery images of another 702 identities. CUHK03-NP is a new training-testing split protocol for CUHK03, it contains two subsets which provide labeled and detected (from a person detector) person images. The detected CUHK03 set includes 7,365 training images, 1,400 query images and 5,332 gallery images. The labeled set contains 7,368 training, 1,400 query and 5,328 gallery images respectively. The new protocol splits the training and testing sets into 767 and 700 identities.
|
| 154 |
+
|
| 155 |
+
Implementation : The proposed MHN is applied on both ResNet50-based IDE [63] and PCB [43] architectures. For both architectures, we adopt the SGD optimizer with a momentum factor of 0.9, set the start learning rate to be 0.01 for backbone CNN and ten times learning rate for the new added layers, and a total of 70 epochs with the learning rate decreased by a factor of 10 each 20 epochs. The dimension of feature f j is 256 and the two FC layers in F have 128, 128 neurons resp , we set all D r | R r =1 to be 64. For IDE, the images are resized to 288x144. For PCB, the images are resized to 336x168. We set the batch size to 32 in all experiments and use one 1080Ti GPU. MHN is implemented by Pytorch [36] and modified from the public code[1], random erasing[67] is also applied. Notation : We use 'MHNk ' to denote that in MHN there are k HOA modules with orders R = { 1 , · · · , k } resp , and 'MHNk (IDE/PCB)' to denote using IDE/PCB architectures, resp .
|
| 156 |
+
|
| 157 |
+
| Market-1501 (%) Methods Ref R-1 R-5 R-10 mAP BoW+kissme [61] ICCV15 44.4 63.9 72.2 20.8 SVDNet [42] ICCV17 82.3 - - 62.1 DaRe(De)+RE [50] CVPR18 89.0 - - 76.0 MLFN [3] CVPR18 90.0 - - 74.3 KPM [39] CVPR18 90.1 96.7 97.9 75.3 HA-CNN [27] CVPR18 91.2 - - 75.7 DNN-CRF [9] CVPR18 93.5 97.7 - 81.6 PABR [41] ECCV18 91.7 96.9 98.1 79.6 PCB+RPP [43] ECCV18 93.8 97.5 98.5 81.6 Mancs [47] ECCV18 93.1 - - 82.3 CASN+PCB [64] CVPR19 94.4 - - 82.8 IDE ∗ [63] 89.0 95.7 97.3 73.9 MHN-6 (IDE) 93.6 97.7 98.6 83.6 PCB ∗ [43] 93.1 97.5 98.5 78.6 MHN-6 (PCB) 95.1 98.1 98.9 85.0 |
|
| 158 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 159 |
+
|
| 160 |
+
Table 1. Results comparisons over Market-1501 [61] under SingleQuery settings. ∗ indicates the re-implementation by our code. The best/second results are shown in red/blue, resp .
|
| 161 |
+
|
| 162 |
+
Table 2. Results comparisons over DuckMTMC-ReID [37, 65]. ∗ indicates the re-implementation by our code. The best/second results are shown in red/blue, resp .
|
| 163 |
+
|
| 164 |
+
| DukeMTMC-ReID (%) Methods Ref R-1 R-5 R-10 mAP BoW+kissme [61] ICCV15 25.1 - - 12.2 SVDNet [42] ICCV17 76.7 - - 56.8 DaRe(De)+RE [50] CVPR18 80.2 - - 64.5 MLFN [3] CVPR18 81.0 - - 62.8 KPM [39] CVPR18 80.3 89.5 91.9 63.2 HA-CNN [27] CVPR18 80.5 - - 63.8 DNN-CRF [9] CVPR18 84.9 92.3 - 69.5 PABR [41] ECCV18 84.4 92.2 93.8 69.3 PCB+RPP [43] ECCV18 83.3 - - 69.2 Mancs [47] ECCV18 84.9 - - 71.8 CASN+PCB [64] CVPR19 87.7 - - 73.7 IDE ∗ [63] 80.1 90.7 93.5 64.2 MHN-6 (IDE) 87.5 93.8 95.6 75.2 PCB ∗ [43] 83.9 91.8 94.4 69.7 MHN-6 (PCB) 89.1 94.6 96.2 77.2 |
|
| 165 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 166 |
+
|
| 167 |
+
Table 3. Results comparisons over CUHK03-NP [26, 66]. ∗ indicates the re-implementation by our code. The best/second results are shown in red/blue, resp .
|
| 168 |
+
|
| 169 |
+
| CUHK03-NP (%) Methods Ref Labeled Detected R-1 mAP R-1 mAP BoW+XQDA [61] ICCV15 7.9 7.3 6.4 6.4 SVDNet [42] ICCV17 - - 41.5 37.3 DaRe(De)+RE [50] CVPR18 66.1 61.6 63.3 59.0 MLFN [3] CVPR18 54.7 49.2 52.8 47.8 HA-CNN [27] CVPR18 44.4 41.0 41.7 38.6 PCB+RPP [43] ECCV18 - - 63.7 57.5 Mancs [47] ECCV18 69.0 63.9 65.5 60.5 CASN+PCB [64] CVPR19 73.7 68.0 71.5 64.4 IDE ∗ [63] 52.9 48.5 50.4 46.3 MHN-6 (IDE) 69.7 65.1 67.0 61.2 PCB ∗ [43] 61.9 56.8 60.6 54.4 MHN-6 (PCB) 77.2 72.4 71.7 65.4 |
|
| 170 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 171 |
+
|
| 172 |
+
Table 4. Effect (%) of attention modules. ∗ indicates the re-implementation and 'era' means random erasing.
|
| 173 |
+
|
| 174 |
+
| CUHK03-NP [26, 66] DukeMTMC-ReID [37, 65] Market-1501 [61] Methods Labeled Detected R-1 mAP R-1 mAP R-1 R-5 R-10 mAP R-1 R-5 R-10 mAP IDE ∗ [63] 52.9 48.5 50.4 46.3 80.1 90.7 93.5 64.2 89.0 95.7 97.3 73.9 IDE ∗ +era 61.4 55.71 56.9 51.3 83.6 92.1 94.3 67.4 90.3 96.5 97.6 75.9 MHN-2 (IDE) 65.9 59.1 60.9 54.8 84.5 92.6 94.7 68.9 90.6 96.1 97.6 76.1 MHN-4 (IDE) 67.4 60.3 62.7 55.8 86.3 93.1 95.6 72.4 91.8 97.6 98.5 80.1 MHN-6 (IDE) 69.7 65.1 67.0 61.2 87.5 93.8 95.6 75.2 93.6 97.7 98.6 83.6 PCB ∗ [43] 61.9 56.8 60.6 54.4 83.9 91.8 94.4 69.7 93.1 97.5 98.5 78.6 PCB ∗ +era 57.4 52.5 54.3 49.9 83.4 91.5 94.3 68.2 91.9 97.4 98.4 76.8 MHN-2 (PCB) 71.2 66.3 67.9 61.9 86.9 93.3 95.3 73.5 94.0 97.8 98.5 82.5 MHN-4 (PCB) 75.1 70.6 71.6 66.1 88.7 94.4 95.9 76.8 94.5 98.0 98.6 84.2 MHN-6 (PCB) 77.2 72.4 71.7 65.4 89.1 94.6 96.2 77.2 95.1 98.1 98.9 85.0 |
|
| 175 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 176 |
+
|
| 177 |
+
Evaluation : In testing, the feature representations f j , j ∈ { 1 , · · · , k } are concatenated after L2 normalization. Then, the metrics of cumulative matching characteristic (CMC) and mean Average Precision (mAP) are used for evaluation. No re-ranking tricks are adopted .
|
| 178 |
+
|
| 179 |
+
## 4.1. Comparison with State-of-the-Art Methods
|
| 180 |
+
|
| 181 |
+
In order to highlight the significance of the proposed MHNforperson ReID task, we compare it with some recent remarkable works, including methods of alignment [39, 41, 64, 43], deep supervision [50], architectures [63, 43], attention [27, 64, 47] and others [42, 9, 3], over the popular used benchmarks Market-1501, DukeMTMC-ReID and CUHK03-NP. For fair comparison, we re-implement the baseline models, i.e. ResNet50-based IDE and PCB, with the same training configurations as ours. MHN is then applied over both IDE and PCB architectures. The comparison results are listed in Tab. 1, Tab. 2 and Tab. 3. From these tables, one can observe that by explicitly intensify the discrimination and diversity within the deep embedding via high-order attention modules, our MHN6 can significantly improve the performances over both the baseline methods IDE and PCB (e.g. comparing with PCB, MHN6 (PCB) has 2% / 6 . 4% improvements of R1 /mAP on Market and 5 . 2% / 7 . 5% improvements of R1 /mAP on DukeMTMC), demonstrating the effectiveness of our high-order attention idea. And our MHN6 (PCB) achieves the new SOTA performances on all these three benchmarks, showing the superiority of our method.
|
| 182 |
+
|
| 183 |
+
## 4.2. Component Analysis
|
| 184 |
+
|
| 185 |
+
Effect of MHN : We conduct quantitative comparisons on MHN as in Tab. 4. From this table, one can observe that the proposed MHN can significantly improve the performances of person ReID task over both IDE and PCB baseline architectures. Specifically, comparing MHN2 (IDE/PCB) with IDE/PCB, we can see that using higherorder attention information indeed encourage the discrimination of the learned embedding. Moreover, the perfor- mances will further increase with the number of HOA modules, e.g. on CUHK03-NP Labeled dataset, applying MHN on PCB, when increasing the number of HOA modules from 2 to 6 the performance of R1 will be increased from 71 . 2% to 77 . 2% , the same phenomenon can be observed in other datasets and architecture. This phenomenon also shows that employing multiple HOA modules is benefit for modeling diverse and discriminative information for recognizing the unseen identities, and MHN6 outperforms all the baseline models by a large margin over all the three benchmarks, demonstrating the effectiveness of our method. However, when further increase the number of HOA modules, e.g. k = 8 , the performance improvements are few, thus we don't report it here.
|
| 186 |
+
|
| 187 |
+
Table 6. Effect (%) of nonlinearity.
|
| 188 |
+
|
| 189 |
+
| Methods DukeMTMC-ReID Market-1501 R-1 mAP R-1 mAP IDE ∗ [63] 80.1 64.2 89.0 73.9 MHN-6 (IDE) w/o L adv 85.5 70.8 91.8 80.0 MHN-6 (IDE) 87.5 75.2 93.6 83.6 PCB ∗ [43] 83.9 69.7 93.1 78.6 MHN-6 (PCB) w/o L adv 87.7 75.4 93.9 83.2 MHN-6 (PCB) 89.1 77.1 95.1 85.0 Table 5. Effect (%) of adversary constraint. ∗ indicates the re- implementation by our code. Methods DukeMTMC-ReID Market-1501 R-1 mAP R-1 mAP MHN-6 (IDE) w/o nonli 87.1 74.9 93.3 83.1 MHN-6 (IDE) 87.5 75.2 93.6 83.6 MHN-6 (PCB) w/o nonli 88.7 76.8 95.0 84.5 MHN-6 (PCB) 89.1 77.1 95.1 85.0 |
|
| 190 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 191 |
+
|
| 192 |
+
Effect of Adversary Constraint : From Tab. 5, when comparing { MHN6 (IDE) w/o L adv } with { IDE } and comparing { MHN6 (PCB) w/o L adv } with { PCB } , one can observe that on both DukeMTMC and Market datasets the performances of R1 and mAP can be improved by simply employing multiple HOA modules without any regularizing constraint, showing that using higher-order attention information will indeed increase the discrimination of the learned knowledge in ZSL settings. However, as mentioned in Sec. 3.3, the task of person ReID pertains to zero-shot settings, the problem of 'partial/biased learning behavior of deep model' will incur the problem of order collapse of HOA modules, i.e. the deep model will partially model the easy and lower-order information regardless the theoretical capacity of HOA module. Therefore, we introduce the adversary constraint to explicitly prevent the problem of order collapse. After equipping with L adv , MHN6 (IDE/PCB) can further improve the performances over both the benchmarks, demonstrating the effectiveness of L adv and implying that explicitly learning diverse high-order attention information is essential for recognizing the unseen identities.
|
| 193 |
+
|
| 194 |
+
Table 7. Comparison to other attention methods (%). ∗ indicates our reproducing.
|
| 195 |
+
|
| 196 |
+
| Methods DukeMTMC-ReID Market-1501 R-1 mAP R-1 mAP IDE ∗ [63] 80.1 64.2 89.0 73.9 SENet50 ∗ [19] 81.2 64.8 90.0 75.6 HA-CNN [27] 80.5 63.8 91.2 75.7 SpaAtt+Q ∗ [25] 84.7 69.6 91.6 77.4 CASN+IDE [64] 84.5 67.0 92.0 78.0 MHN-6 (IDE) 87.5 75.2 93.6 83.6 |
|
| 197 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 198 |
+
|
| 199 |
+
Effect of Nonlinearity : The nonlinearity comparisons are listed in Tab. 6, from this table, one can observe that by adding nonlinearity into the high-order attention modules, the performances can be further improved.
|
| 200 |
+
|
| 201 |
+
Comparison to other attention methods : To demonstrate the effectiveness of our idea of high-order attention, we compare with some other attention methods as in Tab. 7. Specifically, our MHN6 (IDE) outperforms both the spatial and channel attention methods, i.e. HA-CNN [27] and SENet50 3 [19], showing the superiority of high-order attention model to these coarse/first-order attention methods. Moreover, although { SpaAtt+Q } [25] employs multiple diverse attention modules like MHN to enhance the richness of attention information, the used attention method is spatial attention which is coarse and insufficiently rich to capture the complex and high-order interactions of parts, failing in producing more discriminative attention proposals and thus performing worse than MHN6 (IDE). { CASN+IDE } [64] regularizes the attention maps of the paired images belonging to the same identity to be similar and indeed improves the results, but it still performs worse than MHN6 (IDE) since the consistence constraint for attention maps is only based on the the coarse spatial attention maps.
|
| 202 |
+
|
| 203 |
+
In summary, because of the ability of modeling and using complex and high-order information, the proposed MHN can significantly surpass all the listed coarse/first-order attention methods as shown in Tab. 7.
|
| 204 |
+
|
| 205 |
+
Ablation study on the configurations of P 1 & P 2 : As mentioned in Sec. 3.3, the HOA modules are placed between P 1 and P 2 , to investigate the effect of the placed position of HOA modules, we conduct experiments as in Tab. 8. One can observe that placing HOA modules after
|
| 206 |
+
|
| 207 |
+
3 We fine-tune the pre-trained SENet50 released at https:// github.com/moskomule/senet.pytorch .
|
| 208 |
+
|
| 209 |
+
Table 8. Ablation study on the configurations of P 1 and P 2 . All the layer names are shown in Pytorch manner. Here, for convenience we conduct experiments with MHN6 (IDE) and test three configurations, i.e. 1 © , 2 © and 3 © .
|
| 210 |
+
|
| 211 |
+
| Methods Market-1501 R-1 mAP 1 © :P 1 = { conv1 ∼ layer1 } ,P 2 = { layer2 ∼ GAP } 92.2 81.8 2 © :P 1 = { conv1 ∼ layer2 } ,P 2 = { layer3 ∼ GAP } 93.6 83.6 3 © :P 1 = { conv1 ∼ layer3 } ,P 2 = { layer4 ∼ GAP } 92.7 82.1 |
|
| 212 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 213 |
+
|
| 214 |
+
Table 9. Model size comparisons. PN means Parameter Number.
|
| 215 |
+
|
| 216 |
+
| Models PN (million) Depth R-1 (on Market) IDE [63] 24.2 50 89.0% SENet50 [19] 27.4 50 90.0% MHN- 2 (IDE) 24.4 50 90.6% MHN- 4 (IDE) 25.2 50 91.8% MHN- 6 (IDE) 26.8 50 93.6% |
|
| 217 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 218 |
+
|
| 219 |
+
' layer2 ' (i.e. using the configuration 2 © ) performs the best since when placing it at the relatively lower layer (i.e. using the configuration 1 © ) the knowledge input to HOA module is more relevant to the low-level texture information and contains much noise, while placing it at relatively higher layer (i.e. using the configuration 3 © ), some useful knowledge for recognizing the unseen identities might be already lost during the forward propagation of information as a result of partial/biased learning behavior. To this end, we use the configuration 2 © for both IDE and PCB architectures throughout the experiments.
|
| 220 |
+
|
| 221 |
+
Model size : We compare the model size as in Tab. 9, from this table, one can observe that the parameter number of our MHN increases with the order. While comparing with SENet50 [19], the total parameter number of each MHNis not so much, and in terms of the performance, each MHN can outperform SENet50, showing that our MHN is indeed 'light and sweet'.
|
| 222 |
+
|
| 223 |
+
## 5. Conclusion
|
| 224 |
+
|
| 225 |
+
In this paper, we first propose the High-Order Attention (HOA) module so as to increase the discrimination of attention proposals by modeling and using the complex and highorder statistics of parts. Then, considering the fact that the person-ReID task pertains to zero-shot learning where the deep model will easily learn the biased knowledge, we propose the Mixed High-Order Attention Network (MHN) to utilize the HOA modules at different orders, preventing the learning of partial/biased visual information that only benefit to the seen identities. The adversary constraint is further introduced to prevent the problem of order collapse of HOA module. And Extensive experiments have been conducted over three popular benchmarks to validate the necessity and effectiveness of our method.
|
| 226 |
+
|
| 227 |
+
Acknowledgments : This work was partially supported by the National Natural Science Foundation of China under Grant Nos. 61871052, 61573068, 61471048, and BUPT Excellent Ph.D. Students Foundation CX2019307.
|
| 228 |
+
|
| 229 |
+
## References
|
| 230 |
+
|
| 231 |
+
- [1] [https://github.com/layumi/Person\_reID\_ baseline\_pytorch . 6](https://github.com/layumi/Person_reID_baseline_pytorch)
|
| 232 |
+
- [2] Sijia Cai, Wangmeng Zuo, and Lei Zhang. Higher-order integration of hierarchical convolutional activations for finegrained visual categorization. In Proceedings of the IEEE International Conference on Computer Vision , pages 511520, 2017. 3
|
| 233 |
+
- [3] Xiaobin Chang, Timothy M Hospedales, and Tao Xiang. Multi-level factorisation net for person re-identification. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , pages 2109-2118, 2018. 6, 7
|
| 234 |
+
- [4] Soravit Changpinyo, Wei-Lun Chao, Boqing Gong, and Fei Sha. Synthesized classifiers for zero-shot learning. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , pages 5327-5336, 2016. 3
|
| 235 |
+
- [5] Binghui Chen and Weihong Deng. Energy confused adversarial metric learning for zero-shot image retrieval and clustering. In AAAI Conference on Artificial Intelligence , 2019. 2, 3, 5
|
| 236 |
+
- [6] Binghui Chen and Weihong Deng. Hybrid-attention based decoupled metric learning for zero-shot image retrieval. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , pages 2750-2759, 2019. 3
|
| 237 |
+
- [7] Binghui Chen, Weihong Deng, and Junping Du. Noisy softmax: Improving the generalization ability of dcnn via postponing the early softmax saturation. In The IEEE Conference on Computer Vision and Pattern Recognition (CVPR) , July 2017. 2
|
| 238 |
+
- [8] Binghui Chen, Weihong Deng, and Haifeng Shen. Virtual class enhanced discriminative embedding learning. In Advances in Neural Information Processing Systems , pages 1946-1956, 2018. 2
|
| 239 |
+
- [9] Dapeng Chen, Dan Xu, Hongsheng Li, Nicu Sebe, and Xiaogang Wang. Group consistent similarity learning via deep crf for person re-identification. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , pages 8649-8658, 2018. 6, 7
|
| 240 |
+
- [10] Long Chen, Hanwang Zhang, Jun Xiao, Liqiang Nie, Jian Shao, Wei Liu, and Tat-Seng Chua. Sca-cnn: Spatial and channel-wise attention in convolutional networks for image captioning. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , pages 5659-5667, 2017. 1, 2
|
| 241 |
+
- [11] Mircea Cimpoi, Subhransu Maji, and Andrea Vedaldi. Deep filter banks for texture recognition and segmentation. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 3828-3836, 2015. 4
|
| 242 |
+
- [12] Yin Cui, Feng Zhou, Jiang Wang, Xiao Liu, Yuanqing Lin, and Serge Belongie. Kernel pooling for convolutional neural networks. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 2921-2930, 2017. 3
|
| 243 |
+
- [13] Jeffrey Dalton, James Allan, and Pranav Mirajkar. Zero-shot video retrieval using content and concepts. In Proceedings
|
| 244 |
+
14. of the 22nd ACM international conference on Information & Knowledge Management , pages 1857-1860. ACM, 2013. 3
|
| 245 |
+
- [14] Akira Fukui, Dong Huk Park, Daylen Yang, Anna Rohrbach, Trevor Darrell, and Marcus Rohrbach. Multimodal compact bilinear pooling for visual question answering and visual grounding. In Proceedings of the 2016 Conference on Empirical Methods in Natural Language Processing , pages 457-468, 2016. 3
|
| 246 |
+
- [15] Yang Gao, Oscar Beijbom, Ning Zhang, and Trevor Darrell. Compact bilinear pooling. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 317-326, 2016. 3
|
| 247 |
+
- [16] Jorge Garcia, Niki Martinel, Christian Micheloni, and Alfredo Gardel. Person re-identification ranking optimisation by discriminant context information analysis. In Proceedings of the IEEE International Conference on Computer Vision , pages 1305-1313, 2015. 2
|
| 248 |
+
- [17] Ian Goodfellow, Jean Pouget-Abadie, Mehdi Mirza, Bing Xu, David Warde-Farley, Sherjil Ozair, Aaron Courville, and Yoshua Bengio. Generative adversarial nets. In Advances in neural information processing systems , pages 2672-2680, 2014. 5
|
| 249 |
+
- [18] Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep residual learning for image recognition. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 770-778, 2016. 5
|
| 250 |
+
- [19] Jie Hu, Li Shen, and Gang Sun. Squeeze-and-excitation networks. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 7132-7141, 2018. 1, 2, 3, 4, 5, 8
|
| 251 |
+
- [20] Max Jaderberg, Karen Simonyan, Andrew Zisserman, et al. Spatial transformer networks. In Advances in neural information processing systems , pages 2017-2025, 2015. 2
|
| 252 |
+
- [21] Mahdi M Kalayeh, Emrah Basaran, Muhittin G¨ okmen, Mustafa E Kamasak, and Mubarak Shah. Human semantic parsing for person re-identification. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , pages 1062-1071, 2018. 1
|
| 253 |
+
- [22] Jin-Hwa Kim, Kyoung-Woon On, Woosang Lim, Jeonghee Kim, Jung-Woo Ha, and Byoung-Tak Zhang. Hadamard product for low-rank bilinear pooling. arXiv preprint arXiv:1610.04325 , 2016. 3
|
| 254 |
+
- [23] Tamara G Kolda and Brett W Bader. Tensor decompositions and applications. SIAM review , 51(3):455-500, 2009. 3
|
| 255 |
+
- [24] Dangwei Li, Xiaotang Chen, Zhang Zhang, and Kaiqi Huang. Learning deep context-aware features over body and latent parts for person re-identification. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , pages 384-393, 2017. 2
|
| 256 |
+
- [25] Shuang Li, Slawomir Bak, Peter Carr, and Xiaogang Wang. Diversity regularized spatiotemporal attention for videobased person re-identification. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , pages 369-378, 2018. 1, 2, 3, 8
|
| 257 |
+
- [26] Wei Li, Rui Zhao, Tong Xiao, and Xiaogang Wang. Deepreid: Deep filter pairing neural network for person reidentification. In Proceedings of the IEEE Conference on
|
| 258 |
+
|
| 259 |
+
Computer Vision and Pattern Recognition , pages 152-159, 2014. 2, 6, 7
|
| 260 |
+
|
| 261 |
+
- [27] Wei Li, Xiatian Zhu, and Shaogang Gong. Harmonious attention network for person re-identification. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , pages 2285-2294, 2018. 1, 2, 3, 4, 6, 7, 8
|
| 262 |
+
- [28] Yan Li, Junge Zhang, Jianguo Zhang, and Kaiqi Huang. Discriminative learning of latent features for zero-shot recognition. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , pages 7463-7471, 2018. 3
|
| 263 |
+
- [29] Tsung-Yu Lin, Aruni RoyChowdhury, and Subhransu Maji. Bilinear cnn models for fine-grained visual recognition. In Proceedings of the IEEE international conference on computer vision , pages 1449-1457, 2015. 2
|
| 264 |
+
- [30] Xihui Liu, Haiyu Zhao, Maoqing Tian, Lu Sheng, Jing Shao, Shuai Yi, Junjie Yan, and Xiaogang Wang. Hydraplus-net: Attentive deep features for pedestrian analysis. In Proceedings of the IEEE international conference on computer vision , pages 350-359, 2017. 1
|
| 265 |
+
- [31] Chen Change Loy, Tao Xiang, and Shaogang Gong. Multicamera activity correlation analysis. In 2009 IEEE Conference on Computer Vision and Pattern Recognition , pages 1988-1995. IEEE, 2009. 1
|
| 266 |
+
- [32] Chen Change Loy, Tao Xiang, and Shaogang Gong. Timedelayed correlation analysis for multi-camera activity understanding. International Journal of Computer Vision , 90(1):106-129, 2010. 1
|
| 267 |
+
- [33] Vinod Nair and Geoffrey E Hinton. Rectified linear units improve restricted boltzmann machines. In Proceedings of the 27th international conference on machine learning (ICML10) , pages 807-814, 2010. 4
|
| 268 |
+
- [34] Sakrapee Paisitkriangkrai, Chunhua Shen, and Anton Van Den Hengel. Learning to rank in person re-identification with metric ensembles. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , pages 1846-1855, 2015. 2
|
| 269 |
+
- [35] Ninh Pham and Rasmus Pagh. Fast and scalable polynomial kernels via explicit feature maps. In Proceedings of the 19th ACM SIGKDD international conference on Knowledge discovery and data mining , pages 239-247. ACM, 2013. 3
|
| 270 |
+
- [36] Pytorch. https://pytorch.org/. 5, 6
|
| 271 |
+
- [37] Ergys Ristani, Francesco Solera, Roger Zou, Rita Cucchiara, and Carlo Tomasi. Performance measures and a data set for multi-target, multi-camera tracking. In European Conference on Computer Vision , pages 17-35. Springer, 2016. 2, 6, 7
|
| 272 |
+
- [38] Olga Russakovsky, Jia Deng, Hao Su, Jonathan Krause, Sanjeev Satheesh, Sean Ma, Zhiheng Huang, Andrej Karpathy, Aditya Khosla, Michael Bernstein, et al. Imagenet large scale visual recognition challenge. International journal of computer vision , 115(3):211-252, 2015. 2
|
| 273 |
+
- [39] Yantao Shen, Tong Xiao, Hongsheng Li, Shuai Yi, and Xiaogang Wang. End-to-end deep kronecker-product matching for person re-identification. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , pages 6886-6895, 2018. 6, 7
|
| 274 |
+
- [40] Chi Su, Shiliang Zhang, Junliang Xing, Wen Gao, and Qi Tian. Deep attributes driven multi-camera person re-
|
| 275 |
+
|
| 276 |
+
identification. In European conference on computer vision , pages 475-491. Springer, 2016. 2
|
| 277 |
+
|
| 278 |
+
- [41] Yumin Suh, Jingdong Wang, Siyu Tang, Tao Mei, and Kyoung Mu Lee. Part-aligned bilinear representations for person re-identification. In Proceedings of the European Conference on Computer Vision (ECCV) , pages 402-419, 2018. 6, 7
|
| 279 |
+
- [42] Yifan Sun, Liang Zheng, Weijian Deng, and Shengjin Wang. Svdnet for pedestrian retrieval. In Proceedings of the IEEE International Conference on Computer Vision , pages 38003808, 2017. 6, 7
|
| 280 |
+
- [43] Yifan Sun, Liang Zheng, Yi Yang, Qi Tian, and Shengjin Wang. Beyond part models: Person retrieval with refined part pooling (and a strong convolutional baseline). In Proceedings of the European Conference on Computer Vision (ECCV) , pages 480-496, 2018. 2, 5, 6, 7
|
| 281 |
+
- [44] Siyu Tang, Mykhaylo Andriluka, Bjoern Andres, and Bernt Schiele. Multiple people tracking by lifted multicut and person re-identification. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , pages 35393548, 2017. 1
|
| 282 |
+
- [45] Rahul Rama Varior, Mrinal Haloi, and Gang Wang. Gated siamese convolutional neural network architecture for human re-identification. In European Conference on Computer Vision , pages 791-808. Springer, 2016. 1
|
| 283 |
+
- [46] Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin. Attention is all you need. In Advances in Neural Information Processing Systems , pages 5998-6008, 2017. 2
|
| 284 |
+
- [47] Cheng Wang, Qian Zhang, Chang Huang, Wenyu Liu, and Xinggang Wang. Mancs: A multi-task attentional network with curriculum sampling for person re-identification. In The European Conference on Computer Vision (ECCV) , September 2018. 6, 7
|
| 285 |
+
- [48] Taiqing Wang, Shaogang Gong, Xiatian Zhu, and Shengjin Wang. Person re-identification by video ranking. In European Conference on Computer Vision , pages 688-703. Springer, 2014. 2
|
| 286 |
+
- [49] Xiaogang Wang. Intelligent multi-camera video surveillance: A review. Pattern recognition letters , 34(1):3-19, 2013. 1
|
| 287 |
+
- [50] Yan Wang, Lequn Wang, Yurong You, Xu Zou, Vincent Chen, Serena Li, Gao Huang, Bharath Hariharan, and Kilian Q Weinberger. Resource aware person re-identification across multiple resolutions. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , pages 8042-8051, 2018. 6, 7
|
| 288 |
+
- [51] Fei Xiong, Mengran Gou, Octavia Camps, and Mario Sznaier. Person re-identification using kernel-based metric learning methods. In European conference on computer vision , pages 1-16. Springer, 2014. 2
|
| 289 |
+
- [52] Jing Xu, Rui Zhao, Feng Zhu, Huaming Wang, and Wanli Ouyang. Attention-aware compositional network for person re-identification. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , pages 21192128, 2018. 1, 2
|
| 290 |
+
- [53] Kelvin Xu, Jimmy Ba, Ryan Kiros, Kyunghyun Cho, Aaron Courville, Ruslan Salakhudinov, Rich Zemel, and Yoshua
|
| 291 |
+
|
| 292 |
+
Bengio. Show, attend and tell: Neural image caption generation with visual attention. In International conference on machine learning , pages 2048-2057, 2015. 2
|
| 293 |
+
|
| 294 |
+
- [54] Dong Yi, Zhen Lei, Shengcai Liao, and Stan Z Li. Deep metric learning for person re-identification. In 2014 22nd International Conference on Pattern Recognition , pages 3439. IEEE, 2014. 2
|
| 295 |
+
- [55] Shoou-I Yu, Yi Yang, and Alexander Hauptmann. Harry potter's marauder's map: Localizing and tracking multiple persons-of-interest by nonnegative discretization. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , pages 3714-3720, 2013. 1
|
| 296 |
+
- [56] Zhou Yu, Jun Yu, Jianping Fan, and Dacheng Tao. Multimodal factorized bilinear pooling with co-attention learning for visual question answering. In Proceedings of the IEEE international conference on computer vision , pages 18211830, 2017. 3
|
| 297 |
+
- [57] Zhou Yu, Jun Yu, Chenchao Xiang, Jianping Fan, and Dacheng Tao. Beyond bilinear: generalized multimodal factorized high-order pooling for visual question answering. IEEE transactions on neural networks and learning systems , (99):1-13, 2018. 3
|
| 298 |
+
- [58] Haiyu Zhao, Maoqing Tian, Shuyang Sun, Jing Shao, Junjie Yan, Shuai Yi, Xiaogang Wang, and Xiaoou Tang. Spindle net: Person re-identification with human body region guided feature decomposition and fusion. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , pages 1077-1085, 2017. 1
|
| 299 |
+
- [59] Liming Zhao, Xi Li, Yueting Zhuang, and Jingdong Wang. Deeply-learned part-aligned representations for person reidentification. In Proceedings of the IEEE International Conference on Computer Vision , pages 3219-3228, 2017. 2
|
| 300 |
+
- [60] Rui Zhao, Wanli Ouyang, and Xiaogang Wang. Learning mid-level filters for person re-identification. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , pages 144-151, 2014. 2
|
| 301 |
+
- [61] Liang Zheng, Liyue Shen, Lu Tian, Shengjin Wang, Jingdong Wang, and Qi Tian. Scalable person re-identification: A benchmark. In Proceedings of the IEEE International Conference on Computer Vision , pages 1116-1124, 2015. 2, 6, 7
|
| 302 |
+
- [62] Liang Zheng, Shengjin Wang, Lu Tian, Fei He, Ziqiong Liu, and Qi Tian. Query-adaptive late fusion for image search and person re-identification. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 1741-1750, 2015. 2
|
| 303 |
+
- [63] Liang Zheng, Yi Yang, and Alexander G Hauptmann. Person re-identification: Past, present and future. arXiv preprint arXiv:1610.02984 , 2016. 2, 5, 6, 7, 8
|
| 304 |
+
- [64] Meng Zheng, Srikrishna Karanam, Ziyan Wu, and Richard J Radke. Re-identification with consistent attentive siamese networks. In Proceedings of the IEEE conference on computer vision and pattern recognition , 2019. 6, 7, 8
|
| 305 |
+
- [65] Zhedong Zheng, Liang Zheng, and Yi Yang. Unlabeled samples generated by gan improve the person re-identification baseline in vitro. In Proceedings of the IEEE International Conference on Computer Vision , pages 3754-3762, 2017. 2, 6, 7
|
| 306 |
+
- [66] Zhun Zhong, Liang Zheng, Donglin Cao, and Shaozi Li. Reranking person re-identification with k-reciprocal encoding. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , pages 1318-1327, 2017. 2, 6, 7
|
| 307 |
+
- [67] Zhun Zhong, Liang Zheng, Guoliang Kang, Shaozi Li, and Yi Yang. Random erasing data augmentation. arXiv preprint arXiv:1708.04896 , 2017. 6
|
text-versions/attention-markdown/1909.07913_Learning to Deceive with AttentionBased .md
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1909.07913 Learning To Deceive With Attentionbased
|
| 2 |
+
|
| 3 |
+
## Learning to Deceive with Attention-Based Explanations
|
| 4 |
+
|
| 5 |
+
Danish Pruthi † , Mansi Gupta ‡ , Bhuwan Dhingra † , Graham Neubig † , Zachary C. Lipton †
|
| 6 |
+
|
| 7 |
+
†
|
| 8 |
+
|
| 9 |
+
Carnegie Mellon University, Pittsburgh, USA ‡ Twitter, New York, USA
|
| 10 |
+
|
| 11 |
+
ddanish@cs.cmu.edu , mansig@twitter.com , { bdhingra, gneubig, zlipton } @cs.cmu.edu
|
| 12 |
+
|
| 13 |
+
## Abstract
|
| 14 |
+
|
| 15 |
+
Attention mechanisms are ubiquitous components in neural architectures applied to natural language processing. In addition to yielding gains in predictive accuracy, attention weights are often claimed to confer interpretability , purportedly useful both for providing insights to practitioners and for explaining why a model makes its decisions to stakeholders. We call the latter use of attention mechanisms into question by demonstrating a simple method for training models to produce deceptive attention masks. Our method diminishes the total weight assigned to designated impermissible tokens, even when the models can be shown to nevertheless rely on these features to drive predictions. Across multiple models and tasks, our approach manipulates attention weights while paying surprisingly little cost in accuracy. Through a human study, we show that our manipulated attention-based explanations deceive people into thinking that predictions from a model biased against gender minorities do not rely on the gender. Consequently, our results cast doubt on attention's reliability as a tool for auditing algorithms in the context of fairness and accountability 1 .
|
| 16 |
+
|
| 17 |
+
## 1 Introduction
|
| 18 |
+
|
| 19 |
+
Since their introduction as a method for aligning inputs and outputs in neural machine translation, attention mechanisms (Bahdanau et al., 2014) have emerged as effective components in various neural network architectures. Attention works by aggregating a set of tokens via a weighted sum, where the attention weights are calculated as a function of both the input encodings and the state of the decoder.
|
| 20 |
+
|
| 21 |
+
Because attention mechanisms allocate weight among the encoded tokens, these coefficients are sometimes thought of intuitively as indicating which tokens the model focuses on when making a particular prediction. Based on this loose intuition, attention weights are often claimed to explain a model's predictions. For example, a recent survey on attention (Galassi et al., 2019) remarks:
|
| 22 |
+
|
| 23 |
+
1 The code and the datasets used in paper are available at https://github.com/danishpruthi/ deceptive-attention
|
| 24 |
+
|
| 25 |
+
Table 1: Example of an occupation prediction task where attention-based explanation (highlighted) has been manipulated to whitewash problematic tokens.
|
| 26 |
+
|
| 27 |
+
| Attention Biography Label Original Ms. X practices medicine in Memphis, TN and is affiliated ... Ms. X speaks English and Spanish. Physician Ours Ms. X practices medicine in Memphis , TN and is affiliated ... Ms. X speaks English and Spanish. Physician |
|
| 28 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 29 |
+
|
| 30 |
+
'By inspecting the networks attention, ... one could attempt to investigate and understand the outcome of neural networks. Hence, weight visualization is now common practice.'
|
| 31 |
+
|
| 32 |
+
In another work, De-Arteaga et al. (2019) study gender bias in machine learning models for occupation classification. As machine learning is increasingly used in hiring processes for tasks including resume filtering, the potential for bias on the basis of gender raises the spectre that automating this process could lead to social harms. DeArteaga et al. (2019) use attention over genderrevealing tokens (e.g., 'she', 'he', etc.) to verify the biases in occupation classification modelsstating that 'the attention weights indicate which tokens are most predictive'. Similar claims about attention's utility for interpreting models' predictions are common in the literature (Li et al., 2016; Xu et al., 2015; Choi et al., 2016; Xie et al., 2017; Martins and Astudillo, 2016; Lai and Tan, 2019).
|
| 33 |
+
|
| 34 |
+
In this paper, we question whether attention scores necessarily indicate features that influence a model's predictions. Through a series of experiments on diverse classification and sequence-tosequence tasks, we show that attention scores are surprisingly easy to manipulate. We design a simple training scheme whereby the resulting models appear to assign little attention to a specified set of impermissible tokens while continuing to rely upon those features for prediction. The ease with which attention can be manipulated without significantly affecting performance suggests that even if a vanilla model's attention weights conferred some insight (still an open and ill-defined question), these insights would rely on knowing the objective on which models were trained.
|
| 35 |
+
|
| 36 |
+
Our results present troublesome implications for proposed uses of attention in the context of fairness, accountability, and transparency. For example, malicious practitioners asked to justify how their models work by pointing to attention weights could mislead regulators with this scheme. For instance, looking at manipulated attention-based explanation in Table 1, one might (incorrectly) assume that the model does not rely on the gender prefix. To quantitatively study the extent of such deception, we conduct studies where we ask human subjects if the biased occupation classification models (like the ones audited by DeArteaga et al. (2019)) rely on gender related information. We find that our manipulation scheme is able to deceive human annotators into believing that manipulated models do not take gender into account, whereas the models are heavily biased against gender minorities (see § 5.2).
|
| 37 |
+
|
| 38 |
+
Lastly, practitioners often overlook the fact that attention is typically not applied over words but over final layer representations, which themselves capture information from neighboring words. We investigate the mechanisms through which the manipulated models attain low attention values. We note that (i) recurrent connections allow information to flow easily to neighboring representations; (ii) for cases where the flow is restricted, models tend to increase the magnitude of representations corresponding to impermissible tokens to offset the low attention scores; and (iii) models additionally rely on several alternative mechanisms that vary across random seeds (see § 5.3).
|
| 39 |
+
|
| 40 |
+
## 2 Related Work
|
| 41 |
+
|
| 42 |
+
Many recent papers examine whether attention is a valid explanation or not. Jain et al. (2019) iden- tify alternate adversarial attention weights after the model is trained that nevertheless produce the same predictions, and hence claim that attention is not explanation . However, these attention weights are chosen from a large (infinite up to numerical precision) set of possible values and thus it is not surprising that multiple weights produce the same prediction. Moreover since the model does not actually produce these weights, they would never be relied on as explanations in the first place. Similarly, Serrano and Smith (2019) modify attention values of a trained model post-hoc by hard-setting the highest attention values to zero. They find that the number of attention values that must be zeroed out to alter the model's prediction is often too large, and thus conclude that attention is not a suitable tool to for determining which elements should be attributed as responsible for an output. In contrast to these two papers, we manipulate the attention via the learning procedure, producing models whose actual weights might deceive an auditor.
|
| 43 |
+
|
| 44 |
+
In parallel work to ours, Wiegreffe and Pinter (2019) examine the conditions under which attention can be considered a plausible explanation. They design a similar experiment to ours where they train an adversarial model, whose attention distribution is maximally different from the one produced by the base model. Here we look at a related but different question of how attention can be manipulated away from a set of impermissible tokens. We show that in this setting, our training scheme leads to attention maps which are more deceptive , since people find them to be more believable explanations of the output (see § 5.2). We also extend our analysis to sequence-to-sequence tasks, and a broader set of models, including BERT, as well as identify mechanisms by which the manipulated models continue to rely on the impermissible tokens despite assigning low attention to them.
|
| 45 |
+
|
| 46 |
+
Lastly, several papers deliberately train attention weights by introducing an additional source of supervision to improve predictive performance. In some of these papers, the supervision comes from known word alignments for machine translation (Liu et al., 2016; Chen et al., 2016), or by aligning human eye-gaze with model's attention for sequence classification (Barrett et al., 2018).
|
| 47 |
+
|
| 48 |
+
## 3 Manipulating Attention
|
| 49 |
+
|
| 50 |
+
Let S = w 1 , w 2 , . . . , w n denote an input sequence of n words. We assume that for each task, we are given a pre-specified set of impermissible words I , for which we want to minimize the corresponding attention weights. For example, these may include gender words such as 'he', 'she', 'Mr.', or 'Ms.'. We define the mask m to be a binary vector of size n , such that
|
| 51 |
+
|
| 52 |
+
Table 2: Example sentences from each classification task, with highlighted impermissible tokens and their support.
|
| 53 |
+
|
| 54 |
+
| Dataset (Task) Input Example Impermissible Tokens (Percentage) CommonCrawl Biographies (Physician vs Surgeon) Ms. X practices medicine in Memphis, TN and is affiliated with . . . Ms. X speaks English and Spanish. Gender Indicators ( 6 . 5% ) Wikipedia Biographies (Gender Identification) After that, Austen was educated at home until she went to boarding school with Cassandra early in 1785 Gender Indicators ( 7 . 6% ) SST + Wikipedia (Sentiment Analysis) Good fun, good action, good acting, good dialogue, good pace, good cinematography. Helen Maxine Lamond Reddy (born 25 October 1941) is an Australian singer, actress, and activist. SST sentence ( 45 . 5% ) Reference Letters (Acceptance Prediction) It is with pleasure that I am writing this letter in support of . . . I highly recommend her for a place in your institution. Percentile:99.0 Rank:Extraordinary. Percentile, Rank ( 1 . 6% ) |
|
| 55 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 56 |
+
|
| 57 |
+
<!-- formula-not-decoded -->
|
| 58 |
+
|
| 59 |
+
Further, let α ∈ [0 , 1] n denote the attention assigned to each word in S by a model, such that ∑ i α i = 1 . For any task-specific loss function L , we define a new objective function L ′ = L + R where R is an additive penalty term whose purpose is to penalize the model for allocating attention to impermissible words. For a single attention layer, we define R as:
|
| 60 |
+
|
| 61 |
+
<!-- formula-not-decoded -->
|
| 62 |
+
|
| 63 |
+
and λ is a penalty coefficient that modulates the amount of attention assigned to impermissible tokens. The argument of the log term ( 1 -α T m ) captures the total attention weight assigned to permissible words. In contrast to our penalty term, Wiegreffe and Pinter (2019) use KL-divergence to maximally separate the attention distribution of the manipulated model ( α new) from the attention distribution of the given model ( α old ):
|
| 64 |
+
|
| 65 |
+
<!-- formula-not-decoded -->
|
| 66 |
+
|
| 67 |
+
However, their penalty term is not directly applicable to our case: instantiating α old to be uniform over impermissible tokens, and 0 over remainder tokens results in an undefined loss term.
|
| 68 |
+
|
| 69 |
+
When dealing with models that employ multiheaded attention, which use multiple different attention vectors at each layer of the model (Vaswani et al., 2017) we can optimize the mean value of our penalty as assessed over the set of attention heads H as follows:
|
| 70 |
+
|
| 71 |
+
<!-- formula-not-decoded -->
|
| 72 |
+
|
| 73 |
+
When a model has many attention heads, an auditor might not look at the mean attention assigned to certain words but instead look head by head to see if any among them assigns a large amount of attention to impermissible words. Anticipating this, we also explore a variant of our approach for manipulating multi-headed attention where we penalize the maximum amount of attention paid to impermissible words (among all heads) as follows:
|
| 74 |
+
|
| 75 |
+
<!-- formula-not-decoded -->
|
| 76 |
+
|
| 77 |
+
For cases where the impermissible set of tokens is unknown apriori, one can plausibly use the top few highly attended tokens as a proxy.
|
| 78 |
+
|
| 79 |
+
## 4 Experimental Setup
|
| 80 |
+
|
| 81 |
+
We study the manipulability of attention on four binary classification problems, and four sequenceto-sequence tasks. In each dataset, (in some, by design) a subset of input tokens are known a priori to be indispensable for achieving high accuracy.
|
| 82 |
+
|
| 83 |
+
## 4.1 Classification Tasks
|
| 84 |
+
|
| 85 |
+
Occupation classification We use the biographies collected by De-Arteaga et al. (2019) to study bias against gender-minorities in occupation classification models. We carve out a binary classification task of distinguishing between surgeons and (non-surgeon) physicians from the multi-class occupation prediction setup. We chose this subtask because the biographies of the two professions use similar words, and a majority of surgeons ( > 80% ) in the dataset are male. We further downsample minority classes-female surgeons, and male physicians-by a factor of ten, to encourage models to use gender related tokens. Our models (described in detail later in § 4.2) attain 96 . 4% accuracy on the task, and are reduced to 93 . 8% when the gender pronouns in the biographies are anonymized. Thus, the models (trained on unanonymized data) make use of gender indicators to obtain a higher task performance. Consequently, we consider gender indicators as impermissible tokens for this task.
|
| 86 |
+
|
| 87 |
+
Pronoun-based Gender Identification We construct a toy dataset from Wikipedia comprised of biographies, in which we automatically label biographies with a gender (female or male) based solely on the presence of gender pronouns . To do so, we use a pre-specified list of gender pronouns. Biographies containing no gender pronouns, or pronouns spanning both classes are discarded. The rationale behind creating this dataset is that due to the manner in which the dataset was created, attaining 100% classification accuracy is trivial if the model uses information from the pronouns. However, without the pronouns, it may not be possible to achieve perfect accuracy. Our models trained on the same data with pronouns anonymized, achieve at best 72.6% accuracy.
|
| 88 |
+
|
| 89 |
+
Sentiment Analysis with Distractor Sentences We use the binary version of Stanford Sentiment Treebank (SST) (Socher et al., 2013), comprised of 10 , 564 movie reviews. We append one randomly-selected 'distractor' sentence to each review, from a set of opening sentences of Wikipedia pages. 2 Here, without relying upon the tokens in the SST sentences, a model should not be able to outperform random guessing.
|
| 90 |
+
|
| 91 |
+
Graduate School Reference Letters We obtain a dataset of recommendation letters written for the purpose of admission to graduate programs. The task is to predict whether the student, for whom the letter was written, was accepted. The letters include students' ranks and percentile scores as marked by their mentors, which admissions committee members rely on. Indeed, we notice accu- racy improvements when using the rank and percentile features in addition to the reference letter. Thus, we consider percentile and rank labels (which are appended at the end of the letter text) as impermissible tokens. An example from each classification task is listed in Table 2. More details about the datasets are in the appendix.
|
| 92 |
+
|
| 93 |
+
2 Opening sentences tend to be declarative statements of fact and typically are sentiment-neutral.
|
| 94 |
+
|
| 95 |
+
## 4.2 Classification Models
|
| 96 |
+
|
| 97 |
+
Embedding + Attention For illustrative purposes, we start with a simple model with attention directly over word embeddings. The word embeddings are aggregated by a weighted sum (where weights are the attention scores) to form a context vector, which is then fed to a linear layer, followed by a softmax to perform prediction. For all our experiments, we use dot-product attention, where the query vector is a learnable weight vector. In this model, prior to attention there is no interaction between the permissible and impermissible tokens. The embedding dimension size is 128 .
|
| 98 |
+
|
| 99 |
+
BiLSTM + Attention The encoder is a singlelayer bidirectional LSTM model (Graves and Schmidhuber, 2005) with attention, followed by a linear transformation and a softmax to perform classification. The embedding and hidden dimension size are both set to 128 .
|
| 100 |
+
|
| 101 |
+
Transformer Models We use the Bidirectional Encoder Representations from Transformers (BERT) model (Devlin et al., 2019). We use the base version consisting of 12 layers with selfattention. Further, each of the self-attention layers consists of 12 attention heads. The first token of every sequence is the special classification token [CLS] , whose final hidden state is used for classification tasks. To block the information flow from permissible to impermissible tokens, we multiply attention weights at every layer with a selfattention mask M , a binary matrix of size n × n where n is the size of the input sequence. An element M i,j represents whether the token w i should attend on the token w j . M i,j is 1 if both i and j belong to the same set (either the set of impermissible tokens, I or its complement I c ). Additionally, the [CLS] token attends to all the tokens, but no token attends to [CLS] to prevent the information flow between I and I c (Figure 1 illustrates this setting). We attempt to manipulate attention from [CLS] token to other tokens, and consider two variants: one where we manipulate the maxi- mum attention across all heads, and one where we manipulate the mean attention.
|
| 102 |
+
|
| 103 |
+
Figure 1: Restricted self-attention in BERT. The information flow through attention is restricted between impermissible and permissible tokens for every encoder layer. The arrows represent the direction of attention.
|
| 104 |
+
|
| 105 |
+
<!-- image -->
|
| 106 |
+
|
| 107 |
+
## 4.3 Sequence-to-sequence Tasks
|
| 108 |
+
|
| 109 |
+
Previous studies analysing the interpretability of attention are all restricted to classification tasks (Jain et al., 2019; Serrano and Smith, 2019; Wiegreffe and Pinter, 2019). Whereas, attention mechanism was first introduced for, and reportedly leads to significant gains in, sequence-to-sequence tasks. Here, we analyse whether for such tasks attention can be manipulated away from its usual interpretation as an alignment between output and input tokens. We begin with three synthetic sequence-to-sequence tasks that involve learning simple input-to-output mappings. 3
|
| 110 |
+
|
| 111 |
+
Bigram Flipping The task is to reverse the bigrams in the input ( { w 1 , w 2 . . . w 2 n -1 , w 2 n } → { w 2 , w 1 , . . . w 2 n , w 2 n -1 } ) .
|
| 112 |
+
|
| 113 |
+
Sequence Copying The task requires copying the input sequence ( { w 1 , w 2 . . . w n -1 , w n } → { w 1 , w 2 . . . w n -1 , w n } ) .
|
| 114 |
+
|
| 115 |
+
Sequence Reversal The goal here is to reverse the input sequence ( { w 1 , w 2 . . . w n -1 , w n } → { w n , w n -1 . . . w 2 , w 1 } ) .
|
| 116 |
+
|
| 117 |
+
The motivation for evaluating on the synthetic tasks is that for any given target token, we precisely know the input tokens responsible. Thus, for these tasks, the gold alignments act as impermissible tokens in our setup (which are different for each output token). For each of the three tasks, we programmatically generate 100 K random input training sequences (with their corresponding target sequences) of length upto 32 . The input and output vocabulary is fixed to a 1000 unique tokens. For the task of bigram flipping, the input lengths are restricted to be even. We use two sets of 100 K unseen random sequences from the same distribution as the validation and test set.
|
| 118 |
+
|
| 119 |
+
3 These tasks have been previously used in the literature to assess the ability of RNNs to learn long-range reorderings and substitutions (Grefenstette et al., 2015).
|
| 120 |
+
|
| 121 |
+
Machine Translation (English to German) Besides synthetic tasks, we also evaluate on English to German translation. We use the Multi30K dataset, comprising of image descriptions (Elliott et al., 2016). Since the gold target to source wordlevel alignment is unavailable, we rely on the Fast Align toolkit (Dyer et al., 2013) to align target words to their source counterparts. We use these aligned words as impermissible tokens.
|
| 122 |
+
|
| 123 |
+
For all sequence-to-sequence tasks, we use an encoder-decoder architecture. Our encoder is a bidirectional GRU, and our decoder is a unidirectional GRU, with dot-product attention over source tokens, computed at each decoding timestep. 4 We also run ablation studies with (i) no attention, i.e. just using the last (or the first) hidden state of the encoder; and (ii) uniform attention, i.e. all the source tokens are uniformly weighted. 5
|
| 124 |
+
|
| 125 |
+
## 5 Results and Discussion
|
| 126 |
+
|
| 127 |
+
In this section we examine how lowering attention affects task performance ( § 5.1). We then present experiments with human participants to quantify the deception with manipulated attention ( § 5.2). Lastly, we identify alternate workarounds through which models preserve task performance ( § 5.3).
|
| 128 |
+
|
| 129 |
+
## 5.1 Attention mass and task performance
|
| 130 |
+
|
| 131 |
+
For the classification tasks , we experiment with the loss coefficient λ ∈ { 0 , 0 . 1 , 1 } . In each experiment, we measure the (i) attention mass: the sum of attention values over the set of impermissible tokens averaged over all the examples, and (ii) test accuracy. During the course of training (i.e. after each epoch), we arrive at different models from which we choose the one whose performance is within 2% of the original accuracy and provides the greatest reduction in attention mass on impermissible tokens. This is done using the development set, and the results on the test set from the chosen model are presented in Table 3. Across most tasks, and models, we find that our manipulation scheme severely reduces the attention mass on impermissible tokens compared to models without any manipulation (i.e. when λ = 0 ). This reduction comes at a minor, or no, decrease in task accuracy. Note that the models can not achieve performance similar to the original model (as they do), unless they rely on the set of impermissible tokens. This can be seen from the gap between models that do not use impermissible tokens ( I 7 ) from ones that do ( I 3 ).
|
| 132 |
+
|
| 133 |
+
4 Implementation details: the encoder and decoder token embedding size is 256, the encoder and decoder hidden dimension size is 512, and the teacher forcing ratio is 0.5. We use top-1 greedy strategy to decode the output sequence.
|
| 134 |
+
|
| 135 |
+
5 All data and code will be released on publication.
|
| 136 |
+
|
| 137 |
+
Table 3: Accuracy of various classification models along with their attention mass (A.M.) on impermissible tokens I , with varying values of the loss coefficient λ . The first row for each model class represents the case when impermissible tokens I for the task are deleted/anonymized. For most models, and tasks, we can severely reduce attention mass on impermissible tokens while preserving original performance ( λ = 0 implies no manipulation).
|
| 138 |
+
|
| 139 |
+
| Model λ I Occupation Pred. Gender Identify SST + Wiki Ref. Letters Acc. A.M. Acc. A.M. Acc. A.M. Acc. A.M. Embedding 0.0 7 93.8 - 66.8 - 48.9 - 74.2 2.3 Embedding 0.0 3 96.3 51.4 100 99.2 70.7 48.4 77.5 2.3 Embedding 0.1 3 96.2 4.6 99.4 3.4 67.9 36.4 76.8 0.5 Embedding 1.0 3 96.2 1.3 99.2 0.8 48.4 8.7 76.9 0.1 BiLSTM 0.0 7 93.3 - 63.3 - 49.1 - 74.7 - BiLSTM 0.0 3 96.4 50.3 100 96.8 76.9 77.7 77.5 4.9 BiLSTM 0.1 3 96.4 0.08 100 < 10 - 6 60.6 0.04 76.9 3.9 BiLSTM 1.0 3 96.7 < 10 - 2 100 < 10 - 6 61.0 0.07 74.2 < 10 - 2 BERT 0.0 7 95.0 - 72.8 - 50.4 - 68.2 BERT (mean) 0.0 3 97.2 13.9 100 80.8 90.8 59.0 74.7 2.6 BERT (mean) 0.1 3 97.2 0.01 99.9 < 10 - 3 90.9 < 10 - 2 76.2 < 10 - 1 BERT (mean) 1.0 3 97.2 < 10 - 3 99.9 < 10 - 3 90.6 < 10 - 3 75.2 < 10 - 2 BERT 0.0 7 95.0 - 72.8 - 50.4 - 68.2 BERT (max) 0.0 3 97.2 99.7 100 99.7 90.8 96.2 74.7 28.9 BERT (max) 0.1 3 97.1 < 10 - 3 99.9 < 10 - 3 90.7 < 10 - 2 76.7 0.6 BERT (max) 1.0 3 97.4 < 10 - 3 99.8 < 10 - 4 90.2 < 10 - 3 75.9 < 10 - 2 |
|
| 140 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 141 |
+
|
| 142 |
+
Table 4: Performance of sequence-to-sequence models and their attention mass (A.M.) on impermissible tokens I , with varying values of the loss coefficient λ . Similar to classification tasks, we can severely reduce attention mass on impermissible tokens while retaining original performance. All values are averaged over five runs.
|
| 143 |
+
|
| 144 |
+
| Attention λ Bigram Flip Sequence Copy Sequence Reverse En → De MT Acc. A.M. Acc. A.M. Acc. A.M. BLEU A.M. Dot-Product 0.0 100.0 94.5 99.9 98.8 100.0 94.1 24.4 20.6 Uniform 0.0 97.8 5.2 93.8 5.2 88.1 4.7 18.5 5.9 None 0.0 96.4 0.0 84.1 0.0 84.1 0.0 14.9 0.0 Manipulated 0.1 99.9 24.4 100.0 27.3 100 27.6 23.7 7.0 Manipulated 1.0 99.8 0.03 92.9 0.02 99.8 0.01 20.6 1.1 |
|
| 145 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 146 |
+
|
| 147 |
+
The only outlier to our findings is the SST+Wiki sentiment analysis task, where we observe that the manipulated Embedding and BiLSTM models reduce the attention mass but also lose accuracy. We speculate that these models are under parameterized and thus jointly reducing attention mass and retaining original accuracy is harder. The more expressive BERT obtains an accuracy of over 90% while reducing the maximum attention mass over the movie review from 96 . 2% to 10 -3 % .
|
| 148 |
+
|
| 149 |
+
For sequence-to-sequence tasks , from Table 4, we observe that our manipulation scheme can similarly reduce attention mass over impermissible alignments while preserving original performance. To measure performance, we use token-by-token accuracy for synthetic tasks, and BLEU score for English to German MT. We also notice that the models with manipulated attention (i.e. deliberately misaligned) outperform models with none or uniform attention . This suggests that attention mechanisms add value to the learning process in sequence-to-sequence tasks which goes beyond their usual interpretation as alignments.
|
| 150 |
+
|
| 151 |
+
## 5.2 Human Study
|
| 152 |
+
|
| 153 |
+
We present three human subjects a series of inputs and outputs from the BiLSTM models, trained to predict occupation (physician or surgeon) given a short biography. 6 We highlight the input tokens as per the attention scores from three different schemes: (i) original dot-product attention, (ii) adversarial attention from Wiegreffe and Pinter (2019), and, (iii) our proposed attention manipulation strategy. We ask human annotators (Q1): Do you think that this prediction was influenced by the gender of the individual? Each participant answers either 'yes' or 'no' for a set of 50 examples from each of the three attention schemes. 7 After looking at 50 examples from a given attention scheme, we inquire about trustworthiness of the attention scores (Q2): Do you believe the highlighted tokens capture the factors that drive the models' prediction? They answer the question on a scale of 1 to 4 , where 1 denotes that the highlighted tokens do not determine the models' prediction, whereas 4 implies they significantly determine the models' prediction. We deliberately ask participants once (towards the end) about the trustworthiness of attention-based explanations, in contrast to polling after each example, as it requires multiple examples to assess whether the explanations capture factors that are predictive.
|
| 154 |
+
|
| 155 |
+
Results We find that for the original dot-product attention, annotators labeled 66% of predictions to be influenced by gender. Whereas for the other two attention schemes, none of the predictions were marked to be influenced by gender (see Table 5). This is despite all three models achieving roughly the same high accuracy ( 96% ) which relies on gender information. This demonstrates the efficacy of our manipulation scheme-predictions from models biased against gender minorities are perceived (by human participants) as not being influenced by gender. Further, our manipulated explanations receive a trustworthiness score of 2.67 (out of 4), only slightly lower than the score for the original explanations, and significantly better than the adversarial attention. We found that the KL divergence term in training adversarial attention (Eq. 1) encourages all the attention mass to concentrate on a single uninformative token for most examples, and hence was deemed as less trustworthy by the annotators (see Table 5, more examples in appendix). By contrast, our manipulation scheme only reduces attention mass over problematic tokens, and retains attention over nonproblematic but predictive ones (e.g. 'medicine') making it more believable. We assess agreement among annotators, and calculate the Fleiss' Kappa to be 0.97, suggesting almost perfect agreement.
|
| 156 |
+
|
| 157 |
+
6 The participating subjects are graduate students, proficient in English, and unaware of our work.
|
| 158 |
+
|
| 159 |
+
7 Weshuffled the order of sets among the three participants to prevent any ordering bias. Full details of the instructions presented to the annotators are in the appendix
|
| 160 |
+
|
| 161 |
+
Table 5: Results to questions posed to human participants. Q1: Do you think that this prediction was influenced by the gender of the individual? Q2: Do you believe the highlighted tokens capture the factors that drive the models prediction? See § 5.2 for discussion.
|
| 162 |
+
|
| 163 |
+
| Attention Example Q1 Q2 Original Ms. X practices medicine and specializes in urological surgery 66% (yes) 3.00 Adversarial (Wiegreffe and Pinter, 2019) Ms. X practices medicine and specializes in urological surgery 0% (yes) 1.00 Ours Ms. X practices medicine and specializes in urological surgery 0% (yes) 2.67 |
|
| 164 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 165 |
+
|
| 166 |
+
## 5.3 Alternative Workarounds
|
| 167 |
+
|
| 168 |
+
We identify two mechanisms by which the models cheat , obtaining low attention values while remaining accurate.
|
| 169 |
+
|
| 170 |
+
Models with recurrent encoders can simply pass information across tokens through recurrent connections, prior to the application of attention. To measure this effect, we hard-set the attention values corresponding to impermissible words to zero after the manipulated model is trained, thus clipping their direct contributions for inference. For gender classification using the BiLSTM model, we are still able to predict over 99% of instances correctly, thus confirming a large degree of information flow to neighboring representations. 8 In contrast, the Embedding model (which has no means to pass the information pre-attention) attains only about 50% test accuracy after zeroing the attention values for gender pronouns. We see similar evidence of passing around information in sequence-to-sequence models, where certain manipulated attention maps are off by one or two positions from the gold alignments (see Figure 2).
|
| 171 |
+
|
| 172 |
+
Models restricted from passing information prior to the attention mechanism tend to increase the magnitude of the representations corresponding to impermissible words to compensate for the low attention values. This effect is illustrated in Figure 3, where the L2 norm of embeddings for impermissible tokens increase considerably for the Embedding model during training. We do not see increased embedding norms for the BiLSTM model, as this is unnecessary due to the model's capability to move around relevant information.
|
| 173 |
+
|
| 174 |
+
8 A recent study (Brunner et al., 2019) similarly observes a high degree of 'mixing' of information across layers in Transformer models.
|
| 175 |
+
|
| 176 |
+
Figure 2: For three sequence-to-sequence tasks, we plot the original attention map on the left, followed by the attention plots of two manipulated models. The only difference between the manipulated models for each task is the (random) initialization seed. Different manipulated models resort to different alternative mechanisms.
|
| 177 |
+
|
| 178 |
+
<!-- image -->
|
| 179 |
+
|
| 180 |
+
Figure 3: For gender identification task, the norms of embedding vectors corresponding to impermissible tokens increase considerably in Embedding+Attention model to offset the low attention values. This is not the case for BiLSTM+Attention model as it can pass information due to recurrent connections.
|
| 181 |
+
|
| 182 |
+
<!-- image -->
|
| 183 |
+
|
| 184 |
+
Wealso notice that differently initialized models attain different alternative mechanisms . In Figure 2, we present attention maps from the original model, alongside two manipulated models initialized with different seeds. In some cases, the attention map is off by one or two positions from the gold alignments. In other cases, all the attention is confined to the first hidden state. In such cases, manipulated models are similar to a no-attention model, yet they offer better performance. In preliminary experiments, we found a few such models that outperform the no-attention baseline, even when the attention is turned off during inference. This suggests that attention offers benefits during training, even if it is not used during inference.
|
| 185 |
+
|
| 186 |
+
## 6 Conclusion
|
| 187 |
+
|
| 188 |
+
Amidst practices that perceive attention scores to be an indication of what the model focuses on , we show that attention scores are easily manipulable. Our simple training scheme produces models with significantly reduced attention mass over tokens known a priori to be useful for prediction, while continuing to use them. Our results raise concerns about the potential use of attention as a tool to audit algorithms, as malicious actors could employ similar techniques to mislead regulators.
|
| 189 |
+
|
| 190 |
+
## Acknowledgement
|
| 191 |
+
|
| 192 |
+
The authors thank Dr. Julian McAuley for providing, and painstakingly anonymizing the data for reference letters. We also acknowledge Alankar Jain for carefully reading the manuscript and providing useful feedback. ZL thanks Amazon AI, NVIDIA, Salesforce, Facebook AI, AbridgeAI, UPMC, the Center for Machine Learning in Health, the PwC Center, the AI Ethics and Governance Fund, and DARPA's Learning with Less Labels Initiative, for their support of ACMI Lab's research on robust and societally aligned machine learning.
|
| 193 |
+
|
| 194 |
+
## References
|
| 195 |
+
|
| 196 |
+
- Dzmitry Bahdanau, Kyunghyun Cho, and Yoshua Bengio. 2014. Neural machine translation by jointly learning to align and translate. arXiv preprint arXiv:1409.0473 .
|
| 197 |
+
- Maria Barrett, Joachim Bingel, Nora Hollenstein, Marek Rei, and Anders Søgaard. 2018. Sequence classification with human attention. In Proceedings of the 22nd Conference on Computational Natural Language Learning , pages 302-312.
|
| 198 |
+
- Gino Brunner, Yang Liu, Dami´ an Pascual, Oliver Richter, and Roger Wattenhofer. 2019. On the validity of self-attention as explanation in transformer models. arXiv preprint arXiv:1908.04211 .
|
| 199 |
+
- Wenhu Chen, Evgeny Matusov, Shahram Khadivi, and Jan-Thorsten Peter. 2016. Guided alignment training for topic-aware neural machine translation. arXiv preprint arXiv:1607.01628 .
|
| 200 |
+
- Edward Choi, Mohammad Taha Bahadori, Jimeng Sun, Joshua Kulas, Andy Schuetz, and Walter Stewart. 2016. Retain: An interpretable predictive model for healthcare using reverse time attention mechanism. In Advances in Neural Information Processing Systems , pages 3504-3512.
|
| 201 |
+
- Maria De-Arteaga, Alexey Romanov, Hanna Wallach, Jennifer Chayes, Christian Borgs, Alexandra Chouldechova, Sahin Geyik, Krishnaram Kenthapadi, and Adam Tauman Kalai. 2019. Bias in bios: A case study of semantic representation bias in a high-stakes setting. arXiv preprint arXiv:1901.09451 .
|
| 202 |
+
- Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. 2019. Bert: Pre-training of deep bidirectional transformers for language understanding. North American Chapter of the Association for Computational Linguistics (NAACL) .
|
| 203 |
+
- Chris Dyer, Victor Chahuneau, and Noah A Smith. 2013. A simple, fast, and effective reparameterization of ibm model 2. North American Chap-
|
| 204 |
+
- ter of the Association for Computational Linguistics (NAACL) .
|
| 205 |
+
- Desmond Elliott, Stella Frank, Khalil Sima'an, and Lucia Specia. 2016. Multi30k: Multilingual english-german image descriptions. arXiv preprint arXiv:1605.00459 .
|
| 206 |
+
- Andrea Galassi, Marco Lippi, and Paolo Torroni. 2019. Attention, please! a critical review of neural attention models in natural language processing. arXiv preprint arXiv:1902.02181 .
|
| 207 |
+
- Alex Graves and J¨ urgen Schmidhuber. 2005. Framewise phoneme classification with bidirectional lstm and other neural network architectures. Neural Networks , 18(5-6):602-610.
|
| 208 |
+
- Edward Grefenstette, Karl Moritz Hermann, Mustafa Suleyman, and Phil Blunsom. 2015. Learning to transduce with unbounded memory. In Advances in neural information processing systems , pages 18281836.
|
| 209 |
+
- Sarthak Jain, Ramin Mohammadi, and Byron C Wallace. 2019. Attention is not explanation. North American Chapter of the Association for Computational Linguistics (NAACL) .
|
| 210 |
+
- Vivian Lai and Chenhao Tan. 2019. On human predictions with explanations and predictions of machine learning models: A case study on deception detection. In Proceedings of the Conference on Fairness, Accountability, and Transparency , pages 2938. ACM.
|
| 211 |
+
- Jiwei Li, Will Monroe, and Dan Jurafsky. 2016. Understanding neural networks through representation erasure. arXiv preprint arXiv:1612.08220 .
|
| 212 |
+
- Lemao Liu, Masao Utiyama, Andrew Finch, and Eiichiro Sumita. 2016. Neural machine translation with supervised attention. arXiv preprint arXiv:1609.04186 .
|
| 213 |
+
- Andre Martins and Ramon Astudillo. 2016. From softmax to sparsemax: A sparse model of attention and multi-label classification. In International Conference on Machine Learning , pages 1614-1623.
|
| 214 |
+
- Sofia Serrano and Noah A Smith. 2019. Is attention interpretable? 57th annual meeting of the Association for Computational Linguistics (ACL) .
|
| 215 |
+
- Richard Socher, Alex Perelygin, Jean Wu, Jason Chuang, Christopher D Manning, Andrew Ng, and Christopher Potts. 2013. Recursive deep models for semantic compositionality over a sentiment treebank. In Proceedings of the 2013 conference on empirical methods in natural language processing , pages 1631-1642.
|
| 216 |
+
- Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin. 2017. Attention is all you need. In Advances in neural information processing systems , pages 5998-6008.
|
| 217 |
+
- Sarah Wiegreffe and Yuval Pinter. 2019. Attention is not not explanation. Proceedings of the 2019 conference on Empirical Methods in Natural Language Processing, EMNLP .
|
| 218 |
+
- Qizhe Xie, Xuezhe Ma, Zihang Dai, and Eduard Hovy. 2017. An interpretable knowledge transfer model for knowledge base completion. arXiv preprint arXiv:1704.05908 .
|
| 219 |
+
- Kelvin Xu, Jimmy Ba, Ryan Kiros, Kyunghyun Cho, Aaron Courville, Ruslan Salakhutdinov, Richard Zemel, and Yoshua Bengio. 2015. Show, attend and tell: Neural image caption generation with visual attention. arXiv preprint arXiv:1502.03044 .
|
| 220 |
+
|
| 221 |
+
## Supplementary Material
|
| 222 |
+
|
| 223 |
+
## A Instructions for human study
|
| 224 |
+
|
| 225 |
+
In a series of examples, we present the inputs and outputs of a machine learning (ML) model trained to predict occupation (physician or surgeon) given a short bio (text). In each bio, we attempt to explain the predictions of the model. Specifically, we employ a technique that highlights words that (per our explanation method) are thought to be responsible for a particular prediction (colloquially, what the model focuses on ). For each unique example below, answer the following question: Do you think that this prediction was influenced by the gender of the individual?
|
| 226 |
+
|
| 227 |
+
- Yes, I suspect that the gender influenced the prediction.
|
| 228 |
+
- No, I have no reason to suspect that gender influenced the prediction.
|
| 229 |
+
|
| 230 |
+
Please note that, all the examples in this file are input, output pairs from one specific model. Further, darker shades of highlighting indicate a higher emphasis for the token (as per our explanation method).
|
| 231 |
+
|
| 232 |
+
After showing 50 examples from a given attention scheme, we inquire: Overall, do you believe the highlighted tokens capture the factors that drive the models prediction?
|
| 233 |
+
|
| 234 |
+
1. The highlighted tokens capture factors that do not determine the models prediction.
|
| 235 |
+
2. The highlighted tokens capture factors that marginally determine the models prediction.
|
| 236 |
+
3. The highlighted tokens capture factors that moderately determine the models predictions.
|
| 237 |
+
4. The highlighted tokens capture factors that significantly determine the models predictions.
|
| 238 |
+
|
| 239 |
+
## B Dataset Details
|
| 240 |
+
|
| 241 |
+
Details about the datasets used for classification tasks are available in Table 6.
|
| 242 |
+
|
| 243 |
+
## C Qualitative Examples
|
| 244 |
+
|
| 245 |
+
A few qualitative examples illustrating three different attention schemes are listed in Table 7.
|
| 246 |
+
|
| 247 |
+
Table 6: Number of training, validation, and test examples in various datasets used for classification tasks.
|
| 248 |
+
|
| 249 |
+
| Dataset (Task) Train Val Test CommonCrawl Biographies (Physician vs Surgeon) 17629 2519 5037 Wikipedia Biographies (Gender Identification) 9017 1127 1127 SST + Wikipedia (Sentiment Analysis) 6920 872 1821 Reference Letters (Acceptance Prediction) 32800 4097 4094 |
|
| 250 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 251 |
+
|
| 252 |
+
Table 7: Qualitative examples.
|
| 253 |
+
|
| 254 |
+
| Attention Input Example Prediction Original Ms. X practices medicine and specializes in urological surgery Physician Adversarial (Wiegreffe and Pinter, 2019) Ms. X practices medicine and specializes in urological surgery Physician Ours Ms. X practices medicine and specializes in urological surgery Physician Original Ms. X practices medicine in Fort Myers, FL and specializes in family medicine Physician Adversarial (Wiegreffe and Pinter, 2019) Ms. X practices medicine in Fort Myers, FL and specializes in family medicine Physician Ours Ms. X practices medicine in Fort Myers, FL and specializes in family medicine Physician Original Having started his surgical career as a general orthopaedic surgeon, Mr X retains a broad practice which includes knee and hand surgery . He still does regular trauma on-call for the North Hampshire hospital and treats all types of orthopaedic problems and trauma. Surgeon Adversarial (Wiegreffe and Pinter, 2019) Having started his surgical career as a general orthopaedic surgeon, Mr X retains a broad practice which includes knee and hand surgery. He still does regular trauma on-call for the North Hampshire hospital and treats all types of orthopaedic problems and trauma. Surgeon Ours Having started his surgical career as a general orthopaedic surgeon, Mr X retains a broad practice which includes knee and hand surgery. He still does regular trauma on-call for the North Hampshire hospital and treats all types of orthopaedic problems and trauma. Surgeon Original Ms. X practices medicine in ... and specializes in pediatrics. Ms. X is affiliated with childrens of Alabama, Saint Vincents hospital Birmingham and Brookwood Medical Center. Ms. X speaks English and Arabic. Physician Adversarial (Wiegreffe and Pinter, 2019) Ms. X practices medicine in ... and specializes in pediatrics. Ms. X is affiliated with childrens of Alabama, Saint Vincents hospital Birmingham and Brookwood Medical Center. Ms. X speaks English and Arabic. Physician Ours Ms. X practices medicine in ... and specializes in pediatrics . Ms. X is affiliated with childrens of Alabama, Saint Vincents hospital Birmingham and Brookwood Medical Center. Ms. X speaks English and Arabic. Physician |
|
| 255 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
text-versions/attention-markdown/1910.14537_Attention Is All You Need for Chinese Wo.md
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1910.14537 Attention Is All You Need For Chinese Wo
|
| 2 |
+
|
| 3 |
+
1
|
| 4 |
+
|
| 5 |
+
## Attention Is All You Need for Chinese Word Segmentation
|
| 6 |
+
|
| 7 |
+
Sufeng Duan 1 , 2 , 3 , Hai Zhao 1 , 2 , 3 ∗
|
| 8 |
+
|
| 9 |
+
Department of Computer Science and Engineering, Shanghai Jiao Tong University 2 Key Laboratory of Shanghai Education Commission for Intelligent Interaction and Cognitive Engineering, Shanghai Jiao Tong University, Shanghai, China 3 MoE Key Lab of Artificial Intelligence, AI Institute, Shanghai Jiao Tong University
|
| 10 |
+
|
| 11 |
+
1140339019dsf@sjtu.edu.cn, zhaohai@cs.sjtu.edu.cn
|
| 12 |
+
|
| 13 |
+
## Abstract
|
| 14 |
+
|
| 15 |
+
Taking greedy decoding algorithm as it should be, this work focuses on further strengthening the model itself for Chinese word segmentation (CWS), which results in an even more fast and more accurate CWS model. Our model consists of an attention only stacked encoder and a light enough decoder for the greedy segmentation plus two highway connections for smoother training, in which the encoder is composed of a newly proposed Transformer variant, Gaussian-masked Directional (GD) Transformer, and a biaffine attention scorer. With the effective encoder design, our model only needs to take unigram features for scoring. Our model is evaluated on SIGHAN Bakeoff benchmark datasets. The experimental results show that with the highest segmentation speed, the proposed model achieves new state-of-the-art or comparable performance against strong baselines in terms of strict closed test setting.
|
| 16 |
+
|
| 17 |
+
## 1 Introduction
|
| 18 |
+
|
| 19 |
+
Chinese word segmentation (CWS) is the task of delimiting word boundaries in a sentence, as a basic and essential task for Chinese and many other East Asian languages which are written without explicit word delimiters, and thus different from alphabetical languages like English.
|
| 20 |
+
|
| 21 |
+
Learning from an annotated corpus with segmentation, the CWS task may be generally modeled as a decoder which performs segmentation based on a scoring module in terms of contextual feature based representations. Table 1 summarizes typical CWS models according to their decoding ways.
|
| 22 |
+
|
| 23 |
+
∗ Corresponding author. This paper was partially supported by National Key Research and Development Program of China (No. 2017YFB0304100), Key Projects of National Natural Science Foundation of China (U1836222 and 61733011), Huawei-SJTU long term AI project, Cutting-edge Machine reading comprehension and language model.
|
| 24 |
+
|
| 25 |
+
Markov models such as (Ng and Low, 2004) and (Zheng et al., 2013) depend on the maximum entropy model or maximum entropy Markov model both with Viterbi decoding. Besides, conditional random field (CRF) or Semi-CRF for sequence labeling has been used for both traditional and neural models though with different representations (Peng et al., 2004; Andrew, 2006; Wang and Xu, 2017; Ma et al., 2018).
|
| 26 |
+
|
| 27 |
+
Recent neural CWS research have been concerned about the following three perspectives (Emerson, 2005).
|
| 28 |
+
|
| 29 |
+
Decoder . As CWS is a kind of structure learning task, the decoder module generally determines which type of detailed algorithm should be adopted for segmentation, also it may limit the capability of defining feature. As shown in Table 2, not all models can support the word-level features as CWS is a task to predict word boundary. Thus recent works focus on finding more general or flexible decoder design to make model learn the representation of segmentation more effective such as (Cai and Zhao, 2016; Cai et al., 2017).
|
| 30 |
+
|
| 31 |
+
Encoder. Practice in various natural language processing tasks has shown that effective representation is essential to the performance improvement. For such a module in neural models, it is more than an encoder now, which is regarded as the most improvement perspective against traditional models. Thus for better CWS, it is crucial to encode the input character, word or sentence into a distinguishable representation. Table 2 summarizes regular feature sets for typical CWS models including ours as well. The building blocks that encoders use include recurrent neural network (RNN) and convolutional neural network (CNN), and long short-term memory (LSTM) network.
|
| 32 |
+
|
| 33 |
+
External resources and pre-trained embedding. Using external resource such as pre-trained embeddings or language representation provides an alternative for performance improvement other than designing better models (Yang et al., 2017). SIGHAN Bakeoff therefore defines two types of evaluation settings, closed test limits all the data for learning not to be beyond the given training set, while open test does not take this limitation (Emerson, 2005). This work will focus on the closed test setting by finding a better model design for further CWS.
|
| 34 |
+
|
| 35 |
+
Table 1: The classification of Chinese word segmentation model.
|
| 36 |
+
|
| 37 |
+
| Traditional Models Neural Models Decoding Algorithm Greedy Model - Ours Greedy Markov Model (Ng and Low, 2004), (Low et al., 2005) MMTNN: (Pei et al., 2014) (Zheng et al., 2013), LSTM: (Chen et al., 2015) Viterbi Sequence Labeling Model CRF: (Peng et al., 2004), semi-CRF: (Andrew, 2006), (Sun et al., 2009) CNN+CRF:(Wang and Xu, 2017), BiLSTM+CRF:(Ma et al., 2018) General Graph Model (Zhang and Clark, 2007) LSTM+GCNN: (Cai and Zhao, 2016), LSTM+GCNN: (Cai et al., 2017) (Wang et al., 2019a) Beam search |
|
| 38 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 39 |
+
|
| 40 |
+
Table 2: Feature windows of different models. i ( j ) is the index of current character(word).
|
| 41 |
+
|
| 42 |
+
| Models Characters Words character based Ours c 0 , c 1 , . . . , c i , c i +1 , . . . , c n - (Zheng et al., 2013), . . . c i - 2 , c i - 1 , c i , c i +1 , c i +2 - (Chen et al., 2015) c 0 , c 1 , . . . , c i , c i +1 , c i +2 - word based (Zhang and Clark, 2007), . . . c in w j - 1 , w j , w j +1 w j - 1 , w j , w j +1 (Cai and Zhao, 2016; Cai et al., 2017) c 0 , c 1 , . . . , c i w 0 , w 1 , . . . , w j |
|
| 43 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 44 |
+
|
| 45 |
+
Generally speaking, both the major difference between traditional and neural models, and what mostly distinguishes the neural models are about the way to represent input sentences, while the options of decoding algorithms are bounded to how to formalize the CWS into a structural learning task. As shown in Table 1, using Markov contextualized features, Markov models and CRF-based models are capable of using Viterbi decoders with polynomial time complexity. Furthermore, to accommodate more rich features means that the model has to take a deeper structural learning which also requires more complex decoding algorithms (Zhang and Clark, 2007; Cai and Zhao, 2016). However, for such a case, deterministic decoding algorithms may have an intractable complexity, thus it forces the model to use an approximate beam search strategy luckily with low-order polynomial time complexity O ( Mnb 2 ) , where b is beam width, n is the sentence size, and M is a constant representing the model complexity. When the beam width b =1, the beam search will reduce to greedy algorithm with a much better time complexity O ( Mn ) .
|
| 46 |
+
|
| 47 |
+
To make the decoding practical, the beam width b has to be carefully tuned for a tradeoff between accuracy and efficiency: A larger b will make the learning and segmentation extremely slow, while a small b cannot sufficiently guarantee the segmentation performance. However, there has long been a unheeded observation that good enough representations can offer good enough segmentation even though only using a greedy segmentation algorithm. (Sproat and Emerson, 2003) create a topline evaluation by using only using vocabulary from test set to perform a greedy segmentation (maximum matching), which yields around 99% F-scores on all datasets. For neural models, (Cai et al., 2017) verify that if the representations are good enough, beam width 1 can still give state-of-the-art performance compared to their early model with a full beam search decoder in (Cai and Zhao, 2016). Therefore, undertaking a fixed greedy segmentation algorithm, this paper only focuses on more effective encoder design for even better representation.
|
| 48 |
+
|
| 49 |
+
Our model only consists of attention mechanisms as building blocks plus two highway connections via a virtual hidden layer for smooth training. Our model is simply stacked by a variant of Transformer encoder (Vaswani et al., 2017) and a biaffine attention scorer (Dozat and Manning, 2017). Empowered by the self-attention mechanism, the Transformer has been good at capturing long-range dependencies for input sentence. We propose Gaussian-masked Directional (GD) multihead attention to facilitate the learning of localness, position and directional information for CWS, so that we have the proposed GD-Transformer.
|
| 50 |
+
|
| 51 |
+
With our further improved encoder, our model uses only simple unigram features to generate representation of sentences for scoring. Our model will be strictly evaluated on benchmark datasets from SIGHAN Bakeoff shared task in terms of closed test setting, and experimental results show that our model achieves new state-of-the-art.
|
| 52 |
+
|
| 53 |
+
The technical contributions of this paper can be summarized as follows.
|
| 54 |
+
|
| 55 |
+
- To especially enhance the representation of localness information and directional information, we propose a new Gaussian-masked Directional Transformer encoder.
|
| 56 |
+
- Motivated from a simple design idea, we present a new CWS model which is stacked with only attention blocks.
|
| 57 |
+
- With a powerful enough encoder, for the first time, we show that unigram (character) features plus greedy segmentation algorithm can support yielding strong performance instead of using diverse n -gram (character and word) features and highly complex decoding algorithms.
|
| 58 |
+
|
| 59 |
+
## 2 Related Work
|
| 60 |
+
|
| 61 |
+
(Xue, 2003) first formalize CWS as a sequence labeling task, considering CWS as a supervised learning from annotated corpus with human segmentation. (Peng et al., 2004) further adopt standard sequence labeling tool CRFs for CWS modeling, achieving new state-of-the-art. (Zhao et al., 2006b) show that different character tag sets can make essential impact for segmentation performance. (Zhao et al., 2006a) propose a CWS system developed for Bakeoff-2006 based on CRF, which is based on their proposed 6-tag set for character position tagging and achieved state-of-the-art performance at then. (Zhao and Kit, 2007) present a novel Character tagging based CRF framework which is capable of exploiting global information for performance enhancement.
|
| 62 |
+
|
| 63 |
+
Neural word segmentation has been widely used to minimize the efforts in feature engineering. (Zheng et al., 2013) first introduce the neural model into CWS with sliding-window based sequence labeling. (Chen et al., 2015) use LSTM to enhance the learning of long distance information.
|
| 64 |
+
|
| 65 |
+
However, introducing neural models themselves does not really introduce substantial performance improvement in terms of strict closed test of SIGHAN Bakeoff according to (Zhao et al., 2017).
|
| 66 |
+
|
| 67 |
+
Most researchers actually seek help from joint learning, extra learning resources including dictionaries, pre-trained embedding, deeper information extracted from training set and so on. (1) For joint learning, (Lyu et al., 2016) explore a joint model that performs segmentation, POS-Tagging and chunking simultaneously. (Zhang et al., 2017) present a joint model to enhance the segmentation of Chinese microtext by performing CWS and informal word detection simultaneously. (2) For extra resources or clues, (Wang et al., 2019b) propose to incorporate unlabeled and partially-labeled data.
|
| 68 |
+
|
| 69 |
+
Only a few researches are known for concentrating on strengthening the model itself. To accommodate more rich features through a more broadly structural modeling (Cai and Zhao, 2016) propose a neural framework that eliminates context windows and utilize complete segmentation history. (Wang and Xu, 2017) propose a character-based convolutional neural model to capture n -gram features automatically and an effective approach to incorporate word embeddings. (Cai et al., 2017) further improve the model in (Cai and Zhao, 2016) and show that a greedy segmenter can perform fast and accurately in terms of only presenting effective representations. This work follows this line of research by offering even strengthened model design from simple idea, including the least building block type for encoder (attention only), the least feature type for scoring (unigram only) and the least computational complexity for decoding (greedy segmentation).
|
| 70 |
+
|
| 71 |
+
The original Transformer encoder consists of a stack of N identical layers and each layer has one multi-head self-attention layer and one positionwise fully connected feed-forward layer (Vaswani et al., 2017). One residual connection is around two sub-layers and followed by layer normalization. Several variants are proposed to enhance ability of capturing the localness relationship. (Shaw et al., 2018) propose an effcient way to incorporate relative and absolute position representation. (Yang et al., 2018) cast localness modeling as a learnable Gaussian bias to enhance the ability of capturing useful local context. (Kim et al., 2020) propose a Transformer with Gaussian-weighted self-attention to improved speech-enhancement performance. (Zhang et al., 2020b) propose using syntax to guide the text modeling based on selfattention network sponsored Transformer-based encoder. Transformer based pre-trained language models have become a standard performance enhancement means for various NLP tasks (Zhang et al., 2020a).
|
| 72 |
+
|
| 73 |
+
Figure 1: The architecture of our model.
|
| 74 |
+
|
| 75 |
+
<!-- image -->
|
| 76 |
+
|
| 77 |
+
## 3 Models
|
| 78 |
+
|
| 79 |
+
Our model for CWS task is composed of an encoder to represent the input and a decoder based on the encoder to perform actual segmentation. Figure 1 is the architecture of our model. The model feeds sentence into encoder. Embedding captures the vector e of the input character sequences of c . The encoder maps vector sequences of e to two sequences of vector which are v b and v f as the representation of sentences. With v b and v f , the biaffine scorer scores each segmentation gaps which makes our decoder is as simple as one layer, using a threshold to directly and greedily predict every word boundaries of the input.
|
| 80 |
+
|
| 81 |
+
## 3.1 Gaussian-Masked Directional Transformer
|
| 82 |
+
|
| 83 |
+
The standard Transformer encoder consists of a stack of N identical layers and each has one multihead self-attention layer and one position-wise fully connected feed-forward layer. One residual connection is around two sub-layers and followed by layer normalization (Vaswani et al., 2017).
|
| 84 |
+
|
| 85 |
+
The proposed Gaussian-masked Directional (GD) Transformer encoder adopts two key architecture revisions over the standard Transformer. (1)
|
| 86 |
+
|
| 87 |
+
Our encoder includes three parallel directional encoding pipelines instead of only one bidirectional encoder in the original Transformer. (2) By replacing the standard multi-head self-attention with the proposed Gaussian-masked Directional (GD) multihead self-attention which captures representations from different directions, the resulted encoder may gain better ability of capturing the localness information and position information for the importance of adjacent characters.
|
| 88 |
+
|
| 89 |
+
Encoder Stacks In CWS task, word boundary forms a gap between two adjacent characters and divides one sequence into two parts, one part in front of the gap and one part in the rear of it. The forward encoder and backward encoder are proposed to capture information of two directions which correspond to two parts divided by the gap. Assuming that one unidirectional encoder can capture information from one particular direction, we stack three parallel encoding modules, forward, backward and center encoders as shown in Figure 1.
|
| 90 |
+
|
| 91 |
+
The central encoder is to capture information from both directions, which is with the same architecture as the original Transformer. Standard scaled dot-product attention matrix is calculated by dotting query Q with all keys K . For the forward encoder, we forcibly set all values inside the attention matrix representing the character pair relation after the concerned character as 0 so that the encoder can focus on the forward characters. For the backward encoder, we take the similar matrix value setting operations.
|
| 92 |
+
|
| 93 |
+
The encoder respectively outputs one forward and one backward representations for each position, and then both are fused with the representation given by the center encoder to form the updated forward and backward representations, respectively.
|
| 94 |
+
|
| 95 |
+
<!-- formula-not-decoded -->
|
| 96 |
+
|
| 97 |
+
where v b and v f represent the backward and forward representation, respectively, r b , r c and r f are representations from backward encoder, center encoder and forward encoder, respectively.
|
| 98 |
+
|
| 99 |
+
Gaussian-Masked Directional Multi-Head Attention Similar as scaled dot-product attention in the original Transformer (Vaswani et al., 2017), our proposed Gaussian-masked directional attention can be described as a function to map queries and key-value pairs to the representation of input. Here queries, keys and values are all vectors. Standard scaled dot-product attention is calculated by dotting query Q with all keys K , dividing each values by √ d k , where √ d k is the dimension of keys, and apply a softmax function to generate the weights in the attention:
|
| 100 |
+
|
| 101 |
+
<!-- formula-not-decoded -->
|
| 102 |
+
|
| 103 |
+
Different from scaled dot-product attention, Gaussian-masked directional attention expects to pay attention to the adjacent characters of each positions and cast the localness relationship between characters as a fix Gaussian weight for attention. We assume that the Gaussian weight only relies on the distance between characters.
|
| 104 |
+
|
| 105 |
+
Firstly we introduce the Gaussian weight matrix G =( g ij ) which presents the localness relationship between each two characters:
|
| 106 |
+
|
| 107 |
+
<!-- formula-not-decoded -->
|
| 108 |
+
|
| 109 |
+
where g ij is the Gaussian weight between character i and j , dis ij is the distance between character i and j , Φ( x ) is the cumulative distribution function of Gaussian, σ is the standard deviation of Gaussian function and it is a hyperparameter in our method. Eq. (2) ensures the Gaussian weight equals 1 when dis ij is 0. The larger distance between characteristics, the smaller the weight is, which lets one character affect its neighbors more than those non-neighbors.
|
| 110 |
+
|
| 111 |
+
To combine the Gaussian weight to the selfattention, we produce the Hadamard product of Gaussian weight matrix G and the score matrix produced by QK T
|
| 112 |
+
|
| 113 |
+
<!-- formula-not-decoded -->
|
| 114 |
+
|
| 115 |
+
where AG as the Gaussian-masked attention ensures that adjacent characters have a stronger relationship than those non-neighbored ones.
|
| 116 |
+
|
| 117 |
+
The scaled dot-product attention models the relationship between two characters without regard to their distances in one sequence. For CWS task, the weight between adjacent characters should be more important while it is hard for self-attention to achieve the effect explicitly because the selfattention cannot get the order of sentences directly. The Gaussian-masked attention adjusts the weight between characters and their adjacent character to a larger value which stands for the effect of adjacent characters.
|
| 118 |
+
|
| 119 |
+
(a) The architecture of Gaussian-masked directional multi-head attention. (b) The Gaussian-masked directional attention.
|
| 120 |
+
|
| 121 |
+
<!-- image -->
|
| 122 |
+
|
| 123 |
+
Figure 2: Illustration of Gaussian-masked directional multi-head attention.
|
| 124 |
+
|
| 125 |
+
For forward and backward encoder, the selfattention sub-layer needs to use a triangular matrix mask to let the self-attention focus on different weights:
|
| 126 |
+
|
| 127 |
+
<!-- formula-not-decoded -->
|
| 128 |
+
|
| 129 |
+
where pos i is the position of character c i . The triangular matrix for forward and backward encode
|
| 130 |
+
|
| 131 |
+
<!-- formula-not-decoded -->
|
| 132 |
+
|
| 133 |
+
Similar as (Vaswani et al., 2017), we use multihead attention to capture information from different dimension positions as Figure 2(a) and get Gaussian-masked directional multi-head attention GMH as follows,
|
| 134 |
+
|
| 135 |
+
<!-- formula-not-decoded -->
|
| 136 |
+
|
| 137 |
+
where W q i , W k i , W v i ∈ R d k × d h is the parameter matrices to generate heads, W m is a parameter matrices of R d k × d k to generate the attention, d k and d h are dimensions of model and one head, respectively.
|
| 138 |
+
|
| 139 |
+
## 3.2 Biaffine Attention Scorer
|
| 140 |
+
|
| 141 |
+
Our model straightforwardly predicts gap between two adjacent characters as word boundary or not. In detail, we set a label value 1 to indicate word boundary, and 0 means no word boundary. Such a gap labeling task thus requires information of the two adjacent characters. In the meantime, the relationship between adjacent characters can be represented as the gap label.
|
| 142 |
+
|
| 143 |
+
Biaffine attention scorer is used to label the gap (Dozat and Manning, 2017; Li et al., 2018; Cai et al., 2018; Zhou and Zhao, 2019; He et al., 2019). The distribution of labels in a labeling task is often uneven. Biaffine attention uses bias terms to alleviate the burden of the fixed bias term and get the prior probability which makes it different from bilinear attention. The distribution of the gap is uneven that is similar as other labeling task, which makes biaffine available for our task.
|
| 144 |
+
|
| 145 |
+
Biaffine attention scorer labels the target depending on information of independent unit and the joint information of two units. In biaffine attention, the score s ij of characters c i and c j ( i < j ) is calculated by:
|
| 146 |
+
|
| 147 |
+
<!-- formula-not-decoded -->
|
| 148 |
+
|
| 149 |
+
where v f i and v b i represent respectively the forward and backward information of c j , W , U and b are all learnable parameters. W is a matrix with shape ( d i × N × d j ) and U is a ( N × ( d i + d j )) matrix where d i is the dimension of vector v f i and N is the number of labels.
|
| 150 |
+
|
| 151 |
+
In our model, the biaffine scorer uses both the forward and backward character information on either side of the gap to distinguish the position of characters. Figure 3 is an example of gap labeling. The bidirectional scoring ensures that the boundaries of words can be determined by adjacent characters with different directional information. The score vector of the gap is formed by the probability of being a boundary of word. Further, the model generates all boundaries using activation function in a greedy decoding way.
|
| 152 |
+
|
| 153 |
+
## 3.3 Highway Connections via Hidden Layer
|
| 154 |
+
|
| 155 |
+
To smooth the training and fully exploit representations from hidden states, we additionally introduce two Highway connections (Srivastava et al., 2015) via a virtual hidden layer which is called Hidden Representations for Early Decoding (HiRED) in the middle of the Transformer encoder. In our model design, we always put the HiRED layer in the central position among all layers of the encoder, thus the HiRED layer divides each directional encoder (forward, backward or center) pipelines into two parts (front and rear) as shown in Figure 1.
|
| 156 |
+
|
| 157 |
+
Figure 3: An example of biaffine scorer labeling the gap. The biaffine attention scorer only uses the forward information of front character and the backward information of character to label the gap.
|
| 158 |
+
|
| 159 |
+
<!-- image -->
|
| 160 |
+
|
| 161 |
+
For the highway connection specifications, the first connection (called Highway-I) respectively feeds the input embedding to the rear pipelines of the three directional encoders by adding into the embeddings from HiRED layer. Suppose that three front directional encoders respectively give encoding output, r f ′ , r c ′ and r b ′ . Then the corresponding three rear directional encoders will receive input as e + r f ′ , e + r c ′ and e + r b ′ . To feed the second connection (called Highway-O), we perform the same summing as the main encoder output,
|
| 162 |
+
|
| 163 |
+
<!-- formula-not-decoded -->
|
| 164 |
+
|
| 165 |
+
then let v f ′ and v b ′ as the HiRED output go through another same biaffine scorer and a decoder as that of the main encoder. The two decoder layers together give a sum loss for the entire model.
|
| 166 |
+
|
| 167 |
+
Biaffine attentin scorer makes it possible to generate a segmentation by using output of HiRED with little cost during training. With this segmentation, we add representation of characters which belong to the same word together and get a new vector, which plays a similar role as a word embedding. This vector will be fed to encoder layer behind HiRED directly. The operations in HiRED layer can also be viewed as one attention. It makes the model focus on adjacent characters which may be likely in one word.
|
| 168 |
+
|
| 169 |
+
## 3.4 Training Objective
|
| 170 |
+
|
| 171 |
+
The training target of our model is to let the biaffine attention scorer approach the the gold score vector according to the gold segmentation. We adopt cross entropy (CE) loss for training,
|
| 172 |
+
|
| 173 |
+
<!-- formula-not-decoded -->
|
| 174 |
+
|
| 175 |
+
<!-- formula-not-decoded -->
|
| 176 |
+
|
| 177 |
+
where q j i is the log-probability of the i -th gap labeled as j ∈{ 1,0 } . Here 1 indicates word boundary and 0 means not. s j i,i +1 is the biaffine score of i -th gap labeled as j . p is the ground-truth probability which can only be 0 or 1. l is the number of gaps in one input sentence.
|
| 178 |
+
|
| 179 |
+
Table 3: Statistics of SIGHAN Bakeoff 2005 datasets.
|
| 180 |
+
|
| 181 |
+
| PKU MSR Sentences 19,056 86,924 Max length (Character) 1019 581 Max length (Word) 659 338 Word Types 55,303 88,119 Words 1,109,947 2,368,391 Character Types 4,698 5,167 Characters 1,826,448 4,050,469 AS CITYU Sentences 708,953 53,019 Max length (Character) 188 350 Max length (Word) 211 85 Word Types 141,340 69,085 Words 5,449,698 1,455,629 Character Types 6,117 4,923 Characters 8,368,050 2,403,355 |
|
| 182 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 183 |
+
|
| 184 |
+
Table 4: Hyperparameters.
|
| 185 |
+
|
| 186 |
+
| Parameters dimension of hidden vector 256 number of layer 6 dimension of FF 1024 dropout 0.1 warmup 8000 number of head 4 batch size 4096 |
|
| 187 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 188 |
+
|
| 189 |
+
## 4 Experiments
|
| 190 |
+
|
| 191 |
+
## 4.1 Experimental Settings
|
| 192 |
+
|
| 193 |
+
Data Our models are trained and evaluated on benchmark datasets from SIGHAN Bakeoff 2005 (Emerson, 2005) which has four datasets, PKU, MSR, AS and CITYU. Table 3 shows the statistics of train data. F-score is to evaluate the performance.
|
| 194 |
+
|
| 195 |
+
Embedding Initialization Our model only adopts unigram features, so we only train character embeddings. On closed test, we use embeddings initialized randomly. On open test, our character embeddings are pre-trained on Chinese Wikipedia corpus by word2vec (Mikolov et al., 2013) toolkit. The corpus for pre-training is converted to simplified Chinese 1 and trivially segmented into characters.
|
| 196 |
+
|
| 197 |
+
Hyperparameters Our hyperparameter settings are in Table 4. All the settings are tuned on development sets 2 . We set the standard deviation of Gaussian function in Eq. (2) to 2. Each training batch contains sentences with at most 4096 tokens.
|
| 198 |
+
|
| 199 |
+
Optimizer To train our model, we use the Adam (Kingma and Ba, 2015) optimizer with β 1 = 0 . 9 , β 2 = 0 . 98 and ϵ = 10 -9 . The learning rate schedule is the same as (Vaswani et al., 2017):
|
| 200 |
+
|
| 201 |
+
lr = d -0 . 5 · min( step -0 . 5 , step · warmup -1 . 5 step ) where d is the dimension of embeddings, step is the step number of training and warmup step is the step number of warmup. When the number of step is smaller than the step of warmup, the learning rate increases linearly and then decreases.
|
| 202 |
+
|
| 203 |
+
Hardware and Implements Our models are trained on a single CPU (Intel i7-5960X) and an nVidia 1080 Ti GPU, in terms of an implementation using Pytorch 1.0 3 .
|
| 204 |
+
|
| 205 |
+
## 4.2 Results
|
| 206 |
+
|
| 207 |
+
Tables 5 compares recent models and ours in terms of closed test setting, showing that our model achieves new state-of-the-art and outperforms all the other models in MSR and AS. In the meantime, our model can achieve state-of-the-art efficiency.
|
| 208 |
+
|
| 209 |
+
Our models are also compared to the latest neural models in terms of open test setting in which any external resources, especially pre-trained embeddings or language models are allowedly used. Table 6 shows that our models get comparable results in AS and MSR though unremarkable ones in CITYU and PKU.
|
| 210 |
+
|
| 211 |
+
However, it is well known that comparing models accurately is hard for open test setting. Though external strengths like pre-trained embeddings or models can indeed improve the performance, it is difficult to determine which factor exactly makes such a contribution, the model itself, the resource or the better using of the resource. In terms of closed test setting, that is also the reason why this work keeps focusing on improvement of the model design itself.
|
| 212 |
+
|
| 213 |
+
1 OpenCC is used to transfer data from traditional Chinese to simplified Chinese, available at https://github.com/BYVoid/OpenCC.
|
| 214 |
+
|
| 215 |
+
2 Following conventions, the last 10% sentences of training corpus are used as development set.
|
| 216 |
+
|
| 217 |
+
3 Code is available at: https://github.com/ akibcmi/SAMS
|
| 218 |
+
|
| 219 |
+
Table 5: Results on SIGHAN Bakeoff datasets in closed test. - indicates there is no reported result in the corresponding paper. (Tr.: Training).
|
| 220 |
+
|
| 221 |
+
| Models PKU MSR AS CITYU F 1 Tr. (hours) Test (sec.) F 1 Tr. (hours) Test (sec.) F 1 Tr. (hours) Test (sec.) F 1 Tr. (hours) Test (sec.) (Chen et al., 2015) 95.7 58 105 96.4 117 120 - - - - - - (Cai and Zhao, 2016) 95.2 48 95 96.4 96 105 - - - - - - (Cai et al., 2017) 95.4 3 25 97.0 6 30 95.2 - - 95.4 - - (Zhou et al., 2017) 95.0 - - 97.2 - - - - - - - - (Ma et al., 2018) 95.4 - - 97.5 - - 95.5 - - 95.7 - - (Wang et al., 2019a) 95.7 - - 97.4 - - 95.6 - - 95.9 - - Our results 95.5 33 4 97.6 15 4 95.7 67 10 95.4 17 1.5 |
|
| 222 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 223 |
+
|
| 224 |
+
Table 6: F1 scores in open test.
|
| 225 |
+
|
| 226 |
+
| PKU MSR AS CITYU (Cai et al., 2017) 95.8 97.1 95.3 95.6 (Chen et al., 2017) 94.3 96.0 94.6 95.6 (Wang and Xu, 2017) 95.7 97.3 - - (Zhou et al., 2017) 96.0 97.8 - - (Ma et al., 2018) 96.1 98.1 96.2 97.2 (Wang et al., 2019a) 96.1 97.5 - - (Huang et al., 2019) 96.6 97.9 96.6 97.6 Our Method 95.5 97.7 95.7 96.4 |
|
| 227 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 228 |
+
|
| 229 |
+
Compared with other LSTM models, our model performs better in AS and MSR than in CITYU and PKU. We attribute the performance difference to the impact of dataset sizes. Namely, the larger size is, the better model performs. For small corpus, the model tends to be overfitting.
|
| 230 |
+
|
| 231 |
+
Table 5 also shows the decoding time in different datasets. Our model finishes the segmentation with the least decoding time in all four datasets, thanks to the architecture of model which only takes attention mechanism as basic block, only adopts unigram features and a greedy decoding strategy from the very beginning.
|
| 232 |
+
|
| 233 |
+
## 4.3 Ablation Studies
|
| 234 |
+
|
| 235 |
+
This subsection presents ablation studies on MSR and PKU datasets to verify the benefits of each individual component in our model 4 .
|
| 236 |
+
|
| 237 |
+
4 Following (Cai et al., 2017), we show the results on the respective test set for either dataset, as SIGHAN Bakeoff did not provide official development sets.
|
| 238 |
+
|
| 239 |
+
Gaussian-masked Directional Transformer. Table 7 gives the result of model with different Gaussian-masked directional self-attention. The third column and the fifth column are the difference of performance between GD-Transformer and other models. The results show that our full model GD-Transformer significantly outperforms the original Transformer by a large performance margin. Removing either Gaussian mask or directional mask will put negative impact over the performance of our model, which shows that both masks are indispensably necessary for our model performance.
|
| 240 |
+
|
| 241 |
+
Table 7: F1 scores on models removing different components from GD-Transformer.
|
| 242 |
+
|
| 243 |
+
| PKU MSR GD-Transformer 95.4 97.6 -Gaussian mask 94.6 -0.8 97.1 -0.5 -Directional mask 95.1 -0.3 97.4 -0.2 Transformer 94.1 -1.3 96.5 -1.1 |
|
| 244 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 245 |
+
|
| 246 |
+
Highway Connections. Table 8 gives the results of our model respectively removing the highway connections and the related HiRED layer part, which shows that each highway takes its contribution to the overall performance. However, the comparison shows that introducing all the components makes our model training much faster.
|
| 247 |
+
|
| 248 |
+
Directional Encoder. Table 9 gives the results of our models respectively removing the forward, center and backward encoders, which impacts performance of our model and shows that directional encoder and undirectional encoders are all indispensable for our model. The third column and the fifth column are the difference of performance between our full model and our models removing one encoder.
|
| 249 |
+
|
| 250 |
+
Table 8: F1 scores and training time on models related to highway connections and HiRED layer.
|
| 251 |
+
|
| 252 |
+
| Models PKU MSR F 1 Training (hours) F 1 Training (hours) Our full model 95.5 33 97.6 15 -Highway-I 95.2 60 97.5 96 -Highway-O 95.3 45 97.4 102 -both highways 95.1 80 97.5 105 |
|
| 253 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 254 |
+
|
| 255 |
+
Table 9: F1 scores of results on model removing different encoder from model.
|
| 256 |
+
|
| 257 |
+
| PKU MSR Our full model 95.5 97.6 -Forward encoder 95.3 -0.2 97.4 -0.1 -Center encoder 95.3 -0.2 97.5 -0.1 -Backward encoder 95.4 -0.1 97.5 -0.2 |
|
| 258 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 259 |
+
|
| 260 |
+
## 5 Conclusion
|
| 261 |
+
|
| 262 |
+
For Chinese word segmentation, upholding the belief that a better representation is all we need and thus taking a greedy decoder for fast segmentation as the basis, we only focus on the encoder design and propose an attention mechanism only based CWS model. Our model uses the proposed GDTransformer encoder to take sequence input and biaffine attention scorer to directly predict the word boundaries. To improve the ability of capturing the localness and directional information, Gaussianmasked directional multi-head attention in the GDTransformer replaces the standard self-attention in the original Transformer. With powerful enough encoding ability, our model only needs unigram features for scoring instead of various n -gram features in previous work. Our model is evaluated on standard benchmark SIGHAN Bakeoff datasets, which shows not only our model performs segmentation faster than any previous models but also gives new higher or comparable segmentation performance against previous state-of-the-art models.
|
| 263 |
+
|
| 264 |
+
## References
|
| 265 |
+
|
| 266 |
+
- Galen Andrew. 2006. A hybrid Markov/semi-Markov conditional random field for sequence segmentation. In Proceedings of the 2006 Conference on Empirical Methods in Natural Language Processing , pages 465-472, Sydney, Australia. Association for Computational Linguistics.
|
| 267 |
+
- Deng Cai and Hai Zhao. 2016. Neural word segmentation learning for Chinese. In Proceedings of the
|
| 268 |
+
|
| 269 |
+
54th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers) , pages 409-420, Berlin, Germany. Association for Computational Linguistics.
|
| 270 |
+
|
| 271 |
+
- Deng Cai, Hai Zhao, Zhisong Zhang, Yuan Xin, Yongjian Wu, and Feiyue Huang. 2017. Fast and accurate neural word segmentation for Chinese. In Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics (Volume 2: Short Papers) , pages 608-615, Vancouver, Canada. Association for Computational Linguistics.
|
| 272 |
+
- Jiaxun Cai, Shexia He, Zuchao Li, and Hai Zhao. 2018. A full end-to-end semantic role labeler, syntacticagnostic over syntactic-aware? In Proceedings of the 27th International Conference on Computational Linguistics , pages 2753-2765, Santa Fe, New Mexico, USA. Association for Computational Linguistics.
|
| 273 |
+
- Xinchi Chen, Xipeng Qiu, Chenxi Zhu, Pengfei Liu, and Xuanjing Huang. 2015. Long short-term memory neural networks for Chinese word segmentation. In Proceedings of the 2015 Conference on Empirical Methods in Natural Language Processing , pages 1197-1206, Lisbon, Portugal. Association for Computational Linguistics.
|
| 274 |
+
- Xinchi Chen, Zhan Shi, Xipeng Qiu, and Xuanjing Huang. 2017. Adversarial multi-criteria learning for Chinese word segmentation. In Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers) , pages 1193-1203, Vancouver, Canada. Association for Computational Linguistics.
|
| 275 |
+
- Timothy Dozat and Christopher D. Manning. 2017. Deep biaffine attention for neural dependency parsing. In 5th International Conference on Learning Representations, ICLR 2017, Toulon, France, April 24-26, 2017, Conference Track Proceedings .
|
| 276 |
+
- Thomas Emerson. 2005. The second international Chinese word segmentation bakeoff. In Proceedings of the Fourth SIGHAN Workshop on Chinese Language Processing .
|
| 277 |
+
- Shexia He, Zuchao Li, and Hai Zhao. 2019. Syntaxaware multilingual semantic role labeling. In Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP) , pages 5350-5359, Hong Kong, China. Association for Computational Linguistics.
|
| 278 |
+
- Weipeng Huang, Xingyi Cheng, Kunlong Chen, Taifeng Wang, and Wei Chu. 2019. Toward Fast and Accurate Neural Chinese Word Segmentation with Multi-Criteria Learning. CoRR , abs/1903.04190.
|
| 279 |
+
- [Jaeyoung Kim, Mostafa El-Khamy, and Jungwon Lee. 2020. T-GSA: transformer with gaussianweighted self-attention for speech enhancement. In](https://doi.org/10.1109/ICASSP40776.2020.9053591)
|
| 280 |
+
- 2020 IEEE International Conference on Acoustics, Speech and Signal Processing, ICASSP 2020, Barcelona, Spain, May 4-8, 2020 , pages 6649-6653. IEEE.
|
| 281 |
+
- Diederik P. Kingma and Jimmy Ba. 2015. Adam: A method for stochastic optimization. In 3rd International Conference on Learning Representations, ICLR 2015, San Diego, CA, USA, May 7-9, 2015, Conference Track Proceedings .
|
| 282 |
+
- Zuchao Li, Shexia He, Zhuosheng Zhang, and Hai Zhao. 2018. Joint learning of POS and dependencies for multilingual Universal Dependency parsing. In Proceedings of the CoNLL 2018 Shared Task: Multilingual Parsing from Raw Text to Universal Dependencies , pages 65-73, Brussels, Belgium. Association for Computational Linguistics.
|
| 283 |
+
- Jin Kiat Low, Hwee Tou Ng, and Wenyuan Guo. 2005. A maximum entropy approach to Chinese word segmentation. In Proceedings of the Fourth SIGHAN Workshop on Chinese Language Processing .
|
| 284 |
+
- Chen Lyu, Yue Zhang, and Donghong Ji. 2016. Joint word segmentation, pos-tagging and syntactic chunking. In Proceedings of the Thirtieth AAAI Conference on Artificial Intelligence, February 12-17, 2016, Phoenix, Arizona, USA. , pages 3007-3014.
|
| 285 |
+
- Ji Ma, Kuzman Ganchev, and David Weiss. 2018. State-of-the-art Chinese word segmentation with biLSTMs. In Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing , pages 4902-4908, Brussels, Belgium. Association for Computational Linguistics.
|
| 286 |
+
- Tomas Mikolov, Kai Chen, Greg Corrado, and Jeffrey Dean. 2013. Efficient estimation of word representations in vector space. In 1st International Conference on Learning Representations, ICLR 2013, Scottsdale, Arizona, USA, May 2-4, 2013, Workshop Track Proceedings .
|
| 287 |
+
- Hwee Tou Ng and Jin Kiat Low. 2004. Chinese part-ofspeech tagging: One-at-a-time or all-at-once? wordbased or character-based? In Proceedings of the 2004 Conference on Empirical Methods in Natural Language Processing , pages 277-284, Barcelona, Spain. Association for Computational Linguistics.
|
| 288 |
+
- Wenzhe Pei, Tao Ge, and Baobao Chang. 2014. Maxmargin tensor neural network for Chinese word segmentation. In Proceedings of the 52nd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers) , pages 293-303, Baltimore, Maryland. Association for Computational Linguistics.
|
| 289 |
+
- Fuchun Peng, Fangfang Feng, and Andrew McCallum. 2004. Chinese segmentation and new word detection using conditional random fields. In COLING 2004: Proceedings of the 20th International Conference on Computational Linguistics , pages 562-568, Geneva, Switzerland. COLING.
|
| 290 |
+
- Peter Shaw, Jakob Uszkoreit, and Ashish Vaswani. 2018. Self-attention with relative position representations. In Proceedings of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 2 (Short Papers) , pages 464-468, New Orleans, Louisiana. Association for Computational Linguistics.
|
| 291 |
+
- Richard Sproat and Thomas Emerson. 2003. The first international Chinese word segmentation Bakeoff. In The Second SIGHAN Workshop on Chinese Language Processing , page 133-143.
|
| 292 |
+
- Rupesh Kumar Srivastava, Klaus Greff, and J¨ urgen Schmidhuber. 2015. Highway networks. arXiv preprint arXiv:1505.00387 .
|
| 293 |
+
- Xu Sun, Yaozhong Zhang, Takuya Matsuzaki, Yoshimasa Tsuruoka, and Jun'ichi Tsujii. 2009. A discriminative latent variable Chinese segmenter with hybrid word/character information. In Proceedings of Human Language Technologies: The 2009 Annual Conference of the North American Chapter of the Association for Computational Linguistics , pages 56-64, Boulder, Colorado. Association for Computational Linguistics.
|
| 294 |
+
- Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser, and Illia Polosukhin. 2017. Attention is all you need. In Advances in Neural Information Processing Systems 30: Annual Conference on Neural Information Processing Systems 2017, 4-9 December 2017, Long Beach, CA, USA , pages 5998-6008.
|
| 295 |
+
- Chunqi Wang and Bo Xu. 2017. Convolutional neural network with word embeddings for Chinese word segmentation. In Proceedings of the Eighth International Joint Conference on Natural Language Processing (Volume 1: Long Papers) , pages 163-172, Taipei, Taiwan. Asian Federation of Natural Language Processing.
|
| 296 |
+
- Xiaobin Wang, Deng Cai, Linlin Li, Guangwei Xu, Hai Zhao, and Luo Si. 2019a. Unsupervised learning helps supervised neural word segmentation. In The Thirty-Third AAAI Conference on Artificial Intelligence, AAAI 2019, The Thirty-First Innovative Applications of Artificial Intelligence Conference, IAAI 2019, The Ninth AAAI Symposium on Educational Advances in Artificial Intelligence, EAAI 2019, Honolulu, Hawaii, USA, January 27 - February 1, 2019. , pages 7200-7207.
|
| 297 |
+
- Xiaobin Wang, Deng Cai, Linlin Li, Guangwei Xu, Hai Zhao, and Luo Si. 2019b. Unsupervised learning helps supervised neural word segmentation. In AAAI .
|
| 298 |
+
- Nianwen Xue. 2003. Chinese word segmentation as character tagging. In International Journal of Computational Linguistics & Chinese Language Processing, Volume 8, Number 1, February 2003: Special Issue on Word Formation and Chinese Language Processing , pages 29-48.
|
| 299 |
+
- Baosong Yang, Zhaopeng Tu, Derek F. Wong, Fandong Meng, Lidia S. Chao, and Tong Zhang. 2018. Modeling localness for self-attention networks. In Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing , pages 44494458, Brussels, Belgium. Association for Computational Linguistics.
|
| 300 |
+
- Jie Yang, Yue Zhang, and Fei Dong. 2017. Neural word segmentation with rich pretraining. In Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers) , pages 839-849, Vancouver, Canada. Association for Computational Linguistics.
|
| 301 |
+
- Meishan Zhang, Guohong Fu, and Nan Yu. 2017. Segmenting Chinese microtext: Joint informal-word detection and segmentation with neural networks. In Proceedings of the Twenty-Sixth International Joint Conference on Artificial Intelligence, IJCAI 2017, Melbourne, Australia, August 19-25, 2017 , pages 4228-4234.
|
| 302 |
+
- Yue Zhang and Stephen Clark. 2007. Chinese segmentation with a word-based perceptron algorithm. In Proceedings of the 45th Annual Meeting of the Association of Computational Linguistics , pages 840847, Prague, Czech Republic. Association for Computational Linguistics.
|
| 303 |
+
- Zhuosheng Zhang, Yuwei Wu, Hai Zhao, Zuchao Li, Shuailiang Zhang, Xi Zhou, and Xiang Zhou. 2020a. Semantics-aware BERT for language understanding. In The Thirty-Fourth AAAI Conference on Artificial Intelligence, AAAI 2020, The Thirty-Second Innovative Applications of Artificial Intelligence Conference, IAAI 2020, The Tenth AAAI Symposium on Educational Advances in Artificial Intelligence, EAAI 2020, New York, NY, USA, February 7-12, 2020 , pages 9628-9635. AAAI Press.
|
| 304 |
+
- Zhuosheng Zhang, Yuwei Wu, Junru Zhou, Sufeng Duan, Hai Zhao, and Rui Wang. 2020b. Sg-net: Syntax-guided machine reading comprehension. In The Thirty-Fourth AAAI Conference on Artificial Intelligence, AAAI 2020, The Thirty-Second Innovative Applications of Artificial Intelligence Conference, IAAI 2020, The Tenth AAAI Symposium on Educational Advances in Artificial Intelligence, EAAI 2020, New York, NY, USA, February 7-12, 2020 , pages 9636-9643. AAAI Press.
|
| 305 |
+
- Hai Zhao, Deng Cai, Huang Changning, and Chunyu Kit. 2017. Chinese word segmentation, another decade review (2007-2017). In The Frontier of Empirical and Corpus Linguistics . China Social Sciences Press.
|
| 306 |
+
- Hai Zhao, Chang-Ning Huang, and Mu Li. 2006a. An improved Chinese word segmentation system with conditional random field. In Proceedings of the Fifth SIGHAN Workshop on Chinese Language Processing , pages 162-165, Sydney, Australia. Association for Computational Linguistics.
|
| 307 |
+
- Hai Zhao, Chang-Ning Huang, Mu Li, and Bao-Liang Lu. 2006b. Effective tag set selection in Chinese word segmentation via conditional random field modeling. In Proceedings of the 20th Pacific Asia Conference on Language, Information and Computation , pages 87-94, Huazhong Normal University, Wuhan, China. Tsinghua University Press.
|
| 308 |
+
- Hai Zhao and Chunyu Kit. 2007. Incorporating global information into supervised learning for Chinese word segmentation. In In 10th Conference of the Pacific Association for Computational Linguistics , pages 66-74.
|
| 309 |
+
- Xiaoqing Zheng, Hanyang Chen, and Tianyu Xu. 2013. Deep learning for Chinese word segmentation and POS tagging. In Proceedings of the 2013 Conference on Empirical Methods in Natural Language Processing , pages 647-657, Seattle, Washington, USA. Association for Computational Linguistics.
|
| 310 |
+
- Hao Zhou, Zhenting Yu, Yue Zhang, Shujian Huang, Xinyu Dai, and Jiajun Chen. 2017. Word-context character embeddings for Chinese word segmentation. In Proceedings of the 2017 Conference on Empirical Methods in Natural Language Processing , pages 760-766, Copenhagen, Denmark. Association for Computational Linguistics.
|
| 311 |
+
- Junru Zhou and Hai Zhao. 2019. Head-Driven Phrase Structure Grammar parsing on Penn Treebank. In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics , pages 2396-2408, Florence, Italy. Association for Computational Linguistics.
|
text-versions/attention-markdown/1911.03875_Rethinking SelfAttention Towards Interpr.md
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1911.03875 Rethinking Selfattention Towards Interpr
|
| 2 |
+
|
| 3 |
+
## Rethinking Self-Attention: Towards Interpretability in Neural Parsing
|
| 4 |
+
|
| 5 |
+
Khalil Mrini 1 , Franck Dernoncourt 2 , Quan Tran 2 , Trung Bui 2 , Walter Chang 2 , and Ndapa Nakashole 1
|
| 6 |
+
|
| 7 |
+
1 University of California, San Diego, La Jolla, CA 92093
|
| 8 |
+
|
| 9 |
+
khalil@ucsd.edu, nnakashole@eng.ucsd.edu
|
| 10 |
+
|
| 11 |
+
2 Adobe Research, San Jose, CA 95110
|
| 12 |
+
|
| 13 |
+
{ franck.dernoncourt, qtran, bui, wachang } @adobe.com
|
| 14 |
+
|
| 15 |
+
## Abstract
|
| 16 |
+
|
| 17 |
+
Attention mechanisms have improved the performance of NLP tasks while allowing models to remain explainable. Self-attention is currently widely used, however interpretability is difficult due to the numerous attention distributions. Recent work has shown that model representations can benefit from label-specific information, while facilitating interpretation of predictions. We introduce the Label Attention Layer: a new form of self-attention where attention heads represent labels. We test our novel layer by running constituency and dependency parsing experiments and show our new model obtains new state-of-the-art results for both tasks on both the Penn Treebank (PTB) and Chinese Treebank. Additionally, our model requires fewer self-attention layers compared to existing work. Finally, we find that the Label Attention heads learn relations between syntactic categories and show pathways to analyze errors.
|
| 18 |
+
|
| 19 |
+
## 1 Introduction
|
| 20 |
+
|
| 21 |
+
Attention mechanisms (Bahdanau et al., 2014; Luong et al., 2015) provide arguably explainable attention distributions that can help to interpret predictions. For example, for their machine translation predictions, Bahdanau et al. (2014) show a heat map of attention weights from source language words to target language words. Similarly, in transformer architectures (Vaswani et al., 2017), a selfattention head produces attention distributions from the input words to the same input words, as shown in the second row on the right side of Figure 1. However, self-attention mechanisms have multiple heads, making the combined outputs difficult to interpret.
|
| 22 |
+
|
| 23 |
+
Recent work in multi-label text classification (Xiao et al., 2019) and sequence labeling (Cui and Zhang, 2019) shows the efficiency and interpretability of label-specific representations. We introduce the Label Attention Layer: a modified version of self-attention, where each classification label corresponds to one or more attention heads. We project the output at the attention head level, rather than after aggregating all outputs, to preserve the source of head-specific information, thus allowing us to match labels to heads.
|
| 24 |
+
|
| 25 |
+
Figure 1: Comparison of the attention head architectures of our proposed Label Attention Layer and a SelfAttention Layer (Vaswani et al., 2017). The matrix X represents the input sentence ' Select the person '.
|
| 26 |
+
|
| 27 |
+
<!-- image -->
|
| 28 |
+
|
| 29 |
+
To test our proposed Label Attention Layer, we build upon the parser of Zhou and Zhao (2019) and establish a new state of the art for both constituency and dependency parsing, in both English and Chinese. We also release our pre-trained parsers, as well as our code to encourage experiments with the Label Attention Layer 1 .
|
| 30 |
+
|
| 31 |
+
## 2 Label Attention Layer
|
| 32 |
+
|
| 33 |
+
The self-attention mechanism of Vaswani et al. (2017) propagates information between the words of a sentence. Each resulting word representation
|
| 34 |
+
|
| 35 |
+
[1 Available at: GitHub.com/KhalilMrini/LAL-Parser](http://www.github.com/KhalilMrini/LAL-Parser)
|
| 36 |
+
|
| 37 |
+
## Example Input
|
| 38 |
+
|
| 39 |
+
The Label Attention Layer takes word vectors as input (red-contour matrix). In the example sentence, start and end symbols are omitted.
|
| 40 |
+
|
| 41 |
+
<!-- image -->
|
| 42 |
+
|
| 43 |
+
Figure 2: The architecture of the top of our proposed Label Attention Layer. In this figure, the example input sentence is ' Select the person driving '.
|
| 44 |
+
|
| 45 |
+
<!-- image -->
|
| 46 |
+
|
| 47 |
+
contains its own attention-weighted view of the sentence. We hypothesize that a word representation can be enhanced by including each label's attention-weighted view of the sentence, on top of the information obtained from self-attention.
|
| 48 |
+
|
| 49 |
+
The Label Attention Layer (LAL) is a novel, modified form of self-attention, where only one query vector is needed per attention head. Each classification label is represented by one or more attention heads, and this allows the model to learn label-specific views of the input sentence. Figure 1 shows a high-level comparison between our Label Attention Layer and self-attention.
|
| 50 |
+
|
| 51 |
+
We explain the architecture and intuition behind our proposed Label Attention Layer through the example application of parsing.
|
| 52 |
+
|
| 53 |
+
Figure 2 shows one of the main differences between our Label Attention mechanism and selfattention: the absence of the Query matrix W Q . Instead, we have a learned matrix Q of query vectors representing each head. More formally, for the attention head i and an input matrix X of word vectors, we compute the corresponding attention weights vector a i as follows:
|
| 54 |
+
|
| 55 |
+
<!-- formula-not-decoded -->
|
| 56 |
+
|
| 57 |
+
where d is the dimension of query and key vectors, K i is the matrix of key vectors. Given a learned head-specific key matrix W K i , we compute K i as:
|
| 58 |
+
|
| 59 |
+
<!-- formula-not-decoded -->
|
| 60 |
+
|
| 61 |
+
Each attention head in our Label Attention layer has an attention vector , instead of an attention matrix as in self-attention. Consequently, we do not obtain a matrix of vectors, but a single vector that contains head-specific context information. This context vector corresponds to the green vector in Figure 3. We compute the context vector c i of head i as follows:
|
| 62 |
+
|
| 63 |
+
<!-- formula-not-decoded -->
|
| 64 |
+
|
| 65 |
+
where a i is the vector of attention weights in Equation 1, and V i is the matrix of value vectors. Given a learned head-specific value matrix W V i , we compute V i as:
|
| 66 |
+
|
| 67 |
+
<!-- formula-not-decoded -->
|
| 68 |
+
|
| 69 |
+
The context vector gets added to each individual input vector - making for one residual connection per head, rather one for all heads, as in the yellow box in Figure 3. We project the resulting matrix of word vectors to a lower dimension before normalizing. We then distribute the vectors computed by each label attention head, as shown in Figure 4.
|
| 70 |
+
|
| 71 |
+
Figure 3: The Value vector computations in our proposed Label Attention Layer.
|
| 72 |
+
|
| 73 |
+
<!-- image -->
|
| 74 |
+
|
| 75 |
+
We chose to assign as many attention heads to the Label Attention Layer as there are classification labels. As parsing labels (syntactic categories) are related, we did not apply an orthogonality loss to force the heads to learn separate information. We therefore expect an overlap when we match labels to heads. The values from each head are identifiable within the final word representation, as shown in the color-coded vectors in Figure 4.
|
| 76 |
+
|
| 77 |
+
The activation functions of the position-wise feed-forward layer make it difficult to follow the path of the contributions. Therefore we can remove the position-wise feed-forward layer, and compute the contributions from each label. We provide an example in Figure 6, where the contributions are computed using normalization and averaging. In this case, we are computing the contributions of each head to the span vector. The span representation for ' the person ' is computed following the method of Gaddy et al. (2018) and Kitaev and Klein (2018). However, forward and backward represen- tations are not formed by splitting the entire word vector at the middle, but rather by splitting each head-specific word vector at the middle.
|
| 78 |
+
|
| 79 |
+
In the example in Figure 6, we show averaging as one way of computing contributions, other functions, such as softmax, can be used. Another way of interpreting predictions is to look at the head-toword attention distributions, which are the output vectors in the computation in Figure 2.
|
| 80 |
+
|
| 81 |
+
## 3 Syntactic Parsing Model
|
| 82 |
+
|
| 83 |
+
## 3.1 Encoder
|
| 84 |
+
|
| 85 |
+
Our parser is an encoder-decoder model. The encoder has self-attention layers (Vaswani et al., 2017), preceding the Label Attention Layer. We follow the attention partition of Kitaev and Klein (2018), who show that separating content embeddings from position ones improves performance.
|
| 86 |
+
|
| 87 |
+
Sentences are pre-processed following Zhou and Zhao (2019). Trees are represented using a simplified Head-driven Phrase Structure Grammar (HPSG) (Pollard and Sag, 1994). In Zhou and Zhao (2019), two kinds of span representations are proposed: the division span and the joint span. We choose the joint span representation as it is the best-performing one in their experiments. Figure 5 shows how the example sentence in Figure 2 is represented.
|
| 88 |
+
|
| 89 |
+
The token representations for our model are a concatenation of content and position embeddings. The content embeddings are a sum of word and part-of-speech embeddings.
|
| 90 |
+
|
| 91 |
+
## 3.2 Constituency Parsing
|
| 92 |
+
|
| 93 |
+
For constituency parsing, span representations follow the definition of Gaddy et al. (2018) and Kitaev and Klein (2018). For a span starting at the i -th word and ending at the j -th word, the corresponding span vector s ij is computed as:
|
| 94 |
+
|
| 95 |
+
<!-- formula-not-decoded -->
|
| 96 |
+
|
| 97 |
+
where ← -h i and - → h i are respectively the backward and forward representation of the i -th word obtained by splitting its representation in half. An example of a span representation is shown in the middle of Figure 6.
|
| 98 |
+
|
| 99 |
+
The score vector for the span is obtained by applying a one-layer feed-forward layer:
|
| 100 |
+
|
| 101 |
+
<!-- formula-not-decoded -->
|
| 102 |
+
|
| 103 |
+
Figure 4: Redistribution of the head-specific word representations to form word vectors by concatenation. We use different colors for each label attention head. The colors show where the head outputs go in the word representations. We do not use colors for the vectors resulting from the position-wise feed-forward layer, as the head-specific information moved.
|
| 104 |
+
|
| 105 |
+
<!-- image -->
|
| 106 |
+
|
| 107 |
+
Figure 5: Parsing representations of the example sentence in Figure 2.
|
| 108 |
+
|
| 109 |
+
<!-- image -->
|
| 110 |
+
|
| 111 |
+
where LN is Layer Normalization, and W 1 , W 2 , b 1 and b 2 are learned parameters. For the l -th syntactic category, the corresponding score s ( i, j, l ) is then the l -th value in the S ( i, j ) vector.
|
| 112 |
+
|
| 113 |
+
Consequently, the score of a constituency parse tree T is the sum of all of the scores of its spans and their syntactic categories:
|
| 114 |
+
|
| 115 |
+
<!-- formula-not-decoded -->
|
| 116 |
+
|
| 117 |
+
We then use a CKY-style algorithm (Stern et al., 2017; Gaddy et al., 2018) to find the highest scoring tree ˆ T . The model is trained to find the correct parse tree T ∗ , such that for all trees T , the following margin constraint is satisfied:
|
| 118 |
+
|
| 119 |
+
<!-- formula-not-decoded -->
|
| 120 |
+
|
| 121 |
+
where ∆ is the Hamming loss on labeled spans. The corresponding loss function is the hinge loss:
|
| 122 |
+
|
| 123 |
+
<!-- formula-not-decoded -->
|
| 124 |
+
|
| 125 |
+
## 3.3 Dependency Parsing
|
| 126 |
+
|
| 127 |
+
We use the biaffine attention mechanism (Dozat and Manning, 2016) to compute a probability distribution for the dependency head of each word. The child-parent score α ij for the j -th word to be the head of the i -th word is:
|
| 128 |
+
|
| 129 |
+
<!-- formula-not-decoded -->
|
| 130 |
+
|
| 131 |
+
where h ( d ) i is the dependent representation of the i -th word obtained by putting its representation h i through a one-layer perceptron. Likewise, h ( h ) j is the head representation of the j -th word obtained by putting its representation h j through a separate one-layer perceptron. The matrices W , U and V are learned parameters.
|
| 132 |
+
|
| 133 |
+
The model trains on dependency parsing by minimizing the negative likelihood of the correct dependency tree. The loss function is cross-entropy:
|
| 134 |
+
|
| 135 |
+
<!-- formula-not-decoded -->
|
| 136 |
+
|
| 137 |
+
where h i is the correct head for dependent d i , P ( h i | d i ) is the probability that h i is the head of d i , and P ( l i | d i , h i ) is the probability of the correct dependency label l i for the child-parent pair ( d i , h i ) .
|
| 138 |
+
|
| 139 |
+
## Computing Head Contributions
|
| 140 |
+
|
| 141 |
+
Figure 6: If we remove the position-wise feed-forward layer, we can compute the contributions from each label attention head to the span representation, and thus interpret head contributions. This illustrative example follows the label color scheme in Figure 4.
|
| 142 |
+
|
| 143 |
+
<!-- image -->
|
| 144 |
+
|
| 145 |
+
## 3.4 Decoder
|
| 146 |
+
|
| 147 |
+
The model jointly trains on constituency and dependency parsing by minimizing the sum of the constituency and dependency losses:
|
| 148 |
+
|
| 149 |
+
<!-- formula-not-decoded -->
|
| 150 |
+
|
| 151 |
+
The decoder is a CKY-style (Kasami, 1966; Younger, 1967; Cocke, 1969; Stern et al., 2017) algorithm, modified by Zhou and Zhao (2019) to include dependency scores.
|
| 152 |
+
|
| 153 |
+
## 4 Experiments
|
| 154 |
+
|
| 155 |
+
We evaluate our model on the English Penn Treebank (PTB) (Marcus et al., 1993) and on the Chinese Treebank (CTB) (Xue et al., 2005). We use the Stanford tagger (Toutanova et al., 2003) to predict part-of-speech tags and follow standard data splits.
|
| 156 |
+
|
| 157 |
+
Following standard practice, we use the EVALB algorithm (Sekine and Collins, 1997) for constituency parsing, and report results without punctuation for dependency parsing.
|
| 158 |
+
|
| 159 |
+
## 4.1 Setup
|
| 160 |
+
|
| 161 |
+
In our English-language experiments, the Label Attention Layer has 112 heads: one per syntactic category. However, this is an experimental choice, as the model is not designed to have a one-on-one correspondence between attention heads and syntactic categories. The Chinese Treebank is a smaller dataset, and therefore we use 64 heads in Chineselanguage experiments, even though the number of Chinese syntactic categories is much higher. For both languages, the query, key and value vectors, as well as the output vectors of each label attention head, have 128 dimensions, as determined through short parameter-tuning experiments. For the dependency and span scores, we use the same hyperparameters as Zhou and Zhao (2019). We use the large cased pre-trained XLNet (Yang et al., 2019) as our embedding model for our English-language experiments, and a base pre-trained BERT (Devlin et al., 2018) for Chinese.
|
| 162 |
+
|
| 163 |
+
We try English-language parsers with 2, 3, 4, 6, 8, 12 and 16 self-attention layers. Our parsers with 3 and 4 self-attention layers are tied in terms of F1 score, and sum of UAS and LAS scores. The results of our fine-tuning experiments are in the appendix. We decide to use 3 self-attention layers for all the following experiments, for lower computational complexity.
|
| 164 |
+
|
| 165 |
+
## 4.2 Ablation Study
|
| 166 |
+
|
| 167 |
+
As shown in Figure 6, we can compute the contributions from label attention heads only if there is no position-wise feed-forward layer. Residual dropout in self-attention applies to the aggregated outputs from all heads. In label attention, residual dropout applies separately to the output of each head, and therefore can cancel out parts of the head contributions. We investigate the impact of removing these two components from the LAL.
|
| 168 |
+
|
| 169 |
+
Table 1: Results on the PTB test set of the ablation study on the Position-wise Feed-forward Layer ( PFL ) and Residual Dropout ( RD ) of the Label Attention Layer.
|
| 170 |
+
|
| 171 |
+
| PFL RD Prec. Recall F1 UAS LAS Yes Yes 96.47 96.20 96.34 97.33 96.29 No Yes 96.51 96.15 96.33 97.25 96.11 Yes No 96.53 96.24 96.38 97.42 96.26 No No 96.29 96.05 96.17 97.23 96.11 |
|
| 172 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 173 |
+
|
| 174 |
+
Table 2: Results on the PTB test set of the ablation study on the Query Vectors ( QV ) and Concatenation ( Conc. ) parts of the Label Attention Layer.
|
| 175 |
+
|
| 176 |
+
| QV Conc. Prec. Recall F1 UAS LAS Yes Yes 96.53 96.24 96.38 97.42 96.26 No Yes 96.43 96.03 96.23 97.25 96.12 Yes No 96.30 96.10 96.20 97.23 96.15 No No 96.30 96.06 96.18 97.26 96.17 |
|
| 177 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 178 |
+
|
| 179 |
+
We show the results on the PTB dataset of our ablation study on Residual Dropout and Positionwise Feed-forward Layer in Table 1. We use the same residual dropout probability as Zhou and Zhao (2019). When removing the position-wise feed-forward layer and keeping residual dropout, we observe only a slight decrease in overall performance, as shown in the second row. There is therefore no significant loss in performance in exchange for the interpretability of the attention heads.
|
| 180 |
+
|
| 181 |
+
We observe an increase in performance when removing residual dropout only. This suggests that all head contributions are important for performance, and that we were likely over-regularizing.
|
| 182 |
+
|
| 183 |
+
Finally, removing both position-wise feedforward layer and residual dropout brings about a noticeable decrease in performance. We continue our experiments without residual dropout.
|
| 184 |
+
|
| 185 |
+
## 4.3 Comparison with Self-Attention
|
| 186 |
+
|
| 187 |
+
The two main architecture novelties of our proposed Label Attention Layer are the learned Query Vectors that represent labels and replace the Query Matrix in self-attention, and the Concatenation of the outputs of each attention head that replaces the Matrix Projection in self-attention.
|
| 188 |
+
|
| 189 |
+
In this subsection, we evaluate whether our proposed architecture novelties bring about perfor- mance improvements. To this end, we establish an ablation study to compare Label Attention with Self-Attention. We propose three additional model architectures based on our best parser: all models have 3 self-attention layers and a modified Label Attention Layer with 112 attention heads. The three modified Label Attention Layers are as follows: (1) Ablation of Query Vectors: the first model (left of Figure 7) has a Query Matrix like self-attention, and concatenates attention head outputs like Label Attention. (2) Ablation of Concatenation: the second model (right of Figure 7) has a Query Vector like Label Attention, and applies matrix projection to all head outputs like self-attention. (3) Ablation of Query Vectors and Concatenation: the third model (right of Figure 1) has a 112-head self-attention layer.
|
| 190 |
+
|
| 191 |
+
Figure 7: The two hybrid parser architectures for the ablation study on the Label Attention Layer's Query Vectors and Concatenation.
|
| 192 |
+
|
| 193 |
+
<!-- image -->
|
| 194 |
+
|
| 195 |
+
The results of our experiments are in Table 2. The second row shows that, even though query matrices employ more parameters and computation than query vectors, replacing query vectors by query matrices decreases performance. There is a similar decrease in performance when removing concatenation as well, as shown in the last row. This suggests that our Label Attention Layer learns meaningful representations in its query vectors, and that head-to-word attention distributions are more helpful to performance than query matrices and word-to-word attention distributions.
|
| 196 |
+
|
| 197 |
+
In self-attention, the output vector is a matrix projection of the concatenation of head outputs. In Label Attention, the head outputs do not interact through matrix projection, but are concatenated. The third and fourth rows of Table 2 show that there is a significant decrease in performance when replacing concatenation with the matrix projection. This decrease suggests that the model benefits from having one residual connection per attention head, rather than one for all attention heads, and from separating head-specific information in word representations. In particular, the last row shows that replacing our LAL with a self-attention layer with an equal number of attention heads decreases performance: the difference between the performance of the first row and the last row is due to the Label Attention Layer's architecture novelties.
|
| 198 |
+
|
| 199 |
+
Table 3: Constituency Parsing on PTB & CTB test sets.
|
| 200 |
+
|
| 201 |
+
<!-- image -->
|
| 202 |
+
|
| 203 |
+
| Model English Chinese LR LP F1 LR LP F1 Shen et al. (2018) 92.0 91.7 91.8 86.6 86.4 86.5 Fried and Klein (2018) - - 92.2 - - 87.0 Teng and Zhang (2018) 92.2 92.5 92.4 86.6 88.0 87.3 Vaswani et al. (2017) - - 92.7 - - - Dyer et al. (2016) - - 93.3 - - 84.6 Kuncoro et al. (2017) - - 93.6 - - - Charniak et al. (2016) - - 93.8 - - - Liu and Zhang (2017b) 91.3 92.1 91.7 85.9 85.2 85.5 Liu and Zhang (2017a) - - 94.2 - - 86.1 Suzuki et al. (2018) - - 94.32 - - - Takase et al. (2018) - - 94.47 - - - Fried et al. (2017) - - 94.66 - - - Kitaev and Klein (2018) 94.85 95.40 95.13 - - - Kitaev et al. (2018) 95.51 96.03 95.77 91.55 91.96 91.75 Zhou and Zhao (2019) (BERT) 95.70 95.98 95.84 92.03 92.33 92.18 Zhou and Zhao (2019) (XLNet) 96.21 96.46 96.33 - - - Our work 96.24 96.53 96.38 91.85 93.45 92.64 |
|
| 204 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 205 |
+
|
| 206 |
+
## 4.4 English and Chinese Results
|
| 207 |
+
|
| 208 |
+
Our best-performing English-language parser does not have residual dropout, but has a position-wise feed-forward layer. We train Chinese-language parsers using the same configuration. The Chinese Treebank has two data splits for the training, development and testing sets: one for Constituency (Liu and Zhang, 2017b) and one for Dependency parsing (Zhang and Clark, 2008).
|
| 209 |
+
|
| 210 |
+
Finally, we compare our results with the state of the art in constituency and dependency parsing in both English and Chinese. We show our Constituency Parsing results in Table 3, and our Dependency Parsing results in Table 4. Our LAL parser establishes new state-of-the-art results in both languages, improving significantly in dependency parsing.
|
| 211 |
+
|
| 212 |
+
Table 4: Dependency Parsing on PTB & CTB test sets.
|
| 213 |
+
|
| 214 |
+
<!-- image -->
|
| 215 |
+
|
| 216 |
+
| Model English Chinese UAS LAS UAS LAS Kuncoro et al. (2016) 94.26 92.06 88.87 87.30 Li et al. (2018) 94.11 92.08 88.78 86.23 Ma and Hovy (2017) 94.88 92.98 89.05 87.74 Dozat and Manning (2016) 95.74 94.08 89.30 88.23 Choe and Charniak (2016) 95.9 94.1 - - Ma et al. (2018) 95.87 94.19 90.59 89.29 Ji et al. (2019) 95.97 94.31 - - Fern´ andez-Gonz´ alez and G´ omez- Rodr´ ıguez (2019) 96.04 94.43 - - Kuncoro et al. (2017) 95.8 94.6 - - Clark et al. (2018) 96.61 95.02 - - Wang et al. (2018) 96.35 95.25 - - Zhou and Zhao (2019) (BERT) 97.00 95.43 91.21 89.15 Zhou and Zhao (2019) (XLNet) 97.20 95.72 - - Our work 97.42 96.26 94.56 89.28 |
|
| 217 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 218 |
+
|
| 219 |
+
## 4.5 Interpreting Head Contributions
|
| 220 |
+
|
| 221 |
+
We follow the method in Figure 6 to identify which attention heads contribute to predictions. We collect the span vectors from the Penn Treebank test set, and we use our LAL parser with no positionwise feed-forward layer for predictions.
|
| 222 |
+
|
| 223 |
+
Figure 8 displays the bar charts for the three most common syntactic categories: Noun Phrases (NP), Verb Phrases (VP) and Sentences (S). We notice several heads explain each predicted category.
|
| 224 |
+
|
| 225 |
+
We collect statistics about the top-contributing heads for each predicted category. Out of the NP spans, 44.9% get their top contribution from head 35, 13.0% from head 47, and 7.3% from head 0. The top-contributing heads for VP spans are heads 31 (61.1%), 111 (13.2%), and 71 (7.5%). As for S spans, the top-contributing heads are 52 (48.6%), 31 (22.8%), 35 (6.9%), and 111 (5.2%). We see that S spans share top-contributing heads with VP spans (heads 31 and 111), and NP spans (head 35). The similarities reflect the relations between the syntactic categories. In this case, our Label Attention Layer learned the rule S → NP VP.
|
| 226 |
+
|
| 227 |
+
Moreover, the top-contributing heads for PP spans are 35 (29.6%), 31 (26.7%), 111 (10.3%), and 47 (9.4%): they are equally split between NP spans (heads 35 and 47) and VP spans (heads 31 and 111). Here, the LAL has learned that both verb and noun phrases can contain preposition phrases.
|
| 228 |
+
|
| 229 |
+
We see that head 52 is unique to S spans. Actually, 64.7% of spans with head 52 as the highest contribution are S spans. Therefore our model has learned to represent the label S using head 52.
|
| 230 |
+
|
| 231 |
+
All of the aforementioned heads are represented in Figure 8. We see that heads that have low contributions for NP spans, peak in contribution for VP
|
| 232 |
+
|
| 233 |
+
Figure 8: Average contribution of select heads to span vectors with different predicted syntactic categories.
|
| 234 |
+
|
| 235 |
+
<!-- image -->
|
| 236 |
+
|
| 237 |
+
spans (heads 31, 71 and 111), and vice-versa (heads 0, 35 and 47). Moreover, NP spans do not share any top-contributing head with VP spans. This shows that our parser has also learned the differences between dissimilar syntactic categories.
|
| 238 |
+
|
| 239 |
+
## 4.6 Error Analysis
|
| 240 |
+
|
| 241 |
+
Head-to-Word Attention. We analyze prediction errors from the PTB test set. One example is the span ' Fed Ready to Inject Big Funds ', predicted as NP but labelled as S. We trace back the attention weights for each word, and find that, out of the 9 top-contributing heads, only 2 focus their attention on the root verb of the sentence ( Inject ), while 4 focus on a noun ( Funds ), resulting in a noun phrase prediction. We notice similar patterns in other wrongly predicted spans, suggesting that forcing the attention distribution to focus on a relevant word might correct these errors.
|
| 242 |
+
|
| 243 |
+
Top-Contributing Heads. We analyze wrongly predicted spans by their true category. Out of the 53 spans labelled as NP but not predicted as such, we still see the top-contributing head for 36 of them is either head 35 or 47, both top-contributing heads of spans predicted as NP. Likewise, for the 193 spans labelled as S but not predicted as such, the top-contributing head of 141 of them is one of the four top-contributing heads for spans predicted as S. This suggests that a stronger prediction link to the label attention heads, through a loss function for instance, may increase the performance.
|
| 244 |
+
|
| 245 |
+
## 5 Related Work
|
| 246 |
+
|
| 247 |
+
Since their introduction in Machine Translation, attention mechanisms (Bahdanau et al., 2014; Luong et al., 2015) have been extended to other tasks, such as text classification (Yang et al., 2016), natural language inference (Chen et al., 2016) and language modeling (Salton et al., 2017).
|
| 248 |
+
|
| 249 |
+
Self-attention and transformer architectures (Vaswani et al., 2017) are now the state of the art in language understanding (Devlin et al., 2018; Yang et al., 2019), extractive summarization (Liu, 2019), semantic role labeling (Strubell et al., 2018) and machine translation for low-resource languages (Rikters, 2018; Rikters et al., 2018).
|
| 250 |
+
|
| 251 |
+
While attention mechanisms can provide explanations for model predictions, Serrano and Smith (2019) challenge that assumption and find that attention weights only noisily predict overall importance with regard to the model. Jain and Wallace (2019) find that attention distributions rarely correlate with feature importance weights. However, Wiegreffe and Pinter (2019) show through alternative tests that prior work does not discredit the usefulness of attention for interpretability.
|
| 252 |
+
|
| 253 |
+
Xiao et al. (2019) introduce the Label-Specific Attention Network (LSAN) for multi-label document classification. They use label descriptions to compute attention scores for words, and follow the self-attention of Lin et al. (2017). Cui and Zhang (2019) introduce a Label Attention Inference Layer for sequence labeling, which uses the self-attention of Vaswani et al. (2017). In this case, the key and value vectors are learned label embeddings, and the query vectors are hidden vectors obtained from a Bi-LSTM encoder. Our work is unrelated to these two papers, as they were published towards the end of our project.
|
| 254 |
+
|
| 255 |
+
## 6 Conclusions
|
| 256 |
+
|
| 257 |
+
In this paper, we introduce a new form of selfattention: the Label Attention Layer. In our proposed architecture, attention heads represent labels. We incorporate our Label Attention Layer into the HPSG parser (Zhou and Zhao, 2019) and obtain new state-of-the-art results on the Penn Treebank and Chinese Treebank. In English, our results show 96.38 F1 for constituency parsing, and 97.42 UAS and 96.26 LAS for dependency parsing. In Chinese, our model achieves 92.64 F1, 94.56 UAS and 89.28 LAS.
|
| 258 |
+
|
| 259 |
+
We perform ablation studies that show the Query Vector learned by our Label Attention Layer outperform the self-attention Query Matrix. Since we have only one learned vector as query, rather than a matrix, we can significantly reduce the number of parameters per attention head. Finally, our Label Attention heads learn the relations between the syntactic categories, as we show by computing contributions from each attention head to span vectors. We show how the heads also help to analyze prediction errors, and suggest methods to correct them.
|
| 260 |
+
|
| 261 |
+
## Acknowledgements
|
| 262 |
+
|
| 263 |
+
Wethank the anonymous reviewers for their helpful and detailed comments.
|
| 264 |
+
|
| 265 |
+
## References
|
| 266 |
+
|
| 267 |
+
- Dzmitry Bahdanau, Kyunghyun Cho, and Yoshua Bengio. 2014. Neural machine translation by jointly learning to align and translate. arXiv preprint arXiv:1409.0473 .
|
| 268 |
+
- Eugene Charniak et al. 2016. Parsing as language modeling. In Proceedings of the 2016 Conference on Empirical Methods in Natural Language Processing , pages 2331-2336.
|
| 269 |
+
- Qian Chen, Xiaodan Zhu, Zhenhua Ling, Si Wei, and Hui Jiang. 2016. Enhancing and combining sequential and tree lstm for natural language inference. arXiv preprint arXiv:1609.06038 .
|
| 270 |
+
- Do Kook Choe and Eugene Charniak. 2016. Parsing as language modeling. In Proceedings of the 2016 Conference on Empirical Methods in Natural Language Processing , pages 2331-2336, Austin, Texas. Association for Computational Linguistics.
|
| 271 |
+
- Kevin Clark, Minh-Thang Luong, Christopher D Manning, and Quoc Le. 2018. Semi-supervised sequence modeling with cross-view training. In Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing , pages 19141925.
|
| 272 |
+
- John Cocke. 1969. Programming languages and their compilers: Preliminary notes.
|
| 273 |
+
- Leyang Cui and Yue Zhang. 2019. Hierarchicallyrefined label attention network for sequence labeling. In Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP) , pages 41064119.
|
| 274 |
+
- Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. 2018. Bert: Pre-training of deep bidirectional transformers for language understanding. arXiv preprint arXiv:1810.04805 .
|
| 275 |
+
- Timothy Dozat and Christopher D Manning. 2016. Deep biaffine attention for neural dependency parsing. arXiv preprint arXiv:1611.01734 .
|
| 276 |
+
- Chris Dyer, Adhiguna Kuncoro, Miguel Ballesteros, and Noah A Smith. 2016. Recurrent neural network grammars. In Proceedings of the 2016 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies , pages 199-209.
|
| 277 |
+
- Daniel Fern´ andez-Gonz´ alez and Carlos G´ omezRodr´ ıguez. 2019. Left-to-right dependency parsing with pointer networks. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers) , pages 710-716.
|
| 278 |
+
- Daniel Fried and Dan Klein. 2018. Policy gradient as a proxy for dynamic oracles in constituency parsing. In Proceedings of the 56th Annual Meeting of the Association for Computational Linguistics (Volume 2: Short Papers) , pages 469-476, Melbourne, Australia. Association for Computational Linguistics.
|
| 279 |
+
- Daniel Fried, Mitchell Stern, and Dan Klein. 2017. Improving neural parsing by disentangling model combination and reranking effects. In Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics (Volume 2: Short Papers) , pages 161-166.
|
| 280 |
+
- David Gaddy, Mitchell Stern, and Dan Klein. 2018. What's going on in neural constituency parsers? an analysis. In Proceedings of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long Papers) , pages 999-1010.
|
| 281 |
+
- Sarthak Jain and Byron C Wallace. 2019. Attention is not explanation. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers) , pages 3543-3556.
|
| 282 |
+
- Tao Ji, Yuanbin Wu, and Man Lan. 2019. Graph-based dependency parsing with graph neural networks. In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics , pages 24752485.
|
| 283 |
+
- Tadao Kasami. 1966. An efficient recognition and syntax-analysis algorithm for context-free languages. Coordinated Science Laboratory Report no. R-257 .
|
| 284 |
+
- Nikita Kitaev, Steven Cao, and Dan Klein. 2018. Multilingual constituency parsing with self-attention and pre-training. arXiv preprint arXiv:1812.11760 .
|
| 285 |
+
- Nikita Kitaev and Dan Klein. 2018. Constituency parsing with a self-attentive encoder. In Proceedings of the 56th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers) , pages 2676-2686.
|
| 286 |
+
- Adhiguna Kuncoro, Miguel Ballesteros, Lingpeng Kong, Chris Dyer, Graham Neubig, and Noah A Smith. 2017. What do recurrent neural network grammars learn about syntax? In Proceedings of the 15th Conference of the European Chapter of the Association for Computational Linguistics: Volume 1, Long Papers , pages 1249-1258.
|
| 287 |
+
- Adhiguna Kuncoro, Miguel Ballesteros, Lingpeng Kong, Chris Dyer, and Noah A. Smith. 2016. Distilling an ensemble of greedy dependency parsers into one MST parser. In Proceedings of the 2016 Conference on Empirical Methods in Natural Language Processing , pages 1744-1753, Austin, Texas. Association for Computational Linguistics.
|
| 288 |
+
- Zuchao Li, Jiaxun Cai, Shexia He, and Hai Zhao. 2018. Seq2seq dependency parsing. In Proceedings of the 27th International Conference on Computational Linguistics , pages 3203-3214, Santa Fe, New Mexico, USA. Association for Computational Linguistics.
|
| 289 |
+
- Zhouhan Lin, Minwei Feng, Cicero Nogueira dos Santos, Mo Yu, Bing Xiang, Bowen Zhou, and Yoshua Bengio. 2017. A structured self-attentive sentence embedding. arXiv preprint arXiv:1703.03130 .
|
| 290 |
+
- Jiangming Liu and Yue Zhang. 2017a. In-order transition-based constituent parsing. Transactions of the Association for Computational Linguistics , 5:413-424.
|
| 291 |
+
- Jiangming Liu and Yue Zhang. 2017b. Shift-reduce constituent parsing with neural lookahead features. Transactions of the Association for Computational Linguistics , 5:45-58.
|
| 292 |
+
- Yang Liu. 2019. Fine-tune BERT for extractive summarization. CoRR , abs/1903.10318.
|
| 293 |
+
- Thang Luong, Hieu Pham, and Christopher D Manning. 2015. Effective approaches to attention-based neural machine translation. In Proceedings of the 2015 Conference on Empirical Methods in Natural Language Processing , pages 1412-1421.
|
| 294 |
+
- Xuezhe Ma and Eduard Hovy. 2017. Neural probabilistic model for non-projective MST parsing. In Proceedings of the Eighth International Joint Conference on Natural Language Processing (Volume 1: Long Papers) , pages 59-69, Taipei, Taiwan. Asian Federation of Natural Language Processing.
|
| 295 |
+
- Xuezhe Ma, Zecong Hu, Jingzhou Liu, Nanyun Peng, Graham Neubig, and Eduard Hovy. 2018. Stackpointer networks for dependency parsing. In Proceedings of the 56th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers) , pages 1403-1414, Melbourne, Australia. Association for Computational Linguistics.
|
| 296 |
+
- Mitchell Marcus, Beatrice Santorini, and Mary Ann Marcinkiewicz. 1993. Building a large annotated corpus of english: The penn treebank.
|
| 297 |
+
- Carl Pollard and Ivan A Sag. 1994. Head-driven phrase structure grammar . University of Chicago Press.
|
| 298 |
+
- Mat¯ ıss Rikters. 2018. Impact of corpora quality on neural machine translation. arXiv preprint arXiv:1810.08392 .
|
| 299 |
+
- Mat¯ ıss Rikters, M¯ arcis Pinnis, and Rihards Kriˇ slauks. 2018. Training and adapting multilingual nmt for less-resourced and morphologically rich languages. In Proceedings of the Eleventh International Conference on Language Resources and Evaluation (LREC-2018) .
|
| 300 |
+
- Giancarlo Salton, Robert Ross, and John Kelleher. 2017. Attentive language models. In Proceedings of the Eighth International Joint Conference on Natural Language Processing (Volume 1: Long Papers) , pages 441-450.
|
| 301 |
+
- Satoshi Sekine and Michael Collins. 1997. Evalb bracket scoring program. URL: http://www. cs. nyu. edu/cs/projects/proteus/evalb .
|
| 302 |
+
- Sofia Serrano and Noah A Smith. 2019. Is attention interpretable? arXiv preprint arXiv:1906.03731 .
|
| 303 |
+
- Yikang Shen, Zhouhan Lin, Athul Paul Jacob, Alessandro Sordoni, Aaron Courville, and Yoshua Bengio. 2018. Straight to the tree: Constituency parsing with neural syntactic distance. In Proceedings of the 56th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers) , pages 1171-1180, Melbourne, Australia. Association for Computational Linguistics.
|
| 304 |
+
- Mitchell Stern, Jacob Andreas, and Dan Klein. 2017. A minimal span-based neural constituency parser. In Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers) , volume 1, pages 818-827.
|
| 305 |
+
- Emma Strubell, Patrick Verga, Daniel Andor, David Weiss, and Andrew McCallum. 2018. Linguistically-informed self-attention for semantic role labeling. arXiv preprint arXiv:1804.08199 .
|
| 306 |
+
- Jun Suzuki, Sho Takase, Hidetaka Kamigaito, Makoto Morishita, and Masaaki Nagata. 2018. An empirical study of building a strong baseline for constituency parsing. In Proceedings of the 56th Annual Meeting of the Association for Computational Linguistics (Volume 2: Short Papers) , pages 612-618.
|
| 307 |
+
- Sho Takase, Jun Suzuki, and Masaaki Nagata. 2018. Direct output connection for a high-rank language model. In Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing , pages 4599-4609.
|
| 308 |
+
- Zhiyang Teng and Yue Zhang. 2018. Two local models for neural constituent parsing. In Proceedings of the 27th International Conference on Computational Linguistics , pages 119-132, Santa Fe, New Mexico, USA. Association for Computational Linguistics.
|
| 309 |
+
- Kristina Toutanova, Dan Klein, Christopher D Manning, and Yoram Singer. 2003. Feature-rich part-ofspeech tagging with a cyclic dependency network. In Proceedings of the 2003 Conference of the North American Chapter of the Association for Computational Linguistics on Human Language TechnologyVolume 1 , pages 173-180. Association for computational Linguistics.
|
| 310 |
+
- Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin. 2017. Attention is all you need. In Advances in neural information processing systems , pages 5998-6008.
|
| 311 |
+
- Wenhui Wang, Baobao Chang, and Mairgup Mansur. 2018. Improved dependency parsing using implicit word connections learned from unlabeled data. In Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing , pages 2857-2863, Brussels, Belgium. Association for Computational Linguistics.
|
| 312 |
+
- Sarah Wiegreffe and Yuval Pinter. 2019. Attention is not not explanation. In Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLPIJCNLP) , pages 11-20.
|
| 313 |
+
- Lin Xiao, Xin Huang, Boli Chen, and Liping Jing. 2019. Label-specific document representation for multi-label text classification. In Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP) , pages 466-475.
|
| 314 |
+
- Naiwen Xue, Fei Xia, Fu-Dong Chiou, and Marta Palmer. 2005. The penn chinese treebank: Phrase structure annotation of a large corpus. Natural language engineering , 11(2):207-238.
|
| 315 |
+
- Zhilin Yang, Zihang Dai, Yiming Yang, Jaime Carbonell, Ruslan Salakhutdinov, and Quoc V Le. 2019. Xlnet: Generalized autoregressive pretraining for language understanding. arXiv preprint arXiv:1906.08237 .
|
| 316 |
+
- Zichao Yang, Diyi Yang, Chris Dyer, Xiaodong He, Alex Smola, and Eduard Hovy. 2016. Hierarchical attention networks for document classification. In Proceedings of the 2016 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies , pages 1480-1489.
|
| 317 |
+
- Daniel H Younger. 1967. Recognition and parsing of context-free languages in time n3. Information and control , 10(2):189-208.
|
| 318 |
+
- [Yue Zhang and Stephen Clark. 2008. A tale of two parsers: Investigating and combining graph-based](https://www.aclweb.org/anthology/D08-1059)
|
| 319 |
+
- and transition-based dependency parsing. In Proceedings of the 2008 Conference on Empirical Methods in Natural Language Processing , pages 562571, Honolulu, Hawaii. Association for Computational Linguistics.
|
| 320 |
+
- Junru Zhou and Hai Zhao. 2019. Head-driven phrase structure grammar parsing on penn treebank. arXiv preprint arXiv:1907.02684 .
|
| 321 |
+
|
| 322 |
+
## A Additional Experiment Results
|
| 323 |
+
|
| 324 |
+
We report experiment results for hyperparameter tuning based on the number of self-attention layers in Table 5.
|
| 325 |
+
|
| 326 |
+
Table 5: Performance on the Penn Treebank test set of our LAL parser according to the number of self-attention layers. All parsers here include the Position-wise Feed-forward Layer and Residual Dropout.
|
| 327 |
+
|
| 328 |
+
| Self-Attention Layers Precision Recall F1 UAS LAS 2 96.23 96.03 96.13 97.16 96.09 3 96.47 96.20 96.34 97.33 96.29 4 96.52 96.15 96.34 97.39 96.23 6 96.48 96.09 96.29 97.30 96.16 8 96.43 96.09 96.26 97.33 96.15 12 96.27 96.06 96.16 97.24 96.14 16 96.38 96.02 96.20 97.32 96.11 |
|
| 329 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
text-versions/attention-markdown/1912.00835_Low Rank Factorization for Compact Multi.md
ADDED
|
@@ -0,0 +1,370 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1912.00835 Low Rank Factorization For Compact Multi
|
| 2 |
+
|
| 3 |
+
## Compact Multi-Head Self-Attention for Learning Supervised Text Representations
|
| 4 |
+
|
| 5 |
+
Sneha Mehta Virginia Tech, USA
|
| 6 |
+
|
| 7 |
+
snehamehta@cs.vt.edu
|
| 8 |
+
|
| 9 |
+
## ABSTRACT
|
| 10 |
+
|
| 11 |
+
Effective representation learning from text has been an active area of research in the fields of NLP and text mining. Attention mechanisms have been at the forefront in order to learn contextual sentence representations. Current state-of-the-art approaches for many NLP tasks use large pre-trained language models such as BERT, XLNet and so on for learning representations. These models are based on the Transformer architecture that involves recurrent blocks of computation consisting of multi-head self-attention and feedforward networks. One of the major bottlenecks largely contributing to the computational complexity of the Transformer models is the self-attention layer, that is both computationally expensive and parameter intensive. In this work, we introduce a novel multi-head self-attention mechanism operating on GRUs that is shown to be computationally cheaper and more parameter efficient than self-attention mechanism proposed in Transformers for text classification tasks. The efficiency of our approach mainly stems from two optimizations; 1) we use low-rank matrix factorization of the affinity matrix to efficiently get multiple attention distributions instead of having separate parameters for each head 2) attention scores are obtained by querying a global context vector instead of densely querying all the words in the sentence. We evaluate the performance of the proposed model on tasks such as sentiment analysis from movie reviews, predicting business ratings from reviews and classifying news articles into topics. We find that the proposed approach matches or outperforms a series of strong baselines and is more parameter efficient than comparable multi-head approaches. We also perform qualitative analyses to verify that the proposed approach is interpretable and captures context-dependent word importance.
|
| 12 |
+
|
| 13 |
+
## KEYWORDS
|
| 14 |
+
|
| 15 |
+
neural networks, text classification, attention
|
| 16 |
+
|
| 17 |
+
## 1 INTRODUCTION
|
| 18 |
+
|
| 19 |
+
Learning effective language representation is important for a variety of text analysis tasks including sentiment analysis, news classification, natural language inference and question answering. Supervised learning using neural networks commonly entails learning intermediate sentence representations followed by a task specific layer. For text classification tasks; this is usually a fully connected layer followed by an N-way softmax where N is the number of classes.
|
| 20 |
+
|
| 21 |
+
Learning self-supervised language representations has made substantial progress in recent years with the introduction of new techniques for language modeling combined with deep models like ELMo [32], ULMFit [15] and more recently BERT [8] and GPT2 [33]. There has been a surge of BERT-based language models that use larger data for pretraining and different pretraining methods
|
| 22 |
+
|
| 23 |
+
Huzefa Rangwala
|
| 24 |
+
|
| 25 |
+
George Mason University, USA rangwala@cs.gmu.edu Naren Ramakrishnan Virginia Tech, USA naren@cs.vt.edu
|
| 26 |
+
|
| 27 |
+
such as XL-Net [41], RoBERTa [24] while others combine different modalities [37]. These methods have enabled transfer of learned representations via pre-training to downstream tasks. Although these models work well on a variety of tasks there are two major limitations: 1) they are computationally expensive to train 2) they usually have a large number of parameters that greatly increases the model size and memory requirements. For instance, the multilingual BERT-base cased model has 110M parameters, the small GPT-2 model has 117M parameters [33] and the RoBERTa model was trained on 160GB of data [24]. Recently, researchers have proposed 'lighter' BERT models that leverage knowledge distillation during the pre-training phase and reduce the size of the BERT model [40] or try to improve the parameter efficiency of the BERT model by optimizations at the embedding layer and by parameter sharing [21]. However, all of the above models are based on the Transformer architecture [39] the major component of which is the scaled dot-product self-attention mechanism .
|
| 28 |
+
|
| 29 |
+
This layer has a computational complexity of O ' n 2 d ' that scales quadratically with the length of the input ( n ) and linearly with the length of the model hidden size ( d ' . It is natural to see how task specific training or fine-tuning can be limiting when the training data and computational resources are scarce and sequences are long. Further, running inference on and storing such models can also be difficult in low resource scenarios such as IoT devices or low-latency use cases. Hence, supervised learning for task-specific architectures which are trained from scratch, especially where domain specific training data is available are useful. They are light-weight and easy to deploy. In this work, we propose l ow-rank f a ctorization based m ultihead a ttention mechanism (LAMA), a lean attention mechanism which is computationally cheaper and more parameter efficient than prior approaches and exceeds or matches the performance of stateof-the-art baselines including large pretrained models, with fewer parameters.
|
| 30 |
+
|
| 31 |
+
Contrary to previous approaches [12, 23] that are based on additive attention mechanism [2], LAMA is based on multiplicative attention [25] which replaced the additive attention by dot product for faster computation. We further introduce a bilinear projection while computing the dot product to capture similarities between a global context vector and each word in the sentence [25]. The function of the bilinear projection is to capture nuanced context dependent word-importance as corroborated by previous works [3]. Next, unlike previous methods we use low-rank formulation of the bilinear projection matrix based on hadarmard product [17, 42] to produce multiple attentions by querying the global context vector for each word as opposed to having a different learned vector [23] or matrix [43]. In effect, we cast score computation between a word representation and a context vector as unimodal feature fusion to a low dimensional space akin to its multimodal counterparts [22, 43]. Each dimension of this low-dimensional feature space can be considered as the contribution of the word to a different attention head. By controlling the dimension of this feature space new heads can be added or removed. Finally, we devise a mechanism to obtain context-aware supervised sentence embeddings from the obtained attention distributions for downstream classification tasks. We evaluate our model on tasks such as sentiment analysis, predicting business ratings and news classification. We show that the proposed model learns contextdependent word importance like other attention models. Moreover, the proposed model is 3 times more parameter efficient than other comparable attention models especially the encoder of a Transformer model [39]. In terms of performance, the proposed model is competitive and matches or exceeds the performance of strong baselines, attention and non-attention based. Further, we present some ancillary analyses on model efficiency and need for multiple attention heads. In summary, our results show that the proposed model can be reliably used as a leaner multi-head attention alternative for supervised text classification tasks.
|
| 32 |
+
|
| 33 |
+
The organization of the rest of the paper is as follows: the next section (§2) discusses connections with related work, followed by the description of the proposed model (§3), followed by the task descriptions and the experimental evaluation (§4). Finally, in the following sections the results are presented along with their discussion (§5), before concluding (§6).
|
| 34 |
+
|
| 35 |
+
## 2 RELATED WORK
|
| 36 |
+
|
| 37 |
+
Spearheaded by their success in neural machine translation [2, 25] attention mechanisms are now ubiquitously used in problems such as question answering [10, 13, 34], text summarization [3, 31], event extraction [27], and training large language models [8, 33]. In sequence modeling, attention mechanisms allow the decoder to learn which part of the sequence it should 'attend' to based on the input sequence and the output it has generated so far [2].
|
| 38 |
+
|
| 39 |
+
## 2.1 Self-Attention
|
| 40 |
+
|
| 41 |
+
Self-attention, sometimes called intra-attention is an attention mechanism relating different positions of a single sequence in order to compute a representation of the sequence [5]. Self-attention has been used successfully in a variety of tasks including reading comprehension, abstractive summarization, textual entailment and learning task-independent sentence representations [5, 23, 30, 31]. Traditionally, the above methods have depended on Recurrent Neural Networks(RNNs) [7, 14] to model sequential dependencies and attention mechanisms were proposed to alleviate the vanishing gradient problem by establishing shorter connections between the source and target positions. The inherently sequential nature of RNNs precludes parallelization within training examples which becomes a memory bottleneck for batching across examples. Recently Transformer model was proposed [39] that replaced the dependence on RNNs and relies completely on the self-attention mechanism. In this approach, every position attends to every other position and adjusts its embedding accordingly. However, this dense computation is quadratic in the length of the input and is resource intensive. The proposed approach on the contrary leverages RNNs for modeling sequential dependencies and uses a single global query vector for each input word. We show that our approach is computationally more efficient in comparison to encoder of the Transformer model on text classification tasks and exceeds in performance.
|
| 42 |
+
|
| 43 |
+
## 2.2 Multi-Head Attention
|
| 44 |
+
|
| 45 |
+
Models have been proposed that compute multiple attention distributions over a single sequence of words. Multi-view networks [12] use a different set of parameters for each view which leads to an increase in the number of parameters. Lin et al. [23] use the additive attention mechanism, which is a more general approach of computing attention between query and key vectors and modify it to produce multiple attentions to obtain a matrix sentence embedding. Scaled dot product attention proposed by Vaswani et. al. [39] is a direct approach and is based on dot product between the query and key vectors. This approach has been shown to be very effective in machine translation [39] and pretraining language models [8]. However to compute multiple attention heads different transformation parameters are learned for different heads leading to increased parameters. In this work, on the other hand, score between the key (context) and the query (word representation) is computed using a bilinear projection matrix followed by an approach inspired by multi-modal low rank bilinear pooling [17] to factorize the matrix into two low rank matrices to compute multiple attention distributions over words. We find that this is a more parameter efficient way of computing multiple attentions. Contrary to Guo et al. [12] and Vaswani et al. [39] we use matrix factorization to alleviate the problem of increasing parameters with increasing heads and the proposed model performs superior to their approach.
|
| 46 |
+
|
| 47 |
+
## 2.3 Low-Rank Factorization
|
| 48 |
+
|
| 49 |
+
Low-rank factorization has been a popular approach to reduce the size of the hidden layers [4, 38]. Recent work has achieved significant improvements in computational efficiency through factorization tricks [35] and conditional computation [20]. Recently, factorization was also employed at the embedding layer of large pretrained language models such as BERT [8] to reduce the model size [21]. In this work, we employ factorization for unimodal feature fusion for computing attention scores for multiple attention heads. Hadamard product formulation for matrix factorization is used to compactify the multi-head attention layer. This formulation can be viewed as low-rank bilinear pooling for unimodal features based on the corresponding idea of multimodal feature fusion [22, 43].
|
| 50 |
+
|
| 51 |
+
## 3 PROPOSED MODEL
|
| 52 |
+
|
| 53 |
+
In this section, we give an overview of the proposed model followed by a detailed description of each model component.
|
| 54 |
+
|
| 55 |
+
A document (a product review or a news article) is first tokenized and converted to a word embedding via a lookup into a pretrained embedding matrix. The embedding of each token is encoded via a bi-directional Gated Recurrent Unit [6] (bi-GRU) sentence encoder to get a contextual annotation of each word in that document. The LAMA attention mechanism then obtains multiple attention distributions over those words by computing an alignment score of their hidden representation with a word-level context vector. Sum of the word representations weighted by the scores from multiple attention distributions then forms a matrix document embedding. The matrix embedding is then flattened and passed onto downstream layers (either a classifier or another encoder depending on the task).
|
| 56 |
+
|
| 57 |
+
In the rest of the paper, capital bold letters indicate matrices, small bold letters indicate vectors and small letters indicate scalars.
|
| 58 |
+
|
| 59 |
+
## 3.1 Sequence Encoder
|
| 60 |
+
|
| 61 |
+
We use the GRU [2] RNN as the sequence encoder. GRU uses a gating mechanism to track the state of the sequences. There are two types of gates: the reset gate r t and the update gate z t . The update gate decides how much past information is kept and how much new information is added. At time t , the GRU computes its new state as:
|
| 62 |
+
|
| 63 |
+
<!-- formula-not-decoded -->
|
| 64 |
+
|
| 65 |
+
and the update gate z t is updated as:
|
| 66 |
+
|
| 67 |
+
<!-- formula-not-decoded -->
|
| 68 |
+
|
| 69 |
+
The RNN candidate state ˜ h t is computed as:
|
| 70 |
+
|
| 71 |
+
<!-- formula-not-decoded -->
|
| 72 |
+
|
| 73 |
+
Here r t is the reset gate which controls how much the past state contributes to the candidate state. If r t is zero, then it forgets the previous state. The reset gate is updated as follows:
|
| 74 |
+
|
| 75 |
+
<!-- formula-not-decoded -->
|
| 76 |
+
|
| 77 |
+
Consider a document D i containing T words. D i = f w 1 ; :::; w t ; :::; w T g . Let each word be denoted by w t , t 2 » 0 ; T … where every word is converted to a real valued word vector x t using a pre-trained embedding matrix W e = R d j V j , x t = W e w t , t 2 » 1 ; T … where d is the embedding dimension and V is the vocabulary. The embedding matrix W e is fine-tuned during training. Note that we have dropped the subscript i as all the derivations are for the i th document and it is assumed implicit in the following sections unless otherwise stated.
|
| 78 |
+
|
| 79 |
+
We encode the document using a bi-GRU that summarizes information in both directions along the text to get a contextual annotation of a word. In a bi-GRU the hidden state at time step t is represented as a concatenation of hidden states in the forward and backward direction. The forward GRU denoted by ! GRU processes the document from w 1 to w T whereas the backward GRU denoted by GRU processes it from w T to w 1 .
|
| 80 |
+
|
| 81 |
+
<!-- formula-not-decoded -->
|
| 82 |
+
|
| 83 |
+
<!-- formula-not-decoded -->
|
| 84 |
+
|
| 85 |
+
<!-- formula-not-decoded -->
|
| 86 |
+
|
| 87 |
+
Here the word annotation h t is obtained by concatenating the forward hidden state ! h t and the backward hidden state h t .
|
| 88 |
+
|
| 89 |
+
## 3.2 Single-Head Attention
|
| 90 |
+
|
| 91 |
+
To alleviate the burden of remembering long term dependencies from GRUs we use the global attention mechanism [25] in which the document representation is computed by attending to all words in the document. Let h t be the annotation corresponding to the word x t . First we transform h t using a one layer Multi-Layer Perceptron
|
| 92 |
+
|
| 93 |
+
Table 1: Important notations. Capital bold letters indicate matrices, small bold letters indicate vectors, small letters indicate scalars.
|
| 94 |
+
|
| 95 |
+
| Notation Meaning N Corpus size T # of words tokens in a sample m # of attention heads f t alignment score α t attention weight u t word hidden representation c global context vector h GRU hidden state dimension |
|
| 96 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 97 |
+
|
| 98 |
+
(MLP) to obtain its hidden representation u t . We assume Gaussian priors with 0 mean and 0 : 1 standard deviation on W w and b w .
|
| 99 |
+
|
| 100 |
+
<!-- formula-not-decoded -->
|
| 101 |
+
|
| 102 |
+
Next, to compute the importance of the word in the current context we calculate its relevance to a global context vector c using a bilinear projection.
|
| 103 |
+
|
| 104 |
+
<!-- formula-not-decoded -->
|
| 105 |
+
|
| 106 |
+
Here, W i 2 I R 2 h 2 h , is a bilinear projection matrix which is randomly initialized and jointly learned with other parameters during training. h is the dimension of the GRU hidden state and u t & c are both of dimension 2 h 1 since we're using a bi-GRU. The mean of the word embeddings provides a good initial approximation of the global context of the document. We initialize c = 1 T ˝ T t = 1 w t which is then updated during training. We use a bilinear projection because they are more effective in learning pairwise interactions as shown in previous works [3]. The attention weight for the word x t is then computed using a softmax function where summation is taken over all the words in the document.
|
| 107 |
+
|
| 108 |
+
<!-- formula-not-decoded -->
|
| 109 |
+
|
| 110 |
+
## 3.3 Low-Rank Factorization based Multi-Head Attention
|
| 111 |
+
|
| 112 |
+
In this section, we describe the novel low-rank factorization based multi-head attention mechanism (LAMA). The attention distribution in Eq. 9 above usually focuses on a specific component of the document, like a special set of trigger words. So it is expected to reflect an aspect, or component of the semantics in a document. This type of attention is useful for smaller pieces of texts such as tweets or short reviews. For larger reviews there can be multiple aspects that describe that review. For this we introduce a novel way of computing multiple heads of attention that capture different aspects.
|
| 113 |
+
|
| 114 |
+
Suppose m heads of attention are to be computed, we need m alignment scores between each word hidden representation u t and the context vector c . To obtain an m dimensional output f t , we need to learn m weight matrices given by W = » W 1 ; :::; W m … 2 R m 2 h 2 h as demonstrated in previous works. Although this strategy might be effective in capturing pairwise interactions for each aspect it also introduces a huge number of parameters that may lead to overfitting and also incur a high computational cost especially for a large m or a large h . To address this, the rank of matrix W can
|
| 115 |
+
|
| 116 |
+
̃
|
| 117 |
+
|
| 118 |
+
̃
|
| 119 |
+
|
| 120 |
+
̃
|
| 121 |
+
|
| 122 |
+
Figure 1: Figure shows a schematic of the model architecture and its major components including the Sentence Encoder, proposed multi-head attention mechanism LAMA, Structured Sentence Embedding and finally the MLP classifier. The attention computation is demonstrated for a single word.
|
| 123 |
+
|
| 124 |
+
<!-- image -->
|
| 125 |
+
|
| 126 |
+
be reduced by using low-rank bilinear method to have less number of parameters [17, 43]. Consider one head; the bilinear projection matrix W i in Eq. 8 can be factorized into two low rank matrices P & Q .
|
| 127 |
+
|
| 128 |
+
<!-- formula-not-decoded -->
|
| 129 |
+
|
| 130 |
+
To obtain m scores, by Eq.10, the weights to be learned are two three-order tensors P = » P 1 ; :::; P m … 2 I R 2 h k m and Q = » Q 1 ; :::; Q m … 2 I R 2 h k m accordingly. Without loss of generality P and Q can be reformulated as 2-D matrices ˜ P 2 I R 2 h km and ˜ Q 2 I R 2 h km respectively with simple reshape operations. Setting k = 1 , which corresponds to rank-1 factorization. Eq.10 can be written as:
|
| 131 |
+
|
| 132 |
+
where P = » p 1 ; :::; p k … 2 I R 2 h k and Q = » q 1 ; :::; q k … 2 I R 2 h k are two low-rank matrics, is the Hadamard product or the elementwise multiplication of two vectors, ✶ 2 I R k is an all-one vector and k is the latent dimensionality of the factorized matrices.
|
| 133 |
+
|
| 134 |
+
<!-- formula-not-decoded -->
|
| 135 |
+
|
| 136 |
+
t
|
| 137 |
+
|
| 138 |
+
t
|
| 139 |
+
|
| 140 |
+
This brings the two feature vectors u t 2 R 2 h , the word hidden representation and c 2 R 2 h , the global context vector in a common subspace and are given by ˜ u t and ˜ c respectively. f t 2 I R m can be viewed as a multi-head alignment vector for the word x t where each dimension of the vector can be viewed as the score of the word w.r.t. a different attention head. For computing attention for one head, this is equivalent to replacing the projection matrix W i in Eq. 8 by the outer product of vectors ˜ P i and ˜ Q i ; rows of the matrices ˜ P and ˜ Q respectively and rewriting it as the Hadamard product. As a result each row of matrices ˜ P i and ˜ Q i represent the vectors for computing the score for a different head.
|
| 141 |
+
|
| 142 |
+
The multi-head attention vector α t 2 I R m is obtained by computing a softmax function along the sentence length:
|
| 143 |
+
|
| 144 |
+
<!-- formula-not-decoded -->
|
| 145 |
+
|
| 146 |
+
Before computing softmax, similar to previous works [17, 43], to further increase the model capacity we apply the tanh nonlinearlity to f t . Since element-wise multiplication is introduced the variance of the model might increase, so we apply an l 2 normalization layer across the m dimension. Although l 2 is not strictly necessary since both c and u t are in the same modality empirically we do see improvement after applying l 2 . Each component k of α t is the contribution of the word x t to the k th head.
|
| 147 |
+
|
| 148 |
+
Next, we describe how this computation can be vectorized for each word in the document. Let H = ' h 1 ; h 2 ; ::: h T ' be a matrix of all word annotations in the sentence; H 2 I R T 2 h . The attention matrix for the sentence can be computed as:
|
| 149 |
+
|
| 150 |
+
<!-- formula-not-decoded -->
|
| 151 |
+
|
| 152 |
+
where, C д 2 I R 2 h T is c repeated T times, once for each word, l 2 ' x ' = x j j x j j and softmax is applied row-wise. A 2 I R m T is the attention matrix between the sentence and the global context with each row representing attention for one aspect.
|
| 153 |
+
|
| 154 |
+
Given A = » α 1 ; α 2 ; ::: α T … , the multi-head attention matrix for the sentence; A 2 I R m T . The document representation for a head j given by α j = f α j 1 ; α j 2 ; :: α jT g can be computed by taking a weighted sum of all word annotations.
|
| 155 |
+
|
| 156 |
+
<!-- formula-not-decoded -->
|
| 157 |
+
|
| 158 |
+
Similarly, document representation can be computed for all heads and is given in a compact form by:
|
| 159 |
+
|
| 160 |
+
<!-- formula-not-decoded -->
|
| 161 |
+
|
| 162 |
+
Here S 2 I R m 2 h is a matrix sentence embedding and contains as many rows as the number of heads. Each row contains an attention distribution for a new head. It is flattened by concatenating all rows to obtain the document representation d . From the document representation, the class probabilities are obtained as follows.
|
| 163 |
+
|
| 164 |
+
<!-- formula-not-decoded -->
|
| 165 |
+
|
| 166 |
+
̃
|
| 167 |
+
|
| 168 |
+
Loss is computed using cross entropy.
|
| 169 |
+
|
| 170 |
+
<!-- formula-not-decoded -->
|
| 171 |
+
|
| 172 |
+
where C is the number of classes and ˆ y c is the probability of the class c .
|
| 173 |
+
|
| 174 |
+
## 3.4 Disagreement Regularization
|
| 175 |
+
|
| 176 |
+
To reduce the variance of model introduced due to point-wise multiplication and to encourage diversity among multiple attention heads we introduce an auxiliary regularization term.
|
| 177 |
+
|
| 178 |
+
<!-- formula-not-decoded -->
|
| 179 |
+
|
| 180 |
+
where A is the attention matrix, θ represents model parameters, λ is a hyper-parameter and is empirically set to 0.2 in this paper. L ' ˆ y ; y ' is the cross-entropy loss and D ' A j x ; y ; θ ' is the auxiliary regularization term that represents the disagreement between different attentions. It guides the related attention components to capture different features from the corresponding projected subspaces. We try two different regularizations i) regularization over attended positions ii) regularization over document embeddings. For the first type we adapt the penalization term in [23] to represent disagreement between attention distributions (Eq. 19a). Next, we directly regularize the sentence embeddings resulting from different attention distributions represented using their cosine similarity (Eq. 19b). The more similar the embeddings, lesser the disagreement.
|
| 181 |
+
|
| 182 |
+
<!-- formula-not-decoded -->
|
| 183 |
+
|
| 184 |
+
<!-- formula-not-decoded -->
|
| 185 |
+
|
| 186 |
+
The final training loss is given by Eq. 18 summed over all documents in a minibatch. We use the minibatch stochastic gradient descent algorithm [16] with momentum and weight decay for optimizing the loss function and the backpropogation algorithm is used to compute the gradients.
|
| 187 |
+
|
| 188 |
+
Fig. 1 shows a single document and its flow through various model components. The middle block illustrates the proposed attention mechanism for one word w t of the document. It is first transformed through Eq. 7 to u t . In parallel, a context vector c is initialized. Eq. 11 is then used to compute the multi-head attention for this word. Vectorized attention computation can be performed for all words using Eq. 13 to obtain the attention matrix A which is then multiplied by the hidden state matrix H to obtain an embedding for the document which is then passed to the MLP classifier.
|
| 189 |
+
|
| 190 |
+
## 3.5 Hyperparameters
|
| 191 |
+
|
| 192 |
+
We use a word embedding size of 100. The embedding matrix W e is pretrained on the corpus using word2vec [29]. All words appearing less than 5 times are discarded. The GRU hidden state is set to h = 50 , MLP hidden state to 512 and we apply a dropout of 0 : 4 to the hidden layer. Batch size is set to 32 for training and an initial learning rate of 0 : 05 is used. For early stopping we use patience = 5 . Momentum is set to 0.9 and weight decay to 0.0001. We will open source the code on acceptance.
|
| 193 |
+
|
| 194 |
+
Table 2: Per-layer complexity for different layer types. n is the document length, m is the number of attention heads and d is the representation dimension.
|
| 195 |
+
|
| 196 |
+
| Layer Type Complexity per Layer Self Attention (LAMA) O ' n m h ' Self-Attention (TE) O ' n 2 d ' |
|
| 197 |
+
|--------------------------------------------------------------------------------------------------------------------|
|
| 198 |
+
|
| 199 |
+
Table 3: Dataset statistics. # words indicates the average number of tokens per document in the corresponding datasets.
|
| 200 |
+
|
| 201 |
+
| Dataset # Classes # Train # Test # words YELP 5 499,976 4,000 118 YELP-L 5 175,844 1,378 226 YELP-P 2 560,000 38,000 137 IMDB 2 25,000 25,000 221 Reuters 8 4,484 2,189 102 News 4 151,328 32,428 352 |
|
| 202 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 203 |
+
|
| 204 |
+
## 3.6 Computational Complexity
|
| 205 |
+
|
| 206 |
+
Other variables such as document encoder and dimension of the hidden state held constant, the computational complexity of the model depends on the attention layer. It can be seen that the computational complexity of LAMA is linear in input and linear in the number of attention heads. Where as, the attention mechanism in the encoder of a Transformer model [39] is quadratic in the length of the input (Table 2). For cases where n m n 2 , which is a common scenario, attention mechanism LAMA is computationally more efficient than self-attention in encoder of the Transformer model for sequence classification tasks.
|
| 207 |
+
|
| 208 |
+
## 4 EVALUATION
|
| 209 |
+
|
| 210 |
+
## 4.1 Datasets
|
| 211 |
+
|
| 212 |
+
We evaluate the performance of the proposed model on tasks of predicting business ratings from Yelp, sentiment prediction from movie reviews and classifying news articles into topics. Table 3 gives an overview of the datasets and their statistics.
|
| 213 |
+
|
| 214 |
+
4.1.1 Yelp. The Yelp dataset 1 consists of 2.7M Yelp reviews and user ratings from 1 to 5. Given a review the goal is to predict the rating assigned by the user to the corresponding business store. We treat the task as 5-way text classification where each class indicates the user rating. We randomly sampled 500K review-star pairs as training set and 4,000 for test set. Reviews were tokenized using the Spacy tokenizer 2 . 100-dimensional word embeddings were trained from scratch on the train dataset using the gensim 3 software package.
|
| 215 |
+
|
| 216 |
+
4.1.2 Yelp-Long. Multi-head attention capturing multiple aspects is more useful for classifying ratings that are more subjective i.e. longer reviews where people express their experiences in detail. We create a subset of the YELP dataset containing all longer reviews i.e. reviews containing longer than 118 tokens which we found to be the mean length of the reviews in the dataset. The training set consists of 175,844 reviews, and the test set consists of 1,378 reviews. The goal is to predict the ratings from the above subset of the Yelp dataset. We refer to this dataset as Yelp-L (Yelp-Long) in the rest of the paper since it consists of all longer reviews. We hypothesize that having multi-head attention would benefit in this setting where more intricate foraging of information from different parts of the text is required to make a prediction. The model hyperparameters and training settings remain the same as the above.
|
| 217 |
+
|
| 218 |
+
1 https://www.yelp.com/dataset challenge
|
| 219 |
+
|
| 220 |
+
2 https://spacy.io/
|
| 221 |
+
|
| 222 |
+
3 https://radimrehurek.com/gensim/
|
| 223 |
+
|
| 224 |
+
4.1.3 Yelp-Polarity. The Yelp reviews polarity dataset [44] is constructed by considering stars 1 and 2 negative, and 3 and 4 positive from the Yelp dataset. For each polarity 280,000 training samples and 19,000 testing samples are taken randomly. In total there are 560,000 training samples and 38,000 testing samples. This datset is referred as Yelp-P in the paper.
|
| 225 |
+
|
| 226 |
+
4.1.4 Movie Reviews. The large Movie Review dataset [26] contains movie reviews along with their associated binary sentiment polarity labels. It contains 50,000 highly polar reviews ( score 4 out of 10 for negative reviews and score > = 7 out of 10 for positive reviews) split evenly into 25K train and 25K test sets. The overall distribution of labels is balanced (25K pos and 25K neg). In the entire collection, no more than 30 reviews are allowed for any given movie because reviews for the same movie tend to have correlated ratings. Further, the train and test sets contain a disjoint set of movies, so no significant performance is obtained by memorizing movie-unique terms and their associated with observed labels. We refer to this dataset as IMDB in the rest of the paper.
|
| 227 |
+
|
| 228 |
+
4.1.5 News Aggregator. This dataset [9] contains headlines, URLs, and categories for news stories collected by a web aggregator between March 10th, 2014 and August 10th, 2014. News categories included in this dataset include business; science and technology; entertainment; and health. Different news articles that refer to the same news item are also categorized together. Given a news article the task is to classify it into one of the four categories. Training dataset consits of 151,328 articles and test dataset consits of 32, 428. The average token length is 352.
|
| 229 |
+
|
| 230 |
+
4.1.6 Reuters. This dataset 4 is taken from Reuters-21578 Text Categorization Collection. This is a collection of documents that appeared on Reuters newswire in 1987. The documents were assembled and indexed with categories. We evaluate on the Reuters8 dataset consisting of news articles about 8 topics including acq, crude, earn, grain, interest, money-fx, ship,trade.
|
| 231 |
+
|
| 232 |
+
## 4.2 Comparative Methods
|
| 233 |
+
|
| 234 |
+
To benchmark the proposed model against existing methods we use a variety of model architectures as our comparative baselines. We use BERT [8] as one of the baselines. In our experiments, we used the pretrained bert-base uncased model which has 12-layers, 768-hidden state size, 12-heads, 110M parameters and is trained on lower-cased English text. We finetuned it on our datasets for 2 epochs using the ADAM optimizer [19] with a learning rate of 5 e 6 .
|
| 235 |
+
|
| 236 |
+
4 https://www.cs.umb.edu/smimarog/textmining/datasets/
|
| 237 |
+
|
| 238 |
+
It has been shown that average of word embeddings can make for a very strong baseline [36]. We use this as another baseline and refer to it as A VG in the paper.
|
| 239 |
+
|
| 240 |
+
We use a variety of models with and without attention as other baselines. Strong representative baselines for different model architectures are chosen; such as CNN with max-over-time pooling [18], bidirectional GRU [7] model with maxpooling referred as BiGRU. We experimented with n = 1 and n = 2 GRU layers and found that n = 1 converged faster and led to a better performance. For the CNN baseline we used 3 kernels of sizes 3, 4 and 5 with 100 filters each.
|
| 241 |
+
|
| 242 |
+
Among supervised attention-based multi-head models we use the Self Attention Network proposed by Lin et al. [23]. We refer to this baseline as SAN. For each task, we empirically find the number of heads that give the best performance. We use a 1-layer Encoder of the Transformer model (TE) [39] with 8 attention heads as another baseline. We use d = 512 such that d heads = 64 .
|
| 243 |
+
|
| 244 |
+
model model
|
| 245 |
+
|
| 246 |
+
We use two variations of the proposed model to compare the performance with the above baselines. For the first variation we initialize c with mean of word embeddings in the sentence to provide the global context of the sentence. We call this baseline LAMA+ctx . In another variation, we randomly initialize c and jointly learn it with other model parameters ( LAMA ). Our model with embedding regularization is referred as LAMA+ctx + d e and our model with regularization over positions is referred as LAMA+ctx + d p . For the models LAMA and LAMA+ctx we empirically identify the optimal number of attention heads to get the best performance.
|
| 247 |
+
|
| 248 |
+
## 5 RESULTS
|
| 249 |
+
|
| 250 |
+
Table 4 reports the accuracy of the best model on the test set after performing 3-fold cross-validation. The proposed model with global context initialization LAMA+ctx outperforms the SAN model [23] on all tasks from 3.3% (Reuters) to 8.2% (IMDB). This is due to the fact that during attention computation the proposed model architecture has the provision to access the global context of the sentence whereas for SAN no such provision is available.
|
| 251 |
+
|
| 252 |
+
Extrapolating the attention over larger chunks of text we get uniform attention over all words, which is equivalent to no attention or equal preference for all words. This is what a simple BiGRU effects to (in a contextual setting and average of word embeddings in a non-contextual setting). We note that LAMA+ctx outperforms BiGRU by 2.0% (News), 12.2% (Reuters) 7.9% (Yelp) and 9.4 % (Yelp-L) and 2.7 % (IMDB).
|
| 253 |
+
|
| 254 |
+
Our models outperform the Transformer Encoder (TE) on all tasks. It should be noted that this performance improvement also comes with fewer parameters than TE (Table 5). When compared to large fine-tuned pre-trained language models such as BERT we find that LAMA outperforms BERT on News, Reuters, Yelp and IMDB datasets. On YELP-L and YELP-P datasets BERT outperforms LAMA. However, it should be noted that besides being trained on large-scale text corpora and having a large memory footprint compared to LAMA, BERT models also take a longer time for pretraining. For instance, for Yelp-P it took 12.5 hours to train the model just for 1 epoch as compared to 20 mins for LAMA and for Yelp it took 8.5 hours as opposed to 25 mins for LAMA on one Nvidia Tesla P100 GPU.
|
| 255 |
+
|
| 256 |
+
Table 4: Table reports the accuracy of the proposed models ( LAMA , LAMA+ctx ) against various baselines on sentiment analysis and news classification tasks. + D p refers to LAMA + Ctx with position-wise regularization whereas + D e refers to LAMA + Ctx with regularization over embeddings.
|
| 257 |
+
|
| 258 |
+
| Methods News Reuters Yelp IMDB Yelp-L Yelp-P SAN (Lin et al. [23]) 0.876 0.942 0.68 0.831 0.638 0.945 BiGRU 0.905 0.867 0.663 0.876 0.608 0.943 CNN (Kim et al. [18]) 0.914 0.96 0.693 0.874 0.672 0.953 TE (Vaswani et al. [39]) 0.899 0.901 0.655 0.817 0.569 0.925 BERT (Devlin et al. [8]) 0.92 0.97 0.715 0.894 0.672 0.97 AVG (Arora et al. [1]) 0.91 0.795 0.653 0.874 0.652 0.928 LAMA 0.922 0.965 0.697 0.895 0.653 0.947 LAMA + Ctx 0.923 0.973 0.716 0.90 0.665 0.952 + D p 0.903 0.948 0.711 0.874 0.656 0.948 + D e 0.91 0.831 0.677 0.805 0.619 0.893 |
|
| 259 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 260 |
+
|
| 261 |
+
For the non-contextual baseline of average of word embeddings there's an improvement of 1.4% (News), 22.4% (Reuters) 9.8% (Yelp), 11.4% (Yelp-L) and 3.0% (IMDB) which shows that contextual information captured by BiGRU or CNN models are indeed important for the tasks.
|
| 262 |
+
|
| 263 |
+
Compared to CNN models an improvement of 1% (News), 1.4% (Reuters) and 3.3% (Yelp), and 3.0 % (IMDB) can be observed. On the Yelp-L dataset our model and CNN perform similarly. However, the proposed model is more interpretable and gives an option for inspecting the attended keywords.
|
| 264 |
+
|
| 265 |
+
Finally, our results suggest that using disagreement regularization on LAMA worsens the performance in general.
|
| 266 |
+
|
| 267 |
+
From the above results it can be noted that LAMA is a competitive, interpretable and lean supervised model for text classification tasks.
|
| 268 |
+
|
| 269 |
+
## 5.1 Parameter vs Heads
|
| 270 |
+
|
| 271 |
+
In Transformer-based models attention layer can prove to be a memory bottleneck when resources are constrained. In this section, we compare the number of trainable parameters of the proposed model (LAMA) and Transformer Encoder (TE). Table 5 shows the increase in number of parameters (y-axis) when the number of attention heads are varied as 2, 4, 8, 16, 32, 64. Powers of 2 are picked because TE requires number of attention heads to be divisble by d model [39]. Note that reported parameters also contain GRU & embedding parameters for LAMA and feed forward layer & position embedding parameters for TE, although these parameters don't depend on number of attention heads. To ensure a fair comparison we pick BiGRU hidden dimension and d model both as 512. The hidden layer dimension of the final layer sentence classifier is 1024, which is the same for both models. It can be observed that the number of parameters in TE is constant for all heads which is consistent with its definition, because with increasing heads; Key, Value and Query projections parameters are scaled down. For LAMA, the number of parameters increases only slightly with increasing number of heads because P & Q are the only parameter matrices that are dependent on the number of attention heads m and for which the size increases (linearly). More importantly, it should be noted that for the number of heads for most practical use cases, the proposed model LAMA is almost 3 times more compact than Transformer Encoder.
|
| 272 |
+
|
| 273 |
+
Table 5: Comparison of number of trainable parameters in the attention layer of LAMA and TE with increasing number of attention heads. Number of parameters increase linearly for LAMA whereas for TE they are constant. Overall LAMA is more parameter efficient than TE.
|
| 274 |
+
|
| 275 |
+
| # heads # parameters (LAMA) (in millions) # parameters (TE) (in millions) 2 6.403 18.465 4 6.405 18.465 8 6.409 18.465 16 6.418 18.465 32 6.434 18.465 64 6.468 18.465 |
|
| 276 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 277 |
+
|
| 278 |
+
## 5.2 Runtime
|
| 279 |
+
|
| 280 |
+
It should be noted that since LAMA is applied on top of RNN the computation is sequential and attention cannot be computed unless all RNN hidden states are available. Hence, the computational time increases linearly with input length and quadratically with hidden state dimension ' O ' n h 2 '' . Once RNN hidden states are available the complexity of the attention layer LAMA is O ' n m h ' . In comparison, the complexity of the self-attention mechanism in Transformer is O ' n 2 d ' , where d is the hidden state dimension. It increases quadratically with increasing input length and linearly with hidden state dimension. In this section, we compare the runtimes of LAMA and a 1-layer Transformer Encoder. For a fair comparison we compare the runtimes of LAMA free from RNN. We propose, LAMAEncoder - a model that doesn't use RNN to model sequential dependencies and directly operates on the word embeddings of the inputs. That is, the hidden state matrix H in Eq. 13 is populated by the pretrained word embeddings. Fig 2 shows the average runtime per epoch (averaged over 10 epochs) of LAMA Encoder (LE) and Transformer Encoder (TE) when sequence lengths are increased from 50 to 250 for IMDB and Reuters datasets. It can be seen from the figure that TE is computationally more expensive per epoch than LE. LE is also a competitive model with test accuracies of 83.0 % on IMDB and 93.9% on Reuters as compared to 81.7% (IMDB) and 90.1% (REUTERS) of TE.
|
| 281 |
+
|
| 282 |
+
Figure 2: Figure shows the average run time per epoch in seconds (averaged over 10 epochs) for LAMA Encoder (LE) and Transformer Encoder (TE) models as a function of input sequence length (50 to 250). It can be seen that TE (green) is more computationally expensive compared to LAMA (blue). LE is LAMA attention mechanism applied directly to word embeddings without computing GRU hidden states.
|
| 283 |
+
|
| 284 |
+
<!-- image -->
|
| 285 |
+
|
| 286 |
+
Figure 3: Figure shows the accuracy (y-axis) of the models LAMA, SAN, TE and BERT models on YELP-P dataset when viewed against the model parameters (x-axis). LAMA outperforms SAN and TE while also being more parameter efficient. BERT outperforms LAMA by 1.8% but by more than an order of magnitude increase in parameters.
|
| 287 |
+
|
| 288 |
+
<!-- image -->
|
| 289 |
+
|
| 290 |
+
## 5.3 Parameters vs Accuracy
|
| 291 |
+
|
| 292 |
+
On the YELP-P dataset our model is outperformed by BERT by 1.8 %. However it it worth noting the cost of this performance improvement. Fig. 3 shows the accuracy of different models and their corresponding parameters on the YELP-P dataset. It can be seen that LAMA+ctx outperforms SAN & TE with fewer parameters (difference being linear). BERT slightly outperforms LAMA+ctx however with more than an order of magnitude increase in parameters.
|
| 293 |
+
|
| 294 |
+
## 5.4 Contextual Attention Weights
|
| 295 |
+
|
| 296 |
+
To verify that our model captures context dependent word importance and is interpretable we peform qualitative analysis. We plot the distribution of the attention weights of the positive words 'amazing', 'happy' and 'recommended' and negative words 'poor', 'terrible' and 'worst' from the test split of the Yelp data set as shown in Figure 4. We plot the distribution when conditioned on the ratings of the reviews from 1 to 5. It can be seen from Figure 4 that the weight of positive words concentrates on the low end in the reviews with rating 1 (blue curve). As the rating increases, the weight distribution shifts to the right. This indicates that positive words play a more important role for reviews with higher ratings. The trend is opposite for the negative words where words with negative connotation have lower attention weights for reviews with rating 5 (purple curve). However, there are a few exceptions. For example, it is intuitive that 'amazing' gets a high weight for reviews with high ratings but it also gets a high weight for reviews with rating 2 (orange curve). This is because, inspecting the Yelp dataset we find that 'amazing' occurs quite frequently with the word 'not' in the reviews with rating 2; 'above average but not amazing', 'was ok but not amazing'. Our model captures this phrase-level context and assigns similar weights to 'not' and 'amazing'. 'not' being a negative word gets a high weight for lower ratings and hence so does 'amazing'. Similarly, other exceptions such as 'terrible' for rating 4 can be explained due to the fact that customers might dislike one aspect of a business such as their service but like another aspect such as food.
|
| 297 |
+
|
| 298 |
+
To further illustrate context-dependent word importance Table 6 lists top attended keywords for Yelp and Reuters datasets. Note that superlatives such '100 stars' appear in the list which are strong indicators of the sentiment of a review.
|
| 299 |
+
|
| 300 |
+
## 5.5 Why Multiple Heads
|
| 301 |
+
|
| 302 |
+
Figure 5: Figure shows the effect of using multiple attention heads. Validation accuracy of LAMA+Ctx is plotted for different values of m for the Yelp-L dataset(left) and the IMDB dataset(right). x -axis indicates the number of epochs, y -axis indicates the accuracy. Accuracy peaks at m = 15 for both Yelp-L and IMDB.
|
| 303 |
+
|
| 304 |
+
<!-- image -->
|
| 305 |
+
|
| 306 |
+
Table 6: Top attended words for Yelp dataset from reviews with ratings 1 and 5 (indicated in paratheses) and Reuters(r8) Dataset.
|
| 307 |
+
|
| 308 |
+
| Yelp(1) Yelp(5) r8(ship) r8(money) inconsiderate rudest goodnight worst ever boycott loud livid some hassle friendly ugh dealership brutal rather 1 pizza slow torture absolute recommend trust referred downside professional 100 happy attentive stars please delicious safe worth very would blown sensitive removed impressed looks kuwait gulf south tanker cargo warships pentagon says begin iranian shipping from demand salvage trade production japan gulf india combat currencies monetary miyazawa stoltenberg accord louvre fed cooperation rate poehl exchange stability currency german reagan pact policy support trade deficit |
|
| 309 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 310 |
+
|
| 311 |
+
Figure 4: Attention weight ( x -axis ) distribution of the positive words 'amazing', 'happy' & 'recommend' and negative words 'poor', 'terrible', & 'worst'. Positive words tend to get higher weights in reviews with higher ratings (3-5) whereas negative words get higher weights for lower ratings (1-2) Example 'terrible' and 'poor' get a very low weight for reviews with ratings 5 and 'recommend' and 'amazing' get high attention weights for reviews with ratings 4 and 5.
|
| 312 |
+
|
| 313 |
+
<!-- image -->
|
| 314 |
+
|
| 315 |
+
Previous works have shown that more heads does not necessarily lead to better performance for machine translation tasks [28]. In this analysis, we seek to answer a similar question for text classification.
|
| 316 |
+
|
| 317 |
+
We evaluate the model performance as we vary the number of attention heads m from 1 to 25. Specifically, we plot the validation accuracy vs. epochs for different values of m , for the Yelp-L and IMDB datasets. We vary m from 1 to 20 to get 5 models with m = 1 , m = 5 , m = 10 , m = 15 and m = 20 . The plots are shown in Figure 5. From the figure we can see that for the YelpL dataset model performance peaks for m = 15 and then starts falling for m = 20 . We can clearly see a significant difference between m = 1 and m = 20 , showing that having a multi-aspect attention mechanism helps. For the IMDB dataset model with m = 15 performs the best whereas model with m = 1 performs the worst although performances for m = 5 ; 15 ; 20 are similar.
|
| 318 |
+
|
| 319 |
+
## 6 CONCLUSION
|
| 320 |
+
|
| 321 |
+
In this paper we presented a novel compact multi-head attention mechanism and illustrated its effectiveness on text classification benchmarks. The proposed method computes multiple attention distributions over words which leads to contextual sentence representations. The results showed that this mechanism performed better than several other approaches with fewer parameters. We also verified that the model captured context-dependent word importance. We envision two directions for future work - 1) Currently, the model relies on RNNs that makes it slower due to their sequential computation. We seek to investigate ways of adapting the proposed mechanism in Transformer-style self-supervised language models such as BERT, XLNet etc. without dependency on RNNs by incorporating positional embeddings [11] for faster and efficient learning of language representations; 2) currently, the model uses a single global context vector as the query vector that conflates the entire sentence into one vector which could lead to information loss. Transformer models on the other hand use fine-grained context by querying every word in the sequence for each candidate word. Even though this may help develop direct connections between relevant words it might get redundant. In the future work, we seek to investigate ways of incorporating phrase-level queries as a middle ground between a single global context vector like the proposed approach and fine-grained queries like Transformer providing a balance between complexity and context.
|
| 322 |
+
|
| 323 |
+
## REFERENCES
|
| 324 |
+
|
| 325 |
+
- [1] Sanjeev Arora, Yingyu Liang, and Tengyu Ma. 2017. A Simple but Tough-to-Beat Baseline for Sentence Embeddings. (2017).
|
| 326 |
+
- [2] Dzmitry Bahdanau, Kyunghyun Cho, and Yoshua Bengio. 2014. Neural Machine Translation by Jointly Learning to Align and Translate. CoRR abs/1409.0473 (2014).
|
| 327 |
+
- [3] Danqi Chen, Adam Fisch, Jason Weston, and Antoine Bordes. 2017. Reading Wikipedia to Answer Open-Domain Questions. In Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers) . Association for Computational Linguistics, Vancouver, Canada, 1870-1879. https://doi.org/10.18653/v1/P17-1171
|
| 328 |
+
- [4] Ting Chen, Ji Lin, Tian Lin, Song Han, Chong Wang, and Denny Zhou. 2018. Adaptive mixture of low-rank factorizations for compact neural modeling. (2018).
|
| 329 |
+
- [5] Jianpeng Cheng, Li Dong, and Mirella Lapata. 2016. Long Short-Term MemoryNetworks for Machine Reading. In Proceedings of the 2016 Conference on Empirical Methods in Natural Language Processing . Association for Computational Linguistics, Austin, Texas, 551-561. https://doi.org/10.18653/v1/D16-1053
|
| 330 |
+
- [6] Kyunghyun Cho, Bart van Merri¨ enboer, Caglar Gulcehre, Dzmitry Bahdanau, Fethi Bougares, Holger Schwenk, and Yoshua Bengio. 2014. Learning Phrase Representations using RNN Encoder-Decoder for Statistical Machine Translation. In Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing (EMNLP) . Association for Computational Linguistics, Doha, Qatar, 1724-1734. https://doi.org/10.3115/v1/D14-1179
|
| 331 |
+
- [7] Junyoung Chung, Caglar Gulcehre, KyungHyun Cho, and Yoshua Bengio. 2014. Empirical evaluation of gated recurrent neural networks on sequence modeling. In NIPS 2014 Workshop on Deep Learning, December 2014 .
|
| 332 |
+
|
| 333 |
+
- [8] Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. 2019. BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers) . Association for Computational Linguistics, Minneapolis, Minnesota, 4171-4186. https://doi.org/10.18653/v1/N19-1423
|
| 334 |
+
- [9] Dua Dheeru and Efi Karra Taniskidou. 2017. UCI Machine Learning Repository. http://archive.ics.uci.edu/ml
|
| 335 |
+
- [10] Bhuwan Dhingra, Hanxiao Liu, Zhilin Yang, William Cohen, and Ruslan Salakhutdinov. 2017. Gated-Attention Readers for Text Comprehension. In Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers) . Association for Computational Linguistics, Vancouver, Canada, 1832-1846. https://doi.org/10.18653/v1/P17-1168
|
| 336 |
+
- [11] Jonas Gehring, Michael Auli, David Grangier, Denis Yarats, and Yann N. Dauphin. 2017. Convolutional Sequence to Sequence Learning. In Proceedings of the 34th International Conference on Machine Learning - Volume 70 (ICML'17) . JMLR.org, 1243-1252.
|
| 337 |
+
- [12] Hongyu Guo, Colin Cherry, and Jiang Su. 2017. End-to-end multi-view networks for text classification. arXiv preprint arXiv:1704.05907 (2017).
|
| 338 |
+
- [13] Karl Moritz Hermann, Tomas Kocisky, Edward Grefenstette, Lasse Espeholt, Will Kay, Mustafa Suleyman, and Phil Blunsom. 2015. Teaching machines to read and comprehend. In Advances in neural information processing systems . 1693-1701.
|
| 339 |
+
- [14] Sepp Hochreiter and J¨ urgen Schmidhuber. 1997. Long Short-Term Memory. Neural Comput. 9, 8 (Nov. 1997), 1735-1780. https://doi.org/10.1162/neco.1997. 9.8.1735
|
| 340 |
+
- [15] Jeremy Howard and Sebastian Ruder. 2018. Universal Language Model Finetuning for Text Classification. In Proceedings of the 56th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers) . Association for Computational Linguistics, Melbourne, Australia, 328-339. https://doi.org/ 10.18653/v1/P18-1031
|
| 341 |
+
- [16] Jack Kiefer, Jacob Wolfowitz, et al. 1952. Stochastic estimation of the maximum of a regression function. The Annals of Mathematical Statistics 23, 3 (1952), 462-466.
|
| 342 |
+
- [17] Jin-Hwa Kim et al. 2017. Hadamard Product for Low-rank Bilinear Pooling. In ICLR . OpenReview.net. https://openreview.net/forum?id=r1rhWnZkg
|
| 343 |
+
- [18] Yoon Kim. 2014. Convolutional Neural Networks for Sentence Classification. In Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing (EMNLP) . Association for Computational Linguistics, Doha, Qatar, 1746-1751. https://doi.org/10.3115/v1/D14-1181
|
| 344 |
+
- [19] Diederik P. Kingma and Jimmy Ba. 2015. Adam: A Method for Stochastic Optimization. In 3rd International Conference on Learning Representations, ICLR 2015, San Diego, CA, USA, May 7-9, 2015, Conference Track Proceedings , Yoshua Bengio and Yann LeCun (Eds.). http://arxiv.org/abs/1412.6980
|
| 345 |
+
- [20] Oleksii Kuchaiev and Boris Ginsburg. 2017. Factorization tricks for LSTM networks. CoRR abs/1703.10722 (2017). arXiv:1703.10722 http://arxiv.org/abs/ 1703.10722
|
| 346 |
+
- [21] Zhenzhong Lan, Mingda Chen, Sebastian Goodman, Kevin Gimpel, Piyush Sharma, and Radu Soricut. 2019. Albert: A lite bert for self-supervised learning of language representations. arXiv preprint arXiv:1909.11942 (2019).
|
| 347 |
+
- [22] Tsung-Yu Lin, Aruni RoyChowdhury, and Subhransu Maji. 2015. Bilinear cnn models for fine-grained visual recognition. In Proceedings of the IEEE International Conference on Computer Vision . 1449-1457.
|
| 348 |
+
- [23] Zhouhan Lin, Minwei Feng, Cicero Nogueira dos Santos, Mo Yu, Bing Xiang, Bowen Zhou, and Yoshua Bengio. 2017. A Structured Self-Attentive Sentence Embedding. https://openreview.net/forum?id=BJC jUqxe
|
| 349 |
+
- [24] Yinhan Liu, Myle Ott, Naman Goyal, Jingfei Du, Mandar Joshi, Danqi Chen, Omer Levy, Mike Lewis, Luke Zettlemoyer, and Veselin Stoyanov. 2019. Roberta: A robustly optimized bert pretraining approach. arXiv preprint arXiv:1907.11692 (2019).
|
| 350 |
+
- [25] Thang Luong, Hieu Pham, and Christopher D. Manning. 2015. Effective Approaches to Attention-based Neural Machine Translation. In Proceedings of the 2015 Conference on Empirical Methods in Natural Language Processing . Association for Computational Linguistics, Lisbon, Portugal, 1412-1421. https://doi.org/10.18653/v1/D15-1166
|
| 351 |
+
- [26] Andrew L Maas, Raymond E Daly, Peter T Pham, Dan Huang, Andrew Y Ng, and Christopher Potts. 2011. Learning word vectors for sentiment analysis. In Proceedings of the 49th annual meeting of the association for computational linguistics: Human language technologies-volume 1 . Association for Computational Linguistics, 142-150.
|
| 352 |
+
- [27] Sneha Mehta, Mohammad Raihanul Islam, Huzefa Rangwala, and Naren Ramakrishnan. 2019. Event Detection Using Hierarchical Multi-Aspect Attention. In The World Wide Web Conference (WWW '19) . ACM, New York, NY, USA, 3079-3085. https://doi.org/10.1145/3308558.3313659
|
| 353 |
+
- [28] Paul Michel, Omer Levy, and Graham Neubig. 2019. Are Sixteen Heads Really Better than One?. In Advances in Neural Information Processing Systems . 1401414024.
|
| 354 |
+
- [29] Tomas Mikolov, Ilya Sutskever, Kai Chen, Greg S Corrado, and Jeff Dean. 2013. Distributed representations of words and phrases and their compositionality. In
|
| 355 |
+
23. Advances in neural information processing systems . 3111-3119.
|
| 356 |
+
- [30] Ankur P Parikh, Oscar T¨ ackstr¨ om, Dipanjan Das, and Jakob Uszkoreit. 2016. A decomposable attention model for natural language inference. arXiv preprint arXiv:1606.01933 (2016).
|
| 357 |
+
- [31] Romain Paulus, Caiming Xiong, and Richard Socher. 2017. A deep reinforced model for abstractive summarization. arXiv preprint arXiv:1705.04304 (2017).
|
| 358 |
+
- [32] Matthew Peters, Mark Neumann, Mohit Iyyer, Matt Gardner, Christopher Clark, Kenton Lee, and Luke Zettlemoyer. 2018. Deep Contextualized Word Representations. In Proceedings of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long Papers) . Association for Computational Linguistics, New Orleans, Louisiana, 2227-2237. https://doi.org/10.18653/v1/N18-1202
|
| 359 |
+
- [33] Alec Radford, Jeffrey Wu, Rewon Child, David Luan, Dario Amodei, and Ilya Sutskever. [n.d.]. Language models are unsupervised multitask learners. ([n. d.]).
|
| 360 |
+
- [34] Min Joon Seo, Aniruddha Kembhavi, Ali Farhadi, and Hannaneh Hajishirzi. 2017. Bidirectional Attention Flow for Machine Comprehension. In 5th International Conference on Learning Representations, ICLR 2017, Toulon, France, April 24-26, 2017, Conference Track Proceedings . OpenReview.net. https://openreview.net/ forum?id=HJ0UKP9ge
|
| 361 |
+
- [35] Noam Shazeer, Azalia Mirhoseini, Krzysztof Maziarz, Andy Davis, Quoc Le, Geoffrey Hinton, and Jeff Dean. 2017. Outrageously large neural networks: The sparsely-gated mixture-of-experts layer. arXiv preprint arXiv:1701.06538 (2017).
|
| 362 |
+
- [36] Dinghan Shen, Guoyin Wang, Wenlin Wang, Martin Renqiang Min, Qinliang Su, Yizhe Zhang, Chunyuan Li, Ricardo Henao, and Lawrence Carin. 2018. Baseline Needs More Love: On Simple Word-Embedding-Based Models and Associated Pooling Mechanisms. In Proceedings of the 56th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers) . Association for Computational Linguistics, Melbourne, Australia, 440-450. https://doi.org/ 10.18653/v1/P18-1041
|
| 363 |
+
- [37] Weijie Su, Xizhou Zhu, Yue Cao, Bin Li, Lewei Lu, Furu Wei, and Jifeng Dai. 2020. VL-BERT: Pre-training of Generic Visual-Linguistic Representations. In International Conference on Learning Representations . https://openreview.net/ forum?id=SygXPaEYvH
|
| 364 |
+
- [38] Cheng Tai, Tong Xiao, Yi Zhang, Xiaogang Wang, and E. Weinan. 2016. Convolutional neural networks with low-rank regularization. 4th International Conference on Learning Representations, ICLR 2016 ; Conference date: 02-05-2016 Through 04-05-2016.
|
| 365 |
+
- [39] Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin. 2017. Attention is all you need. In Advances in neural information processing systems . 5998-6008.
|
| 366 |
+
- [40] Thomas Wolf, Lysandre Debut, Victor Sanh, Julien Chaumond, Clement Delangue, Anthony Moi, Pierric Cistac, Tim Rault, R´ emi Louf, Morgan Funtowicz, et al. 2019. Transformers: State-of-the-art Natural Language Processing. arXiv preprint arXiv:1910.03771 (2019).
|
| 367 |
+
- [41] Zhilin Yang et al. 2019. Xlnet: Generalized autoregressive pretraining for language understanding. In Advances in neural information processing systems . 5754-5764.
|
| 368 |
+
- [42] Mo Yu, Matthew R Gormley, and Mark Dredze. 2015. Combining word embeddings and feature embeddings for fine-grained relation extraction. In Proceedings of the 2015 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies . 1374-1379.
|
| 369 |
+
- [43] Zhou Yu, Jun Yu, Jianping Fan, and Dacheng Tao. 2017. Multi-modal factorized bilinear pooling with co-attention learning for visual question answering. In Proceedings of the IEEE international conference on computer vision . 18211830.
|
| 370 |
+
- [44] Xiang Zhang, Junbo Zhao, and Yann LeCun. 2015. Character-level convolutional networks for text classification. In Advances in neural information processing systems . 649-657.
|
text-versions/attention-markdown/2002.07028_LowRank Bottleneck in Multihead Attentio.md
ADDED
|
@@ -0,0 +1,417 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2002.07028 Lowrank Bottleneck In Multihead Attentio
|
| 2 |
+
|
| 3 |
+
## Low-Rank Bottleneck in Multi-head Attention Models
|
| 4 |
+
|
| 5 |
+
Srinadh Bhojanapalli *
|
| 6 |
+
|
| 7 |
+
Chulhee Yun †
|
| 8 |
+
|
| 9 |
+
Ankit Singh Rawat ‡
|
| 10 |
+
|
| 11 |
+
Sanjiv Kumar ¶
|
| 12 |
+
|
| 13 |
+
## Abstract
|
| 14 |
+
|
| 15 |
+
Attention based Transformer architecture has enabled significant advances in the field of natural language processing. In addition to new pre-training techniques, recent improvements crucially rely on working with a relatively larger embedding dimension for tokens. Unfortunately, this leads to models that are prohibitively large to be employed in the downstream tasks. In this paper we identify one of the important factors contributing to the large embedding size requirement. In particular, our analysis highlights that the scaling between the number of heads and the size of each head in the current architecture gives rise to a low-rank bottleneck in attention heads, causing this limitation. We further validate this in our experiments. As a solution we propose to set the head size of an attention unit to input sequence length, and independent of the number of heads, resulting in multi-head attention layers with provably more expressive power. We empirically show that this allows us to train models with a relatively smaller embedding dimension and with better performance scaling.
|
| 16 |
+
|
| 17 |
+
## 1 Introduction
|
| 18 |
+
|
| 19 |
+
Attention based architectures, such as Transformers, have been effective for sequence modelling tasks such as machine translation [Gehring et al., 2017, Vaswani et al., 2017], question answering, sentence classification [Radford et al., 2018, Devlin et al., 2018] and document generation [Liu et al., 2018]. These models have emerged as better alternatives to the recurrent models - RNNs [Sutskever et al., 2014], LSTMs [Hochreiter and Schmidhuber, 1997] and GRUs [Cho et al., 2014]. This is mainly due to their feed forward structure, which removes the sequential processing bottleneck for sequence data, making them easier to train compared to the recurrent models. Self attention models also have found applications in vision [Wang et al., 2018], adversarial networks [Zhang et al., 2018], reinforcement learning [Zambaldi et al., 2018, Li, 2017] and speech recognition [Chiu et al., 2018].
|
| 20 |
+
|
| 21 |
+
Recent advances in using the self attention models in natural language tasks have been made by first using a language modeling task to pre-train the models and then fine tuning the learned models on specific downstream tasks. Radford et al. [2018] and Devlin et al. [2018] used Transformers to pre-train a language model and showed that the fine tuned model outperforms LSTMs on many natural language understanding and question answering tasks. For example, BERT [Devlin et al., 2018], a 24 layer transformer model, is shown to achieve the state of the art performance on several NLP tasks, including on the SQuAD dataset. These advances, in addition to novel pre-training tasks, relied on bigger models with a larger embedding size. BERT model uses an embedding size of 1024 [Devlin et al., 2018]; GPT-2 uses models with embedding size up to 1600 [Radford et al., 2019].
|
| 22 |
+
|
| 23 |
+
A single Transformer block consists of two key components: a multi-head self attention layer followed by a feed forward layer [Vaswani et al., 2017]. A single head in a multi-head attention layer, computes self attention between the tokens in the input sequence, which it then uses to compute a weighted average of embeddings for each token. Each head projects the data into a lower dimensional subspace, and computes the self attention in this subspace. This projection size for each head is commonly referred to as the head size .
|
| 24 |
+
|
| 25 |
+
* Google Research NY. bsrinadh@google.com
|
| 26 |
+
|
| 27 |
+
† MIT. Based on work performed at Google Research New York. chulheey@mit.edu
|
| 28 |
+
|
| 29 |
+
‡ Google Research NY. ankitsrawat@google.com
|
| 30 |
+
|
| 31 |
+
§ Google Research NY. sashank@google.com
|
| 32 |
+
|
| 33 |
+
¶ Google Research NY. sanjivk@google.com
|
| 34 |
+
|
| 35 |
+
Sashank J. Reddi §
|
| 36 |
+
|
| 37 |
+
Table 1: Performance of BERTLARGE [Devlin et al., 2018], a 24 layer Transformer with an embedding size of 1024, suffers with the increasing number of heads after 8 heads.
|
| 38 |
+
|
| 39 |
+
| # heads 8 16 32 # params 336M 336M 336M SQuAD - F1 90.89 ± 0.15 90.61 ± 0.14 90.45 ± 0.08 SQuAD - EM 84.1 ± 0.34 83.75 ± 0.27 83.48 ± 0.13 MNLI 85 ± 0.2 84.5 ± 0.4 84.4 ± 0.2 |
|
| 40 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 41 |
+
|
| 42 |
+
To keep the number of parameters fixed in the attention layer regardless of the number of heads, the prevalent heuristic is to scale the head size with 1/(number of heads). This heuristic was initially proposed in Vaswani et al. [2017] and has become a de facto standard heuristic in multi-head attention models [Radford et al., 2018, Devlin et al., 2018]. However, increasing the number of heads decreases the head size, decreasing the expressive power of individual heads. We prove that reducing the head size to a value below the input sequence length harms the representation power of each head (see Theorem 1). This is because a smaller head size introduces a rank constraint on the projection matrices in each head, and limits their representation power. We indeed notice this effect in practice: while the performance improves with increasing the number of heads in the beginning [Devlin et al., 2018], we notice a drop in the performance once the number of heads increases beyond a certain threshold, as seen in Table 1 and Fig. 1 (see also Table 4(A) in Vaswani et al. [2017]).
|
| 43 |
+
|
| 44 |
+
In order to avoid hurting the performance, the existing models allow for multiple heads by increasing the embedding size, which in turn increases the head size. However, larger embedding size, in addition to increasing the number of parameters, makes it expensive to use the model and the learned embeddings in downstream tasks, as the downstream model sizes scale with the embedding size of the tokens. For example, the inference time and memory required in retrieval tasks typically increases linearly with the embedding size.
|
| 45 |
+
|
| 46 |
+
In this paper we propose setting the head size of attention units to input sequence length. While this is a simple hyper-parameter change in the Transformer architecture, we show that it is important to set this value appropriately to avoid the low-rank bottleneck (see Theorem 1), and to improve the representation power (see Theorem 2). This fixed head size is also independent of both the number of heads and the embedding size of the model. This allows us to train models with a relatively smaller embedding size (hence fewer parameters) without affecting the head size. Another advantage of the fixed head size is that unlike the standard setting which requires the number of heads to be a factor of the embedding size, we are free to set an arbitrary number of heads as required for the task.
|
| 47 |
+
|
| 48 |
+
Interestingly, we note that this simple yet novel approach of fixing the head size in multi-head Transformers results in empirically superior performance. We evaluate Transformers trained with this fixed head size on language modeling (LM1B dataset), natural language inference (MNLI dataset) and question answering tasks (SQuAD dataset). We show that fixing the head size allows us to train Transformers with a better performance scaling and smaller embedding size. We show that with the fixed head size Transformers trained with an embedding size of 512 can match the performance of the BERTLARGE[Devlin et al., 2018], a Transformer with an embedding size of 1024 (see Fig. 2). We further present experimental results evaluating the effect of different choices of the head size and the embedding size in Section 4.
|
| 49 |
+
|
| 50 |
+
Our contributions in this paper lie in identifying and rigorously proving the low rank bottleneck in multi-head attention models, and showing that fixing the head size to input sequence length results in a strictly better model, both theoretically and empirically. The contributions of this paper are summarized below.
|
| 51 |
+
|
| 52 |
+
- We analyze the representation power of the multi-head self attention layer and prove the low-rank bottleneck the head size places on the attention units (Theorem 1).
|
| 53 |
+
- We propose to set the head size to input sequence length, and show that fixing the head size strictly improves the expressive power of the multi-head attention layers compared to the standard heuristic for setting the head size (Theorem 2). This allows us to both increase the number of heads per layer and decrease the embedding size, without hurting the performance. We develop a novel construction based approach to prove this result, which can potentially be useful in analyzing other variants of the Transformer architecture.
|
| 54 |
+
- We experimentally show that with a fixed head size, Transformers can be trained with better performance scaling and
|
| 55 |
+
|
| 56 |
+
a smaller embedding size on three standard NLP tasks.
|
| 57 |
+
|
| 58 |
+
## 1.1 Related Works
|
| 59 |
+
|
| 60 |
+
Given the significance of self attention models, there has been work trying to both improve the performance and speed up the computation in Transformers. Ott et al. [2018] and You et al. [2019] reduce precision and use large batch training to reduce the training time of the attention models. Child et al. [2019] propose sparse self attention models to speed up the computation in the attention layer for long sequence data generation tasks. They show that these sparse attention models can be trained on tasks with sequence length greater than 10k without sacrificing the accuracy. Dehghani et al. [2018] propose a depth recurrent Transformer network that reuses the parameters across layers. They show that this modification makes the Transformer networks Turing complete even with finite precision weights. Yang et al. [2019] propose a new way to increase the effective sequence length that the Transformer attends to, by reusing the intermediate embeddings across sequences. They show that the modified architecture performs better on tasks that require computing context over longer sequence lengths. We note that most of these modifications rely on the multi-head self attention, the same building block of the Transformers. Our work is studying this basic multi-head attention layer, and suggesting a new way to set the head size, which can be easily applied along with any of the above architectural modifications.
|
| 61 |
+
|
| 62 |
+
Wu et al. [2019] propose to replace the self-attention layer with lightweight dynamic convolutions and show improved performance on machine translation and language modeling. Even though the resulting model has faster inference time, it still needs to use a large embedding size (1024), as big as the original attention models. We believe the techniques in this paper can be combined with these results to realize both smaller embedding size and faster inference time.
|
| 63 |
+
|
| 64 |
+
Sun et al. [2019] perform neural architecture search using evolutionary methods on sequence to sequence models and find an evolved transformer architecture, which in addition to multi-head attention units, has convolution filter and gated linear units. Our proposed modifications stay closer to Transformers in spirit and can be used as seed units for this architecture search.
|
| 65 |
+
|
| 66 |
+
Yang et al. [2017] have studied the effect of rank constraint caused by the small projection sizes in computing the softmax loss. The situation in self attention layers is a bit different. While the expressive power of each head reduces with the decreasing head size, at the same time we are increasing the number of heads, which can potentially negate this and increase the overall capacity of the layer. As we show in Theorem 2, the prevalent head size heuristic indeed limits the expressive power of the multi-head attention layer.
|
| 67 |
+
|
| 68 |
+
Yun et al. [2019] studied the representation power of Transformers and showed that they are universal approximators of sequence to sequence functions. However they do not study the low rank bottleneck caused by the prevalent head size heuristic and its connection to the embedding size.
|
| 69 |
+
|
| 70 |
+
Voita et al. [2019], Michel et al. [2019] study the importance of different heads in an attention layer. They observe that, during inference, many of the heads in each layer can be pruned away with a little effect on the prediction. However, they still need multiple heads during the training.
|
| 71 |
+
|
| 72 |
+
Child et al. [2019], Correia et al. [2019] impose sparsity structure on the attention layer during training to improve both interpretability and performance. Fixing the head size will in fact make it easier to learn such sparsity patterns, as a low rank constraint does not allow a head to express all possible sparsity patterns. Combining these techniques can hence potentially enable training of sparse attention models with a smaller embedding size.
|
| 73 |
+
|
| 74 |
+
## 2 Transformer Architecture and Analysis
|
| 75 |
+
|
| 76 |
+
In this section, we present the Transformer architecture and analyze the representation power of the multi-head self attention, a key component of the Transformer block.
|
| 77 |
+
|
| 78 |
+
The input to a Transformer network is a sequence of n tokens. Typically, each token is converted into a token embedding of dimension d by an embedding layer. We let X ∈ R d × n be the embedding matrix corresponding to the n tokens in the input sequence.
|
| 79 |
+
|
| 80 |
+
## 2.1 Single-Head Attention
|
| 81 |
+
|
| 82 |
+
The Transformer block is a combination of a self attention layer followed by a feed forward layer [Vaswani et al., 2017]. Both layers have a skip connection and use Layer Normalization (LN) [Ba et al., 2016]. In particular, for token embeddings X , the dot product attention is computed as follows.
|
| 83 |
+
|
| 84 |
+
<!-- formula-not-decoded -->
|
| 85 |
+
|
| 86 |
+
Here W q ∈ R d q × d , W k ∈ R d k × d and W v ∈ R d v × d represent the projection matrices associated with the query, key and value respectively in an attention unit [Vaswani et al., 2017]. For a single-head attention unit, we have d q = d k = d v = d . In the dot-product attention (cf. (1)), P aims to capture the context of the input for a given token based on the remaining tokens in the input sequence. Subsequently, the output of the attention layer takes the following form.
|
| 87 |
+
|
| 88 |
+
<!-- formula-not-decoded -->
|
| 89 |
+
|
| 90 |
+
where LN ( · ) represents the layer-normalization operation. Given the attention module, as defined in (1), it is natural to question its ability to represent arbitrary contexts P for a given input sequence X .
|
| 91 |
+
|
| 92 |
+
In the following result we establish that for a large enough projection size an attention unit can represent any data pair ( X , P ) . We also show that the model cannot represent arbitrary context when d is smaller than n , creating a low-rank bottleneck.
|
| 93 |
+
|
| 94 |
+
Theorem 1 (Representation Theorem) . If d q = d k = d ≥ n , then given any full column rank matrix X ∈ R d × n and an arbitrary n × n positive column stochastic matrix P , there always exists d × d projection matrices W q and W k such that
|
| 95 |
+
|
| 96 |
+
<!-- formula-not-decoded -->
|
| 97 |
+
|
| 98 |
+
If d q = d k = d < n , there exist X and P such that (3) does not hold for all W q and W k .
|
| 99 |
+
|
| 100 |
+
This result shows that the projection dimension d q = d k = d needs to be larger than the sequence length n for the attention unit to be able to represent any desired context P . Even though this result describes a single example sequence case, it highlights a fundamental property of the model architecture that decreasing the projection size below a certain threshold introduces a bottleneck.
|
| 101 |
+
|
| 102 |
+
Proof of Theorem 1. d ≥ n case . To prove the first part of the result, we present an explicit construction of W k and W q which allows us to generate P from X using the dot product attention. Since X has full column rank, there exists a left inverse X † = ( X T X ) -1 X T ∈ R n × d such that X † X = I n . Let W k = ˜ W k X † and W q = ˜ W q X † . Then
|
| 103 |
+
|
| 104 |
+
<!-- formula-not-decoded -->
|
| 105 |
+
|
| 106 |
+
Now that the above choice of W q and W k has handled the dependence on X , we will choose a ˜ W kq depending on P and finish the construction. Below we express the Softmax operation on the query and key inner products. Note that the Softmax here is a columnwise operator computing the attention scores for each query. By using (4), we obtain that
|
| 107 |
+
|
| 108 |
+
<!-- formula-not-decoded -->
|
| 109 |
+
|
| 110 |
+
where D ˜ W kq is an n × n diagonal matrix such that
|
| 111 |
+
|
| 112 |
+
<!-- formula-not-decoded -->
|
| 113 |
+
|
| 114 |
+
Hence, we can establish the desired result by showing that there always exists a ˜ W kq that satisfies the following fixed point equation.
|
| 115 |
+
|
| 116 |
+
<!-- formula-not-decoded -->
|
| 117 |
+
|
| 118 |
+
Given P , to construct such a ˜ W kq , we pick an arbitrary positive diagonal matrix D 0 , and set
|
| 119 |
+
|
| 120 |
+
<!-- formula-not-decoded -->
|
| 121 |
+
|
| 122 |
+
Since P is a positive matrix, such a ˜ W kq always exists. Next, we verify that this construction indeed satisfies the fixed point equation (cf. (5)). Note that
|
| 123 |
+
|
| 124 |
+
<!-- formula-not-decoded -->
|
| 125 |
+
|
| 126 |
+
The last equation follows from the fact that P is a column stochastic matrix. Now, using (6) and (7),
|
| 127 |
+
|
| 128 |
+
<!-- formula-not-decoded -->
|
| 129 |
+
|
| 130 |
+
This completes the first part of the proof.
|
| 131 |
+
|
| 132 |
+
d < n case . Consider the case of d = 1 and n = 2 . Then X ∈ R 1 × 2 and W q and W k ∈ R 1 × 1 . Let X = [1 , 0] . Then
|
| 133 |
+
|
| 134 |
+
<!-- formula-not-decoded -->
|
| 135 |
+
|
| 136 |
+
This matrix clearly cannot be used to generate P that have distinct elements in the second column, e.g., P = [ 0 . 5 0 . 75 0 . 5 0 . 25 ] .
|
| 137 |
+
|
| 138 |
+
## 2.2 Multi-Head Attention
|
| 139 |
+
|
| 140 |
+
As discussed in Section 2.1, an attention unit updates the embedding of an input token based on a weighted average of the embeddings of all the tokens in the sequence, using the context P (cf. (1)). Vaswani et al. [2017] proposed Multi-Head attention mechanism that increases the representation power of an attention layer, where multiple attention units operate on different low dimensional projections of the input, with each attention unit being referred to as a head. This is followed by concatenation of the outputs from different heads. In particular, the computation inside a Multi-Head attention with h heads takes the following form:
|
| 141 |
+
|
| 142 |
+
<!-- formula-not-decoded -->
|
| 143 |
+
|
| 144 |
+
<!-- formula-not-decoded -->
|
| 145 |
+
|
| 146 |
+
The output of the Multi-head attention layer then becomes
|
| 147 |
+
|
| 148 |
+
<!-- formula-not-decoded -->
|
| 149 |
+
|
| 150 |
+
where W o ∈ R d × d . For a model with h heads, the query, key and value projection matrices { W i q } , { W i k } and { W i v } are d h × d matrices. Therefore, each head projects the input onto a d h -dimensional subspace to compute the context, and keeps the number of parameters fixed per layer. Using MultiHead has resulted in empirically better performance over the single head attention layer [Vaswani et al., 2017].
|
| 151 |
+
|
| 152 |
+
Figure 1: Performance of Transformers trained with the prevalent head size heuristic ( d p = d / h ) (baseline) compared with the fixed head size ( d p = 32 ) on a language modeling task (LM1B) on the test set. We train baseline models with embedding sizes from 256 to 512. We train the fixed head size models with a fixed embedding size of 256 and a head size of 32, and vary the number of heads from 4 to 70, while matching the number of parameters. The plots clearly indicate that fixing the head size allows us to train Transformers with a smaller embedding size (plot (b)), and with a better scaling of performance (plot (a)). Note that for perplexity lower values are better.
|
| 153 |
+
|
| 154 |
+
<!-- image -->
|
| 155 |
+
|
| 156 |
+
## 2.3 Low-Rank Bottleneck
|
| 157 |
+
|
| 158 |
+
While increasing the number of heads seemingly gives the model more expressive power, at the same time we are reducing the head size, which can decrease the expressive power. When the number of heads h is larger than d n , the attention unit inside each head projects onto a dimension smaller than n , creating a low-rank bottlenck and loses its ability to represent arbitrary context vectors (cf. Theorem 1). Interestingly, this is consistent with the empirical observation in Table 1 that increasing h beyond 8 results in performance degradation in BERTLARGE [Devlin et al., 2018]; note that d = 1024 and n = 128 for most of the pre-training phase of BERTLARGE.
|
| 159 |
+
|
| 160 |
+
Since the sequence length is fixed from the data/task at hand, the only way to increase the number of heads without introducing the low-rank bottleneck is by increasing the embedding size d . This is a fundamental limitation of the currently dominant head size heuristic, that we need to increase the embedding size in order to support more heads.
|
| 161 |
+
|
| 162 |
+
Unfortunately, increasing the embedding size leads to higher computation and memory requirements to train and store the model. Further, since it is common to use learned embeddings from Transformer based models for downstream tasks [Devlin et al., 2018], larger embedding size increases the model size and computation required for all the downstream tasks as well.
|
| 163 |
+
|
| 164 |
+
## 3 Fixed Multi-Head Attention
|
| 165 |
+
|
| 166 |
+
In this section we propose to fix the head size of the Transformer, which allows us to enjoy the advantage of higher expressive power of multiple heads without requiring the embedding size to be large. The key is to decouple the dependency between the projection size in a head and the embedding size of the model. The projection matrices now project onto subspaces of a fixed dimension d p irrespective of the number of heads h . This approach where d p is independent of d and h leads to the following attention mechanism.
|
| 167 |
+
|
| 168 |
+
<!-- formula-not-decoded -->
|
| 169 |
+
|
| 170 |
+
<!-- formula-not-decoded -->
|
| 171 |
+
|
| 172 |
+
Note that the projection matrices used here { V i q } , { V i k } and { V i v } are d p × d matrices. With V o ∈ R d × h · d p , the output of this new multi-head attention layer takes the following form.
|
| 173 |
+
|
| 174 |
+
<!-- formula-not-decoded -->
|
| 175 |
+
|
| 176 |
+
This modification makes each attention head more similar to a hidden unit in a feed forward network or a filter in a convolutional network, and allows us to vary the number of heads without worrying about reducing the representation power per head. The downside is, unlike the standard MultiHead, the number of parameters per layer increases with the number of heads. However, this modification allows us to train a model with a smaller embedding size without a low-rank bottleneck, ultimately allowing us to reduce the total number of parameters in the model.
|
| 177 |
+
|
| 178 |
+
## 3.1 MultiHead vs. FixedMultiHead Attention
|
| 179 |
+
|
| 180 |
+
Given a MultiHead layer, we can always represent it using a FixedMultiHead layer, whenever we have the head size d p ≥ d / h . While this shows that increasing the number of heads h beyond d / d p makes individual heads of the FixedMultiHead as expressive as the ones in the MultiHead, it is not obvious if FixedMultiHead is strictly more expressive. Can the FixedMultiHead layer represent functions that the standard MultiHead layer can not represent? In this subsection we show that indeed, in the multi-head regime, the FixedMultiHead layer is strictly better than the standard MultiHead layer in terms of expressive power.
|
| 181 |
+
|
| 182 |
+
Consider the standard multi-head attention units in (8).
|
| 183 |
+
|
| 184 |
+
<!-- formula-not-decoded -->
|
| 185 |
+
|
| 186 |
+
We denote the collection of all parameter matrices as W . Similarly, consider the function represented by the fixed head size attention units:
|
| 187 |
+
|
| 188 |
+
<!-- formula-not-decoded -->
|
| 189 |
+
|
| 190 |
+
Let V be the collection of all these parameter matrices. We define F and G to be the class of functions f W ( · ) and g V ( · ) , respectively. As noted above, if d p ≥ d / h , we have F ⊂ G .
|
| 191 |
+
|
| 192 |
+
The following theorem shows that even for simple examples in G , functions in F fail to represent them; this already shows that F is a strict subset of G .
|
| 193 |
+
|
| 194 |
+
Theorem 2. Let n ≥ 2 , d ≥ d p , and h > d / d p . Consider a FixedMultiHead attention layer g V ( · ) with parameters that satisfy the following conditions:
|
| 195 |
+
|
| 196 |
+
<!-- formula-not-decoded -->
|
| 197 |
+
|
| 198 |
+
̸
|
| 199 |
+
|
| 200 |
+
Then, for any f W ∈ F , there exists X ∈ R d × n such that f W ( X ) = g V ( X ) .
|
| 201 |
+
|
| 202 |
+
Because ‖ f W ( X ) -g V ( X ) ‖ is a continuous function of X , existence of such an X implies that the integral of the norm of difference (i.e., approximation error) is strictly positive. We note that the assumptions on V i k and V i q in the above Theorem are made to provide a simple and constructive proof; in fact, failure of MultiHead ( F ) to represent such simple attention layers suggests that the situation is likely worse for more complex functions.
|
| 203 |
+
|
| 204 |
+
Theorem 2 shows that the expressive power of the FixedMultiHead attention function class is strictly superior to the standard MultiHead attention function class. Hence the heuristic of reducing the head size with the number of heads is limiting the expressive power of MultiHead, whereas using the fixed head size will increase the expressive power of the attention layers.
|
| 205 |
+
|
| 206 |
+
## 4 Experiments
|
| 207 |
+
|
| 208 |
+
The goal of this section is to show that setting the head size in a principled way leads to better performance than using the prevalent heuristic. We again note that while this is a simple hyper-parameter change to the Transformer, setting this to input sequence length as shown in our analysis, allows us to train better models with a smaller embedding size.
|
| 209 |
+
|
| 210 |
+
Figure 2: Comparison of 24 layer Transformer models trained with the prevalent head size heuristic BERTLARGE (baseline) vs. the fixed head size model on the SQuAD and MNLI dev sets. We vary the embedding size of the baseline models from 512 to 1024. We train the fixed head size models with a fixed embedding size of 512 and a head size of 128, with a varying number of heads from 8 to 32, while matching the number of parameters. Fixing the head size allows us to train models with a smaller embedding size of 512 and with a better performance.
|
| 211 |
+
|
| 212 |
+
<!-- image -->
|
| 213 |
+
|
| 214 |
+
Figure 3: Ablation studies on LM1B: (a) We fix the embedding size of all the models to 256 and vary the capacity of Transformers trained with the prevalent head size heuristic (baseline) by increasing the size of the feedforward layers. For the fixed head size models we fix the head size to 32, so 8 head fixed head size model is the same as the 8 head baseline model. We notice that again with the standard heuristic increasing the number of heads beyond 16 hurts the performance, whereas with a fixed head size increasing the number of heads monotonically improves the performance. (b) We show the effect of head size on the performance with different number of heads. Both plots clearly show the advantage in having an additional way to tune the capacity of Transformers with a fixed embedding size.
|
| 215 |
+
|
| 216 |
+
<!-- image -->
|
| 217 |
+
|
| 218 |
+
In this section we present our experiments on three standard NLP tasks, language modeling (LM1B), question answering (SQuAD), and sentence entailment (MNLI), to demonstrate: 1) Increasing the number of heads in Transformers beyond a certain point hurts the performance with the prevalent head size heuristic, but always helps with the fixed head size attention layers; 2) Decoupling the head size from embedding size allows us to train models with a smaller embedding size; and 3) Setting the head size appropriately in the Transformers allows us to train models with a better performance scaling. We first describe our experimental setup followed by our results and ablation studies on the proposed modifications.
|
| 219 |
+
|
| 220 |
+
## 4.1 Setup and Datasets
|
| 221 |
+
|
| 222 |
+
For the language modeling task we use the one billion word benchmark dataset (LM1B) [Chelba et al., 2013]. This dataset has around 30M training examples and around 300k examples in the test set. We use a sub-word tokenizer with Table 2: Ablation studies on SQuAD and MNLI: (A) 24 layer Transformer with a fixed head size of 128 and 512 embedding size shows an improvement in the accuracy with the increasing number of heads. (B) The fixed head size model with 512 embedding size and 8 heads shows an improvement in accuracy with the increasing head size. This shows that indeed head size is an important capacity controlling parameter in the self attention architecture.
|
| 223 |
+
|
| 224 |
+
(A) Increasing number of heads
|
| 225 |
+
|
| 226 |
+
| # heads 8 12 16 32 # params 168M 193M 218M 319M SQuAD - F1 89.6 ± 0.17 90.25 ± 0.21 90.43 ± 0.14 90.95 ± 0.14 SQuAD - EM 82.73 ± 0.21 83.18 ± 0.24 83.59 ± 0.06 84.4 ± 0.29 MNLI 83.5 ± 0.2 84.2 ± 0.2 83.9 ± 0.2 84.9 ± 0.2 |
|
| 227 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 228 |
+
|
| 229 |
+
(B) Increasing head size
|
| 230 |
+
|
| 231 |
+
| head size 32 64 128 256 # params 130M 142M 168M 218M SQuAD - F1 88.53 ± 0.06 89.51 ± 0.15 89.6 ± 0.17 90.33 ± 0.23 SQuAD - EM 81.19 ± 0.21 82.41 ± 0.32 82.73 ± 0.21 83.36 ± 0.48 MNLI 82.5 ± 0.1 83.4 ± 0.3 83.5 ± 0.2 83.9 ± 0.2 |
|
| 232 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 233 |
+
|
| 234 |
+
32k vocab and cap the input to 256 sequence length. We train a 6 layer Transformer model with the ADAM optimizer using the tensor2tensor library [Vaswani et al., 2018]. The detailed experimental setting is presented in Section C.
|
| 235 |
+
|
| 236 |
+
Multi-Genre Natural Language Inference (MNLI) is a sentence level entailment task, designed to test natural language understanding [Williams et al., 2018]. Given a premise sentence and a hypothesis sentence, the goal is to predict whether hypothesis entails, contradicts or is neutral to the premise. We report the classification accuracy for this task. Stanford Question Answering Dataset (SQuAD) is a question answering dataset, where given a paragraph and a question, the goal is to predict the sequence of words in the paragraph that constitute the answer to the question [Rajpurkar et al., 2016]. This is a harder word level task, compared to the sentence classification task. We report both Exact Match (EM) and F1 scores for this task. All results in this section are reported on the Dev set, which has not been used in any experimental choices in this paper.
|
| 237 |
+
|
| 238 |
+
For these latter two tasks, we follow the two stage approach of first pre-training on a language modeling task and then fine-tuning the models on the task data. We follow the same experimental setup for both pre-training and fine-tuning as BERT [Devlin et al., 2018], and use their codebase 1 . We first pre-train our models using the masked language model and the next sentence prediction objectives, and then fine tune the pre-trained model for individual tasks [Devlin et al., 2018]. For pre-training we use English Wikipedia and BooksCorpus dataset [Zhu et al., 2015]. The input to the models is tokenized using the WordPiece representation with 30000 tokens in the vocabulary. We present the key experiment choices in Section C, and refer the reader to Devlin et al. [2018] for a complete description of the setup.
|
| 239 |
+
|
| 240 |
+
Choice of the head size. Our proposed modification introduces head size d p as a new model hyper-parameter. We choose head size to be 128 for our BERT experiments, as most of the pre-training is done with 128 sequence length data. While we have ablation studies (cf. Table 2(B)) showing bigger head size improves the performance, there is a tradeoff between increasing the head size vs number of heads vs layers. We found that having sufficiently large head size, e.g., matching the pre-training sequence length, is better than having a larger embedding size.
|
| 241 |
+
|
| 242 |
+
## 4.2 Results
|
| 243 |
+
|
| 244 |
+
For our first set of experiments we want to see if Transformers trained with a fixed head size and a smaller embedding size can match the performance of training with the standard head size heuristic but with a larger embedding size. As a baseline for the language modeling task, we train Transformers with the embedding size increasing from 256 to 512
|
| 245 |
+
|
| 246 |
+
1 https://github.com/google-research/bert
|
| 247 |
+
|
| 248 |
+
with different number of heads. We train the fixed head size models with a fixed embedding size of 256 and a head size of 32, with an increasing number of heads from 4 to 70. We notice that Transformers with a fixed head size and an embedding size of 256 have better performance than the baseline models with an embedding size of 512 (see Fig. 1). We repeat the similar experiment on the other two tasks, where for baseline we train BERTLARGE, a 24 layer, 16 head Transformer with the standard head size heuristic, with embedding sizes from 512 to 1024. We compare it with the fixed head size model, with an embedding size of 512 and a head size of 128, with an increasing number of heads from 8 to 32. We again notice that the Transformers trained with a fixed head size and 512 embedding size have better performance than the baseline, BERTLARGE (see Fig. 2).
|
| 249 |
+
|
| 250 |
+
Note that simply trying to increase the head size of the Transformers by decreasing the number of heads does not improve the performance, as decreasing the number of heads reduces the expressive power of the model (see Fig. 4 in the Appendix). Hence, both the head size and the number of heads needs to be set high enough for better performance.
|
| 251 |
+
|
| 252 |
+
## 4.3 Ablation
|
| 253 |
+
|
| 254 |
+
Increasing heads. From Table 1 and Fig. 1a we can see that increasing the number of heads hurts the performance of the Transformer after a certain number. We repeat the same experiments with the fixed head size Transformer, and present the results in Table 2(A) and Fig. 3a. The results show that the performance of the modified model improves monotonically as the number of heads increase. This is because the model capacity (a function of the head size) is no longer reduced with the increasing number of heads.
|
| 255 |
+
|
| 256 |
+
Increasing head size. In Table 2(B) and Fig. 3b, we present comparisons between models with different head sizes. This shows that the gains in the performance of the fixed head size models indeed come from adjusting the head size of the query, key and value layers in the attention unit. The table shows a clear trend of better performance with a larger head size, suggesting that it indeed is an important factor in the performance of the attention models.
|
| 257 |
+
|
| 258 |
+
## 5 Conclusion
|
| 259 |
+
|
| 260 |
+
In this paper we studied the representation power of the multi-head self attention models and proved the low-rank bottleneck that results from a small head size in the multi-head attention. We showed that the larger embedding size used in the current models is a consequence of this low-rank bottleneck in multi-head attention layers. We propose to instead use fixed head size attention units, with the head size set to input sequence length, to avoid this bottleneck. We showed that it allows us to increase the number of heads without increasing the embedding size. As a consequence we are able to train Transformers with a smaller embedding size and fewer parameters, with better performance. In the future, it will be interesting to experiment with varying head sizes within an attention block and across layers. This requires further understanding of the role of each layer in computing the context, which is an interesting direction for the future work.
|
| 261 |
+
|
| 262 |
+
## References
|
| 263 |
+
|
| 264 |
+
- J. L. Ba, J. R. Kiros, and G. E. Hinton. Layer normalization. arXiv preprint arXiv:1607.06450 , 2016.
|
| 265 |
+
- C. Chelba, T. Mikolov, M. Schuster, Q. Ge, T. Brants, and P. Koehn. One billion word benchmark for measuring progress in statistical language modeling. CoRR , abs/1312.3005, 2013. URL http://arxiv.org/abs/1312.3005 .
|
| 266 |
+
- R. Child, S. Gray, A. Radford, and I. Sutskever. Generating long sequences with sparse transformers. arXiv preprint arXiv:1904.10509 , 2019.
|
| 267 |
+
4. C.-C. Chiu, T. N. Sainath, Y. Wu, R. Prabhavalkar, P. Nguyen, Z. Chen, A. Kannan, R. J. Weiss, K. Rao, E. Gonina, et al. State-of-the-art speech recognition with sequence-to-sequence models. In 2018 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP) , pages 4774-4778. IEEE, 2018.
|
| 268 |
+
|
| 269 |
+
- K. Cho, B. van Merrienboer, D. Bahdanau, and Y. Bengio. On the properties of neural machine translation: Encoderdecoder approaches. In Proceedings of SSST-8, Eighth Workshop on Syntax, Semantics and Structure in Statistical Translation , pages 103-111, 2014.
|
| 270 |
+
- G. M. Correia, V. Niculae, and A. F. Martins. Adaptively sparse transformers. In Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP) , pages 2174-2184, 2019.
|
| 271 |
+
- M. Dehghani, S. Gouws, O. Vinyals, J. Uszkoreit, and Ł. Kaiser. Universal transformers. arXiv preprint arXiv:1807.03819 , 2018.
|
| 272 |
+
- J. Devlin, M.-W. Chang, K. Lee, and K. Toutanova. Bert: Pre-training of deep bidirectional transformers for language understanding. arXiv preprint arXiv:1810.04805 , 2018.
|
| 273 |
+
- J. Gehring, M. Auli, D. Grangier, D. Yarats, and Y. N. Dauphin. Convolutional sequence to sequence learning. In Proceedings of the 34th International Conference on Machine Learning-Volume 70 , pages 1243-1252. JMLR. org, 2017.
|
| 274 |
+
- S. Hochreiter and J. Schmidhuber. Long short-term memory. Neural computation , 9(8):1735-1780, 1997.
|
| 275 |
+
- Y. Li. Deep reinforcement learning: An overview. arXiv preprint arXiv:1701.07274 , 2017.
|
| 276 |
+
- P. J. Liu, M. Saleh, E. Pot, B. Goodrich, R. Sepassi, L. Kaiser, and N. Shazeer. Generating wikipedia by summarizing long sequences. arXiv preprint arXiv:1801.10198 , 2018.
|
| 277 |
+
- P. Michel, O. Levy, and G. Neubig. Are sixteen heads really better than one? arXiv preprint arXiv:1905.10650 , 2019.
|
| 278 |
+
- M. Ott, S. Edunov, D. Grangier, and M. Auli. Scaling neural machine translation. In Proceedings of the Third Conference on Machine Translation: Research Papers , pages 1-9, 2018.
|
| 279 |
+
- A. Radford, K. Narasimhan, T. Salimans, and I. Sutskever. Improving language understanding by generative pre-training. Technical report, OpenAI , 2018.
|
| 280 |
+
- A. Radford, J. Wu, R. Child, D. Luan, D. Amodei, and I. Sutskever. Language models are unsupervised multitask learners. Technical report, OpenAI , 2019.
|
| 281 |
+
- P. Rajpurkar, J. Zhang, K. Lopyrev, and P. Liang. Squad: 100,000+ questions for machine comprehension of text. arXiv preprint arXiv:1606.05250 , 2016.
|
| 282 |
+
- H. Sun, X. Tan, J.-W. Gan, H. Liu, S. Zhao, T. Qin, and T.-Y. Liu. Token-level ensemble distillation for grapheme-tophoneme conversion. arXiv preprint arXiv:1904.03446 , 2019.
|
| 283 |
+
- I. Sutskever, O. Vinyals, and Q. V. Le. Sequence to sequence learning with neural networks. In Advances in neural information processing systems , pages 3104-3112, 2014.
|
| 284 |
+
- A. Vaswani, N. Shazeer, N. Parmar, J. Uszkoreit, L. Jones, A. N. Gomez, Ł. Kaiser, and I. Polosukhin. Attention is all you need. In Advances in Neural Information Processing Systems , pages 5998-6008, 2017.
|
| 285 |
+
- A. Vaswani, S. Bengio, E. Brevdo, F. Chollet, A. N. Gomez, S. Gouws, L. Jones, L. Kaiser, N. Kalchbrenner, N. Parmar, R. Sepassi, N. Shazeer, and J. Uszkoreit. Tensor2tensor for neural machine translation. CoRR , abs/1803.07416, 2018. URL http://arxiv.org/abs/1803.07416 .
|
| 286 |
+
- E. Voita, D. Talbot, F. Moiseev, R. Sennrich, and I. Titov. Analyzing multi-head self-attention: Specialized heads do the heavy lifting, the rest can be pruned. arXiv preprint arXiv:1905.09418 , 2019.
|
| 287 |
+
- X. Wang, R. Girshick, A. Gupta, and K. He. Non-local neural networks. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , pages 7794-7803, 2018.
|
| 288 |
+
|
| 289 |
+
- A. Williams, N. Nangia, and S. Bowman. A broad-coverage challenge corpus for sentence understanding through inference. In Proceedings of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long Papers) , pages 1112-1122. Association for Computational Linguistics, 2018. URL http://aclweb.org/anthology/N18-1101 .
|
| 290 |
+
- F. Wu, A. Fan, A. Baevski, Y. N. Dauphin, and M. Auli. Pay less attention with lightweight and dynamic convolutions. arXiv preprint arXiv:1901.10430 , 2019.
|
| 291 |
+
- Z. Yang, Z. Dai, R. Salakhutdinov, and W. W. Cohen. Breaking the softmax bottleneck: A high-rank rnn language model. arXiv preprint arXiv:1711.03953 , 2017.
|
| 292 |
+
- Z. Yang, Z. Dai, Y. Yang, J. Carbonell, R. Salakhutdinov, and Q. V. Le. Xlnet: Generalized autoregressive pretraining for language understanding. arXiv preprint arXiv:1906.08237 , 2019.
|
| 293 |
+
- Y. You, J. Li, J. Hseu, X. Song, J. Demmel, and C.-J. Hsieh. Reducing bert pre-training time from 3 days to 76 minutes. arXiv preprint arXiv:1904.00962 , 2019.
|
| 294 |
+
- C. Yun, S. Bhojanapalli, A. S. Rawat, S. J. Reddi, and S. Kumar. Are transformers universal approximators of sequence-to-sequence functions? arXiv preprint arXiv:1912.10077 , 2019.
|
| 295 |
+
- V. Zambaldi, D. Raposo, A. Santoro, V. Bapst, Y. Li, I. Babuschkin, K. Tuyls, D. Reichert, T. Lillicrap, E. Lockhart, et al. Relational deep reinforcement learning. arXiv preprint arXiv:1806.01830 , 2018.
|
| 296 |
+
- H. Zhang, I. Goodfellow, D. Metaxas, and A. Odena. Self-attention generative adversarial networks. arXiv preprint arXiv:1805.08318 , 2018.
|
| 297 |
+
- Y. Zhu, R. Kiros, R. Zemel, R. Salakhutdinov, R. Urtasun, A. Torralba, and S. Fidler. Aligning books and movies: Towards story-like visual explanations by watching movies and reading books. In Proceedings of the IEEE international conference on computer vision , pages 19-27, 2015.
|
| 298 |
+
|
| 299 |
+
## A Notation
|
| 300 |
+
|
| 301 |
+
## B Proofs
|
| 302 |
+
|
| 303 |
+
Proof of Theorem 2. First let us rewrite the MultiHead and FixedMultiHead layers as follows. The MultiHead layer can be rewritten as
|
| 304 |
+
|
| 305 |
+
<!-- formula-not-decoded -->
|
| 306 |
+
|
| 307 |
+
where W i o are d × d/h matrices and W i v , W i k , and W i q are d/h × d matrices. We denote the collection of all parameter matrices as W .
|
| 308 |
+
|
| 309 |
+
Similarly, rewrite the fixed head size attention layer as
|
| 310 |
+
|
| 311 |
+
<!-- formula-not-decoded -->
|
| 312 |
+
|
| 313 |
+
where V i o ∈ R d × d p , and V i v , V i k , V i q ∈ R d p × d . Let V be the collection of all these matrices.
|
| 314 |
+
|
| 315 |
+
̸
|
| 316 |
+
|
| 317 |
+
The outline of the proof is basically a case analysis: we divide possible values of W into three categories, and show in each case that there exists a X such that f W ( X ) = g V ( X ) . Here are the three cases:
|
| 318 |
+
|
| 319 |
+
̸
|
| 320 |
+
|
| 321 |
+
- Case 1 : ∑ h i =1 W i o W i v = ∑ h i =1 V i o V i v .
|
| 322 |
+
- Case 2 : ∑ h i =1 W i o W i v = ∑ h i =1 V i o V i v , and there exists i ∈ { 1 , . . . , h } such that U / √ d p -( W i k ) T ( W i q ) / √ d/h is not skew-symmetric.
|
| 323 |
+
- Case 3 : ∑ h i =1 W i o W i v = ∑ h i =1 V i o V i v , and all U / √ d p -( W i k ) T ( W i q ) / √ d/h are skew-symmetric.
|
| 324 |
+
|
| 325 |
+
̸
|
| 326 |
+
|
| 327 |
+
Case 1. In the first case, we can choose any v such that ( ∑ h i =1 W i o W i v -∑ h i =1 V i o V i v ) v = 0 . Choose X = v1 T = [ v v . . . v ] . Then, note that for any column stochastic matrix P , we have XP = X . Therefore,
|
| 328 |
+
|
| 329 |
+
̸
|
| 330 |
+
|
| 331 |
+
<!-- formula-not-decoded -->
|
| 332 |
+
|
| 333 |
+
̸
|
| 334 |
+
|
| 335 |
+
Case 2. In cases where ∑ h i =1 W i o W i v = ∑ h i =1 V i o V i v , since ∑ h i =1 V i o V i v is full rank by assumption and each W i o W i v is at most rank d/h , it follows that all columns in W i o ∈ R d × d/h must be linearly independent. Therefore, for any v = 0 , { W i o W i v v , i = 1 , . . . , h } is a set of linearly independent vectors, because each W i o W i v v is a linear combination of d/h column vectors of W i o that are linearly independent of other column vectors in W j o , j = i .
|
| 336 |
+
|
| 337 |
+
| Embedding size d Number of layers l Number of heads h Sequence length n Vocab size v Head size d p |
|
| 338 |
+
|------------------------------------------------------------------------------------------------------------------|
|
| 339 |
+
|
| 340 |
+
̸
|
| 341 |
+
|
| 342 |
+
Now consider any v ∈ R d , and X = ve T 1 , where e 1 = (1 , 0 , . . . , 0) ∈ R n . Define φ ( t ) = exp( t ) / (exp( t )+ n -1) . Then, we have
|
| 343 |
+
|
| 344 |
+
<!-- formula-not-decoded -->
|
| 345 |
+
|
| 346 |
+
Similarly, we can calculate
|
| 347 |
+
|
| 348 |
+
<!-- formula-not-decoded -->
|
| 349 |
+
|
| 350 |
+
Notice that all the columns of f W ( X ) and g V ( X ) , from the second columns to the last ones, are the same. We now compare the first columns:
|
| 351 |
+
|
| 352 |
+
<!-- formula-not-decoded -->
|
| 353 |
+
|
| 354 |
+
̸
|
| 355 |
+
|
| 356 |
+
Recall that for any v = 0 , W i o W i v v are linearly independent, so f W ( X ) : , 1 -g V ( X ) : , 1 = 0 if and only if all φ ( v T ( W i k ) T W i q v √ d/h ) -φ ( v T Uv √ d p ) are zero. However, since there exists i ∈ { 1 , . . . , h } such that U / √ d p -( W i k ) T ( W i q ) / √ d/h is not skew-symmetric, we can choose v to be one that satisfies v T ( W i k ) T W i q v √ d/h = v T Uv √ d p , hence
|
| 357 |
+
|
| 358 |
+
̸
|
| 359 |
+
|
| 360 |
+
<!-- formula-not-decoded -->
|
| 361 |
+
|
| 362 |
+
̸
|
| 363 |
+
|
| 364 |
+
Case 3. Now consider any X = [ v 1 v 2 0 . . . 0 ] , where v 1 and v 2 will be chosen later. Define φ 1 ( t 1 , t 2 ) = exp( t 1 ) / (exp( t 1 ) + exp( t 2 ) + n -2) , φ 2 ( t 1 , t 2 ) = exp( t 2 ) / (exp( t 1 ) + exp( t 2 ) + n -2) . Then, we have
|
| 365 |
+
|
| 366 |
+
<!-- formula-not-decoded -->
|
| 367 |
+
|
| 368 |
+
Therefore, the first column of g V ( X ) can be written as
|
| 369 |
+
|
| 370 |
+
<!-- formula-not-decoded -->
|
| 371 |
+
|
| 372 |
+
̸
|
| 373 |
+
|
| 374 |
+
Similarly, the first column of f W ( X ) is
|
| 375 |
+
|
| 376 |
+
<!-- formula-not-decoded -->
|
| 377 |
+
|
| 378 |
+
̸
|
| 379 |
+
|
| 380 |
+
Since U / √ d p -( W 1 k ) T ( W 1 q ) / √ d/h is skew-symmetric by assumption, we have v T 1 ( U √ d p -( W 1 k ) T ( W 1 q ) √ d/h ) v 1 = 0 for all v 1 . Recall that U is rankd p by assumption, so U / √ d p -( W 1 k ) T ( W 1 q ) / √ d/h is at least rank d p -d/h ≥ 1 , so we can choose any v 1 such that ( U √ d p -( W 1 k ) T ( W 1 q ) √ d/h ) v 1 = 0 .
|
| 381 |
+
|
| 382 |
+
<!-- formula-not-decoded -->
|
| 383 |
+
|
| 384 |
+
̸
|
| 385 |
+
|
| 386 |
+
Then, consider the difference f W ( X ) : , 1 -g V ( X ) : , 1 . Recall that for any v , W 1 o W 1 v v is independent of { W i o W i v v , i = 1 } . This means that, to show f W ( X ) : , 1 -g V ( X ) : , 1 = 0 , it suffices to show that
|
| 387 |
+
|
| 388 |
+
̸
|
| 389 |
+
|
| 390 |
+
̸
|
| 391 |
+
|
| 392 |
+
<!-- formula-not-decoded -->
|
| 393 |
+
|
| 394 |
+
If we scale v 2 = α ˜ v 2 with large enough α , the second term will dominate the first term and the first term will never be able to cancel the second one. Thus, by choosing large enough α > 0 , we can make sure that the sum is nonzero.
|
| 395 |
+
|
| 396 |
+
Even in case where one of U √ d p v 1 and ( W 1 k ) T ( W 1 q ) √ d/h v 1 is zero (say ( W 1 k ) T ( W 1 q ) √ d/h v 1 = 0 ), we can choose ˜ v 2 = U √ d p v 1 and use a similar scaling argument. By choosing large enough α > 0 and v 2 = α ˜ v 2 , one can show that the difference f W ( X ) : , 1 -g V ( X ) : , 1 is nonzero.
|
| 397 |
+
|
| 398 |
+
## C Experimental settings
|
| 399 |
+
|
| 400 |
+
For our experiments with the language modeling (LM1B dataset), we train 6 layer Transformer models. We use a batch size of 4096 and train for 250k steps. We use a learning rate of 0.1 with a linear warm up for the first 10k steps. We decay the learning rate with the square root of the number of steps. We train the baseline models, with the prevalent head size heuristic, with the embedding dimension varying from 256 to 512. We fix the width of the feed forward layer in the Transformer to be 1024. In addition, we use weight decay of 0.01 and dropout with probability of 0.1 on all the layers.
|
| 401 |
+
|
| 402 |
+
For our experiments with BERT, we follow the same experimental settings as in [Devlin et al., 2018]. We present the key details here and refer the reader to [Devlin et al., 2018]. We train with a batch size of 1024 for 450k steps with inputs of sequence length n = 128 followed by 50k steps with inputs of sequence length 512. In contrast the BERT paper uses a batch size of 512, and does the pre-training for 900K steps with 128 sequence length inputs and 100k steps with 512 sequence length inputs. We train using ADAM with a learning rate of 1e-4, and a linear warmup and decay schedule as in BERT. We use 5k warmup steps for the first stage, and a re-warmup of 3k steps for the second stage [You et al., 2019]. Again, we use weight decay of 0.01 and dropout with probability of 0.1 on all the layers.
|
| 403 |
+
|
| 404 |
+
For the language modeling task, training is performed on 4 TPUv2 chips for a couple of hours. For BERT models training is performed on 16 TPUv3 chips in the first stage and 64 TPUv3 chips for the second stage. Pre-training with this configuration takes between 2 to 3 days. We did not attempt to find the optimal hyper-parameters for the fixed head size architecture, and use the same hyper-parameters as used for training the BERT models.
|
| 405 |
+
|
| 406 |
+
## D Additional experimental results
|
| 407 |
+
|
| 408 |
+
Figure 4: Performance of the Transformers trained with the prevalent head size heuristic (baseline) compared with the fixed head size ( d p ) models for a language modeling task (LM1B) on the test set. Unlike Fig.1, we vary both the embedding size and the number of heads of the baseline models to keep their head size fixed to 32. We train the fixed head size models with a fixed embedding size of 256 and a head size of 32, and vary the number of heads from 4 to 70, while matching the number of parameters. The plot again clearly indicates the advantage of the fixed head size models. The main issue with the baseline models is that fixing the head size to 32 forces the number of heads to be small when the embedding size is small. Reducing the number of heads below certain threshold hurts the performance of the Transformer.
|
| 409 |
+
|
| 410 |
+
<!-- image -->
|
| 411 |
+
|
| 412 |
+
| # heads 8 12 16 20 # params 214M 252M 290M 327M SQuAD - F1 90.35 ± 0.14 90.48 ± 0.09 90.92 ± 0.14 90.89 ± 0.08 SQuAD - EM 83.37 ± 0.12 83.67 ± 0.03 84.16 ± 0.35 84.29 ± 0.16 MNLI 84.4 ± 0.2 84.4 ± 0.2 84.7 ± 0.1 85.1 ± 0.4 |
|
| 413 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 414 |
+
|
| 415 |
+
(A) Increasing number of heads
|
| 416 |
+
|
| 417 |
+
Table 3: (A): 24 layer Transformer trained with a fixed head size of 128 and an embedding size of 768 shows an improvement in the accuracy with the increasing number of heads.
|
text-versions/attention-markdown/2003.11644_MultiLabel Text Classification using Att.md
ADDED
|
@@ -0,0 +1,380 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2003.11644 Multilabel Text Classification Using Att
|
| 2 |
+
|
| 3 |
+
## MAGNET: Multi-Label Text Classification using Attention-based Graph Neural Network
|
| 4 |
+
|
| 5 |
+
Ankit Pal, Muru Selvakumar and Malaikannan Sankarasubbu
|
| 6 |
+
|
| 7 |
+
Saama AI Research, Chennai, India
|
| 8 |
+
|
| 9 |
+
{ ankit.pal, selvakumar.murugan, malaikannan.sankarasubbu } @saama.com
|
| 10 |
+
|
| 11 |
+
Multi-label text classification, Graph Neural Networks, Attention networks, Deep Learning, Natural Language Processing, Supervised Learning
|
| 12 |
+
|
| 13 |
+
Keywords:
|
| 14 |
+
|
| 15 |
+
Abstract:
|
| 16 |
+
|
| 17 |
+
In Multi-Label Text Classification (MLTC), one sample can belong to more than one class. It is observed that most MLTC tasks, there are dependencies or correlations among labels. Existing methods tend to ignore the relationship among labels. In this paper, a graph attention network-based model is proposed to capture the attentive dependency structure among the labels. The graph attention network uses a feature matrix and a correlation matrix to capture and explore the crucial dependencies between the labels and generate classifiers for the task. The generated classifiers are applied to sentence feature vectors obtained from the text feature extraction network(BiLSTM) to enable end-to-end training. Attention allows the system to assign different weights to neighbor nodes per label, thus allowing it to learn the dependencies among labels implicitly. The results of the proposed model are validated on five real-world MLTC datasets. The proposed model achieves similar or better performance compared to the previous state-of-the-art models.
|
| 18 |
+
|
| 19 |
+
## 1 INTRODUCTION
|
| 20 |
+
|
| 21 |
+
Multi-Label Text Classification (MLTC) is the task of assigning one or more labels to each input sample in the corpus. This makes it both a challenging and essential task in Natural Language Processing(NLP). We have a set of labelled training data { ( xi , yi ) } n i = 1 , where xi ∈ R D are the input features with D dimension for each data instances and yi ∈ { 0 , 1 } are the targets. The vector yi has one in the j th coordinate if the i th data point belongs to j th class. We need to learn a mapping (prediction rule) between the features and the labels, such that we can predict the class label vector y of a new data point x correctly.
|
| 22 |
+
|
| 23 |
+
MLTC has many real-world applications, such as text categorization (Schapire and Singer, 2000), tag recommendation (Katakis et al., 2008), information retrieval (Gopal and Yang, 2010), and so on. Before deep learning, the solution to the MLTC task used to focus on traditional machine learning algorithms.
|
| 24 |
+
|
| 25 |
+
In Proceedings of the 12th International Conference on Agents and Artificial Intelligence (ICAART 2020)
|
| 26 |
+
|
| 27 |
+
Science and Technol-
|
| 28 |
+
|
| 29 |
+
ogy Publications, Lda. All rights reserved Different techniques have been proposed in the literature for treating multi-label classification problems. In some of them, multiple single-label classifiers are combined to emulate MLTC problems. Other techniques involve modifying single-label classifiers by changing their algorithms to allow their use in multi-label problems.
|
| 30 |
+
|
| 31 |
+
The most popular traditional method for solving MLTC is Binary Relevance (BR) (Zhang et al., 2018). BR emulates the MLTC task into multiple independent binary classification problems. However, it ignores the correlation or the dependencies among labels (Luaces et al., 2012). Binary Relevance has stimulated research for finding approaches to capture and explore the label correlations in various ways. Some methods, including Deep Neural Network (DNN) based and probabilistic based models, have been introduced to model dependencies among labels, such as Hierarchical Text Classification. (Sun and Lim, 2001), (Xue et al., 2008), (Gopal et al., 2012) and (Peng et al., 2019). Recently Graph-based Neural Networks (Wu et al., 2019) e.g. Graph Convolution Network (Kipf and Welling, 2016), Graph Attention Networks (Velickovic et al., 2018) and Graph Embeddings (Cai et al., 2017) have received considerable research attention. This is due to the fact that many real-world problems in complex systems, such as recommendation systems (Ying et al., 2018), social networks and biological networks (Fout et al., 2017) etc, can be modelled as machine learning tasks over large networks. Graph Convolutional Network (GCN) was proposed to deal with graph structures. The GCN benefits from the advantage of the Convolutional Neural Network(CNN) architecture: it performs predictions with high accuracy, but a relatively low computational cost by utilizing fewer parameters compared to a fully connected multi-layer perceptron (MLP) model. It can also capture essential sentence features that determine node properties by analyzing relations between neighboring nodes. Despite the advantages as mentioned above, we suspect that the GCN is still missing an essential structural feature to capture better correlation or dependencies between nodes.
|
| 32 |
+
|
| 33 |
+
One possible approach to improve the GCN performance is to add adaptive attention weights depending on the feature matrix to graph convolutions.
|
| 34 |
+
|
| 35 |
+
To capture the correlation between the labels better, we propose a novel deep learning architecture based on graph attention networks. The proposed model with graph attention allows us to capture the dependency structure among labels for MLTC tasks. As a result, the correlation between labels can be automatically learned based on the feature matrix. We propose to learn inter-dependent sentence classifiers from prior label representations (e.g. word embeddings) via an attention-based function. We name the proposed method M ulti-label Text classification using A ttention based G raph Neural NET work (MAGNET). It uses a multi-head attention mechanism to extract the correlation between labels for the MLTC task. Specifically, these are the following contributions:
|
| 36 |
+
|
| 37 |
+
- The drawbacks of current models for the MLTC task are analyzed.
|
| 38 |
+
- Anovel end-to-end trainable deep network is proposed for MLTC. The model employs Graph Attention Network (GAT) to find the correlation between labels.
|
| 39 |
+
- It shows that the proposed method achieves similar or better performance compared to previous State-of-the-art(SoTA) models across two MLTC metrics and five MLTC datasets.
|
| 40 |
+
|
| 41 |
+
## 2 RELATED WORK
|
| 42 |
+
|
| 43 |
+
The MLTC task can be modeled as finding an optimal label sequence y ∗ that maximizes the conditional probability p ( y | x ) , which is calculated as follows:
|
| 44 |
+
|
| 45 |
+
<!-- formula-not-decoded -->
|
| 46 |
+
|
| 47 |
+
There are mainly three types of methods to solve the MLTC task:
|
| 48 |
+
|
| 49 |
+
- Problem transformation methods
|
| 50 |
+
- Algorithm adaptation methods
|
| 51 |
+
- Neural network models
|
| 52 |
+
|
| 53 |
+
## 2.1 Problem transformation methods
|
| 54 |
+
|
| 55 |
+
Problem transformation methods transform the multilabel classification problem either into one or more single-label classification or regression problems. Most popular problem transformation method is Binary relevance (BR) (Boutell et al., 2004), BR learns a separate classifier for each label and combines the result of all classifiers into a multi-label prediction by ignoring the correlations between labels. Label Powers(LP) treats a multi-label problem as a multiclass problem by training a multi-class classifier on all unique combinations of labels in the dataset. Classifier Chains (CC) transform the multi-label text classification problem into a Bayesian conditioned chain of the binary text classification problem. However, the problem transformation method takes a lot of time and space if the dataset and labels are too large.
|
| 56 |
+
|
| 57 |
+
## 2.2 Algorithm adaptation methods
|
| 58 |
+
|
| 59 |
+
Algorithm adaptation, on the other hand, adapts the algorithms to handle multi-label data directly, instead of transforming the data. Clare and King (2001) construct a decision tree by modifying the c4.5 algorithm (Quinlan, 1993) and develop resampling strategies. (Elisseeff and Weston 2002) propose the RankSVMbyamending a Support Vector Machine (SVM). (Zhang and Zhou 2007) propose a multi-label lazy learning approach (ML-KNN), ML-KNN uses correlations of different labels by adopting the traditional K-nearest neighbor (KNN) algorithm. However, the algorithm adaptation method is limited to utilizing only the first or second order of label correlation.
|
| 60 |
+
|
| 61 |
+
## 2.3 Neural network models
|
| 62 |
+
|
| 63 |
+
In recent years, various Neural network-based models are used for MLTC task. For example, (Yang et al., 2016) propose hierarchical attention networks (HAN), uses the GRU gating mechanism with hierarchical attention for document classification. Zhang and Zhou (2006) propose a framework called Backpropagation for multilabel learning (BP-MLL) that learns ranking errors in neural networks via backpropagation. However, these types of neural networks don't perform well on high dimensional and largescale data.
|
| 64 |
+
|
| 65 |
+
Many CNN based model, RCNN (Lai et al., 2015), Ensemble method of CNN and RNN by Chen et al. (2017), XML-CNN (Liu et al., 2017), CNN (Kim, 2014a) and TEXTCNN (Kim, 2014a) have been proposed to solve the MLTC task. However, they neglect the correlations between labels.
|
| 66 |
+
|
| 67 |
+
To utilise the relation between the labels some Hierarchical text classification models have been proposed, Transfer learning idea proposed by (Xiao et al., 2011) uses hierarchical Support Vector Machine (SVM), (Gopal et al., 2012) and (Gopal and Yang, 2015) uses hierarchical and graphical dependencies between class-labels, (Peng et al., 2018) utilize the graph operation on the graph of words. However, these methods are limited as they consider only pair-wise relation due to computational constraints.
|
| 68 |
+
|
| 69 |
+
Recently, the BERT language model achieves state-of-the-art performance in many NLP tasks. (Devlin et al., 2019b)
|
| 70 |
+
|
| 71 |
+
## 3 MAGNET ARCHITECTURE
|
| 72 |
+
|
| 73 |
+
## 3.1 Graph representation of labels
|
| 74 |
+
|
| 75 |
+
Agraph G consists of a feature description M ∈ R n × d and the corresponding adjacency matrix A ∈ R n × n where n denotes the number of labels and d denotes the number of dimensions.
|
| 76 |
+
|
| 77 |
+
GAT network takes the node features and adjacency matrix that represents the graph data as inputs. The adjacency matrix is constructed based on the samples. In our case, we do not have a graph dataset. Instead, we learn the adjacency matrix, hoping that the model will determine the graph, thereby learning the correlation of the labels.
|
| 78 |
+
|
| 79 |
+
Our intuition is that by modeling the correlation among labels as a weighted graph, we force the GAT network to learn such that the adjacency matrix and the attention weights together represent the correlation. We use three methods to initialize the weights of the adjacency matrix. Section 3.5 explains the initialization methods in detail.
|
| 80 |
+
|
| 81 |
+
In the context of our model, the embedding vectors of the labels act as the node features, and the adjacency matrix is a learn-able parameter.
|
| 82 |
+
|
| 83 |
+
## 3.2 Node updating Mechanism in Graph convolution
|
| 84 |
+
|
| 85 |
+
In Graph Convolution Network Nodes can be updated by different types of node updating mechanisms. The basic version of GCN updates each node i of the ℓ -th layer, H ( ℓ + 1 ) i , as follows.
|
| 86 |
+
|
| 87 |
+
<!-- formula-not-decoded -->
|
| 88 |
+
|
| 89 |
+
Where s ( · ) denote an activation function, A is an adjacency matrix and W ( ℓ ) is the convolution weights of the ℓ -th layer. We represent each node of the graph structure as a label; at each layer, the label's features are aggregated by neighbors to form the label features of the next layer. In this way, features become increasingly more abstract at each consecutive layer. e.g., label 2 has three adjacent labels 1, 3 and 4. In this case, another way to write equation (2) is
|
| 90 |
+
|
| 91 |
+
<!-- formula-not-decoded -->
|
| 92 |
+
|
| 93 |
+
So, in this case, the graph convolution network sums up all labels features with the same convolution weights, and then the result is passed through one activation function to produce the updated node feature output.
|
| 94 |
+
|
| 95 |
+
## 3.3 Graph Attention Networks for multi-label classification
|
| 96 |
+
|
| 97 |
+
In GCNs, the neighborhoods of nodes combine with equal or pre-defined weights. However, the influence of neighbors can vary greatly, and the attention mechanism can identify label importance in correlation graph by considering the importance of their neighbor labels.
|
| 98 |
+
|
| 99 |
+
The node updating mechanism, equation (3), can be written as a linear combination of neighboring labels with attention coefficients.
|
| 100 |
+
|
| 101 |
+
<!-- formula-not-decoded -->
|
| 102 |
+
|
| 103 |
+
where a ℓ i j is an attention coefficient which measures the importance of the j th node in updating the i th node of the ℓ -th hidden layer. The basic expression of the attention coefficient can be written as
|
| 104 |
+
|
| 105 |
+
<!-- formula-not-decoded -->
|
| 106 |
+
|
| 107 |
+
Figure 1: Illustration of overall structure of MAGNET model with a single Graph Attention layer for multi label text classification. ( x ( n ) , y ( n ) ) , n = 1 , 2 , . . . , N is input for BiLSTM to generate the feature vectors. x ( n ) are encoded using BERT embeddings. Input for Graph attention network is the Adjacency matrix A ∈ R n × n and label vectors M ∈ R n × d GAT output is attended label features which is applied on the feature vectors obtained from the BiLSTM
|
| 108 |
+
|
| 109 |
+
<!-- image -->
|
| 110 |
+
|
| 111 |
+
The attention coefficient can be obtained typically by i) a similarity base, ii) concatenating features, and iii) coupling all features. We evaluate the attention coefficient by concatenating features.
|
| 112 |
+
|
| 113 |
+
<!-- formula-not-decoded -->
|
| 114 |
+
|
| 115 |
+
In our experiment, we are using multi-head attention (Vaswani et al., 2017) that utilizes K different heads to describe labels relationships. The operations of the layer are independently replicated K times (each replication is done with different parameters), and the outputs are aggregated feature wise (typically by concatenating or adding).
|
| 116 |
+
|
| 117 |
+
<!-- formula-not-decoded -->
|
| 118 |
+
|
| 119 |
+
Where a i j is the attention coefficient of label j to i . N ( i ) represents the neighborhood of label i in the graph. We use a cascade of GAT layers. For first layer the input is label embedding matrix M ∈ R n × d .
|
| 120 |
+
|
| 121 |
+
.
|
| 122 |
+
|
| 123 |
+
<!-- formula-not-decoded -->
|
| 124 |
+
|
| 125 |
+
The output from the previous GAT layer is fed into the successive GAT layer similar to RNN but the GAT layer weights are not shared
|
| 126 |
+
|
| 127 |
+
<!-- formula-not-decoded -->
|
| 128 |
+
|
| 129 |
+
The output from the last layer is the attended label features Hgat ∈ R c × d where c denotes the number of labels and d denotes the dimension of the attended label features. which is applied to the textual features from the BiLSTM.
|
| 130 |
+
|
| 131 |
+
## 3.4 Feature vector generation
|
| 132 |
+
|
| 133 |
+
We are using bidirectional LSTM (Hochreiter and Schmidhuber, 1997) to obtain the feature vectors. We use BERT for embedding the words and then feed it to BiLSTM for fine-tuning for the domain-specific task, BiLSTM reads the text sequence x from both directions and computes the hidden states for each word,
|
| 134 |
+
|
| 135 |
+
<!-- formula-not-decoded -->
|
| 136 |
+
|
| 137 |
+
We obtain the final hidden representation of the i -th word by concatenating the hidden states from both directions,
|
| 138 |
+
|
| 139 |
+
<!-- formula-not-decoded -->
|
| 140 |
+
|
| 141 |
+
<!-- formula-not-decoded -->
|
| 142 |
+
|
| 143 |
+
Where s is the sentence, q rnn is Rnn parameters, q BERT is BERTs parameter, D is hidden size of BiLSTM. Later we multiply feature vectors with attended label features to get the final prediction score as,
|
| 144 |
+
|
| 145 |
+
<!-- formula-not-decoded -->
|
| 146 |
+
|
| 147 |
+
Where Hgat ∈ R c × d and F is feature vectors obtained from BiLSTM model. Figure 1 shows the overall structure of the proposed model.
|
| 148 |
+
|
| 149 |
+
## 3.5 Adjacency matrix generation
|
| 150 |
+
|
| 151 |
+
In this section, we explain how to initialize the adjacency matrix for the GAT network. We use three different methods to initialize the weights..
|
| 152 |
+
|
| 153 |
+
- Identity Matrix We use the Identity matrix as the adjacency matrix. Ones on the main diagonal and zeros elsewhere, i.e., starting with zero correlation as a starting point.
|
| 154 |
+
- Xavier initialization We use Xavier initialization (Glorot and Bengio, 2010) to initialize the weight of adjacency matrix.
|
| 155 |
+
|
| 156 |
+
<!-- formula-not-decoded -->
|
| 157 |
+
|
| 158 |
+
where ni is the number of incoming network connections.
|
| 159 |
+
|
| 160 |
+
## · Correlation matrix
|
| 161 |
+
|
| 162 |
+
The correlation matrix is constructed by counting the pairwise co-occurrence of labels. The frequency vector is vector F ∈ R n where n is the number of labels and Fi is the frequency of label i in the overall training set. The co-occurrence matrix is then normalized by the frequency vector.
|
| 163 |
+
|
| 164 |
+
<!-- formula-not-decoded -->
|
| 165 |
+
|
| 166 |
+
where M ∈ R n × n is the co-occurrence matrix and F ∈ R n is the frequency vector of individual labels. This is similar to how the correlation matrix built-in (Chen et al., 2019), except we do not employ binarization.
|
| 167 |
+
|
| 168 |
+
## 3.6 Loss function
|
| 169 |
+
|
| 170 |
+
We use Cross-entropy as the loss function. If the ground truth label of a data point is y ∈ R c , where yi = { 0 , 1 }
|
| 171 |
+
|
| 172 |
+
<!-- formula-not-decoded -->
|
| 173 |
+
|
| 174 |
+
Where s is sigmoid activation function
|
| 175 |
+
|
| 176 |
+
## 4 EXPERIMENT
|
| 177 |
+
|
| 178 |
+
In this section, we introduce the datasets, experiment details, and baseline results. Subsequently, the authors make a comparison of the proposed methods with baselines
|
| 179 |
+
|
| 180 |
+
## 4.1 Datasets
|
| 181 |
+
|
| 182 |
+
In this section, we provide detail and use the source of the datasets in the experiment. Table 2 shows the Statistics of all datasets.
|
| 183 |
+
|
| 184 |
+
Reuters-21578 is a collection of documents collected from Reuters News Wire in 1987. The Reuters-21578 test collection, together with its earlier variants, has been such a standard benchmark for the text categorization (TC) (Debole and Sebastiani, 2005). It contains 10,788 documents, which has 8,630 documents for training and 2,158 for testing with a total of 90 categories.
|
| 185 |
+
|
| 186 |
+
RCV1-V2 provided by Lewis et al. (2004) (Lewis et al., 2004), consists of categorized newswire stories made available by Reuters Ltd. Each newswire story can have multiple topics assigned to it, with 103 topics in total. RCV1-V2 contains 8,04,414 documents which are divided into 6,43,531 documents for training and 1,60,883 for testing.
|
| 187 |
+
|
| 188 |
+
Arxiv Academic Paper Dataset (AAPD) is provided by Yang et al. (2018). The dataset consists of the abstract and its corresponding subjects of 55,840 academic papers, and each paper can have multiple subjects. The target is to predict subjects of an academic paper according to the content of the abstract. The AAPD dataset then divides into 44,672 documents for training and 11,168 for testing with a total of 54 classes.
|
| 189 |
+
|
| 190 |
+
Slashdot dataset was collected from the Slashdot website and consists of article blurbs labeled with the subject categories. Slashdot contains 19,258 samples for training and 4,814 samples for testing with a total of 291 classes.
|
| 191 |
+
|
| 192 |
+
Toxic comment dataset , We are using toxic comment dataset from Kaggle. This dataset has large number of comments from Wikipedia talk page edits. Human raters have labeled them for toxic behavior.
|
| 193 |
+
|
| 194 |
+
## 4.2 Experiment details
|
| 195 |
+
|
| 196 |
+
We implement our experiments in Tensorflow on an NVIDIA 1080Ti GPU. Our model consists of two GAT layers with multi-head attention. Table 1 shows the hyper-parameters of the model on five datasets. For label representations, we adopt 768 dim BERT trained on Wikipedia and BookCorpus. For the categories whose names contain multiple words, we obtain the label representation as to the average of embeddings for all words. For all datasets, the batch size is set to 250, and out of vocabulary(OOV) words are replaced with unk . We use BERT embedding to encode the sentences. We use Adam optimizer to minimize the final objective function. The learning rate is initialized to 0.001 and we make use of the dropout 0.5 (Srivastava et al. 2014) to avoid overfitting and clip the gradients (Pascanu, Mikolov, and Bengio 2013) to the maximum norm of 10.
|
| 197 |
+
|
| 198 |
+
## 4.3 Performance Evaluation
|
| 199 |
+
|
| 200 |
+
miF1 In the micro-average method, the individual true positives, false positives, and false negatives of the system are summed up for different sets and applied to get Micro-average F-Score.
|
| 201 |
+
|
| 202 |
+
<!-- formula-not-decoded -->
|
| 203 |
+
|
| 204 |
+
Hamming loss (HL): Hamming-Loss is the fraction of labels that are incorrectly predicted. (Destercke, 2014). Therefore, hamming loss takes into account the prediction of both an incorrect label and a missing label normalized over the total number of classes and the total number of examples.
|
| 205 |
+
|
| 206 |
+
<!-- formula-not-decoded -->
|
| 207 |
+
|
| 208 |
+
where yi , j is the target and zi , j is the prediction. Ideally, we would expect Hamming loss, HL = 0, which would imply no error; practically the smaller the value of hamming loss , the better the performance of the learning algorithm.
|
| 209 |
+
|
| 210 |
+
## 4.4 Comparison of methods
|
| 211 |
+
|
| 212 |
+
We compare the performance of 27 algorithms, including state-of-the-art models. Furthermore, we compare the latest state-of-the-art models on the rcv1v2 dataset. Compared algorithms can be categorized into three groups, as described below:
|
| 213 |
+
|
| 214 |
+
- Flat baselines Flat Baseline models transform the documents and extract the features using TF-IDF (Ramos, ), later use those features as input to Logistic regression (LR) (Allison, 1999) , Support Vector Machine (SVM) (Hearst, 1998) , Hierarchical Support Vector Machine (HSVM) (Vural and Dy, 2004) , Binary Relevance (BR) (Boutell et al., 2004), Classifier Chains (CC)(Read et al., 2011). Flat Baseline methods ignore the relation between words and dependency between labels.
|
| 215 |
+
|
| 216 |
+
## · Sequence, Graph and N-gram based models
|
| 217 |
+
|
| 218 |
+
These types of models first transform the text dataset into sequences of words, the graph of words or N-grams features, later apply different types of deep learning models on those features including CNN (Kim, 2014b), CNN-RNN (Chen et al., 2017), RCNN (Lai et al., 2015), DCNN (Schwenk et al., 2017), XML-CNN (Liu et al., 2017), HR-DGCNN (Peng et al., 2018), Hierarchical LSTM (HLSTM) (Chen et al., 2016), multi-label classification approach based on a conditional cyclic directed graphical model (CDN-SVM) (Guo and Gu, 2011), Hierarchical Attention Network (HAN) (Yang et al., 2016) and Bi-directional Block Self-Attention Network (BiBloSAN) (Shen et al., 2018) etc. for the multilabel classification task For example, Hierarchical Attention Networks for Document Classification (HAN) uses a GRU grating mechanism to encode the sequences and apply word and sentence level attention on those sequences for document classification. Bi-directional Block SelfAttention Network (BI-BloSAN) uses intra-block and inter-block self-attentions to capture both local and long-range context dependencies by splitting the sequences into several blocks.
|
| 219 |
+
|
| 220 |
+
Table 1: Main experimental hyper-parameters
|
| 221 |
+
|
| 222 |
+
| Dataset Vocab Size Embed size Hidden size Attention heads Reuters-21578 20,000 768 250 4 RCV1-V2 50,000 768 250 8 AAPD 30,000 768 250 8 Slashdot 30,000 768 300 4 Toxic Comment 50,000 768 200 8 |
|
| 223 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 224 |
+
|
| 225 |
+
Table 2: Statistics of the datasets
|
| 226 |
+
|
| 227 |
+
| Dataset Domain #Train #Test Labels Reuters-21578 Text 8,630 2,158 90 RCV1-V2 Text 6,43,531 1,60,883 103 AAPD Text 44,672 11,168 54 Slashdot Text 19,258 4,814 291 Toxic Comment Text 126,856 31,714 7 |
|
| 228 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 229 |
+
|
| 230 |
+
## · Recent state-of-the-art models
|
| 231 |
+
|
| 232 |
+
Wecompare our model with different state-of-theart models for multi-label classification task including BP-MLL RAD (Nam et al., 2014), Input Encoding with Feature Message Passing (FMP) (Lanchantin et al., 2019), TEXT-CNN (Kim, 2014a), Hierarchical taxonomy-aware and attentional graph capsule recurrent CNNs framework (HE-AGCRCNN) (Peng et al., 2019), BOWCNN (Johnson and Zhang, 2014), Capsule-B networks (Zhao et al., 2018), Hierarchical Text Classification with Reinforced Label Assignment (HiLAP) (Mao et al., 2019), Hierarchical Text Classification with Recursively Regularized Deep Graph-CNN (HR-DGCNN) (Peng et al., 2018), Hierarchical Transfer Learning-based Strategy (HTrans) (Banerjee et al., 2019), BERT (Bidirectional Encoder Representations from Transformers)(Devlin et al., 2019b), BERT-SGM (Yarullin and Serdyukov, 2019), For example FMP + LaMP is a variant of LaMP model which uses Input Encoding with Feature Message Passing (FMP). It achieves state-of-the-art accuracy across five metrics and seven datasets. HEAGCRCNN uses a hierarchical taxonomy embedding method to learn the hierarchical relations among the labels.is another recent state-of-the-art model, which has shown outstanding performance in large-scale multi-label text classification. It uses a hierarchical taxonomy embedding method to learn the hierarchical relations among the labels. BERT (Bidirectional Encoder Representa- tions from Transformers) is a recent pre-trained language model that has shown groundbreaking results in many NLP tasks. BERT uses attention mechanism (Transformer) to learns contextual relations between words in a text.
|
| 233 |
+
|
| 234 |
+
## 5 PERFORMANCE ANALYSIS
|
| 235 |
+
|
| 236 |
+
In this section, we will compare our proposed method with baselines on the test sets. Table 4 shows the detailed Comparisons of Micro F1-score for various state-of-the-art models.
|
| 237 |
+
|
| 238 |
+
## 5.1 Comparisons with State-of-the-art
|
| 239 |
+
|
| 240 |
+
First, we compare the result of Traditional Machine learning algorithms. Among LR, SVM, and HSVM, HSVM performs better than the other two. HSVM uses SVM at each node of the Decision tree. Later we compare the result of Hierarchical, CNN based models and graph-based deep learning models. Among Hierarchical Models HLSTM, HAN, HE-AGCRCNN, HR-DGCNN, HiLAP, and HTrans, HE-AGCRCNN performs better compared to other Hierarchical models. HAN and HLSTM methods are based on recurrent neural networks. While analyzing the performance of the recurrent model with baseline Flat models, recurrent neural networks perform worse than HSVM even though there was an ignorance of label dependency in baseline models. RNN faces the problem of vanishing gradients and exploding gradients when the sequences are too long. Graph model, HR-DGCNN, performs better than recurrent and baseline models. Comparing the CNN-based model RCNN, XML-CNN, DCNN, TEXTCNN, CNN, and CNN-RNN, TEXTCNN performs better among all of them while RCNN performs worse among them.
|
| 241 |
+
|
| 242 |
+
The sequence generator model treats the multilabel classification task as a sequence generation. When comparing the sequence generator models SGM-GE and seq2seq, SGM performs better than the seq2seq network. SGM utilizes the correlation between labels by using sequence generator model with a novel decoder structure.
|
| 243 |
+
|
| 244 |
+
Comparing the proposed MAGNET against the state-of-the-art models, MAGNET significantly improved previous state-of-the-art results, we see ~20% improvement in miF1 comparison to HSVM model. While comparing with the best Hierarchical text classification models, we observe ~11%, ~19%, ~5% and ~8% accuracy improvement compared to HEAGCRCNN, HAN, HiLAP, HTrans respectively. The proposed model produced a ~16% improvement in miF1 over the popular bi-directional block selfattention network (Bi-BloSAN).
|
| 245 |
+
|
| 246 |
+
Comparing with CNN group models, proposed model improves the performance by ~12% and ~6% accuracy compared with TEXTCNN and BOW-CNN method respectively. MAGNET achieves ~2% improvement over state-of-the-art BERT model.
|
| 247 |
+
|
| 248 |
+
## 5.2 Evaluation on other datasets
|
| 249 |
+
|
| 250 |
+
We also evaluate our proposed model on four different datasets rather than RCV1 to observe the performance of the model on those datasets, which vary in the number of samples and the number of labels. Table 3 shows the miF1 scores for different datasets, and we also report the Hamming loss in Table 5. Evaluation results show that proposed methods achieve the best performance in the primary evaluation metrics. Weobserve 3% and 4% miF1 improvement in AAPD and Slashdot dataset, respectively, as compared to the CNN-RNN method.
|
| 251 |
+
|
| 252 |
+
## 5.3 Analysis and Discussion
|
| 253 |
+
|
| 254 |
+
Here we discuss a further analysis of the model and experimental results. We report the evaluation results in terms of hamming loss and macro-F1 score. We are using a moving average with a window size of 3 to draw the plots to make the scenarios more comfortable to read.
|
| 255 |
+
|
| 256 |
+
## 5.3.1 Impact of initialization of the adjacency matrix
|
| 257 |
+
|
| 258 |
+
We initialized the adjacency matrix in three different ways random, identity, and co-occurrence matrix. We hypothesized that the co-occurrence matrix would perform the best since the model is fed with richer prior information than the identity matrix, where the correlation is zero and random matrix. To our surprise, random initialization performed the best at 0.887, and identity matrix performed the worst at 0.865, whereas the co-occurrence matrix achieved the micro-F1 score of 0.878. Even though Xavier initializer performed the best, all the other random initializers performed better than co-occurrence and identity matrices. This shows that the textual information from samples contain richer information than that in the label co-occurrence matrix that we initialize the adjacency with, and both co-occurrence and identity matrix, traps the model in a local minima.
|
| 259 |
+
|
| 260 |
+
## 5.3.2 Results on different types of word embeddings
|
| 261 |
+
|
| 262 |
+
In this section, we investigate the impact of the four different word embeddings on our proposed architecture, namely the Word2Vec embeddings(Mikolov et al., 2013), Glove embeddings (Pennington et al., 2014), Random embeddings, BERT embeddings (Devlin et al., 2019a). Figure (2) and Figure (3) shows the f1 score of all four different word embeddings on the (unseen) test dataset of Reuters-21578.
|
| 263 |
+
|
| 264 |
+
Figure 2: Different types of word embeddings performance on MAGNET x axis refer to the different types of word embeddings and y axis refer to the Accuracy ( F1-score)
|
| 265 |
+
|
| 266 |
+
<!-- image -->
|
| 267 |
+
|
| 268 |
+
Accordingly, we make the following observations:
|
| 269 |
+
|
| 270 |
+
- Glove and word2vec embeddings produce similaer results.
|
| 271 |
+
- Random embeddings perform worse than other embeddings. Pre-trained word embeddings have
|
| 272 |
+
|
| 273 |
+
Table 3: Comparisons of Micro F1-score for various models on four benchmark datasets.
|
| 274 |
+
|
| 275 |
+
| F1-accuracy Methods Reuters- 21578 AAPD Slashdot Toxic BR 0.878 0.648 0.486 0.853 BR-support 0.872 0.682 0.516 0.874 CC 0.879 0.654 0.480 0.893 CNN 0.863 0.664 0.512 0.775 CNN-RNN 0.855 0.669 0.530 0.904 MAGNET 0.899 0.696 0.568 0.930 |
|
| 276 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 277 |
+
|
| 278 |
+
Table 4: Comparisons of Micro F1-score for various state-of-the-art models on Rcv1-v2 dataset.
|
| 279 |
+
|
| 280 |
+
| Rcv1-v2 Method Accuracy LR 0.692 SVM 0.691 HSVM 0.693 HLSTM 0.673 RCNN 0.686 XML-CNN 0.695 HAN 0.696 Bi-BloSAN 0.72 DCNN 0.732 SGM+GE 0.719 CAPSULE-B 0.739 CDN-SVM 0.738 HR-DGCNN 0.761 TEXTCNN 0.766 HE-AGCRCNN 0.778 BP-MLL RAD 0.780 HTrans 0.805 BOW-CNN 0.827 HilAP 0.833 BERT 0.864 BERT + SGM 0.846 FMP + LaMP pr 0.877 MAGNET 0.885 |
|
| 281 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 282 |
+
|
| 283 |
+
proven to be highly useful in our proposed architecture compared to the random embeddings.
|
| 284 |
+
|
| 285 |
+
- BERT embeddings outperform other embeddings in this experiment. Therefore, using BERT feature embeddings increase the accuracy and performance of our architecture.
|
| 286 |
+
|
| 287 |
+
Our proposed model uses BERT embeddings for encoding the sentences.
|
| 288 |
+
|
| 289 |
+
Figure 3: Performance of proposed model on different types of word embeddings. x-axis is the number of epoch and the y-axis refers to the micro-F1 score.
|
| 290 |
+
|
| 291 |
+
<!-- image -->
|
| 292 |
+
|
| 293 |
+
## 5.3.3 Comparison between Two different Graph neural networks
|
| 294 |
+
|
| 295 |
+
In this section, we compare the performance of GAT and GCN networks. The critical difference between GAT and GCN is how the information aggregates from the neighborhood. GAT computes the hidden states of each node by attending over its neighbors, following a self-attention strategy where GCN produces the normalized sum of the node features of neighbors.
|
| 296 |
+
|
| 297 |
+
GATimproved the average miF1 score by 4% over the GCN model. It shows that the GAT model captures better label correlation compare to GCN. The attention mechanism can identify label importance in correlation graph by considering the significance of their neighbor labels.
|
| 298 |
+
|
| 299 |
+
Table 5: Comparisons of hamming loss for various models on four benchmark datasets. the smaller the value, the better.
|
| 300 |
+
|
| 301 |
+
| Hamming-loss Methods Rcv1-v2 AAPD Reuters- 21578 Slashdot Toxic BR 0.0093 0.0316 0.0032 0.052 0.034 CC 0.0089 0.0306 0.0031 0.057 0.030 CNN 0.0084 0.0287 0.0033 0.049 0.039 CNN-RNN 0.0086 0.0282 0.0037 0.046 0.025 MAGNET 0.0079 0.0252 0.0029 0.039 0.022 |
|
| 302 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 303 |
+
|
| 304 |
+
Figure 4: Performance of GAT vs GCN. x-axis is number of epochs and y-axis is micro-F1 score.
|
| 305 |
+
|
| 306 |
+
<!-- image -->
|
| 307 |
+
|
| 308 |
+
Figure (4) shows the accuracy of both neural network on Reuters-21578 dataset.
|
| 309 |
+
|
| 310 |
+
## 5.4 Conclusion
|
| 311 |
+
|
| 312 |
+
The proposed approach can improve the accuracy and efficiency of models and can work across a wide range of data types and applications. To model and capture the correlation between labels, we proposed a GAT based model for multi-label text classification.
|
| 313 |
+
|
| 314 |
+
We evaluated the proposed model on various datasets and presented the results. The combination of GAT with bi-directional LSTM shows that it has achieved consistently higher accuracy than those obtained by conventional approaches.
|
| 315 |
+
|
| 316 |
+
Even though our proposed model performs very well, there are still some limitations. When the dataset contains a large number of labels correlation matrix will be very large, and training the model can be difficult. Our work alleviates this problem to some extent, but we still think the exploration of more effective solutions is vital in the future.
|
| 317 |
+
|
| 318 |
+
## REFERENCES
|
| 319 |
+
|
| 320 |
+
- Allison, P. (1999). Logistic Regression Using Sas®: Theory and Application . SAS Publishing, first edition.
|
| 321 |
+
- Banerjee, S., Akkaya, C., Perez-Sorrosal, F., and Tsioutsiouliklis, K. (2019). Hierarchical transfer learning for multi-label text classification. In Proceedings of the 57th Conference of the Association for Computational Linguistics, ACL 2019, Florence, Italy, July 28August 2, 2019, Volume 1: Long Papers , pages 62956300.
|
| 322 |
+
- Boutell, M. R., Luo, J., Shen, X., and Brown, C. M. (2004). Learning multi-label scene classification. Pattern Recognition , 37(9):1757 - 1771.
|
| 323 |
+
- Cai, H., Zheng, V. W., and Chang, K. C. (2017). A comprehensive survey of graph embedding: Problems, techniques and applications. CoRR , abs/1709.07604.
|
| 324 |
+
- Chen, G., Ye, D., Xing, Z., Chen, J., and Cambria, E. (2017). Ensemble application of convolutional and recurrent neural networks for multi-label text categorization. In 2017 International Joint Conference on Neural Networks (IJCNN) , pages 2377-2383.
|
| 325 |
+
- Chen, H., Sun, M., Tu, C., Lin, Y., and Liu, Z. (2016). Neural sentiment classification with user and product attention. In Proceedings of the 2016 Conference on Empirical Methods in Natural Language Processing, EMNLP 2016, Austin, Texas, USA, November 1-4, 2016 , pages 1650-1659.
|
| 326 |
+
|
| 327 |
+
Chen, Z.-M., Wei, X.-S., Wang, P., and Guo, Y. (2019). Multi-Label Image Recognition with Graph Convolutional Networks. In The IEEE Conference on Computer Vision and Pattern Recognition (CVPR) .
|
| 328 |
+
|
| 329 |
+
- Debole, F. and Sebastiani, F. (2005). An analysis of the relative hardness of reuters-21578 subsets: Research articles. J. Am. Soc. Inf. Sci. Technol. , 56(6):584-596.
|
| 330 |
+
- Destercke, S. (2014). Multilabel prediction with probability sets: The hamming loss case. In Information Processing and Management of Uncertainty in KnowledgeBased Systems - 15th International Conference, IPMU 2014, Montpellier, France, July 15-19, 2014, Proceedings, Part II , pages 496-505.
|
| 331 |
+
- Devlin, J., Chang, M., Lee, K., and Toutanova, K. (2019a). BERT: pre-training of deep bidirectional transformers for language understanding. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, NAACL-HLT 2019, Minneapolis, MN, USA, June 2-7, 2019, Volume 1 (Long and Short Papers) , pages 4171-4186.
|
| 332 |
+
- Devlin, J., Chang, M.-W., Lee, K., and Toutanova, K. (2019b). Bert: Pre-training of deep bidirectional transformers for language understanding. In NAACLHLT .
|
| 333 |
+
- Fout, A., Byrd, J., Shariat, B., and Ben-Hur, A. (2017). Protein interface prediction using graph convolutional networks. In Proceedings of the 31st International Conference on Neural Information Processing Systems , NIPS'17, pages 6533-6542, USA. Curran Associates Inc.
|
| 334 |
+
- Glorot, X. and Bengio, Y. (2010). Understanding the difficulty of training deep feedforward neural networks. In Proceedings of the Thirteenth International Conference on Artificial Intelligence and Statistics, AISTATS 2010, Chia Laguna Resort, Sardinia, Italy, May 1315, 2010 , pages 249-256.
|
| 335 |
+
- Gopal, S. and Yang, Y. (2010). Multilabel classification with meta-level features. pages 315-322.
|
| 336 |
+
- Gopal, S. and Yang, Y. (2015). Hierarchical bayesian inference and recursive regularization for large-scale classification. TKDD , 9(3):18:1-18:23.
|
| 337 |
+
- Gopal, S., Yang, Y., Bai, B., and Niculescu-Mizil, A. (2012). Bayesian models for large-scale hierarchical classification. In Advances in Neural Information Processing Systems 25: 26th Annual Conference on Neural Information Processing Systems 2012. Proceedings of a meeting held December 3-6, 2012, Lake Tahoe, Nevada, United States , pages 2420-2428.
|
| 338 |
+
- Guo, Y. and Gu, S. (2011). Multi-label classification using conditional dependency networks. In IJCAI 2011, Proceedings of the 22nd International Joint Conference on Artificial Intelligence, Barcelona, Catalonia, Spain, July 16-22, 2011 , pages 1300-1305.
|
| 339 |
+
- Hearst, M. A. (1998). Support vector machines. IEEE Intelligent Systems , 13(4):18-28.
|
| 340 |
+
- Johnson, R. and Zhang, T. (2014). Effective use of word order for text categorization with convolutional neural networks. CoRR , abs/1412.1058.
|
| 341 |
+
- Katakis, I., Tsoumakas, G., and Vlahavas, I. (2008). Multilabel text classification for automated tag suggestion. In Proceedings of the ECML/PKDD 2008 Discovery Challenge .
|
| 342 |
+
- Kim, Y. (2014a). Convolutional neural networks for sentence classification. In Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing, EMNLP 2014, October 25-29, 2014,
|
| 343 |
+
- Doha, Qatar, A meeting of SIGDAT, a Special Interest Group of the ACL , pages 1746-1751.
|
| 344 |
+
- Kim, Y. (2014b). Convolutional neural networks for sentence classification. CoRR , abs/1408.5882.
|
| 345 |
+
- Kipf, T. N. and Welling, M. (2016). Semi-supervised classification with graph convolutional networks. CoRR , abs/1609.02907.
|
| 346 |
+
- Lai, S., Xu, L., Liu, K., and Zhao, J. (2015). Recurrent convolutional neural networks for text classification. In Proceedings of the Twenty-Ninth AAAI Conference on Artificial Intelligence, January 25-30, 2015, Austin, Texas, USA , pages 2267-2273.
|
| 347 |
+
- Lanchantin, J., Sekhon, A., and Qi, Y. (2019). Neural message passing for multi-label classification. CoRR , abs/1904.08049.
|
| 348 |
+
- Lewis, D. D., Yang, Y., Rose, T. G., and Li, F. (2004). Rcv1: A new benchmark collection for text categorization research. J. Mach. Learn. Res. , 5:361-397.
|
| 349 |
+
- Liu, J., Chang, W., Wu, Y., and Yang, Y. (2017). Deep learning for extreme multi-label text classification. In Proceedings of the 40th International ACM SIGIR Conference on Research and Development in Information Retrieval, Shinjuku, Tokyo, Japan, August 7-11, 2017 , pages 115-124.
|
| 350 |
+
- Luaces, O., D´ ıez, J., Barranquero, J., del Coz, J. J., and Bahamonde, A. (2012). Binary relevance efficacy for multilabel classification. Progress in Artificial Intelligence , 1(4):303-313.
|
| 351 |
+
- Mao, Y., Tian, J., Han, J., and Ren, X. (2019). Hierarchical text classification with reinforced label assignment. CoRR , abs/1908.10419.
|
| 352 |
+
- Mikolov, T., Sutskever, I., Chen, K., Corrado, G. S., and Dean, J. (2013). Distributed representations of words and phrases and their compositionality. In Advances in Neural Information Processing Systems 26: 27th Annual Conference on Neural Information Processing Systems 2013. Proceedings of a meeting held December 5-8, 2013, Lake Tahoe, Nevada, United States. , pages 3111-3119.
|
| 353 |
+
- Nam, J., Kim, J., Loza Menc'ia, E., Gurevych, I., and F¨ urnkranz, J. (2014). Large-scale multi-label text classification - revisiting neural networks. In Machine Learning and Knowledge Discovery in Databases European Conference, ECML PKDD 2014, Nancy, France, September 15-19, 2014. Proceedings, Part II , pages 437-452.
|
| 354 |
+
- Peng, H., Li, J., Gong, Q., Wang, S., He, L., Li, B., Wang, L., and Yu, P. S. (2019). Hierarchical taxonomy-aware and attentional graph capsule rcnns for large-scale multi-label text classification. CoRR , abs/1906.04898.
|
| 355 |
+
- Peng, H., Li, J., He, Y., Liu, Y., Bao, M., Wang, L., Song, Y., and Yang, Q. (2018). Large-scale hierarchical text classification with recursively regularized deep graphcnn. In Proceedings of the 2018 World Wide Web Conference on World Wide Web, WWW 2018, Lyon, France, April 23-27, 2018 , pages 1063-1072.
|
| 356 |
+
- Pennington, J., Socher, R., and Manning, C. D. (2014). Glove: Global vectors for word representation. In Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing, EMNLP
|
| 357 |
+
|
| 358 |
+
2014, October 25-29, 2014, Doha, Qatar, A meeting of SIGDAT, a Special Interest Group of the ACL , pages 1532-1543.
|
| 359 |
+
|
| 360 |
+
- Quinlan, J. R. (1993). C4.5: Programs for Machine Learning . Morgan Kaufmann Publishers Inc., San Francisco, CA, USA.
|
| 361 |
+
- Ramos, J. Using tf-idf to determine word relevance in document queries.
|
| 362 |
+
- Read, J., Pfahringer, B., Holmes, G., and Frank, E. (2011). Classifier chains for multi-label classification. Machine Learning , 85(3):333-359.
|
| 363 |
+
- Schapire, R. E. and Singer, Y. (2000). Boostexter: A boosting-based system for text categorization. Machine Learning , 39(2/3):135-168.
|
| 364 |
+
- Schwenk, H., Barrault, L., Conneau, A., and LeCun, Y. (2017). Very deep convolutional networks for text classification. In Proceedings of the 15th Conference of the European Chapter of the Association for Computational Linguistics, EACL 2017, Valencia, Spain, April 3-7, 2017, Volume 1: Long Papers , pages 11071116.
|
| 365 |
+
- Shen, T., Zhou, T., Long, G., Jiang, J., and Zhang, C. (2018). Bi-directional block self-attention for fast and memory-efficient sequence modeling. CoRR , abs/1804.00857.
|
| 366 |
+
- Sun, A. and Lim, E. (2001). Hierarchical text classification and evaluation. In Proceedings of the 2001 IEEE International Conference on Data Mining, 29 November - 2 December 2001, San Jose, California, USA , pages 521-528.
|
| 367 |
+
- Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., Kaiser, L., and Polosukhin, I. (2017). Attention is all you need. CoRR , abs/1706.03762.
|
| 368 |
+
- Velickovic, P., Cucurull, G., Casanova, A., Romero, A., Li` o, P., and Bengio, Y. (2018). Graph attention networks. In 6th International Conference on Learning Representations, ICLR 2018, Vancouver, BC, Canada, April 30 - May 3, 2018, Conference Track Proceedings .
|
| 369 |
+
- Vural, V. and Dy, J. G. (2004). A hierarchical method for multi-class support vector machines. In Proceedings of the Twenty-first International Conference on Machine Learning , ICML '04, pages 105-, New York, NY, USA. ACM.
|
| 370 |
+
- Wu, Z., Pan, S., Chen, F., Long, G., Zhang, C., and Yu, P. S. (2019). A comprehensive survey on graph neural networks. CoRR , abs/1901.00596.
|
| 371 |
+
- Xiao, L., Zhou, D., and Wu, M. (2011). Hierarchical classification via orthogonal transfer. In Proceedings of the 28th International Conference on Machine Learning, ICML 2011, Bellevue, Washington, USA, June 28 - July 2, 2011 , pages 801-808.
|
| 372 |
+
- Xue, G., Xing, D., Yang, Q., and Yu, Y. (2008). Deep classification in large-scale text hierarchies. In Proceedings of the 31st Annual International ACM SIGIR Conference on Research and Development in Information Retrieval, SIGIR 2008, Singapore, July 20-24, 2008 , pages 619-626.
|
| 373 |
+
- Yang, Z., Yang, D., Dyer, C., He, X., Smola, A. J., and Hovy, E. H. (2016). Hierarchical attention networks
|
| 374 |
+
|
| 375 |
+
for document classification. In NAACL HLT 2016, The 2016 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, San Diego California, USA, June 12-17, 2016 , pages 1480-1489.
|
| 376 |
+
|
| 377 |
+
- Yarullin, R. and Serdyukov, P. (2019). Bert for sequenceto-sequence multi-label text classification.
|
| 378 |
+
- Ying, R., He, R., Chen, K., Eksombatchai, P., Hamilton, W. L., and Leskovec, J. (2018). Graph convolutional neural networks for web-scale recommender systems. CoRR , abs/1806.01973.
|
| 379 |
+
- Zhang, M.-L., Li, Y.-K., Liu, X.-Y., and Geng, X. (2018). Binary relevance for multi-label learning: an overview. Frontiers of Computer Science , 12(2):191202.
|
| 380 |
+
- Zhao, W., Ye, J., Yang, M., Lei, Z., Zhang, S., and Zhao, Z. (2018). Investigating capsule networks with dynamic routing for text classification. CoRR , abs/1804.00538.
|
text-versions/attention-markdown/2005.09561_Normalized Attention Without Probability.md
ADDED
|
@@ -0,0 +1,352 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2005.09561 Normalized Attention Without Probability
|
| 2 |
+
|
| 3 |
+
## Normalized Attention Without Probability Cage
|
| 4 |
+
|
| 5 |
+
## Oliver Richter and Roger Wattenhofer
|
| 6 |
+
|
| 7 |
+
Department of Electrical Engineering and Information Technology
|
| 8 |
+
|
| 9 |
+
ETH Zurich, Switzerland
|
| 10 |
+
|
| 11 |
+
{richtero,wattenhofer}@ethz.ch
|
| 12 |
+
|
| 13 |
+
## Abstract
|
| 14 |
+
|
| 15 |
+
Attention architectures are widely used; they recently gained renewed popularity with Transformers yielding a streak of state of the art results. Yet, the geometrical implications of softmax -attention remain largely unexplored. In this work we highlight the limitations of constraining attention weights to the probability simplex and the resulting convex hull of value vectors. We show that Transformers are sequence length dependent biased towards token isolation at initialization and contrast Transformers to simple max- and sum-pooling - two strong baselines rarely reported. We propose to replace the softmax in self-attention with normalization, yielding a hyperparameter and data-bias robust, generally applicable architecture. We support our insights with empirical results from more than 25,000 trained models. All results and implementations are made available. 1
|
| 16 |
+
|
| 17 |
+
## 1 Introduction
|
| 18 |
+
|
| 19 |
+
The concept of neural attention [11, 3] has sparked a number of architectural breakthroughs. The Transformer architecture [32] successfully deploys multi-headed self-attention in several consecutive layers for natural language processing (NLP) - an architecture choice that has become popular [32, 26, 27, 9, 40, 28, 19, 7]. Apart from NLP, self-attention has shown success in applications ranging from image classification [23] to generative adversarial networks [43] to reinforcement learning [4, 22]. The attention architecture choice is thereby often based on one, if not both, of the following arguments: (1) Attention helps with credit assignment by providing more direct, dynamic links between inputs and outputs. (2) Attention is directly interpretable as one can investigate the percentages to which different inputs are 'attended' to. However, this second argument has been challenged recently, as several works show that attention weights do not directly correlate with predictions [14, 34, 5, 24] in NLP models. With interpretability in dispute, we are left with an open question: Can we improve the credit assignment ability by removing the constraint on attention weights to represent a distribution?
|
| 20 |
+
|
| 21 |
+
In this work, we show the theoretical implications of constraining the attention weights to the probability simplex, and propose an unconstrained alternative based on normalization. We show that the popular Transformer architecture has an innate bias towards token isolation at initialization and showcase implications thereof on biases in the data. Our experimental results demonstrate the advantage of unconstrained attention. In particular, we improve robustness to hyperparameters and show the general applicability of attention based architectures as compared to other architectures such as sum and max pooling. To summarize, our contributions include:
|
| 22 |
+
|
| 23 |
+
- a theoretical investigation of the probability simplex constraint in self-attention
|
| 24 |
+
- a robust, general purpose alternative based on normalization
|
| 25 |
+
- a large scale experimental comparison of the performance implications that an architecture choice entails with respect to the task type, hyperparameters as well as biases in the data
|
| 26 |
+
|
| 27 |
+
1 https://github.com/OliverRichter/normalized-attention
|
| 28 |
+
|
| 29 |
+
## 2 Background and Related Work
|
| 30 |
+
|
| 31 |
+
Many data processing tasks can be addressed by representing the input as a set or sequence of discrete tokens, e.g., the words in a sentence or the frames in a video. As a general formulation, we represent each input token through a vector x i ∈ R d for i ∈ { 1 , . . . , N } , where N is the sequence length and d is the dimensionality of each token. For ease of notation we use the word 'sequence' throughout, but note that all architectures discussed are also applicable to unordered sequences, i.e., sets of tokens. Multi-headed dot-product self-attention is a fundamental building block of the Transformer architecture [32]. It allows for information exchange between different tokens of the input sequence. More formally, for each attention head m the input vectors x i are projected through an affine transformation to a query q i m , key k i m and value vector v i m . The dimensionality of these vectors is chosen as d h = d M , where M is the number of attention heads. The query and key vectors are used for a pairwise dot product, scaled by the square root of the head dimension d h , to form the attention logits l i,j m and attention vectors a i m as
|
| 32 |
+
|
| 33 |
+
<!-- formula-not-decoded -->
|
| 34 |
+
|
| 35 |
+
where softmax refers to the normalized exponential function softmax( x ) j = exp( x j ) ∑ k exp( x k ) commonly used to project vectors to the probability simplex S P = { a i m | a i,j m ≥ 0 ∀ j and ∑ j a i,j m = 1 } . The output o i m of each attention head m is then given by a weighted sum of all value vectors o i m = ∑ j a i,j m · v j m . These attention head outputs are concatenated and mixed trough an additional affine transformation to form the attention layer output in the Transformer architecture [32].
|
| 36 |
+
|
| 37 |
+
In this work, we investigate whether constraining the attention vectors a i m into the probability simplex through the softmax function is the best we can do. We contrast the multi-head self-attention architecture to attention-inspired architectures without softmax (discussed in Section 4) as well as simpler aggregation methods commonly used. Specifically, while Yun et al. [41] show that Transformers are universal sequence-to-sequence function approximators, we question the practical necessity of an attention architecture, when sum pooling [42] already provides general function approximation capabilities [42, 38, 30]. Further, we compare to max pooling, a common aggregator choice that has shown good empirical success [20, 42, 33]. Several recent works have proposed architectural changes to the Transformer [41, 35, 16, 8, 10, 37, 25, 2]. However, to the best of our knowledge, we are the first to explicitly question the softmax in self-attention.
|
| 38 |
+
|
| 39 |
+
## 3 Limitations and Implications of Softmax Attention
|
| 40 |
+
|
| 41 |
+
To start our discussion, we highlight an observation that follows directly from attention vectors a i being constrained to the probability simplex S P :
|
| 42 |
+
|
| 43 |
+
## Attention head outputs o i m are convex combinations of value vectors v i m
|
| 44 |
+
|
| 45 |
+
This in itself has drastic implications. First and foremost, we note that a convex combination of vectors v i m cannot yield any vector outside the convex hull spanned by the value vectors v i m . An illustration of this output cage is given in Figure 1 (left). We conjecture that this constraint limits flexibility - and thereby ease of adjustment - of the functions expressed by the neural network throughout the training process. This conjecture is supported by our experimental results showing an increased robustness to hyperparameter choices when the constraint is removed. Exploring the observation above further, we note the following from a theoretical perspective:
|
| 46 |
+
|
| 47 |
+
## No convex combination can represent the binary exclusive OR (XOR) function
|
| 48 |
+
|
| 49 |
+
A formal proof is given in Appendix A. Note that this implication highlights an inability to represent non-linearity. While XOR can be represented in architectures with multiple heads and layers, the insight further underlines our argument: An aggregation with weights constrained to the probability simplex is restrictive. Especially if we compare it to other aggregation methods that can represent XOR (cf. Section 4). Finally, we want to highlight an additional insight that, to the best of our knowledge, has not been discussed in the literature so far:
|
| 50 |
+
|
| 51 |
+
Figure 1: Left: Softmax attention outputs can only lie within the convex hull spanned by the value vectors v i (blue region). Middle/Right: The standard deviation ( σ ) and norm of a pooling output is dependent on the sequence length N (x-axis) and the pooling method, if the output is not normalized. Softmax attention outputs scale similar to mean pooling at initialization, i.e., Transformers focus more on local information in longer sequences.
|
| 52 |
+
|
| 53 |
+
<!-- image -->
|
| 54 |
+
|
| 55 |
+
Transformers have an aggregation size dependent focus on local information at initialization.
|
| 56 |
+
|
| 57 |
+
To see this, consider the embeddings after the first residual connection, given by
|
| 58 |
+
|
| 59 |
+
<!-- formula-not-decoded -->
|
| 60 |
+
|
| 61 |
+
̸
|
| 62 |
+
|
| 63 |
+
where [ · ] denotes concatenation and W and b represent the parameters of the affine transformation that mixes the attention M head outputs. Our aim is to show how much this embedding e i is influenced by the local information x i relative to the context information { x j | j = i } . We first note that the contribution of context information depends on the initialization of W and b , where a typical initialization in language models favors the residual connection, i.e., local information. 2 However, even if we consider W as scale preserving, we note that the magnitudes of the attention head outputs o m are upper bounded by the magnitudes of the value vectors v m as a result of the convex hull. Moreover, attention logits are normally close to 0 at initialization (to have the softmax in the unsaturated region). This yields attention to be close to mean aggregation as ∑ j a i,j m · v j m ≈ 1 N ∑ j v j m . We note that taking the mean effectively scales the standard deviation of a random variable by the square root of the aggregation size. This means that the fraction of context information in e i is dependent on the sequence length and is smaller for longer sequences! Specifically, at initialization, Transformers focus more on local information in longer sequence than in shorter sequences. For reference, we visualize the dependence of o m on aggregation size at initialization for different aggregators in Figure 1 (right). Details on the corresponding experiment can be found in Appendix B. We note that while an architectural bias towards local information might be beneficial in some applications, the implicit dependence on aggregation size is questionable.
|
| 64 |
+
|
| 65 |
+
## 4 Normalized Attention Pooling
|
| 66 |
+
|
| 67 |
+
Given the implications that a self-attention based architecture brings along, a few natural questions to ask are: What happens if we remove the softmax? Is some form of online logit normalization necessary at all? And how do these architectures compare to simpler pooling methods like sum- or max-pooling? To investigate these, we contrast the following architectures in our experiments. We provide a schematic figure of each architecture in Appendix C.
|
| 68 |
+
|
| 69 |
+
Transformer Encoder (BERT): As a starting point, we replicate the encoder architecture presented by [32] as described in the code release of [9]. 3 This architecture is among others also used by [26, 27, 40, 28, 19, 7]. Each Transformer-layer consists of two sub-modules: a multi-head selfattention 'layer' and a feed forward network. Both modules have residual connections around them. The multi-head self-attention 'layer' consists of a projection to queries, keys and values, the attention mechanism as well as a mixing layer as described in Section 2. The feed forward network consists of two layers with a GELU [12] non-linearity on the hidden layer. Layer normalization [1] is applied between incoming and outgoing residual connections. Note that this gives a crucial distinction of this architecture: Embeddings are normalized after they are summed with the residual connection. This yields the implicit dependence on the sequence length as discussed in the end of Section 3. Further, in this architecture training is done with learning rate warm-up and gradient norm clipping.
|
| 70 |
+
|
| 71 |
+
2 As an example, BERT [9] initializes W with parameters drawn from a truncated normal distribution with standard deviation 0.02 and b to 0 .
|
| 72 |
+
|
| 73 |
+
[3 https://github.com/google-research/bert](https://github.com/google-research/bert)
|
| 74 |
+
|
| 75 |
+
Modified Transformer Encoder (MTE): To overcome the implicit dependence on sequence length, reduce training specific confounding factors and to make the two sub-modules more similar to each other, we introduce the following modifications: We remove learning rate warm-up and gradient clipping, but keep a linearly decreasing learning rate schedule, taking [17] as reference. Layer normalization is moved before the residual addition. Additionally, we add layer normalization on the hidden layers in the modules, i.e., before the mixing layer and before the GELU non-linearity in the feed forward network. These modifications remove the dependence on sequence length. Note that this is different from the recently studied PreNorm [22, 21, 18] that places the normalization before the attention mechanism. Finaly, we add an additional GELU non-linearity in the middle of the attention sub-module. We provide an ablation of all modifications in Appendix D. All following architectures apply the same modifications. The resulting MTE architecture here still projects the attention weights to the probability simplex through the softmax in the multi-head attention. This architecture is thereby limited to convex combinations of value vectors.
|
| 76 |
+
|
| 77 |
+
Normalized Attention Pooling (NAP): Given the success of online normalization during training be it through batch- [13], layer-[1] , group- [36], instance- [31] or weight-normalization [29] - our main proposal is to simply replace the softmax through a normalization:
|
| 78 |
+
|
| 79 |
+
<!-- formula-not-decoded -->
|
| 80 |
+
|
| 81 |
+
where µ x = 1 N ∑ j x j and σ x = 1 N ∑ j ( x j -µ x ) 2 are the mean and standard deviation of the corresponding input vector x , in our case the logit vector calculated through key-query dot products. Similar to layer normalization [1], we introduce trainable gain and bias parameters g and b initialized to 1 and 0 , respectively. However, while [1] introduce gain and bias vectors, we only introduce scalar parameters and broadcast these over the sequence/vector length, as we want the architecture to be independent of the sequence length N . Note that while no convex combination can represent the logical XOR, a normalized weighting can - see Appendix A for the corresponding proof.
|
| 82 |
+
|
| 83 |
+
No Online Logit Normalization (NON): To investigate whether a dynamic normalization of the attention logits is necessary, we also train a model where we use the logits l i,j m directly as attention weights, i.e., o i m = GELU ( 1 √ N ∑ j l i,j m · v j m ) . We also replaced the layer normalization after the attention weighting here through a simple scaling factor 1 √ N . Note that this also yields an in expectation constant contribution of context at initialization, independent of sequence length. However, the model can easily deviate from it during training.
|
| 84 |
+
|
| 85 |
+
Simple Summation of Embeddings (sum): From a theoretical perspective summation is sufficient for general function approximation [42, 38, 30]. Therefore, we investigate to simply replace attention through a sum-reduce-broadcast operation.
|
| 86 |
+
|
| 87 |
+
Max Pooling over Sequence Dimension (max): Similar to sum pooling, we can replace the attention sub-module through a simple max-reduce-broadcast operation over the sequence dimension. Note that max pooling over the sequence is a powerful operation, as the resulting embedding has a direct link to up to d different tokens.
|
| 88 |
+
|
| 89 |
+
If not varied in a corresponding experiment, we default architecture hyperparameters to L = 2 Transformer-layers (consisting of an attention sub-module and feed forward sub-module each), M = 4 heads to calculate the logits (if applicable), d = 128 as model dimension and train on a total of 3200 batches of 32 example sequences each, using the Adam optimizer [15]. The hidden dimension of the feed forward sub-modules is 4 · d for the models BERT , MTE , NAP and NON . For the models sum and max we increase the feed forward hidden dimension to approximately match the parameter counts of the other models.
|
| 90 |
+
|
| 91 |
+
## 5 Experiments and Results
|
| 92 |
+
|
| 93 |
+
Our goal with this work is to provide an insight into the variety of performance implications that the architecture choices entail. We aim to provide these insights independent of any particular downstream application, as these architectures can be applied to a variety of tasks - from NLP to graph neural networks to reinforcement learning agents. We therefore focus on carefully crafted synthetic tasks that (1) are general enough in that we can expect the insights to generalize to a large set of downstream tasks and (2) let us modify key aspects that are hidden in real world data sets, such as a bias towards a certain sub-task. The focus on synthetic tasks also allows us to get a better grasp on the learning dynamics - the focus of this work - as we can train thousands of models in diverse hyperparameter combinations. To limit the influence of confounding variables, we generate new data points for every batch. This allows us to omit regularization. See Appendix E for an in depth discussion of this setup.
|
| 94 |
+
|
| 95 |
+
Figure 2: Left: Pseudo code for case distinction task data. The case distinction points 64 and 50 are chosen arbitrarily. Middle/Right: Task setup for outputs across all tokens (middle, cf. Section 5.1) and outputs from the first token (right, cf. Section 5.2). Green boxes represent the trainable network layers (shared across tokens) while red boxes represent the pooling across tokens, the focus of this work. The targets of the displayed examples would be [0, 0, 0, 1] and [1, 0, 0, 0], respectively.
|
| 96 |
+
|
| 97 |
+
<!-- image -->
|
| 98 |
+
|
| 99 |
+
## 5.1 Argmin-First-Argmax Case Distinction Task
|
| 100 |
+
|
| 101 |
+
As a first task, we consider an input pipeline where tokens from a fixed integer-vocabulary are translated to a randomly initialized embedding. To the embedded tokens, a (also randomly initialized) positional embedding is added to provide position-relative information. The sequence of tokens is then processed by several architecture dependent Transformer-layers (as described in Section 4). Finally, each contextualized embedding is projected to a single output. A softmax-crossentropy loss is applied over the sequence dimension to train the networks to pin-point a specific, input dependent token. See the example in the middle of Figure 2 for a visualization. Note that the ability to pin-point a specific token is an abstract task relevant to NLP (e.g., question answering or co-reference resolution), graph neural networks (e.g., finding the next hop in a shortest path) as well as reinforcement learning (e.g., action credit assignment). To make the task input dependent, we generate the data as given in the pseudo code in Figure 2. Note that the argmin and argmax make this task quite challenging from a learning perspective as the networks start from random embeddings which do not provide any ordering information. Which embeddings correspond to bigger integers and which to smaller integers has to be inferred during training. Further, the case distinction in this task lets us tweak the data bias towards each sub-task. Specifically, we consider a vocabulary size of S = 100 integers (0-99) and uniformly random sampled sequences of N = 128 tokens in length. This leads to a bias as p argmin = 1 -(1 -1 S ) N ≈ 72 . 4% of data points require the network to pin-point the minimum in the input sequence, p first ≈ 20 . 1% require the network to pin-point the first token of the sequence and the remaining p argmax ≈ 7 . 5% require the network to pin-point the maximum in the input.
|
| 102 |
+
|
| 103 |
+
## 5.1.1 Varying Model Dimension d
|
| 104 |
+
|
| 105 |
+
As a first investigation, we are interested in how varying the model dimension d influences the architectures ability to learn the given task. For this, we train each of the architectures for each of the model dimensions d ∈ { 8 , 16 , 32 , 64 , 128 , 256 , 512 , 1024 } using 10 different learning rates and 5 random seeds for each hyperparameter combination. As we want to base our insights on as many results as possible, we derive a novel, human friendly visualization of results. Figure 3 (top row) shows the first results as follows: The outcome of each hyperparameter combination is reported as an RGB pixel in the plot, where the R (red) value corresponds to the accuracy of the worst performing random seed, the G (green) value corresponds to the average over the random seeds and the B (blue) value corresponds to the best performing random seed. For each value (R, G and B), the max over the course of training is taken. This assignment roughly translates as follows: The brighter, the better brighter pixels correspond to higher min-, mean- and max-accuracy. Blue/turquoise pixels highlight a large performance variation across random seeds and black/grey pixels correspond to hyperparameter combinations where none of the random seeds could solve the task. These condensed results directly give rise to the following observations: (1) All models have some hyper-parameter combinations that learn the task well (white pixels). (2) The optimal learning rate depends on the model size, especially in the BERT architecture. This has profound implications for hyperparameter optimization: Tuning hyperparameters independent of each other might lead to sub-optimal results. (3) Models with probability simplex limitations ( BERT and MTE ) work for a smaller range of hyperparameters. We provide case learning curves and additional results in Appendix F. Next, given that all architectures are applicable to sequences of any length, we investigate how the architectures generalize to sequences of different length. Specifically, we validated each of the models trained above after every 100 batches on 32 batches with sequences of half the length ( N = 64 ). We report the corresponding accuracies as before in Figure 3 (bottom row). Note that as we are taking the maximum over the course of training, we report optimal early stopping results. We observe: (1) The sum architecture does not generalize well in this task. (2) Our NAP architecture seems to be the most robust to this generalization.
|
| 106 |
+
|
| 107 |
+
Figure 3: Learning rate (y-axis) vs. model dimension d (x-axis) on the argmin-first-argmax case distinction task (with output across all tokens). The pixels' R (red), G (green) and B (blue) values correspond to min-, mean- and max-accuracy, respectively, of the corresponding hyperparameter combination - see main text for details. Top row: Training accuracy (sequence length N = 128 ). Bottom row: Validation accuracy when validating on sequences of half the length ( N = 64 ). Crosses indicate the combination for best mean validation accuracy, which we report behind the model name.
|
| 108 |
+
|
| 109 |
+
<!-- image -->
|
| 110 |
+
|
| 111 |
+
## 5.1.2 Case Accuracy under Varying Data Biases
|
| 112 |
+
|
| 113 |
+
As a next experiment we reset the model dimension to d = 128 and vary the sequence length N ∈ { 4 , 8 , 16 , 32 , 64 , 128 , 256 , 512 } . Note that this implicitly varies the biases p argmin , p first and p argmax in the data. We report the case specific accuracies in Figure 4 as follows: After every 100 batches, we validate the models on 1000 examples per case. Reported is the best accurracy over the course of training in form of pixel value with R (red) corresponding to the argmin -case accuracy, G (green) corresponding to the fi rst -case accuracy and B (blue) corresponding to the argmax -case accuracy. As a consequence, white pixels correspond to all cases learned and yellow pixels correspond to the argmin - and fi rst -case learned. We make the following observations: (1) If the learning rate is too low, models tend to focus on the majority case (indicated in a shift from blue to red as the bias shifts from the argmax - to the argmin -case with increasing sequence length N ). (2) If the learning rate is too high, the BERT architecture tends to focus on the fi rst -case. We believe this is due to the architectural bias towards local information as discussed in Section 3. Note that the fi rst -case can be solved by relying on the local positional embedding. (3) Only the NAP and max architecture manage to learn all three cases from the highly biased data when N = 256 . In Appendix G.1 we provide a further experiment investigating different batch sizes. The results are complementary.
|
| 114 |
+
|
| 115 |
+
Figure 4: Learning rate (y-axis) vs. sequence length N (x-axis) on the case distinction task (with output across all tokens). RGB pixel values correspond to argmin -, fi rst - and argmax -mean-caseaccuracies, respectively.
|
| 116 |
+
|
| 117 |
+
<!-- image -->
|
| 118 |
+
|
| 119 |
+
Figure 5: Learning rate (y-axis) vs. model dimension d (x-axis) on the case distinction task with output from the first token. RGB pixel values correspond to argmin -, fi rst - and argmax -mean-caseaccuracies. Crosses indicate the best mean accuracy, which we report behind the model name.
|
| 120 |
+
|
| 121 |
+
<!-- image -->
|
| 122 |
+
|
| 123 |
+
## 5.2 First Token Output
|
| 124 |
+
|
| 125 |
+
The task so far requires the architectures to learn an information flow between tokens to distinguish the case and decide per token, whether it is the token that is looked for or not. Now we investigate, whether all this information can also be aggregated into a single token. We therefore modify the architecture output slightly in that we only take the contextualized embedding of the first token and project from it to a vector of size N (see example on the right in Figure 2). Note that this task set-up is harder and can highlight bottlenecks in the information flow across tokens.
|
| 126 |
+
|
| 127 |
+
We fix the sequence lenght to N = 128 and again vary the model dimension d . We report the the case specific mean accuracies in Figure 5, min-, mean- and max-overall-accuracies are given in Appendix G.2. We observe: (1) All architectures learn for (almost) all combinations the now close to trivial fi rst -case. (2) The sum pooling architecture does not learn any of the other cases. (3) Only NAP and max learn all three cases in some hyperparameter combinations. The worse performance of NON highlights the advantage of online normalization of the logits. While the softmax provides some form of online normalization, we hypothesize that the worse performance of MTE and BERT in this task stems from an information bottleneck induced by the probability simplex limitations. To test this hypothesis, we vary the number of attention heads M with results in Figure 6. We observe that increasing the number of heads helps the MTE and BERT architecture, supporting our hypothesis. Note however, that MTE and BERT are still outperformed significantly by NAP . In Appendix G.3 we provide a further experiment, varying the depth up to L = 64 . The results are complementary.
|
| 128 |
+
|
| 129 |
+
## 5.3 Mode Finding Task
|
| 130 |
+
|
| 131 |
+
Given the results so far, one could conclude that max is the best choice due to its simplicity. Note however, that max has an architectural prior that is in line with the underlying task of finding the maximum or minimum of the sequence. To study the effect of architectural priors, we experiment on an additional task: Finding the mode/most common integer in the input sequence. Also this task has ties to NLP (e.g., sentiment analysis), graph neural networks (e.g., consensus/agreement) and reinforcement learning (e.g., count based exploration). Here we remove the positional embeddings, as this task can also be done on sets, and project from the contextualized embedding of the first token to a vector of dimension S (the vocabulary size) over which we apply the softmax-cross-entropy loss. We keep N = 128 but reduce S to 10 to have meaningful modes. Ties are broken by taking the smallest integer of the ones with maximal occurrence. Results of varying the model dimension d are reported in Figure 7. We observe: (1) sum pooling works well on this task, as it has a suitable architecutral prior. (2) max pooling cannot learn the task, not even with a model dimension d = 1024 = 8 · N . In Appendix H we provide an additional experiment, varying the vocabulary size. The results are complementary. We refer an interested reader to [39] for more on architecture-task alignment.
|
| 132 |
+
|
| 133 |
+
Figure 6: Learning rate (y-axis) vs. attention heads M (x-axis) on the case distinction task (output from the first token). RGB pixel values correspond to min, mean and max accuracy. Black crosses indicate the best mean accuracy, reported in the table to the right. Red crosses indicate that the best mean validation accuracy (when validating with N = 64 ) was taken from a different combination. Bold numbers indicate a min-accuracy higher than the best max-accuracy of the other models.
|
| 134 |
+
|
| 135 |
+
<!-- image -->
|
| 136 |
+
|
| 137 |
+
Figure 7: Learning rate (y-axis) vs. model dimension d (x-axis) on the mode finding task. RGB pixel values correspond to min, mean and max accuracy. Crosses indicate the reported best mean accuracy.
|
| 138 |
+
|
| 139 |
+
<!-- image -->
|
| 140 |
+
|
| 141 |
+
## 6 Conclusion
|
| 142 |
+
|
| 143 |
+
Taking all observations together, we come to the following conclusions: Many recent works apply some sort of neural self-attention mechanism involving a softmax that projects the attention weights to the probability simplex. In this work we question the softmax in dot-product self-attention modules. Our theoretical investigation shows that softmax -attention outputs are constrained to the convex hull spanned by the value vectors. In our experiments we show that this can lead to an unwanted hyperparameter sensibility. We show that simpler architectures like max- and sum-pooling perform well when their architectural prior aligns with the underlying task. These architectures however fail in cases where the architectural prior is not suitable. As a solution, we propose to replace the softmax in attention through normalization. Our resulting normalized attention pooling ( NAP ) architecture is the only architecture of the 6 investigated that performs well in all tasks and setups, showing a broad applicability and better performance than the widely used BERT architecture. We hope that our work provides a stepping stone to examine architectures with respect to biases in the data. Further, we see a lot of potential for future work to investigate the correlated effects of hyperparameters.
|
| 144 |
+
|
| 145 |
+
## Broader Impact
|
| 146 |
+
|
| 147 |
+
We contrast different architectures on an abstract level in this work. Hence, there is no direct risk associated with system failure or an implication that would put some at a disadvantage. On the contrary: We see huge potential in our work to benefit (1) researchers and practitioners that do not have the computational resources to perform expensive hyperparameter optimizations and (2) minorities under-represented in data-sets, as our proposed architecture shows increased robustness to hyperparameter changes and biases in the data.
|
| 148 |
+
|
| 149 |
+
## Acknowledgments
|
| 150 |
+
|
| 151 |
+
The main author would like to thank his colleagues Damián Pascual, Béni Egressy, Lukas Faber, Gino Brunner, Zhao Meng and Johannes Ackermann for the insightful discussions and helpful feedback on preliminary versions of this work.
|
| 152 |
+
|
| 153 |
+
## References
|
| 154 |
+
|
| 155 |
+
- [1] Jimmy Lei Ba, Jamie Ryan Kiros, and Geoffrey E Hinton. Layer normalization. arXiv preprint arXiv:1607.06450 , 2016.
|
| 156 |
+
- [2] Thomas Bachlechner, Bodhisattwa Prasad Majumder, Huanru Henry Mao, Garrison W Cottrell, and Julian McAuley. Rezero is all you need: Fast convergence at large depth. arXiv preprint arXiv:2003.04887 , 2020.
|
| 157 |
+
- [3] Dzmitry Bahdanau, Kyunghyun Cho, and Yoshua Bengio. Neural machine translation by jointly learning to align and translate. In Yoshua Bengio and Yann LeCun, editors, 3rd International Conference on Learning Representations, ICLR 2015, San Diego, CA, USA, May 7-9, 2015, Conference Track Proceedings , 2015.
|
| 158 |
+
- [4] Timo Bram, Gino Brunner, Oliver Richter, and Roger Wattenhofer. Attentive multi-task deep reinforcement learning. 07 2019.
|
| 159 |
+
- [5] Gino Brunner, Yang Liu, Damian Pascual, Oliver Richter, Massimiliano Ciaramita, and Roger Wattenhofer. On identifiability in transformers. In International Conference on Learning Representations , 2020.
|
| 160 |
+
- [6] Satrajit Chatterjee. Coherent gradients: An approach to understanding generalization in gradient descent-based optimization. In International Conference on Learning Representations , 2020.
|
| 161 |
+
- [7] Kevin Clark, Minh-Thang Luong, Quoc V. Le, and Christopher D. Manning. Electra: Pretraining text encoders as discriminators rather than generators. In International Conference on Learning Representations , 2020.
|
| 162 |
+
- [8] Mostafa Dehghani, Stephan Gouws, Oriol Vinyals, Jakob Uszkoreit, and Lukasz Kaiser. Universal transformers. In International Conference on Learning Representations , 2019.
|
| 163 |
+
- [9] Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. BERT: pre-training of deep bidirectional transformers for language understanding. In Jill Burstein, Christy Doran, and Thamar Solorio, editors, Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, NAACL-HLT 2019, Minneapolis, MN, USA, June 2-7, 2019, Volume 1 (Long and Short Papers) , pages 4171-4186. Association for Computational Linguistics, 2019.
|
| 164 |
+
- [10] Angela Fan, Edouard Grave, and Armand Joulin. Reducing transformer depth on demand with structured dropout. In International Conference on Learning Representations , 2020.
|
| 165 |
+
- [11] Alex Graves. Generating sequences with recurrent neural networks. CoRR , abs/1308.0850, 2013.
|
| 166 |
+
- [12] Dan Hendrycks and Kevin Gimpel. Gaussian error linear units (gelus). arXiv preprint arXiv:1606.08415 , 2016.
|
| 167 |
+
- [13] Sergey Ioffe and Christian Szegedy. Batch normalization: Accelerating deep network training by reducing internal covariate shift. In Francis R. Bach and David M. Blei, editors, Proceedings of the 32nd International Conference on Machine Learning, ICML 2015, Lille, France, 6-11 July 2015 , volume 37 of JMLR Workshop and Conference Proceedings , pages 448-456. JMLR.org, 2015.
|
| 168 |
+
|
| 169 |
+
- [14] Sarthak Jain and Byron C. Wallace. Attention is not explanation. In Jill Burstein, Christy Doran, and Thamar Solorio, editors, Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, NAACL-HLT 2019, Minneapolis, MN, USA, June 2-7, 2019, Volume 1 (Long and Short Papers) , pages 3543-3556. Association for Computational Linguistics, 2019.
|
| 170 |
+
- [15] Diederik P Kingma and Jimmy Ba. Adam: A method for stochastic optimization. arXiv preprint arXiv:1412.6980 , 2014.
|
| 171 |
+
- [16] Zhenzhong Lan, Mingda Chen, Sebastian Goodman, Kevin Gimpel, Piyush Sharma, and Radu Soricut. Albert: A lite bert for self-supervised learning of language representations. In International Conference on Learning Representations , 2020.
|
| 172 |
+
- [17] Mengtian Li, Ersin Yumer, and Deva Ramanan. Budgeted training: Rethinking deep neural network training under resource constraints. In International Conference on Learning Representations , 2020.
|
| 173 |
+
- [18] Liyuan Liu, Xiaodong Liu, Jianfeng Gao, Weizhu Chen, and Jiawei Han. Understanding the difficulty of training transformers. arXiv preprint arXiv:2004.08249 , 2020.
|
| 174 |
+
- [19] Yinhan Liu, Myle Ott, Naman Goyal, Jingfei Du, Mandar Joshi, Danqi Chen, Omer Levy, Mike Lewis, Luke Zettlemoyer, and Veselin Stoyanov. Roberta: A robustly optimized BERT pretraining approach. CoRR , abs/1907.11692, 2019.
|
| 175 |
+
- [20] Jawad Nagi, Frederick Ducatelle, Gianni A Di Caro, Dan Cire¸ san, Ueli Meier, Alessandro Giusti, Farrukh Nagi, Jürgen Schmidhuber, and Luca Maria Gambardella. Max-pooling convolutional neural networks for vision-based hand gesture recognition. In 2011 IEEE International Conference on Signal and Image Processing Applications (ICSIPA) , pages 342-347. IEEE, 2011.
|
| 176 |
+
- [21] Toan Q Nguyen and Julian Salazar. Transformers without tears: Improving the normalization of self-attention. arXiv preprint arXiv:1910.05895 , 2019.
|
| 177 |
+
- [22] Emilio Parisotto, H Francis Song, Jack W Rae, Razvan Pascanu, Caglar Gulcehre, Siddhant M Jayakumar, Max Jaderberg, Raphael Lopez Kaufman, Aidan Clark, Seb Noury, et al. Stabilizing transformers for reinforcement learning. arXiv preprint arXiv:1910.06764 , 2019.
|
| 178 |
+
- [23] Niki Parmar, Prajit Ramachandran, Ashish Vaswani, Irwan Bello, Anselm Levskaya, and Jon Shlens. Stand-alone self-attention in vision models. In Hanna M. Wallach, Hugo Larochelle, Alina Beygelzimer, Florence d'Alché-Buc, Emily B. Fox, and Roman Garnett, editors, Advances in Neural Information Processing Systems 32: Annual Conference on Neural Information Processing Systems 2019, NeurIPS 2019, 8-14 December 2019, Vancouver, BC, Canada , pages 68-80, 2019.
|
| 179 |
+
- [24] Damian Pascual, Gino Brunner, and Roger Wattenhofer. Telling bert's full story: from local attention to global aggregation. arXiv preprint arXiv:2004.05916 , 2020.
|
| 180 |
+
- [25] Ofir Press, Noah A Smith, and Omer Levy. Improving transformer models by reordering their sublayers. arXiv preprint arXiv:1911.03864 , 2019.
|
| 181 |
+
- [26] Alec Radford, Karthik Narasimhan, Tim Salimans, and Ilya Sutskever. Improving language understanding by generative pre-training. 2018.
|
| 182 |
+
- [27] Alec Radford, Jeff Wu, Rewon Child, David Luan, Dario Amodei, and Ilya Sutskever. Language models are unsupervised multitask learners. 2019.
|
| 183 |
+
- [28] Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, and Peter J Liu. Exploring the limits of transfer learning with a unified text-to-text transformer. arXiv preprint arXiv:1910.10683 , 2019.
|
| 184 |
+
- [29] Tim Salimans and Diederik P. Kingma. Weight normalization: A simple reparameterization to accelerate training of deep neural networks. In Daniel D. Lee, Masashi Sugiyama, Ulrike von Luxburg, Isabelle Guyon, and Roman Garnett, editors, Advances in Neural Information Processing Systems 29: Annual Conference on Neural Information Processing Systems 2016, December 5-10, 2016, Barcelona, Spain , page 901, 2016.
|
| 185 |
+
- [30] Nimrod Segol and Yaron Lipman. On universal equivariant set networks. In International Conference on Learning Representations , 2020.
|
| 186 |
+
- [31] Dmitry Ulyanov, Andrea Vedaldi, and Victor Lempitsky. Instance normalization: The missing ingredient for fast stylization. arXiv preprint arXiv:1607.08022 , 2016.
|
| 187 |
+
|
| 188 |
+
- [32] Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser, and Illia Polosukhin. Attention is all you need. In Isabelle Guyon, Ulrike von Luxburg, Samy Bengio, Hanna M. Wallach, Rob Fergus, S. V. N. Vishwanathan, and Roman Garnett, editors, Advances in Neural Information Processing Systems 30: Annual Conference on Neural Information Processing Systems 2017, 4-9 December 2017, Long Beach, CA, USA , pages 5998-6008, 2017.
|
| 189 |
+
- [33] Petar Veliˇ ckovi´ c, Rex Ying, Matilde Padovano, Raia Hadsell, and Charles Blundell. Neural execution of graph algorithms. In International Conference on Learning Representations , 2020.
|
| 190 |
+
- [34] Sarah Wiegreffe and Yuval Pinter. Attention is not not explanation. In Kentaro Inui, Jing Jiang, Vincent Ng, and Xiaojun Wan, editors, Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing, EMNLP-IJCNLP 2019, Hong Kong, China, November 3-7, 2019 , pages 11-20. Association for Computational Linguistics, 2019.
|
| 191 |
+
- [35] Felix Wu, Angela Fan, Alexei Baevski, Yann Dauphin, and Michael Auli. Pay less attention with lightweight and dynamic convolutions. In International Conference on Learning Representations , 2019.
|
| 192 |
+
- [36] Yuxin Wu and Kaiming He. Group normalization. Int. J. Comput. Vis. , 128(3):742-755, 2020.
|
| 193 |
+
- [37] Zhanghao Wu*, Zhijian Liu*, Ji Lin, Yujun Lin, and Song Han. Lite transformer with long-short range attention. In International Conference on Learning Representations , 2020.
|
| 194 |
+
- [38] Keyulu Xu, Weihua Hu, Jure Leskovec, and Stefanie Jegelka. How powerful are graph neural networks? In 7th International Conference on Learning Representations, ICLR 2019, New Orleans, LA, USA, May 6-9, 2019 . OpenReview.net, 2019.
|
| 195 |
+
- [39] Keyulu Xu, Jingling Li, Mozhi Zhang, Simon S. Du, Ken ichi Kawarabayashi, and Stefanie Jegelka. What can neural networks reason about? In International Conference on Learning Representations , 2020.
|
| 196 |
+
- [40] Zhilin Yang, Zihang Dai, Yiming Yang, Jaime G. Carbonell, Ruslan Salakhutdinov, and Quoc V. Le. Xlnet: Generalized autoregressive pretraining for language understanding. In Hanna M. Wallach, Hugo Larochelle, Alina Beygelzimer, Florence d'Alché-Buc, Emily B. Fox, and Roman Garnett, editors, Advances in Neural Information Processing Systems 32: Annual Conference on Neural Information Processing Systems 2019, NeurIPS 2019, 8-14 December 2019, Vancouver, BC, Canada , pages 5754-5764, 2019.
|
| 197 |
+
- [41] Chulhee Yun, Srinadh Bhojanapalli, Ankit Singh Rawat, Sashank Reddi, and Sanjiv Kumar. Are transformers universal approximators of sequence-to-sequence functions? In International Conference on Learning Representations , 2020.
|
| 198 |
+
- [42] Manzil Zaheer, Satwik Kottur, Siamak Ravanbakhsh, Barnabás Póczos, Ruslan Salakhutdinov, and Alexander J. Smola. Deep sets. In Isabelle Guyon, Ulrike von Luxburg, Samy Bengio, Hanna M. Wallach, Rob Fergus, S. V. N. Vishwanathan, and Roman Garnett, editors, Advances in Neural Information Processing Systems 30: Annual Conference on Neural Information Processing Systems 2017, 4-9 December 2017, Long Beach, CA, USA , pages 3391-3401, 2017.
|
| 199 |
+
- [43] Han Zhang, Ian J. Goodfellow, Dimitris N. Metaxas, and Augustus Odena. Self-attention generative adversarial networks. In Kamalika Chaudhuri and Ruslan Salakhutdinov, editors, Proceedings of the 36th International Conference on Machine Learning, ICML 2019, 9-15 June 2019, Long Beach, California, USA , volume 97 of Proceedings of Machine Learning Research , pages 7354-7363. PMLR, 2019.
|
| 200 |
+
|
| 201 |
+
## A Lemmas and Proofs
|
| 202 |
+
|
| 203 |
+
Lemma 1. No convex combination can represent the binary exclusive OR (XOR) function defined on binary inputs x 1 ∈ { 0 , 1 } and x 2 ∈ { 0 , 1 } by the indicator function as XOR ( x 1 , x 2 ) = 1 x 1 = x 2 .
|
| 204 |
+
|
| 205 |
+
̸
|
| 206 |
+
|
| 207 |
+
Proof. Suppose there exist convex combination weights a 1 and a 2 with a 1 + a 2 = 1 , such that a 1 · x 1 + a 2 · x 2 represents the XOR function. Plugging in x 1 = x 2 = 1 yields a 1 · x 1 + a 2 · x 2 = a 1 + a 2 = 1 , which gives the contradiction.
|
| 208 |
+
|
| 209 |
+
Lemma 2. Given the two binary inputs x 1 ∈ { 0 , 1 } and x 2 ∈ { 0 , 1 } , there exists an affine mapping f : { 0 , 1 } 2 → R 2 , such that
|
| 210 |
+
|
| 211 |
+
<!-- formula-not-decoded -->
|
| 212 |
+
|
| 213 |
+
̸
|
| 214 |
+
|
| 215 |
+
is equivalent to the logical exclusive OR given by the indicator function as XOR ( x 1 , x 2 ) = 1 x 1 = x 2 .
|
| 216 |
+
|
| 217 |
+
Proof. For a vector l ∈ R 2 , the standard deviation σ l can be simplified to
|
| 218 |
+
|
| 219 |
+
<!-- formula-not-decoded -->
|
| 220 |
+
|
| 221 |
+
and the normalization function reduces to
|
| 222 |
+
|
| 223 |
+
<!-- formula-not-decoded -->
|
| 224 |
+
|
| 225 |
+
As an example, consider the affine mapping f ( x ) = l = [3 x 1 +1 , 2 x 2 ] T , which for x 1 ∈ { 0 , 1 } and x 2 ∈ { 0 , 1 } results in the function
|
| 226 |
+
|
| 227 |
+
̸
|
| 228 |
+
|
| 229 |
+
<!-- formula-not-decoded -->
|
| 230 |
+
|
| 231 |
+
We note that for a realization of such an affine mapping across tokens given the weight sharing constraints of the discussed architectures we would need x 1 and x 2 to be distinguishable for the mapping to keys and queries, e.g., through positional embeddings. This however does not invalidate our conclusion that normalized weighting is more expressive than softmax weighting, as we do not require the inputs that are weighted to be distinguishable.
|
| 232 |
+
|
| 233 |
+
## B Sequence Length Dependent Local/Context-Focus
|
| 234 |
+
|
| 235 |
+
For the middle and right plot in Figure 1 we sample 16'384 value, key and query vectors of dimension d h = 128 per sequence length N ∈ { 1 , 2 , 4 , 8 , 16 , 32 , 64 , 128 , 512 , 1024 , 2048 } from a normal Gaussian N ( 0 , I d h ) -I d h being the d h -dimensional identity matrix. We split the samples to form the sequences and calculate the corresponding output vectors o i for i ∈ { 1 , . . . , N } . Here, the softmax attention outputs are calculated as described in Section 2, while the mean-, sum- and max-outputs are calculated as mean-, sum- and max-reduce of the value vectors over the sequence dimension. For the normalized results we take the sum-output vectors and normalize them (over the d h -dimensional vector dimension). Note that such a normalization can be applied to any of the aggregation methods to get qualitatively similar results. The plots in Figure 1 are generated by reporting the standard deviation over all output values and the mean norm of the output values, respectively.
|
| 236 |
+
|
| 237 |
+
Given the numerous successes of Transformers in natural language processing, we conjecture that a bias towards local information might be beneficial in language modeling. However, the implicit dependence on sequence length in a model that should be oblivious to different input sequence lengths is questionable. We leave an in depth investigation to future work.
|
| 238 |
+
|
| 239 |
+
## C Architectures
|
| 240 |
+
|
| 241 |
+
We provide a schematic of 1 Transformer-layer of each architecture investigated in Figure 8. Our base architectures consist of 2 such layers followed by a projection to the output dependent on the task as described in the corresponding sections (cf. Section 5.1, 5.2 and 5.3).
|
| 242 |
+
|
| 243 |
+
Figure 8: Schematics of 1 Transformer-layer block of the different architectures investigated. Green layers correspond to the main weight matrices that are trained. Note that displayed dimensions are not to scale - the hidden dimension of the feed forward layer is larger than the model dimension and the hidden layer size in the feed forward network of 'max' and 'sum' are adjusted to approximately match the parameter count of the other architectures.
|
| 244 |
+
|
| 245 |
+
<!-- image -->
|
| 246 |
+
|
| 247 |
+
## D Architecture Modification Ablations
|
| 248 |
+
|
| 249 |
+
An empirical ablation of the modifications that lead from the BERT architecture to the MTE architecture is given in Figure 9. The plots are generated as described in Sections 5.1.1 and 5.1.2.
|
| 250 |
+
|
| 251 |
+
Figure 9: Learning rate (y-axis) vs. model dimension d (x-axis) on the argmin-first-argmax case distinction task (with output across all tokens) - architecture modification ablation study. In the first two rows, RGB pixel values correspond to min-, mean- and max-accuracy. In the last two rows, RGB pixel values correspondto argmin -, fi rst - and argmax -mean-case-accuracies. 1. row: Training accuracy (sequence length N = 128 ). 2. row: Validation accuracy when validating on sequences of half the length ( N = 64 ). 3. row: Training case accuracy (sequence length N = 128 ). 4. row: Validation case accuracy when validating on sequences of half the length ( N = 64 ). Crosses indicate the combination for best mean accuracy, the accuracies at these locations are reported in Table 1.
|
| 252 |
+
|
| 253 |
+
<!-- image -->
|
| 254 |
+
|
| 255 |
+
The first column in Figure 9 corresponds to the original BERT architecture, trained with gradient norm clipping and learning rate warm up.
|
| 256 |
+
|
| 257 |
+
The second column (- warm up) corresponds to the same architecture, but trained without learning rate warm up. Here we see that too high learning rates learn even less without learning rate warm up in the BERT architecture, hinting at a necessity for learning rate warm up for the original architecture.
|
| 258 |
+
|
| 259 |
+
Table 1: Ablation study accuracy values taken from the hyper-parameter combination that led to the best mean overall accuracy, indicated by a cross in Figure 9.
|
| 260 |
+
|
| 261 |
+
| BERT - warm up - grad. clip + normalize + GELU Overall min 99.3% 99.4% 99.3% 99.2% 99.3% Training mean 99.4% 99.5% 99.4% 99.3% 99.3% Accuracy max 99.5% 99.6% 99.6% 99.5% 99.5% Overall min 96.5% 96.9% 96.9% 96.3% 96.7% Validation mean 97.2% 97.6% 97.2% 96.8% 97.3% Accuracy max 98.2% 98.2% 98.2% 98.4% 98.2% Mean Case argmin 99.3% 99.6% 99.5% 99.6% 99.5% Accuracy first 100% 100% 100% 100% 100% Training argmax 96.9% 98.1% 97.5% 96.5% 98.0% Mean Case argmin 98.0% 98.0% 98.0% 98.1% 97.9% Accuracy first 100% 100% 100% 100% 100% Validation argmax 93.9% 93.8% 93.1% 91.2% 93.8% |
|
| 262 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 263 |
+
|
| 264 |
+
The third column (- grad. clip) reports the results if we further remove gradient clipping from the training schedule. This does not seem to have a big impact in our setup.
|
| 265 |
+
|
| 266 |
+
Next, we report in the forth column (+ normalize) the results of moving the layer normalization before the residual addition and introducing an additional layer normalization right after the attention mechanism as well as on the hidden layer of the feed forward network. Note that this change removes the bias towards local information discussed in the end of Section 3. We see that this change leads to a profound shift in focus in regions where the learning rate is high: models with the original normalization focus the (local) fi rst -case, while models with our normalization focus on the (majority) argmin -case. This is in line with the insights stated in Section 5.1.2.
|
| 267 |
+
|
| 268 |
+
Finally, we report in the fifth column (+ GELU) the results of adding an additional GELU layer after the attention mechanism. These results correspond to the MTE architecture used throughout the paper.
|
| 269 |
+
|
| 270 |
+
Apart from the performance landscape changes just mentioned, the best hyper-parameter accuracies remain similar throughout all modifications, cf. Table 1.
|
| 271 |
+
|
| 272 |
+
## E Regularization Experiments
|
| 273 |
+
|
| 274 |
+
To limit the number of variables which are not accounted for in the experiments, we focus on the infinite data but limited training time regime. In this regime, every batch consists of new data points. We believe that this regime is of paramount interest in future research, as more devices create a constant stream of data and training is more limited by the available training time than the available data. This regime allows us to omit regularization in all architectures as over-fitting is not an issue. In fact, our supplementary experiments below as well as related work [16] show that regularization does not help in this regime. We leave a comparison of the architectures in the limited data regime to future work.
|
| 275 |
+
|
| 276 |
+
Here, we show empirical results supporting the intuition that L 2 as well as dropout regularization does not help in our setup. For each of our tasks, we take our default hyper-parameters ( d = 128 , L = 2 , M = 4 , N = 128 ) and train 5 random seeds per learning rate for models with regularization, varying the dropout rate in { 0 . 0625 , 0 . 125 , 0 . 25 , 0 . 5 } and the L 2 regularization weighting in { 0 . 0001 , 0 . 001 , 0 . 01 , 0 . 1 } . Tables 2, 3 and 4 report the best mean accuracy achieved with the small number behind the accuracies indicating the regularization used, 1 referring to the smallest, 4 to the largest. We underline the results where regularization did lead to an improvement in mean accuracy. Note however that these improvements should be taken with a grain of salt, as (1) none of these improvements is significant considering the performance variation across random seeds and (2) the regularized values are likely to be overestimated, as the max is taken over 40 averages (4 regularization values times 10 learning rates) as compared to 10 averages (10 learning rates) in the unregulated case.
|
| 277 |
+
|
| 278 |
+
Table 2: Regularization results in the case distinction task with output taken across all tokens. The top three rows correspond to the best mean training accuracy, while the bottom three rows correspond to the best mean validation accuracy when validating on sequences of half the length.
|
| 279 |
+
|
| 280 |
+
| BERT MTE NAP NON sum max unregularized 99.3% 99.1% 99.3% 99.1% 98.9% 99.2% with dropout 98 . 1% 1 97 . 3% 1 97 . 8% 1 97 . 5% 1 97 . 3% 1 98 . 2% 1 with L 2 -regularization 99 . 3% 2 99 . 2% 1 99 . 2% 2 99 . 2% 1 98 . 9% 1 99 . 4% 2 unregularized 95.5% 95.5% 97.0% 95.3% 75.0% 97.1% with dropout 94 . 4% 1 94 . 6% 1 96 . 8% 2 96 . 0% 1 83 . 1% 1 96 . 3% 1 with L 2 -regularization 97 . 2% 2 93 . 6% 2 97 . 1% 1 96 . 1% 2 67 . 7% 2 97 . 2% 2 |
|
| 281 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 282 |
+
|
| 283 |
+
Table 3: Regularization results in the case distinction task with output from the first token. The top three rows correspond to the best mean training accuracy, while the bottom three rows correspond to the best mean validation accuracy when validating on sequences of half the length.
|
| 284 |
+
|
| 285 |
+
| BERT MTE NAP NON sum max unregularized 36.6% 66.5% 94.5% 23.2% 22.8% 97.8% with dropout 44 . 9% 1 44 . 3% 1 85 . 0% 1 23 . 2% 1 22 . 6% 1 92 . 6% 1 with L 2 -regularization 36 . 0% 2 55 . 3% 1 93 . 8% 2 22 . 8% 1 22 . 8% 1 95 . 4% 1 unregularized 36.7% 50.6% 83.9% 29.6% 28.5% 88.5% with dropout 41 . 4% 2 40 . 7% 1 74 . 6% 1 29 . 6% 3 28 . 9% 4 87 . 8% 1 with L 2 -regularization 37 . 2% 2 45 . 7% 1 82 . 5% 2 28 . 9% 1 29 . 0% 1 81 . 0% 1 |
|
| 286 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 287 |
+
|
| 288 |
+
Table 4: Regularization results in the mode finding task. The top three rows correspond to the best mean training accuracy, while the bottom three rows correspond to the best mean validation accuracy when validating on sequences of twice the length.
|
| 289 |
+
|
| 290 |
+
| BERT MTE NAP NON sum max unregularized 99.6% 99.8% 99.6% 98.7% 99.8% 14.4% with dropout 93 . 9% 1 93 . 3% 1 94 . 3% 1 91 . 8% 1 93 . 3% 1 24 . 5% 1 with L 2 -regularization 99 . 5% 1 99 . 9% 2 99 . 7% 1 98 . 8% 1 99 . 9% 4 14 . 4% 2 unregularized 95.3% 95.4% 94.9% 91.3% 95.8% 13.5% with dropout 94 . 8% 2 95 . 4% 2 93 . 8% 1 92 . 6% 1 95 . 7% 2 13 . 4% 4 with L 2 -regularization 94 . 7% 1 96 . 0% 1 94 . 9% 1 94 . 7% 2 95 . 8% 1 13 . 7% 1 |
|
| 291 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 292 |
+
|
| 293 |
+
Overall we note that none of the architectures consistently benefits from regularization in our setup and regularization often decreases mean performance. Further, we point out that the best performance with regularization is most of the times achieved with the smallest regularization.
|
| 294 |
+
|
| 295 |
+
## F Case Learning Curves
|
| 296 |
+
|
| 297 |
+
Figures 10, 11 and 12 show the case accuracies over the course of training. The corresponding results in the main text are given in Figure 3 (top row). Besides the observations made in the main text, a few additional insights can be noted: (1) Cases are mostly learned in the order of their occurrences (recall that 72 . 37% of the examples are from the argmin case, 20 . 09% are from the fi rst case and 7 . 53% are from the argmax case). This is to be expected when training with gradient descent, cf. [6]. (2) This order is not always given in the BERT architecture. Besides the focus on the fi rst case if the learning rate is too high - discussed in the main text - we also highlight a curiosity that occurs when the model dimension is too small (see plot highlighted in with red in Figure 10): The fi rst case is learned and then unlearned in favor of the argmin case. Note that all 5 random seeds follow this pattern. Note also that for a different learning rate, the opposite holds as seen in the plot just below the highlighted plot.
|
| 298 |
+
|
| 299 |
+
We highly encourage an interested reader to check out our code release 4 , which includes all results as well as visualization scripts to inspect them further.
|
| 300 |
+
|
| 301 |
+
[4 https://github.com/OliverRichter/normalized-attention](https://github.com/OliverRichter/normalized-attention)
|
| 302 |
+
|
| 303 |
+
Figure 10: Case accuracies over the course of training on the argmin -fi rst -argmax case distinction task with output across all tokens, cf. Section 5.1. Each small sub-plot shows the case accuracies (y-axis, bottom is set to 0%, top to 100%) over the course of training (x-axis). Solid lines represent the mean accuracy over the 5 random seeds while shaded areas fill the spread between min- and max-accuracy achieved. Models BERT and MTE are shown here, cf. Figures 11 and 12.
|
| 304 |
+
|
| 305 |
+
<!-- image -->
|
| 306 |
+
|
| 307 |
+
Figure 11: Case accuracies over the course of training on the argmin -fi rst -argmax case distinction task with output across all tokens, cf. Section 5.1. Each small sub-plot shows the case accuracies (y-axis, bottom is set to 0%, top to 100%) over the course of training (x-axis). Solid lines represent the mean accuracy over the 5 random seeds while shaded areas fill the spread between min- and max-accuracy achieved. Models NAP and NON are shown here, cf. Figures 10 and 12.
|
| 308 |
+
|
| 309 |
+
<!-- image -->
|
| 310 |
+
|
| 311 |
+
Figure 12: Case accuracies over the course of training on the argmin -fi rst -argmax case distinction task with output across all tokens, cf. Section 5.1. Each small sub-plot shows the case accuracies (y-axis, bottom is set to 0%, top to 100%) over the course of training (x-axis). Solid lines represent the mean accuracy over the 5 random seeds while shaded areas fill the spread between min- and max-accuracy achieved. Models sum and max are shown here, cf. Figures 10 and 11.
|
| 312 |
+
|
| 313 |
+
<!-- image -->
|
| 314 |
+
|
| 315 |
+
## G Argmin-First-Argmax Case Distinction Task - Additional Results
|
| 316 |
+
|
| 317 |
+
## G.1 Varying Batch Size
|
| 318 |
+
|
| 319 |
+
In Figure 13 we provide the case accuracy results of an additional experiment, varying the batch size. In this experiment we train the models using different batch sizes, adjusting the number of training steps accordingly to keep the total number of training points seen constant. With this experiment we aim to show the training behaviour of the different architectures if we go from single example batches (many, potentially noisier updates) to batches of size 128 - a batch size in which each batch contains in expectation several examples per case, but fewer updates are made to the network parameters. Besides replicating several insights made in the main text, this experiment additionally shows: (1) smaller batches require a smaller learning rate, supporting our argument that hyper-parameters should not be optimized independent of each other. (2) The focus of BERT on the fi rst -case when the learning rate is too high is amplified in smaller batches.
|
| 320 |
+
|
| 321 |
+
Figure 13: Learning rate (y-axis) vs. batch size (x-axis) on the argmin-first-argmax case distinction task (with output across all tokens). RGB pixel values correspond to argmin -, fi rst - and argmax -caseaccuracies, respectively.
|
| 322 |
+
|
| 323 |
+
<!-- image -->
|
| 324 |
+
|
| 325 |
+
## G.2 First Token Output - Varying Model Dimension
|
| 326 |
+
|
| 327 |
+
Section 5.2 discusses the case accuracies when training on the case distinction task with outputs taken from the first token. In Figure 14 we addtionally give best the min-, mean- and max-accuracies over the course of training. The top row corresponds to in-distribution/training accuracy ( N = 128 ) while the bottom row corresponds to out-of-distribution generalization accrucay when validating on sequences of half the length ( N = 64 ). Again we note a correlation between optimal learning rate and model dimension, especially in the BERT and MTE architecture. We also note that these probability simplex constrained architectures have a large performance variation across random seeds in this setup.
|
| 328 |
+
|
| 329 |
+
## G.3 First Token output - Varying Depth
|
| 330 |
+
|
| 331 |
+
In this section we investigate whether our results are tied to the shallow architecture of L = 2 Transformer layers. We therefore vary the number of Tranfromer layers L and report the results on the case distinction task with outputs taken from the first token in Figure 15. The results lead us to the following observations: (1) The BERT architecture does seem to perform better when the number of Transformer layers is increased to L = 4 . However, the performance degrades if we further increase the depth. (2) The NAP architecture achieves a higher best mean accuracy and performs well on a wide range of depths. (3) The max architecture performs well on the biggest range of hyperparameters. This is due to the beneficial architectural prior as discussed in the main text.
|
| 332 |
+
|
| 333 |
+
Figure 14: Learning rate (y-axis) vs. model dimension d (x-axis) on the case distinction task with output from the first token. RGB pixel values correspond to min, mean and max accuracy. Top row: Training accuracy (sequence length N = 128 ). Bottom row: Validation accuracy when validating on sequences of half the length ( N = 64 ). Crosses indicate the combination for best mean validation accuracy, which we report behind the model name.
|
| 334 |
+
|
| 335 |
+
<!-- image -->
|
| 336 |
+
|
| 337 |
+
Figure 15: Learning rate (y-axis) vs. Transformer-layers L (x-axis) on the case distinction task (output from the first token). RGB pixel values correspond to min, mean and max accuracy. Top row: Training accuracy (sequence length N = 128 ). Bottom row: Validation accuracy when validating on sequences of half the length ( N = 64 ). Crosses indicate the combination for best mean validation accuracy, which we report behind the model name.
|
| 338 |
+
|
| 339 |
+
<!-- image -->
|
| 340 |
+
|
| 341 |
+
## H Mode Finding Task - Varying Vocabulary Size
|
| 342 |
+
|
| 343 |
+
Figure 16 shows the results of an additional experiment, varying the vocabulary size S while keeping the sequence length N = 128 constant during training. For this experiment, we also vary the total number of training steps and set it to 400 · S , to keep the number of examples seen per vocabulary token approximately constant. We also include zero-shot generalization results when testing on sequences of twice the length ( N = 256 ). Compared to the case distinction task we can do such a generalization evaluation here as we do not learn any positional embeddings in this setup. We make the following observations: (1) max completely fails to learn in any of the vocabulary sizes. Note that the shading to the left merely corresponds to the majority class base rate. (2) NAP struggles when the vocabulary consists of only 2 tokens. This is expected, as the mean subtraction in the normalization effectively removes the task relevant information (the mode) in this case. Note however, that for a high enough learning rate, the model learns to use the bias parameter b introduced in Equation 1 effectively reverting to sum pooling. (3) While all models learn the task well on small vocabularies, NAP outperforms all other approaches significantly when S gets larger then the training sequence length, cf. Table 5.
|
| 344 |
+
|
| 345 |
+
Figure 16: Learning rate (y-axis) vs. vocabulary size S (x-axis) on the mode finding task. RGB pixel values correspond to min, mean and max accuracy. Top row: Training accuracy (sequence length N = 128 ). Bottom row: Validation accuracy when validating on sequences of twice the length ( N = 256 ). Crosses indicate the learning rate for best mean accuracy, which we report in Table 5.
|
| 346 |
+
|
| 347 |
+
<!-- image -->
|
| 348 |
+
|
| 349 |
+
Table 5: Best mean accuracy per vocabulary size, taken from the combinations indicated in Figure 16. First six rows correspond to training accuracies, bottom six rows correspond to validation accuracies. Bold numbers indicate a min-accuracy higher than the best max accuracy of all other models.
|
| 350 |
+
|
| 351 |
+
| S = 2 S = 4 S = 8 S = 16 S = 32 S = 64 S = 128 S = 256 BERT 100% 99.9% 99.9 % 92.1% 72.5% 76.2% 77.4% 74.4% MTE 100% 100% 99.9% 99.8% 99.3% 97.3% 73.3% 64.9% NAP 100% 99.9% 99.8% 99.6% 99.7% 99.6% 97.4% 84.6% NON 100% 99.9% 99.2% 97.3% 74.7% 71.5% 65.2% 61.5% sum 100% 100% 99.9% 99.8% 99.7% 99.2% 97.5% 60.6% max 55.7% 30.1% 17.3% 10.4% 6.6% 4.6% 3.6% 3.1% BERT 100% 98.2% 95.8 % 88.0% 65.7% 68.6% 68.0% 53.0% MTE 99.2% 98.4% 96.1% 93.6% 90.5% 85.4% 61.6% 38.9% NAP 99.6% 98.4% 95.8% 93.1% 90.6% 90.4% 84.3% 64.3% NON 100% 97.7% 93.1% 85.7% 66.4% 58.3% 50.2% 46.4% sum 99.0% 97.9% 96.7% 94.4% 91.6% 89.1% 85.9% 45.6% max 53.8% 29.3% 16.1% 9.5% 6.0% 4.2% 3.0% 2.1% |
|
| 352 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
text-versions/attention-markdown/2006.10962_Attention Mesh Highfidelity Face Mesh Pr.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2006.10962 Attention Mesh Highfidelity Face Mesh Pr
|
| 2 |
+
|
| 3 |
+
## Attention Mesh: High-fidelity Face Mesh Prediction in Real-time
|
| 4 |
+
|
| 5 |
+
Ivan Grishchenko Artsiom Ablavatski Yury Kartynnik Karthik Raveendran Matthias Grundmann Google Research 1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA
|
| 6 |
+
|
| 7 |
+
{ igrishchenko, artsiom, kartynnik, krav, grundman } @google.com
|
| 8 |
+
|
| 9 |
+
## Abstract
|
| 10 |
+
|
| 11 |
+
We present Attention Mesh, a lightweight architecture for 3D face mesh prediction that uses attention to semantically meaningful regions. Our neural network is designed for real-time on-device inference and runs at over 50 FPS on a Pixel 2 phone. Our solution enables applications like AR makeup, eye tracking and AR puppeteering that rely on highly accurate landmarks for eye and lips regions. Our main contribution is a unified network architecture that achieves the same accuracy on facial landmarks as a multistage cascaded approach, while being 30 percent faster.
|
| 12 |
+
|
| 13 |
+
## 1. Introduction
|
| 14 |
+
|
| 15 |
+
In this work, we address the problem of registering a detailed 3D mesh template to a human face on an image. This registered mesh can be used for the virtual try-on of lipstick or puppeteering of virtual avatars where the accuracy of lip and eye contours is critical to realism.
|
| 16 |
+
|
| 17 |
+
In contrast to methods that use a parametric model of the human face [1], we directly predict the positions of face mesh vertices in 3D. We base our architecture on earlier efforts in this field [5] that use a two stage architecture involving a face detector followed by a landmark regression network. However, using a single regression network for the entire face leads to degraded quality in regions that are perceptually more significant ( e.g . lips, eyes).
|
| 18 |
+
|
| 19 |
+
One possible way to alleviate this issue is a cascaded approach: use the initial mesh prediction to produce tight crops around these regions and pass them to specialized networks to produce higher quality landmarks. While this directly addresses the problem of accuracy, it introduces performance issues, e.g . relatively large separate models that use the original image as input, and additional synchronization steps between the GPU and CPU that are very costly on mobile phones. In this paper, we show that it is possible for a single model to achieve the same quality as the cascaded approach by employing region-specific heads that transform the feature maps with spatial transformers [4], while being up to 30 percent faster during inference. We term this architecture as attention mesh . An added benefit is that it is easier to train and distribute since it is internally consistent compared to multiple disparate networks that are chained together.
|
| 20 |
+
|
| 21 |
+
Figure 1. Salient contours predicted by Attention Mesh submodels
|
| 22 |
+
|
| 23 |
+
<!-- image -->
|
| 24 |
+
|
| 25 |
+
We use an architecture similar to one described in [7], where the authors build a network that is robust to the initialization provided by different face detectors. Despite the differing goals of the two papers, it is interesting to note that both suggest that a combination of using spatial transformers with heads corresponding to salient face regions produces marked improvements over a single large network. We provide the details of our implementation for producing landmarks corresponding to eyes, irises, and lips, as well as quality and inference performance benchmarks.
|
| 26 |
+
|
| 27 |
+
## 2. Attention mesh
|
| 28 |
+
|
| 29 |
+
Model architecture The model accepts a 256 × 256 image as input. This image is provided by either the face detector or via tracking from a previous frame. After extract- ing a 64 × 64 feature map, the model splits into several sub-models (Figure 2). One submodel predicts all 478 face mesh landmarks in 3D and defines crop bounds for each region of interest. The remaining submodels predict region landmarks from the corresponding 24 × 24 feature maps that are obtained via the attention mechanism.
|
| 30 |
+
|
| 31 |
+
Figure 2. The inference pipeline and the model architecture overview
|
| 32 |
+
|
| 33 |
+
<!-- image -->
|
| 34 |
+
|
| 35 |
+
Weconcentrate on three facial regions with key contours: the lips and two eyes (Figure 1). Each eye submodel predicts the iris as a separate output after reaching the spatial resolution of 6 × 6 . This allows the reuse of eye features while keeping dynamic iris independent from the more static eye landmarks.
|
| 36 |
+
|
| 37 |
+
Individual submodels allow us to control the network capacity dedicated to each region and boost quality where necessary. To further improve the accuracy of the predictions, we apply a set of normalizations to ensure that the eyes and lips are aligned with the horizontal and are of uniform size.
|
| 38 |
+
|
| 39 |
+
We train the attention mesh network in two phases. First, we employ ideal crops from the ground truth with slight augmentations and train all submodels independently. Then, we obtain crop locations from the model itself and train again to adapt the region submodels to them.
|
| 40 |
+
|
| 41 |
+
Attention mechanism Several attention mechanisms (soft and hard) have been developed for visual feature extraction [2, 4]. These attention mechanisms sample a grid of 2D points in feature space and extract the features under the sampled points in a differentiable manner ( e.g . using 2D Gaussian kernels or affine transformations and differentiable interpolations). This allows to train architectures endto-end and enrich the features that are used by the attention mechanism. Specifically, we use a spatial transformer mod- ule [4] to extract 24 × 24 region features from the 64 × 64 feature map. The spatial transformer is controlled by an affine transformation matrix θ (Equation 1) and allows us to zoom, rotate, translate, and skew the sampled grid of points.
|
| 42 |
+
|
| 43 |
+
<!-- formula-not-decoded -->
|
| 44 |
+
|
| 45 |
+
This affine transformation can be constructed either via supervised prediction of matrix parameters, or by computing them from the output of the face mesh submodel.
|
| 46 |
+
|
| 47 |
+
Figure 3. Spatial transformer as the attention mechanism
|
| 48 |
+
|
| 49 |
+
<!-- image -->
|
| 50 |
+
|
| 51 |
+
Dataset Our dataset contains 30K in-the-wild mobile camera photos taken with numerous camera sensors and in varied conditions. We used manual annotation with special emphasis on consistency for salient contours to obtain the ground truth mesh vertex coordinates in 2D. The Z coordinate was approximated using a synthetic model.
|
| 52 |
+
|
| 53 |
+
## 3. Results
|
| 54 |
+
|
| 55 |
+
To evaluate our unified approach, we compare it against the cascaded model which consists of independently trained region-specific models for the base mesh, eyes and lips that are run in succession.
|
| 56 |
+
|
| 57 |
+
Performance Table 1 demonstrates that the attention mesh runs 25%+ faster than the cascade of separate face and region models on a typical modern mobile device. The performance has been measured using the TFLite GPU inference engine [6]. An additional 5% speed-up is achieved due to the reduction of costly CPU-GPU synchronizations, since the whole attention mesh inference is performed in one pass on the GPU.
|
| 58 |
+
|
| 59 |
+
Table 1. Performance on Pixel 2XL (ms)
|
| 60 |
+
|
| 61 |
+
| Model Inference Time (ms) Mesh 8.82 Lips 4.18 Eye & iris 4.70 Cascade (sum of above) 22.4 Attention Mesh 16.6 |
|
| 62 |
+
|--------------------------------------------------------------------------------------------------------------------------------|
|
| 63 |
+
|
| 64 |
+
Mesh quality A quantitative comparison of both models is presented in Table 2. As the representative metric, we employ the mean distance between the predicted and ground truth locations of a specific subset of the points, normalized by 3D interocular distance (or the distance between the corners in the case of lips and eyes) for scale invariance. The attention mesh model outperforms the cascade of models on the eye regions and demonstrates comparable performance on the lips region.
|
| 65 |
+
|
| 66 |
+
Table 2. Mean normalized error in 2D.
|
| 67 |
+
|
| 68 |
+
| Model All Lips Eyes Mesh 2.99 3.28 6.6 Cascade 2.99 2.70 6.28 Attention mesh 3.11 2.89 6.04 |
|
| 69 |
+
|--------------------------------------------------------------------------------------------------------------|
|
| 70 |
+
|
| 71 |
+
## 4. Applications
|
| 72 |
+
|
| 73 |
+
The performance of our model enables several real-time AR applications like virtual try-on of makeup and puppeteering.
|
| 74 |
+
|
| 75 |
+
AR Makeup Accurate registration of the face mesh is critical to applications like AR makeup where even small errors in alignment can drive the rendered effect into the 'uncanny valley' [8]. We built a lipstick rendering solution (Figure 4) on top of our attention mesh model by using the contours provided by the lip submodel. A/B testing on 10 images and 80 people showed that 46% of AR samples were actually classified as real and 38% of real samples as AR.
|
| 76 |
+
|
| 77 |
+
Figure 4. Virtual makeup comparison: base mesh without refinements (left) vs. attention mesh with submodels (right)
|
| 78 |
+
|
| 79 |
+
<!-- image -->
|
| 80 |
+
|
| 81 |
+
Puppeteering Our model can also be used for virtual puppeteering and facial triggers. We built a small fully connected model that predicts 10 blend shape coefficients for the mouth and 8 blend shape coefficients for each eye. We feed the output of the attention mesh submodels to this blend shape network. In order to handle differences between various human faces, we apply Laplacian mesh editing to morph a canonical mesh into the predicted mesh [3]. This lets us use the blend shape coefficients for different human faces without additional fine-tuning. We demonstrate some results in Figure 5.
|
| 82 |
+
|
| 83 |
+
Figure 5. Puppeteering
|
| 84 |
+
|
| 85 |
+
<!-- image -->
|
| 86 |
+
|
| 87 |
+
## 5. Conclusion
|
| 88 |
+
|
| 89 |
+
We present a unified model that enables accurate face mesh prediction in real-time. By using a differentiable attention mechanism, we are able to devote computational resources to salient face regions without incurring the performance penalty of running independent regionspecific models. Our model and demos will soon be avail- able in MediaPipe ( https://github.com/google/ mediapipe ).
|
| 90 |
+
|
| 91 |
+
## References
|
| 92 |
+
|
| 93 |
+
- [1] Volker Blanz and Thomas Vetter. A morphable model for the synthesis of 3D faces. In Proceedings of 36th Internaional Conference and Exhibition on Computer Graphics and Interactive Techniques , pages 187-194, 1999. 1
|
| 94 |
+
- [2] Karol Gregor, Ivo Danihelka, Alex Graves, Danilo Jimenez Rezende, and Daan Wierstra. Draw: A recurrent neural network for image generation. arXiv preprint arXiv:1502.04623 , 2015. 2
|
| 95 |
+
- [3] Jianwei Hu, Ligang Liu, and Guozhao Wang. Dual laplacian morphing for triangular meshes. Computer Animation and Virtual Worlds , 18(45):271-277, 2007. 3
|
| 96 |
+
- [4] Max Jaderberg, Karen Simonyan, Andrew Zisserman, et al. Spatial transformer networks. In Advances in neural information processing systems , pages 2017-2025, 2015. 1, 2
|
| 97 |
+
- [5] Yury Kartynnik, Artsiom Ablavatski, Ivan Grishchenko, and Matthias Grundmann. Real-time Facial Surface Geometry from Monocular Video on Mobile GPUs. arXiv preprint arXiv:1502.04623 , July 2019. 1
|
| 98 |
+
- [6] Juhyun Lee, Nikolay Chirkov, Ekaterina Ignasheva, Yury Pisarchyk, Mogan Shieh, Fabio Riccardi, Raman Sarokin, Andrei Kulik, and Matthias Grundmann. On-device neural net inference with mobile gpus. arXiv preprint arXiv:1907.01989 , 2019. 3
|
| 99 |
+
- [7] J. Lv, X. Shao, J. Xing, C. Cheng, and X. Zhou. A deep regression architecture with two-stage re-initialization for high performance facial landmark detection. In 2017 IEEE Conference on Computer Vision and Pattern Recognition (CVPR) , pages 3691-3700, 2017. 1
|
| 100 |
+
- [8] Junichiro Seyama and Ruth S. Nagayama. The uncanny valley: Effect of realism on the impression of artificial human faces. Presence: Teleoper. Virtual Environ. , 16(4):337351, Aug. 2007. 3
|
text-versions/attention-markdown/2006.13730_AttentionBased Neural Networks for Senti.md
ADDED
|
@@ -0,0 +1,449 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2006.13730 Attentionbased Neural Networks For Senti
|
| 2 |
+
|
| 3 |
+
## Attention-Based Neural Networks for Sentiment Attitude Extraction using Distant Supervision
|
| 4 |
+
|
| 5 |
+
Nicolay Rusnachenko kolyarus@yandex.ru Bauman Moscow State Technical University
|
| 6 |
+
|
| 7 |
+
Moscow, Russia
|
| 8 |
+
|
| 9 |
+
## ABSTRACT
|
| 10 |
+
|
| 11 |
+
In the sentiment attitude extraction task, the aim is to identify «attitudes» - sentiment relations between entities mentioned in text. In this paper, we provide a study on attention-based context encoders in the sentiment attitude extraction task. For this task, we adapt attentive context encoders of two types: (1) feature-based; (2) selfbased. In our study, we utilize the corpus of Russian analytical texts RuSentRel and automatically constructed news collection RuAttitudes for enriching the training set. We consider the problem of attitude extraction as two-class (positive, negative) and three-class (positive, negative, neutral) classification tasks for whole documents. Our experiments 1 with the RuSentRel corpus show that the threeclass classification models, which employ the RuAttitudes corpus for training, result in 10% increase and extra 3% by F 1 , when model architectures include the attention mechanism. We also provide the analysis of attention weight distributions in dependence on the term type.
|
| 12 |
+
|
| 13 |
+
## CCS CONCEPTS
|
| 14 |
+
|
| 15 |
+
· Computing methodologies → Neural networks ; Natural language processing .
|
| 16 |
+
|
| 17 |
+
## ACMReference Format:
|
| 18 |
+
|
| 19 |
+
Nicolay Rusnachenko and Natalia Loukachevitch. 2020. Attention-Based Neural Networks for Sentiment Attitude Extraction using Distant Supervision. In Proceedings of WIMS '20. ACM, Biarritz, France https://doi.org/10.1145/ nnnnnnn.nnnnnnn
|
| 20 |
+
|
| 21 |
+
## 1 INTRODUCTION
|
| 22 |
+
|
| 23 |
+
Classifying relations between entities mentioned in texts remains one of the difficult tasks in natural language processing (NLP). The sentiment attitude extraction aims to seek for positive/negative relations between objects expressed as named entities in texts [14]. For example, in Figure 1 named entities «Russia» and «NATO» have the negative attitude towards each other with additional indication of other named entities.
|
| 24 |
+
|
| 25 |
+
[1 https://github.com/nicolay-r/attitude-extraction-with-attention-and-ds](https://github.com/nicolay-r/attitude-extraction-with-attention-and-ds)
|
| 26 |
+
|
| 27 |
+
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from permissions@acm.org.
|
| 28 |
+
|
| 29 |
+
WIMS '20, June 30th - July 3rd, 2020, Biarritz, France
|
| 30 |
+
|
| 31 |
+
©2020 Association for Computing Machinery.
|
| 32 |
+
|
| 33 |
+
ACM ISBN 978-1-4503-XXXX-X/20/06...$15.00
|
| 34 |
+
|
| 35 |
+
https://doi.org/10.1145/nnnnnnn.nnnnnnn Natalia Loukachevitch louk\_nat@mail.ru Lomonosov Moscow State University Moscow, Russia When extracting relations from texts, one encounters the complexity of the sentence structure; sentences can contain many named entity mentions; a single opinion might comprise several sentences.
|
| 36 |
+
|
| 37 |
+
Figure 1: Example of a context with attitudes mentioned in it; named entities «Russia» and «NATO» have the negative attitude towards each other with additional indication of other named entities.
|
| 38 |
+
|
| 39 |
+
| CONTEXT При этом Москва Москва Москва Москва Москва Москва Москва Москва Москва неоднократно подчерки- вала, что ее активность на балтике балтике балтике балтике балтике балтике балтике балтике балтике явля- ется ответом именно на действия НАТО НАТО НАТО НАТО НАТО НАТО НАТО НАТО НАТО и эскалацию враждебного подхода к России России России России России России России России России вблизи ее восточных границ . . . Meanwhile Moscow Moscow Moscow Moscow Moscow Moscow Moscow Moscow Moscow has repeatedly emphasized that its activity in the Baltic Sea Baltic Sea Baltic Sea Baltic Sea Baltic Sea Baltic Sea Baltic Sea Baltic Sea Baltic Sea is a response pre- cisely to actions of NATO NATO NATO NATO NATO NATO NATO NATO NATO and the escalation of the hostile approach to Russia Russia Russia Russia Russia Russia Russia Russia Russia near its eastern borders . . . ATTITUDES NATO → Russia : neg Russia → NATO : neg |
|
| 40 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 41 |
+
|
| 42 |
+
This paper is devoted to study of models for targeted sentiment analysis with attention. The intuition exploited in the models with attentive encoders is that only some terms in the context are relevant for attitude indication. The interactions of words, not just their isolated presence, may reveal the specificity of contexts with attitudes of different polarities. We additionally used the distant supervision (DS) [12] technique to fine-tune the attention mechanism by providing relevant contexts, with words that indicate the presence of attitude. Our contribution in this paper is three-fold:
|
| 43 |
+
|
| 44 |
+
- We apply attentive encoders based on (1) attitude participants and (2) context itself;
|
| 45 |
+
- We conduct the experiments on the RuSentRel [9] collection using the distant supervision technique in the training process. The results demonstrate that the application of attention-based encoders enhance quality by 3% F 1 in the three-class classification task;
|
| 46 |
+
- We provide an analysis of weight distribution to illustrate the influence of distant supervision onto informative terms selection.
|
| 47 |
+
|
| 48 |
+
## 2 RELATED WORK
|
| 49 |
+
|
| 50 |
+
In previous works, various neural network approaches for targeted sentiment analysis were proposed. In [14] the authors utilize convolutional neural networks (CNN). Considering relation extraction as a three-scale classification task of contexts with attitudes in it, the authors subdivide each context into outer and inner (relative to attitude participants) to apply Piecewise-CNN (PCNN) [20]. The latter architecture utilizes a specific idea of the max-pooling operation. Initially, this is an operation, which extracts the maximal values within each convolution. However, for relation classification, it reduces information extremely rapid and blurs significant aspects of context parts. In case of PCNN, separate max-pooling operations are applied to outer and inner contexts. In the experiments, the authors revealed a fast training process and a slight improvement in the PCNN results in comparison to CNN.
|
| 51 |
+
|
| 52 |
+
In [16], the authors proposed an attention-based CNN model for semantic relation classification [5]. The authors utilized the attention mechanism to select the most relevant context words with respect to participants of a semantic relation. The architecture of the attention model is a multilayer perceptron (MLP), which calculates the weight of a word in context with respect to the entity. The resulting ATTCNN model outperformed several CNN and LSTM based approaches with 2 . 6-3 . 8% by F1-measure.
|
| 53 |
+
|
| 54 |
+
In [18, 21], the authors experimented with self-based attention models, in which targets became adapted automatically during the training process. The authors considered the attention as context word quantification with respect to abstract targets. In [18], the authors brought a similar idea also onto the sentence level. The obtained hierarchical model was called as HAN.
|
| 55 |
+
|
| 56 |
+
In [15], authors apply distant supervision (DS) approach to developing an automatic collection for the sentiment attitude extraction task in the news domain. A combination of two labeling methods (1) pair-based and (2) frame-based were used to perform context labeling. The developed collection was called as RuAttitudes. Experimenting with the RuSentRel corpus, the authors consider the problem of sentiment attitude extraction as a two-class classification task and mention the 13.4% increase by F 1 when models trained with an application of RuAttitudes over models which training relies on supervised learning.
|
| 57 |
+
|
| 58 |
+
For Russian, Archipenko et al. [1] compared neural architectures for entity-related tweet setiment classification; they found that the best results were obtained with the GRU neural model [2]. The authors of [13] annotated more than 31 thousand social media posts in Russian with three sentiment categories and compared several baseline classification methods, obtaining the best results with a four-layer neural model with non-linear activations between layers. These results were improved in [8], where the authors applied the BERT model trained on Russian data (RuBERT). Tutubalina et al. [17] compared several neural network models to extract positive or negative adverse drug reactions in Russian social network texts.
|
| 59 |
+
|
| 60 |
+
## 3 RESOURCES
|
| 61 |
+
|
| 62 |
+
In our study we utilize the following collections: (1) RuSentRel as a source of news texts with manually provided attitude labeling in it, and (2) automatically developed RuAttitudes collection, which addresses the lack of training examples in RuSentRel.
|
| 63 |
+
|
| 64 |
+
We also use two Russian sentiment resources: the RuSentiLex lexicon [9], which contains words and expressions of the Russian language with sentiment labels and the RuSentiFrames lexicon [15], which provides several types of sentiment attitudes for situations associated with specific Russian predicates.
|
| 65 |
+
|
| 66 |
+
## 3.1 RuSentRel collection
|
| 67 |
+
|
| 68 |
+
We consider sentiment analysis of Russian analytical articles collected in the RuSentRel corpus [10]. The corpus comprises texts in the international politics domain and contains a lot of opinions. The articles are labeled with annotations of two types: (1) the author's opinion on the subject matter of the article; (2) the attitudes between the participants of the described situations. The annotation of the latter type includes 2000 relations across 73 large analytical texts. Annotated sentiments can be only positive or negative . Additionally, each text is provided with annotation of mentioned named entities. Synonyms and variants of named entities are also given, which allows not to deal with the coreference of named entities.
|
| 69 |
+
|
| 70 |
+
## 3.2 RuSentiFrames lexicon
|
| 71 |
+
|
| 72 |
+
The RuSentiFrames 2 lexicon describes sentiments and connotations conveyed with a predicate in a verbal or nominal form [15], such as "осудить, улучшить, преувеличить" (to condemn, to improve, to exaggerate), etc. The structure of the frames in RuSentFrames comprises: (1) the set of predicate-specific roles; (2) frames dimensions such as the attitude of the author towards participants of the situation, attitudes between the participants, effects for participants. Currently, RuSentiFrames contains frames for more than 6 thousand words and expressions.
|
| 73 |
+
|
| 74 |
+
Table 1: Example description of frame «Одобрить» (Approve) in RuSentiLex lexicon.
|
| 75 |
+
|
| 76 |
+
| Frame "Одобрить" (Approve) ROLES A0 : who approves A1 : what is approved POLARITY A0 → A1 , pos, 1.0 A1 → A0 , pos, 0.7 EFFECT A1 , pos, 1.0 STATE A0 , pos, 1.0 A1 , pos, 1.0 |
|
| 77 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 78 |
+
|
| 79 |
+
In RuSentiFrames, individual semantic roles are numbered, beginning with zero. For a particular predicate entry, Arg0 is generally the argument exhibiting features of a Prototypical Agent, while Arg1 is a Prototypical Patient or Theme [3]. In the main part of the frame, the most applicable for the current study is the polarity of Arg0 with a respect to Arg1 ( A0 → A1 ). Table 1 provides an example of frame "одобрить" (to approve).
|
| 80 |
+
|
| 81 |
+
## 3.3 RuAttitudes
|
| 82 |
+
|
| 83 |
+
The RuAttitudes [15] is a corpus of news texts automatically labeled using distant supervision approach. These are news stories from specialized political sites and Russian sites of world-known news agencies published in 2017. The news texts are annotated with attitudes between participants, which sentiments can be only positive or negative. In comparison with RuSentRel, the RuAttitudes corpus includes 14 . 6 K attitudes gathered across 13 . 4 K news texts.
|
| 84 |
+
|
| 85 |
+
Every news text is presented as a sequence of its contexts, where the first context is a news title and others are news content or sentences . For a particular news story, the RuAttitudes corpus keeps
|
| 86 |
+
|
| 87 |
+
[2 https://github.com/nicolay-r/RuSentiFrames/tree/v1.0](https://github.com/nicolay-r/RuSentiFrames/tree/v1.0)
|
| 88 |
+
|
| 89 |
+
## TITLE
|
| 90 |
+
|
| 91 |
+
Маккейн: США США США США США США США США США e продолжат pos поддержку pos Грузии Грузии Грузии Грузии Грузии Грузии Грузии Грузии Грузии e McCain: USA USA USA USA USA USA USA USA USA e continue pos supporting pos Georgia Georgia Georgia Georgia Georgia Georgia Georgia Georgia Georgia e
|
| 92 |
+
|
| 93 |
+
## ↓ USA → Georgia pos
|
| 94 |
+
|
| 95 |
+
## SENTENCE: 5
|
| 96 |
+
|
| 97 |
+
«США США США США США США США США США e и далее продолжат pos поддержку pos свободы, суверенитета и территориальной целостности Грузии Грузии Грузии Грузии Грузии Грузии Грузии Грузии Грузии e в рамках международно признанных границ страны», - сказал он.
|
| 98 |
+
|
| 99 |
+
«USA USA USA USA USA USA USA USA USA e and in further continue pos support pos freedom, sovereignty and territorial integrity Georgia Georgia Georgia Georgia Georgia Georgia Georgia Georgia Georgia e within the internationally recognized borders of the country», - he said.
|
| 100 |
+
|
| 101 |
+
## ↓ USA → Georgia pos
|
| 102 |
+
|
| 103 |
+
## SENTENCE: 11
|
| 104 |
+
|
| 105 |
+
29 декабря премьер-министр Квирикашвили Квирикашв��ли Квирикашвили Квирикашвили Квирикашвили Квирикашвили Квирикашвили Квирикашвили Квирикашвили e сообщил, что правительство Грузии Грузии Грузии Грузии Грузии Грузии Грузии Грузии Грузии e установило первые контакты с новой администрацией США США США США США США США США США e .
|
| 106 |
+
|
| 107 |
+
29'th december prime-minister Kvirikashvili Kvirikashvili Kvirikashvili Kvirikashvili Kvirikashvili Kvirikashvili Kvirikashvili Kvirikashvili Kvirikashvili e reported, that the government of Georgia Georgia Georgia Georgia Georgia Georgia Georgia Georgia Georgia e has established first contacts with the new USA USA USA USA USA USA USA USA USA administration.
|
| 108 |
+
|
| 109 |
+
e
|
| 110 |
+
|
| 111 |
+
Figure 2: Example of news (#11323) description from RuAttitudes-1.1 collection illustrates the attitude USA → Georgia pos which is annotated by FRAME-BASED and PAIR-BASED factors in news title with the corresponding appearance of ⟨ USA , Georдia ⟩ pair in the sentences (#5, #11) of news content.
|
| 112 |
+
|
| 113 |
+
information of only those contexts, which has at least one attitude mentioned in it. Each context is presented as a sequence of words with named entities markup. According to Section 2, the authors considered an application of two factors (1) PAIR-BASED and (2) FRAME-BASED in order to define the fact of presence and sentiment polarity of an attitude , which is described by a pair of mentioned named entities.
|
| 114 |
+
|
| 115 |
+
PAIR-BASED factor assumes to perform annotation using a list of entity pairs with preassigned sentiment polarities. In turn, FRAMEBASED factor utilizes infomation from the RuSentiFrames lexicon (Section 3.2) in order to perform annotation. The context is retrieved in case when both factors are met. Due to the latter, it is worth to mention the specifics of the FRAME-BASED factor. A pair of neighbour named entities is considered as having a sentiment attitude when a news title has the following structure:
|
| 116 |
+
|
| 117 |
+
<!-- formula-not-decoded -->
|
| 118 |
+
|
| 119 |
+
where k corresponds to the size of the non-empty set. The sentiment score is considered positive in the case when all the frame entries of the set are equally positive in terms of A0 → A1 polarity values. Otherwise, the sentiment is considered negative . The annotated attitude is then utilized in news content filtering. Sentences that has no subject and object entries of the related attitude are discarded. Figure 2 provides an example of a news text, in which attitude ⟨ Georдia , USA ⟩ assumes to be annotated by FRAME-BASED factor as positive: all the frames mentioned between attitude ends (to continue, to support) conveys the same positive sentiment value of A0 → A1 polarity.
|
| 120 |
+
|
| 121 |
+
Figure 3: General, context-based 3-scale (positive, negative, neutral) classification model, with details on «Attention-Based Context Encoder» block in Section 5 and 6.
|
| 122 |
+
|
| 123 |
+
<!-- image -->
|
| 124 |
+
|
| 125 |
+
## 4 MODEL
|
| 126 |
+
|
| 127 |
+
In this paper, the problem of sentiment attitude extraction is treated as a classification task of two types: two-scale and three-scale. Given a pair of named entities, we predict a sentiment label of a pair, which could be as follows:
|
| 128 |
+
|
| 129 |
+
- sentiment, i.e. positive or negative (two-scale classification format);
|
| 130 |
+
- sentiment or neutral .
|
| 131 |
+
|
| 132 |
+
As the RuSentRel corpus provides opinions with positive or negative sentiment labels only (Section 3), we automatically added neutral sentiments for all pairs not mentioned in the annotation and co-occurred in the same sentences of the collection texts.
|
| 133 |
+
|
| 134 |
+
We consider a context as a text fragment that is limited by a single sentence and includes a pair of named entities. The general architecture is presented in Figure 3, where the sentiment could be extracted from the context. To present a context, we treat the original text as a sequence of terms [ t 1 , . . . , t n ] limited by n , with the distance between attitude participants limited by η terms. Each term belongs to one of the following groups: ENTITIES, FRAMES, TOKENS, and WORDS (if none of the prior has not been matched).
|
| 135 |
+
|
| 136 |
+
We use masked representation for attitude participants (E E E E E E E E E obj , E E E E E E E E E subj ) and mentioned named entities (E E E E E E E E E) to prevent models from capturing related information. To represent FRAMES, we combine a frame entry with the corresponding A0 → A1 sentiment polarity value (and neutral if the latter is absent). We also invert sentiment polarity when an entry has "не" (not) preposition. The TOKENS
|
| 137 |
+
|
| 138 |
+
## CONTEXT
|
| 139 |
+
|
| 140 |
+
Говорить о разделении кавказского региона кавказского региона кавказского региона кавказского региона кавказского региона кавказского региона кавказского региона кавказского региона кавказского региона из-за конфронтации России Ро��сии России России России России России России России obj и Турции Турции Турции Турции Турции Турции Турции Турции Турции subj пока не приходится, хотя опасность есть.
|
| 141 |
+
|
| 142 |
+
Talking about the separation of the Caucasus region Caucasus region Caucasus region Caucasus region Caucasus region Caucasus region Caucasus region Caucasus region Caucasus region due to the confrontation between Russia Russia Russia Russia Russia Russia Russia Russia Russia obj and Turkey Turkey Turkey Turkey Turkey Turkey Turkey Turkey Turkey subj is not necessary, although there is a danger.
|
| 143 |
+
|
| 144 |
+
↓
|
| 145 |
+
|
| 146 |
+
TERMS
|
| 147 |
+
|
| 148 |
+
Talking about the separation of the E E E E E E E E E due to the confrontation neд between E E E E E E E E E obj and E E E E E E E E E subj is not-necessary neд <COMMA> although there is a danger <DOT>
|
| 149 |
+
|
| 150 |
+
Figure 4: An example of a context processing into a sequence of terms; attitude participants ⟨ Russia , Turkey ⟩ and other mentioned entities become masked; frames are italic and optionally suffixed with the sentiment value of A0 → A1 polarity.
|
| 151 |
+
|
| 152 |
+
group includes: punctuation marks, numbers, url-links. Each term of WORDS is considered in a lemmatized 3 form.
|
| 153 |
+
|
| 154 |
+
Figure 4 provides an example of a context processing into a sequence of input terms. All entries are encoded with the negative polarity A0 → A1 : "конфронтация" (confrontation) has a negative polarity, and "не приходится" (not necessary) has a positive polarity of entry "necessary" which is inverted due to the "not" preposition.
|
| 155 |
+
|
| 156 |
+
To represent the context in a model, each term is embedded with a vector of fixed dimension. The sequence of embedded vectors X = [ x 1 , . . . , x n ] is denoted as input embedding ( x i ∈ R m , i ∈ 1 .. n ). Sections 5 and 6 provide an encoder implementation in details. In particular, each encoder relies on input embedding and generates output embedded context vector s .
|
| 157 |
+
|
| 158 |
+
In order to determine a sentiment class by the embedded context s , we apply: (1) the hyperbolic tangent activation function towards s and (2) transformation through the fully connected layer :
|
| 159 |
+
|
| 160 |
+
<!-- formula-not-decoded -->
|
| 161 |
+
|
| 162 |
+
In Formula 1, W r ∈ R | s |× c and b r ∈ R c correspond to the hidden states; | s | correspond to the size of vector s , and c ∈ { 2 , 3 } is a number of classes. Finally, the result o = σ ( r , c ) is an output vector of probabilities, which is computed by:
|
| 163 |
+
|
| 164 |
+
<!-- formula-not-decoded -->
|
| 165 |
+
|
| 166 |
+
## 5 FEATURE ATTENTIVE CONTEXT ENCODERS
|
| 167 |
+
|
| 168 |
+
In this section, we consider features as a significant for attitude identification context terms, towards which we would like to quantify the relevance of each term in the context. For a particular context, we select embedded values of the attitude participants (E E E E E E E E E , E E E E E E E E E ).
|
| 169 |
+
|
| 170 |
+
obj subj
|
| 171 |
+
|
| 172 |
+
Figure 5 illustrates a feature-based encoder [7]. In formulas 3-5, we describe the quantification process of a context embedding X
|
| 173 |
+
|
| 174 |
+
[3 https://tech.yandex.ru/mystem/](https://tech.yandex.ru/mystem/)
|
| 175 |
+
|
| 176 |
+
Figure 5: Feature-attentive context encoder architecture, based on ATTCNN model [7].
|
| 177 |
+
|
| 178 |
+
<!-- image -->
|
| 179 |
+
|
| 180 |
+
with respect to a particular feature f ∈ F . Given an i 'th embedded term x i , we concatenate its representation with f :
|
| 181 |
+
|
| 182 |
+
<!-- formula-not-decoded -->
|
| 183 |
+
|
| 184 |
+
The quantification of the relevance of x i with respect to f is denoted as u i ∈ R and calculated as follows:
|
| 185 |
+
|
| 186 |
+
<!-- formula-not-decoded -->
|
| 187 |
+
|
| 188 |
+
In Formula 4, W we ∈ R 2 · m × h MLP and W a ∈ R h MLP correspond to the weight and attention matrices respectively, and h MLP corresponds to the size of the hidden representation in the weight matrix. To deal with normalized weights within a context, we transform quantified values u i into probabilities α i by Formula 2 as follows: α = σ ( u , n ). We utilize Formula 5 to obtain attention-based context embedding ˆ s of a context with respect to feature f :
|
| 189 |
+
|
| 190 |
+
<!-- formula-not-decoded -->
|
| 191 |
+
|
| 192 |
+
Applying Formula 5 towards each feature f j ∈ F , j ∈ 1 .. k results in vector { ˆ s j } k j = 1 . We use average-pooling to transform the latter sequence into single averaged vector s ∈ R m .
|
| 193 |
+
|
| 194 |
+
f We also utilize a «CNN encoder» block (Figure 5) in order to compose the context representation s cnn . The resulting context embedding vector s is a concatenation of s f and s cnn :
|
| 195 |
+
|
| 196 |
+
<!-- formula-not-decoded -->
|
| 197 |
+
|
| 198 |
+
Structurally, a convolutional neural network based encoder is a sequence of the following transformations: convolutions and pooling. Figure 6 provides a detailed comparison between classic neural network (CNN, Figure 6a), and piecewise convolutional neural network (PCNN, Figure 6b).
|
| 199 |
+
|
| 200 |
+
Starting with the convolution operation, which remains equal across all the encoders of Figure 6, let x a : b is as consequent vectors concatenation from a 'th till b 'th positions. An application of ω ∈ R d , ( d = l · m ) towards the concatenation x a : b is a sequence convolution by filter ω , where l is a filter window size, and m corresponds to embedding vector size. For convolving calculation c j
|
| 201 |
+
|
| 202 |
+
Figure 6: Comparison of CNN-based context encoders; ω corresponds to convolutional filter window, size of 3.
|
| 203 |
+
|
| 204 |
+
<!-- image -->
|
| 205 |
+
|
| 206 |
+
( j ∈ 1 .. n ), we apply scalar multiplication as follows:
|
| 207 |
+
|
| 208 |
+
<!-- formula-not-decoded -->
|
| 209 |
+
|
| 210 |
+
To get multiple feature combinations, a set of different filters W = { ω 1 , . . . , ω t } has been applied towards X . This leads to a modified version of Formula 7 by introduced layer index i :
|
| 211 |
+
|
| 212 |
+
<!-- formula-not-decoded -->
|
| 213 |
+
|
| 214 |
+
Denoting c i = { c i , 1 , . . . , c i , n } in Formula 8 we reduce the latter by index j ∈ 1 .. n and compose a matrix C = { c 1 , c 2 , . . . , c t } which represents convolution matrix with shape C ∈ R n × t .
|
| 215 |
+
|
| 216 |
+
Max-pooling is an operation that reduces values by keeping maximum. In original CNN architecture (Figure 6a), max pooling applies separately per each convolution layers c i , which results in p ∈ R t . It reduces convolved information quite rapidly which is not appropriate for attitude classification task. To keep context features that are inside and outside of the attitude entities, authors [20] perform piecewise max-pooling (Figure 6b). Given attitude entities as borders, we divide each c i into inner, left and right segments { c i , 1 , c i , 2 , c i , 3 } . Then max-pooling applies per each segment separately:
|
| 217 |
+
|
| 218 |
+
<!-- formula-not-decoded -->
|
| 219 |
+
|
| 220 |
+
Thus, for each c i we have a set p i = { p i , 1 , p i , 2 , p i , 3 } . Concatenation of these sets for each layer i results in p ∈ R 3 t and that is a result of piecewise max-pooling operation.
|
| 221 |
+
|
| 222 |
+
## 6 SELF ATTENTIVE CONTEXT ENCODERS
|
| 223 |
+
|
| 224 |
+
In section 5 the application of attention in context embedding fully relies on the sequence of predefined features. The quantification of context terms is performed towards each feature. In turn, the self-attentive approach assumes to quantify a context with respect to an abstract parameter. Unlike quantification methods in featureattentive embedding models, here the latter is replaced with a hidden state ( w ) which modified during the training process.
|
| 225 |
+
|
| 226 |
+
To learn the hidden term semantics for each input, we utilize the LSTM [6] recurrent neural network architecture, which addresses learning long-term dependencies by avoiding gradient vanishing and expansion problems. The calculation h t of t 'th embedded term x t is based on prior state h t -1 , where the latter acts as a parameter of auxiliary functions [6]. Figure 7 illustrates the attention-based sentence encoder architecture, builded on top of the BiLSTM - is a bi-directional LSTM to obtain a pair of sequences - → h and ← -h ( - → h i , ← -h i ∈ R h ). The resulting context representation H = [ h 1 , . . . , h n ] is composed as the concatenation of bidirectional sequences elementwise: h i = - → h i + ← -h i , i ∈ 1 .. n . The quantification of hidden term representation h i ∈ R 2 · h with respect to w ∈ R 2 · h is described in formulas 10-11.
|
| 227 |
+
|
| 228 |
+
Figure 7: Self-attentive context encoder architecture, with self-attention module of ATT-BLSTM model [21] over bidirectional LSTM encoder.
|
| 229 |
+
|
| 230 |
+
<!-- image -->
|
| 231 |
+
|
| 232 |
+
<!-- formula-not-decoded -->
|
| 233 |
+
|
| 234 |
+
<!-- formula-not-decoded -->
|
| 235 |
+
|
| 236 |
+
i
|
| 237 |
+
|
| 238 |
+
In order to deal with normalized weights, we transoform quantified values u i into α i as follows: α = σ ( u , n ) (Formula 2). The resulting context embedding vector s is an activated weighted sum of each parameter of context hidden states:
|
| 239 |
+
|
| 240 |
+
<!-- formula-not-decoded -->
|
| 241 |
+
|
| 242 |
+
## 7 MODEL DETAILS
|
| 243 |
+
|
| 244 |
+
We provide embedding details of context term groups described in Section 4. For WORDS and FRAMES, we look up for vectors in precomputed and publicly available model 4 M word based on news articles with window size of 20 , and vector size of 1000 . Each term that is not presented in model we treat as a sequence of parts ( n -grams) and look up for related vectors in M word to complete an averaged vector. For a particular part, we start with trigrams ( n = 3 ) and decrease n until the related n -gram is found. For masked entities (E E E E E E E E E, E E E E E E E E E obj , E E E E E E E E E subj ) and TOKENS, each element embedded with a vector of size 1000; every vector is randomly initialized from a Gaussian distribution [4].
|
| 245 |
+
|
| 246 |
+
[4 http://rusvectores.org/static/models/rusvectores2/news\_mystem\_skipgram\_1000\_20\_ 2015.bin.gz](http://rusvectores.org/static/models/rusvectores2/news_mystem_skipgram_1000_20_2015.bin.gz)
|
| 247 |
+
|
| 248 |
+
Table 2: Experiment (TWO-SCALE and THREE-SCALE) context classification results by F 1 measure over RuSentRel collection; all the models are separated into the following groups (from top to bottom): BiLSTM, PCNN, CNN; models that employ RuAttitudes in the training process (DS mode) are labeled with « · »; columns related to result evaluation in each experiment (from left to right): (1) average value in CV-3 experiment ( F 1 avд ) with results on each split ( F 1 i cv , i ∈ 1 .. 3 ), (2) results on TRAIN/TEST separation ( F 1 TEST).
|
| 249 |
+
|
| 250 |
+
| TWO-SCALE THREE-SCALE Model DS F 1 avд F 1 1 cv F 1 2 cv F 1 3 cv F 1 TEST F 1 avд F 1 1 cv F 1 2 cv F 1 3 cv F 1 TEST ATT-BLSTM • 0.667 0.71 0.62 0.67 0.68 0.332 0.36 0.33 0.31 0.38 BiLSTM • 0.653 0.70 0.60 0.66 0.70 0.312 0.34 0.31 0.29 0.39 ATT-BLSTM 0.640 0.69 0.60 0.64 0.68 0.314 0.35 0.27 0.32 0.32 BiLSTM 0.632 0.66 0.63 0.61 0.67 0.286 0.32 0.26 0.28 0.34 ATTPCNN e • 0.644 0.67 0.61 0.65 0.66 0.312 0.33 0.30 0.31 0.41 PCNN • 0.599 0.70 0.53 0.57 0.63 0.315 0.33 0.30 0.31 0.40 ATTPCNN e 0.617 0.64 0.56 0.65 0.67 0.297 0.32 0.29 0.28 0.35 PCNN 0.608 0.62 0.58 0.63 0.66 0.285 0.29 0.27 0.30 0.32 ATTCNN e • 0.631 0.64 0.64 0.62 0.66 0.316 0.35 0.29 0.30 0.41 CNN • 0.625 0.62 0.63 0.63 0.68 0.305 0.31 0.30 0.31 0.40 ATTCNN e 0.636 0.66 0.64 0.61 0.62 0.270 0.33 0.23 0.25 0.30 CNN 0.553 0.60 0.56 0.51 0.59 0.274 0.30 0.26 0.26 0.31 |
|
| 251 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 252 |
+
|
| 253 |
+
Each context term has been additionally expanded with the following parameters:
|
| 254 |
+
|
| 255 |
+
- Distance embedding [14] ( v D -obj , v D -subj ) - is vectorized distance in terms from attitude participants of entry pair (E E E E E E E E E obj and E E E E E E E E E subj respectively) to a given term;
|
| 256 |
+
- Closest to synonym distance embedding ( v SD -obj , v SD -subj ) is a vectorized absolute distance in terms from a given term towards the nearest entity, synonymous to E E E E E E E E E obj and E E E E E E E E E subj ;
|
| 257 |
+
- Part-of-speech embedding ( v POS) is a vectorized tag for WORDS (for terms of other groups considering «unknown» tag);
|
| 258 |
+
- A0 → A1 polarity embedding ( v A 0 → A 1 ) is a vectorized «positive» or «negative» value for frame entries whose description in RuSentiFrames provides the corresponding polarity (otherwise considering «neutral» value); polarity is inverted when an entry has "не" (not) preposition.
|
| 259 |
+
|
| 260 |
+
## 7.1 Training
|
| 261 |
+
|
| 262 |
+
This process assumes hidden parameter optimization of a given model. We utilize an algorithm described in [14]. The input is organized in minibatches, where each minibatch yields of l bags . Each bag has a set of t pairs X j , y j t j = 1 , where each pair is described by an input embedding X j with the related label y j ∈ R c . The training process is iterative, and each iteration includes the following steps in order to calculate vector cost and perform hidden states update.
|
| 263 |
+
|
| 264 |
+
The first step assumes a minibatch composing, which is consist of l bags of size t . Then we perform a forward propagation through the network which results in a vector (size of q = l · t ) of outputs o k ∈ R c . In the third step we calculate cross entropy loss for an output vector as follows:
|
| 265 |
+
|
| 266 |
+
<!-- formula-not-decoded -->
|
| 267 |
+
|
| 268 |
+
In the final step we compose a cost vector, where i 'th component cost i ( i = 1 .. l ) corresponds to the maximal cross entropy loss within a related i 'th bag:
|
| 269 |
+
|
| 270 |
+
<!-- formula-not-decoded -->
|
| 271 |
+
|
| 272 |
+
## 7.2 Parameters settings
|
| 273 |
+
|
| 274 |
+
The minibatch size ( l ) is set to 2 , where contexts count per bag t is set to 3 . All the contexts were limited by n = 50 terms, with the distance between attitude participants limited to η = 10 terms. For embedding parameters (Section 7) we use vectors with size of 5 . For CNN and PCNN context encoders, the size of convolutional window ( ω ) and filters count ( c ) were set to 3 and 300 respectively. As for parameters related to sizes of hidden states in Sections 5 and 6: h MLP = 10 , h = 128 . We utilize the AdaDelta optimizer with parameters ρ = 0 . 95 and ϵ = 10 -6 [19]. To prevent models from overfitting, we apply dropout towards the output with keep probability set to 0 . 8 . For hidden state values initialization we utilize Xavier weight intializer [4].
|
| 275 |
+
|
| 276 |
+
## 8 EXPERIMENTS
|
| 277 |
+
|
| 278 |
+
According to Section 4, we treat sentiment attitude extraction as a classification task of different scales of output classes. We train and evaluate all the models in the following experiments:
|
| 279 |
+
|
| 280 |
+
- (1) TWO-SCALE [15], in which all the models have to predict a sentiment label of an attitude in context. It is important to note that for each document we consider only those attitudes that might be fitted in a context;
|
| 281 |
+
- (2) THREE-SCALE [14], in which each model might classify a given context with an attitude in it as sentiment-oriented (positive/negative) or neutral .
|
| 282 |
+
|
| 283 |
+
It is worth to note that the evaluation process in case of TWOSCALE experiment assumes to treat only those pairs in comparison, which could be found within a context of the related document.
|
| 284 |
+
|
| 285 |
+
## 8.1 Datasets and Evaluation formats
|
| 286 |
+
|
| 287 |
+
The evaluation in experiments has been performed over the RuSentRel corpus, using the following formats:
|
| 288 |
+
|
| 289 |
+
- (1) CV-BASED format, in which it is supposed to utilize 3-fold cross-validation (CV); all folds are equal in terms of sentence count;
|
| 290 |
+
- (2) FIXED format, in which the predefined separation of documents onto TRAIN/TEST sets is considered 5 .
|
| 291 |
+
|
| 292 |
+
For evaluating models in this task, we adopt macro-averaged F1score ( F 1 ) over documents. F1-score is considered averaging of the positive and negative classes, which are most important in attitude analysis.
|
| 293 |
+
|
| 294 |
+
## 8.2 Model Comparisons and Training
|
| 295 |
+
|
| 296 |
+
In terms of architecture aspects, all the models differ only in sentence encoder implementation of a single context classification model (Figure 3). The list of the models selected for the experiments is as follows:
|
| 297 |
+
|
| 298 |
+
- CNN model with a classic convolutional neural network architecture (Figure 6a);
|
| 299 |
+
- PCNN model, in which the encoder treats each convolution layer in parts, relatively to the attitude participants' positions in the context (Figure 6b);
|
| 300 |
+
- ATTCNN e , ATTPCNN e are models with feature attentive encoders (Section 5); «e» corresponds to the set of attitude participants (E E E E E E E E E obj , E E E E E E E E E subj ).
|
| 301 |
+
- BiLSTM is a bi-directional LSTM [6];
|
| 302 |
+
- ATT-BLSTM model (Section 6);
|
| 303 |
+
|
| 304 |
+
For a particular model, the training (and related evaluation) process has been performed in the following modes:
|
| 305 |
+
|
| 306 |
+
- (1) DS, is an application of distant supervision, which is considered as a combination of RuSentRel and RuAttitudes collections;
|
| 307 |
+
- (2) SL, is supervised learning, using RuSentRel.
|
| 308 |
+
|
| 309 |
+
It is worth to clarify the details of the training set creation in DS mode depending on the evaluation formats (Section 8.1):
|
| 310 |
+
|
| 311 |
+
- For CV-BASED, in each split, the RuAttitudes collection is combined with each training block of the RuSentRel collection;
|
| 312 |
+
- For FIXED, the training set represents a combination of RuAttitudes with the TRAIN part.
|
| 313 |
+
|
| 314 |
+
We measure F 1 on the training part every 10 epoch. The number of epochs was limited by 150. The training process terminates when F 1 on the training part becomes greater than 0 . 85 .
|
| 315 |
+
|
| 316 |
+
## 8.3 Result Analysis
|
| 317 |
+
|
| 318 |
+
Table 2 provides the results in the experiments for models organized (and separated) into the following groups: CNN, PCNN, BiLSTM. To access the effectiveness of both an application of distant supervision in the training process (DS mode, marked with « · » sign in Table 2) and attention-based encoders (prefixed with «ATT»), we provide efficiency assessment in the following directions:
|
| 319 |
+
|
| 320 |
+
(1) Application of DS mode for baselines;
|
| 321 |
+
|
| 322 |
+
[5 https://miem.hse.ru/clschool/results](https://miem.hse.ru/clschool/results)
|
| 323 |
+
|
| 324 |
+
Table 3: Calculated E DS and E DSA ratios in each experiment for CV-BASED ( F 1 avд ) and FIXED ( F 1 TEST) evaluation formats; values below zero displayed as « · »
|
| 325 |
+
|
| 326 |
+
| TWO-SCALE THREE-SCALE Ratio Parameter CNN PCNN BiLSTM CNN PCNN BiLSTM E DS F 1 avд 0.13 · 0.01 0.11 0.11 0.09 F 1 TEST 0.15 · 0.04 0.29 0.25 0.15 E DSA F 1 avд 0.01 0.08 0.02 0.04 · 0.06 F 1 TEST · 0.05 · 0.03 0.03 · |
|
| 327 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 328 |
+
|
| 329 |
+
(2) Application of attention-based sentence encoders in DS mode.
|
| 330 |
+
|
| 331 |
+
To accomplish the comparison in a particular experiment, for each model we calculate the corresponding ratios by F 1 avд and F 1 TEST:
|
| 332 |
+
|
| 333 |
+
- E DS - is the effectiveness of baseline models trained in DS mode over a related baseline that trained in SL mode;
|
| 334 |
+
- E DSA - is the effectiveness of models trained in DS mode with attention-based sentence encoder (prefixed with ATT) over related baseline version.
|
| 335 |
+
|
| 336 |
+
Table 3 provides calculated ratios for the TWO-SCALE and THREESCALE experiments. The ratio calculation ( r ) for a result A over a result B performed as follows: r = A / B -1 .
|
| 337 |
+
|
| 338 |
+
Analyzing results in the TWO-SCALE experiment by E DS in Table 3, model ATTCNN e shows a significant increase in 13% and 15% in case of CV-BASED and FIXED evaluation formats respectively. An application of attention-based encoders does not illustrate an increase in result model quality, only 1% for ATTCNN e and 5-8% for ATTPCNN e . The highest result is obtained by the ATT-BLSTM model with a 4% increase by E .
|
| 339 |
+
|
| 340 |
+
DS
|
| 341 |
+
|
| 342 |
+
As for the THREE-SCALE experiment, it is also possible to investigate a significant increase by E DS with 10% in the CV-BASED evaluation mode and 15-29% on the TEST part (FIXED evaluation format). Utilizing attentive encoders in the models that employ RuAttitudes in training provides 3% results improvement according to E DSA ratio. The highest increase by E DSA is achieved by ATT-BLSTM model with 6% when the model is evaluated in the CV-BASED format.
|
| 343 |
+
|
| 344 |
+
## 9 ANALYSIS OF ATTENTION WEIGHTS
|
| 345 |
+
|
| 346 |
+
According to Section 3.3, one of the assumptions behind the distant supervision application for RuAttitudes collection developing is that the attitude might be conveyed by a frame of a certain sentiment polarity. For models of the THREE-SCALE experiment with attentionbased encoders (ATTCNN e , ATTPCNN e , ATT-BLSTM), in this section, we analyze how contexts with sentiment and neutral attitudes affect on weight distribution in dependence on the term type.
|
| 347 |
+
|
| 348 |
+
The terms quantification process remains a significant part of each attention-based encoder. Being assigned and normalized, weights of every term in a context might be treated as probability weight distribution across all the terms appeared in a context.
|
| 349 |
+
|
| 350 |
+
The source of documents for contexts in this analysis is the TEST part of the RuSentRel collection (Section 8.1). We analyse the weight
|
| 351 |
+
|
| 352 |
+
<!-- image -->
|
| 353 |
+
|
| 354 |
+
Figure 8: Kernel density estimations (KDE) of context-level weight distributions across neutral ( N ) and sentiment ( S ) context sets for models ATT-BLSTM and ATTCNN e trained in different modes: distant supervision application (DS), and supervised learning only (SL); the probability range (x-axis) scale depends on the group of terms: [ 0 , 0 . 4 ] (FRAMES, SENTIMENT), [ 0 , 0 . 5 ] (NOUNS), and [ 0 , 0 . 2 ] (PREP); vertical lines indicate expected values of corresponding distributions.
|
| 355 |
+
|
| 356 |
+
Table 4: Calculated statistics ( D ∗ ) from Kolmogorov-Smirnov test by following term groups: FRAMES (F), NOUNS (N), PREP (P), SENTIMENT (S), and VERBS (V); highest and second highest values per each category are bolded and underlined respectively.
|
| 357 |
+
|
| 358 |
+
| Model DS D F D N D P D S D V ATT-BLSTM • 0.29 0.23 0.26 0.14 0.17 ATT-BLSTM 0.13 0.22 0.08 0.11 0.07 ATTCNN e • 0.05 0.03 0.05 0.03 0.03 ATTCNN e 0.09 0.07 0.09 0.07 0.07 ATTPCNN e • 0.10 0.03 0.04 0.04 0.06 ATTPCNN e 0.09 0.17 0.15 0.08 0.06 |
|
| 359 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 360 |
+
|
| 361 |
+
Table 5: The difference in estimated values of ρ S and ρ N ( ∆ ∗ ) by following term groups: FRAMES (F), NOUNS (N), PREP (P), SENTIMENT (S), and VERBS (V); absolute max values by each term group are bolded; absolute values less or equal 0 . 1 displayed as « · »
|
| 362 |
+
|
| 363 |
+
| Model DS ∆ F ∆ N ∆ P ∆ S ∆ V ATT-BLSTM • 0.20 -0.09 -0.02 0.09 · ATT-BLSTM 0.07 0.12 0.03 0.05 0.03 ATTCNN e • · · · · · ATTCNN e · · · · · ATTPCNN e • 0.06 · · · · ATTPCNN e · -0.02 · · · |
|
| 364 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 365 |
+
|
| 366 |
+
## ATT-BLSTM (SL) (Original)
|
| 367 |
+
|
| 368 |
+
. . .
|
| 369 |
+
|
| 370 |
+
. . .
|
| 371 |
+
|
| 372 |
+
## ATT-BLSTM (SL)
|
| 373 |
+
|
| 374 |
+
. . .
|
| 375 |
+
|
| 376 |
+
. . .
|
| 377 |
+
|
| 378 |
+
## ATT-BLSTM (DS)
|
| 379 |
+
|
| 380 |
+
. . .
|
| 381 |
+
|
| 382 |
+
. . .
|
| 383 |
+
|
| 384 |
+
Figure 9: Weight distribution visualization on sentiment contexts for model ATT-BLSTM, trained in different modes: supervised learning (SL), and with an application of distant supervision (DS); for visualization purposes, weight of each term is normalized by the maximum in context; frame entries (marked italic and bolded) appeared between masked attitude participants become greater weighted when training process employs RuAttitudes (DS mode).
|
| 385 |
+
|
| 386 |
+
distribution of the FRAMES group, declared in Section 4, across all input contexts. We additionally introduce a list of extra groups utilized in the analysis by separating the subset of WORDS into prepositions (PREP), terms appeared in RuSentiLex lexicon (SENTIMENT, Section 3), nouns (NOUNS), and verbs (VERBS). The contents of NOUNS and VERBS is considered only for those entries that are not present in the RuSentiLex lexicon.
|
| 387 |
+
|
| 388 |
+
The context-level weight of a particular term group is a weighted sum of terms which both appear in the context and belong to the corresponding term group. For discrepancy analysis between sentiment and neutrally labeled contexts, we utilize distributions of context-levels weights across:
|
| 389 |
+
|
| 390 |
+
- (1) Sentiment contexts (S) - contexts, labeled with positive or negative labels;
|
| 391 |
+
- (2) Neutral contexts (N) - contexts, labeled as neutral .
|
| 392 |
+
|
| 393 |
+
Further, such weight distributions over sentiment and neutral contexts denoted as ρ ∗ S and ρ ∗ N respectively, where asterisk corresponds to the certain term group.
|
| 394 |
+
|
| 395 |
+
To reveal the difference between distributions, the statistics from Kolmogorov-Smirnov test was used [11]. In our analysis, the calculation of such statistics is considered to be performed between a pair of samples (tabulated distributions), where each sample is a sequence of term group probabilities within each context. It is worth to note that such tabulated distributions meet the criteria of the independence of values (weights) related to continious set. Considering the latter, we are able to switch from tabulated to the cumulative distributions as follows:
|
| 396 |
+
|
| 397 |
+
<!-- formula-not-decoded -->
|
| 398 |
+
|
| 399 |
+
where X is related to the contexts set of a certain polarity (sentiment or neutral), i.e. X ∈ { S , N } , x ∈ [ 0 , 1 ] . The Kolmogorov-Smirnov statistics (KS-statistics) represent the maximum of the absolute deviation between cumulative distributions F ∗ S and F ∗ N :
|
| 400 |
+
|
| 401 |
+
<!-- formula-not-decoded -->
|
| 402 |
+
|
| 403 |
+
Table 4 provides the calculated KS-statistics (Formula 16) separately for each group of terms. Larger values by D ∗ address on a greater difference in weights distribution between ρ ∗ S and ρ ∗ N .
|
| 404 |
+
|
| 405 |
+
Another statistics that we utilize in analysis is a difference in estimated values of ρ ∗ S and ρ ∗ N :
|
| 406 |
+
|
| 407 |
+
<!-- formula-not-decoded -->
|
| 408 |
+
|
| 409 |
+
In addition to KS-statistics, the calculation of ∆ ∗ provides the sign of the difference. Summarizing results of both statistics, we may conclude that among all the models presented in our analysis, only ATT-BLSTM illustrates a significant difference between ρ N and ρ S across all the term groups. The comparative kernel density estimations of context weight distributions for ATT-BLSTM and ATTCNN e is presented in Figure 8. In case of ATT-BLSTM, application of RuAttitudes in training (DS mode) results in weights distribution biasing from NOUNS and PREP onto terms of the FRAMES and SENTIMENT groups in sentiment contexts. The similar case is observed for ATTCNN e trained in DS mode: terms of FRAMES and SENTIMENT groups become more valuable equally in sentiment and neutral context sets. The assumption here is a structure of contexts in RuAttitudes (Section 3.3): all the contexts enriched with frames, appeared between attitude participants. Those cases where frames convey the presence of an attitude in context are presented in Figure 9. According to the provided examples for ATT-BLSTM model, it is possible to investigate greater weighted frame entries when the training process of related model employs RuAttitudes.
|
| 410 |
+
|
| 411 |
+
Overall, the model ATT-BLSTM stands out baselines and models with feature-based attention encoders (ATTCNN e , ATTPCNN e ) both due to results (Section 8) and the greatest discrepancy between ρ S and ρ N across all the term groups presented in the analysis (Figure 8). We assume that the latter is achieved due to the following factors: (1) application of bi-directional LSTM encoder; (2) utilization of a single trainable vector ( w ) in the quantification process (Section 6) while the models of feature-based approach (Section 5, Formula 4) depend on fully-connected layers.
|
| 412 |
+
|
| 413 |
+
## CONCLUSION
|
| 414 |
+
|
| 415 |
+
In this paper, we study the attention-based models, aimed to extract sentiment attitudes from analytical articles. We consider the problem of extraction as two-class and three-class classification tasks for whole documents. Depending on the task, the described models should classify a context with an attitude mentioned in it onto the following classes: positive or negative (two-class); positive, negative, or neutral (three-class).
|
| 416 |
+
|
| 417 |
+
We investigated two types of attention embedding approaches: (1) feature-based, (2) self-based. To fine-tune the attention mechanism, we utilized distant supervision technique by employing RuAttitudes collection in the training process.
|
| 418 |
+
|
| 419 |
+
We conducted experiments on Russian analytical texts of the RuSentRel corpus and provided analysis of the results. The affection of distant-supervision technique onto attention-based encoders was shown by the variety in weight distribution of certain term groups between sentiment and non-sentiment contexts. Utilizing the distantsupervision approach in training three-class classification models results in 10% improvement by F 1 for architectures that do not employ attention module in context encoder. Replacing the latter with attention-based encoders provides the classification improvement by 3% F 1 .
|
| 420 |
+
|
| 421 |
+
In further work we plan to study application of language models for the presented tasks, as it continues the idea of attentive encoders application.
|
| 422 |
+
|
| 423 |
+
## ACKNOWLEDGMENTS
|
| 424 |
+
|
| 425 |
+
The reported study was funded by RFBR according to the research project № 20-07-01059.
|
| 426 |
+
|
| 427 |
+
## REFERENCES
|
| 428 |
+
|
| 429 |
+
- [1] KArkhipenko, I Kozlov, J Trofimovich, K Skorniakov, A Gomzin, and D Turdakov. 2016. Comparison of neural network architectures for sentiment analysis of russian tweets. In Proceedings of international conference, computational linguistics and intellectual technologies .
|
| 430 |
+
- [2] Kyunghyun Cho, Bart van Merriënboer, Caglar Gulcehre, Dzmitry Bahdanau, Fethi Bougares, Holger Schwenk, and Yoshua Bengio. 2014. Learning Phrase Representations using RNN Encoder-Decoder for Statistical Machine Translation. In Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing (EMNLP) . 1724-1734.
|
| 431 |
+
- [3] David Dowty. 1991. Thematic proto-roles and argument selection. language 67, 3 (1991), 547-619.
|
| 432 |
+
- [4] Xavier Glorot and Yoshua Bengio. 2010. Understanding the difficulty of training deep feedforward neural networks. In Proceedings of the thirteenth international conference on artificial intelligence and statistics . 249-256.
|
| 433 |
+
- [5] Iris Hendrickx, Su Nam Kim, Zornitsa Kozareva, Preslav Nakov, Diarmuid Ó Séaghdha, Sebastian Padó, Marco Pennacchiotti, Lorenza Romano, and Stan Szpakowicz. 2009. Semeval-2010 task 8: Multi-way classification of semantic relations between pairs of nominals. In Proceedings of the Workshop on Semantic Evaluations: Recent Achievements and Future Directions . 94-99.
|
| 434 |
+
- [6] Sepp Hochreiter and Jürgen Schmidhuber. 1997. Long short-term memory. Neural computation 9, 8 (1997), 1735-1780.
|
| 435 |
+
- [7] Xuanjing Huang et al. 2016. Attention-based convolutional neural network for semantic relation extraction. In Proceedings of COLING 2016, the 26th International Conference on Computational Linguistics: Technical Papers . 2526-2536.
|
| 436 |
+
- [8] Yuri Kuratov and Mikhail Arkhipov. 2019. Adaptation of deep bidirectional multilingual transformers for russian language. arXiv preprint arXiv:1905.07213 (2019).
|
| 437 |
+
- [9] Natalia Loukachevitch and Anatolii Levchik. 2016. Creating a general russian sentiment lexicon. In Proceedings of the Tenth International Conference on Language Resources and Evaluation (LREC'16) . 1171-1176.
|
| 438 |
+
- [10] Natalia Loukachevitch and Nicolay Rusnachenko. 2018. Extracting sentiment attitudes from analytical texts. Proceedings of International Conference on Computational Linguistics and Intellectual Technologies Dialogue-2018 (arXiv:1808.08932) (2018), 459-468.
|
| 439 |
+
- [11] Frank J Massey Jr. 1951. The Kolmogorov-Smirnov test for goodness of fit. Journal of the American statistical Association 46, 253 (1951), 68-78.
|
| 440 |
+
- [12] Mike Mintz, Steven Bills, Rion Snow, and Dan Jurafsky. 2009. Distant supervision for relation extraction without labeled data. In Proceedings of the Joint Conference of the 47th Annual Meeting of the ACL and the 4th International Joint Conference on Natural Language Processing of the AFNLP: Volume 2-Volume 2 . Association for Computational Linguistics, 1003-1011.
|
| 441 |
+
- [13] Anna Rogers, Alexey Romanov, Anna Rumshisky, Svitlana Volkova, Mikhail Gronas, and Alex Gribov. 2018. Rusentiment: An enriched sentiment analysis dataset for social media in russian. In Proceedings of the 27th International Conference on Computational Linguistics . 755-763.
|
| 442 |
+
- [14] Nicolay Rusnachenko and Natalia Loukachevitch. 2018. Neural Network Approach for Extracting Aggregated Opinions from Analytical Articles. In International Conference on Data Analytics and Management in Data Intensive Domains . Springer, 167-179.
|
| 443 |
+
- [15] Nicolay Rusnachenko, Natalia Loukachevitch, and Elena Tutubalina. 2019. Distant Supervision for Sentiment Attitude Extraction. Proceedings of the International Conference on Recent Advances in Natural Language Processing (RANLP 2019) (2019).
|
| 444 |
+
- [16] Yatian Shen and Xuanjing Huang. 2016. Attention-Based Convolutional Neural Network for Semantic Relation Extraction. In Proceedings of COLING 2016, the 26th International Conference on Computational Linguistics: Technical Papers . 2526-2536.
|
| 445 |
+
- [17] Elena Tutubalina, Ilseyar Alimova, Zulfat Miftahutdinov, Andrey Sakhovskiy, Valentin Malykh, and Sergey Nikolenko. 2020. The Russian Drug Reaction Corpus and Neural Models for Drug Reactions and Effectiveness Detection in User Reviews. arXiv preprint arXiv:2004.03659 (2020).
|
| 446 |
+
- [18] Zichao Yang, Diyi Yang, Chris Dyer, Xiaodong He, Alex Smola, and Eduard Hovy. 2016. Hierarchical attention networks for document classification. In Proceedings of the 2016 conference of the North American chapter of the association for computational linguistics: human language technologies . 1480-1489.
|
| 447 |
+
- [19] Matthew D Zeiler. 2012. ADADELTA: an adaptive learning rate method. arXiv preprint:1212.5701 (2012).
|
| 448 |
+
- [20] Daojian Zeng, Kang Liu, Yubo Chen, and Jun Zhao. 2015. Distant supervision for relation extraction via piecewise convolutional neural networks. In Proceedings of the 2015 Conference on Empirical Methods in Natural Language Processing . 1753-1762.
|
| 449 |
+
- [21] Peng Zhou, Wei Shi, Jun Tian, Zhenyu Qi, Bingchen Li, Hongwei Hao, and Bo Xu. 2016. Attention-based bidirectional long short-term memory networks for relation classification. In Proceedings of the 54th annual meeting of the association for computational linguistics (volume 2: Short papers) . 207-212.
|
text-versions/attention-markdown/2006.15222_BERTology Meets Biology Interpreting Att.md
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2006.15222 Bertology Meets Biology Interpreting Att
|
| 2 |
+
|
| 3 |
+
## BERTOLOGY MEETS BIOLOGY: INTERPRETING ATTENTION IN PROTEIN LANGUAGE MODELS
|
| 4 |
+
|
| 5 |
+
Jesse Vig 1 Ali Madani 1 Lav R. Varshney 1,2 Caiming Xiong 1
|
| 6 |
+
|
| 7 |
+
Richard Socher 1 Nazneen Fatema Rajani 1 1 2
|
| 8 |
+
|
| 9 |
+
Salesforce Research, University of Illinois at Urbana-Champaign
|
| 10 |
+
|
| 11 |
+
{jvig,amadani,cxiong,rsocher,nazneen.rajani}@salesforce.com varshney@illinois.edu
|
| 12 |
+
|
| 13 |
+
## ABSTRACT
|
| 14 |
+
|
| 15 |
+
Transformer architectures have proven to learn useful representations for protein classification and generation tasks. However, these representations present challenges in interpretability. In this work, we demonstrate a set of methods for analyzing protein Transformer models through the lens of attention. We show that attention: (1) captures the folding structure of proteins, connecting amino acids that are far apart in the underlying sequence, but spatially close in the three-dimensional structure, (2) targets binding sites, a key functional component of proteins, and (3) focuses on progressively more complex biophysical properties with increasing layer depth. We find this behavior to be consistent across three Transformer architectures (BERT, ALBERT, XLNet) and two distinct protein datasets. We also present a three-dimensional visualization of the interaction between attention and protein structure. Code for visualization and analysis is available at https://github.com/salesforce/provis .
|
| 16 |
+
|
| 17 |
+
## 1 INTRODUCTION
|
| 18 |
+
|
| 19 |
+
The study of proteins, the fundamental macromolecules governing biology and life itself, has led to remarkable advances in understanding human health and the development of disease therapies. The decreasing cost of sequencing technology has enabled vast databases of naturally occurring proteins (El-Gebali et al., 2019a), which are rich in information for developing powerful machine learning models of protein sequences. For example, sequence models leveraging principles of co-evolution, whether modeling pairwise or higher-order interactions, have enabled prediction of structure or function (Rollins et al., 2019).
|
| 20 |
+
|
| 21 |
+
Proteins, as a sequence of amino acids, can be viewed precisely as a language and therefore modeled using neural architectures developed for natural language. In particular, the Transformer (Vaswani et al., 2017), which has revolutionized unsupervised learning for text, shows promise for similar impact on protein sequence modeling. However, the strong performance of the Transformer comes at the cost of interpretability, and this lack of transparency can hide underlying problems such as model bias and spurious correlations (Niven & Kao, 2019; Tan & Celis, 2019; Kurita et al., 2019). In response, much NLP research now focuses on interpreting the Transformer, e.g., the subspecialty of 'BERTology' (Rogers et al., 2020), which specifically studies the BERT model (Devlin et al., 2019).
|
| 22 |
+
|
| 23 |
+
In this work, we adapt and extend this line of interpretability research to protein sequences. We analyze Transformer protein models through the lens of attention, and present a set of interpretability methods that capture the unique functional and structural characteristics of proteins. We also compare the knowledge encoded in attention weights to that captured by hidden-state representations. Finally, we present a visualization of attention contextualized within three-dimensional protein structure.
|
| 24 |
+
|
| 25 |
+
Our analysis reveals that attention captures high-level structural properties of proteins, connecting amino acids that are spatially close in three-dimensional structure, but apart in the underlying sequence (Figure 1a). We also find that attention targets binding sites, a key functional component of proteins (Figure 1b). Further, we show how attention is consistent with a classic measure of similarity between amino acids-the substitution matrix. Finally, we demonstrate that attention captures progressively higher-level representations of structure and function with increasing layer depth.
|
| 26 |
+
|
| 27 |
+
(a) Attention in head 12-4, which targets amino acid pairs that are close in physical space (see inset subsequence 117D-157I) but lie apart in the sequence. Example is a de novo designed TIMbarrel (5BVL) with characteristic symmetry.
|
| 28 |
+
|
| 29 |
+
<!-- image -->
|
| 30 |
+
|
| 31 |
+
(b) Attention in head 7-1, which targets binding sites, a key functional component of proteins. Example is HIV-1 protease (7HVP). The primary location receiving attention is 27G, a binding site for protease inhibitor small-molecule drugs.
|
| 32 |
+
|
| 33 |
+
<!-- image -->
|
| 34 |
+
|
| 35 |
+
Figure 1: Examples of how specialized attention heads in a Transformer recover protein structure and function, based solely on language model pre-training. Orange lines depict attention between amino acids (line width proportional to attention weight; values below 0.1 hidden). Heads were selected based on correlation with ground-truth annotations of contact maps and binding sites. Visualizations based on the NGL Viewer (Rose et al., 2018; Rose & Hildebrand, 2015; Nguyen et al., 2017).
|
| 36 |
+
|
| 37 |
+
In contrast to NLP, which aims to automate a capability that humans already have-understanding natural language-protein modeling also seeks to shed light on biological processes that are not fully understood. Thus we also discuss how interpretability can aid scientific discovery.
|
| 38 |
+
|
| 39 |
+
## 2 BACKGROUND: PROTEINS
|
| 40 |
+
|
| 41 |
+
In this section we provide background on the biological concepts discussed in later sections.
|
| 42 |
+
|
| 43 |
+
Amino acids. Just as language is composed of words from a shared lexicon, every protein sequence is formed from a vocabulary of amino acids, of which 20 are commonly observed. Amino acids may be denoted by their full name (e.g., Proline ), a 3-letter abbreviation ( Pro ), or a single-letter code ( P ).
|
| 44 |
+
|
| 45 |
+
Substitution matrix. While word synonyms are encoded in a thesaurus, proteins that are similar in structure or function are captured in a substitution matrix , which scores pairs of amino acids on how readily they may be substituted for one another while maintaining protein viability. One common substitution matrix is BLOSUM (Henikoff & Henikoff, 1992), which is derived from co-occurrence statistics of amino acids in aligned protein sequences.
|
| 46 |
+
|
| 47 |
+
Protein structure. Though a protein may be abstracted as a sequence of amino acids, it represents a physical entity with a well-defined three-dimensional structure (Figure 1). Secondary structure describes the local segments of proteins; two commonly observed types are the alpha helix and beta sheet . Tertiary structure encompasses the large-scale formations that determine the overall shape and function of the protein. One way to characterize tertiary structure is by a contact map , which describes the pairs of amino acids that are in contact (within 8 angstroms of one another) in the folded protein structure but lie apart (by at least 6 positions) in the underlying sequence (Rao et al., 2019).
|
| 48 |
+
|
| 49 |
+
Binding sites. Proteins may also be characterized by their functional properties. Binding sites are protein regions that bind with other molecules (proteins, natural ligands, and small-molecule drugs) to carry out a specific function. For example, the HIV-1 protease is an enzyme responsible for a critical process in replication of HIV (Brik & Wong, 2003). It has a binding site, shown in Figure 1b, that is a target for drug development to ensure inhibition.
|
| 50 |
+
|
| 51 |
+
Post-translational modifications. After a protein is translated from RNA, it may undergo additional modifications, e.g. phosphorylation, which play a key role in protein structure and function.
|
| 52 |
+
|
| 53 |
+
## 3 METHODOLOGY
|
| 54 |
+
|
| 55 |
+
Model. We demonstrate our interpretability methods on five Transformer models that were pretrained through language modeling of amino acid sequences. We primarily focus on the BERT-Base model from TAPE (Rao et al., 2019), which was pretrained on Pfam, a dataset of 31M protein sequences (ElGebali et al., 2019b). We refer to this model as TapeBert . We also analyze 4 pre-trained Transformer models from ProtTrans (Elnaggar et al., 2020): ProtBert and ProtBert-BFD , which are 30-layer, 16-head BERT models; ProtAlbert , a 12-layer, 64-head ALBERT (Lan et al., 2020) model; and ProtXLNet , a 30-layer, 16-head XLNet (Yang et al., 2019) model. ProtBert-BFD was pretrained on BFD (Steinegger & Söding, 2018), a dataset of 2.1B protein sequences, while the other ProtTrans models were pretrained on UniRef100 (Suzek et al., 2014), which includes 216M protein sequences. A summary of these 5 models is presented in Appendix A.1.
|
| 56 |
+
|
| 57 |
+
Here we present an overview of BERT, with additional details on all models in Appendix A.2. BERT inputs a sequence of amino acids x = ( x 1 , . . . , x n ) and applies a series of encoders. Each encoder layer ℓ outputs a sequence of continuous embeddings ( h ( ℓ ) 1 , . . . , h ( ℓ ) n ) using a multi-headed attention mechanism. Each attention head in a layer produces a set of attention weights α for an input, where α i,j > 0 is the attention from token i to token j , such that ∑ j α i,j = 1 . Intuitively, attention weights define the influence of every token on the next layer's representation for the current token. We denote a particular head by <layer>-<head\_index> , e.g. head 3-7 for the 3rd layer's 7th head.
|
| 58 |
+
|
| 59 |
+
Attention analysis. We analyze how attention aligns with various protein properties. For properties of token pairs, e.g. contact maps, we define an indicator function f ( i, j ) that returns 1 if the property is present in token pair ( i, j ) (e.g., if amino acids i and j are in contact), and 0 otherwise. We then compute the proportion of high-attention token pairs ( α i,j > θ ) where the property is present, aggregated over a dataset X :
|
| 60 |
+
|
| 61 |
+
<!-- formula-not-decoded -->
|
| 62 |
+
|
| 63 |
+
where θ is a threshold to select for high-confidence attention weights. We also present an alternative, continuous version of this metric in Appendix B.1.
|
| 64 |
+
|
| 65 |
+
For properties of individual tokens , e.g. binding sites, we define f ( i, j ) to return 1 if the property is present in token j (e.g. if j is a binding site). In this case, p α ( f ) equals the proportion of attention that is directed to the property (e.g. the proportion of attention focused on binding sites).
|
| 66 |
+
|
| 67 |
+
When applying these metrics, we include two types of checks to ensure that the results are not due to chance. First, we test that the proportion of attention that aligns with particular properties is significantly higher than the background frequency of these properties, taking into account the Bonferroni correction for multiple hypotheses corresponding to multiple attention heads. Second, we compare the results to a null model, which is an instance of the model with randomly shuffled attention weights. We describe these methods in detail in Appendix B.2.
|
| 68 |
+
|
| 69 |
+
Probing tasks. We also perform probing tasks on the model, which test the knowledge contained in model representations by using them as inputs to a classifier that predicts a property of interest (Veldhoen et al., 2016; Conneau et al., 2018; Adi et al., 2016). The performance of the probing classifier serves as a measure of the knowledge of the property that is encoded in the representation. We run both embedding probes , which assess the knowledge encoded in the output embeddings of each layer, and attention probes (Reif et al., 2019; Clark et al., 2019), which measure the knowledge contained in the attention weights for pairwise features. Details are provided in Appendix B.3.
|
| 70 |
+
|
| 71 |
+
Datasets. For our analyses of amino acids and contact maps, we use a curated dataset from TAPE based on ProteinNet (AlQuraishi, 2019; Fox et al., 2013; Berman et al., 2000; Moult et al., 2018), which contains amino acid sequences annotated with spatial coordinates (used for the contact map analysis). For the analysis of secondary structure and binding sites we use the Secondary Structure dataset (Rao et al., 2019; Berman et al., 2000; Moult et al., 2018; Klausen et al., 2019) from TAPE. We employed a taxonomy of secondary structure with three categories: Helix , Strand , and Turn/Bend , with the last two belonging to the higher-level beta sheet category (Sec. 2). We used this taxonomy to study how the model understood structurally distinct regions of beta sheets. We obtained token-level binding site and protein modification labels from the Protein Data Bank (Berman et al., 2000). For analyzing attention, we used a random subset of 5000 sequences from the training split of the respective datasets (note that none of the aforementioned annotations were used in model training). For the diagnostic classifier, we used the respective training splits for training and the validation splits for evaluation. See Appendix B.4 for additional details.
|
| 72 |
+
|
| 73 |
+
Figure 2: Agreement between attention and contact maps across five pretrained Transformer models from TAPE (a) and ProtTrans (b-e). The heatmaps show the proportion of high-confidence attention weights ( α i,j > θ ) from each head that connects pairs of amino acids that are in contact with one another. In TapeBert (a), for example, we can see that 45% of attention in head 12-4 (the 12th layer's 4th head) maps to contacts. The bar plots show the maximum value from each layer. Note that the vertical striping in ProtAlbert (b) is likely due to cross-layer parameter sharing (see Appendix A.3).
|
| 74 |
+
|
| 75 |
+
<!-- image -->
|
| 76 |
+
|
| 77 |
+
Experimental details We exclude attention to the [SEP] delimiter token, as it has been shown to be a 'no-op' attention token (Clark et al., 2019), as well as attention to the [CLS] token, which is not explicitly used in language modeling. We only include results for attention heads where at least 100 high-confidence attention arcs are available for analysis. We set the attention threshold θ to 0.3 to select for high-confidence attention while retaining sufficient data for analysis. We truncate all protein sequences to a length of 512 to reduce memory requirements. 1
|
| 78 |
+
|
| 79 |
+
We note that all of the above analyses are purely associative and do not attempt to establish a causal link between attention and model behavior (Vig et al., 2020; Grimsley et al., 2020), nor to explain model predictions (Jain & Wallace, 2019; Wiegreffe & Pinter, 2019).
|
| 80 |
+
|
| 81 |
+
## 4 WHAT DOES ATTENTION UNDERSTAND ABOUT PROTEINS?
|
| 82 |
+
|
| 83 |
+
## 4.1 PROTEIN STRUCTURE
|
| 84 |
+
|
| 85 |
+
Here we explore the relationship between attention and tertiary structure, as characterized by contact maps (see Section 2). Secondary structure results are included in Appendix C.1.
|
| 86 |
+
|
| 87 |
+
Attention aligns strongly with contact maps in the deepest layers. Figure 2 shows how attention aligns with contact maps across the heads of the five models evaluated 2 , based on the metric defined in Equation 1. The most aligned heads are found in the deepest layers and focus up to 44.7% (TapeBert), 55.7% (ProtAlbert), 58.5% (ProtBert), 63.2% (ProtBert-BFD), and 44.5% (ProtXLNet) of attention on contacts, whereas the background frequency of contacts among all amino acid pairs in the dataset is 1.3%. Figure 1a shows an example of the induced attention from the top head in TapeBert. We note that the model with the single most aligned head-ProtBert-BFD-is the largest model (same size as ProteinBert) at 420M parameters (Appendix A.1) and it was also the only model pre-trained on the largest dataset, BFD. It's possible that both factors helped the model learn more structurally-aligned attention patterns. Statistical significance tests and null models are reported in Appendix C.2.
|
| 88 |
+
|
| 89 |
+
1 94% of sequences had length less than 512. Experiments performed on single 16GB Tesla V-100 GPU.
|
| 90 |
+
|
| 91 |
+
2 Heads with fewer than 100 high-confidence attention weights across the dataset are grayed out.
|
| 92 |
+
|
| 93 |
+
Figure 3: Proportion of attention focused on binding sites across five pretrained models. The heatmaps show the proportion of high-confidence attention ( α i,j > θ ) from each head that is directed to binding sites. In TapeBert (a), for example, we can see that 49% of attention in head 11-6 (the 11th layer's 6th head) is directed to binding sites. The bar plots show the maximum value from each layer.
|
| 94 |
+
|
| 95 |
+
<!-- image -->
|
| 96 |
+
|
| 97 |
+
Considering the models were trained on language modeling tasks without any spatial information, the presence of these structurally-aware attention heads is intriguing. One possible reason for this emergent behavior is that contacts are more likely to biochemically interact with one another, creating statistical dependencies between the amino acids in contact. By focusing attention on the contacts of a masked position, the language models may acquire valuable context for token prediction.
|
| 98 |
+
|
| 99 |
+
While there seems to be a strong correlation between the attention head output and classically-defined contacts, there are also differences. The models may have learned differing contextualized or nuanced formulations that describe amino acid interactions. These learned interactions could then be used for further discovery and investigation or repurposed for prediction tasks similar to how principles of coevolution enabled a powerful representation for structure prediction.
|
| 100 |
+
|
| 101 |
+
## 4.2 BINDING SITES AND POST-TRANSLATIONAL MODIFICATIONS
|
| 102 |
+
|
| 103 |
+
We also analyze how attention interacts with binding sites and post-translational modifications (PTMs), which both play a key role in protein function.
|
| 104 |
+
|
| 105 |
+
Attention targets binding sites throughout most layers of the models. Figure 3 shows the proportion of attention focused on binding sites (Eq. 1) across the heads of the 5 models studied. Attention to binding sites is most pronounced in the ProtAlbert model (Figure 3b), which has 22 heads that focus over 50% of attention on bindings sites, whereas the background frequency of binding sites in the dataset is 4.8%. The three BERT models (Figures 3a, 3c, and 3d) also attend strongly to binding sites, with attention heads focusing up to 48.2%, 50.7%, and 45.6% of attention on binding sites, respectively. Figure 1b visualizes the attention in one strongly-aligned head from the TapeBert model. Statistical significance tests and a comparison to a null model are provided in Appendix C.3.
|
| 106 |
+
|
| 107 |
+
ProtXLNet (Figure 3e) also targets binding sites, but not as strongly as the other models: the most aligned head focuses 15.1% of attention on binding sites, and the average head directs just 6.2% of attention to binding sites, compared to 13.2%, 19.8%, 16.0%, and 15.1% for the first four models in Figure 3. It's unclear whether this disparity is due to differences in architectures or pre-training objectives; for example, ProtXLNet uses a bidirectional auto-regressive pretraining method (see Appendix A.2), whereas the other 4 models all use masked language modeling objectives.
|
| 108 |
+
|
| 109 |
+
Figure 4: Each plot shows the percentage of attention focused on the given property, averaged over all heads within each layer. The plots, sorted by center of gravity (red dashed line), show that heads in deeper layers focus relatively more attention on binding sites and contacts, whereas attention toward specific secondary structures is more even across layers.
|
| 110 |
+
|
| 111 |
+
<!-- image -->
|
| 112 |
+
|
| 113 |
+
Figure 5: Performance of probing classifiers by layer, sorted by task order in Figure 4. The embedding probes (orange) quantify the knowledge of the given property that is encoded in each layer's output embeddings. The attention probe (blue), show the amount of information encoded in attention weights for the (pairwise) contact feature. Additional details are provided in Appendix B.3.
|
| 114 |
+
|
| 115 |
+
<!-- image -->
|
| 116 |
+
|
| 117 |
+
Why does attention target binding sites? In contrast to contact maps, which reveal relationships within proteins, binding sites describe how a protein interacts with other molecules. These external interactions ultimately define the high-level function of the protein, and thus binding sites remain conserved even when the sequence as a whole evolves (Kinjo & Nakamura, 2009). Further, structural motifs in binding sites are mainly restricted to specific families or superfamilies of proteins (Kinjo & Nakamura, 2009), and binding sites can reveal evolutionary relationships among proteins (Lee et al., 2017). Thus binding sites may provide the model with a high-level characterization of the protein that is robust to individual sequence variation. By attending to these regions, the model can leverage this higher-level context when predicting masked tokens throughout the sequence.
|
| 118 |
+
|
| 119 |
+
Attention targets PTMs in a small number of heads. A small number of heads in each model concentrate their attention very strongly on amino acids associated with post-translational modifications (PTMs). For example, Head 11-6 in TapeBert focused 64% of attention on PTM positions, though these occur at only 0.8% of sequence positions in the dataset. 3 Similar to our discussion on binding sites, PTMs are critical to protein function (Rubin & Rosen, 1975) and thereby are likely to exhibit behavior that is conserved across the sequence space. See Appendix C.4 for full results.
|
| 120 |
+
|
| 121 |
+
## 4.3 CROSS-LAYER ANALYSIS
|
| 122 |
+
|
| 123 |
+
We analyze how attention captures properties of varying complexity across different layers of TapeBert, and compare this to a probing analysis of embeddings and attention weights (see Section 3).
|
| 124 |
+
|
| 125 |
+
Attention targets higher-level properties in deeper layers. As shown in Figure 4, deeper layers focus relatively more attention on binding sites and contacts (high-level concept), whereas secondary structure (low- to mid-level concept) is targeted more evenly across layers. The probing analysis of attention (Figure 5, blue) similarly shows that knowledge of contact maps (a pairwise feature)
|
| 126 |
+
|
| 127 |
+
3 This head also targets binding sites (Fig. 3a) but at a percentage of 49%.
|
| 128 |
+
|
| 129 |
+
<!-- image -->
|
| 130 |
+
|
| 131 |
+
Head Head
|
| 132 |
+
|
| 133 |
+
Figure 6: Percentage of each head's attention focused on amino acids Pro (left) and Phe (right).
|
| 134 |
+
|
| 135 |
+
<!-- image -->
|
| 136 |
+
|
| 137 |
+
Figure 7: Pairwise attention similarity (left) vs. substitution matrix (right) (codes in App. C.5)
|
| 138 |
+
|
| 139 |
+
is encoded in attention weights primarily in the last 1-2 layers. These results are consistent with prior work in NLP that suggests deeper layers in text-based Transformers attend to more complex properties (Vig & Belinkov, 2019) and encode higher-level representations (Raganato & Tiedemann, 2018; Peters et al., 2018; Tenney et al., 2019; Jawahar et al., 2019).
|
| 140 |
+
|
| 141 |
+
The embedding probes (Figure 5, orange) also show that the model first builds representations of local secondary structure in lower layers before fully encoding binding sites and contact maps in deeper layers. However, this analysis also reveals stark differences in how knowledge of contact maps is accrued in embeddings, which accumulate this knowledge gradually over many layers, compared to attention weights, which acquire this knowledge only in the final layers in this case. This example points out limitations of common layerwise probing approaches that only consider embeddings, which, intuitively, represent what the model knows but not necessarily how it operationalizes that knowledge.
|
| 142 |
+
|
| 143 |
+
## 4.4 AMINO ACIDS AND THE SUBSTITUTION MATRIX
|
| 144 |
+
|
| 145 |
+
In addition to high-level structural and functional properties, we also performed a fine-grained analysis of the interaction between attention and particular amino acids.
|
| 146 |
+
|
| 147 |
+
Attention heads specialize in particular amino acids. We computed the proportion of TapeBert's attention to each of the 20 standard amino acids, as shown in Figure 6 for two example amino acids. For 16 of the amino acids, there exists an attention head that focuses over 25% of attention on that amino acid, significantly greater than the background frequencies of the corresponding amino acids, which range from 1.3% to 9.4%. Similar behavior was observed for ProtBert, ProtBert-BFD, ProtAlbert, and ProtXLNet models, with 17, 15, 16, and 18 amino acids, respectively, receiving greater than 25% of the attention from at least one attention head. Detailed results for TapeBert including statistical significance tests and comparison to a null model are presented in Appendix C.5.
|
| 148 |
+
|
| 149 |
+
Attention is consistent with substitution relationships. A natural follow-up question from the above analysis is whether each head has 'memorized' specific amino acids to target, or whether it has actually learned meaningful properties that correlate with particular amino acids. To test the latter hypothesis, we analyze whether amino acids with similar structural and functional properties are attended to similarly across heads. Specifically, we compute the Pearson correlation between the distribution of attention across heads between all pairs of distinct amino acids, as shown in Figure 7 (left) for TapeBert. For example, the entry for Pro (P) and Phe (F) is the correlation between the two heatmaps in Figure 6. We compare these scores to the BLOSUM62 substitution scores (Sec. 2) in Figure 7 (right), and find a Pearson correlation of 0.73, suggesting that attention is moderately consistent with substitution relationships. Similar correlations are observed for the ProtTrans models: 0.68 (ProtBert), 0.75 (ProtBert-BFD), 0.60 (ProtAlbert), and 0.71 (ProtXLNet). As a baseline, the randomized versions of these models (Appendix B.2) yielded correlations of -0.02 (TapeBert), 0.02 (ProtBert), -0.03 (ProtBert-BFD), -0.05 (ProtAlbert), and 0.21 (ProtXLNet).
|
| 150 |
+
|
| 151 |
+
## 5 RELATED WORK
|
| 152 |
+
|
| 153 |
+
## 5.1 PROTEIN LANGUAGE MODELS
|
| 154 |
+
|
| 155 |
+
Deep neural networks for protein language modeling have received broad interest. Early work applied the Skip-gram model (Mikolov et al., 2013) to construct continuous embeddings from protein sequences (Asgari & Mofrad, 2015). Sequence-only language models have since been trained through autoregressive or autoencoding self-supervision objectives for discriminative and generative tasks, for example, using LSTMs or Transformer-based architectures (Alley et al., 2019; Bepler & Berger, 2019; Rao et al., 2019; Rives et al., 2019). TAPE created a benchmark of five tasks to assess protein sequence models, and ProtTrans also released several large-scale pretrained protein Transformer models (Elnaggar et al., 2020). Riesselman et al. (2019); Madani et al. (2020) trained autoregressive generative models to predict the functional effect of mutations and generate natural-like proteins.
|
| 156 |
+
|
| 157 |
+
From an interpretability perspective, Rives et al. (2019) showed that the output embeddings from a pretrained Transformer can recapitulate structural and functional properties of proteins through learned linear transformations. Various works have analyzed output embeddings of protein models through dimensionality reduction techniques such as PCA or t-SNE (Elnaggar et al., 2020; Biswas et al., 2020). In our work, we take an interpretability-first perspective to focus on the internal model representations, specifically attention and intermediate hidden states, across multiple protein language models. We also explore novel biological properties including binding sites and post-translational modifications.
|
| 158 |
+
|
| 159 |
+
## 5.2 INTERPRETING MODELS IN NLP
|
| 160 |
+
|
| 161 |
+
The rise of deep neural networks in ML has also led to much work on interpreting these so-called black-box models. This section reviews the NLP interpretability literature on the Transformer model, which is directly comparable to our work on interpreting Transformer models of protein sequences.
|
| 162 |
+
|
| 163 |
+
Interpreting Transformers. The Transformer is a neural architecture that uses attention to accelerate learning (Vaswani et al., 2017). In NLP, transformers are the backbone of state-of-the-art pre-trained language models such as BERT (Devlin et al., 2019). BERTology focuses on interpreting what the BERT model learns about language using a suite of probes and interventions (Rogers et al., 2020). So-called diagnostic classifiers are used to interpret the outputs from BERT's layers (Veldhoen et al., 2016). At a high level, mechanisms for interpreting BERT can be placed into three main categories: interpreting the learned embeddings (Ethayarajh, 2019; Wiedemann et al., 2019; Mickus et al., 2020; Adi et al., 2016; Conneau et al., 2018), BERT's learned knowledge of syntax (Lin et al., 2019; Liu et al., 2019; Tenney et al., 2019; Htut et al., 2019; Hewitt & Manning, 2019; Goldberg, 2019), and BERT's learned knowledge of semantics (Tenney et al., 2019; Ettinger, 2020).
|
| 164 |
+
|
| 165 |
+
Interpreting attention specifically. Interpreting attention on textual sequences is a wellestablished area of research (Wiegreffe & Pinter, 2019; Zhong et al., 2019; Brunner et al., 2020; Hewitt & Manning, 2019). Past work has been shown that attention correlates with syntactic and semantic relationships in natural language in some cases (Clark et al., 2019; Vig & Belinkov, 2019; Htut et al., 2019). Depending on the task and model architecture, attention may have less or more explanatory power for model predictions (Jain & Wallace, 2019; Serrano & Smith, 2019; Pruthi et al., 2020; Moradi et al., 2019; Vashishth et al., 2019). Visualization techniques have been used to convey the structure and properties of attention in Transformers (Vaswani et al., 2017; Kovaleva et al., 2019; Hoover et al., 2020; Vig, 2019). Recent work has begun to analyze attention in Transformer models outside of the domain of natural language (Schwaller et al., 2020; Payne et al., 2020).
|
| 166 |
+
|
| 167 |
+
Our work extends these methods to protein sequence models by considering particular biophysical properties and relationships. We also present a joint cross-layer probing analysis of attention weights and layer embeddings. While past work in NLP has analyzed attention and embeddings across layers, we believe we are the first to do so in any domain using a single, unified metric, which enables us to directly compare the relative information content of the two representations. Finally, we present a novel tool for visualizing attention embedded in three-dimensional structure.
|
| 168 |
+
|
| 169 |
+
## 6 CONCLUSIONS AND FUTURE WORK
|
| 170 |
+
|
| 171 |
+
This paper builds on the synergy between NLP and computational biology by adapting and extending NLP interpretability methods to protein sequence modeling. We show how a Transformer language model recovers structural and functional properties of proteins and integrates this knowledge directly into its attention mechanism. While this paper focuses on reconciling attention with known properties of proteins, one might also leverage attention to uncover novel relationships or more nuanced forms of existing measures such as contact maps, as discussed in Section 4.1. In this way, language models have the potential to serve as tools for scientific discovery. But in order for learned representations to be accessible to domain experts, they must be presented in an appropriate context to facilitate discovery. Visualizing attention in the context of protein structure (Figure 1) is one attempt to do so. We believe there is the potential to develop such contextual visualizations of learned representations in a range of scientific domains.
|
| 172 |
+
|
| 173 |
+
## ACKNOWLEDGMENTS
|
| 174 |
+
|
| 175 |
+
We would like to thank Xi Victoria Lin, Stephan Zheng, Melvin Gruesbeck, and the anonymous reviewers for their valuable feedback.
|
| 176 |
+
|
| 177 |
+
## REFERENCES
|
| 178 |
+
|
| 179 |
+
- Yossi Adi, Einat Kermany, Yonatan Belinkov, Ofer Lavi, and Yoav Goldberg. Fine-grained analysis of sentence embeddings using auxiliary prediction tasks. arXiv:1608.04207 [cs.CL]., 2016.
|
| 180 |
+
- Ethan C Alley, Grigory Khimulya, Surojit Biswas, Mohammed AlQuraishi, and George M Church. Unified rational protein engineering with sequence-based deep representation learning. Nature Methods , 16(12):1315-1322, 2019.
|
| 181 |
+
- Mohammed AlQuraishi. ProteinNet: a standardized data set for machine learning of protein structure. BMC Bioinformatics , 20, 2019.
|
| 182 |
+
- Ehsaneddin Asgari and Mohammad RK Mofrad. Continuous distributed representation of biological sequences for deep proteomics and genomics. PLOS One , 10(11), 2015.
|
| 183 |
+
- Tristan Bepler and Bonnie Berger. Learning protein sequence embeddings using information from structure. In International Conference on Learning Representations , 2019.
|
| 184 |
+
- Helen M Berman, John Westbrook, Zukang Feng, Gary Gilliland, Talapady N Bhat, Helge Weissig, Ilya N Shindyalov, and Philip E Bourne. The protein data bank. Nucleic Acids Research , 28(1): 235-242, 2000.
|
| 185 |
+
- Surojit Biswas, Grigory Khimulya, Ethan C. Alley, Kevin M. Esvelt, and George M. Church. Low-n protein engineering with data-efficient deep learning. bioRxiv , 2020. doi: 10.1101/ 2020.01.23.917682. URL https://www.biorxiv.org/content/early/2020/08/ 31/2020.01.23.917682 .
|
| 186 |
+
- Ashraf Brik and Chi-Huey Wong. HIV-1 protease: Mechanism and drug discovery. Organic & Biomolecular Chemistry , 1(1):5-14, 2003.
|
| 187 |
+
- Gino Brunner, Yang Liu, Damian Pascual, Oliver Richter, Massimiliano Ciaramita, and Roger Wattenhofer. On identifiability in Transformers. In International Conference on Learning Representations , 2020. URL https://openreview.net/forum?id=BJg1f6EFDB .
|
| 188 |
+
- Kevin Clark, Urvashi Khandelwal, Omer Levy, and Christopher D. Manning. What does BERT look at? An analysis of BERT's attention. In BlackBoxNLP@ACL , 2019.
|
| 189 |
+
|
| 190 |
+
- Alexis Conneau, German Kruszewski, Guillaume Lample, Loïc Barrault, and Marco Baroni. What you can cram into a single $&!#* vector: Probing sentence embeddings for linguistic properties. In Proceedings of the 56th Annual Meeting of the Association for Computational Linguistics , pp. 2126-2136, 2018.
|
| 191 |
+
- Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. BERT: Pre-training of deep bidirectional transformers for language understanding. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers) , pp. 4171-4186, Minneapolis, Minnesota, 2019. Association for Computational Linguistics.
|
| 192 |
+
- Sara El-Gebali, Jaina Mistry, Alex Bateman, Sean R. Eddy, Aurélien Luciani, Simon C. Potter, Matloob Qureshi, Lorna J. Richardson, Gustavo A. Salazar, Alfredo Smart, Erik L. L. Sonnhammer, Layla Hirsh, Lisanna Paladin, Damiano Piovesan, Silvio C. E. Tosatto, and Robert D. Finn. The Pfam protein families database in 2019. Nucleic Acids Research , 47(D1):D427-D432, January 2019a. doi: 10.1093/nar/gky995.
|
| 193 |
+
- Sara El-Gebali, Jaina Mistry, Alex Bateman, Sean R Eddy, Aurélien Luciani, Simon C Potter, Matloob Qureshi, Lorna J Richardson, Gustavo A Salazar, Alfredo Smart, Erik L L Sonnhammer, Layla Hirsh, Lisanna Paladin, Damiano Piovesan, Silvio C E Tosatto, and Robert D Finn. The Pfam protein families database in 2019. Nucleic Acids Research , 47(D1):D427-D432, 2019b. ISSN 0305-1048. doi: 10.1093/nar/gky995.
|
| 194 |
+
- Ahmed Elnaggar, Michael Heinzinger, Christian Dallago, Ghalia Rihawi, Yu Wang, Llion Jones, Tom Gibbs, Tamas Feher, Christoph Angerer, Martin Steinegger, Debsindhu Bhowmik, and Burkhard Rost. ProtTrans: Towards cracking the language of life's code through self-supervised deep learning and high performance computing. arXiv preprint arXiv:2007.06225 , 2020.
|
| 195 |
+
- Kawin Ethayarajh. How contextual are contextualized word representations? Comparing the geometry of BERT, ELMo, and GPT-2 embeddings. In Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP) , pp. 55-65, Hong Kong, China, 2019. Association for Computational Linguistics.
|
| 196 |
+
- Allyson Ettinger. What BERT is not: Lessons from a new suite of psycholinguistic diagnostics for language models. Transactions of the Association for Computational Linguistics , 8:34-48, 2020.
|
| 197 |
+
- Naomi K Fox, Steven E Brenner, and John-Marc Chandonia. SCOPe: Structural classification of proteins-extended, integrating scop and astral data and classification of new structures. Nucleic Acids Research , 42(D1):D304-D309, 2013.
|
| 198 |
+
- Yoav Goldberg. Assessing BERT's syntactic abilities. arXiv preprint arXiv:1901.05287 , 2019.
|
| 199 |
+
- Christopher Grimsley, Elijah Mayfield, and Julia R.S. Bursten. Why attention is not explanation: Surgical intervention and causal reasoning about neural models. In Proceedings of The 12th Language Resources and Evaluation Conference , pp. 1780-1790, Marseille, France, May 2020. European Language Resources Association. ISBN 979-10-95546-34-4. URL https://www. aclweb.org/anthology/2020.lrec-1.220 .
|
| 200 |
+
- S Henikoff and J G Henikoff. Amino acid substitution matrices from protein blocks. Proceedings of the National Academy of Sciences , 89(22):10915-10919, 1992. ISSN 0027-8424. doi: 10.1073/ pnas.89.22.10915. URL https://www.pnas.org/content/89/22/10915 .
|
| 201 |
+
- John Hewitt and Christopher D Manning. A structural probe for finding syntax in word representations. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers) , pp. 4129-4138, 2019.
|
| 202 |
+
- Benjamin Hoover, Hendrik Strobelt, and Sebastian Gehrmann. exBERT: A Visual Analysis Tool to Explore Learned Representations in Transformer Models. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics: System Demonstrations , pp. 187-196. Association for Computational Linguistics, 2020.
|
| 203 |
+
|
| 204 |
+
- Phu Mon Htut, Jason Phang, Shikha Bordia, and Samuel R Bowman. Do attention heads in BERT track syntactic dependencies? arXiv preprint arXiv:1911.12246 , 2019.
|
| 205 |
+
- Sarthak Jain and Byron C. Wallace. Attention is not Explanation. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers) , pp. 3543-3556, June 2019.
|
| 206 |
+
- Ganesh Jawahar, Benoît Sagot, and Djamé Seddah. What does BERT learn about the structure of language? In ACL 2019 - 57th Annual Meeting of the Association for Computational Linguistics , Florence, Italy, July 2019. URL https://hal.inria.fr/hal-02131630 .
|
| 207 |
+
- Akira Kinjo and Haruki Nakamura. Comprehensive structural classification of ligand-binding motifs in proteins. Structure , 17(2), 2009.
|
| 208 |
+
- Michael Schantz Klausen, Martin Closter Jespersen, Henrik Nielsen, Kamilla Kjaergaard Jensen, Vanessa Isabell Jurtz, Casper Kaae Soenderby, Morten Otto Alexander Sommer, Ole Winther, Morten Nielsen, Bent Petersen, et al. NetSurfP-2.0: Improved prediction of protein structural features by integrated deep learning. Proteins: Structure, Function, and Bioinformatics , 2019.
|
| 209 |
+
- Olga Kovaleva, Alexey Romanov, Anna Rogers, and Anna Rumshisky. Revealing the dark secrets of BERT. In Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLPIJCNLP) , pp. 4365-4374, Hong Kong, China, 2019. Association for Computational Linguistics.
|
| 210 |
+
- Keita Kurita, Nidhi Vyas, Ayush Pareek, Alan W Black, and Yulia Tsvetkov. Measuring bias in contextualized word representations. In Proceedings of the First Workshop on Gender Bias in Natural Language Processing , pp. 166-172, Florence, Italy, 2019. Association for Computational Linguistics.
|
| 211 |
+
- Zhenzhong Lan, Mingda Chen, Sebastian Goodman, Kevin Gimpel, Piyush Sharma, and Radu Soricut. Albert: A lite bert for self-supervised learning of language representations. In International Conference on Learning Representations , 2020.
|
| 212 |
+
- Juyong Lee, Janez Konc, Dusanka Janezic, and Bernard Brooks. Global organization of a binding site network gives insight into evolution and structure-function relationships of proteins. Sci Rep , 7 (11652), 2017.
|
| 213 |
+
- Yongjie Lin, Yi Chern Tan, and Robert Frank. Open sesame: Getting inside BERT's linguistic knowledge. In Proceedings of the 2019 ACL Workshop BlackboxNLP: Analyzing and Interpreting Neural Networks for NLP , pp. 241-253, Florence, Italy, 2019. Association for Computational Linguistics.
|
| 214 |
+
- Nelson F. Liu, Matt Gardner, Yonatan Belinkov, Matthew E. Peters, and Noah A. Smith. Linguistic knowledge and transferability of contextual representations. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers) , pp. 1073-1094. Association for Computational Linguistics, 2019.
|
| 215 |
+
- Ali Madani, Bryan McCann, Nikhil Naik, Nitish Shirish Keskar, Namrata Anand, Raphael R. Eguchi, Po-Ssu Huang, and Richard Socher. Progen: Language modeling for protein generation. arXiv preprint arXiv:2004.03497 , 2020.
|
| 216 |
+
- Timothee Mickus, Mathieu Constant, Denis Paperno, and Kees Van Deemter. What do you mean, BERT? Assessing BERT as a Distributional Semantics Model. Proceedings of the Society for Computation in Linguistics , 3, 2020.
|
| 217 |
+
- Tomas Mikolov, Ilya Sutskever, Kai Chen, Greg S Corrado, and Jeff Dean. Distributed representations of words and phrases and their compositionality. In C. J. C. Burges, L. Bottou, M. Welling, Z. Ghahramani, and K. Q. Weinberger (eds.), Advances in Neural Information Processing Systems 26 , pp. 3111-3119. Curran Associates, Inc., 2013.
|
| 218 |
+
|
| 219 |
+
- Pooya Moradi, Nishant Kambhatla, and Anoop Sarkar. Interrogating the explanatory power of attention in neural machine translation. In Proceedings of the 3rd Workshop on Neural Generation and Translation , pp. 221-230, Hong Kong, November 2019. Association for Computational Linguistics. doi: 10.18653/v1/D19-5624. URL https://www.aclweb.org/anthology/ D19-5624 .
|
| 220 |
+
- John Moult, Krzysztof Fidelis, Andriy Kryshtafovych, Torsten Schwede, and Anna Tramontano. Critical assessment of methods of protein structure prediction (CASP)-Round XII. Proteins: Structure, Function, and Bioinformatics , 86:7-15, 2018. ISSN 08873585. doi: 10.1002/prot.25415. URL http://doi.wiley.com/10.1002/prot.25415 .
|
| 221 |
+
- Hai Nguyen, David A Case, and Alexander S Rose. NGLview-interactive molecular graphics for Jupyter notebooks. Bioinformatics , 34(7):1241-1242, 12 2017. ISSN 1367-4803. doi: 10.1093/ bioinformatics/btx789. URL https://doi.org/10.1093/bioinformatics/btx789 .
|
| 222 |
+
- Timothy Niven and Hung-Yu Kao. Probing neural network comprehension of natural language arguments. In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics , pp. 4658-4664, Florence, Italy, 2019. Association for Computational Linguistics.
|
| 223 |
+
- Josh Payne, Mario Srouji, Dian Ang Yap, and Vineet Kosaraju. Bert learns (and teaches) chemistry. arXiv preprint arXiv:2007.16012 , 2020.
|
| 224 |
+
- Matthew Peters, Mark Neumann, Luke Zettlemoyer, and Wen-tau Yih. Dissecting contextual word embeddings: Architecture and representation. In Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing , pp. 1499-1509, Brussels, Belgium, OctoberNovember 2018. Association for Computational Linguistics. doi: 10.18653/v1/D18-1179. URL https://www.aclweb.org/anthology/D18-1179 .
|
| 225 |
+
- Danish Pruthi, Mansi Gupta, Bhuwan Dhingra, Graham Neubig, and Zachary C. Lipton. Learning to deceive with attention-based explanations. In Annual Conference of the Association for Computational Linguistics (ACL) , July 2020. URL https://arxiv.org/abs/1909.07913 .
|
| 226 |
+
- Alessandro Raganato and Jörg Tiedemann. An analysis of encoder representations in Transformerbased machine translation. In Proceedings of the 2018 EMNLP Workshop BlackboxNLP: Analyzing and Interpreting Neural Networks for NLP , pp. 287-297, Brussels, Belgium, November 2018. Association for Computational Linguistics. doi: 10.18653/v1/W18-5431. URL https://www. aclweb.org/anthology/W18-5431 .
|
| 227 |
+
- Roshan Rao, Nicholas Bhattacharya, Neil Thomas, Yan Duan, Xi Chen, John Canny, Pieter Abbeel, and Yun S Song. Evaluating protein transfer learning with TAPE. In Advances in Neural Information Processing Systems , 2019.
|
| 228 |
+
- Emily Reif, Ann Yuan, Martin Wattenberg, Fernanda B Viegas, Andy Coenen, Adam Pearce, and Been Kim. Visualizing and measuring the geometry of BERT. In H. Wallach, H. Larochelle, A. Beygelzimer, F. d'Alché-Buc, E. Fox, and R. Garnett (eds.), Advances in Neural Information Processing Systems , volume 32, pp. 8594-8603. Curran Associates, Inc., 2019.
|
| 229 |
+
- Adam J Riesselman, Jung-Eun Shin, Aaron W Kollasch, Conor McMahon, Elana Simon, Chris Sander, Aashish Manglik, Andrew C Kruse, and Debora S Marks. Accelerating protein design using autoregressive generative models. bioRxiv , pp. 757252, 2019.
|
| 230 |
+
- Alexander Rives, Siddharth Goyal, Joshua Meier, Demi Guo, Myle Ott, C Lawrence Zitnick, Jerry Ma, and Rob Fergus. Biological structure and function emerge from scaling unsupervised learning to 250 million protein sequences. bioRxiv , pp. 622803, 2019.
|
| 231 |
+
- Anna Rogers, Olga Kovaleva, and Anna Rumshisky. A primer in BERTology: What we know about how BERT works. Transactions of the Association for Computational Linguistics , 8:842-866, 2020.
|
| 232 |
+
- Nathan J Rollins, Kelly P Brock, Frank J Poelwijk, Michael A Stiffler, Nicholas P Gauthier, Chris Sander, and Debora S Marks. Inferring protein 3D structure from deep mutation scans. Nature Genetics , 51(7):1170, 2019.
|
| 233 |
+
|
| 234 |
+
- Alexander S. Rose and Peter W. Hildebrand. NGL Viewer: a web application for molecular visualization. Nucleic Acids Research , 43(W1):W576-W579, 04 2015. ISSN 0305-1048. doi: 10.1093/nar/gkv402. URL https://doi.org/10.1093/nar/gkv402 .
|
| 235 |
+
- Alexander S Rose, Anthony R Bradley, Yana Valasatava, Jose M Duarte, Andreas Prli´ c, and Peter W Rose. NGL viewer: web-based molecular graphics for large complexes. Bioinformatics , 34(21): 3755-3758, 05 2018. ISSN 1367-4803. doi: 10.1093/bioinformatics/bty419. URL https: //doi.org/10.1093/bioinformatics/bty419 .
|
| 236 |
+
- Charles Rubin and Ora Rosen. Protein phosphorylation. Annual Review of Biochemistry , 44:831-887, 1975. URL https://doi.org/10.1146/annurev.bi.44.070175.004151 .
|
| 237 |
+
- Philippe Schwaller, Benjamin Hoover, Jean-Louis Reymond, Hendrik Strobelt, and Teodoro Laino. Unsupervised attention-guided atom-mapping. ChemRxiv , 5 2020. doi: 10.26434/ chemrxiv.12298559.v1. URL https://chemrxiv.org/articles/Unsupervised\_ Attention-Guided\_Atom-Mapping/12298559 .
|
| 238 |
+
- Sofia Serrano and Noah A. Smith. Is attention interpretable? In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics , pp. 2931-2951, Florence, Italy, July 2019. Association for Computational Linguistics. doi: 10.18653/v1/P19-1282. URL https: //www.aclweb.org/anthology/P19-1282 .
|
| 239 |
+
- Martin Steinegger and Johannes Söding. Clustering huge protein sequence sets in linear time. Nature Communications , 9(2542), 2018. doi: 10.1038/s41467-018-04964-5.
|
| 240 |
+
- Baris E. Suzek, Yuqi Wang, Hongzhan Huang, Peter B. McGarvey, Cathy H. Wu, and the UniProt Consortium. UniRef clusters: a comprehensive and scalable alternative for improving sequence similarity searches. Bioinformatics , 31(6):926-932, 11 2014. ISSN 1367-4803. doi: 10.1093/ bioinformatics/btu739. URL https://doi.org/10.1093/bioinformatics/btu739 .
|
| 241 |
+
- Yi Chern Tan and L. Elisa Celis. Assessing social and intersectional biases in contextualized word representations. In Advances in Neural Information Processing Systems 32 , pp. 13230-13241. Curran Associates, Inc., 2019.
|
| 242 |
+
- Ian Tenney, Dipanjan Das, and Ellie Pavlick. BERT rediscovers the classical NLP pipeline. In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics , pp. 4593-4601, Florence, Italy, 2019. Association for Computational Linguistics.
|
| 243 |
+
- Shikhar Vashishth, Shyam Upadhyay, Gaurav Singh Tomar, and Manaal Faruqui. Attention interpretability across NLP tasks. arXiv preprint arXiv:1909.11218 , 2019.
|
| 244 |
+
- Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin. Attention is all you need. In Advances in Neural Information Processing Systems , pp. 5998-6008, 2017.
|
| 245 |
+
- Sara Veldhoen, Dieuwke Hupkes, and Willem H. Zuidema. Diagnostic classifiers revealing how neural networks process hierarchical structure. In CoCo@NIPS , 2016.
|
| 246 |
+
- Jesse Vig. A multiscale visualization of attention in the Transformer model. In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics: System Demonstrations , pp. 37-42, Florence, Italy, 2019. Association for Computational Linguistics.
|
| 247 |
+
- Jesse Vig and Yonatan Belinkov. Analyzing the structure of attention in a Transformer language model. In Proceedings of the 2019 ACL Workshop BlackboxNLP: Analyzing and Interpreting Neural Networks for NLP , pp. 63-76, Florence, Italy, 2019. Association for Computational Linguistics.
|
| 248 |
+
- Jesse Vig, Sebastian Gehrmann, Yonatan Belinkov, Sharon Qian, Daniel Nevo, Yaron Singer, and Stuart Shieber. Investigating gender bias in language models using causal mediation analysis. In Advances in Neural Information Processing Systems , volume 33, pp. 12388-12401, 2020.
|
| 249 |
+
- Gregor Wiedemann, Steffen Remus, Avi Chawla, and Chris Biemann. Does BERT make any sense? Interpretable word sense disambiguation with contextualized embeddings. arXiv preprint arXiv:1909.10430 , 2019.
|
| 250 |
+
|
| 251 |
+
- Sarah Wiegreffe and Yuval Pinter. Attention is not not explanation. In Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP) , pp. 11-20, November 2019.
|
| 252 |
+
- Zhilin Yang, Zihang Dai, Yiming Yang, Jaime Carbonell, Russ R Salakhutdinov, and Quoc V Le. XLNet: Generalized autoregressive pretraining for language understanding. In H. Wallach, H. Larochelle, A. Beygelzimer, F. d'Alché-Buc, E. Fox, and R. Garnett (eds.), Advances in Neural Information Processing Systems , volume 32, pp. 5753-5763. Curran Associates, Inc., 2019.
|
| 253 |
+
- Ruiqi Zhong, Steven Shao, and Kathleen McKeown. Fine-grained sentiment analysis with faithful attention. arXiv preprint arXiv:1908.06870 , 2019.
|
| 254 |
+
|
| 255 |
+
## A MODEL OVERVIEW
|
| 256 |
+
|
| 257 |
+
## A.1 PRE-TRAINED MODELS
|
| 258 |
+
|
| 259 |
+
Table 1 provides an overview of the five pre-trained Transformer models studied in this work. The models originate from the TAPE and ProtTrans repositories, spanning three model architectures: BERT, ALBERT, and XLNet.
|
| 260 |
+
|
| 261 |
+
Table 1: Summary of pre-trained models analyzed, including the source of the model, the type of Transformer used, the number of layers and heads, the total number of model parameters, the source of the pre-training dataset, and the number of protein sequences in the pre-training dataset.
|
| 262 |
+
|
| 263 |
+
| Source Name Type Layers Heads Params Train Dataset # Seq TAPE TapeBert BERT 12 12 94M Pfam 31M ProtTrans ProtBert BERT 30 16 420M Uniref100 216M ProtTrans ProtBert-BFD BERT 30 16 420M BFD 2.1B ProtTrans ProtAlbert ALBERT 12 64 224M Uniref100 216M ProtTrans ProtXLNet XLNet 30 16 409M Uniref100 216M |
|
| 264 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 265 |
+
|
| 266 |
+
## A.2 BERT TRANSFORMER ARCHITECTURE
|
| 267 |
+
|
| 268 |
+
Stacked Encoder: BERT uses a stacked-encoder architecture, which inputs a sequence of tokens x = ( x 1 , ..., x n ) and applies position and token embeddings followed by a series of encoder layers. Each layer applies multi-head self-attention (see below) in combination with a feedforward network, layer normalization, and residual connections. The output of each layer ℓ is a sequence of contextualized embeddings ( h ( ℓ ) 1 , . . . , h ( ℓ ) n ) .
|
| 269 |
+
|
| 270 |
+
Self-Attention: Given an input x = ( x 1 , . . . , x n ) , the self-attention mechanism assigns to each token pair i , j an attention weight α i,j > 0 where ∑ j α i,j = 1 . Attention in BERT is bidirectional. In the multi-layer, multi-head setting, α is specific to a layer and head. The BERT-Base model has 12 layers and 12 heads. Each attention head learns a distinct set of weights, resulting in 12 x 12 = 144 distinct attention mechanisms in this case.
|
| 271 |
+
|
| 272 |
+
The attention weights α i,j are computed from the scaled dot-product of the query vector of i and the key vector of j , followed by a softmax operation. The attention weights are then used to produce a weighted sum of value vectors:
|
| 273 |
+
|
| 274 |
+
<!-- formula-not-decoded -->
|
| 275 |
+
|
| 276 |
+
using query matrix Q , key matrix K , and value matrix V , where d k is the dimension of K . In a multi-head setting, the queries, keys, and values are linearly projected h times, and the attention operation is performed in parallel for each representation, with the results concatenated.
|
| 277 |
+
|
| 278 |
+
## A.3 OTHER TRANSFORMER VARIANTS
|
| 279 |
+
|
| 280 |
+
ALBERT: The architecture of ALBERT differs from BERT in two ways: (1) It shares parameters across layers, unlike BERT which learns distinct parameters for every layer and (2) It uses factorized embeddings, which allows the input token embeddings to be of a different (smaller) size than the hidden states. The original version of ALBERT designed for text also employed a sentence-order prediction pretraining task, but this was not used on the models studied in this paper.
|
| 281 |
+
|
| 282 |
+
XLNet: Instead of the masked-language modeling pretraining objective use for BERT, XLNet uses a bidirectional auto-regressive pretraining method that considers all possible orderings of the input factorization. The architecture also adds a segment recurrence mechanism to process long sequences, as well as a relative rather than absolute encoding scheme.
|
| 283 |
+
|
| 284 |
+
## B ADDITIONAL EXPERIMENTAL DETAILS
|
| 285 |
+
|
| 286 |
+
## B.1 ALTERNATIVE ATTENTION AGREEMENT METRIC
|
| 287 |
+
|
| 288 |
+
Here we present an alternative formulation to Eq. 1 based on an attention-weighted average. We define an indicator function f ( i, j ) for property f that returns 1 if the property is present in token pair ( i, j ) (i.e., if amino acids i and j are in contact), and zero otherwise. We then compute the proportion of attention that matches with f over a dataset X as follows:
|
| 289 |
+
|
| 290 |
+
<!-- formula-not-decoded -->
|
| 291 |
+
|
| 292 |
+
where α i,j ( x ) denotes the attention from i to j for input sequence x .
|
| 293 |
+
|
| 294 |
+
## B.2 STATISTICAL SIGNIFICANCE TESTING AND NULL MODELS
|
| 295 |
+
|
| 296 |
+
We perform statistical significance tests to determine whether any results based on the metric defined in Equation 1 are due to chance. Given a property f , as defined in Section 3, we perform a twoproportion z-test comparing (1) the proportion of high-confidence attention arcs ( α i,j > θ ) for which f ( i, j ) = 1 , and (2) the proportion of all possible pairs i, j for which f ( i, j ) = 1 . Note that the first proportion is exactly the metric p α ( f ) defined in Equation 1 (e.g. the proportion of attention aligned with contact maps). The second proportion is simply the background frequency of the property (e.g. the background frequency of contacts). Since we extract the maximum scores over all of the heads in the model, we treat this as a case of multiple hypothesis testing and apply the Bonferroni correction, with the number of hypotheses m equal to the number of attention heads.
|
| 297 |
+
|
| 298 |
+
As an additional check that the results did not occur by chance, we also report results on baseline (null) models. We initially considered using two forms of null models: (1) a model with randomly initialized weights. and (2) a model trained on randomly shuffled sequences. However, in both cases, none of the sequences in the dataset yielded attention weights greater than the attention threshold θ . This suggests that the mere existence of the high-confidence attention weights used in the analysis could not have occurred by chance, but it does not shed light on the particular analyses performed. Therefore, we implemented an alternative randomization scheme in which we randomly shuffle attention weights from the original models as a post-processing step. Specifically, we permute the sequence of attention weights from each token for every attention head. To illustrate, let's say that the original model produced attention weights of (0.3, 0.2, 0.1, 0.4, 0.0) from position i in protein sequence x from head h , where | x | = 5 . In the null model, the attention weights from position i in sequence x in head h would be a random permutation of those weights, e.g., (0.2, 0.0, 0.4, 0.3, 0.1). Note that these are still valid attention weights as they would sum to 1 (since the original weights would sum to 1 by definition). We report results using this form of baseline model.
|
| 299 |
+
|
| 300 |
+
## B.3 PROBING METHODOLOGY
|
| 301 |
+
|
| 302 |
+
Embedding probe. We probe the embedding vectors output from each layer using a linear probing classifier. For token-level probing tasks (binding sites, secondary structure) we feed each token's output vector directly to the classifier. For token-pair probing tasks (contact map) we construct a pairwise feature vector by concatenating the elementwise differences and products of the two tokens' output vectors, following the TAPE 4 implementation.
|
| 303 |
+
|
| 304 |
+
We use task-specific evaluation metrics for the probing classifier: for secondary structure prediction, we measure F1 score; for contact prediction, we measure precision@ L/ 5 , where L is the length of the protein sequence, following standard practice (Moult et al., 2018); for binding site prediction, we measure precision@ L/ 20 , since approximately one in twenty amino acids in each sequence is a binding site (4.8% in the dataset).
|
| 305 |
+
|
| 306 |
+
Attention probe. Just as the attention weight α i,j is defined for a pair of amino acids ( i, j ) , so is the contact property f ( i, j ) , which returns true if amino acids i and j are in contact. Treating the attention weight as a feature of a token-pair ( i, j ) , we can train a probing classifier that predicts the contact property based on this feature, thereby quantifying the attention mechanism's knowledge of that property. In our multi-head setting, we treat the attention weights across all heads in a given layer as a feature vector, and use a probing classifier to assess the knowledge of a given property in the attention weights across the entire layer. As with the embedding probe, we measure performance of the probing classifier using precision@ L/ 5 , where L is the length of the protein sequence, following standard practice for contact prediction.
|
| 307 |
+
|
| 308 |
+
[4 https://github.com/songlab-cal/tape](https://github.com/songlab-cal/tape)
|
| 309 |
+
|
| 310 |
+
## B.4 DATASETS
|
| 311 |
+
|
| 312 |
+
We used two protein sequence datasets from the TAPE repository for the analysis: the ProteinNet dataset (AlQuraishi, 2019; Fox et al., 2013; Berman et al., 2000; Moult et al., 2018) and the Secondary Structure dataset (Rao et al., 2019; Berman et al., 2000; Moult et al., 2018; Klausen et al., 2019). The former was used for analysis of amino acids and contact maps, and the latter was used for analysis of secondary structure. We additionally created a third dataset for binding site and post-translational modification (PTM) analysis from the Secondary Structure dataset, which was augmented with binding site and PTM annotations obtained from the Protein Data Bank's Web API. 5 We excluded any sequences for which annotations were not available. The resulting dataset sizes are shown in Table 2. For the analysis of attention, a random subset of 5000 sequences from the training split of each dataset was used, as the analysis was purely evaluative. For training and evaluating the diagnostic classifier, the full training and validation splits were used.
|
| 313 |
+
|
| 314 |
+
Table 2: Datasets used in analysis
|
| 315 |
+
|
| 316 |
+
| Dataset Train size Validation size ProteinNet 25299 224 Secondary Structure 8678 2170 Binding Sites / PTM 5734 1418 |
|
| 317 |
+
|----------------------------------------------------------------------------------------------------------------------------------|
|
| 318 |
+
|
| 319 |
+
## C ADDITIONAL RESULTS OF ATTENTION ANALYSIS
|
| 320 |
+
|
| 321 |
+
## C.1 SECONDARY STRUCTURE
|
| 322 |
+
|
| 323 |
+
Figure 8: Percentage of each head's attention that is focused on Helix secondary structure.
|
| 324 |
+
|
| 325 |
+
<!-- image -->
|
| 326 |
+
|
| 327 |
+
[5 http://www.rcsb.org/pdb/software/rest.do](http://www.rcsb.org/pdb/software/rest.do)
|
| 328 |
+
|
| 329 |
+
Figure 9: Percentage of each head's attention that is focused on Strand secondary structure.
|
| 330 |
+
|
| 331 |
+
<!-- image -->
|
| 332 |
+
|
| 333 |
+
Figure 10: Percentage of each head's attention that is focused on Turn/Bend secondary structure.
|
| 334 |
+
|
| 335 |
+
<!-- image -->
|
| 336 |
+
|
| 337 |
+
## C.2 CONTACT MAPS: STATISTICAL SIGNIFICANCE TESTS AND NULL MODELS
|
| 338 |
+
|
| 339 |
+
Figure 11: Top 10 heads (denoted by <layer>-<head> ) for each model based on the proportion of attention aligned with contact maps [95% conf. intervals]. The differences between the attention proportions and the background frequency of contacts (orange dashed line) are statistically significant ( p < 0 . 00001 ). Bonferroni correction applied for both confidence intervals and tests (see App. B.2).
|
| 340 |
+
|
| 341 |
+
<!-- image -->
|
| 342 |
+
|
| 343 |
+
Figure 12: Top-10 contact-aligned heads for null models. See Appendix B.2 for details.
|
| 344 |
+
|
| 345 |
+
<!-- image -->
|
| 346 |
+
|
| 347 |
+
## C.3 BINDING SITES: STATISTICAL SIGNIFICANCE TESTS AND NULL MODEL
|
| 348 |
+
|
| 349 |
+
Figure 13: Top 10 heads (denoted by <layer>-<head> ) for each model based on the proportion of attention focused on binding sites [95% conf. intervals]. Differences between attention proportions and the background frequency of binding sites (orange dashed line) are all statistically significant ( p < 0 . 00001 ). Bonferroni correction applied for both confidence intervals and tests (see App. B.2).
|
| 350 |
+
|
| 351 |
+
<!-- image -->
|
| 352 |
+
|
| 353 |
+
Figure 14: Top-10 heads most focused on binding sites for null models. See Appendix B.2 for details.
|
| 354 |
+
|
| 355 |
+
<!-- image -->
|
| 356 |
+
|
| 357 |
+
## C.4 POST-TRANSLATIONAL MODIFICATIONS (PTMS)
|
| 358 |
+
|
| 359 |
+
Figure 15: Percentage of each head's attention that is focused on post-translational modifications.
|
| 360 |
+
|
| 361 |
+
<!-- image -->
|
| 362 |
+
|
| 363 |
+
Figure 16: Top 10 heads (denoted by <layer>-<head> ) for each model based on the proportion of attention focused on PTM positions [95% conf. intervals]. The differences between the attention proportions and the background frequency of PTMs (orange dashed line) are statistically significant ( p < 0 . 00001 ). Bonferroni correction applied for both confidence intervals and tests (see App. B.2).
|
| 364 |
+
|
| 365 |
+
<!-- image -->
|
| 366 |
+
|
| 367 |
+
Figure 17: Top-10 heads most focused on PTMs for null models. See Appendix B.2 for details.
|
| 368 |
+
|
| 369 |
+
<!-- image -->
|
| 370 |
+
|
| 371 |
+
## C.5 AMINO ACIDS
|
| 372 |
+
|
| 373 |
+
Figure 18: Percentage of each head's attention that is focused on the given amino acid, averaged over a dataset (TapeBert).
|
| 374 |
+
|
| 375 |
+
<!-- image -->
|
| 376 |
+
|
| 377 |
+
Figure 19: Percentage of each head's attention that is focused on the given amino acid, averaged over a dataset (cont.)
|
| 378 |
+
|
| 379 |
+
<!-- image -->
|
| 380 |
+
|
| 381 |
+
Table 3: Amino acids and the corresponding maximally attentive heads in the standard and randomized versions of TapeBert. The differences between the attention percentages for TapeBert and the background frequencies of each amino acid are all statistically significant ( p < 0 . 00001 ) taking into account the Bonferroni correction. See Appendix B.2 for details. The bolded numbers represent the higher of the two values between the standard and random models. In all cases except for Glutamine, which was the amino acid with the lowest top attention proportion in the standard model (7.1), the standard TapeBert model has higher values than the randomized version.
|
| 382 |
+
|
| 383 |
+
| TapeBert TapeBert-Random Abbrev Code Name Background % Top Head Attn % Top Head Attn % Ala A Alanine 7.9 12-11 25.5 11-12 12.1 Arg R Arginine 5.2 12-8 63.2 12-7 8.4 Asn N Asparagine 4.3 8-2 44.8 8-2 6.7 Asp D Aspartic acid 5.8 12-6 79.9 5-4 10.7 Cys C Cysteine 1.3 11-6 83.2 11-6 9.3 Gln Q Glutamine 3.8 11-7 7.1 12-1 9.2 Glu E Glutamic acid 6.9 11-7 16.2 11-4 11.8 Gly G Glycine 7.1 2-11 98.1 11-8 14.6 His H Histidine 2.7 9-10 56.7 11-6 5.4 Ile I Isoleucine 5.6 11-10 27.0 9-5 10.6 Leu L Leucine 9.4 2-12 44.1 12-11 13.9 Lys K Lysine 6.0 12-8 29.4 6-11 12.9 Met M Methionine 2.3 3-10 73.5 9-3 6.2 Phe F Phenylalanine 3.9 12-3 22.7 12-1 6.7 Pro P Proline 4.6 1-11 98.3 10-6 7.6 Ser S Serine 6.4 12-7 36.1 11-12 11.0 Thr T Threonine 5.4 12-7 19.0 10-4 9.0 Trp W Tryptophan 1.3 11-4 68.1 9-2 3.0 Tyr Y Tyrosine 3.4 12-3 51.6 12-11 6.6 Val V Valine 6.8 12-11 34.0 8-2 15.0 |
|
| 384 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
text-versions/attention-markdown/2007.04639_Attention Neural Network for Trash Detec.md
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2007.04639 Attention Neural Network For Trash Detec
|
| 2 |
+
|
| 3 |
+
## ATTENTION NEURAL NETWORK FOR TRASH DETECTION ON WATER CHANNELS
|
| 4 |
+
|
| 5 |
+
Mohbat Tharani, Abdul Wahab Amin, Mohammad Maaz and Murtaza Taj
|
| 6 |
+
|
| 7 |
+
Computer Vision and Graphics Lab, School of Science and Engineering, Lahore University of Management Sciences, Lahore, Pakistan
|
| 8 |
+
|
| 9 |
+
## ABSTRACT
|
| 10 |
+
|
| 11 |
+
Rivers and canals flowing through cities are often used illegally for dumping trash. This contaminates fresh water channels as well as causes blockage in sewerage resulting urban flooding. When this contaminated water reaches agricultural fields, it results in degradation of soil and poses critical environmental as well as economic threats. The dumped trash is often found floating on the water surface. The trash could be disfigured, partially submerged, decomposed into smaller pieces, clumped together with other objects which obscures its shape and creates a challenging detection problem. This paper proposes a method for detection of visible trash floating on the water surface of the canals in urban areas. We also provide a large dataset, first of its kind, trash in water channels that contains object level annotations. A novel attention layer is proposed that improves the detection of smaller objects. Towards the end of this paper, we provide a detailed comparison of our method with state-of-the-art object detectors and show that our method significantly improves the detection of smaller objects. The dataset will be made publicly available.
|
| 12 |
+
|
| 13 |
+
Index Terms -Object Detection, Smaller Objects, Attention, Water Quality, Urban Trash
|
| 14 |
+
|
| 15 |
+
## 1. INTRODUCTION
|
| 16 |
+
|
| 17 |
+
Every year millions of tons of trash, especially plastic, is discarded globally which pollutes our lands, rivers, and oceans. This causes environmental as well as economic repercussions. In developing countries, 90% of sewerage and 70% of the industrial waste is discharged in local water channels without treatment [1] which contaminates water and adds toxins to our food chain. According to the United Nations world water development report [2], annually about 3 . 5 million people, mostly children, die from water-related infections.
|
| 18 |
+
|
| 19 |
+
To cater to this issue of water pollution, the first step is to identify the main elements present in water. Trash is one of the major contributors which is dumped in drainage and fresh water channels of urban areas, from where it finally reaches the rivers. This trash consists of soluble and insoluble trash such as papers, card-boards, food residuals, plastic bottles and bags, etc. These trash elements upon reaching agricultural fields degrade the soil, reduce fertility and harm crops. To measure the amount of trash in canals as an index of water contamination, the detection of visual floating trash is a key step. The detected trash would then be quantified to notify planning authorities to take appropriate actions.
|
| 20 |
+
|
| 21 |
+
This work was supported by Higher Education Commission, Pakistan under funding of National Agricultural Robotics Lab.
|
| 22 |
+
|
| 23 |
+
Fig. 1 : Sample camera views from the collected dataset. The variation in views, shadows of overpass bridge, reflection of buildings and presence of vegetation is clear in these images.
|
| 24 |
+
|
| 25 |
+
<!-- image -->
|
| 26 |
+
|
| 27 |
+
The existing work on vision-based approaches for detection of trash could be divided into three categories i) Classification of trash in a controlled environment, applicable at waste recycling plants [3, 4]. ii) Detection of piles of trash, usually illegally dumped in cities [5, 6]. iii) Detection of sparse trash could be street trash or marine litter [7, 8, 9, 10]. In this paper, we introduce a fourth category of detecting visual trash floating on the water channels, especially drainage canals. Different from the above discussed studies, our problem focuses on surface trash present in canals running through dense urban areas.
|
| 28 |
+
|
| 29 |
+
Most of the recent work on trash detection employ deep learning based object detectors including SSD [11], YOLO [12], and Faster RCNN [13]. These well knowm object detectors [11, 12, 13, 14, 15] are designed for general applications, especially for urban scenarios such as those related to surveillance and self driving cars. These networks do perform better on relevant benchmark datasets such as MS-COCO [16] and Pascal-VOC [17]. However, detecting trash over water channels is a more challenging problem due to the changes in object shape with flow of water and broad spectrum of object sizes. To overcome the issue of variation in object sizes, various efforts have been done such as image pyramids [18], feature fusion networks [19, 20], Thinned U-shape Modules(TUM) [21], and attention mechanism [22, 23].
|
| 30 |
+
|
| 31 |
+
Fig. 2 : Sample cropped images showing wide-variety of challenging scenarios present in the fresh water and drainage canals.
|
| 32 |
+
|
| 33 |
+
<!-- image -->
|
| 34 |
+
|
| 35 |
+
This paper introduces a new category of trash detection, provides a manually collected and annotated trash images dataset, and proposes a novel attention layer that implicitly focuses on smaller objects. Through experiment, we demonstrate that our proposed attention layer improves the detection of small trash particles missed by state-of-the-art object detectors [11, 12, 15].
|
| 36 |
+
|
| 37 |
+
## 2. DATASET
|
| 38 |
+
|
| 39 |
+
## 2.1. Collection
|
| 40 |
+
|
| 41 |
+
Although, the problem of ocean trash has received significant attention in the recent years, however, to the best of our knowledge the problem of trash in fresh and waste water ways has not been addressed in the past. Consequently, there is no any existing dataset available on this problem. Thus, in this work, we contribute first of its kind image dataset. The videos for dataset were collected during different day times, weather conditions, and localities to ensure the recorded data contain a myriad of objects of interest. We surveyed many sites near commercial areas, slum neighbourhoods and industrial areas of the city and selected five critical sites. We recorded 30
|
| 42 |
+
|
| 43 |
+
Table 1 : Distribution of objects in annotated images when divided into small, medium and large categories.
|
| 44 |
+
|
| 45 |
+
| Size No. of Objects Area / px 2 Small 11090 area ≤ 32 2 Medium 33116 32 2 < area ≤ 96 2 Large 4692 area > 96 2 |
|
| 46 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 47 |
+
|
| 48 |
+
different videos of upto 60 minutes each. Some of the example images from our dataset are shown in Fig. 1. These images contains several challenging scenarios which are discussed next.
|
| 49 |
+
|
| 50 |
+
## 2.2. Challenges in dataset
|
| 51 |
+
|
| 52 |
+
Objects in the water are often deformed (see Fig. 2(a)), have no defined geometrical shape and their shapes also change over time. For example, floating plastic bags may distort to a multitude of shapes that vary with time. Due to water flow, not only objects are submerged (Fig. 2(b)) but also sometimes sink in water and then resurface later. Sometimes sewer gases are produced through the decomposition of organic household products or industrial waste as shown in Fig. 2(c), and they show resemblance to surface trash. As shown in Fig. 2(d)(f), the trash may be present as sparsely distributed objects or dense piles of trash on the water surface.
|
| 53 |
+
|
| 54 |
+
Since the dataset was collected from dense urban areas, the reflections and shadows of static (buildings and electricity poles, and moving (flying birds) objects (see Fig. 2 (g)-(i)) appear significantly in these water channel. Depending upon the camera view point and time of the day, they may cover a significant portion of the water surface. The color and opacity of water varies from channel to channel depending on the amount of chemical discharge from factories and sewerage, eventually changing the reflection and refraction of sunlight. These cases are not found in ocean environment and increases the complexity of our problem.
|
| 55 |
+
|
| 56 |
+
## 2.3. Annotation
|
| 57 |
+
|
| 58 |
+
Annotations were done by four different individuals under the supervision of a domain expert. A total of 13500 images were selected from the collected videos at a regular interval and annotated for bounding box in VOC format [17]. LabelImg 1 was used to annotate the images for bounding boxes. A total of 48898 objects were annotated in 13500 images ranging from almost 256 to 300 , 000 px 2 in area. From this dataset 12500 images were considered as the train-validation set and the remaining 1000 test images were divided into easy and hard test sets containing 500 images each. Images in Easy Test Set have different weather conditions and water texture and some videos were collected during rainy weather (No examples of rainy day in training set) whereas Hard Test Set contains a variety of view points, different weather conditions, water color and gas bubbles coming out of water.
|
| 59 |
+
|
| 60 |
+
1 https://github.com/tzutalin/labelImg
|
| 61 |
+
|
| 62 |
+
Fig. 3 : Attention Layer multiplies output of a convolutional layer with its log activation.
|
| 63 |
+
|
| 64 |
+
<!-- image -->
|
| 65 |
+
|
| 66 |
+
We intentionally do not annotate micro-particles, leaves, twigs, non-floating trash and air bubbles. Minuscule microparticles affect the texture of the water surface, so instead of object detection, they can be quantified using texture analysis and hence were omitted from our study. Moreover, we also did not annotate objects which were less than 7 pixels in both width and height. To get the distribution of annotated objects in terms of size, following MS-COCO standard they were grouped into three categories i.e. small with area less than 32 2 px 2 , medium with area between 32 2 to 96 2 px 2 and large otherwise. Table 1 shows that the more than 90% of objects are either small or medium size.
|
| 67 |
+
|
| 68 |
+
## 3. PROPOSED METHOD
|
| 69 |
+
|
| 70 |
+
We trained some of the popular object detectors such as SSD [11] and YOLO-v3-Tiny whereas YOLO-v3 [14] and PeeleNet [15]. We observed that these models have encouraging results on our dataset as given in Table 2. Further analysis (see Table 3) indicates that the performing models shown unsatisfactory outcome on tiny objects. The feature extractors used in these object detectors merge features from multiple scales to detect objects of variable sizes. Despite this, they still fail to identify smaller objects present in our novel case of visual trash detection. To resolve this problem, an attention layer can be employed to enforce the algorithm to focus on smaller objects.
|
| 71 |
+
|
| 72 |
+
Conventionally, attention layer employ Sigmoid or Softmax to predict the probability of objectness in features, which are then merged together to highlight a certain area in the feature space. Attention based on Sigmoid and Softmax activation functions seems to perform well for segmenting the pixels near boundaries of the objects []. Nevertheless, in our study, we require an activation function that implicitly focuses on smaller objects in an image. Logarithm scale is used to overcome the skewness in the data i.e. if few values are very large or very small than rest of the data, then logarithm would transform this wide-range into a smaller one. Thus, it reduces the variance in the features and scales up smaller values. This motivates us to utilize log based attention layer to emphasize on smaller objects. We employed log attention layer as given in Fig. 3 on multi-resolution features. Mathematically, we define our attention layer as:
|
| 73 |
+
|
| 74 |
+
Fig. 4 : Proposed model: Left side backbone network is modified to introduce attention layer while the right side is the detector.
|
| 75 |
+
|
| 76 |
+
<!-- image -->
|
| 77 |
+
|
| 78 |
+
<!-- formula-not-decoded -->
|
| 79 |
+
|
| 80 |
+
where f i is output of i th layer, and i = 0 , ..., N and N is number of layers. Here, ReLU discards the negative values in the activations and bias 1 shifts it one scale up, making it possible to compute log . The derivative of this attention layer would be:
|
| 81 |
+
|
| 82 |
+
<!-- formula-not-decoded -->
|
| 83 |
+
|
| 84 |
+
Fig. 5 : Visualization of layer activation: Effects of log attention layer on features learned by YOLO-v3 same convolutional layer. (a)Input Image (b) Vanilla YOLO-v3 (c) Log attention.
|
| 85 |
+
|
| 86 |
+
<!-- image -->
|
| 87 |
+
|
| 88 |
+
The log attention introduces numerical stability by responding to unevenness in the features due to large variations in object size. Object detector contains a backbone network that learns deep features, some optional convolutional layers applied on features learned by backbone and final prediction layers. Since, the backbone network learns the features required by the detector, so amplification of smaller activation values in backbone network would eventually drive the performance of detector. Therefore, we applied our attention layer on the features consumed by the detector as shown in Fig. 4. Updated features were forwarded to preceding layer of the backbone network to improve features progressively as evident in Fig. 5, where activation show clear improvement learning features for objects.
|
| 89 |
+
|
| 90 |
+
Table 2 : Comparative evaluation of the state-of-the-art object detection techniques. (Key: AP: Average Precision, IoU: Intersection over Union).
|
| 91 |
+
|
| 92 |
+
| Model Easy Test SetHard Test Set AP IoU AP IoU SSD [11] 24.1 64.0 26.3 72.0 YOLO-v3-Tiny 5.6 69.2 11.6 66.9 YOLO-v3 [12] 43.8 64.5 31.5 68.5 RetinaNet [20] 45.6 73.7 41.0 74.0 RetinaNet-resnet50 49.9 - 48.5 - PeleeNet [15] 40.7 67.1 24.2 72.1 YOLO-v3+Attn 48.1 64.5 31.2 69.4 PeleeNet+Attn 41.4 66.4 23.5 72.7 RetinaNet+Attm 51.8 73.7 43.9 73.9 RetinaNet-resnet50+Attn52.6 - 43.9 - |
|
| 93 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 94 |
+
|
| 95 |
+
## 4. RESULTS AND EVALUATION
|
| 96 |
+
|
| 97 |
+
We compare the performance of our model with state-ofthe-art models such as SSD, YOLO-v3, YOLO-v3-Tiny, PeeleNet. Since there is no existing dataset on the problem of trash on water surface, so these methods were evaluated on the dataset introduced in this paper (Section 2). In order to validate the performance of the trained network, we used two standard benchmark performance metrics namely average precision (AP) and Intersection over Union (IoU) as used by MS-COCO [16].
|
| 98 |
+
|
| 99 |
+
## 4.1. Training
|
| 100 |
+
|
| 101 |
+
All the networks were trained using their default hyperparameters and APIs. All the models were initialized with pre-trained weights trained on Pascal VOC [17]. The 12500 images of the dataset were randomly split into 80 -20% and these splits were fixed for all the models. We used 80% of them for training, 20% for validation during training. The test set was made from the images of site other than the trainvalidation sites. It contains a total of 1000 images which were sub-divided into two sets i.e Easy and Hard Test Set, containing 500 images each.
|
| 102 |
+
|
| 103 |
+
## 4.2. Quantitative Results
|
| 104 |
+
|
| 105 |
+
The quantitative evaluation of the object detection algorithms on two sets (easy and hard) is shown in Table 2. Our proposed attention layer with YOLO-v3 outperforms all the other models on the Easy Test Set whereas it approximately gives the same performance on the Hard Test Set. SSD and YOLO-v3Tiny fail to learn and given poor average precision for both test sets.
|
| 106 |
+
|
| 107 |
+
Table 3 : Comparative analysis of average precision (AP) scores of the state-of-the-art object detection techniques on three different object size categories namely small(S), medium(M) and large(L) indicated by superscript.
|
| 108 |
+
|
| 109 |
+
| Model Easy Test Set Hard Test Set AP S AP M AP L AP S AP M AP L SSD [11] 1.6 7.8 38.1 0.8 10.2 31.3 YOLO-v3-Tiny 0.0 1.9 36.7 0.6 3.1 12.4 YOLO-v3 [12] 4.5 16.3 52.0 1.3 9.9 32.2 RetinaNet [20] 5.0 28.6 71.8 4.0 19.5 38.9 RetinaNet-resnet50 3.7 36.4 67.6 5.0 24.5 40.5 PeleeNet [15] 5.5 15.3 50.3 1.9 9.4 28.1 YOLO-v3+Attn 5.4 16.3 51.6 1.3 10.0 31.8 PeleeNet+Attn 6.2 15.1 46.6 9.0 8.7 30.1 RetinaNet+Attn 6.3 35.8 75.5 4.1 22.2 41.5 |
|
| 110 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 111 |
+
|
| 112 |
+
All models have comparable IoU but in terms of average precision (AP), YOLO-v3 with our attention layer outperforms all other models on the Easy Test Set with an AP score of 48 . 1% whereas it closely coincides with the Vanilla YOLO-v3 on the Hard Test Set. YOLO-v3-Tiny has the lowest AP score of 11 . 6% .
|
| 113 |
+
|
| 114 |
+
## 4.3. Analysis on object sizes
|
| 115 |
+
|
| 116 |
+
In order to find out the performance dependency on object sizes, the trained networks were evaluated on three scales of objects given in Table 1. Table 3 demonstrates that the performance of all the networks on smaller objects is poorer than medium and large objects. Even though large objects are only 4692 , which is half of the number of smaller objects, networks were still able to detect them. This is due to prior training of models for object detection task on Pascal VOC dataset, so the information of 'objectness' was retained for large objects. YOLO-v3 with attention has better AP on large and medium object on the Easy Test Set and performs better on large objects on the Hard Test Set . PeeleNet with attention closely coincides with YOLO-v3 with attention for all object sizes.
|
| 117 |
+
|
| 118 |
+
## 5. CONCLUSION
|
| 119 |
+
|
| 120 |
+
This paper presents a new category of visual trash detection through deep learning based object detectors. A dataset of trash floating on canal surface in dense urban areas is collected and annotated. Then, several recent and popular deep object detection models were trained and evaluated. Finally, we proposed a novel log based attention layer that has improved the performance particularly on small objects. Overall, the detection of floating trash specially in water channels in urban areas is a challenging task and an emerging area of research. The dataset provided in this work will serve as a stepping stone towards finding a solution to this problem.
|
| 121 |
+
|
| 122 |
+
## 6. REFERENCES
|
| 123 |
+
|
| 124 |
+
- [1] C. Liyanage and K. Yamada, 'Impact of population growth on the water quality of natural water bodies,' Sustainability , vol. 9, no. 8, p. 1405, 2017.
|
| 125 |
+
- [2] K. Engin, M. Tran, R. Connor, and S. Uhlenbrook, 'The united nations world water development report 2018: nature-based solutions for water; facts and figures,' UNESCO , 2018.
|
| 126 |
+
- [3] G. E. Sakr, M. Mokbel, A. Darwich, M. N. Khneisser, and A. Hadi, 'Comparing deep learning and support vector machines for autonomous waste sorting,' in IEEE International Multidisciplinary Conference on Engineering Technology , 2016.
|
| 127 |
+
- [4] S. Sudha, M. Vidhyalakshmi, K. Pavithra et al. , 'An automatic classification method for environment,' IEEE Technological Innovations in ICT for Agriculture and Rural Development , 2016.
|
| 128 |
+
- [5] G. Mittal, K. B. Yagnik, M. Garg, and N. C. Krishnan, 'Spotgarbage: smartphone app to detect garbage using deep learning,' in ACM International Joint Conference on Pervasive and Ubiquitous Computing , 2016, pp. 940-945.
|
| 129 |
+
- [6] M. S. Rad, A. von Kaenel, A. Droux, F. Tieche, N. Ouerhani, H. K. Ekenel, and J.-P. Thiran, 'A computer vision system to localize and classify wastes on the streets,' in Lecture Notes in Computer Science . Springer International Publishing, 2017, pp. 195-204.
|
| 130 |
+
- [7] M. Fulton, J. Hong, M. J. Islam, and J. Sattar, 'Robotic detection of marine litter using deep visual detection models,' arXiv preprint arXiv:1804.01079 , 2018.
|
| 131 |
+
- [8] Z. Ge, H. Shi, X. Mei, Z. Dai, and D. Li, 'Semiautomatic recognition of marine debris on beaches,' Scientific Reports , vol. 6, p. 25759, 2016.
|
| 132 |
+
- [9] M. Valdenegro-Toro, 'Submerged marine debris detection with autonomous underwater vehicles,' in IEEE International Conference on Robotics and Automation for Humanitarian Applications , 2016, pp. 1-7.
|
| 133 |
+
- [10] Y. Liu, Z. Ge, G. Lv, and S. Wang, 'Research on automatic garbage detection system based on deep learning and narrowband internet of things,' in Journal of
|
| 134 |
+
|
| 135 |
+
Physics: Conference Series , vol. 1069, no. 1. IOP Publishing, 2018, p. 012032.
|
| 136 |
+
|
| 137 |
+
- [11] W. Liu, D. Anguelov, D. Erhan, C. Szegedy, S. Reed, C.-Y. Fu, and A. C. Berg, 'Ssd: Single shot multibox detector,' in European conference on computer vision . Springer, 2016, pp. 21-37.
|
| 138 |
+
- [12] J. Redmon and A. Farhadi, 'Yolov3: An incremental improvement,' arXiv preprint arXiv:1804.02767 , 2018.
|
| 139 |
+
- [13] S. Ren, K. He, R. Girshick, and J. Sun, 'Faster r-cnn: Towards real-time object detection with region proposal networks,' in Advances in neural information processing systems , 2015, pp. 91-99.
|
| 140 |
+
- [14] J. Redmon, S. Divvala, R. Girshick, and A. Farhadi, 'You only look once: Unified, real-time object detection,' in IEEE Conference on Computer Vision and Pattern Recognition , 2016, pp. 779-788.
|
| 141 |
+
- [15] R. J. Wang, X. Li, and C. X. Ling, 'Pelee: A real-time object detection system on mobile devices,' in Advances in Neural Information Processing Systems , 2018, pp. 1963-1972.
|
| 142 |
+
- [16] X. Chen, H. Fang, T.-Y. Lin, R. Vedantam, S. Gupta, P. Doll´ ar, and C. L. Zitnick, 'Microsoft coco captions: Data collection and evaluation server,' arXiv preprint arXiv:1504.00325 , 2015.
|
| 143 |
+
- [17] M. Everingham, L. Van Gool, C. K. Williams, J. Winn, and A. Zisserman, 'The pascal visual object classes (voc) challenge,' International journal of computer vision , vol. 88, no. 2, pp. 303-338, 2010.
|
| 144 |
+
- [18] Y. Pang, T. Wang, R. M. Anwer, F. S. Khan, and L. Shao, 'Efficient featurized image pyramid network for single shot detector,' in IEEE/CVF Conference on Computer Vision and Pattern Recognition , 2019.
|
| 145 |
+
- [19] T.-Y. Lin, P. Dollar, R. Girshick, K. He, B. Hariharan, and S. Belongie, 'Feature pyramid networks for object detection,' in IEEE Conference on Computer Vision and Pattern Recognition , 2017.
|
| 146 |
+
- [20] T.-Y. Lin, P. Goyal, R. Girshick, K. He, and P. Dollar, 'Focal loss for dense object detection,' in IEEE International Conference on Computer Vision (ICCV) , Oct 2017.
|
| 147 |
+
- [21] Q. Zhao, T. Sheng, Y. Wang, Z. Tang, Y. Chen, L. Cai, and H. Lin, 'M2det: A single-shot object detector based on multi-level feature pyramid network,' in AAAI Conference on Artificial Intelligence , 2019.
|
| 148 |
+
- [22] I. Bello, B. Zoph, Q. Le, A. Vaswani, and J. Shlens, 'Attention augmented convolutional networks,' in 2019
|
| 149 |
+
|
| 150 |
+
IEEE/CVF International Conference on Computer Vision (ICCV) . IEEE, oct 2019. [Online]. Available: https://doi.org/10.11092Ficcv.2019.00338
|
| 151 |
+
|
| 152 |
+
- [23] A. Vaswani, N. Shazeer, N. Parmar, J. Uszkoreit, L. Jones, A. N. Gomez, Ł. Kaiser, and I. Polosukhin, 'Attention is all you need,' in Advances in neural Information Processing Systems , 2017, pp. 5998-6008.
|
text-versions/attention-markdown/2007.08442_Kronecker Attention Networks.md
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2007.08442 Kronecker Attention Networks
|
| 2 |
+
|
| 3 |
+
## Kronecker Attention Networks
|
| 4 |
+
|
| 5 |
+
Hongyang Gao Texas A&M University College Station, TX hongyang.gao@tamu.edu
|
| 6 |
+
|
| 7 |
+
## ABSTRACT
|
| 8 |
+
|
| 9 |
+
Attention operators have been applied on both 1-D data like texts and higher-order data such as images and videos. Use of attention operators on high-order data requires flattening of the spatial or spatial-temporal dimensions into a vector, which is assumed to follow a multivariate normal distribution. This not only incurs excessive requirements on computational resources, but also fails to preserve structures in data. In this work, we propose to avoid flattening by assuming the data follow matrix-variate normal distributions. Based on this new view, we develop Kronecker attention operators (KAOs) that operate on high-order tensor data directly. More importantly, the proposed KAOs lead to dramatic reductions in computational resources. Experimental results show that our methods reduce the amount of required computational resources by a factor of hundreds, with larger factors for higher-dimensional and higher-order data. Results also show that networks with KAOs outperform models without attention, while achieving competitive performance as those with original attention operators.
|
| 10 |
+
|
| 11 |
+
## CCS CONCEPTS
|
| 12 |
+
|
| 13 |
+
· Computing methodologies → Artificial intelligence; Machine learning algorithms ; Neural networks .
|
| 14 |
+
|
| 15 |
+
## KEYWORDS
|
| 16 |
+
|
| 17 |
+
Attention, neural networks, Kronecker attention, image classification, image segmentation
|
| 18 |
+
|
| 19 |
+
## ACMReference Format:
|
| 20 |
+
|
| 21 |
+
Hongyang Gao, Zhengyang Wang, and Shuiwang Ji. 2020. Kronecker Attention Networks. In Proceedings of the 26th ACM SIGKDD Conference on Knowledge Discovery and Data Mining USB Stick (KDD '20), August 2327, 2020, Virtual Event, USA. ACM, New York, NY, USA, 9 pages. https: //doi.org/10.1145/3394486.3403065
|
| 22 |
+
|
| 23 |
+
## 1 INTRODUCTION
|
| 24 |
+
|
| 25 |
+
Deep neural networks with attention operators have shown great capability of solving challenging tasks in various fields, such as natural language processing [3, 19, 33], computer vision [26, 38], and network embedding [9, 34]. Attention operators are able to capture long-range dependencies, resulting in significant performance boost [23, 27]. While attention operators were originally proposed
|
| 26 |
+
|
| 27 |
+
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from permissions@acm.org.
|
| 28 |
+
|
| 29 |
+
KDD '20, August 23-27, 2020, Virtual Event, USA
|
| 30 |
+
|
| 31 |
+
© 2020 Association for Computing Machinery.
|
| 32 |
+
|
| 33 |
+
ACM ISBN 978-1-4503-7998-4/20/08...$15.00
|
| 34 |
+
|
| 35 |
+
[https://doi.org/10.1145/3394486.3403065](https://doi.org/10.1145/3394486.3403065)
|
| 36 |
+
|
| 37 |
+
Zhengyang Wang Texas A&M University College Station, TX zhengyang.wang@tamu.edu Shuiwang Ji Texas A&M University College Station, TX sji@tamu.edu
|
| 38 |
+
|
| 39 |
+
for 1-D data, recent studies [7, 35, 40] have attempted to apply them on high-order data, such as images and videos. However, a practical challenge of using attention operators on high-order data is the excessive requirement computational resources, including computational cost and memory usage. For example, for 2-D image tasks, the time and space complexities are both quadratic to the product of the height and width of the input feature maps. This bottleneck becomes increasingly severe as the spatial or spatialtemporal dimensions and the order of input data increase. Prior methods address this problem by either down-sampling data before attention operators [35] or limiting the path of attention [16].
|
| 40 |
+
|
| 41 |
+
In this work, we propose novel and efficient attention operators, known as Kronecker attention operators (KAOs), for highorder data. We investigate the above problem from a probabilistic perspective. Specifically, regular attention operators flatten the data and assume the flattened data follow multivariate normal distributions. This assumption not only results in high computational cost and memory usage, but also fails to preserve the spatial or spatial-temporal structures of data. We instead propose to use matrix-variate normal distributions to model the data, where the Kronecker covariance structure is able to capture relationships among spatial or spatial-temporal dimensions. Based on this new view, we propose our KAOs, which avoid flattening and operate on high-order data directly. Experimental results show that KAOs are as effective as original attention operators, while dramatically reducing the amount of required computational resources. In particular, we employ KAOs to design a family of efficient modules, leading to our compact deep models known as Kronecker attention networks (KANets). KANets significantly outperform prior compact models on the image classification task, with fewer parameters and less computational cost. Additionally, we perform experiments on image segmentation tasks to demonstrate the effectiveness of our methods in general application scenarios.
|
| 42 |
+
|
| 43 |
+
## 2 BACKGROUND AND RELATED WORK
|
| 44 |
+
|
| 45 |
+
In this section, we describe the attention and related non-local operators, which have been applied on various types of data such as texts, images and videos.
|
| 46 |
+
|
| 47 |
+
## 2.1 Attention Operator
|
| 48 |
+
|
| 49 |
+
The inputs to an attention operator include a query matrix Q = [ q 1 , q 2 , ⋯ , q m ] ∈ R d × m with each q i ∈ R d , a key matrix K = [ k 1 , k 2 , ⋯ , k n ] ∈ R d × n with each k i ∈ R d , and a value matrix V = [ v 1 , v 2 , ⋯ , v n ] ∈ R p × n with each v i ∈ R p . The attention operation computes the responses of a query vector q i by attending it to all key vectors in K and uses the results to take a weighted sum over value vectors in V . The layer-wise forward-propagation operation of an attention operator can be expressed as
|
| 50 |
+
|
| 51 |
+
Figure 1: An illustration of the attention operator. Here, × denotes matrix multiplication, and softmax( ⋅ ) is the columnwise softmax operator. Q , K , and V are input matrices. A similarity score is computed between each query vector as a column of Q and each key vector as a column in K . Softmax( ⋅ ) normalizes these scores and makes them sum to 1. Multiplication between normalized scores and the matrix V yields the corresponding output vector.
|
| 52 |
+
|
| 53 |
+
<!-- image -->
|
| 54 |
+
|
| 55 |
+
<!-- formula-not-decoded -->
|
| 56 |
+
|
| 57 |
+
Matrix multiplication between K T and Q results in a coefficient matrix E = K T Q , in which each element e i j is calculated by the inner product between k T i and q j . This coefficient matrix E computes similarity scores between every query vector q i , and every key vector k j and is normalized by a column-wise softmax operator to make every column sum to 1. The output O ∈ R p × m is obtained by multiplying V with the normalized E . In self-attention operators [33], we have Q = K = V . Figure 1 provides an illustration of the attention operator. The computational cost in Eq. 1 is O ( m × n ×( d + p )) . The memory required for storing the intermediate coefficient matrix E is O ( mn ) . If d = p and m = n , the time and space complexities become O ( m 2 × d ) and O ( m 2 ) , respectively.
|
| 58 |
+
|
| 59 |
+
There are several other ways to compute E from Q and K , including Gaussian function, dot product, concatenation, and embedded Gaussian function. It has been shown that dot product is the simplest but most effective one [35]. Therefore, we focus on the dot product similarity function in this work.
|
| 60 |
+
|
| 61 |
+
In practice, we can first perform separate linear transformations on each input matrix, resulting in the following attention operator: O = W V V Softmax (( W K K ) T W Q Q ) , where W V ∈ R p ′ × p , W K ∈ R d ′ × d , and W Q ∈ R d ′ × d . For notational simplicity, we omit linear transformations in the following discussion.
|
| 62 |
+
|
| 63 |
+
## 2.2 Non-Local Operator
|
| 64 |
+
|
| 65 |
+
Non-local operators, which is proposed in [35], apply self-attention operators on higher-order data such as images and videos. Taking 2-D data as an example, the input to the non-local operator is a third-order tensor X ∈ R h × w × c , where h , w , and c denote the height, width, and number of channels, respectively. The tensor is first converted into a matrix X ( 3 ) ∈ R c × hw by unfolding along mode3 [21], as illustrated in Figure 2. Then we perform the operation in Eq. 1 by setting Q = K = V = X ( 3 ) . The output of the attention operator is converted back to a third-order tensor as the final output.
|
| 66 |
+
|
| 67 |
+
Figure 2: Conversion of a third-order tensor into a matrix by unfolding along mode-3. In this example, a h × w × c tensor is unfolded into a c × hw matrix.
|
| 68 |
+
|
| 69 |
+
<!-- image -->
|
| 70 |
+
|
| 71 |
+
One practical challenge of the non-local operator is that it consumes excessive computational resources. If h = w , the computational cost of a 2-D non-local operator is O ( h 4 × c ) . The memory used to store the intermediate coefficient matrix incurs O ( h 4 ) space complexity. The time and space complexities are prohibitively high for high-dimensional and high-order data.
|
| 72 |
+
|
| 73 |
+
## 3 KRONECKER ATTENTION NETWORKS
|
| 74 |
+
|
| 75 |
+
In this section, we describe our proposed Kronecker attention operators, which are efficient and effective attention operators on high-order data. We also describe how to use these operators to build Kronecker attention networks.
|
| 76 |
+
|
| 77 |
+
## 3.1 From Multivariate to Matrix-Variate Distributions
|
| 78 |
+
|
| 79 |
+
We analyze the problem of attention operators on high-order data and propose solutions from a probabilistic perspective. To illustrate the idea, we take the non-local operator on 2-D data in Section 2.2 as an example. Formally, consider a self-attention operator with Q = K = V = X ( 3 ) , where X ( 3 ) ∈ R c × hw is the mode-3 unfolding of a third-order input tensor X ∈ R h × w × c , as illustrated in Figure 2. The i th row of X ( 3 ) corresponds to vec ( X ∶∶ i ) T ∈ R 1 × hw , where X ∶∶ i ∈ R h × w denotes the i th frontal slice of X [21], and vec (⋅) denotes the vectorization of a matrix by concatenating its columns [12].
|
| 80 |
+
|
| 81 |
+
The frontal slices X ∶∶ 1 , X ∶∶ 2 , . . . , X ∶∶ c ∈ R h × w of X are usually known as c feature maps. In this view, the mode-3 unfolding is equivalent to the vectorization of each feature map independently. It is worth noting that, in addition to vec (⋅) , any other operation that transforms each feature map into a vector leads to the same output from the non-local operator, as long as a corresponding reverse operation is performed to fold the output into a tensor. This fact indicates that unfolding of X in local operators ignores the structural information within each feature map, i.e., the relationships among rows and columns. In addition, such unfolding results in excessive requirements on computational resources, as explained in Section 2.2.
|
| 82 |
+
|
| 83 |
+
In the following discussions, we focus on one feature map X ∈ { X ∶∶ 1 , X ∶∶ 2 , . . . , X ∶∶ c } by assuming feature maps are conditionally independent of each other, given feature maps of previous layers. This assumption is shared by many deep learning techniques that process each feature map independently, including the unfolding mentioned above, batch normalization [18], instance normalization [31], and pooling operations [22]. To view the problem above from a probabilistic perspective [18, 31], the unfolding yields the assumption that vec ( X ) follows a multivariate normal distribution as vec ( X ) ∼ N hw ( µ , Ω ) , where µ ∈ R hw and Ω ∈ R hw × hw . Apparently, the multivariate normal distribution does not model relationships among rows and columns in X . To address this limitation, we propose to model X using a matrix-variate normal distribution [12], defined as below.
|
| 84 |
+
|
| 85 |
+
Definition 1. A random matrix A ∈ R m × n is said to follow a matrix-variate normal distribution MN m × n ( M , Ω ⊗ Ψ ) with mean matrix M ∈ R m × n and covariance matrix Ω ⊗ Ψ , where Ω ∈ R m × m ≻ 0 and Ψ ∈ R n × n ≻ 0, if vec ( A T ) ∼ N mn ( vec ( M T ) , Ω ⊗ Ψ ) . Here, ⊗ denotes the Kronecker product [11, 32].
|
| 86 |
+
|
| 87 |
+
The matrix-variate normal distribution has separate covariance matrices for rows and columns. They interact through the Kronecker product to produce the covariance matrix for the original distribution. Specifically, for two elements X i j and X i ′ j ′ from different rows and columns in X , the relationship between X i j and X i ′ j ′ is modeled by the interactions between the i th and i ′ th rows and the j th and j ′ th columns. Therefore, the matrix-variate normal distribution is able to incorporate relationships among rows and columns.
|
| 88 |
+
|
| 89 |
+
## 3.2 The Proposed Mean and Covariance Structures
|
| 90 |
+
|
| 91 |
+
In machine learning, Kalaitzis et al. [20] proposed to use the Kronecker sum to form covariance matrices, instead of the Kronecker product. Based on the above observations and studies, we propose to model X as X ∼ MN h × w ( M , Ω ⊕ Ψ ) , where M ∈ R h × w , Ω ∈ R h × h ≻ 0, Ψ ∈ R w × w ≻ 0, ⊕ denotes the Kronecker sum [20], defined as Ω ⊕ Ψ = Ω ⊗ I [ w ] + I [ h ] ⊗ Ψ , and I [ n ] denotes an n × n identity matrix. Covariance matrices following the Kronecker sum structure can still capture the relationships among rows and columns [20]. It also follows from [2, 37] that constraining the mean matrix M allows a more direct modeling of the structural information within a feature map. Following these studies, we assume X follows a variant of the matrix-variate normal distribution as
|
| 92 |
+
|
| 93 |
+
<!-- formula-not-decoded -->
|
| 94 |
+
|
| 95 |
+
where the mean matrix M ∈ R h × w is restricted to be the outer sum of two vectors, defined as
|
| 96 |
+
|
| 97 |
+
<!-- formula-not-decoded -->
|
| 98 |
+
|
| 99 |
+
where µ ∈ R h , υ ∈ R w , and 1 [ n ] denotes a vector of all ones of size n .
|
| 100 |
+
|
| 101 |
+
Under this model, the marginal distributions of rows and columns are both multivariate normal [2]. Specifically, the i th row vector X i ∶ ∈ R 1 × w follows X T i ∶ ∼ N w ( µ i + υ T , Ω ii + Ψ ) , and the j th column vector X ∶ j ∈ R h × 1 follows X ∶ j ∼ N h ( υ i + µ , Ψ ii + Ω ) . In the following discussion, we assume that Ω and Ψ are diagonal, implying that any pair of variables in X are uncorrelated. Note that, although the variables in X are independent, their covariance matrix still follows the Kronecker covariance structure, thus capturing the relationships among rows and columns [2, 37].
|
| 102 |
+
|
| 103 |
+
## 3.3 Main Technical Results
|
| 104 |
+
|
| 105 |
+
Let X row = (∑ h i = 1 X T i ∶ )/ h ∈ R w and X col = (∑ w j = 1 X ∶ j )/ w ∈ R h be the average of row and column vectors, respectively. Under the assumption above, X row and X col follow multivariate normal distributions as
|
| 106 |
+
|
| 107 |
+
<!-- formula-not-decoded -->
|
| 108 |
+
|
| 109 |
+
<!-- formula-not-decoded -->
|
| 110 |
+
|
| 111 |
+
where µ = (∑ h i = 1 µ i )/ h , Ω = (∑ h i = 1 Ω ii )/ h , υ = (∑ w j = 1 υ j )/ w , and Ψ = (∑ w j = 1 Ψ j j )/ w . Our main technical results can be summarized in the following theorem.
|
| 112 |
+
|
| 113 |
+
Theorem 1. Given the multivariate normal distributions in Eqs. (4) and (5) with diagonal Ω and Ψ , if (a) r 1 , r 2 , . . . , r h are independent and identically distributed (i.i.d.) random vectors that follow the distribution in Eq. (4), (b) c 1 , c 2 , . . . , c w are i.i.d. random vectors that follow the distribution in Eq. (5), (c) r 1 , r 2 , . . . , r h and c 1 , c 2 , . . . , c w are independent, we have
|
| 114 |
+
|
| 115 |
+
<!-- formula-not-decoded -->
|
| 116 |
+
|
| 117 |
+
where ˜ X = [ r 1 , r 2 , . . . , r h ] T +[ c 1 , c 2 , . . . , c w ] , ˜ M = ( µ /diamondplus υ )+( µ + υ ) . In particular, if h = w , the covariance matrix satisfies
|
| 118 |
+
|
| 119 |
+
<!-- formula-not-decoded -->
|
| 120 |
+
|
| 121 |
+
where tr (⋅) denotes matrix trace.
|
| 122 |
+
|
| 123 |
+
Proof. The fact that Ω and Ψ are diagonal implies independence in the case of multivariate normal distributions. Therefore, it follows from assumptions (a) and (b) that
|
| 124 |
+
|
| 125 |
+
<!-- formula-not-decoded -->
|
| 126 |
+
|
| 127 |
+
where M r = µ +[ υ , υ , . . . , υ ] T = µ + 1 [ h ] υ T , and
|
| 128 |
+
|
| 129 |
+
<!-- formula-not-decoded -->
|
| 130 |
+
|
| 131 |
+
where M c = υ +[ µ , µ , . . . , µ ] = υ + µ 1 T [ w ] .
|
| 132 |
+
|
| 133 |
+
Given assumption (c) and ˜ X = [ r 1 , r 2 , . . . , r h ] T +[ c 1 , c 2 , . . . , c w ] , we have
|
| 134 |
+
|
| 135 |
+
<!-- formula-not-decoded -->
|
| 136 |
+
|
| 137 |
+
where ˜ M = M r + M c = ( µ /diamondplus υ ) + ( µ + υ ) .
|
| 138 |
+
|
| 139 |
+
If h = w , we have
|
| 140 |
+
|
| 141 |
+
<!-- formula-not-decoded -->
|
| 142 |
+
|
| 143 |
+
Figure 3: Illustrations of regular attention operator (a), KAO KV (b) and KAO QKV (c) on 2-D data. In the regular attention operator (a), the input tensor is unfolded into a mode-3 matrix and fed into the attention operator. The output of the attention operator is folded back to a tensor as the final output. In KAO KV (b), we juxtapose the horizontal and lateral average matrices derived from the input tensor as the key and value matrices. We keep the mode-3 unfolding of input tensor as the query matrix. In KAO QKV (c), all three input matrices use the juxtaposition of two average matrices. In contrast to KAO KV , we use an outer-sum operation to generate the third-order tensor from the output of the attention operator.
|
| 144 |
+
|
| 145 |
+
<!-- image -->
|
| 146 |
+
|
| 147 |
+
and
|
| 148 |
+
|
| 149 |
+
## 3.4 Kronecker Attention Operators
|
| 150 |
+
|
| 151 |
+
Wedescribe the Kronecker attention operators (KAO) in the context of self-attention on 2-D data, but they can be easily generalized to generic attentions. In this case, the input to the ℓ th layer is a third-order tensor X ( ℓ ) ∈ R h × w × c . Motivated by the theoretical results of Sections 3.2 and 3.3, we propose to use horizontal and lateral average matrices to represent original mode-3 unfolding without much information loss. Based on Eq. (4) and Eq. (5), the horizontal average matrix H and the lateral average matrix L are computed as
|
| 152 |
+
|
| 153 |
+
<!-- formula-not-decoded -->
|
| 154 |
+
|
| 155 |
+
where X ( ℓ ) i ∶∶ and X ( ℓ ) ∶ j ∶ are the horizontal and lateral slices [21] of tensor X ( ℓ ) , respectively. We then form a matrix C by juxtaposing H T and L T as
|
| 156 |
+
|
| 157 |
+
<!-- formula-not-decoded -->
|
| 158 |
+
|
| 159 |
+
Based on the horizontal and lateral average matrices contained in C , we propose two Kronecker attention operators (KAOs), i.e. ,
|
| 160 |
+
|
| 161 |
+
<!-- formula-not-decoded -->
|
| 162 |
+
|
| 163 |
+
h
|
| 164 |
+
|
| 165 |
+
This completes the proof of the theorem.
|
| 166 |
+
|
| 167 |
+
□
|
| 168 |
+
|
| 169 |
+
With certain normalization on X , we can have µ + υ = 0, resulting in
|
| 170 |
+
|
| 171 |
+
<!-- formula-not-decoded -->
|
| 172 |
+
|
| 173 |
+
As the trace of a covariance matrix measures the total variation, Theorem 1 implies that ˜ X follows a matrix-variate normal distribution with the same mean and scaled covariance as the distribution of X in Eq. (2). Given this conclusion and the process to obtain ˜ X from X , we propose our Kronecker attention operators in the following section.
|
| 174 |
+
|
| 175 |
+
Figure 4: Architectures of the BaseModule (a), BaseSkipModule (b), AttnModule (c), and AttnSkipModule (d) as described in Section 3.5. The skip connections indicated by single dashed paths are not used when s > 1 or c ≠ d . Those indicated by double dashed paths are not used when s > 1 .
|
| 176 |
+
|
| 177 |
+
<!-- image -->
|
| 178 |
+
|
| 179 |
+
KAO KV and KAO QKV . In KAO KV as shown in Figure 3 (b), we use X ( ℓ ) ( 3 ) as the query matrix and C as the key and value matrices as
|
| 180 |
+
|
| 181 |
+
<!-- formula-not-decoded -->
|
| 182 |
+
|
| 183 |
+
Note that the number of columns in O depends on the number of query vectors. Thus, we obtain hw output vectors from the attention operation in Eq. (16). Similar to the regular attention operator, O is folded back to a third-order tensor Y ( ℓ ) ∈ R h × w × c by considering the column vectors in O as mode-3 fibers of Y ( ℓ ) . KAO KV uses Y ( ℓ ) as the output of layer ℓ .
|
| 184 |
+
|
| 185 |
+
If h = w , the time and space complexities of KAO KV are O ( hw × c × ( h + w )) = O ( h 3 × c ) and O ( hw × ( h + w )) = O ( h 3 ) , respectively. Compared to the original local operator on 2-D data, KAO KV reduces time and space complexities by a factor of h .
|
| 186 |
+
|
| 187 |
+
In order to reduce the time and space complexities further, we propose another operator known as KAO QKV . In KAO QKV as shown in Figure 3(c), we use C as the query, key, and value matrices as
|
| 188 |
+
|
| 189 |
+
<!-- formula-not-decoded -->
|
| 190 |
+
|
| 191 |
+
The final output tensor Y ( ℓ ) ∈ R h × w × c is obtained as
|
| 192 |
+
|
| 193 |
+
<!-- formula-not-decoded -->
|
| 194 |
+
|
| 195 |
+
where ˜ H i ∶ and ˜ L i ∶ are the i th rows of the corresponding matrices. That is, the i th frontal slice of Y ( ℓ ) is obtained by computing the outer sum of the i th rows of ˜ H and ˜ L .
|
| 196 |
+
|
| 197 |
+
If h = w , the time and space complexities of KAO QKV are O (( h + w ) × c ×( h + w )) = O ( h 2 × c ) and O (( h + w ) × ( h + w )) = O ( h 2 ) , respectively. Thus, the time and space complexities have been reduced by a factor of h 2 as compared to the original local operator, and by a factor of h as compared to KAO KV .
|
| 198 |
+
|
| 199 |
+
Note that we do not consider linear transformations in our description, but these transformations can be applied to all three input matrices in KAO KV and KAO QKV as shown in Figure 3.
|
| 200 |
+
|
| 201 |
+
## 3.5 Kronecker Attention Modules and Networks
|
| 202 |
+
|
| 203 |
+
Attention models have not been used in compact deep models to date, primarily due to their high computational cost. Our efficient KAOs make it possible to use attention operators in compact convolutional neural networks (CNNs) like MobileNet [28]. In this section, we design a family of efficient Kronecker attention modules based on MobileNetV2 that can be used in compact CNNs.
|
| 204 |
+
|
| 205 |
+
BaseModule: MobileNetV2 [28] is mainly composed of bottleneck blocks with inverted residuals. Each bottleneck block consists of three convolutional layers; those are, 1 × 1 convolutional layer, 3 × 3 depth-wise convolutional layer, and another 1 × 1 convolutional layer. Suppose the expansion factor is r and stride is s . Given input X ( ℓ ) ∈ R h × w × c for the ℓ th block, the first 1 × 1 convolutional layer outputs rc feature maps ˜ X ( ℓ ) ∈ R h × w × rc . The depth-wise convolutional layer uses a stride of s and outputs rc feature maps ¯ X ( ℓ ) ∈ R h s × w s × rc . The last 1 × 1 convolutional layer produces d feature maps Y ( ℓ ) ∈ R h s × w s × d . When s = 1 and c = d , a skip connection is added between X ( ℓ ) and Y ( ℓ ) . The BaseModule is illustrated in Figure 4 (a).
|
| 206 |
+
|
| 207 |
+
BaseSkipModule: To facilitate feature reuse and gradient backpropagation in deep models, we improve the BaseModule by adding a skip connection. Given input X ( ℓ ) , we use an expansion factor of r -1 for the first 1 × 1 convolutional layer, instead of r as in BaseModule. We then concatenate the output with the original input, resulting in ˜ X ( ℓ ) ∈ R h × w × rc . The other parts of the BaseSkipModule are the same as those of the BaseModule as illustrated in Figure 4 (b). Compared to the BaseModule, the BaseSkipModule reduces the number of parameters by c × c and computational cost by h × w × c . It achieves better feature reuse and gradient backpropagation.
|
| 208 |
+
|
| 209 |
+
Table 1: Details of the KANets architecture. Each line describes a sequence of operators in the format of 'input size / operator name / expansion rate r / number of output channels c / number of operators in the sequence n / stride s '. 'Conv2D' denotes the regular 2D convolutional layer. 'AvgPool' and 'FC' denote the global average pooling layer and the fully-connected layer, respectively. All depth-wise convolutions use the kernel size of 3 × 3 . For multiple operators in a sequence denoted in the same line, all operators produce c output channels. And the first operator applies the stride of s while the following operators applies the stride of 1. k denotes the class number in the task.
|
| 210 |
+
|
| 211 |
+
| Input Operator r c n s 224 2 × 3 Conv2D 3 × 3 - 32 1 2 112 2 × 32 BaseSkipModule 1 16 1 1 112 2 × 16 BaseSkipModule 6 24 2 2 56 2 × 24 BaseSkipModule 6 32 2 2 28 2 × 32 AttnSkipModule 6 32 1 1 28 2 × 32 BaseSkipModule 6 64 1 2 14 2 × 64 AttnSkipModule 6 64 3 1 14 2 × 64 AttnSkipModule 6 96 3 1 14 2 × 96 BaseSkipModule 6 160 1 2 7 2 × 160 AttnSkipModule 6 160 2 1 7 2 × 160 AttnSkipModule 6 320 1 1 7 2 × 320 Conv2D 1 × 1 - 1280 1 1 7 2 × 1280 AvgPool + FC - k 1 - |
|
| 212 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 213 |
+
|
| 214 |
+
AttnModule: We propose to add an attention operator into the BaseModule to enable the capture of global features. We reduce the expansion factor of the BaseModule by 1 and add a new parallel path with an attention operator that outputs c feature maps. Concretely, after the depth-wise convolutional layer, the original path outputs ¯ X ( ℓ ) a ∈ R h s × w s ×( r -1 ) c . The attention operator, optionally followed by an average pooling of stride s if s > 1, produces ¯ X ( ℓ ) b ∈ R h s × w s × c . Concatenating them gives ¯ X ( ℓ ) ∈ R h s × w s × rc . The final 1 × 1 convolutional layer remains the same. Within the attention operator, we only apply the linear transformation on the value matrix V to limit the number of parameters and required computational resources. We denote this module as the AttnModule as shown in Figure 4 (b). In this module, the original path acts as locality-based feature extractors, while the new parallel path with an attention operator computes global features. This enables the module to incorporate both local and global information. Note that we can use any attention operator in this module, including the regular attention operator and our KAOs.
|
| 215 |
+
|
| 216 |
+
AttnSkipModule: We propose to add an additional skip connection in the AttnModule, as shown in Figure 4 (d). This skip connection can always be added unless s > 1. The AttnSkipModule has the same amount of parameters and computational cost as the AttnModule.
|
| 217 |
+
|
| 218 |
+
## 4 EXPERIMENTAL STUDIES
|
| 219 |
+
|
| 220 |
+
In this section, we evaluate our proposed operators and networks on image classification and segmentation tasks. We first compare our proposed KAOs with regular attention operators in terms of computational cost and memory usage. Next, we design novel compact CNNs known as Kronecker attention networks (KANets) using our proposed operators and modules. We compare KANets with other compact CNNs on the ImageNet ILSVRC 2012 dataset [5]. Ablation studies are conducted to investigate how our KAOs benefit the entire networks. We also perform experiments on the PASCAL 2012 dataset [6] to show the effectiveness of our KAOs on general application scenarios.
|
| 221 |
+
|
| 222 |
+
## 4.1 Experimental Setup
|
| 223 |
+
|
| 224 |
+
In this section, we describe the experimental setups for both image classification tasks and image segmentation tasks.
|
| 225 |
+
|
| 226 |
+
Experimental Setup for Image Classification As a common practice on this dataset, we use the same data augmentation scheme in He et al. [14]. Specifically, during training, we scale each image to 256 × 256 and then randomly crop a 224 × 224 patch. During inference, the center-cropped patches are used. We train our KANets using the same settings as MobileNetV2 [28] with minor changes. We perform batch normalization [18] on the coefficient matrices in KAOs to stabilize the training. All trainable parameters are initialized with the Xavier initialization [10]. We use the standard stochastic gradient descent optimizer with a momentum of 0.9 [30] to train models for 150 epochs in total. The initial learning rate is 0.1 and it decays by 0.1 at the 80th, 105th, and 120th epoch. Dropout [29] with a keep rate of 0 . 8 is applied after the global average pooling layer. We use 8 TITAN Xp GPUs and a batch size of 512 for training, which takes about 1 . 5 days. Since labels of the test dataset are not available, we train our networks on training dataset and report accuracies on the validation dataset.
|
| 227 |
+
|
| 228 |
+
Experimental Setup for Image Segmentation We train all the models with randomly cropped patches of size 321 × 321 and a batch size of 8. Data augmentation by randomly scaling the inputs for training is employed. We adopt the 'poly' learning rate policy [25] with power = 0 . 9, and set the initial learning rate to 0.00025. Following DeepLabV2, we use the ResNet-101 model pre-trained on ImageNet [5] and MS-COCO [24] for initialization. The models are then trained for 25,000 iterations with a momentum of 0.9 and a weight decay of 0.0005. We perform no post-processing such as conditional random fields and do not use multi-scale inputs due to limited GPU memory. All the models are trained on the training set and evaluated on the validation set.
|
| 229 |
+
|
| 230 |
+
Table 2: Comparisons between the regular attention operator, the regular attention operator with a pooling operation [35], and our proposed KAO KV and KAO QKV in terms of the number of parameters, number of MAdd, memory usage, and CPU inference time on simulated data of different sizes. The input sizes are given in the format of 'batch size × spatial sizes × number of input channels'. 'Attn' denotes the regular attention operator. 'Attn+Pool' denotes the regular attention operator which employs a 2 × 2 pooling operation on K and V input matrices to reduce required computational resources.
|
| 231 |
+
|
| 232 |
+
| Input Operator MAdd Cost Saving Memory Memory Saving Time Speedup 8 × 14 2 × 8 Attn 0.63m 0.00% 5.2MB 0.00% 5.8ms 1.0 × Attn+Pool 0.16m 75.00% 1.5MB 71.65% 2.0ms 3.0 × KAO KV 0.09m 85.71% 0.9MB 82.03% 1.7ms 3.5 × KAO QKV 0.01m 97.71% 0.3MB 95.06% 0.8ms 6.8 × 8 × 28 2 × 8 Attn 9.88m 0.00% 79.9MB 0.00% 72.4ms 1.0 × Attn+Pool 2.47m 75.00% 20.7MB 74.13% 20.9ms 3.5 × KAO KV 0.71m 92.86% 6.5MB 91.88% 7.1ms 10.1 × KAO QKV 0.05m 99.46% 0.9MB 98.85% 1.7ms 40.9 × 8 × 56 2 × 8 Attn 157.55m 0.00% 1,262.6MB 0.00% 1,541.1ms 1.0 × Attn+Pool 39.39m 75.00% 318.7MB 74.76% 396.9ms 3.9 × KAO KV 5.62m 96.43% 48.2MB 96.18% 49.6ms 31.1 × KAO QKV 0.21m 99.87% 3.4MB 99.73% 5.1ms 305.8 × |
|
| 233 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 234 |
+
|
| 235 |
+
## 4.2 Comparison of Computational Efficiency
|
| 236 |
+
|
| 237 |
+
According to the theoretical analysis in Section 3.4, our KAOs have efficiency advantages over regular attention operators on highorder data, especially for inputs with large spatial sizes. We conduct simulated experiments to evaluate the theoretical results. To reduce the influence of external factors, we build networks composed of a single attention operator, and apply the TensorFlow profile tool [1] to report the multiply-adds (MAdd), required memory, and time consumed on 2-D simulated data. For the simulated input data, we set the batch size and number of channels both to 8, and test three spatial sizes; those are, 56 × 56, 28 × 28, and 14 × 14. The number of output channels is also set to 8.
|
| 238 |
+
|
| 239 |
+
Table 2 summarizes the comparison results. On simulated data of spatial sizes 56 × 56, our KAO KV and KAO QKV achieve 31.1 and 305.8 times speedup, and 96.18% and 99.73% memory saving compared to the regular attention operator, respectively. Our proposed KAOs show significant improvements over regular attention operators in terms of computational resources, which is consistent with the theoretical analysis. In particular, the amount of improvement increases as the spatial sizes increase. These results show that the proposed KAOs are efficient attention operators on high-dimensional and high-order data.
|
| 240 |
+
|
| 241 |
+
## 4.3 Results on Image Classification
|
| 242 |
+
|
| 243 |
+
With the high efficiency of our KAOs, we have proposed several efficient Kronecker attention modules for compact CNNs in Section 3.5. To further show the effectiveness of KAOs and the modules, we build novel compact CNNs known as Kronecker attention networks (KANets). Following the practices in [35], we apply these modules on inputs of spatial sizes 28 × 28, 14 × 14, and 7 × 7. The detailed network architecture is described in Table 1 in the Section 4.1.
|
| 244 |
+
|
| 245 |
+
We compare KANets with other CNNs on the ImageNet ILSVRC 2012 image classification dataset, which serves as the benchmark for compact CNNs [8, 15, 28, 39]. The dataset contains 1.2 million training, 50 thousand validation, and 50 thousand testing images. Each image is labeled with one of 1,000 classes. Details of the experimental setups are provided in the Section 4.1.
|
| 246 |
+
|
| 247 |
+
Table 3: Comparisons between KANets and other CNNs in terms of the top-1 accuracy on the ImageNet validation set, the numberoftotal parameters, and MAdd. We use KANet KV andKANet QKV to denote KANets using KAO KV andKAO QKV , respectively.
|
| 248 |
+
|
| 249 |
+
| Model Top-1 Params MAdd GoogleNet 0.698 6.8m 1550m VGG16 0.715 128m 15300m AlexNet 0.572 60m 720m SqueezeNet 0.575 1.3m 833m MobileNetV1 0.706 4.2m 569m ShuffleNet 1.5x 0.715 3.4m 292m ChannelNet-v1 0.705 3.7m 407m MobileNetV2 0.720 3.47m 300m KANet KV (ours) 0.729 3.44m 288m KANet QKV (ours) 0.728 3.44m 281m |
|
| 250 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 251 |
+
|
| 252 |
+
The comparison results between our KANets and other CNNs in terms of the top-1 accuracy, number of parameters, and MAdd are reported in Table 3. SqueezeNet [17] has the least number of parameters, but uses the most MAdd and does not obtain competitive performance as compared to other compact CNNs. Among compact CNNs, MobileNetV2 [28] is the previous state-of-the-art model, which achieves the best trade-off between effectiveness and efficiency. According to the results, our KANets significantly outperform MobileNetV2 with 0.03 million fewer parameters. Specifically, our KANet KV and KANet QKV outperform MobileNetV2 by margins of 0.9% and 0.8%, respectively. More importantly, our KANets has the least computational cost. These results demonstrate the effectiveness and efficiency of our proposed KAOs.
|
| 253 |
+
|
| 254 |
+
Table 4: Comparisons between KANets with regular attention operators (denoted as AttnNet), KANets with regular attention operators with a pooling operation (denoted as AttnNet+Pool) and KANets with KAOs in terms of the top-1 accuracy on the ImageNet validation set, the number of total parameters, and MAdd.
|
| 255 |
+
|
| 256 |
+
| Model Top-1 Params MAdd AttnNet 0.730 3.44m 365m AttnNet+Pool 0.729 3.44m 300m KANet KV 0.729 3.44m 288m KANet QKV 0.728 3.44m 281m |
|
| 257 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 258 |
+
|
| 259 |
+
The performance of KANets indicates that our proposed methods are promising, since we only make small modifications to the architecture of MobileNetV2 to include KAOs. Compared to modules with the regular convolutional layers only, our proposed modules with KAOs achieve better performance without using excessive computational resources. Thus, our methods can be used widely for designing compact deep models. Our KAOs successfully address the practical challenge of applying regular attention operators on highorder data. In the next experiments, we show that our proposed KAOs are as effective as regular attention operators.
|
| 260 |
+
|
| 261 |
+
## 4.4 Comparison with Regular Attention Operators
|
| 262 |
+
|
| 263 |
+
Weperform experiments to compare our proposed KAOs with regular attention operators. We consider the regular attention operator and the one with a pooling operation in [35]. For the attention operator with pooling operation, the spatial sizes of the key matrix K and value matrix V are reduced by 2 × 2 pooling operations to save computation cost. To compare these operators in fair settings, we replace all KAOs in KANets with regular attention operators and regular attention operators with a pooling operation, denoted as AttnNet and AttnNet+Pool, respectively.
|
| 264 |
+
|
| 265 |
+
The comparison results are summarized in Table 4. Note that all these models have the same number of parameters. We can see that KANet KV and KANet QKV achieve similar performance as AttnNet and AttnNet+Pool with dramatic reductions of computational cost. The results indicate that our proposed KAOs are as effective as regular attention operators while being much more efficient. In addition, our KAOs are better than regular attention operators that uses a pooling operation to increase efficiency in [35].
|
| 266 |
+
|
| 267 |
+
## 4.5 Ablation Studies
|
| 268 |
+
|
| 269 |
+
To show how our KAOs benefit entire networks in different settings, we conduct ablation studies on MobileNetV2 and KANet KV . For MobileNetV2, we replace BaseModules with AttnModules as described in Section 3.5, resulting in a new model denoted as MobileNetV2+KAO. On the contrary, based on KANet KV , we replace all AttnSkipModules by BaseModules. The resulting model is denoted as KANet w/o KAO.
|
| 270 |
+
|
| 271 |
+
Table 5 reports the comparison results. By employing KAO KV , MobileNetV2+KAO gains a performance boost of 0.6% with fewer parameters than MobileNetV2. On the other hand, KANet KV outperforms KANet w/o KAO by a margin of 0.8%, while KANet w/o KAO has more parameters than KANet KV . KANet KV achieves the best performance while costing the least computational resources. The results indicate that our proposed KAOs are effective and efficient, which is independent of specific network architectures.
|
| 272 |
+
|
| 273 |
+
Table 5: Comparisons between MobileNetV2, MobileNetV2 with KAOs KV (denoted as MobileNetV2+KAO KV ), KANet KV , and KANet KV without KAO KV (denoted as KANet w/o KAO) in terms of the top-1 accuracy on the ImageNet validation set, the number of total parameters, and MAdd.
|
| 274 |
+
|
| 275 |
+
| Model Top-1 Params MAdd MobileNetV2 0.720 3.47m 300m MobileNetV2+KAO 0.726 3.46m 298m KANet KV 0.729 3.44m 288m KANet w/o KAO 0.721 3.46m 298m |
|
| 276 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 277 |
+
|
| 278 |
+
Table 6: Comparisons of DeepLabV2, DeepLabV2 with the regular attention operator (DeepLabV2+Attn), DeepLabV2 with our KAO KV (DeepLabV2+KAO KV ), and DeepLabV2 with our KAO QKV (DeepLabV2+KAO QKV ) in terms of the pixelwise accuracy, and mean IOU on the PASCAL VOC 2012 validation dataset.
|
| 279 |
+
|
| 280 |
+
| Model Accuracy Mean IOU DeepLabV2 0.944 75.1 DeepLabV2+Attn 0.947 76.3 DeepLabV2+KAO KV 0.946 75.9 DeepLabV2+KAO QKV 0.946 75.8 |
|
| 281 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 282 |
+
|
| 283 |
+
## 4.6 Results on Image Segmentation
|
| 284 |
+
|
| 285 |
+
In order to show the efficiency and effectiveness of our KAOs in broader application scenarios, we perform additional experiments on image segmentation tasks using the PASCAL 2012 dataset [6]. With the extra annotations provided by [13], the augmented dataset contains 10,582 training, 1,449 validation, and 1,456 testing images. Each pixel of the images is labeled by one of 21 classes with 20 foreground classes and 1 background class.
|
| 286 |
+
|
| 287 |
+
We re-implement the DeepLabV2 model [4] as our baseline. Following [36], using attention operators as the output layer, instead of atrous spatial pyramid pooling (ASPP), results in a significant performance improvement. In our experiments, we replace ASPP with the regular attention operator and our proposed KAOs, respectively, and compare the results. For all attention operators, linear transformations are applied on Q , K , and V . Details of the experimental setups are provided in the Section 4.1.
|
| 288 |
+
|
| 289 |
+
Table 6 shows the evaluation results in terms of pixel accuracy and mean intersection over union (IoU) on the PASCAL VOC 2012 validation set. Clearly, models with attention operators outperform the baseline model with ASPP. Compared with the regular attention operator, KAOs result in similar pixel-wise accuracy but slightly lower mean IoU. From the pixel-wise accuracy, results indicate that KAOsare as effective as the regular attention operator. The decrease in mean IoU may be caused by the strong structural assumption behind KAOs. Overall, the experimental results demonstrate the efficiency and effectiveness of our KAOs in broader application scenarios.
|
| 290 |
+
|
| 291 |
+
## 5 CONCLUSIONS
|
| 292 |
+
|
| 293 |
+
In this work, we propose Kronecker attention operators to address the practical challenge of applying attention operators on highorder data. We investigate the problem from a probabilistic perspective and use matrix-variate normal distributions with Kronecker covariance structure. Experimental results show that our KAOs reduce the amount of required computational resources by a factor of hundreds, with larger factors for higher-dimensional and higherorder data. We employ KAOs to design a family of efficient modules, leading to our KANets. KANets significantly outperform the previous state-of-the-art compact models on image classification tasks, with fewer parameters and less computational cost. Additionally, we perform experiments on the image segmentation task to show the effectiveness of our KAOs on general application scenarios.
|
| 294 |
+
|
| 295 |
+
## ACKNOWLEDGMENTS
|
| 296 |
+
|
| 297 |
+
This work was supported in part by National Science Foundation grants IIS-1908220 and DBI-1922969.
|
| 298 |
+
|
| 299 |
+
## REFERENCES
|
| 300 |
+
|
| 301 |
+
- [1] Martín Abadi, Paul Barham, Jianmin Chen, Zhifeng Chen, Andy Davis, Jeffrey Dean, Matthieu Devin, Sanjay Ghemawat, Geoffrey Irving, Michael Isard, et al. 2016. Tensorflow: a system for large-scale machine learning.. In OSDI , Vol. 16. 265-283.
|
| 302 |
+
- [2] Genevera I Allen and Robert Tibshirani. 2010. Transposable regularized covariance models with an application to missing data imputation. The Annals of Applied Statistics 4, 2 (2010), 764.
|
| 303 |
+
- [3] Dzmitry Bahdanau, Kyunghyun Cho, and Yoshua Bengio. 2015. Neural machine translation by jointly learning to align and translate. International Conference on Learning Representations (2015).
|
| 304 |
+
- [4] Liang-Chieh Chen, George Papandreou, Iasonas Kokkinos, Kevin Murphy, and Alan L Yuille. 2018. Deeplab: Semantic image segmentation with deep convolutional nets, atrous convolution, and fully connected crfs. IEEE transactions on pattern analysis and machine intelligence 40, 4 (2018), 834-848.
|
| 305 |
+
- [5] J. Deng, W. Dong, R. Socher, L.-J. Li, K. Li, and L. Fei-Fei. 2009. ImageNet: A Large-Scale Hierarchical Image Database. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition .
|
| 306 |
+
- [6] Mark Everingham, Luc Van Gool, Christopher KI Williams, John Winn, and Andrew Zisserman. 2010. The pascal visual object classes (voc) challenge. International journal of computer vision 88, 2 (2010), 303-338.
|
| 307 |
+
- [7] Hongyang Gao and Shuiwang Ji. 2019. Graph representation learning via hard and channel-wise attention networks. In Proceedings of the 25th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining . 741-749.
|
| 308 |
+
- [8] Hongyang Gao, Zhengyang Wang, and Shuiwang Ji. 2018. ChannelNets: Compact and Efficient Convolutional Neural Networks via Channel-Wise Convolutions. In Advances in Neural Information Processing Systems . 5203-5211.
|
| 309 |
+
- [9] Hongyang Gao, Zhengyang Wang, and Shuiwang Ji. 2018. Large-scale learnable graph convolutional networks. In Proceedings of the 24th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining . 1416-1424.
|
| 310 |
+
- [10] Xavier Glorot and Yoshua Bengio. 2010. Understanding the difficulty of training deep feedforward neural networks. In Proceedings of the Thirteenth International Conference on Artificial Intelligence and Statistics . 249-256.
|
| 311 |
+
- [11] Alexander Graham. 2018. Kronecker products and matrix calculus with applications . Courier Dover Publications.
|
| 312 |
+
- [12] Arjun K Gupta and Daya K Nagar. 2018. Matrix variate distributions . Chapman and Hall/CRC.
|
| 313 |
+
- [13] Bharath Hariharan, Pablo Arbeláez, Lubomir Bourdev, Subhransu Maji, and Jitendra Malik. 2011. Semantic contours from inverse detectors. In Computer Vision (ICCV), 2011 IEEE International Conference on . IEEE, 991-998.
|
| 314 |
+
- [14] Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. 2016. Deep residual learning for image recognition. In Proceedings of the IEEE conference on computer vision and pattern recognition . 770-778.
|
| 315 |
+
- [15] Andrew G Howard, Menglong Zhu, Bo Chen, Dmitry Kalenichenko, Weijun Wang, Tobias Weyand, Marco Andreetto, and Hartwig Adam. 2017. Mobilenets: Efficient convolutional neural networks for mobile vision applications. arXiv preprint arXiv:1704.04861 (2017).
|
| 316 |
+
- [16] Zilong Huang, Xinggang Wang, Lichao Huang, Chang Huang, Yunchao Wei, and Wenyu Liu. 2018. CCNet: Criss-Cross Attention for Semantic Segmentation. arXiv preprint arXiv:1811.11721 (2018).
|
| 317 |
+
- [17] Forrest N Iandola, Song Han, Matthew W Moskewicz, Khalid Ashraf, William J Dally, and Kurt Keutzer. 2016. SqueezeNet: AlexNet-level accuracy with 50x fewer parameters and< 0.5 MB model size. arXiv preprint arXiv:1602.07360 (2016).
|
| 318 |
+
- [18] Sergey Ioffe and Christian Szegedy. 2015. Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift. In International Conference on Machine Learning . 448-456.
|
| 319 |
+
- [19] Rie Johnson and Tong Zhang. 2015. Semi-supervised convolutional neural networks for text categorization via region embedding. In Advances in neural information processing systems . 919-927.
|
| 320 |
+
- [20] Alfredo Kalaitzis, John Lafferty, Neil Lawrence, and Shuheng Zhou. 2013. The bigraphical lasso. In International Conference on Machine Learning . 1229-1237.
|
| 321 |
+
21. Tamara G. Kolda and Brett W. Bader. 2009. Tensor Decompositions and Applica-
|
| 322 |
+
- [21] tions. SIAM Rev. 51, 3 (2009), 455-500.
|
| 323 |
+
- [22] Yann LeCun, Léon Bottou, Yoshua Bengio, and Patrick Haffner. 1998. Gradientbased learning applied to document recognition. Proc. IEEE 86, 11 (1998), 22782324.
|
| 324 |
+
- [23] Guanbin Li, Xiang He, Wei Zhang, Huiyou Chang, Le Dong, and Liang Lin. 2018. Non-locally Enhanced Encoder-Decoder Network for Single Image De-raining. In 2018 ACM Multimedia Conference on Multimedia Conference . ACM, 1056-1064.
|
| 325 |
+
- [24] Tsung-Yi Lin, Michael Maire, Serge Belongie, James Hays, Pietro Perona, Deva Ramanan, Piotr Dollár, and C Lawrence Zitnick. 2014. Microsoft coco: Common objects in context. In European conference on computer vision . Springer, 740-755.
|
| 326 |
+
- [25] Wei Liu, Andrew Rabinovich, and Alexander C Berg. 2015. Parsenet: Looking wider to see better. arXiv preprint arXiv:1506.04579 (2015).
|
| 327 |
+
- [26] Jiasen Lu, Jianwei Yang, Dhruv Batra, and Devi Parikh. 2016. Hierarchical question-image co-attention for visual question answering. In Advances In Neural Information Processing Systems . 289-297.
|
| 328 |
+
- [27] Mateusz Malinowski, Carl Doersch, Adam Santoro, and Peter Battaglia. 2018. Learning Visual Question Answering by Bootstrapping Hard Attention. In Proceedings of the European Conference on Computer Vision (ECCV) . 3-20.
|
| 329 |
+
- [28] Mark Sandler, Andrew Howard, Menglong Zhu, Andrey Zhmoginov, and LiangChieh Chen. 2018. Mobilenetv2: Inverted residuals and linear bottlenecks. In 2018 IEEE/CVF Conference on Computer Vision and Pattern Recognition . IEEE, 4510-4520.
|
| 330 |
+
- [29] Nitish Srivastava, Geoffrey Hinton, Alex Krizhevsky, Ilya Sutskever, and Ruslan Salakhutdinov. 2014. Dropout: A simple way to prevent neural networks from overfitting. Journal of Machine Learning Research 15, 1 (2014), 1929-1958.
|
| 331 |
+
- [30] Ilya Sutskever, James Martens, George Dahl, and Geoffrey Hinton. 2013. On the importance of initialization and momentum in deep learning. In International conference on machine learning . 1139-1147.
|
| 332 |
+
- [31] Dmitry Ulyanov, Andrea Vedaldi, and Victor Lempitsky. 2016. Instance Normalization: The Missing Ingredient for Fast Stylization. arXiv preprint arXiv:1607.08022 (2016).
|
| 333 |
+
- [32] Charles F Van Loan. 2000. The ubiquitous Kronecker product. Journal of computational and applied mathematics 123, 1-2 (2000), 85-100.
|
| 334 |
+
- [33] Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin. 2017. Attention is all you need. In Advances in Neural Information Processing Systems . 5998-6008.
|
| 335 |
+
- [34] Petar Veličković, Guillem Cucurull, Arantxa Casanova, Adriana Romero, Pietro Liò, and Yoshua Bengio. 2017. Graph Attention Networks. arXiv preprint arXiv:1710.10903 (2017).
|
| 336 |
+
- [35] Xiaolong Wang, Ross Girshick, Abhinav Gupta, and Kaiming He. 2018. Nonlocal neural networks. In The IEEE Conference on Computer Vision and Pattern Recognition (CVPR) , Vol. 1. 4.
|
| 337 |
+
- [36] Zhengyang Wang and Shuiwang Ji. 2018. Smoothed Dilated Convolutions for Improved Dense Prediction. In Proceedings of the 24th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining . ACM, 2486-2495.
|
| 338 |
+
- [37] Zhengyang Wang, Hao Yuan, and Shuiwang Ji. 2019. Spatial Variational AutoEncoding via Matrix-Variate Normal Distributions. In Proceedings of the 2019 SIAM International Conference on Data Mining . SIAM, 648-656.
|
| 339 |
+
- [38] Kelvin Xu, Jimmy Ba, Ryan Kiros, Kyunghyun Cho, Aaron Courville, Ruslan Salakhudinov, Rich Zemel, and Yoshua Bengio. 2015. Show, attend and tell: Neural image caption generation with visual attention. In International conference on machine learning . 2048-2057.
|
| 340 |
+
- [39] Xiangyu Zhang, Xinyu Zhou, Mengxiao Lin, and Jian Sun. 2017. Shufflenet: An extremely efficient convolutional neural network for mobile devices. arXiv preprint arXiv:1707.01083 (2017).
|
| 341 |
+
- [40] Hengshuang Zhao, Yi Zhang, Shu Liu, Jianping Shi, Chen Change Loy, Dahua Lin, and Jiaya Jia. 2018. PSANet: Point-wise Spatial Attention Network for Scene Parsing. In Proceedings of the European Conference on Computer Vision (ECCV) . 267-283.
|
text-versions/attention-markdown/2009.12064_Attention Meets Perturbations Robust and.md
ADDED
|
@@ -0,0 +1,448 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2009.12064 Attention Meets Perturbations Robust And
|
| 2 |
+
|
| 3 |
+
Received May 18, 2021, accepted Jun 21, 2021, date of publication xxxx 00, 0000, date of current version xxxx 00, 0000.
|
| 4 |
+
|
| 5 |
+
Digital Object Identifier 10.1109/ACCESS.2021.3093456
|
| 6 |
+
|
| 7 |
+
## Attention Meets Perturbations: Robust and Interpretable Attention with Adversarial Training
|
| 8 |
+
|
| 9 |
+
## SHUNSUKE KITADA 1 , AND HITOSHI IYATOMI 1 (Member, IEEE)
|
| 10 |
+
|
| 11 |
+
1 Hosei University, Graduate School of Science and Engineering, Department of Applied Informatics, Tokyo 1883-8584, Japan
|
| 12 |
+
|
| 13 |
+
Corresponding author: Shunsuke Kitada (e-mail: shunsuke.kitada.8y@stu.hosei.ac.jp).
|
| 14 |
+
|
| 15 |
+
This work was supported by JSPS KAKENHI Grant Number 21J14143.
|
| 16 |
+
|
| 17 |
+
ABSTRACT Although attention mechanisms have been applied to a variety of deep learning models and have been shown to improve the prediction performance, it has been reported to be vulnerable to perturbations to the mechanism. To overcome the vulnerability to perturbations in the mechanism, we are inspired by adversarial training (AT), which is a powerful regularization technique for enhancing the robustness of the models. In this paper, we propose a general training technique for natural language processing tasks, including AT for attention (Attention AT) and more interpretable AT for attention (Attention iAT). The proposed techniques improved the prediction performance and the model interpretability by exploiting the mechanisms with AT. In particular, Attention iAT boosts those advantages by introducing adversarial perturbation, which enhances the difference in the attention of the sentences. Evaluation experiments with ten open datasets revealed that AT for attention mechanisms, especially Attention iAT, demonstrated (1) the best performance in nine out of ten tasks and (2) more interpretable attention (i.e., the resulting attention correlated more strongly with gradient-based word importance) for all tasks. Additionally, the proposed techniques are (3) much less dependent on perturbation size in AT.
|
| 18 |
+
|
| 19 |
+
INDEX TERMS natural language processing, attention mechanism, adversarial training, interpretability, binary classification, question answering, natural language inference
|
| 20 |
+
|
| 21 |
+
## I. INTRODUCTION
|
| 22 |
+
|
| 23 |
+
A TTENTION mechanisms [1] are widely applied in natural language processing (NLP) field through deep neural networks (DNNs). As the effectiveness of attention mechanisms became apparent in various tasks [2]-[7], they were applied not only to recurrent neural networks (RNNs) but also to convolutional neural networks (CNNs). Moreover, Transformers [8] which make proactive use of attention mechanisms have also achieved excellent results. However, it has been pointed out that DNN models tend to be locally unstable, and even tiny perturbations to the original inputs [9] or attention mechanisms can mislead the models [10]. Specifically, Jain and Wallace [10] used a practical bi-directional RNN (BiRNN) model to investigate the effect of attention mechanisms and reported that learned attention weights based on the model are vulnerable to perturbations. 1
|
| 24 |
+
|
| 25 |
+
1 In Jain and Wallace [10], the vulnerability of attention mechanisms to perturbations is confirmed with an RNN-based model [10]. In this paper, we focus on the model, and Transformer [8]-based model such as BERT [11] and their successor models [12], [13] will be future work.
|
| 26 |
+
|
| 27 |
+
The Transformer [8] and its follow-up models [12], [13] have self-attention mechanisms that estimate the relationship of each word in the sentence. These models take advantage of the effect of the mechanisms and have shown promising performances. Thus, there is no doubt that the effect of the mechanisms is extremely large. However, they are not easy to train, as they require huge amounts of GPU memory to maintain the weights of the model. Recently, there have been proposals to reduce memory consumption [14], and we acknowledge the advantages of the models. On the other hand, the application of attention mechanisms to DNN models, such as RNN and CNN models, which have been widely used and do not require relatively high training requirements, has not been sufficiently studied.
|
| 28 |
+
|
| 29 |
+
In this paper, we focus on improving the robustness of commonly used BiRNN models (as described detail in Section III) to perturbations in the attention mechanisms. Furthermore, we demonstrate that the result of overcoming the vulnerability of the attention mechanisms is an improvement in the prediction performance and model interpretability.
|
| 30 |
+
|
| 31 |
+
<!-- image -->
|
| 32 |
+
|
| 33 |
+
<!-- image -->
|
| 34 |
+
|
| 35 |
+
FIGURE 1. An example of an attention heatmap for a BiRNN model with attention mechanisms and the model with attention mechanisms trained with adversarial training from the Stanford Sentiment Treebank (SST) [17]. The proposed adversarial training for attention mechanisms helps the model learn cleaner attention.
|
| 36 |
+
|
| 37 |
+
<!-- image -->
|
| 38 |
+
|
| 39 |
+
To tackle the models' vulnerability to perturbation, Goodfellow et al. [15] proposed adversarial training (AT) that increases robustness by adding adversarial perturbations to the input and the training technique forcing the model to address its difficulties. Previous studies [15], [16] in the image recognition field have theoretically explained the regularization effect of AT and shown that it improves the robustness of the model for unseen images.
|
| 40 |
+
|
| 41 |
+
AT is also widely used in the NLP field as a powerful regularization technique [18]-[21]. In pioneering work, Miyato et al. [18] proposed a simple yet effective technique to improving the text classification performance by applying AT to a word embedding space. Later, interpretable AT (iAT) was proposed to increase the interpretability of the model by restricting the direction of the perturbations to existing words in the word embedding space [19]. The attention weight of each word is considered an indicator of the importance of each word [22], and thus, in terms of interpretability, we assume that the weight is considered a higher-order feature than the word embedding. Therefore, AT for attention mechanisms that adds an adversarial perturbation to deceive the attention mechanisms is expected to be more effective than AT for word embedding.
|
| 42 |
+
|
| 43 |
+
From motivations above, we propose a new general training technique for attention mechanisms based on AT, called adversarial training for attention (Attention AT) and more interpretable adversarial training for attention (Attention iAT). The proposed techniques are the first attempt to employ AT for attention mechanisms. The proposed Attention AT/iAT is expected to improve the robustness and the interpretability of the model by appropriately overcoming the adversarial perturbations to attention mechanisms [23][25]. Because our proposed AT techniques for attention mechanisms is model-independent and a general technique, it can be applied to various DNN models (e.g., RNN and CNN) with attention mechanisms. Our technique can also be applied to any similarity functions for attention mechanisms, e.g, additive function [1] and scaled dot-product function [8], which is famous for calculating the similarity in attention mechanisms.
|
| 44 |
+
|
| 45 |
+
To demonstrate the effects of these techniques, we evaluated them compared to several other state-of-the-art ATbased techniques [18], [19] with ten common datasets for different NLP tasks. These datasets included binary classification (BC), question answering (QA), and natural language inference (NLI). We also evaluated how the attention weights obtained through the proposed AT technique agreed with the word importance calculated by the gradients [26]. Evaluating the proposed techniques, we obtained the following findings concerning AT for attention mechanisms in NLP:
|
| 46 |
+
|
| 47 |
+
- AT for attention mechanisms improves the prediction performance of various NLP tasks.
|
| 48 |
+
- AT for attention mechanisms helps the model learn cleaner attention (as shown in Figure 1) and demonstrates a stronger correlation with the word importance calculated from the model gradients.
|
| 49 |
+
- The proposed training techniques are much less independent concerning perturbation size in AT.
|
| 50 |
+
|
| 51 |
+
Especially, our Attention iAT demonstrated the best performance in nine out of ten tasks and more interpretable attention, i.e., resulting attention weight correlated more strongly with the gradient-based word importance [26]. The implementation required to reproduce these techniques and the evaluation experiments are available on GitHub. 2
|
| 52 |
+
|
| 53 |
+
## II. RELATED WORK
|
| 54 |
+
|
| 55 |
+
## A. ATTENTION MECHANISMS
|
| 56 |
+
|
| 57 |
+
Attention mechanisms were introduced by Bahdanau et al. [1] for the task of machine translation. Today, these mechanisms contribute to improving the prediction performance of various tasks in the NLP field, such as sentence-level classification [2], sentiment analysis [3], question answering [4], and natural language inference [5]. There are a wide variety of attention mechanisms; for instance, additive [1] and scaled dot-product [8] functions are used as similarity functions.
|
| 58 |
+
|
| 59 |
+
Attention weights are often claimed to offer insights into the inner workings of DNNs [22]. However, Jain and Wallace [10] reported that learned attention weights are often uncorrelated with the word importance calculated through the gradient-based method [26], and perturbations interfere with interpretation. In this paper, we demonstrate that AT for attention mechanisms can mitigate these issues.
|
| 60 |
+
|
| 61 |
+
## B. ADVERSARIAL TRAINING
|
| 62 |
+
|
| 63 |
+
AT [9], [15], [27] is a powerful regularization technique that has been primarily explored in the field of image recognition to improve the robustness of models for input perturbations. In the NLP field, AT has been applied to various tasks by extending the concept of adversarial perturbations, e.g., text classification [18], [19], part-of-speech tagging [20], and machine reading comprehension [21], [28]. As mentioned earlier, these techniques apply AT for word embedding. Other AT-based techniques for the NLP tasks include those
|
| 64 |
+
|
| 65 |
+
[2 https://github.com/shunk031/attention-meets-perturbation](https://github.com/shunk031/attention-meets-perturbation)
|
| 66 |
+
|
| 67 |
+
(a)
|
| 68 |
+
|
| 69 |
+
<!-- image -->
|
| 70 |
+
|
| 71 |
+
<!-- image -->
|
| 72 |
+
|
| 73 |
+
Single sequence model
|
| 74 |
+
|
| 75 |
+
(b)
|
| 76 |
+
|
| 77 |
+
Pair sequence model
|
| 78 |
+
|
| 79 |
+
FIGURE 2. Illustration of the common model architectures to apply the proposed training technique: (a) a single sequence model for the binary classification task and (b) a pair sequence model for question answering and natural language inference tasks. In (a), the input of the model is word embeddings, { w 1 , · · · , w T S } associated with the input sentence X S . In (b), the inputs are word embeddings { w ( p ) 1 , · · · , w ( p ) T P } and { w ( q ) 1 , · · · , w ( q ) T Q } from two input sequences, X P and X Q , respectively. These inputs are encoded into hidden states through a bi-directional encoder (Enc). In conventional models, the worst-case perturbation r is added to the word embeddings. In our adversarial training for attention mechanisms, we compute and add the r to attention a to improve the prediction performance and the interpretability of the model.
|
| 80 |
+
|
| 81 |
+
related to parameter updating [29] and generative adversarial network (GAN)-based retrieval-enhancement method [30]. Our proposal is an adversarial training technique for attention mechanisms and is different from these methods.
|
| 82 |
+
|
| 83 |
+
Miyato et al. [18] proposed Word AT, a technique that applied AT to the word embeddings. The adversarial perturbations are generated according to the back-propagation gradients. These perturbations are expected to regularize the model. Since then, Sato et al. [19] proposed Word iAT, and it has been known to achieve almost the same performance as Word AT that does not expect interpretability [19]. The Word iAT technique aims to increase the model's interpretability by determining the perturbation's direction so that it is closer to other word embeddings in the vocabulary. Both reports demonstrated improved task performance via AT. However, the specific effect of AT on attention mechanisms has yet to be investigated. In this paper, we aim to address this issue by providing analyses of the effects of AT for attention mechanisms using various NLP tasks.
|
| 84 |
+
|
| 85 |
+
AT is considered to be related to other regularization techniques (e.g., dropout [31], batch normalization [32]). Specifically, dropout can be considered a kind of noise addition. Word dropout [33] and character dropout [34], known as wildcard training, are variants for NLP tasks. These techniques can be considered random noise for the target task. In contrast, AT has been demonstrated to be effective because it creates particularly vulnerable perturbations that the model is trained to overcome [15].
|
| 86 |
+
|
| 87 |
+
It has been reported that DNN models that introduce adversarial training to overcome adversarial perturbations capture human-like features [23]-[25]. These features help to make the prediction of DNN models easier to interpret for humans. In this paper, we demonstrate that the proposed AT to attention mechanisms provides cleaner attention that is more easily interpreted by humans.
|
| 88 |
+
|
| 89 |
+
## III. COMMON MODEL ARCHITECTURE
|
| 90 |
+
|
| 91 |
+
Our goal is to improve the performance of NLP models (i.e., predictability and interpretability) by aiming at the robustness of the attention mechanisms. To demonstrate the effectiveness of exploiting AT to attention for words, we adopted the BiRNN-based model used by Jain and Wallace [10] as our common model architecture and set their performance as our performance baseline, as described in Section I. This is because they performed extensive experiments across a variety of public NLP tasks to investigate the effect of attention mechanisms, and their model has demonstrated desirable prediction performance. However, the attention mechanism in the model has been reported to be vulnerable to perturbations.
|
| 92 |
+
|
| 93 |
+
Based on the model of Jain and Wallace [10], we investigated three common NLP tasks, BC, QA, and NLI. Because Jain and Wallace [10] considered the same tasks. A BC task is a single sequence task that takes one input text, while QA and NLI tasks are pair sequence tasks that take two input sequences. Then, we defined two base models, a single sequence model and pair sequence model, for those tasks, as shown in Figure 2.
|
| 94 |
+
|
| 95 |
+
## A. MODEL WITH ATTENTION MECHANISMS FOR SINGLE SEQUENCE TASK
|
| 96 |
+
|
| 97 |
+
For a single sequence task, such as the BC task, the input is a word sequence of one-hot encoding X S =
|
| 98 |
+
|
| 99 |
+
<!-- image -->
|
| 100 |
+
|
| 101 |
+
( x 1 , x 2 , · · · , x T S ) ∈ R T S ×| V | , where T S and | V | are the number of words in the sentence and vocabulary size. We introduce the following short notation for the sequence ( x 1 , x 2 , · · · , x T S ) as ( x t ) T S t =1 . Let w t ∈ R d be a d -dimensional word embedding that corresponds to x t . We represent each word with the word embeddings to obtain ( w t ) T S t =1 ∈ R T S × d . Next, we use the BiRNN encoder Enc to obtain m -dimensional hidden states h t :
|
| 102 |
+
|
| 103 |
+
<!-- formula-not-decoded -->
|
| 104 |
+
|
| 105 |
+
where h 0 is the initial hidden state and is regarded as a zero vector. Next, we use the additive formulation of attention mechanisms proposed by Bahdanau et al. [1] to compute the attention score for the t -th word ˜ a t , defined as:
|
| 106 |
+
|
| 107 |
+
<!-- formula-not-decoded -->
|
| 108 |
+
|
| 109 |
+
where W ∈ R d ′ × m and b , c ∈ R d ′ are the parameters of the model. Then, from the attention scores ˜ a = (˜ a t ) T S t =1 , the attention weights a = ( a t ) T S t =1 for all words are computed as
|
| 110 |
+
|
| 111 |
+
<!-- formula-not-decoded -->
|
| 112 |
+
|
| 113 |
+
The weighted instance representation h a is calculated as
|
| 114 |
+
|
| 115 |
+
<!-- formula-not-decoded -->
|
| 116 |
+
|
| 117 |
+
Finally, h a is fed to a dense layer Dec , and the output activation function is then used to obtain the predictions:
|
| 118 |
+
|
| 119 |
+
<!-- formula-not-decoded -->
|
| 120 |
+
|
| 121 |
+
where σ is a sigmoid function, and | y | is the label set size.
|
| 122 |
+
|
| 123 |
+
## B. MODEL WITH ATTENTION MECHANISMS FOR PAIR SEQUENCE TASK
|
| 124 |
+
|
| 125 |
+
For a pair sequence task, such as the QA and NLI tasks, the input is X P = ( x ( p ) t ) T P t =1 ∈ R T P ×| V | and X Q = ( x ( q ) t ) T Q t =1 ∈ R T Q ×| V | . T P and T Q are the number of words in each sentence. X P and X Q represent the paragraph and question in the QA and the hypothesis and premise in the NLI. We used two separate BiRNN encoders to obtain the hidden states h ( p ) t ∈ R m and h ( q ) t ∈ R m :
|
| 126 |
+
|
| 127 |
+
<!-- formula-not-decoded -->
|
| 128 |
+
|
| 129 |
+
where h ( p ) 0 and h ( q ) 0 are the initial hidden states and are regarded as zero vectors. Next, we computed the attention weight ˜ a t of each word of X P as:
|
| 130 |
+
|
| 131 |
+
<!-- formula-not-decoded -->
|
| 132 |
+
|
| 133 |
+
where W 1 ∈ R ′ d × m and W 2 ∈ R d ′ × m denote the projection matrices, and b , c ∈ R d ′ are the parameter vectors. Similar to Eq. 3, the attention weight a t can be calculated from ˜ a t . The presentation is obtained from a sum of words in X P .
|
| 134 |
+
|
| 135 |
+
<!-- formula-not-decoded -->
|
| 136 |
+
|
| 137 |
+
is fed to a Dec , and then a softmax function is used as σ to obtain the prediction (in the same manner as in Eq. 5).
|
| 138 |
+
|
| 139 |
+
## C. TRAINING MODEL WITH ATTENTION MECHANISMS
|
| 140 |
+
|
| 141 |
+
Let X ˜ a be an input sequence with attention score ˜ a , where ˜ a is a concatenated attention score for all t . We model the conditional probability of the class y as p ( y | X ˜ a ; θ ) , where θ represents all model parameters. For training the model, we minimize the following negative log likelihood as a loss function with respect to the model parameters:
|
| 142 |
+
|
| 143 |
+
<!-- formula-not-decoded -->
|
| 144 |
+
|
| 145 |
+
## IV. ADVERSARIAL TRAINING FOR ATTENTION MECHANISMS
|
| 146 |
+
|
| 147 |
+
The main contribution of this paper is to explore the idea of employing AT for attention mechanisms. In this paper, we propose a new training technique for attention mechanisms based on AT, called Attention AT and Attention iAT. The proposed techniques aim to achieve better regularization effects and to provide better interpretation of attention in the sentence. These techniques are the first application of AT to the attention in each word, which is expected to be more interpretable, with reference to AT for word embeddings [18] and a technique more focused on interpretability [19]. In this paper, we generate adversarial perturbations based on the model described in Section III.
|
| 148 |
+
|
| 149 |
+
## A. ATTENTION AT: ADVERSARIAL TRAINING FOR ATTENTION
|
| 150 |
+
|
| 151 |
+
We describe the proposed Attention AT, which features adversarial perturbations in the attention mechanisms rather than in the word embeddings [18], [19]. The adversarial perturbation on the mechanisms is defined as the worst-case perturbation on attention mechanisms of a small bounded norm ϵ that maximizes loss function L of the current model:
|
| 152 |
+
|
| 153 |
+
<!-- formula-not-decoded -->
|
| 154 |
+
|
| 155 |
+
where X ˜ a + r is the input sequence with attention score ˜ a , its perturbation r , y is the target output, and ˆ θ represents the current model parameters. We apply the fast gradient method [11], [18], i.e., first-order approximation to obtain an approximate worst-case perturbation of norm ϵ , through a single gradient computation as follows:
|
| 156 |
+
|
| 157 |
+
<!-- formula-not-decoded -->
|
| 158 |
+
|
| 159 |
+
ϵ is a hyper-parameter to be determined using the validation dataset. We find this r AT against the current model parameterized by ˆ θ at each training step and construct an adversarial perturbation for attention score ˜ a :
|
| 160 |
+
|
| 161 |
+
<!-- formula-not-decoded -->
|
| 162 |
+
|
| 163 |
+
## B. ATTENTION IAT: INTERPRETABLE ADVERSARIAL TRAINING FOR ATTENTION
|
| 164 |
+
|
| 165 |
+
We describe the proposed Attention iAT for further boosting the prediction performance and the interpretability of NLP tasks. Rather than utilizing AT to attention mechanisms (as described in Section IV-A), Attention iAT effectively exploits differences in the attention to each word in a sentence for the training. As a result, this technique provides cleaner attention in the sentence and improves the interpretability of the attention. These effects contribute to improving the performance of various NLP tasks.
|
| 166 |
+
|
| 167 |
+
In terms of formulation, the proposed Attention iAT is analogous to interpretable AT for word embeddings (Word iAT) [19], which increases the interpretability of AT for word embeddings in formulas. However, the implications and effects for training the model are very different; in the proposed Attention iAT, the attention difference enhancement , described later, enhances the difference in attention for each word. The difference and its effect will be explained later in this section and discussed in Section VII-C.
|
| 168 |
+
|
| 169 |
+
Suppose ˜ a t denotes the attention score corresponding to the t -th position in the sentence. We define the difference vector d t as the difference between the attention to the t -th word ˜ a t in a sentence and the attention to any k -th word ˜ a k :
|
| 170 |
+
|
| 171 |
+
<!-- formula-not-decoded -->
|
| 172 |
+
|
| 173 |
+
T = T S in single sequence task, and T = T P in a pair sequence task. By normalizing the norm of the vector, we define a normalized difference vector of the attention for the t -th word:
|
| 174 |
+
|
| 175 |
+
<!-- formula-not-decoded -->
|
| 176 |
+
|
| 177 |
+
The number of dimensions in d k is the number of the vocabulary (fixed length) for Word iAT, while the dimension of words in a sentence (variable length) for Attention iAT. The dimensionality of d t in Attention iAT is much smaller compared to Word iAT. 3 We define perturbation r ( α t ) for attention to the t -th word with trainable parameters α t = ( α t,k ) T t =1 ∈ R T and the normalized difference vector of the attention ˜ d t as follows:
|
| 178 |
+
|
| 179 |
+
<!-- formula-not-decoded -->
|
| 180 |
+
|
| 181 |
+
By combining α t for all t , we can calculate perturbation r ( α ) for the sentence:
|
| 182 |
+
|
| 183 |
+
<!-- formula-not-decoded -->
|
| 184 |
+
|
| 185 |
+
Then, similar to X ˜ a + r in Eq. 10, we introduce X ˜ a + r ( α ) and seek the worst-case weights of the difference vectors that maximize the loss functions as follows:
|
| 186 |
+
|
| 187 |
+
<!-- formula-not-decoded -->
|
| 188 |
+
|
| 189 |
+
Contrary to Attention iAT, in Word iAT, the difference d t,k in Eq. 13 is defined as the distance between the t -th word
|
| 190 |
+
|
| 191 |
+
3 This normalization is done on a sentence-by-sentence basis, so it does not matter that the dimension is varies ( T << V ).
|
| 192 |
+
|
| 193 |
+
<!-- image -->
|
| 194 |
+
|
| 195 |
+
in a sentence and the k -th word in the vocabulary in the word embedding space. Based on the distance, Word iAT determines the direction of perturbation for the t -th word as a linear sum of the word directional vectors in the vocabulary. In contrast, Attention iAT does not compute the distance to word embeddings in the vocabulary. Instead, this technique computes the difference in attention to other words in the sentence and determines the direction of the perturbation. The adversarial perturbation of Attention iAT, defined in this way, works to increase the difference in attention to each word. We call this process in Attention iAT as attention difference enhancement . Owing to the process, Attention iAT improves the interpretability of attention and contributes to the performance of the model's prediction. The detail discussions are shared in Section VII-C.
|
| 196 |
+
|
| 197 |
+
For computational efficiency, we calculate the interpretable adversarial perturbation by applying the same approximation method as in Eq. 11:
|
| 198 |
+
|
| 199 |
+
<!-- formula-not-decoded -->
|
| 200 |
+
|
| 201 |
+
Then, similar to Eq. 12, we construct a perturbated example for attention score ˜ a :
|
| 202 |
+
|
| 203 |
+
<!-- formula-not-decoded -->
|
| 204 |
+
|
| 205 |
+
C. TRAINING A MODEL WITH ADVERSARIAL TRAINING At each training step, we generate adversarial perturbation in the current model. To this end, we define the loss function for adversarial training as follows:
|
| 206 |
+
|
| 207 |
+
<!-- formula-not-decoded -->
|
| 208 |
+
|
| 209 |
+
where λ is the coefficient that controls the balance between two loss functions. Note that X ˜ a ADV can be X ˜ a adv for Attention AT or X ˜ a iadv for Attention iAT.
|
| 210 |
+
|
| 211 |
+
## V. EXPERIMENTS
|
| 212 |
+
|
| 213 |
+
In this section, we describe the evaluation tasks and datasets, the details of the models, and the evaluation criteria.
|
| 214 |
+
|
| 215 |
+
## A. TASKS AND DATASETS
|
| 216 |
+
|
| 217 |
+
We evaluated the proposed techniques using the open benchmark tasks (i.e., four BCs, four QAs, and two NLIs) used in Jain and Wallace [10]. In our experiment, we added MultiNLI [41] as an additional NLI task for more detailed analysis (see the details in Appendix A). Table 1 presents the statistics for all datasets. We split the dataset into a training set, a validation set, and a test set. 4 We performed preprocessing, including tokenization with spaCy 5 , mapping out vocabulary words to a special <unk> token, and mapping all words with numeric characters to qqq in the same manner as Jain and Wallace [10].
|
| 218 |
+
|
| 219 |
+
4 Jain and Wallace [10] split the dataset into only a training set and a test set, so we did not get the same results.
|
| 220 |
+
|
| 221 |
+
5 spaCy · Industrial-strength Natural Language Processing in Python https: //spacy.io/
|
| 222 |
+
|
| 223 |
+
<!-- image -->
|
| 224 |
+
|
| 225 |
+
TABLE 1. Dataset statistics. We used the three most well-known NLP tasks for evaluation: binary classification (BC), question answering (QA), and natural language inference (NLI). We split the dataset into training, validation, and test sets. We performed preprocessing as shown at https://github.com/successar/AttentionExplanation in the same manner as Jain and Wallace [10]. See the details in Appendix A. Jain and Wallace [10] split the dataset into only a training set and a test set, so we did not get the same result.
|
| 226 |
+
|
| 227 |
+
| Task Dataset # class # train # valid # test # vocab Avg. # words Binary Classification (BC) SST [17] 2 6,920 872 1,821 13,723 18 IMDB [35] 2 17,186 4,294 4,353 12,485 171 20News [36] 2 1,145 278 357 5,986 110 AGNews [37] 2 51,000 9,000 3,800 13,713 35 Question Answering (QA) CNN news [38] 584 380,298 3,924 3,198 70,192 773 bAbI Task 1 6 8,500 1,500 1,000 22 39 Task 2 [39] 6 8,500 1,500 1,000 36 98 Task 3 6 8,500 1,500 1,000 37 313 Natural Language Inference (NLI) SNLI [40] 3 549,367 9,842 9,824 20,979 22 Multi NLI [41] 3 314,161 78,541 19,647 53,112 34 |
|
| 228 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 229 |
+
|
| 230 |
+
## B. MODEL SETTINGS
|
| 231 |
+
|
| 232 |
+
We compared the two proposed training techniques to four conventional training techniques. They were implemented using the same model architecture as described in Section III. Following Jain and Wallace [10], we used bi-directional long short-term memory (LSTM) [42] as the BiRNN-based encoder, including Enc , Enc P , and Enc Q . A total of six training techniques were evaluated in the experiments:
|
| 233 |
+
|
| 234 |
+
- Vanilla [10]: a model with attention mechanisms trained without the use of AT.
|
| 235 |
+
- Word AT [18]: word embeddings trained with AT.
|
| 236 |
+
- Word iAT [19]: word embeddings trained with iAT.
|
| 237 |
+
- Attention RP : attention to the word embeddings is trained with random perturbation (RP).
|
| 238 |
+
- Attention AT ( Proposed ): attention to the word embeddings is trained with AT.
|
| 239 |
+
- Attention iAT ( Proposed ): attention to the word embeddings is trained with iAT.
|
| 240 |
+
|
| 241 |
+
We implemented the training techniques above using the AllenNLP library with Interpret [43], [44]. Through the experiments, we set the hyper-parameter λ = 1 related to AT or iAT in Eq. 20. To ensure a fair comparison of the training techniques, we followed the configurations (e.g., initialization of word embedding, hidden size of the encoder, optimizer settings) used in the literature [10] (see the details in Appendix B).
|
| 242 |
+
|
| 243 |
+
Note that while Jain and Wallace [10] used a test set to adjust the model's hyper-parameters, we used a validation set. In adversarial training, the Allentune library [45] was used to adjust hyper-parameter ϵ , and we report the test scores for the model with the highest validation score.
|
| 244 |
+
|
| 245 |
+
## C. EVALUATION CRITERIA
|
| 246 |
+
|
| 247 |
+
First, we compared the prediction performance of each model for each task. As an evaluation metric of the prediction performance, we used the F1 score 6 , accuracy, and the microF1 score for the BC, QA, and NLI, respectively, as in [10].
|
| 248 |
+
|
| 249 |
+
6 The F1 score is a metric that harmonizes precision and recall.. Therefore, this score takes both false positives and false negatives into account.
|
| 250 |
+
|
| 251 |
+
Next, we compared how the attention weights obtained through the proposed AT-based technique agreed with the importance of words calculated by the gradients [26]. To evaluate the agreement, we compared the Pearson's correlations between the attention weights and the word importance of the gradient-based method. In [10], the Kendall tau, which represents rank correlation, was used to evaluate the relationship between attention and the word importance obtained by the gradients. Recently, however, it has been pointed out that rank correlations often misrepresent the relationship between the two due to the noise in the order of the low rankings [46]; we concurred with this, so we used Pearson's correlations.
|
| 252 |
+
|
| 253 |
+
Finally, we compared the effects of perturbation size ϵ of AT on the validation performance of the BC, QA, and NLI tasks with a fixed λ = 1 . We randomly choose the value of ϵ in the 0-30 range and ran the training 100 times. The configurations in [18], [19] were ϵ = 5 for Word AT and ϵ = 15 for Word iAT.
|
| 254 |
+
|
| 255 |
+
## VI. RESULTS
|
| 256 |
+
|
| 257 |
+
In this section, we share the results of the experiments. Table 2 presents the prediction performance and the Pearson's correlations between the attention weight for the words and word importance calculated from the model gradient. The most significant results are shown in bold.
|
| 258 |
+
|
| 259 |
+
## A. COMPARISON OF PREDICTION PERFORMANCE
|
| 260 |
+
|
| 261 |
+
In terms of prediction performance, the model that applied the proposed Attention AT/iAT demonstrated a clear advantage over the model without AT (as shown in Vanilla [10]) as well as other AT-based techniques (Word AT [18] and Word iAT [19]). The proposed technique achieved the best results in almost all benchmarks. For 20News and AGNews in the BC and bAbI task 1 in QA, the conventional techniques, including the Vanilla model, were sufficiently accurate (the score was higher than 95%), so the performance improvement of the proposed techniques to the tasks was limited to some extent. Meanwhile, Attention AT/iAT contributed to solid performance improvements in other complicated tasks.
|
| 262 |
+
|
| 263 |
+
TABLE 2. Comparison of prediction performance and the Pearson's correlation coefficients (Corr.) between the attention weight and the word importance of the gradient-based method. We used the same test metrics as in [10]: binary classification (BC), question answering (QA), and natural language inference (NLI). As an evaluation metrics of the prediction performance, we used the F1 score (F1), accuracy (Acc.), and the micro-F1 (Micro-F1) score for BC, QA, and NLI, respectively.
|
| 264 |
+
|
| 265 |
+
<!-- image -->
|
| 266 |
+
|
| 267 |
+
(a) Binary classification (BC)
|
| 268 |
+
|
| 269 |
+
| Model SST IMDB 20News AGNews F1 [%] Corr. F1 [%] Corr. F1 [%] Corr. F1 [%] Corr. Vanilla [10] 79.27 0.652 88.77 0.788 95.05 0.891 95.27 0.822 Word AT [18] 79.61 0.647 89.65 0.838 95.11 0.892 95.59 0.813 Word iAT [19] 79.57 0.643 89.64 0.839 95.14 0.893 95.62 0.809 Attention RP 81.90 0.531 89.79 0.628 96.09 0.883 96.08 0.792 Attention AT ( Proposed ) 81.72 0.852 90.00 0.819 96.69 0.868 96.12 0.835 Attention iAT ( Proposed ) 82.20 0.876 90.21 0.861 96.58 0.897 96.19 0.891 |
|
| 270 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 271 |
+
|
| 272 |
+
(b) Question answering (QA)
|
| 273 |
+
|
| 274 |
+
| Model CNN news bAbI Acc. [%] Corr. Task 1 Task 2 Task 3 Acc. [%] Corr. Acc. [%] Corr. Acc. [%] Corr. Vanilla [10] 64.95 0.765 99.90 0.714 45.10 0.459 52.00 0.387 Word AT [18] 65.67 0.779 100.00 0.797 79.50 0.657 55.10 0.439 Word iAT [19] 65.66 0.776 99.90 0.798 79.80 0.658 54.90 0.437 Attention RP 65.78 0.614 100.00 0.592 80.60 0.584 55.35 0.373 Attention AT ( Proposed ) 65.93 0.771 100.00 0.807 82.30 0.632 56.00 0.514 Attention iAT ( Proposed ) 66.17 0.784 100.00 0.821 85.40 0.710 57.10 0.589 |
|
| 275 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 276 |
+
|
| 277 |
+
(c) Natural language inference (NLI)
|
| 278 |
+
|
| 279 |
+
| Model SNLI Multi NLI Micro-F1 [%] Corr. Micro-F1 [%] Corr. Avg. Matched Mismatched Vanilla [10] 78.64 0.764 60.26 59.80 60.71 0.541 Word AT [18] 79.03 0.812 60.72 60.58 60.86 0.601 Word iAT [19] 79.12 0.815 60.73 60.59 60.87 0.603 Attention RP 79.23 0.569 60.97 61.02 60.91 0.547 Attention AT ( Proposed ) 79.19 0.792 61.17 61.20 61.13 0.626 Attention iAT ( Proposed ) 79.32 0.818 61.34 61.75 60.93 0.668 |
|
| 280 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 281 |
+
|
| 282 |
+
## B. COMPARISON OF CORRELATION BETWEEN ATTENTION WEIGHTS AND GRADIENTS ON WORD IMPORTANCE
|
| 283 |
+
|
| 284 |
+
In terms of model interpretability, the attention to the words obtained with the Attention AT/iAT techniques notably correlated with the importance of the word as determined by the gradients. Attention iAT demonstrated the highest correlation among the techniques in all benchmarks. Figure 3 visualizes the attention weight for each word and gradientbased word importance in the SST test dataset. Attention AT yielded clearer attention compared to the Vanilla model or Attention iAT. Specifically, Attention AT tended to strongly focus attention on a few words. Regarding the correlation of word importance based on attention weights and gradientbased word importance, Attention iAT demonstrated higher similarities than the other models.
|
| 285 |
+
|
| 286 |
+
## C. EFFECTS OF PERTURBATION SIZE
|
| 287 |
+
|
| 288 |
+
Figure 4 shows the effect of the perturbation size ϵ on the validation performance of SST (BC), CNN news (QA), and Multi NLI (NLI) with a fixed λ = 1 . We observed that the performances of the conventional Word AT/iAT techniques deteriorated according to the increase in the perturbation size; meanwhile, our Attention AT/iAT techniques maintained almost the same prediction performance. We observed similar trends in other datasets as described in Section V-A.
|
| 289 |
+
|
| 290 |
+
## VII. DISCUSSION
|
| 291 |
+
|
| 292 |
+
## A. COMPARISON OF ADVERSARIAL TRAINING FOR ATTENTION MECHANISMS AND WORD EMBEDDING
|
| 293 |
+
|
| 294 |
+
Attention AT/iAT is based on our hypothesis that attention is more important in finding significant words in document processing than the word embeddings themselves. Therefore,
|
| 295 |
+
|
| 296 |
+
<!-- image -->
|
| 297 |
+
|
| 298 |
+
<!-- image -->
|
| 299 |
+
|
| 300 |
+
| (a) Vanilla (b) ( Proposed ) Attention AT |
|
| 301 |
+
|--------------------------------------------------|
|
| 302 |
+
|
| 303 |
+
(c)
|
| 304 |
+
|
| 305 |
+
(
|
| 306 |
+
|
| 307 |
+
Proposed
|
| 308 |
+
|
| 309 |
+
) Attention iAT
|
| 310 |
+
|
| 311 |
+
FIGURE 3. Visualization of attention weight for each word and word importance calculated by gradients on the SST dataset. Best viewed in color. The models that apply the proposed Attention AT/iAT give clearer attention. In terms of word importance, Attention iAT has more similar attention-based and gradient-based results than the other methods.
|
| 312 |
+
|
| 313 |
+
we sought to achieve prediction performance and model interpretability by introducing AT to the attention mechanisms. We confirmed that the application of AT to the attention mechanisms (Attention AT/iAT) was more effective than word embedding (Word AT/iAT) and supports the correctness of our hypothesis, as shown in Table 2. In particular, the Attention iAT technique was not only more accurate in its model than the Word AT/iAT techniques but also demonstrated a higher correlation with the importance of the words predicted based on the gradient.
|
| 314 |
+
|
| 315 |
+
As shown in Figure 3, Attention AT tended to display more attention to the sentence than the Vanilla model. The results showed that training with adversarial perturbations to the attention mechanism allowed for cleaner attention without changing word meanings or grammatical functions. Furthermore, we confirmed that the proposed Attention AT/iAT techniques were more robust regarding the variation of perturbation size ϵ than conventional Word AT/iAT, as shown in Figure 4. Although it is difficult to directly compare perturbations to attention and word embedding because of the difference in the range of the perturbation size to the part, the model that added perturbations to attention behaved robustly even when the perturbations were relatively large.
|
| 316 |
+
|
| 317 |
+
## B. COMPARISON OF RANDOM PERTURBATIONS AND ADVERSARIAL PERTURBATIONS
|
| 318 |
+
|
| 319 |
+
Attention RP demonstrated better prediction performance than Word AT/iAT. The results revealed that augmentation for the attention mechanism is very effective, even with simple random noise. In contrast, the correlations between the attention weight for the word and the gradient-based word importance were significantly reduced, as shown in Table 2. Weconsider that Attention RP is successful in learning robust discriminative boundaries through random perturbation and improving to the desired classification performance. However, as the gradient is smoothed out by the perturbation around the (supervised) data points, the correlation with the word importance by the gradient is considered to be degraded. In other words, Attention RP can achieve a certain level of classification performance, but it does not lead to which words are useful from their gradients.
|
| 320 |
+
|
| 321 |
+
<!-- image -->
|
| 322 |
+
|
| 323 |
+
FIGURE 4. The effect of perturbation size ϵ on the validation performance. We observed that the model with Attention AT/iAT maintained an almost constant prediction performance even when the perturbation size increased. Compared to Word AT/iAT, The model with the proposed techniques, Attention AT/iAT, was more robust with a large ϵ .
|
| 324 |
+
|
| 325 |
+
<!-- image -->
|
| 326 |
+
|
| 327 |
+
## C. COMPARISON OF ATTENTION AT, ATTENTION IAT, AND WORD IAT
|
| 328 |
+
|
| 329 |
+
In the experiments, Attention iAT showed a better performance compared Attention AT in the prediction performance and the correlation with the gradient-based word importance. Attention iAT exploits the difference in the attention weight of each word in a sentence to determine adversarial perturbations. Because the norm of the difference in attention weight (as shown in Eq. 14) is normalized to one, adversarial perturbations in attention mechanisms will make these differences clear, especially in the case of sentences with a small difference in the attention to each word. That is, even in situations where there is little difference in attention between each element of d t = ( d t, 1 , d t, 2 , · · · , d t,T ) , the difference is amplified by Eq. 14. Therefore, even for the same perturbation size || α || < ϵ , more effective perturbations r ( α ) weighted by ˜ d t were successfully obtained for each word. However, in the case of sentences where there was originally a difference in the clear attention to each word, the regularization of d t in Eq. 14 had practically no effect because it did not change their ratio nearly as much. Thus, we posit that the Attention iAT technique enhances the effectiveness of AT applied to attention mechanisms by generating effective perturbations for each word.
|
| 330 |
+
|
| 331 |
+
The Attention iAT technique was inspired by Word iAT. Word iAT generates perturbations in the direction that maxi- mizes the loss function while restricting the direction of the perturbation to become a linear combination of the direction of word embedding in the vocabulary. Word iAT indirectly improves the interpretability of the model by indicating which words in the vocabulary to which the perturbation is similar. However, we are confident that Attention iAT is a direct improvement in the interpretability of the model, because it can show more clearly which words to pay attention. This is owing to the attention difference enhancement process described in Eq. 14. Thus, the proposed techniques are highly effective in that they lead to a more substantive improvement in interpretability.
|
| 332 |
+
|
| 333 |
+
## D. LIMITATIONS
|
| 334 |
+
|
| 335 |
+
Our proposal is a general-purpose robust training technique for DNN models, which are commonly used for NLP tasks. Therefore, we have chosen here an RNN with an attention mechanism that has been put to practical use [10]. For this reason, models such as BERT [47] that deal with selfattention were outside the scope of this study, and will be the subject of future work. We also did not deal with tasks (such as machine translation) that were not used in the literature [10] as baselines. Additionally, for the same reason in as [48], we did not consider the variants of attention mechanisms, such as bi-attentive architecture [5], multiheaded architecture [8], because they could have different interpretability properties.
|
| 336 |
+
|
| 337 |
+
As an extension of AT, virtual adversarial training (V AT), which is a semi-supervised training technique, was proposed in [18], [49]. Based on VAT, the proposed technique can be expected to improve accuracy by using unlabeled datasets.
|
| 338 |
+
|
| 339 |
+
## VIII. CONCLUSION
|
| 340 |
+
|
| 341 |
+
We proposed robust and interpretable attention training techniques that exploit AT. In the experiments with various NLP tasks, we confirmed that AT for attention mechanisms achieves better performance than techniques using AT for word embedding in terms of the prediction performance and the interpretability of the model. Specifically, the Attention iAT technique introduced adversarial perturbations that em- phasized differences in the importance of words in a sentence and combined high accuracy with interpretable attention, which was more strongly correlated with the gradient-based method of word importance. The proposed technique could be applied to various models and NLP tasks. This paper provides strong support and motivation for utilizing AT with attention mechanisms in NLP tasks.
|
| 342 |
+
|
| 343 |
+
<!-- image -->
|
| 344 |
+
|
| 345 |
+
In the experiment, we demonstrated the effectiveness of the proposed techniques for RNN models that are reported to be vulnerable to attention mechanisms, but we will confirm the effectiveness of the proposed technique for large language models with attention mechanisms such as Transformer [8] or BERT [47] in the future. Because the proposed techniques are model-independent and general techniques for attention mechanisms, we can expect they will improve predictability and the interpretability for language models.
|
| 346 |
+
|
| 347 |
+
.
|
| 348 |
+
|
| 349 |
+
## APPENDIX A TASKS AND DATASET
|
| 350 |
+
|
| 351 |
+
## A. BINARY CLASSIFICATION
|
| 352 |
+
|
| 353 |
+
The following datasets were used for evaluation. The Stanford Sentiment Treebank (SST) [17] 7 was used to ascertain positive or negative sentiment from a sentence. IMDB Large Movie Reviews (IMDB) [35] 8 , 9 was used to identify positive or negative sentiment from movie reviews. 20 Newsgroups (20News) [36] 10 were used to ascertain the topic of news articles as either baseball (set as a negative label) or hockey (set as a positive label). The AG News (AGNews) [37] 11 was used to identify the topic of news articles as either world (set as a negative label) or business (set as a positive label).
|
| 354 |
+
|
| 355 |
+
## B. QUESTION ANSWERING
|
| 356 |
+
|
| 357 |
+
The following datasets were used for evaluation. The CNN news article corpus (CNN news) [38] 12 was used to identify answer entities from a paragraph. The bAbI dataset (bAbI) [39] 13 contains 20 different question-answer tasks, and we considered three tasks: (task 1) basic factoid question answered with a single supporting fact, (task 2) factoid question answered with two supporting facts, and (task 3) factoid question answered with three supporting facts. The model was trained for each task.
|
| 358 |
+
|
| 359 |
+
## C. NATURAL LANGUAGE INFERENCE
|
| 360 |
+
|
| 361 |
+
The following datasets were used for evaluation. The Stanford Natural Language Inference (SNLI) [40] 14 is used to identify whether a hypothesis sentence entails, contradicts, or is neutral concerning a given premise sentence. Multi-Genre NLI (MultiNLI) [41] 15 uses the same format as SNLI and is comparable in size, but it includes a more diverse range of text, as well as an auxiliary test set for cross-genre transfer evaluation.
|
| 362 |
+
|
| 363 |
+
[7 https://nlp.stanford.edu/sentiment/trainDevTestTrees\_PTB.zip](https://nlp.stanford.edu/sentiment/trainDevTestTrees_PTB.zip)
|
| 364 |
+
|
| 365 |
+
[8 https://s3.amazonaws.com/text-datasets/imdb\_full.pkl](https://s3.amazonaws.com/text-datasets/imdb_full.pkl)
|
| 366 |
+
|
| 367 |
+
[9 https://s3.amazonaws.com/text-datasets/imdb\_word\_index.json](https://s3.amazonaws.com/text-datasets/imdb_word_index.json)
|
| 368 |
+
|
| 369 |
+
[10 https://ndownloader.figshare.com/files/5975967](https://ndownloader.figshare.com/files/5975967)
|
| 370 |
+
|
| 371 |
+
11 The dataset can be found on Xiang Zhang's Google Drive.
|
| 372 |
+
|
| 373 |
+
12 The dataset can be found on Deep Mind Q&A Google Drive.
|
| 374 |
+
|
| 375 |
+
[13 https://research.fb.com/downloads/babi/](https://research.fb.com/downloads/babi/)
|
| 376 |
+
|
| 377 |
+
[14 https://nlp.stanford.edu/projects/snli/snli\_1.0.zip](https://nlp.stanford.edu/projects/snli/snli_1.0.zip)
|
| 378 |
+
|
| 379 |
+
[15 https://www.nyu.edu/projects/bowman/multinli/multinli\_1.0.zip](https://www.nyu.edu/projects/bowman/multinli/multinli_1.0.zip)
|
| 380 |
+
|
| 381 |
+
## APPENDIX B IMPLEMENTATION DETAIL
|
| 382 |
+
|
| 383 |
+
For all datasets, we either used pretrained GloVe [50] or fastText [51] word embedding with 300 dimensions except the bAbI dataset. For the bAbI dataset, we trained 50 dimensional word embeddings from scratch during training. We used a one-layer LSTM as the encoder with a hidden size of 64 for the bAbI dataset and 256 for the other datasets. All models were regularized using L 2 regularization ( 10 -5 ) applied to all parameters. We trained the model using the maximum likelihood loss utilizing the Adam [52] optimizer with a learning rate of 0.001.
|
| 384 |
+
|
| 385 |
+
## ACKNOWLEDGMENT
|
| 386 |
+
|
| 387 |
+
We would like to appreciate the editors and anonymous reviewers for their helpful feedback. We also thank Quan Huu Cap and Mahmoud Daif for feedback and fruitful discussions.
|
| 388 |
+
|
| 389 |
+
## REFERENCES
|
| 390 |
+
|
| 391 |
+
- [1] D. Bahdanau, K. Cho, and Y. Bengio, 'Neural machine translation by jointly learning to align and translate,' CoRR preprint arXiv:1409.0473, 2014. [Online]. Available: https://arxiv.org/abs/1409.0473
|
| 392 |
+
- [2] Z. Lin, M. Feng, C. N. dos Santos, M. Yu, B. Xiang, B. Zhou, and Y. Bengio, 'A structured self-attentive sentence embedding,' in Proc. of the 5th International Conference on Learning Representations, ICLR, Conference Track Proceedings, 2017. [Online]. Available: https://openreview.net/forum?id=BJC\_jUqxe&noteId=BJC\_jUqxe
|
| 393 |
+
- [3] Y. Wang, M. Huang, and L. Zhao, 'Attention-based LSTM for aspectlevel sentiment classification,' in Proc. of the 2016 Conference on Empirical Methods in Natural Language Processing, ser. Association for Computational Linguistics (ACL), 2016, pp. 606-615. [Online]. Available: http://dx.doi.org/10.18653/v1/D16-1058
|
| 394 |
+
- [4] X. He and D. Golub, 'Character-level question answering with attention,' in Proc. of the 2016 Conference on Empirical Methods in Natural Language Processing, ser. Association for Computational Linguistics (ACL), 2016, pp. 1598-1607. [Online]. Available: http: //dx.doi.org/10.18653/v1/D16-1166
|
| 395 |
+
- [5] A. Parikh, O. Täckström, D. Das, and J. Uszkoreit, 'A decomposable attention model for natural language inference,' in Proc. of the 2016 Conference on Empirical Methods in Natural Language Processing, ser. Association for Computational Linguistics (ACL), 2016, pp. 2249-2255. [Online]. Available: http://dx.doi.org/10.18653/v1/D16-1244
|
| 396 |
+
- [6] T. Luong, H. Pham, and C. D. Manning, 'Effective approaches to attention-based neural machine translation,' in Proc. of the 2015 Conference on Empirical Methods in Natural Language Processing, ser. Association for Computational Linguistics (ACL), 2015, pp. 1412-1421. [Online]. Available: http://dx.doi.org/10.18653/v1/D15-1166
|
| 397 |
+
- [7] A. M. Rush, S. Chopra, and J. Weston, 'A neural attention model for abstractive sentence summarization,' in Proc. of the 2015 Conference on Empirical Methods in Natural Language Processing, ser. Association for Computational Linguistics (ACL), 2015, pp. 379-389. [Online]. Available: http://dx.doi.org/10.18653/v1/D15-1044
|
| 398 |
+
- [8] A. Vaswani, N. Shazeer, N. Parmar, J. Uszkoreit, L. Jones, A. N. Gomez, Ł. Kaiser, and I. Polosukhin, 'Attention is all you need,' in Proc. of the 30th International Conference on Neural Information Processing Systems, 2017, pp. 5998-6008. [Online]. Available: https: //arxiv.org/abs/1706.03762
|
| 399 |
+
- [9] C. Szegedy, W. Zaremba, I. Sutskever, J. Bruna, D. Erhan, I. Goodfellow, and R. Fergus, 'Intriguing properties of neural networks,' in 2nd International Conference on Learning Representations, ICLR, Conference Track Proceedings, 2013. [Online]. Available: https://arxiv.org/abs/1312. 6199
|
| 400 |
+
|
| 401 |
+
- [10] S. Jain and B. C. Wallace, 'Attention is not explanation,' in Proc. of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers), ser. Association for Computational Linguistics (ACL), 2019, pp. 3543-3556. [Online]. Available: http://dx.doi.org/10.18653/v1/N19-1357
|
| 402 |
+
- [11] Y. Liu, X. Chen, C. Liu, and D. Song, 'Delving into transferable adversarial examples and black-box attacks,' CoRR preprint arXiv:1611.02770, 2016. [Online]. Available: https://arxiv.org/abs/1611.02770
|
| 403 |
+
- [12] Y. Liu, M. Ott, N. Goyal, J. Du, M. Joshi, D. Chen, O. Levy, M. Lewis, L. Zettlemoyer, and V. Stoyanov, 'Roberta: A robustly optimized bert pretraining approach,' CoRR preprint arXiv:1907.11692, 2019. [Online]. Available: https://arxiv.org/abs/1907.11692
|
| 404 |
+
- [13] Z. Lan, M. Chen, S. Goodman, K. Gimpel, P. Sharma, and R. Soricut, 'Albert: A lite bert for self-supervised learning of language representations,' in International Conference on Learning Representations, 2020. [Online]. Available: https://openreview.net/forum?id=H1eA7AEtvS
|
| 405 |
+
- [14] Y. Tay, M. Dehghani, D. Bahri, and D. Metzler, 'Efficient transformers: A survey,' CoRR preprint arXiv:2009.06732, 2020. [Online]. Available: https://arxiv.org/abs/2009.06732
|
| 406 |
+
- [15] I. J. Goodfellow, J. Shlens, and C. Szegedy, 'Explaining and harnessing adversarial examples,' in 3rd International Conference on Learning Representations, ICLR, Conference Track Proceedings, 2014. [Online]. Available: http://arxiv.org/abs/1412.6572
|
| 407 |
+
- [16] U. Shaham, Y. Yamada, and S. Negahban, 'Understanding adversarial training: Increasing local stability of supervised models through robust optimization,' Neurocomputing, vol. 307, pp. 195-204, 2018. [Online]. Available: https://doi.org/10.1016/j.neucom.2018.04.027
|
| 408 |
+
- [17] R. Socher, A. Perelygin, J. Wu, J. Chuang, C. D. Manning, A. Ng, and C. Potts, 'Recursive deep models for semantic compositionality over a sentiment treebank,' in Proc. of the 2013 Conference on Empirical Methods in Natural Language Processing, ser. Association for Computational Linguistics (ACL), 2013, pp. 1631-1642. [Online]. Available: https://www.aclweb.org/anthology/D13-1170/
|
| 409 |
+
- [18] T. Miyato, A. M. Dai, and I. Goodfellow, 'Adversarial training methods for semi-supervised text classification,' in 5th International Conference on Learning Representations, ICLR, Conference Track Proceedings, 2016. [Online]. Available: https://openreview.net/forum?id=r1X3g2\_xl
|
| 410 |
+
- [19] M. Sato, J. Suzuki, H. Shindo, and Y. Matsumoto, 'Interpretable adversarial perturbation in input embedding space for text,' in Proc. of the 27th International Joint Conference on Artificial Intelligence, ser. AAAI Press, 2018, pp. 4323-4330. [Online]. Available: https: //dl.acm.org/doi/10.5555/3304222.3304371
|
| 411 |
+
- [20] M. Yasunaga, J. Kasai, and D. Radev, 'Robust multilingual part-of-speech tagging via adversarial training,' in Proc. of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long Papers), ser. Association for Computational Linguistics (ACL), 2018, pp. 976-986. [Online]. Available: http://dx.doi.org/10.18653/v1/N18-1089
|
| 412 |
+
- [21] Y. Wang and M. Bansal, 'Robust machine comprehension models via adversarial training,' in Proc. of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 2 (Short Papers), ser. Association for Computational Linguistics (ACL), 2018, pp. 575-581. [Online]. Available: http://dx.doi.org/10.18653/v1/N18-2091
|
| 413 |
+
- [22] J. Li, W. Monroe, and D. Jurafsky, 'Understanding neural networks through representation erasure,' CoRR preprint arXiv:1612.08220, 2016. [Online]. Available: https://arxiv.org/abs/1612.08220
|
| 414 |
+
- [23] D. Tsipras, S. Santurkar, L. Engstrom, A. Turner, and A. Madry, 'Robustness may be at odds with accuracy,' in International Conference on Learning Representations, no. 2019, 2019. [Online]. Available: https://openreview.net/forum?id=SyxAb30cY7
|
| 415 |
+
- [24] T. Itazuri, Y. Fukuhara, H. Kataoka, and S. Morishima, 'What do adversarially robust models look at?' CoRR preprint arXiv:1905.07666, 2019. [Online]. Available: https://arxiv.org/abs/1905.07666
|
| 416 |
+
- [25] T. Zhang and Z. Zhu, 'Interpreting adversarially trained convolutional neural networks,' in International Conference on Machine Learning. PMLR, 2019, pp. 7502-7511. [Online]. Available: http://proceedings.mlr. press/v97/zhang19s.html
|
| 417 |
+
- [26] K. Simonyan, A. Vedaldi, and A. Zisserman, 'Deep inside convolutional networks: Visualising image classification models and saliency maps,' in 2nd International Conference on Learning Representations, ICLR, Workshop Track Proceedings, 2013. [Online]. Available: https://arxiv.org/ abs/1312.6034
|
| 418 |
+
- [27] B. Wang, J. Gao, and Y. Qi, 'A theoretical framework for robustness of (deep) classifiers against adversarial examples,' CoRR preprint arXiv:1612.00334, 2016. [Online]. Available: https://arxiv.org/abs/1612. 00334
|
| 419 |
+
- [28] K. Liu, X. Liu, A. Yang, J. Liu, J. Su, S. Li, and Q. She, 'A robust adversarial training approach to machine reading comprehension,' in Proc. of the AAAI Conference on Artificial Intelligence, vol. 34, no. 05, 2020, pp. 8392-8400. [Online]. Available: https://doi.org/10.1609/aaai. v34i05.6357
|
| 420 |
+
- [29] S. Barham and S. Feizi, 'Interpretable adversarial training for text,' CoRR preprint arXiv:1905.12864, 2019. [Online]. Available: https: //arxiv.org/abs/1905.12864
|
| 421 |
+
- [30] Q. Zhu, L. Cui, W.-N. Zhang, F. Wei, and T. Liu, 'Retrieval-enhanced adversarial training for neural response generation,' in Proc. of the 57th Annual Meeting of the Association for Computational Linguistics. Association for Computational Linguistics, 2019, pp. 3763-3773. [Online]. Available: http://dx.doi.org/10.18653/v1/P19-1366
|
| 422 |
+
- [31] N. Srivastava, G. Hinton, A. Krizhevsky, I. Sutskever, and R. Salakhutdinov, 'Dropout: a simple way to prevent neural networks from overfitting,' The journal of machine learning research, vol. 15, no. 1, pp. 1929-1958, 2014. [Online]. Available: https://jmlr.org/papers/v15/srivastava14a.html
|
| 423 |
+
- [32] S. Ioffe and C. Szegedy, 'Batch normalization: Accelerating deep network training by reducing internal covariate shift,' in International Conference on Machine Learning, 2015, pp. 448-456. [Online]. Available: http://proceedings.mlr.press/v37/ioffe15.html
|
| 424 |
+
- [33] M. Iyyer, V. Manjunatha, J. Boyd-Graber, and H. Daumé III, 'Deep unordered composition rivals syntactic methods for text classification,' in Proc. of the 53rd Annual Meeting of the Association for Computational Linguistics and the 7th International Joint Conference on Natural Language Processing (Volume 1: Long Papers), 2015, pp. 1681-1691. [Online]. Available: http://dx.doi.org/10.3115/v1/P15-1162
|
| 425 |
+
- [34] D. Shimada, R. Kotani, and H. Iyatomi, 'Document classification through image-based character embedding and wildcard training,' in Proc. of IEEE International Conference on Big Data. IEEE, 2016, pp. 3922-3927. [Online]. Available: https://doi.org/10.1109/BigData.2016.7841067
|
| 426 |
+
- [35] A. L. Maas, R. E. Daly, P. T. Pham, D. Huang, A. Y. Ng, and C. Potts, 'Learning word vectors for sentiment analysis,' in Proc. of the 49th Annual Meeting of the Association for Computational Linguistics: Human Language Technologies, ser. Association for Computational Linguistics (ACL), vol. 1, 2011, pp. 142-150. [Online]. Available: https://www.aclweb.org/anthology/P11-1015/
|
| 427 |
+
- [36] K. Lang, 'Newsweeder: Learning to filter netnews,' in Machine Learning Proceedings. Elsevier, 1995, pp. 331-339. [Online]. Available: https://doi.org/10.1016/B978-1-55860-377-6.50048-7
|
| 428 |
+
- [37] X. Zhang, J. Zhao, and Y. LeCun, 'Character-level convolutional networks for text classification,' in Proc. of the 28th International Conference on Neural Information Processing Systems, ser. MIT Press, vol. 1, 2015, pp. 649-657. [Online]. Available: https://dl.acm.org/doi/10.5555/ 2969239.2969312
|
| 429 |
+
- [38] K. M. Hermann, T. Kocisky, E. Grefenstette, L. Espeholt, W. Kay, M. Suleyman, and P. Blunsom, 'Teaching machines to read and comprehend,' in Proc. of the 28th International Conference on Neural Information Processing Systems, ser. MIT Press, vol. 1, 2015, pp. 1693-1701. [Online]. Available: https://dl.acm.org/doi/10.5555/2969239. 2969428
|
| 430 |
+
- [39] J. Weston, A. Bordes, S. Chopra, and T. Mikolov, 'Towards AI-complete question answering: A set of prerequisite toy tasks,' in 4th International Conference on Learning Representations, ICLR, Conference Track Proceedings, 2016. [Online]. Available: https://arxiv.org/abs/1502.05698
|
| 431 |
+
- [40] S. Bowman, G. Angeli, C. Potts, and C. D. Manning, 'A large annotated corpus for learning natural language inference,' in Proc. of the 2015 Conference on Empirical Methods in Natural Language Processing, ser. Association for Computational Linguistics (ACL), 2015, pp. 632-642. [Online]. Available: http://dx.doi.org/10.18653/v1/D15-1075
|
| 432 |
+
- [41] A. Williams, N. Nangia, and S. R. Bowman, 'A broad-coverage challenge corpus for sentence understanding through inference,' in Proc. of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (Long Papers), ser. Association for Computational Linguistics (ACL), 2017. [Online]. Available: http://dx.doi.org/10.18653/v1/N18-1101
|
| 433 |
+
- [42] S. Hochreiter and J. Schmidhuber, 'Long short-term memory,' Neural Computation, vol. 9, no. 8, pp. 1735-1780, 1997. [Online]. Available: https://doi.org/10.1162/neco.1997.9.8.1735
|
| 434 |
+
|
| 435 |
+
<!-- image -->
|
| 436 |
+
|
| 437 |
+
<!-- image -->
|
| 438 |
+
|
| 439 |
+
- [43] M. Gardner, J. Grus, M. Neumann, O. Tafjord, P. Dasigi, N. Liu, M. Peters, M. Schmitz, and L. Zettlemoyer, 'Allennlp: A deep semantic natural language processing platform,' CoRR preprint arXiv:1803.07640, 2018. [Online]. Available: http://dx.doi.org/10.18653/v1/W18-2501
|
| 440 |
+
- [44] E. Wallace, J. Tuyls, J. Wang, S. Subramanian, M. Gardner, and S. Singh, 'AllenNLP Interpret: A framework for explaining predictions of NLP models,' in Proc. of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP): System Demonstrations, ser. Association for Computational Linguistics (ACL), 2019, pp. 7-12. [Online]. Available: http://dx.doi.org/10.18653/ v1/D19-3002
|
| 441 |
+
- [45] J. Dodge, S. Gururangan, D. Card, R. Schwartz, and N. A. Smith, 'Show your work: Improved reporting of experimental results,' in Proc. of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP), ser. Association for Computational Linguistics (ACL), 2019, pp. 2185-2194. [Online]. Available: http://dx.doi.org/10.18653/v1/D19-1224
|
| 442 |
+
- [46] A. K. Mohankumar, P. Nema, S. Narasimhan, M. M. Khapra, B. V. Srinivasan, and B. Ravindran, 'Towards transparent and explainable attention models,' in Proc. of the 58th Annual Meeting of the Association for Computational Linguistics, ser. Association for Computational Linguistics (ACL), 2020, pp. 4206-4216. [Online]. Available: http: //dx.doi.org/10.18653/v1/2020.acl-main.387
|
| 443 |
+
- [47] J. Devlin, M.-W. Chang, K. Lee, and K. Toutanova, 'Bert: Pretraining of deep bidirectional transformers for language understanding,' in Proc. of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers), ser. Association for Computational Linguistics (ACL), 2019, pp. 4171-4186. [Online]. Available: http://dx.doi.org/10.18653/v1/N19-1423
|
| 444 |
+
- [48] S. Serrano and N. A. Smith, 'Is attention interpretable?' in Proc. of the 57th Annual Meeting of the Association for Computational Linguistics, ser. Association for Computational Linguistics (ACL), 2019, pp. 2931-2951. [Online]. Available: http://dx.doi.org/10.18653/v1/P19-1282
|
| 445 |
+
- [49] T. Miyato, S.-i. Maeda, M. Koyama, and S. Ishii, 'Virtual adversarial training: a regularization method for supervised and semi-supervised learning,' IEEE transactions on pattern analysis and machine intelligence, vol. 41, no. 8, pp. 1979-1993, 2018. [Online]. Available: https: //doi.org/10.1109/TPAMI.2018.2858821
|
| 446 |
+
- [50] J. Pennington, R. Socher, and C. Manning, 'Glove: Global vectors for word representation,' in Proc. of the 2014 Conference on Empirical Methods in Natural Language Processing, ser. Association for Computational Linguistics (ACL), 2014, pp. 1532-1543. [Online]. Available: http://dx.doi.org/10.3115/v1/D14-1162
|
| 447 |
+
- [51] P. Bojanowski, E. Grave, A. Joulin, and T. Mikolov, 'Enriching word vectors with subword information,' Transactions of the Association for Computational Linguistics, vol. 5, pp. 135-146, 2017. [Online]. Available: http://dx.doi.org/10.1162/tacl\_a\_00051
|
| 448 |
+
- [52] D. P. Kingma and J. Ba, 'Adam: A method for stochastic optimization,' CoRR preprint arXiv:1412.6980, 2014. [Online]. Available: https: //arxiv.org/abs/1412.6980
|
text-versions/attention-markdown/2010.13154_Attention is All You Need in Speech Sepa.md
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2010.13154 Attention Is All You Need In Speech Sepa
|
| 2 |
+
|
| 3 |
+
## ATTENTION IS ALL YOU NEED IN SPEECH SEPARATION
|
| 4 |
+
|
| 5 |
+
Cem Subakan 1 , Mirco Ravanelli 1 , Samuele Cornell 2 , Mirko Bronzi 1 , Jianyuan Zhong 3
|
| 6 |
+
|
| 7 |
+
1 Mila-Quebec AI Institute, Canada, 2 Universit` a Politecnica delle Marche, Italy 3 University of Rochester, USA
|
| 8 |
+
|
| 9 |
+
Fig. 1 . The high-level description of our system: The encoder block estimates a learned-representation for the input signal, while the masking network estimates optimal masks to separate the sources present in the mixtures. The decoder finally reconstructs the estimated sources in the time domain using the masks provided by the masking network.
|
| 10 |
+
|
| 11 |
+
<!-- image -->
|
| 12 |
+
|
| 13 |
+
sequences to perform well. Current systems rely, in large part, on the learned-domain masking strategy popularized by Conv-TasNet [15]. In this framework, an overcomplete set of analysis and synthesis filters is learned directly from the data, and separation is performed by estimating a mask for each source in this learned-domain. Building on this, Dual-Path RNN (DPRNN) [17] has demonstrated that better long-term modeling is crucial to improve the separation performance. This is achieved by splitting the input sequence into multiple chunks that are processed locally and globally with different RNNs. Nevertheless, due to the use of RNNs, DPRNN still suffers from the aforementioned limitations of recurrent connections, especially regarding the global processing step. An attempt to integrate transformers into the speech separation pipeline has been recently done in [22] where the proposed Dual-Path Transformer Network (DPTNet) is shown to outperform the standard DPRNN. Such an architecture, however, still embeds an RNN, effectively negating the parallelization capability of pure-attention models.
|
| 14 |
+
|
| 15 |
+
In this paper, we propose a novel model called SepFormer (Separation Transformer), which is mainly composed of multi-head attention and feed-forward layers. We adopt the dual-path framework introduced by DPRNN and we replace RNNs with a multiscale pipeline composed of transformers that learn both short and long-term dependencies. The dual-path framework enables to mitigate the quadratic complexity of transformers, as transformers in the dual-path framework process smaller chunks.
|
| 16 |
+
|
| 17 |
+
To the best of our knowledge, this is the first work showing that we can obtain state-of-the-art performance in separation with an RNN-free Transformer-based architecture. The SepFormer achieves an SI-SNRi of 22.3 dB on the standard WSJ0-2mix dataset. It also achieves the SOTA performance of 19.5 dB SI-SNRi on the WSJ03mix dataset. The SepFormer not only processes all the time steps in parallel but also achieves competitive performance when downsampling the encoded representation by a factor of 8. This makes the proposed architecture significantly faster and less memory demand-
|
| 18 |
+
|
| 19 |
+
## ABSTRACT
|
| 20 |
+
|
| 21 |
+
Recurrent Neural Networks (RNNs) have long been the dominant architecture in sequence-to-sequence learning. RNNs, however, are inherently sequential models that do not allow parallelization of their computations. Transformers are emerging as a natural alternative to standard RNNs, replacing recurrent computations with a multi-head attention mechanism.
|
| 22 |
+
|
| 23 |
+
In this paper, we propose the SepFormer , a novel RNN-free Transformer-based neural network for speech separation. The SepFormer learns short and long-term dependencies with a multi-scale approach that employs transformers. The proposed model achieves state-of-the-art (SOTA) performance on the standard WSJ0-2/3mix datasets. It reaches an SI-SNRi of 22.3 dB on WSJ0-2mix and an SI-SNRi of 19.5 dB on WSJ0-3mix. The SepFormer inherits the parallelization advantages of Transformers and achieves a competitive performance even when downsampling the encoded representation by a factor of 8. It is thus significantly faster and it is less memory-demanding than the latest speech separation systems with comparable performance.
|
| 24 |
+
|
| 25 |
+
Index Terms -speech separation, source separation, transformer, attention, deep learning.
|
| 26 |
+
|
| 27 |
+
## 1. INTRODUCTION
|
| 28 |
+
|
| 29 |
+
RNNs are a crucial component of modern audio processing systems and they are used in many different domains, including speech recognition, synthesis, enhancement, and separation, just to name a few. Especially when coupled with multiplicative gate mechanisms (like LSTM [1] and GRU [2, 3]), their recurrent connections are essential to learn long-term dependencies and properly manage speech contexts. Nevertheless, the inherently sequential nature of RNNs impairs an effective parallelization of the computations. This bottleneck is particularly evident when processing large datasets with long sequences. On the other hand, Transformers [4] completely avoid this bottleneck by eliminating recurrence and replacing it with a fully attention-based mechanism. By attending to the whole sequence at once, a direct connection can be established between distant elements allowing Transformers to learn long-term dependencies more easily [5]. For this reason, Transformers are gaining considerable popularity for speech processing and recently showed competitive performance in speech recognition [6], synthesis [7], enhancement [8], diarization [9], as well as speaker recognition [10].
|
| 30 |
+
|
| 31 |
+
Little research has been done so far on Transformer-based models for monaural audio source separation. The field has been revolutionized by the adoption of deep learning techniques [11-16], and with recent works [17-23] achieving impressive results by adopting an end-to-end approach. Most of the current speech separation techniques [14, 15, 17-22] require effective modeling of long input ing than the latest RNN-based separation models.
|
| 32 |
+
|
| 33 |
+
## 2. THE MODEL
|
| 34 |
+
|
| 35 |
+
The proposed model is based on the learned-domain masking approach [14, 15, 17-22] and employs an encoder, a decoder, and a masking network, as shown in Figure 1. The encoder is fully convolutional, while the masking network employs two Transformers embedded inside the dual-path processing block proposed in [17]. The decoder finally reconstructs the separated signals in the time domain by using the masks predicted by the masking network. To foster reproducibility, the SepFormer will be made available within the SpeechBrain toolkit 1 .
|
| 36 |
+
|
| 37 |
+
## 2.1. Encoder
|
| 38 |
+
|
| 39 |
+
The encoder takes in the time-domain mixture-signal x ∈ R T as input, which contains audio from multiple speakers. It learns an STFT-like representation h ∈ R F × T ′ using a single convolutional layer:
|
| 40 |
+
|
| 41 |
+
<!-- formula-not-decoded -->
|
| 42 |
+
|
| 43 |
+
As we will describe in Sec. 4, the stride factor of this convolution impacts significantly on the performance, speed, and memory of the model.
|
| 44 |
+
|
| 45 |
+
## 2.2. Masking Network
|
| 46 |
+
|
| 47 |
+
Figure 2 (top) shows the detailed architecture of the masking network (Masking Net). The masking network is fed by the encoded representations h ∈ R F × T ′ and estimates a mask { m 1 , . . . , m Ns } for each of the Ns speakers in the mixture.
|
| 48 |
+
|
| 49 |
+
As in [15], the encoded input h is normalized with layer normalization [24] and processed by a linear layer (with dimensionality F ). We then create overlapping chunks of size C by chopping up h on the time axis with an overlap factor of 50%. We denote the output of the chunking operation with h ′ ∈ R F × C × Nc , where C is the length of each chunk, and Nc is the resulting number of chunks.
|
| 50 |
+
|
| 51 |
+
The representation h ′ feeds the SepFormer block, which is the main component of the masking network. This block, which will be described in detail in Sec. 2.3, employs a pipeline composed of two transformers able to learn short and long-term dependencies.
|
| 52 |
+
|
| 53 |
+
The output of the SepFormer h ′′ ∈ R F × C × Nc is processed by PReLU activations followed by a linear layer. We denote the output of this module h ′′′ ∈ R ( F × Ns ) × C × Nc , where Ns is the number of speakers. Afterwards we apply the overlap-add scheme described in [17] and obtain h ′′′′ ∈ R F × Ns × T ′ . We pass this representation through two feed-forward layers and a ReLU activation at the end to finally obtain the mask m k for each of the speakers.
|
| 54 |
+
|
| 55 |
+
## 2.3. SepFormer Block
|
| 56 |
+
|
| 57 |
+
Figure 2 (Middle) shows the architecture of the SepFormer block. The SepFormer block is designed to model both short and longterm dependencies with the dual-scale approach of DPRNNs [17]. In our model, the transformer block which models the short-term dependencies is named IntraTransformer (IntraT), and the block for longer-term dependencies is named InterTransformer (InterT). IntraT processes the second dimension of h ′ , and thus acts on each chunk independently, modeling the short-term dependencies within each chunk. Next, we permute the last two dimensions (which we denote with P ), and the InterT is applied to model the transitions across chunks. This scheme enables effective modelling of longterm dependencies across the chunks. The overall transformation of the SepFormer is therefore defined as follows:
|
| 58 |
+
|
| 59 |
+
[1 speechbrain.github.io/](speechbrain.github.io)
|
| 60 |
+
|
| 61 |
+
<!-- formula-not-decoded -->
|
| 62 |
+
|
| 63 |
+
where we denote the IntraT and InterT with f inter ( . ) , and f intra ( . ) , respectively. The overall SepFormer block is repeated N times.
|
| 64 |
+
|
| 65 |
+
## 2.3.1. Intra and Inter Transformers
|
| 66 |
+
|
| 67 |
+
Figure 2 (Bottom) shows the architecture of the Transformers used for both the IntraT and InterT blocks. It closely resembles the original one defined in [4]. We use the variable z to denote the input to the Transformer. First of all, sinusoidal positional encoding e is added to the input z , such that,
|
| 68 |
+
|
| 69 |
+
<!-- formula-not-decoded -->
|
| 70 |
+
|
| 71 |
+
Positional encoding injects information on the order of the various elements composing the sequence, thus improving the separation performance. We follow the positional encoding definition in [4].
|
| 72 |
+
|
| 73 |
+
We then apply multiple Transformer layers. Inside each Transformer layer g ( . ) , we first apply layer normalization, followed by multi-head attention (MHA):
|
| 74 |
+
|
| 75 |
+
<!-- formula-not-decoded -->
|
| 76 |
+
|
| 77 |
+
As proposed in [4], each attention head computes the scaled dotproduct attention between all the elements of the sequence. The Transformer finally employs a feed-forward network (FFW), which is applied to each position independently:
|
| 78 |
+
|
| 79 |
+
<!-- formula-not-decoded -->
|
| 80 |
+
|
| 81 |
+
The overall transformer block is therefore defined as follows:
|
| 82 |
+
|
| 83 |
+
<!-- formula-not-decoded -->
|
| 84 |
+
|
| 85 |
+
where g K ( . ) denotes K layers of transformer layer g ( . ) . We use K = Nintra layers for the IntraT, and K = Ninter layers for the InterT. As shown in Figure 2 (Bottom) and Eq. (6), we add residual connections across the transformer layers, and across the transformer architecture to improve gradient backpropagation.
|
| 86 |
+
|
| 87 |
+
## 2.4. Decoder
|
| 88 |
+
|
| 89 |
+
The decoder simply uses a transposed convolution layer, with the same stride and kernel size of the encoder. The input to the decoder is the element-wise multiplication between the mask m k of the source k and the output of the encoder h . The transformation of the decoder can therefore be expressed as follows:
|
| 90 |
+
|
| 91 |
+
<!-- formula-not-decoded -->
|
| 92 |
+
|
| 93 |
+
where ̂ s k ∈ R T denotes the separated source k .
|
| 94 |
+
|
| 95 |
+
## 3. EXPERIMENTAL SETUP
|
| 96 |
+
|
| 97 |
+
## 3.1. Dataset
|
| 98 |
+
|
| 99 |
+
We use the popular WSJ0-2mix and WSJ0-3mix datasets [11] for source separation, where mixtures of two speakers and three speakers are created by randomly mixing utterances in the WSJ0 corpus. The relative levels for the sources are sampled uniformly between 0 dB to 5 dB. Respectively, 30, 10, 5 hours of speech is used for training, validation, and test. The training and test sets are created with different sets of speakers. The waveforms are sampled at 8 kHz.
|
| 100 |
+
|
| 101 |
+
Fig. 2 . (Top) The overall architecture proposed for the masking network. (Middle) The SepFormer Block. (Bottom) The transformer architecture f ( . ) that is used both in the IntraTransformer block and in the InterTransformer block.
|
| 102 |
+
|
| 103 |
+
<!-- image -->
|
| 104 |
+
|
| 105 |
+
## 3.2. Architecture and Training Details
|
| 106 |
+
|
| 107 |
+
The encoder is based on 256 convolutional filters with a kernel size of 16 samples and a stride factor of 8 samples. The decoder uses the same kernel size and the stride factors of the encoder.
|
| 108 |
+
|
| 109 |
+
In our best models, the SepFormer masking network processes chunks of size C = 250 with a 50 % overlap between them and employs 8 layers of transformers in both IntraT and InterT. The IntraT-InterT dual-path processing pipeline is repeated N = 2 times. We used 8 parallel attention heads, and 1024-dimensional positional feed-forward networks within each Transformer layer. The model has a total of 26 million parameters.
|
| 110 |
+
|
| 111 |
+
We explored the use of dynamic mixing (DM) data augmentation [23] which consists in on-the-fly creation of new mixtures from single speaker sources. In this work we expanded this powerful technique by applying also speed perturbation on the sources before mixing them. The speed randomly changes between 95 % slow-down and 105 % speed-up.
|
| 112 |
+
|
| 113 |
+
We used the Adam algorithm [25] as optimizer, with a learning rate of 15 e -5 . After epoch 65 (after epoch 100 with DM), the learning rate is annealed by halving it if we do not observe any improvement of the validation performance for 3 successive epochs (5 epoch for DM). Gradient clipping is employed to limit the L 2 norm of the gradients to 5. During training, we used a batch size of 1, and used the scale-invariant signal-to-noise Ratio (SI-SNR) [26] via utterance-level permutation invariant loss [13], with clipping at 30dB [23]. We used automatic mixed-precision to speed up training. The system is trained for a maximum of 200 epochs. Each epoch takes approximately 1.5 hours on a single NVIDIA V100 GPU with 32 GB of memory.
|
| 114 |
+
|
| 115 |
+
## 4. RESULTS
|
| 116 |
+
|
| 117 |
+
## 4.1. Results on WSJ0-2mix
|
| 118 |
+
|
| 119 |
+
Table 1 compares the performance achieved by the proposed SepFormer with the best results reported in the literature on the WSJ02mix dataset. The SepFormer achieves an SI-SNR improvement (SISNRi) of 22.3 dB and a Signal-to-Distortion Ratio [30] (SDRi) improvement of 22.4 dB on the test-set with dynamic mixing. When using dynamic mixing, the proposed architecture achieves state-ofthe-art performance. The SepFormer outperforms previous systems without using dynamic mixing except Wavesplit, which uses speaker identity as additional information.
|
| 120 |
+
|
| 121 |
+
Table 1 . Best results on the WSJ0-2mix dataset (test-set). DM stands for dynamic mixing.
|
| 122 |
+
|
| 123 |
+
| Model SI-SNRi SDRi # Param Stride Tasnet [27] 10.8 11.1 n.a 20 SignPredictionNet [28] 15.3 15.6 55.2M 8 ConvTasnet [15] 15.3 15.6 5.1M 10 Two-Step CTN [29] 16.1 n.a. 8.6M 10 DeepCASA [18] 17.7 18.0 12.8M 1 FurcaNeXt [19] n.a. 18.4 51.4M n.a. DualPathRNN [17] 18.8 19.0 2.6M 1 sudo rm -rf [21] 18.9 n.a. 2.6M 10 VSUNOS [20] 20.1 20.4 7.5M 2 DPTNet* [22] 20.2 20.6 2.6M 1 Wavesplit** [23] 21.0 21.2 29M 1 Wavesplit** + DM [23] 22.2 22.3 29M 1 SepFormer 20.4 20.5 26M 8 SepFormer + DM 22.3 22.4 26M 8 |
|
| 124 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 125 |
+
|
| 126 |
+
Table 2 . Ablation of the SepFormer on WSJ0-2Mix (validation set).
|
| 127 |
+
|
| 128 |
+
| SI-SNRi N Nintra Ninter # Heads DFF PosEnc DM 22.3 2 8 8 8 1024 Yes Yes 20.5 2 8 8 8 1024 Yes No 20.4 2 4 4 16 2048 Yes No 20.2 2 4 4 8 2048 Yes No 19.9 2 4 4 8 2048 Yes No 19.8 3 4 4 8 2048 Yes No 19.4 2 4 4 8 2048 No No 19.2 2 4 1 8 2048 Yes No 19.1 2 3 3 8 2048 Yes No 19.0 2 3 3 8 2048 No No |
|
| 129 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 130 |
+
|
| 131 |
+
## 4.2. Ablation Study
|
| 132 |
+
|
| 133 |
+
Hereafter we study the effect of various hyperparameters and data augmentation on the performance of the SepFormer using WSJ02mix dataset. The results are summarized in Table 2. The reported performance in this table is calculated on the validation set.
|
| 134 |
+
|
| 135 |
+
We observe that the number of InterT and IntraT blocks has an important impact on the performance. The best results are achieved with 8 layers for both blocks replicated two times. We also would like to point out that a respectable performance of 19.2 dB is obtained even when we use a single layer transformer for the Inter- Transformer. This suggests that the IntraTransformer, and thus local processing, has a greater influence on the performance. It also emerges that positional encoding is helpful (e.g. see lines 3 and 5 of Table 2). A similar outcome has been observed in [31] for speech enhancement. As for the number of attention heads, we observe a slight performance difference between 8 and 16 heads. Finally, it can be observed that dynamic mixing helps the performance significantly.
|
| 136 |
+
|
| 137 |
+
Fig. 3 . ( Left ) The traning curves of SepFormer, DPRNN, and DPTNeT on the WSJ0-2mix dataset. (Middle & Right) The comparison of forward-pass speed and memory usage in the GPU on inputs ranging 1-5 seconds long sampled at 8kHz.
|
| 138 |
+
|
| 139 |
+
<!-- image -->
|
| 140 |
+
|
| 141 |
+
Table 3 . Best results on the WSJ0-3mix dataset.
|
| 142 |
+
|
| 143 |
+
| Model SI-SNRi SDRi # Param ConvTasnet [15] 12.7 13.1 5.1M DualPathRNN [17] 14.7 n.a 2.6M VSUNOS [20] 16.9 n.a 7.5M Wavesplit [23] 17.3 17.6 29M Wavesplit [23] + DM 17.8 18.1 29M Sepformer 17.6 17.9 26M Sepformer + DM 19.5 19.7 26M |
|
| 144 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 145 |
+
|
| 146 |
+
## 4.3. Results on WSJ0-3mix
|
| 147 |
+
|
| 148 |
+
Table 3 showcases the best performing models on the WSJ0-3mix dataset. SepFormer obtains the state-of-the-art performance with an SI-SNRi of 19.5 dB and an SDRi of 19.7 dB. We used here the best architecture found for the WSJ0-2mix dataset. The only difference is that the decoder has now three outputs. It is worth noting that on this corpus the SepFormer outperforms all previously proposed systems.
|
| 149 |
+
|
| 150 |
+
Our results on WSJ0-2mix and WSJ0-3mix show that it is possible to achieve state-of-the-art performance in separation with an RNN-free Transformer-based model. The big advantage of SepFormer over RNN-based systems like [17,20,22] is the possibility to parallelize the computations over different time steps. This leads to faster training and inference, as described in the following section.
|
| 151 |
+
|
| 152 |
+
## 4.4. Speed and Memory Comparison
|
| 153 |
+
|
| 154 |
+
We now compare the training and inference speed of our model with DPRNN [17] and DPTNet [22]. Figure 3 (left) shows the training curves of the aforementioned models on the WSJ0-2mix dataset. We plot the performance achieved on the validation set in the first 48 hours of training versus the wall-clock time. For a fair comparison, we used the same machine with the same GPU (a single NVIDIA V100-32GB) for all the models. Moreover, all the systems are trained with a batch size of 1 and employ automatic mixed precision. We observe that the SepFormer is faster than DPRNN and DPTNeT. Figure 3 (left), highlights that SepFormer reaches above 17dB levels only after a full day of training, whereas the DPRNN
|
| 155 |
+
|
| 156 |
+
model requires two days of training to achieve the same level of performance.
|
| 157 |
+
|
| 158 |
+
Figure 3 (middle&right) compares the average computation time (in ms) and the total memory allocation (in GB) during inference when single precision is used. We analyze the speed of our best model for both WSJ0-2Mix and WSJ0-3Mix datasets. We compare our models against DP-RNN, DPTNeT, and Wavesplit. All the models are stored in the same NVIDIA RTX8000-48GB GPU and we performed this analysis using the PyTorch profiler [32]. For Wavesplit we used the implementation in [33].
|
| 159 |
+
|
| 160 |
+
From this analysis, it emerges that the SepFormer is not only faster but also less memory demanding than DPTNet, DPRNN, and Wavesplit. We observed the same behavior using the CPU for inference also. Such a level of computational efficiency is achieved even though the proposed SepFormer employs more parameters than the other RNN-based methods (see Table 1). This is not only due to the superior parallelization capabilities of the proposed model, but also because the best performance is achieved with a stride factor of 8 samples, against a stride of 1 for DPRNN and DPTNet. Increasing the stride of the encoder results in downsampling the input sequence, and therefore the model processes less data. In [17], the authors showed that the DPRNN performance degrades when increasing the stride factor. The SepFormer, instead, reaches competitive results even with a relatively large stride, leading to the aforementioned speed and memory advantages.
|
| 161 |
+
|
| 162 |
+
## 5. CONCLUSIONS
|
| 163 |
+
|
| 164 |
+
In this paper, we proposed a novel neural model for speech separation called SepFormer (Separation Transformer). The SepFormer is an RNN-free architecture that employs a masking network composed of transformers only. The masking network learns both short and long-term dependencies using a multi-scale approach. Our results, reported on the WSJ0-2mix and WSJ0-3mix datasets, highlight that we can reach state-of-the-art performances in source separation without using RNNs in the network design. This way, computations over different time-steps can be parallelized. Moreover, our model achieves a competitive performance even when subsampling the encoded representation by a factor of 8. These two properties lead to a significant speed-up at training/inference time and a drastic reduction of memory usage, especially when compared to recent models such as DPRNN, DPTNet, and Wavesplit. As future work, we would like to explore different transformer architectures that could potentially further improve performance, speed, and memory usage.
|
| 165 |
+
|
| 166 |
+
## 6. REFERENCES
|
| 167 |
+
|
| 168 |
+
- [1] S. Hochreiter and J. Schmidhuber, 'Long short-term memory,' Neural Computation , vol. 9, no. 8, pp. 1735-1780, Nov. 1997.
|
| 169 |
+
- [2] K. Cho, B. van Merri¨ enboer, D. Bahdanau, and Y. Bengio, 'On the properties of neural machine translation: Encoder-decoder approaches,' in Proc. of SSST , 2014, pp. 103-111.
|
| 170 |
+
- [3] M. Ravanelli, P. Brakel, M. Omologo, and Y. Bengio, 'Light gated recurrent units for speech recognition,' IEEE Transactions on Emerging Topics in Computational Intelligence , vol. 2, no. 2, pp. 92-102, April 2018.
|
| 171 |
+
- [4] A. Vaswani, N. Shazeer, N. Parmar, J. Uszkoreit, L. Jones, A. N. Gomez, L. Kaiser, and I. Polosukhin, 'Attention is all you need,' CoRR , vol. abs/1706.03762, 2017.
|
| 172 |
+
- [5] G. Kerg, B. Kanuparthi, A. Goyal, K. Goyette, Y. Bengio, and G. Lajoie, 'Untangling tradeoffs between recurrence and selfattention in neural networks,' CoRR , vol. abs/2006.09471, 2020.
|
| 173 |
+
- [6] S. Karita, N. Chen, T. Hayashi, T. Hori, H. Inaguma, Z. Jiang, M. Someki, N. E. Y. Soplin, R. Yamamoto, X. Wang, S. Watanabe, T. Yoshimura, and W. Zhang, 'A comparative study on transformer vs rnn in speech applications,' in Proc. of ASRU , 2019, pp. 449-456.
|
| 174 |
+
- [7] N. Li, S. Liu, Y. Liu, S. Zhao, and M. Liu, 'Neural speech synthesis with transformer network,' in Proc. of AAAI , 2019, pp. 6706-6713.
|
| 175 |
+
- [8] J. Kim, M. El-Khamy, and J. Lee, 'T-gsa: Transformer with gaussian-weighted self-attention for speech enhancement,' in Proc. of ICASSP , 2020, pp. 6649-6653.
|
| 176 |
+
- [9] Q. Li, F. L. Kreyssig, C. Zhang, and P. C. Woodland, 'Discriminative neural clustering for speaker diarisation,' CoRR , vol. abs/1910.09703, 2019.
|
| 177 |
+
- [10] X. Chang, W. Zhang, Y. Qian, J. Le Roux, and S. Watanabe, 'End-to-end multi-speaker speech recognition with transformer,' in Proc. of ICASSP , 2020, pp. 6134-6138.
|
| 178 |
+
- [11] J. R. Hershey, Z. Chen, J. Le Roux, and S. Watanabe, 'Deep clustering: Discriminative embeddings for segmentation and separation,' in Proc. of ICASSP , 2016, pp. 31-35.
|
| 179 |
+
- [12] D. Yu, M. Kolbæk, Z. Tan, and J. Jensen, 'Permutation invariant training of deep models for speaker-independent multitalker speech separation,' in Proc. of ICASSP , 2017, pp. 241245.
|
| 180 |
+
- [13] M. Kolbæk, D. Yu, Z.-H. Tan, and J. Jensen, 'Multitalker speech separation with utterance-level permutation invariant training of deep recurrent neural networks,' IEEE/ACM Transactions on Audio, Speech, and Language Processing , vol. 25, no. 10, pp. 1901-1913, 2017.
|
| 181 |
+
- [14] Shrikant Venkataramani, Jonah Casebeer, and Paris Smaragdis, 'End-to-end source separation with adaptive front-ends,' in Proc. of ACSSC , 2018, pp. 684-688.
|
| 182 |
+
- [15] Y. Luo and N. Mesgarani, 'Conv-TasNet: Surpassing Ideal Time-Frequency Magnitude Masking for Speech Separation,' vol. 27, no. 8, pp. 1256-1266, Aug. 2019.
|
| 183 |
+
- [16] P. Huang, M. Kim, M. Hasegawa-Johnson, and P. Smaragdis, 'Deep learning for monoaural source separation,' in Proc. of ICASSP , 2014, pp. 1562-1566.
|
| 184 |
+
- [17] Y. Luo, Z. Chen, and T. Yoshioka, 'Dual-path rnn: efficient long sequence modeling for time-domain single-channel speech separation,' in Proc. of ICASSP , 2020, pp. 46-50.
|
| 185 |
+
- [18] Y. Liu and D. Wang, 'Divide and conquer: A deep casa approach to talker-independent monaural speaker separation,' IEEE/ACM Transactions on audio, speech, and language processing , vol. 27, no. 12, 2019.
|
| 186 |
+
- [19] Z. Shi, H. Lin, L. Liu, R. Liu, J. Han, and A. Shi, 'Furcanext: End-to-end monaural speech separation with dynamic gated dilated temporal convolutional networks,' in MultiMedia Modeling , 2020, pp. 653-665.
|
| 187 |
+
- [20] E. Nachmani, Y. Adi, and L. Wolf, 'Voice separation with an unknown number of multiple speakers,' ICML , pp. 71647175, 2020.
|
| 188 |
+
- [21] E. Tzinis, Z. Wang, and P. Smaragdis, 'Sudo rm -rf: Efficient networks for universal audio source separation,' in MLSP , 2020, pp. 1-6.
|
| 189 |
+
- [22] J. Chen, Q. Mao, and D. Liu, 'Dual-Path Transformer Network: Direct Context-Aware Modeling for End-to-End Monaural Speech Separation,' in Proc. of Interspeech 2020 , 2020, pp. 2642-2646.
|
| 190 |
+
- [23] N. Zeghidour and D. Grangier, 'Wavesplit: End-to-end speech separation by speaker clustering,' arXiv preprint arXiv:2002.08933 , 2020.
|
| 191 |
+
- [24] L. J. Ba, J. R. Kiros, and G. E. Hinton, 'Layer normalization,' CoRR , vol. abs/1607.06450, 2016.
|
| 192 |
+
- [25] D. P. Kingma and J. Ba, 'Adam: A method for stochastic optimization,' arXiv preprint arXiv:1412.6980 , 2014.
|
| 193 |
+
- [26] J. Le Roux, S. Wisdom, H. Erdogan, and J. R. Hershey, 'Sdrhalf-baked or well done?,' in Proc. of ICASSP . IEEE, 2019, pp. 626-630.
|
| 194 |
+
- [27] Y. Luo and N. Mesgarani, 'TasNet: time-domain audio separation network for real-time, single-channel speech separation,' CoRR , vol. abs/1711.00541, 2017.
|
| 195 |
+
- [28] Zhong-Qiu Wang, Ke Tan, and DeLiang Wang, 'Deep learning based phase reconstruction for speaker separation: A trigonometric perspective,' in Proc. of ICASSP , 2019, pp. 71-75.
|
| 196 |
+
- [29] E. Tzinis, S. Venkataramani, Z. Wang, C. Subakan, and P. Smaragdis, 'Two-step sound source separation: Training on learned latent targets,' in Proc. of ICASSP , 2020, pp. 31-35.
|
| 197 |
+
- [30] E. Vincent, R. Gribonval, and C F´ evotte, 'Performance measurement in blind audio source separation,' IEEE transactions on audio, speech, and language processing , vol. 14, no. 4, pp. 1462-1469, 2006.
|
| 198 |
+
- [31] J. Kim, M. El-Khamy, and J. Lee, 'T-gsa: Transformer with gaussian-weighted self-attention for speech enhancement,' in Proc. of ICASSP , 2020, pp. 6649-6653.
|
| 199 |
+
- [32] Pytorch, 'Profiler,' https://pytorch.org/ tutorials/recipes/recipes/profiler.html , 2020, Accessed: 2020-10-21.
|
| 200 |
+
- [33] M. Pariente, S. Cornell, J. Cosentino, S. Sivasankaran, E. Tzinis, J. Heitkaemper, M. Olvera, F.-R. St¨ oter, M. Hu, J. M. Martın-Do˜ nas, D. Ditter, A. Frank, A. Deleforge, and E. Vincent, 'Asteroid: the PyTorch-based audio source separation toolkit for researchers,' in Proc. of Interspeech , 2020, pp. 2637-2641.
|
text-versions/attention-markdown/2011.09763_AttentionBased Transformers for Instance.md
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2011.09763 Attentionbased Transformers For Instance
|
| 2 |
+
|
| 3 |
+
## Attention-Based Transformers for Instance Segmentation of Cells in Microstructures
|
| 4 |
+
|
| 5 |
+
Tim Prangemeier, Christoph Reich, Heinz Koeppl ‡
|
| 6 |
+
|
| 7 |
+
Centre for Synthetic Biology,
|
| 8 |
+
|
| 9 |
+
Department of Electrical Engineering and Information Technology, Department of Biology,
|
| 10 |
+
|
| 11 |
+
Technische Universit¨ at Darmstadt
|
| 12 |
+
|
| 13 |
+
‡ heinz.koeppl@bcs.tu-darmstadt.de
|
| 14 |
+
|
| 15 |
+
Abstract -Detecting and segmenting object instances is a common task in biomedical applications. Examples range from detecting lesions on functional magnetic resonance images, to the detection of tumours in histopathological images and extracting quantitative single-cell information from microscopy imagery, where cell segmentation is a major bottleneck. Attention-based transformers are state-of-the-art in a range of deep learning fields. They have recently been proposed for segmentation tasks where they are beginning to outperform other methods. We present a novel attention-based cell detection transformer (CellDETR) for direct end-to-end instance segmentation. While the segmentation performance is on par with a state-of-the-art instance segmentation method, Cell-DETR is simpler and faster. We showcase the method's contribution in a the typical use case of segmenting yeast in microstructured environments, commonly employed in systems or synthetic biology. For the specific use case, the proposed method surpasses the state-of-the-art tools for semantic segmentation and additionally predicts the individual object instances. The fast and accurate instance segmentation performance increases the experimental information yield for a posteriori data processing and makes online monitoring of experiments and closed-loop optimal experimental design feasible. Code and data samples are available at https://git.rwth-aachen. de/bcs/projects/cell-detr.git.
|
| 16 |
+
|
| 17 |
+
Index Terms -attention, instance segmentation, transformers, single-cell analysis, synthetic biology, microfluidics, deep learning
|
| 18 |
+
|
| 19 |
+
## I. INTRODUCTION
|
| 20 |
+
|
| 21 |
+
Instance segmentation is a common task in biomedical applications. It is comprised of both detecting individual object instances and segmenting them [1], [2]. Prevalent examples in healthcare and life sciences include the detection of individual tumour or cell entities and the segmentation of their shape. Recent advances in automated single-cell image processing, such as instance segmentation, have contributed to early tumour detection, personalised medicine, biological signal transduction and insight into the mechanisms behind cell population heterogeneity, amongst others [3]-[6]. An example of instance segmentation is shown in Fig. 1, with four separate cell and two trap microstructures detected and segmented individually.
|
| 22 |
+
|
| 23 |
+
Object detection and panoptic segmentation are closely related to instance segmentation [2], [7]. Carion et al. recently proposed a novel attention-based detection transformer DETR for panoptic segmentation [8]. DETR achieves state-of-theart panoptic segmentation performance, while exhibiting a comparatively simple architecture that is easier to implement and is computationally more efficient than previous approaches [8]. Its simplicity promises to be beneficial for its adoption in real-world applications.
|
| 24 |
+
|
| 25 |
+
Time-lapse fluorescence microscopy (TLFM) is a powerful technique for studying cellular processes in living cells [4], [9]-[11]. The vast amount of quantitative data TLFM yields, promises to constitute the backbone of the rational design of de novo biomolecular functionality [10], [11]. Ideally in synthetic biology, well characterised parts are combined in silico in a quantitatively predictive bottom up approach [11]-[13], for example, to detect and kill cancer cells [14], [15].
|
| 26 |
+
|
| 27 |
+
Quantitative TLFM with high-throughput microfluidics is an essential technique for concurrently studying the heterogeneity and dynamics of synthetic circuitry on the single cell level [4], [9], [11]. A typical TLFM experiment yields thousands of specimen images (Fig. 1) requiring automated segmentation, examples include [5], [16], [17]. Segmenting each individual cell enables its pertinent information to be extracted quantitatively. For example, the abundance of a fluorescent reporter can be measured, giving insight into the cell's inner workings.
|
| 28 |
+
|
| 29 |
+
Fig. 1. Schematic of Cell-DETR direct instance segmentation discerning individual cell (colour) and trap microstructure (grey) object instances.
|
| 30 |
+
|
| 31 |
+
<!-- image -->
|
| 32 |
+
|
| 33 |
+
Instance segmentation is a major bottleneck in quantifying single-cell microscopy data and manual analysis is prohibitively labour intensive [9], [11], [16], [18], [19]. The vast majority of single-cell segmentation methods are designed for a posteriori data processing and often require post-processing for instance detection or manual input [9]. This is not only a drawback on the amount of experiments that can be performed, but also limits the type of experiments [18], [20]. For example, harnessing the potential of advanced closedloop optimal experimental design techniques [12], [21], [22] requires online monitoring with fast instance segmentation capabilities. Attention-based methods, such as the recently proposed detection transformer DETR [8], are increasingly outperforming other methods [8], [23]. For the yeast-trap configuration (Fig. 1) direct instance segmentation has yet to be employed and attention-based transformers have yet to be applied for segmentation in the biomedical fields in general.
|
| 34 |
+
|
| 35 |
+
In this study, we present Cell-DETR, a novel attention-based detection transformer for instance segmentation of biomedical samples based on DETR [8]. We address the automated cell instance segmentation bottleneck for yeast cells in microstructured environments (Fig. 1) and showcase Cell-DETR on this application. Section II introduces the previous segmentation approaches and the microstructured environment. Our experimental setup for fluorescence microscopy, the tested architectures and our approach to training and evaluation are presented in Section III. We analyse the proposed method's performance in Section IV and compare it to the application specific state-of-the-art, as well as to a general instance segmentation baseline. After interpreting the results and highlighting the method's future potential in Section V, we summarise and conclude the study in Section VI. Our model surpasses the previous application baseline and is on par with a general stateof-the-art instance segmentation method. The relatively short inference runtimes enable higher throughput a posteriori data processing and make online monitoring of experiments with approximately 1000 cell traps feasible.
|
| 36 |
+
|
| 37 |
+
## II. BACKGROUND
|
| 38 |
+
|
| 39 |
+
An extensive body of research into the automated processing of microscopy imagery dates back to the middle of the 20-th century. Recent studies demonstrate the utility of deep learning segmentation approaches, for example [6], [9], [19], [24], [25]. Comprehensive reviews of the many methods to segment yeast on microscopy imagery are available elsewhere [3], [20]. Here we focus on dedicated tools for segmenting cells in trapped microstructures. U-Net convolutional neural networks (CNNs) with an encoder-decoder architecture bridged by skip connections have been shown to perform semantic segmentation well for E. coli mother machines [9], [19] and yeast in microstructured environments [6]. In the case of trapped yeast, the previous state-of-the-art tool DISCO [16] was based on conventional methods (template matching, support vector machine, active contours), until recently being superseded by U-Nets [6]. The current baseline for semantic segmentation of yeast in microstructured environments, as measured by the cell class intersection-over-union, is 0 . 82 [6]. Additional postprocessing, of the segmentation maps is required to attain each individual cell instance [6].
|
| 40 |
+
|
| 41 |
+
For instance segmentation in general, recent state-of-the-art methods are available, for example Mask R-CNN [1]. It is a proposal-based instance segmentation model, which combines a CNN backbone, region proposals with non-maximumsuppression, region-of-interest (ROI) pooling, and multiple prediction heads [1]. Attention-based methods are increasingly outperforming convolutional methods and are currently state-of-the-art in natural language processing [23]. Beyond natural language processing, attention-based approaches, such as axial-attention modules [26], have demonstrated promising results in computer vision applications [8]. Recently, the first transformer-based method (DETR [8]) for object detection and panoptic segmentation was reported. DETR achieves state-ofthe-art results on par with Faster R-CNN and constitutes a promising approach for further improvements in automated object detection and segmentation performance.
|
| 42 |
+
|
| 43 |
+
Fig. 2. Single-cell fluorescence measurement setup. Microfluidic chip on the microscope table (top right), microscope imagery and design of the yeast trap microstructures. The trap chamber (green rectangle) contains an array of approximately 1000 traps. Single specimen images show a pair of microstructures and fluorescent cells, violet contours indicate segmentation of two separate cell instances with corresponding fluorescence measurement F 1 and F 2 ; black scale bar 1mm , white scale bar 10 µ m .
|
| 44 |
+
|
| 45 |
+
<!-- image -->
|
| 46 |
+
|
| 47 |
+
The microfluidic trap microstructures we consider here are designed for long-term culture of yeast cells ( Saccharomyces cerevisiae ) within the focal plane of a microscope [17]. The on-chip environment is tightly controlled and conducive to yeast growth. Examples of its routine employ include Fig. 2 and [4]-[6], [11], [16]. A constant flow of yeast growth media hydrodynamically traps the cells in the microstructures and allows the introduction of chemical perturbations. An automated microscope records an entire trap chamber of up to 1000 traps by imaging both the brightfield and fluorescent channels at approximately 20 neighbouring positions. Typical experiments each produce hundreds of GB of image data. Time-lapse recordings allow individual cells to be tracked through time. Robust instance segmentation facilitates tracking [9], [20], which itself can be a limiting factor with regard to the data yield of an experiment [4], [9], [19], [20].
|
| 48 |
+
|
| 49 |
+
## III. METHODOLOGY
|
| 50 |
+
|
| 51 |
+
## A. Live-cell microscopy dataset and annotations
|
| 52 |
+
|
| 53 |
+
The individual specimen images each contain a single microfluidic trap and some yeast cells, as depicted in Fig. 1. These are extracted from larger microscope recordings, whereby each exposure contains up to 50 traps (Fig. 2 middle). Ideally, a single mother cell persists in each trap, with subsequent daughter cells being removed by the constant flow of yeast growth media. In practice, multiple cells accumulate around some traps, while other traps remain empty (Fig. 3).
|
| 54 |
+
|
| 55 |
+
We distinguish between three classes on the specimen image annotations, as depicted in Fig. 3. The yeast cells in violet are the most important class for biological applications. To counteract traps being segmented as cells, we employ a distinct class for them (dark grey). The background (light grey) is annotated for semantic segmentation training, for example of U-Nets. For instance segmentation training we introduce a noobject class ∅ in place of the background class.
|
| 56 |
+
|
| 57 |
+
Fig. 3. Example of class and instance annotations for a specimen image; brightfield image (left), background label in light grey ■■ , instances of the trap class in shades of dark grey ■■ and instances of the cell class in shades of violet ■■ (left to right respectively); scale bar 10 µ m .
|
| 58 |
+
|
| 59 |
+
<!-- image -->
|
| 60 |
+
|
| 61 |
+
Each instance of cells or trap structures are annotated individually with a bounding box, class specification and separate pixel-wise segmentation map. Here we omit the bounding boxes to enable an unobscured view of the contours. Instead, the distinct cell instances and their individual segmentation maps are indicated by different shades of violet in Fig. 3.
|
| 62 |
+
|
| 63 |
+
The annotated set of 419 specimen images from various experiments was randomly assigned for network training, validation and testing ( 76 % , 12 % and 12 % respectively). Examples are shown in Fig. 4. Images include a balance of the common yeast-trap configurations: 1) empty traps, 2) single cells (with daughter) and 3) multiple cells. Slight variations in trap fabrication, debris, contamination, focal shift, illumination levels and yeast morphology were included. Further scenarios or strong variations, such as trap design geometries, model organisms and significant focal shift, were omitted.
|
| 64 |
+
|
| 65 |
+
## B. The Cell-DETR instance segmentation architecture
|
| 66 |
+
|
| 67 |
+
The proposed Cell-DETR models A and B are based on the DETR panoptic segmentation architecture [8]. We adapted the architecture for non-overlapping instance segmentation and reduced it in size for faster inference. The main differences between DETR and our variants Cell-DETR A and B are summarised in Table I. The Cell-DETR variants have approximately one order of magnitude less parameters than the original ( ∼ 40 × 10 6 reduced to ∼ 5 × 10 6 parameters). The main building blocks of the Cell-DETR model are detailed in Fig. 5. They are the backbone CNN encoder, the transformer encoder-decoder, the bounding box and class prediction heads, and the segmentation head.
|
| 68 |
+
|
| 69 |
+
The CNN encoder (left in Fig. 5) extracts image features of the brightfield specimen image input. It is based on four ResNet-like [27] blocks with 64 , 128 , 256 and 256 convolutional filters. After each block a 2 × 2 average pooling layer is utilised to downsample the intermediate feature maps. The Cell-DETR variants employ different activations and convolutions, as detailed in Table I.
|
| 70 |
+
|
| 71 |
+
The transformer encoder determines the attention between image features. The transformer decoder predicts the attention regions for each of the N = 20 object queries. They are both based on the DETR architecture [8]. We reduced the number of transformer encoder blocks to three and decoder blocks to two, each with 512 hidden features in the feed-forward neuralnetwork (FFNN). The 128 backbone features are flattened before being fed into the transformer. In contrast to the original DETR, we employed learned positional encodings. While Cell-DETR A employs leaky ReLU [28] activations, Pad´ e activation units [29] are utilised for Cell-DETR B.
|
| 72 |
+
|
| 73 |
+
Fig. 4. Characteristic selection of specimen images and corresponding annotations, including empty or single trap structures, trapped single cells (with single daughter adjacent) and multiple trapped cells; trap instances in shades of dark grey ■■ , cell instances in shades of violet ■■ and transparent background; scale bar 10 µ m .
|
| 74 |
+
|
| 75 |
+
<!-- image -->
|
| 76 |
+
|
| 77 |
+
TABLE I OVERVIEW OF DIFFERENCES BETWEEN DETR, CELL-DETR A AND B.
|
| 78 |
+
|
| 79 |
+
| --- Model Activation functions Convolutions Feature fusion Param. × 10 6 DETR [8] ReLU standard spatial addition ⪆ 40 C-DETR A leaky ReLU [28] standard spatial addition 4 . 3 C-DETR B Pad´ e [29] deformable (v2) [30] pix.-adapt. conv. [31] 5 . 0 |
|
| 80 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 81 |
+
|
| 82 |
+
The prediction heads for the bounding box and classification are each a FFNN. They map the transformer encoder-decoder output to the bounding box and classification prediction. These FFNN process each query in parallel and share parameters over all queries. In addition to the cell and trap classes, the classification head can also predict the no-object class ∅ .
|
| 83 |
+
|
| 84 |
+
Fig. 5. Architecture of the end-to-end instance segmentation network, with brightfield specimen image input and an instance segmentation prediction as output. The backbone CNN encoder extracts image features that then feed into both the transformer encoder-decoder for class and bounding box prediction, as well as to the CNN decoder for segmentation. The transformer encoded features, as well as the transformer decoded features, are fed into a multi-head-attention module and together with the image features from the CNN backbone feed into the CNN decoder for segmentation. Skip connections additionally bridge between the backbone CNN encoder and the CNN decoder. Input and output resolution is 128 × 128 pixels.
|
| 85 |
+
|
| 86 |
+
<!-- image -->
|
| 87 |
+
|
| 88 |
+
The segmentation head is composed of a multi-head attention mechanism and a CNN decoder to predict the segmentation maps for each object instance. We employ the original DETR [8] two-dimensional multi-head attention mechanism between the transformer encoder and decoder features. The resulting attention maps are concatenated channel-wise onto the image features and fed into the CNN decoder. The three ResNet-like decoder blocks decrease the feature channel size while increasing the spatial dimensions. Long skip connections bridge between the CNN encoder and CNN decoder blocks' respective outputs. The features are fused by element-wise addition in Cell-DETR A and by pixel-adaptive convolutions in Cell-DETR B. A fourth convolutional block incorporates the queries in the feature dimension and returns the original input's spatial dimension for each query. Non-overlapping segmentation is ensured by a softmax over all queries.
|
| 89 |
+
|
| 90 |
+
## C. Training Cell-DETR
|
| 91 |
+
|
| 92 |
+
We employ a combined loss function and a direct set prediction to train our Cell-DETR networks end-to-end. The set prediction ˆ y = { ˆ y i = { ˆ p i , ˆ b i , ˆ s i }} N =20 1 is comprised of the respective predictions for class probability ˆ p i ∈ R K (here K = 3 classes, no-object, trap, cell), bounding box ˆ b i ∈ R 4 and segmentation ˆ s i ∈ R 128 × 128 for each of the N queries. We assigned each instance set label y σ ( i ) to the corresponding query set prediction ˆ y i with the Hungarian algorithm [8], [32]. The indices σ i denote the best matching permutation of labels.
|
| 93 |
+
|
| 94 |
+
The combined loss L is comprised of a classification loss L p , a bounding box loss L b , and a segmentation loss L s
|
| 95 |
+
|
| 96 |
+
̸
|
| 97 |
+
|
| 98 |
+
<!-- formula-not-decoded -->
|
| 99 |
+
|
| 100 |
+
̸
|
| 101 |
+
|
| 102 |
+
with N = 20 object instance queries in this case. We employ class-wise weighted cross entropy for the classification loss
|
| 103 |
+
|
| 104 |
+
<!-- formula-not-decoded -->
|
| 105 |
+
|
| 106 |
+
with weights β = [0 . 5 , 0 . 5 , 1 . 5] for the K = 3 classes, noobject, trap and cell classes respectively. The bounding box loss is itself composed of two weighted loss terms. These are a generalised intersection-over-union L J [33], and a L1 loss, with respective weights λ J = 0 . 4 and λ L 1 = 0 . 6
|
| 107 |
+
|
| 108 |
+
<!-- formula-not-decoded -->
|
| 109 |
+
|
| 110 |
+
The segmentation loss L s is a weighted sum of the focal loss L F [34] and Sørensen-Dice loss L D [6], [8]
|
| 111 |
+
|
| 112 |
+
<!-- formula-not-decoded -->
|
| 113 |
+
|
| 114 |
+
The respective weights are λ F = 0 . 05 and λ D = 1 , with focusing parameter γ = 2 and ϵ = 1 for numerical stability.
|
| 115 |
+
|
| 116 |
+
## D. Evaluation and implementation
|
| 117 |
+
|
| 118 |
+
We employ a number of metrics to quantitatively analyse the performance of the trained networks with regard to classification, bounding box and segmentation performance. Given the ground truth Y and the prediction ˆ Y (in the corresponding instance-matched permutation), we evaluate the segmentation performance with variants of the Jaccard index J and the Sørensen-Dice D coefficient [6], [8], omitting the background
|
| 119 |
+
|
| 120 |
+
<!-- formula-not-decoded -->
|
| 121 |
+
|
| 122 |
+
with J k intuitively the intersection-over-union for each class k . With respect to the metrological application in image cytometry, the cell class is of most importance, therefore, we consider the Jaccard index for the cell class alone ( J c ). Similarly, in the case of instance segmentation, we compute J i for each instance i and average over all I object instances to compute the mean instance Jaccard index ¯ J I = 1 I ∑ I i =1 J i .
|
| 123 |
+
|
| 124 |
+
We utilise the accuracy as the proportion of correct predictions for classification. The bounding boxes are evaluated with the Jaccard index ¯ J b . It is defined analogously to the object instance Jaccard index (compare Eqn. 1), yet computed implicitly with the bounding box coordinates.
|
| 125 |
+
|
| 126 |
+
We compare the proposed method with our own implementations of both the state-of-the-art for the trapped yeast application (U-Net [6]), as well as more generally with a state-of-the-art instance segmentation meta algorithm (Mask R-CNN [1]). The multiclass U-Net for semantic segmentation was implemented in PyTorch, with the architecture, pre- and post-processing described in [6]. We implemented a Mask RCNN [1] with Torchvision (PyTorch) and a ResNet-18 [27] backbone, which was pre-trained for image classification.
|
| 127 |
+
|
| 128 |
+
We implemented the proposed Cell-DETR A and B architectures with PyTorch. We used the MMDetection toolkit [35] for deformable convolutions and the PyTorch/Cuda implementation for the Pad´ e activation units [29]. We trained the models using AdamW [36] for optimisation with a weight decay of 10 -6 . The initial learning rate was 10 -5 for the backbone and 10 -4 for the rest of the model. The learning rates were decreased by an order of magnitude after 50 and again 100 epochs of the total 200 epochs. The additional first and secondorder momentum moving average factors were 0 . 9 and 0 . 999 respectively. We selected the best performing model based on the cell class Jaccard index J c , typically after 80 to 140 epochs with mini batch size 8 . The training data was randomly augmented by elastic deformation [6], [24], horizontal flipping or by the addition of noise with a probability of 0 . 6 . Inference runtimes for one forward pass were averaged over 1000 runs on a Nvidia RTX 2080 Ti for all three methods (U-Net, Mask R-CNN and Cell-DETR).
|
| 129 |
+
|
| 130 |
+
## E. Data acquisition setup
|
| 131 |
+
|
| 132 |
+
Yeast cells were cultured in a tightly controlled microfluidic environment. A temperature of 30 ° C and the flow of yeast growth media enables yeast to grow for prolonged periods and over multiple cell-cycles. The microfluidic chips confined the cells to the focal plane of the microscope. Continuous media flow hydrodynamically traps the living cells in the microstructures. The Polydimethylsiloxane (PDMS) microstructures constrain the cells in XY , while axial constraints in Z are provided by the cover slip and PDMS ceiling. The space between cover slip and the PDMS ceiling is on the order of a cell diameter to facilitate continuously uniform focus of the cells.
|
| 133 |
+
|
| 134 |
+
We recored time-lapse brightfield (transmitted light) and fluorescent channel imagery of the budding yeast cells every 10 min with a computer controlled microscope (Nikon Eclipe Ti with XYZ stage; µ Manager; 60x objective). A CoolLED pE-100 and a Lumencor SpectraX light engine illuminated the respective channels, which were captured with a ORCA Flash 4.0 (Hamamatsu) camera. Multiple lateral and axial positions were recorded sequentially at each timestep (Fig. 2).
|
| 135 |
+
|
| 136 |
+
## IV. RESULTS
|
| 137 |
+
|
| 138 |
+
## A. Cell-DETR variant results
|
| 139 |
+
|
| 140 |
+
A sample of segmentation results for the two Cell-DETR variants is shown in Fig. 6. The cell and trap instances are all detected and classified correctly with slight variations in segmentation contours. Separate instances of cells and traps are indicated by the shades of violet and grey respectively. Variant B demonstrates slightly better segmentation performance. A qualitative example of this is shown in in Fig. 6, where CellDETR A in contrast to B excludes a small section of one cell.
|
| 141 |
+
|
| 142 |
+
Fig. 6. Qualitative comparison of Cell-DETR A and B segmentation examples for a selected test image (left) and label (right); trap instances in shades of dark grey ■■ , cell instances in shades in violet ■■ ; scale bar 10 µ m .
|
| 143 |
+
|
| 144 |
+
<!-- image -->
|
| 145 |
+
|
| 146 |
+
The quantitative comparison between the segmentation performance of the Cell-DETR variants is summarised in Table II. We modified model B for better performance on our application, as described in Section III-B. The mean Jaccard index over all object instances increased from ¯ J I = 0 . 84 for model A to ¯ J I = 0 . 85 for model B, while the cell class Jaccard index increased by a similar margin from J c = 0 . 83 to J c = 0 . 84 . Taking the background into account, a segmentation accuracy of 0 . 96 is achieved. Both Cell-DETR surpass the segmentation performance ( J c ) of the previous state-of-the-art methods for the trapped yeast application [6], [16], in addition to directly attaining the instances.
|
| 147 |
+
|
| 148 |
+
TABLE II SEGMENTATION PERFORMANCE OF CELL-DETR A AND B.
|
| 149 |
+
|
| 150 |
+
| --- Model Sørensen Dice D Mean instance ¯ J I --- Cell class J c Seg. accuracy C-DETR A 0.92 0.84 0.83 0.96 C-DETR B 0.92 0.85 0.84 0.96 |
|
| 151 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 152 |
+
|
| 153 |
+
The bounding box and classification performance is summarised in Table III. Again, both models perform similarly well. They correctly classify the object instances (classification accuracy of 1 . 0 ) and detect the correct number of instances for each class. They also perform similarly well at localising the instances, achieve a bounding box intersection-over-union of J b = 0 . 81 , for the standard formulation as well as the generalised form employed for training.
|
| 154 |
+
|
| 155 |
+
TABLE III BOUNDING BOX AND CLASSIFICATION PERFORMANCE METRICS FOR CELL-DETR A AND B.
|
| 156 |
+
|
| 157 |
+
| Bounding box Classification Model Jaccard J b accuracy C-DETR A 0.81 1.0 C-DETR B 0.81 1.0 |
|
| 158 |
+
|----------------------------------------------------------------------------------------------------------|
|
| 159 |
+
|
| 160 |
+
The slight increase in segmentation performance that model B yields is a trade off with increased computational cost. The number of parameters is increased from approximately 4 × 10 6 , to over 5 × 10 6 (Table I). This leads to an increase in runtime from 9 . 0 ms for model A to 21 . 2 ms for model B. These times are orders of magnitude faster than the previous state-of-theart method DISCO [16] and on the same order of magnitude as the currently fastest reported network for this application [6]. Runtimes on this order of magnitude suffice for in-the-loop experimental techniques.
|
| 161 |
+
|
| 162 |
+
We select model B for further analysis, based on the improved performance and sufficiently fast runtimes. A selection of segmentation predictions for the three most typical scenarios in the test dataset is given in Fig. 7. The detection of cell and trap instances, without any overlap between instances, is successful for single cells (middle row), multiple cells (bottom row), and empty traps are correctly identified. The introduction of multiple classes (traps, cells), as well as individual object instances facilitated individually segmenting each cell entity and discerning these from both the traps and other cells.
|
| 163 |
+
|
| 164 |
+
Fig. 7. Example of different scenarios from the test dataset segmented with Cell-DETR B: an empty trap (top row), a single trapped cell (middle row) and multiple cells; columns are brightfield, an overlay of the prediction, the prediction mask and the ground truth label (left to right respectively). Colours indicate traps in shades of grey ■■ and cell instances in shades of violet ■■ ; scale bar 10 µ m .
|
| 165 |
+
|
| 166 |
+
<!-- image -->
|
| 167 |
+
|
| 168 |
+
The intended application of our method is to deliver segmentation masks for each cell instance for subsequent singlecell fluorescence measurements. We trialled this application on unlabelled and unseen data as depicted in Fig. 8. The cell instances are detected based on the brightfield image (left) and the resulting object segmentation predictions are used as masks to measure the individual cell fluorescence on the fluorescent channel (right). An overlay of the brightfield, fluorescent images with the segmentation contours is depicted in the middle, along with the green fluorescent protein (GFP) channel. The individual cell area ( A 1 and A 2 ) is measured as the number of pixels in the instance segmentation mask and indicated on the GFP channel. The cell instance fluorescence ( F 1 and F 2 ) is summed over the mask area and indicated on the right for each individual cell in arbitrary fluorescence units.
|
| 169 |
+
|
| 170 |
+
Fig. 8. Example of individual cell fluorescence measurement application with a segmentation mask contour for each individual cell (violet contours violet ■■ ) based on the brightfield image (left); scale bar 10 µ m .
|
| 171 |
+
|
| 172 |
+
<!-- image -->
|
| 173 |
+
|
| 174 |
+
## B. Comparison with state-of-the-art methods
|
| 175 |
+
|
| 176 |
+
We compare our proposed method with the state-of-the-art for the trapped yeast application (DISCO [16], U-Net [6]), as well as with a general state-of-the-art method for instance segmentation (Mask R-CNN [1]). We implemented both the U-Net and Mask R-CNN methods in this study (Section III-D). A characteristic qualitative example of the results is given in Fig. 9, with the ground truth on the left, followed by CellDETR B, Mask R-CNN and U-Net segmentations results. All three methods segment two trap microstructures and all four cells in separate classes, without any overlap or touching cells. Cell-DETR B and Mask R-CNN additionally segment each cell or trap object as an individual instance. The contours are slightly smaller for the U-Net, which is deemed a result of the emphasis on avoiding touching cells and the associated difficulty of discerning these in subsequent post-processing.
|
| 177 |
+
|
| 178 |
+
Fig. 9. Example segmentation for our implementations of Cell-DETR B, Mask R-CNN and U-Net. Trap instances in shades of grey ■■ and cell instances in shades of violet ■■ (no instance detection for U-Net); scale bar 10 µ m .
|
| 179 |
+
|
| 180 |
+
<!-- image -->
|
| 181 |
+
|
| 182 |
+
Accurate segmentation of the cells is particularly important for the measurement of cell morphology or fluorescence. We compare the cell class Jaccard index J c of our proposed methods Cell-DETR A and B with the application state-ofthe-art methods DISCO, U-Net and Mask R-CNN. The comparison is summarised in Table IV. U-Net recently superseded DISCO [16] ( J c ∼ 0 . 7 ) as the state-of-the-art trapped yeast segmentation method, achieving J c = 0 . 82 . Our Cell-DETR variants both further improve on this result, with model B achieving the same J c = 0 . 84 on par with our Mask R-CNN implementation. Cell-DETR and Mask R-CNN additionally provide each cell object instance.
|
| 183 |
+
|
| 184 |
+
We measured the average runtime of a forward pass of each method on a single specimen image (Table IV). For DISCO
|
| 185 |
+
|
| 186 |
+
TABLE IV COMPARISON OF CELL-DETR PERFORMANCE WITH THE STATE-OF-THE-ART METHODS FOR THE TRAPPED YEAST APPLICATION (DISCO, U-NET) AND INSTANCE SEGMENTATION (MASK R-CNN).
|
| 187 |
+
|
| 188 |
+
| ---- Model Cell Class J c Inference runtime 1 -- Instances DISCO [16] 2 ∼ 0 . 70 ∼ 1300 ms × U-Net 0 . 82 1 . 8 ms × Mask R-CNN 0 . 84 29 . 8 ms ✓ Cell-DETR A 0 . 83 9 . 0 ms ✓ Cell-DETR B 0 . 84 21 . 2 ms ✓ |
|
| 189 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 190 |
+
|
| 191 |
+
- 1 Runtimes for U-Net, Mask R-CNN, and Cell-DETR averaged over 1000 runs ( ∼ 300 different images) on a Nvidia RTX 2080 Ti; measurement uncertainty is below ± 5% .
|
| 192 |
+
|
| 193 |
+
2 Reported literature values [16].
|
| 194 |
+
|
| 195 |
+
[16] we consider the reported values that include some preand post-processing steps to detect cells individually. The deep methods are significantly faster than DISCO, making online monitoring of live experiments feasible. The U-Net is the fastest, taking 1 . 8 ms for a forward pass, in contrast to 29 . 8 ms for the Mask R-CNN [1]. However, the U-Net requires further post-processing steps to detect the object instances and has been reported to take approximately 20 ms in conjunction with watershed post-processing [6]. The Cell-DETR variants take the middle ground with 9 . 0 ms and 21 . 2 ms .
|
| 196 |
+
|
| 197 |
+
## V. DISCUSSION
|
| 198 |
+
|
| 199 |
+
## A. Analysis of the instance segmentation performance
|
| 200 |
+
|
| 201 |
+
Cell-DETR has some benefits in comparison to state-ofthe-art methods, such as Mask R-CNN. The Cell-DETR architecture is comparatively simple and avoids common hand designed components of Mask R-CNNs, such as nonmaximum suppression and ROI pooling. This reduces CellDETR's reliance on hyperparameters and facilitates end-toend training with a single combined loss function. In contrast, Mask R-CNNs require additional supervision to train the region proposal network. As a result of these differences, CellDETR is easier to implement, has less parameters and is faster than Mask R-CNN for the same segmentation performance.
|
| 202 |
+
|
| 203 |
+
While Cell-DETR does not rely on explicit region proposals, it does utilise attention maps that highlight the pertinent features in the latent space. The mapping of these is learnt during the end-to-end training. The loss curves of individual prediction tasks are shown in Fig. 10. The classification loss L p (blue) converges first, indicating that the network first learns how many objects are present in an image and to which class they belong. The bounding box loss L b (red) converges next, with the network learning the approximate location of each object. Finally, the model learns to refine the pixelwise segmentation maps with the segmentation loss L s (green) converging last.
|
| 204 |
+
|
| 205 |
+
With respect to the specific single-cell measurement application, Cell-DETR offers robust and repeatable instance segmentation of yeast cells in microstructures. The key cell class segmentation performance surpasses the previous state-of-theart semantic segmentation methods [6], [16] with a cell class Jaccard index of 0 . 84 . Additionally, the proposed technique directly detects individual object instances and classifies the objects robustly (near 100 % accuracy). The robust instance segmentation performance promises to facilitate cell tracking, increase the experimental information yield and enables CellDETR to be employed without human intervention.
|
| 206 |
+
|
| 207 |
+
Fig. 10. Classification, bounding boxes and segmentation loss curves for Cell-DETR B; thick lines are running averages (window size 30).
|
| 208 |
+
|
| 209 |
+
<!-- image -->
|
| 210 |
+
|
| 211 |
+
## B. Limitations, outlook and future potential
|
| 212 |
+
|
| 213 |
+
The presented models are trained for a specific microfluidic configuration and trap geometry. While they are relatively robust and fulfil their intended purpose, their utility could be broadened by expanding the dataset to include more classes, for example different trap geometries. More generally as an instance segmentation method, Cell-DETR offers a platform for incorporating future advances in attention mechanisms as they are increasingly outperforming convolutional approaches. For example, replacing the convolutional elements in the backbone and segmentation head with axial-attention [26] may lead to further improved performance. Currently, Cell-DETR achieves state-of-the-art performance and as an instance segmentation method is generally suitable for and readily adaptable to a wide range of biomedical imaging applications.
|
| 214 |
+
|
| 215 |
+
The presented Cell-DETR methods can be harnessed for high-content quantitative single-cell TLFM. Cell-DETR, Mask R-CNN and U-Net achieve runtimes orders of magnitudes faster than the previous state-of-the-art trapped yeast method (DISCO [16]). These runtimes coupled with Cell-DETRs robust instance segmentation make both online monitoring and closed-loop optimal experimental design of typical experiments with approximately 1000 traps feasible. Harnessing this potential promises to provide increased experimental information yields and greater biological insights in the future.
|
| 216 |
+
|
| 217 |
+
## VI. CONCLUSION
|
| 218 |
+
|
| 219 |
+
In summary, we present Cell-DETR, an attention-based transformer method for direct instance segmentation and showcase it on a typical application. To the best of our knowledge, this is the first application of detection transformers on biomedical data. The proposed method has fewer parameters and is 30% faster while matching the segmentation performance of a state-of-the-art Mask R-CNN. A simpler Cell- DETR variant exhibits slightly lesser segmentation performance ( J c = 0 . 83 instead of 0 . 84 ) while requiring 1 / 3 rd of a Mask R-CNN's runtime. As a general instance segmentation model, Cell-DETR achieves state-of-the-art performance and is deemed suitable and readily adaptable for a range of biomedical imaging applications.
|
| 220 |
+
|
| 221 |
+
Showcased on a typical systems or synthetic biology application, the proposed Cell-DETR robustly detects each cell instance and directly provides instance-wise segmentation maps suitable for cell morphology and fluorescence measurements. In comparison to the previous semantic segmentation trapped yeast baselines, Cell-DETR provides better segmentation performance with a cell class Jaccard index J c = 0 . 84 while additionally detecting each individual cell instance and maintaining comparable runtimes. This promises to reduce measurement uncertainty, facilitate cell tracking efficacy and increase the experimental data yield in future applications. The resulting runtimes and accurate instance segmentation make future online monitoring feasible, for example for closed-loop optimal experimental control.
|
| 222 |
+
|
| 223 |
+
## ACKNOWLEDGEMENTS
|
| 224 |
+
|
| 225 |
+
We thank Christian Wildner for insightful discussions, Andr´ e O. Franc ¸ani and Jan Basrawi for contributing to labelling and Markus Baier for aid with the computational setup.
|
| 226 |
+
|
| 227 |
+
This work was supported by the Landesoffensive f¨ ur wissenschaftliche Exzellenz as part of the LOEWE Schwerpunkt CompuGene. H.K. acknowledges support from the European Research Council (ERC) with the consolidator grant CONSYN (nr. 773196).
|
| 228 |
+
|
| 229 |
+
## REFERENCES
|
| 230 |
+
|
| 231 |
+
- [1] K. He, G. Gkioxari, P. Doll´ ar, and R. Girshick, 'Mask R-CNN,' in IEEE ICCV , 2017, pp. 2961-2969.
|
| 232 |
+
- [2] M. Cordts, M. Omran, S. Ramos, T. Rehfeld, M. Enzweiler, R. Benenson, U. Franke, S. Roth, and B. Schiele, 'The cityscapes dataset for semantic urban scene understanding,' in IEEE/CVF CVPR , 2016.
|
| 233 |
+
- [3] J. Sun, A. T´ arnok, and X. Su, 'Deep Learning-Based Single-Cell Optical Image Studies,' Cytom. Part A , vol. 97, no. 3, pp. 226-240, 2020.
|
| 234 |
+
- [4] M. Leygeber, D. Lindemann, C. C. Sachs, E. Kaganovitch, W. Wiechert, K. N¨ oh, and D. Kohlheyer, 'Analyzing Microbial Population Heterogeneity - Expanding the Toolbox of Microfluidic Single-Cell Cultivations,' J. Mol. Biol. , 2019.
|
| 235 |
+
- [5] A. Hofmann, J. Falk, T. Prangemeier, D. Happel, A. K¨ ober, A. Christmann, H. Koeppl, and H. Kolmar, 'A tightly regulated and adjustable CRISPR-dCas9 based AND gate in yeast,' Nucleic Acids Res. , vol. 47, no. 1, pp. 509-520, 2019.
|
| 236 |
+
- [6] T. Prangemeier, C. Wildner, A. O. Franc ¸ani, C. Reich, and H. Koeppl, 'Multiclass yeast segmentation in microstructured environments with deep learning,' IEEE CIBCB , 2020.
|
| 237 |
+
- [7] A. Kirillov, K. He, R. Girshick, C. Rother, and P. Doll´ ar, 'Panoptic segmentation,' in IEEE/CVF CVPR , 2019, pp. 9404-9413.
|
| 238 |
+
- [8] N. Carion, F. Massa, G. Synnaeve, N. Usunier, A. Kirillov, and S. Zagoruyko, 'End-to-end object detection with transformers,' arXiv:2005.12872 , 2020.
|
| 239 |
+
- [9] J.-B. Lugagne, H. Lin, and M. J. Dunlop, 'DeLTA: Automated cell segmentation, tracking, and lineage reconstruction using deep learning,' PLoS Comput Biol , vol. 16, no. 4, 2020.
|
| 240 |
+
- [10] R. Pepperkok and J. Ellenberg, 'High-throughput fluorescence microscopy for systems biology,' Nat. Rev. Mol. Cell Biol. , p. 690, 2006.
|
| 241 |
+
- [11] T. Prangemeier, F. X. Lehr, R. M. Schoeman, and H. Koeppl, 'Microfluidic platforms for the dynamic characterisation of synthetic circuitry,' Curr. Opin. Biotechnol. , vol. 63, pp. 167-176, 2020.
|
| 242 |
+
- [12] D. G. Cabeza, L. Bandiera, E. Balsa-Canto, and F. Menolascina, 'Information content analysis reveals desirable aspects of in vivo experiments of a synthetic circuit,' in IEEE CIBCB , 2019, pp. 1-8.
|
| 243 |
+
- [13] F.-X. Lehr, M. Hanst, M. Vogel, J. Kremer, H. U. G¨ oringer, B. Suess, and H. Koeppl, 'Cell-free prototyping of and-logic gates based on heterogeneous rna activators,' ACS Synth. Biol. , p. 2163, 2019.
|
| 244 |
+
- [14] Z. Xie, L. Wroblewska, L. Prochazka, R. Weiss, and Y. Benenson, 'Multi-input RNAi-based logic circuit for identification of specific cancer cells,' Science , vol. 333, pp. 1307-1312, 2011.
|
| 245 |
+
- [15] W. Si, C. Li, and P. Wei, 'Synthetic immunology: T-cell engineering and adoptive immunotherapy,' Synth. Syst. Biotechnol. , vol. 3, no. 3, pp. 179-185, 2018.
|
| 246 |
+
- [16] E. Bakker, P. S. Swain, and M. M. Crane, 'Morphologically constrained and data informed cell segmentation of budding yeast,' Bioinformatics , vol. 34, no. 1, pp. 88-96, 2018.
|
| 247 |
+
- [17] M. M. Crane, I. B. N. Clark, E. Bakker, S. Smith, and P. S. Swain, 'A Microfluidic System for Studying Ageing and Dynamic Single-Cell Responses in Budding Yeast,' PLoS One , vol. 9, p. e100042, 2014.
|
| 248 |
+
- [18] D. A. Van Valen, T. Kudo, K. M. Lane, D. N. Macklin, N. T. Quach, M. M. DeFelice, I. Maayan, Y. Tanouchi, E. A. Ashley, and M. W. Covert, 'Deep Learning Automates the Quantitative Analysis of Individual Cells in Live-Cell Imaging Experiments,' PLoS Comput Biol , vol. 12, no. 11, pp. 1-24, 2016.
|
| 249 |
+
- [19] J. Sauls, J. Schroeder, S. Brown, G. Treut, F. Si, D. Li, J. Wang, and S. Jun, 'Mother machine image analysis with MM3,' bioRxiv , 2019.
|
| 250 |
+
- [20] E. Moen, D. Bannon, T. Kudo, W. Graf, M. Covert, and D. Van Valen, 'Deep learning for cellular image analysis,' Nat. Methods , vol. 16, no. 12, p. 1233, 2019.
|
| 251 |
+
- [21] T. Prangemeier, C. Wildner, M. Hanst, and H. Koeppl, 'Maximizing information gain for the characterization of biomolecular circuits,' in Proc. 5th ACM/IEEE NanoCom , 2018, pp. 1-6.
|
| 252 |
+
- [22] L. Bandiera, D. Gomez-Cabeza, J. Gilman, E. Balsa-Canto, and F. Menolascina, 'Optimally Designed Model Selection for Synthetic Biology,' ACS Synth. Biol. , 2020.
|
| 253 |
+
- [23] A. Vaswani, N. Shazeer, N. Parmar, J. Uszkoreit, L. Jones, A. N. Gomez, Ł. Kaiser, and I. Polosukhin, 'Attention is all you need,' in NeurIPS , 2017, pp. 5998-6008.
|
| 254 |
+
- [24] O. Ronneberger, P. Fischer, and T. Brox, 'U-Net: Convolutional Networks for Biomedical Image Segmentation,' in MICCAI , 2015, p. 234.
|
| 255 |
+
- [25] N. Dietler, M. Minder, V. Gligorovski, A. M. Economou, D. A. H. L. Joly, A. Sadeghi, C. H. M. Chan, M. Kozi´ nski, M. Weigert, A.-F. Bitbol, and S. J. Rahi, 'A convolutional neural network segments yeast microscopy images with high accuracy,' Nat. Commun. , p. 5723, 2020.
|
| 256 |
+
- [26] H. Wang, Y. Zhu, B. Green, H. Adam, A. Yuille, and L.-C. Chen, 'Axial-deeplab: Stand-alone axial-attention for panoptic segmentation,' arXiv:2003.07853 , 2020.
|
| 257 |
+
- [27] K. He, X. Zhang, S. Ren, and J. Sun, 'Deep residual learning for image recognition,' in IEEE/CVF CVPR , 2016, pp. 770-778.
|
| 258 |
+
- [28] A. L. Maas, A. Y. Hannun, and A. Y. Ng, 'Rectifier nonlinearities improve neural network acoustic models,' in ICML , 2013, p. 3.
|
| 259 |
+
- [29] A. Molina, P. Schramowski, and K. Kersting, 'Pad´ e activation units: End-to-end learning of flexible activation functions in deep networks,' in ICLR , 2019.
|
| 260 |
+
- [30] X. Zhu, H. Hu, S. Lin, and J. Dai, 'Deformable convnets v2: More deformable, better results,' in IEEE/CVF CVPR , 2019, pp. 9308-9316.
|
| 261 |
+
- [31] H. Su, V. Jampani, D. Sun, O. Gallo, E. Learned-Miller, and J. Kautz, 'Pixel-adaptive convolutional neural networks,' in IEEE/CVF CVPR , 2019, pp. 11 166-11 175.
|
| 262 |
+
- [32] H. W. Kuhn, 'The hungarian method for the assignment problem,' Naval Research Logistics Quarterly , vol. 2, no. 1-2, pp. 83-97, 1955.
|
| 263 |
+
- [33] H. Rezatofighi, N. Tsoi, J. Gwak, A. Sadeghian, I. Reid, and S. Savarese, 'Generalized intersection over union: A metric and a loss for bounding box regression,' in IEEE/CVF CVPR , 2019, pp. 658-666.
|
| 264 |
+
- [34] T.-Y. Lin, P. Goyal, R. Girshick, K. He, and P. Doll´ ar, 'Focal loss for dense object detection,' in IEEE ICCV , 2017, pp. 2980-2988.
|
| 265 |
+
- [35] K. Chen, J. Wang, J. Pang et al. , 'MMDetection: Open mmlab detection toolbox and benchmark,' arXiv:1906.07155 , 2019.
|
| 266 |
+
- [36] I. Loshchilov and F. Hutter, 'Decoupled weight decay regularization,' in ICLR , 2019.
|
text-versions/attention-markdown/2012.02994_AttentionDriven Dynamic Graph Convolutio.md
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2012.02994 Attentiondriven Dynamic Graph Convolutio
|
| 2 |
+
|
| 3 |
+
## Attention-Driven Dynamic Graph Convolutional Network for Multi-Label Image Recognition
|
| 4 |
+
|
| 5 |
+
Jin Ye 1 ∗ , Junjun He 1 , 2 ∗ , Xiaojiang Peng 1 ∗ , Wenhao Wu 1 , and Yu Qiao 1 †
|
| 6 |
+
|
| 7 |
+
1 ShenZhen Key Lab of Computer Vision and Pattern Recognition, Shenzhen Institutes of Advanced Technology, Chinese Academy of Sciences, Shenzhen, China. 2 School of Biomedical Engineering, the Institute of Medical Robotics, Shanghai Jiao Tong University, Shanghai, China.
|
| 8 |
+
|
| 9 |
+
Abstract. Recent studies often exploit Graph Convolutional Network (GCN) to model label dependencies to improve recognition accuracy for multi-label image recognition. However, constructing a graph by counting the label co-occurrence possibilities of the training data may degrade model generalizability, especially when there exist occasional cooccurrence objects in test images. Our goal is to eliminate such bias and enhance the robustness of the learnt features. To this end, we propose an Attention-Driven Dynamic Graph Convolutional Network (ADD-GCN) to dynamically generate a specific graph for each image. ADD-GCN adopts a Dynamic Graph Convolutional Network (D-GCN) to model the relation of content-aware category representations that are generated by a Semantic Attention Module (SAM). Extensive experiments on public multi-label benchmarks demonstrate the effectiveness of our method, which achieves mAPs of 85.2%, 96.0%, and 95.5% on MSCOCO, VOC2007, and VOC2012, respectively, and outperforms current state-of-the-art methods with a clear margin. All codes can be found at https://github.com/Yejin0111/ADD-GCN .
|
| 10 |
+
|
| 11 |
+
Keywords: Multi-label image recognition, semantic attention, label de- pendency, dynamic graph convolutional network
|
| 12 |
+
|
| 13 |
+
## 1 Introduction
|
| 14 |
+
|
| 15 |
+
Nature scenes usually contains multiple objects. In the computer vision community, multi-label image recognition is a fundamental computer vision task and plays a critical role in wide applications such as human attribute recognition [19], medical image recognition [9] and recommendation systems [15,33]. Unlike single-label classification, multi-label image recognition needs to assign multiple labels to a single image. Therefore it is reasonable to take account of the relationships of different labels to enhance recognition performance.
|
| 16 |
+
|
| 17 |
+
Recently, Graph Convolutional Network (GCN) [16] achieves great success in modeling relationship among vertices of a graph. Current state-of-the art methods [2,4] build a complete graph to model the label correlations between each two categories by utilizing prior frequency of label co-occurrence of the target dataset and achieved remarkable results. However, building such a global graph for the whole dataset could cause the frequency-bias problem in most common datasets. As highlighted in [25,26], most prominent vision datasets are afflicted with the co-occur frequency biases despite the best efforts of their creators. Let us consider a common category 'car', which always appears with different kind of vehicles such as 'truck', 'motorbike', and 'bus'. This may inadvertently cause the frequency-bias in these datasets, which would guide the model to learn higher relations among them. Specifically, as shown in Fig 1(a), each image share a static graph which is built by calculating the co-occurrence frequency of categories in target dataset. The static graph gives higher relation values between 'car' and 'truck' and lower ones between 'car' and 'toilet'in each image. This may result in several problems as follows: 1) failing to identify 'car' in a different context such as in the absence of 'truck', 2) hallucinating 'truck' even in a scene containing only 'car', and 3) ignoring 'toilet' when 'car' co-occurs with 'toilet'.
|
| 18 |
+
|
| 19 |
+
∗ Equally-contributed first authors. † Corresponding author (yu.qiao@siat.ac.cn)
|
| 20 |
+
|
| 21 |
+
Fig. 1. Static graph and dynamic graph. Solid line indicates higher relation and dashed line indicates lower relation of the categories. (a) illustrates all images share a static graph [2,3]. (b) shows our motivation that different image has its own graph that can describe the relations of co-occurred categories in the image.
|
| 22 |
+
|
| 23 |
+
<!-- image -->
|
| 24 |
+
|
| 25 |
+
Given these issues, our goal is to build a dynamic graph that can capture the content-aware category relations for each image. Specifically, as shown in Fig 1(b), we construct the image-specific dynamic graph in which 'car' and 'toilet' has strong connections for the image that 'car' and 'toilet' appear together and vice versa. To this end, we propose a novel Attention-Driven Dynamic Graph Convolutional Network (ADD-GCN) for multi-label image recognition which leverages content-aware category representations to construct dynamic graph representation. Unlike previous graph based methods [2,4], ADD-GCN models semantic relation for each input image by estimating an image-specific dynamic graph. Specifically, we first decompose the convolutional feature map into multiple content-aware category representations through the Semantic Attention Module (SAM). Then we feed these representations into a Dynamic GCN(D-GCN) module which performs feature propagation via two joint graphs: static graph and dynamic graph. Finally discriminative vectors are generated by D-GCN for multi-label classification. The static graph mainly captures coarse label dependencies over the training dataset and learns such semantic relations as shown in Fig 1(a). The correlation matrix of dynamic graph is the output feature map of a light-weight network applied upon content-aware category representations for each image, and is used to capture fine dependencies of those content-aware category representations as illustrated in Fig 1(b).
|
| 26 |
+
|
| 27 |
+
Our main contributions can be summarized as follows,
|
| 28 |
+
|
| 29 |
+
- -The major contribution of this paper is that we introduce a novel dynamic graph constructed from content-aware category representations for multilabel image recognition. The dynamic graph is able to capture category relations for a specific image in an adaptive way, which further enhance its representative and discriminative ability.
|
| 30 |
+
- -We elaborately design an end-to-end Attention-Driven Dynamic Graph Convolutional Network (ADD-GCN), which consists of two joint modules. i) Semantic Attention Module (SAM) for locating semantic regions and producing content-aware category representations for each image, and ii) Dynamic Graph Convolutional Network (D-GCN) for modeling the relation of content-aware category representations for final classification.
|
| 31 |
+
- -Our ADD-GCN significantly outperforms recent state-of-the-art approaches on popular multi-label datasets: MS-COCO, VOC2007, and VOC2012. Specifically, our ADD-GCN achieves mAPs of 85.2% on MS-COCO, 96.0% on VOC2007, and 95.5% on VOC2012, respectively, which are new records on these benchmarks.
|
| 32 |
+
|
| 33 |
+
## 2 Related work
|
| 34 |
+
|
| 35 |
+
Recent renaissance of deep neural network remarkably accelerates the progresses in single-label image recognition. Convolutional Neural Networks (CNNs) can learn powerful features from large scale image datasets such as MS-COCO [20], PASCAL VOC [7] and ImageNet [6], which greatly alleviates the difficulty of designing hand-crafted features. Recently, many CNN-based approaches have been proposed for multi-label image recognition as well [2,5,10,23,37,27,30], which can be roughly categorized into two main directions as following.
|
| 36 |
+
|
| 37 |
+
Region based methods . One direction aims to first coarsely localize multiple regions and then recognize each region with CNNs [5,10,23,37]. Wei et al. [31] propose a Hypotheses-CNN-Pooling (HCP) framework which generates a large number of proposals by objectness detection methods [5,37] and treats each proposal as a single-label image recognition problem. Yang et al. [32] formulate the task as a multi-class multi-instance learning problem. Specifically, they incorporate local information by generating a bag of instances for each image and enhance the discriminative features with label information. However, these object proposal based methods lead to numerous category-agnostic regions, which make the whole framework sophisticated and require massive computational cost. Moreover, these methods largely ignore the label dependencies and region relations, which are essential for multi-label image recognition.
|
| 38 |
+
|
| 39 |
+
Relation based methods . Another direction aims to exploit the label dependencies or region relations [27,30,17,4,2,29]. Wang et al. [27] propose CNNRNN framework to predict the final scores and formulate label relation by utilizing Recurrent Neural Network (RNN). Wang et al. [30] attempt to discover such relations by iterative locating attention regions with spatial transformer [14] and LSTM [13]. Actually, these RNN/LSTM based methods explore the relation between labels or semantic regions in a sequential way, which cannot fully exploit the direct relations among them. Different from these sequential methods, some works resort to Graphical architectures. Li et al. [17] cope with such relations by image-dependent conditional label structures with Graphical Lasso framework. Li et al. [18] use a maximum spanning tree algorithm to create a tree-structured graph in the label space. Recently, the remarkable capacity of Graph Convolutional Networks (GCNs) has been proved in several vision tasks, Chen et al. [4] utilize GCN to propagate prior label representations (e.g. word embeddings) and generate a classifier, which replaces the last linear layer in a normal deep convolutional neural network such as ResNet [11]. With the help of label annotations, Chen et al. [2] compute a probabilistic matrix as the relation edge between each label in a graph. Our work is largely inspired by these GCN based methods for multi-label image recognition. However, instead of using external word embedding for category representations and label statistics for graph construction, our Attention-Driven Dynamic Graph Convolutional Network (ADD-GCN) directly decomposes the feature map extracted by a CNN backbone into content-aware category representations and optimizes the D-GCN, which consists of a static graph for capturing the global coarse category dependencies and a dynamic graph for exploiting content-dependent category relations, respectively.
|
| 40 |
+
|
| 41 |
+
## 3 Method
|
| 42 |
+
|
| 43 |
+
This section presents Attention-Driven Dynamic Graph Convolutional Network (ADD-GCN) for multi-label image recognition. We first give a brief overview of ADD-GCN, and then describe its key modules (Semantic Attention Module and Dynamic GCN module) in details.
|
| 44 |
+
|
| 45 |
+
## 3.1 Overview of ADD-GCN
|
| 46 |
+
|
| 47 |
+
As objects always co-occur in image, how to effectively capture the relations among them is important for multi-label recognition. Graph based representations provide a practical way to model label dependencies. We can use nodes V = [ v 1 , v 2 , . . . , v C ] to represent labels and correlation matrix A to represent the label relations (edges). Recent studies [2,4] exploited Graph Convolutional Network (GCN) to improve the performance of multi-label image recognition with a clear margin. However, they construct correlation matrix A in a static way, which mainly accounts for the label co-occurrence in the training dataset, and is fixed for each input image. As a result, they fail to explicitly utilize the content of each specific input image.
|
| 48 |
+
|
| 49 |
+
Fig. 2. Overall framework of our approach. Given an image, ADD-GCN first uses a CNN backbone to extract convolutional feature maps X . Then, SAM decouples X to content-aware category representations V , and D-GCN models global and local relations among V to generate the final robust representations Z that contains rich relation information with other categories.
|
| 50 |
+
|
| 51 |
+
<!-- image -->
|
| 52 |
+
|
| 53 |
+
To address this problem, this paper proposes ADD-GCN with two elaborately designed modules: We first introduce Semantic Attention Module (SAM) to estimate content-aware category representation v c for each class c from the extracted feature map and the representations are input to another module, Dynamic-GCN, for final classification. We will detail them in the next part.
|
| 54 |
+
|
| 55 |
+
## 3.2 Semantic Attention Module
|
| 56 |
+
|
| 57 |
+
The objective of Semantic Attention Module (SAM) is to obtain a set of contentaware category representations, each of which describes the contents related to a specific label from input feature map X ∈ R H × W × D . As shown in Fig 2, SAM first calculates category-specific activation maps M = [ m 1 , m 2 , . . . , m C ] ∈ R H × W × C and then they are used to convert the transformed feature map X ′ ∈ R H × W × D ′ into the content-aware category representations V = [ v 1 , v 2 , . . . , v C ] ∈ R C × D . Specifically, each class representation v c is formulated as a weighted sum on X ′ as follows, such that the produced v c can selectively aggregate features related to its specific category c .
|
| 58 |
+
|
| 59 |
+
<!-- formula-not-decoded -->
|
| 60 |
+
|
| 61 |
+
where m c i,j and x ′ i,j ∈ R D ′ are the weight of c th activation map and the feature vector of the feature map at ( i, j ), respectively. Then the problem reduces to how to calculate the category-specific activation maps M , where the difficulty comes from we do not have explicit supervision like bounding box or category segmentation for images.
|
| 62 |
+
|
| 63 |
+
Activation map generation . We generate the category-specific activation maps M based on Class Activation Mapping (CAM) [35], which is a technique to expose the implicit attention on an image without bounding box and segmentation. Specifically, we can perform Global Average Pooling (GAP) or Global Max Pooling (GMP) on the feature map X and classify these pooled features with FC classifiers. Then these classifiers are used to identify the category-specific activation maps by convolving the weights of FC classifiers with feature map X . Unlike CAM, we put a convolution layer as the classifier as well as a Sigmoid ( · ) to regularize M before the global spatial pooling, which has better performance in experiments. Ablation studies on these methods are presented in Table 6.
|
| 64 |
+
|
| 65 |
+
## 3.3 Dynamic GCN
|
| 66 |
+
|
| 67 |
+
With content-aware category representations V obtained in previous section, we introduce Dynamic GCN (D-GCN) to adaptively transform their coherent correlation for multi-label recognition. Recently Graph Convolutional Network (GCN) [16] has been widely proven to be effective in several computer vision tasks and is applied to model label dependencies for multi-label image recognition with a static graph [2,4]. Different from these works, we propose a novel D-GCN to fully exploit relations between content-aware category representations to generate discriminative vectors for final classification. Specifically, our D-GCN consists of two graph representations, static graph and dynamic graph, as shown in Fig 2. We first revisit the traditional GCN and then detail our D-GCN.
|
| 68 |
+
|
| 69 |
+
Revisit GCN . Given a set of features V ∈ R C × D as input nodes, GCN aims to utilize a correlation matrix A ∈ R C × C and a state-update weight matrix W ∈ R D × D u to update the values of V . Formally, The updated nodes V u ∈ R C × D u can be formulated by a single-layer GCN as
|
| 70 |
+
|
| 71 |
+
<!-- formula-not-decoded -->
|
| 72 |
+
|
| 73 |
+
where A is usually pre-defined and W is learned during training. δ ( · ) denotes an activation function, such as the ReLU ( · ) or Sigmoid ( · ), which makes the whole operation nonlinear. The correlation matrix A reflects the relations between the features of each node. During inference, the correlation matrix Afi rst diffuse the correlated information among all nodes, then each node receives all necessary information and its state is updated through a linear transformation W .
|
| 74 |
+
|
| 75 |
+
D-GCN . As shown in the bottom of Fig 2, D-GCN takes the content-aware category representations V as input node features, and sequentially feeds them into a static GCN and a dynamic GCN. Specifically, the single-layer static GCN is simply defined as H = LReLU ( A s VW s ), where H = [ h 1 , h 2 , . . . , h C ] ∈ R C × D 1 , the activation function LReLU ( · ) is LeakyReLU, and the correlation matrix A s and state-update weights W is randomly initialized and learned by gradient decent during training. Since A s is shared for all images, it is expected that A s can capture global coarse category dependencies.
|
| 76 |
+
|
| 77 |
+
In the next, we introduces dynamic GCN to transform H , whose correlation matrix A d is estimated adaptively from input features H . Note this is different from static GCN whose correlation matrix is fixed and shared for all input samples after training, while our A d is constructed dynamically dependent on input feature. Since every sample has different A d , it makes model increase its representative ability and decrease the over-fitting risk that static graph brings. Formally, the output Z ∈ R C × D 2 of the dynamic GCN can be defined as,
|
| 78 |
+
|
| 79 |
+
<!-- formula-not-decoded -->
|
| 80 |
+
|
| 81 |
+
where f ( · ) is the LeakyReLU activation function, δ ( · ) is the Sigmoid activation function, W d ∈ R D 1 × D 2 is the state-update weights, W A ∈ R C × 2 D 1 is the weights of a conv layer to formulate the dynamic correlation matrix A d , and H ′ ∈ R 2 D 1 × C is obtained by concatenating H and its global representations h g ∈ R D 1 , which is obtained by global average pooling and one conv layer, sequentially. Formally, H ′ is defined as,
|
| 82 |
+
|
| 83 |
+
<!-- formula-not-decoded -->
|
| 84 |
+
|
| 85 |
+
It is worth mentioning that the dynamic graph A d is specific for each image which may capture content-dependent category dependencies. Overall, our DGCN enhances the content-aware category representations from V to Z by the dataset-specific graph and the image-specific graph.
|
| 86 |
+
|
| 87 |
+
## 3.4 Final Classification and Loss
|
| 88 |
+
|
| 89 |
+
Final Classification . As shown in Fig 2, the final category representation Z = [ z 1 , z 2 , . . . , z C ] is used for final classification. Due to each vector z i is aligned with its specific class and contains rich relation information with others, we simply put each category vector into a binary classifier to predict its category score. In particular, we concatenate the score for each category to generate the final score vector s r = [ s 1 r , s 2 r , . . . , s C r ]. In addition, we can also get another confident scores s m = [ s 1 m , s 2 m , . . . , s C m ] through global spatial pooling on the category-specific activation map M estimated by SAM in Section 3.2. Thus, we can aggregate the two score vectors to predict more reliable results. Here we simply average them to produce the final scores s = [ s 1 , s 2 , . . . , s C ].
|
| 90 |
+
|
| 91 |
+
Training Loss . We supervise the final score s and train the whole ADDGCN with the traditional multi-label classification loss as follows,
|
| 92 |
+
|
| 93 |
+
<!-- formula-not-decoded -->
|
| 94 |
+
|
| 95 |
+
where σ ( · ) is Sigmoid ( · ) function.
|
| 96 |
+
|
| 97 |
+
## 4 Experiments
|
| 98 |
+
|
| 99 |
+
In this section, we first introduce the evaluation metrics and our implementation details. And then, we compare our ADD-GCN with other existing state-of-theart methods on three public multi-label image recognition dataset, i.e. , MSCOCO [20], Pascal VOC 2007 [7], and Pascal VOC 2012 [7]. Finally, we conduct extensive ablation studies and present some visualization results of the categoryspecific activation maps and the dynamic graphs.
|
| 100 |
+
|
| 101 |
+
## 4.1 Evaluation Metrics
|
| 102 |
+
|
| 103 |
+
To compare with other existing methods in a fair way, we follow previous works [2,4,36] to adopt the average of overall/per-class precision (OP/CP), overall/per-class recall (OR/CR), overall/per-class F1-score (OF1/CF1) and the mean Average Precision (mAP) as evaluation metrics. When measuring precision/recall/F1score, the label is considered as positive if its confident score is great than 0.5. Besides, top-3 results of precision/recall/F1-score are also reported. Generally, the OF1, CF1 and mAP are more important than other metrics.
|
| 104 |
+
|
| 105 |
+
## 4.2 Implementation Details
|
| 106 |
+
|
| 107 |
+
For the whole ADD-GCN framework, we use ResNet-101 [11] as our backbone. The channel of V is 1024 and the nonlinear activation function LeakyReLU with negative slop of 0.2 is adopted in our SAM and D-GCN. During training, we adopt the data augmentation suggested in [4] to avoid over-fitting: the input image is random cropped and resized to 448 × 448 with random horizontal flips for data augmentation. To make our model converge quickly, we follow [2] to choose the model that trained on COCO as the pre-train model for Pascal VOC. We choose SGD as our optimizer, with momentum of 0.9 and weight decay of 10 -4 . The batch size of each GPU is 18. The initial learning rate is set to 0.5 for SAM/D-GCN and 0.05 for backbone CNN. We train our model for 50 epoch in total and the learning rate is reduced by a factor of 0.1 at 30 and 40 epoch, respectively. All experiments are implemented based on PyTorch [22].
|
| 108 |
+
|
| 109 |
+
Table 1. Comparison of our ADD-GCN and other state-of-the-art methods on MSCOCO dataset. The best results are marked as bold.
|
| 110 |
+
|
| 111 |
+
| Method All Top-3 mAP CP CR CF1 OP OR OF1 CP CR CF1 OP OR OF1 RARL [1] - - - - - - - 78.8 57.2 66.2 84.0 61.6 71.1 RDAR [30] - - - - - - - 79.1 58.7 67.4 84.0 63.0 72.0 Multi-Evidence [8] - 80.4 70.2 74.9 85.2 72.5 78.4 84.5 62.2 70.6 89.1 64.3 74.7 ResNet-101 [11] 79.7 82.7 67.4 74.3 86.4 71.8 78.4 85.9 60.5 71.0 90.2 64.2 75.0 DecoupleNet [21] 82.2 83.1 71.6 76.3 84.7 74.8 79.5 - - - - - - ML-GCN [4] 83.0 85.1 72.0 78.0 85.8 75.4 80.3 89.2 64.1 74.6 90.5 66.5 76.7 SSGRL [2] 83.8 89.9 68.5 76.8 91.3 70.8 79.7 91.9 62.5 72.7 93.8 64.1 76.2 Ours 85.2 84.7 75.9 80.1 84.9 79.4 82.0 88.8 66.2 75.8 90.3 68.5 77.9 |
|
| 112 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 113 |
+
|
| 114 |
+
## 4.3 Comparison with State of The Arts
|
| 115 |
+
|
| 116 |
+
To demonstrate the scalability and effectiveness of our proposed ADD-GCN, extensive experiments are conducted on three widely used benchmarks, i.e., MSCOCO [20], Pascal VOC 2007 [7], and Pascal VOC 2012 [7].
|
| 117 |
+
|
| 118 |
+
MS-COCO . Microsoft COCO [20] is primarily built for object segmentation and detection, and it is also widely used for multi-label recognition recently. It is composed of a training set with 82081 images, a validation set with 40137 images. The dataset covers 80 common object categories with about 2.9 object labels per image. The number of labels for each image varies considerably, rendering MS-COCO more challenging. Since the labels of the test set are not given, we compare our performance to other previous methods on the validation set.
|
| 119 |
+
|
| 120 |
+
Table 1 shows the comparison between our ADD-GCN and other state-ofthe-art methods. In particular, we compare with RARL [1], RDAR [30], MultiEvidence [8], ResNet-101 [11], DecoupleNet [21], ML-GCN [4], and SSGRL [2]. Our ADD-GCN consistently outperforms the other state-of-the-art approaches in terms of OF1, CF1, and mAP, as well as some other less important metrics. In particular, both ML-GCN and SSGRL also construct graphs for multi-label classification, our ADD-GCN respectively outperforms ML-GCN by 2.2% and SSGRL by 1.4% in terms of mAP. In addition, our ADD-GCN improves the baseline by 5.5%. This demonstrates the superiority of our approach.
|
| 121 |
+
|
| 122 |
+
VOC 2007 . Pascal VOC 2007 [7] is widely used multi-label dataset, which contains 9963 images from 20 common object categories. It is divided into a train set, a validation set, and a test set. For fair comparisons, following previous works [2,4], we train our model on the trainval set (5011 images) and evaluate on the test set (4952 images). The evaluation metrics are the Average Precision (AP) and the mean of Average Precision (mAP).
|
| 123 |
+
|
| 124 |
+
The comparison between our ADD-GCN and other methods is presented in Table 2. Our method consistently outperforms these methods with a clear margin, and improves our baseline from 90.8% to 96.0%. Particularly, compared with other two current state-of-the-art methods ML-GCN and SSGRL [2], the gain of overall mAP is 2.0% and 1.0%, respectively.
|
| 125 |
+
|
| 126 |
+
Table 2. Comparison of our ADD-GCN and other state-of-the-art methods on Pascal VOC 2007 dataset. The best results are marked as bold.
|
| 127 |
+
|
| 128 |
+
| Method aero bike bird boat bottle bus car cat chair cow table dog horse mbike person plant sheep sofa train tv mAP CNN-RNN [27] 96.7 83.1 94.2 92.8 61.2 82.1 89.1 94.2 64.2 83.6 70.0 92.4 91.7 84.2 93.7 59.8 93.2 75.3 99.7 78.6 84.0 RMIC [12] 97.1 91.3 94.2 57.1 86.7 90.7 93.1 63.3 83.3 76.4 92.8 94.4 91.6 95.1 92.3 59.7 86.0 69.5 96.4 79.0 84.5 RLSD [34] 96.4 92.7 93.8 94.1 71.2 92.5 94.2 95.7 74.3 90.0 74.2 95.4 96.2 92.1 97.9 66.9 93.5 73.7 97.5 87.6 88.5 VeryDeep [24] 98.9 95.0 96.8 95.4 69.7 90.4 93.5 96.0 74.2 86.6 87.8 96.0 96.3 93.1 97.2 70.0 92.1 80.3 98.1 87.0 89.7 ResNet-101 [11] 99.1 97.3 96.2 94.7 68.3 92.9 95.9 94.6 77.9 89.9 85.1 94.7 96.8 94.3 98.1 80.8 93.1 79.1 98.2 91.1 90.8 HCP [31] 98.6 97.1 98.0 95.6 75.3 94.7 95.8 97.3 73.1 90.2 80.0 97.3 96.1 94.9 96.3 78.3 94.7 76.2 97.9 91.5 90.9 RDAR [30] 98.6 97.4 96.3 96.2 75.2 92.4 96.5 97.1 76.5 92.0 87.7 96.8 97.5 93.8 98.5 81.6 93.7 82.8 98.6 89.3 91.9 FeV+LV [32] 98.2 96.9 97.1 95.8 74.3 94.2 96.7 96.7 76.7 90.5 88.0 96.9 97.7 95.9 98.6 78.5 93.6 82.4 98.4 90.4 92.0 RARL [1] 98.6 97.1 97.1 95.5 75.6 92.8 96.8 97.3 78.3 92.2 87.6 96.9 96.5 93.6 98.5 81.6 93.1 83.2 98.5 89.3 92.0 RCP [28] 99.3 97.6 98.0 96.4 79.3 93.8 96.6 97.1 78.0 88.7 87.1 97.1 96.3 95.4 99.1 82.1 93.6 82.2 98.4 92.8 92.5 ML-GCN [4] 99.5 98.5 98.6 98.1 80.8 94.6 97.2 98.2 82.3 95.7 86.4 98.2 98.4 96.7 99.0 84.7 96.7 84.3 98.9 93.7 94.0 SSGRL [2] 99.7 98.4 98.0 97.6 85.7 96.2 98.2 98.8 82.0 98.1 89.7 98.8 98.7 97.0 99.0 86.9 98.1 85.8 99.0 93.7 95.0 Ours 99.8 99.0 98.4 99.0 86.7 98.1 98.5 98.3 85.8 98.3 88.9 98.8 99.0 97.4 99.2 88.3 98.7 90.7 99.5 97.0 96.0 |
|
| 129 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 130 |
+
|
| 131 |
+
Table 3. Comparison of our ADD-GCN and other state-of-the-art methods on Pascal VOC 2012 dataset. The best results are marked as bold.
|
| 132 |
+
|
| 133 |
+
| Methods aero bike bird boat bottle bus car cat chair cow table dog horse mbike person plant sheep sofa train tv mAP RMIC [12] 98.0 85.5 92.6 88.7 64.0 86.8 82.0 94.9 72.7 83.1 73.4 95.2 91.7 90.8 95.5 58.3 87.6 70.6 93.8 83.0 84.4 VeryDeep [24] 99.1 88.7 95.7 93.9 73.1 92.1 84.8 97.7 79.1 90.7 83.2 97.3 96.2 94.3 96.9 63.4 93.2 74.6 97.3 87.9 89.0 HCP [31] 99.1 92.8 97.4 94.4 79.9 93.6 89.8 98.2 78.2 94.9 79.8 97.8 97.0 93.8 96.4 74.3 94.7 71.9 96.7 88.6 90.5 FeV+LV [32] 98.4 92.8 93.4 90.7 74.9 93.2 90.2 96.1 78.2 89.8 80.6 95.7 96.1 95.3 97.5 73.1 91.2 75.4 97.0 88.2 89.4 RCP [28] 99.3 92.2 97.5 94.9 82.3 94.1 92.4 98.5 83.8 93.5 83.1 98.1 97.3 96.0 98.8 77.7 95.1 79.4 97.7 92.4 92.2 SSGRL [2] 99.7 96.1 97.7 96.5 86.9 95.8 95.0 98.9 88.3 97.6 87.4 99.1 99.2 97.3 99.0 84.8 98.3 85.8 99.2 94.1 94.8 Ours 99.8 97.1 98.6 96.8 89.4 97.1 96.5 99.3 89.0 97.7 87.5 99.2 99.1 97.7 99.1 86.3 98.8 87.0 99.3 95.4 95.5 |
|
| 134 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 135 |
+
|
| 136 |
+
VOC 2012 . Pascal VOC 2012 [7] is the dataset that is widely used for multilabel image recognition task, which consists of 11540 images as trainval set and 10991 as test set from 20 common object categories. For fair comparisons with previous state-of-the-art methods, we train our model on the trainval set and evaluate our results on test set.
|
| 137 |
+
|
| 138 |
+
We present the AP of each category and mAP over all categories of VOC 2012 in Table 3. Our ADD-GCN also achieves the best performance compared with other state-of-the-art methods. Concretely, the proposed ADD-GCN obtains 95.5% mAP, which outperforms another state-of-the-art SSGRL by 0.7%. And the AP of each category is higher than other methods except 'horse'. The results demonstrate the effectiveness of our framework.
|
| 139 |
+
|
| 140 |
+
## 4.4 Ablation Studies
|
| 141 |
+
|
| 142 |
+
In this section, we conduct ablation experiments on MS-COCO and VOC 2007.
|
| 143 |
+
|
| 144 |
+
Evaluation of SAM and D-GCN . To investigate the contribution of each module in ADD-GCN, we separately apply SAM and D-GCN with certain adaptions upon a standard ResNet backbone. We evaluate the effectiveness of SAM by removing D-GCN and adding binary classifiers upon the output of SAM ( V )
|
| 145 |
+
|
| 146 |
+
Performance(%)
|
| 147 |
+
|
| 148 |
+
Fig. 3. Evaluation of SAM and D-GCN on MS-COCO and VOC 2007.
|
| 149 |
+
|
| 150 |
+
<!-- image -->
|
| 151 |
+
|
| 152 |
+
Table 4. The performance of different combinations of static and dynamic graph. 'S': static graph and 'D': dynamic graph. 'P': we propagate information through the static and dynamic graph in a parallel way, and fuse them by either addition (add) or element-wise multiplication (mul) or concatenation (cat).
|
| 153 |
+
|
| 154 |
+
| Methods All (COCO) All (VOC 2007) mAP OF1 CF1 mAP OF1 CF1 ResNet-101 79.7 78.4 74.3 90.8 84.3 83.4 S 82.9 78.3 74.7 94.5 89.3 88.3 D 83.7 79.4 76.6 94.9 89.9 88.7 P (add) 84.0 79.4 76.9 94.6 88.8 88.2 P (mul) 83.7 80.8 78.5 94.6 89.6 88.5 P (cat) 83.3 80.0 76.9 94.9 89.7 88.8 D → S 84.5 81.4 79.3 95.0 90.1 88.8 S → D 85.2 82.0 80.1 96.0 91.0 89.9 |
|
| 155 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 156 |
+
|
| 157 |
+
directly, while for evaluating the effectiveness of D-GCN, we simply replace SAM with a Conv-LReLU block. The results are shown in Fig 3. As can be seen, on both MS-COCO and VOC-2007, SAM and D-GCN individually improve the baseline with large margins. Compared to the baseline that directly learn classifier upon global-pooled features, SAM first decomposes the feature map into content-aware category representations and train classifiers upon them. The improvement from SAM shows that the decomposed representations are more discriminative. We also find that D-GCN is able to enhance the discriminative ability of features from the results compared with the baseline. Combining SAM and D-GCN further boosts performance as we expect, since they focus on different aspects. Specifically, the gain of the mAP, OF1 and CF1 over the baseline is 5.5%, 3.6% and 5.8% on MS-COCO, while 5.2%, 6.7% and 6.5% on VOC 2007.
|
| 158 |
+
|
| 159 |
+
SAM+D-GCN
|
| 160 |
+
|
| 161 |
+
Table 5. Comparison of different final representations.
|
| 162 |
+
|
| 163 |
+
| Methods All (COCO) All (VOC 2007) mAP OF1 CF1 mAP OF1 CF1 Sum 84.5 81.5 79.5 94.7 89.4 88.4 Avg 84.5 81.5 79.2 94.8 89.6 88.6 Max 83.9 81.2 78.8 94.7 89.6 88.8 Bi 85.2 82.0 80.1 96.0 91.0 89.9 |
|
| 164 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 165 |
+
|
| 166 |
+
Table 6. Evaluation of activation map generation.
|
| 167 |
+
|
| 168 |
+
| Methods All (COCO) All (VOC 2007) mAP OF1 CF1 mAP OF1 CF1 GAP → cls 85.0 82.0 79.8 94.8 89.7 88.5 GMP → cls 84.1 80.9 79.0 93.9 89.1 87.7 cls → GMP 85.2 82.0 80.1 96.0 91.0 89.9 |
|
| 169 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 170 |
+
|
| 171 |
+
Static graph vs Dynamic graph . We investigate the effects of static graph and dynamic graph in D-GCN. Results are shown in Table 4. Firstly, we study the case with only one graph. Both static and dynamic graph can achieve better performance compared with baseline ResNet-101, and the dynamic graph performs better on both MS-COCO and VOC 2007. The results show that modeling local ( i.e. , image-level) category-aware dependencies is more effective than coarse label dependencies over the whole dataset. To further explore whether the static graph is complementary with the dynamic graph, we attempt to combine them in different ways as shown in Table 4. 'S' stands for static graph, 'D' donates dynamic graph, 'P' denotes that we propagate information through the static graph and dynamic graph in a parallel way, and fuse them by either addition (add) or element-wise multiplication (mul) or concatenation (cat). From the results, 'S → D' achieves the best performance among all settings.
|
| 172 |
+
|
| 173 |
+
Final representations . To demonstrate the effectiveness and rationality of category-specific feature representations, we compare it with image-level feature representations by aggregating the category-specific feature representations to an image feature vector. For aggregation, Sumation (Sum), Average (Avg) and Maximum (Max) are adopted to fuse category-specific feature representations Z , which are the output of D-GCN for obtaining image-level feature representations. 'Bi' means that we utilize binary classifier for each category-specific feature representation to decide whether this class exists or not. Table 5 shows the results that the category-specific feature representations outperforms other aggregated representations on all metrics. Thus, we can believe it is an effective way to represent an input image by decomposing the feature map to category-specific representations for multi-label recognition.
|
| 174 |
+
|
| 175 |
+
Evaluation of activation map generation . As mentioned in Section 3.2, we first adopt the standard CAM as baseline. Here we compare the final performance of ADD-GCN between our method and the standard CAM. Specifically, CAM can be donated as 'GAP → cls' or 'GMP → cls', and ours is 'cls → GMP'. 'GAP → cls' equals to 'cls → GAP' since the classifier is linear operator. The results are shown in Table 6. Comparing the results of GAP ( i.e. , GAP → cls) and GMP ( i.e. , GMP → cls), we believe that GMP loses lots of information as GMP only identify one discriminative part. However, our adaption 'cls → GMP' outperforms 'GAP → cls', which indicates that the modified GMP(cls → GMP) may compensate for the disadvantages that 'GMP → cls' brings.
|
| 176 |
+
|
| 177 |
+
Fig. 4. Visualization results of category-specific activation maps on MS-COCO.
|
| 178 |
+
|
| 179 |
+
<!-- image -->
|
| 180 |
+
|
| 181 |
+
## 4.5 Visualization
|
| 182 |
+
|
| 183 |
+
In this section, we visualize some examples of category-specific activation maps and dynamic correlation matrix A d to illustrate whether SAM can locate semantic targets and what relations dynamic graph has learned, respectively.
|
| 184 |
+
|
| 185 |
+
Visualization of category-specific activation maps . We visualize original images with their corresponding category-specific activation maps to illustrate the capability of capturing the semantic region of each category appeared in the image with our SAM module. Some examples are shown in Fig 4, each row presents the original image, corresponding category-specific activation maps and the final score of each category. For the categories appeared in image, we observe that our model can locate their semantic regions accurately. In contrast, the activation map has low activation of categories that the image does not contain. For example, the second row has labels of 'person', 'tie' and 'chair', our ADD-GCN can accurately highlight related semantic regions of the three classes. Besides, the final scores demonstrate that the category-aware representations are discrminative enough, and can be accurately recognized by our method.
|
| 186 |
+
|
| 187 |
+
Visualization of dynamic graph . As shown in Fig 5, we visualize an original image with its corresponding dynamic correlation matrix A d to illustrate what relations D-GCN has learned. For the input image in Fig 5(a), its ground truths are 'car', 'dog' and 'person'. Fig 5(b) is the visualization of the A d of the input image. We can find that A car ; dog d and A car ; person d rank top (about top
|
| 188 |
+
|
| 189 |
+
Fig. 5. Visualization of an example and what its dynamic correlation matrix A d looks like on Pascal-VOC 2007.
|
| 190 |
+
|
| 191 |
+
<!-- image -->
|
| 192 |
+
|
| 193 |
+
10%) in the row of 'car'. It means that 'dog' and 'person' are more relevant for 'car' in the image. Similar results can also be found in the rows of 'dog' and 'person'. From the observation of the dynamic graph's visualization, we can believe that D-GCN has capacity to capture such semantic relations for a specific input image.
|
| 194 |
+
|
| 195 |
+
## 5 Conclusion
|
| 196 |
+
|
| 197 |
+
In this work, we propose an Attention-Driven Dynamic Graph Convolutional Network (ADD-GCN) for multi-label image recognition. ADD-GCN first decomposes the input feature map into category-aware representations by the Semantic Attention Module (SAM), and then models the relations of these representations for final recognition by a novel dynamic GCN which captures content-aware category relations for each image. Extensive experiments on public benchmarks (MS-COCO, Pascal VOC 2007, and Pascal VOC 2012) demonstrate the effectiveness and rationality of our ADD-GCN.
|
| 198 |
+
|
| 199 |
+
Acknowledgements . This work is partially supported by National Natural Science Foundation of China (U1813218, U1713208), Science and Technology Service Network Initiative of Chinese Academy of Sciences (KFJ-STS-QYZX092), Guangdong Special Support Program (2016TX03X276), and Shenzhen Basic Research Program (JSGG20180507182100698, CXB201104220032A), Shenzhen Institute of Artificial Intelligence and Robotics for Society. We also appreciate Xiaoping Lai and Hao Xing from VIPShop Inc. who cooperate this project with us and provide validation Fashion data.
|
| 200 |
+
|
| 201 |
+
## References
|
| 202 |
+
|
| 203 |
+
1. Chen, T., Wang, Z., Li, G., Lin, L.: Recurrent attentional reinforcement learning for multi-label image recognition. In: Thirty-Second AAAI Conference on Artificial Intelligence (2018)
|
| 204 |
+
2. Chen, T., Xu, M., Hui, X., Wu, H., Lin, L.: Learning semantic-specific graph representation for multi-label image recognition. arXiv preprint arXiv:1908.07325 (2019)
|
| 205 |
+
3. Chen, Y., Rohrbach, M., Yan, Z., Shuicheng, Y., Feng, J., Kalantidis, Y.: Graphbased global reasoning networks. In: Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition. pp. 433-442 (2019)
|
| 206 |
+
4. Chen, Z.M., Wei, X.S., Wang, P., Guo, Y.: Multi-label image recognition with graph convolutional networks. In: Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition. pp. 5177-5186 (2019)
|
| 207 |
+
5. Cheng, M.M., Zhang, Z., Lin, W.Y., Torr, P.: Bing: Binarized normed gradients for objectness estimation at 300fps. In: Proceedings of the IEEE conference on computer vision and pattern recognition. pp. 3286-3293 (2014)
|
| 208 |
+
6. Deng, J., Dong, W., Socher, R., Li, L.J., Li, K., Fei-Fei, L.: Imagenet: A largescale hierarchical image database. In: 2009 IEEE conference on computer vision and pattern recognition. pp. 248-255. Ieee (2009)
|
| 209 |
+
7. Everingham, M., Van Gool, L., Williams, C.K., Winn, J., Zisserman, A.: The pascal visual object classes (voc) challenge. International journal of computer vision 88 (2), 303-338 (2010)
|
| 210 |
+
8. Ge, W., Yang, S., Yu, Y.: Multi-evidence filtering and fusion for multi-label classification, object detection and semantic segmentation based on weakly supervised learning. In: Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition. pp. 1277-1286 (2018)
|
| 211 |
+
9. Ge, Z., Mahapatra, D., Sedai, S., Garnavi, R., Chakravorty, R.: Chest x-rays classification: A multi-label and fine-grained problem. arXiv preprint arXiv:1807.07247 (2018)
|
| 212 |
+
10. Girshick, R.: Fast r-cnn. In: Proceedings of the IEEE international conference on computer vision. pp. 1440-1448 (2015)
|
| 213 |
+
11. He, K., Zhang, X., Ren, S., Sun, J.: Deep residual learning for image recognition. In: Proceedings of the IEEE conference on computer vision and pattern recognition. pp. 770-778 (2016)
|
| 214 |
+
12. He, S., Xu, C., Guo, T., Xu, C., Tao, D.: Reinforced multi-label image classification by exploring curriculum. In: Thirty-Second AAAI Conference on Artificial Intelligence (2018)
|
| 215 |
+
13. Hochreiter, S., Schmidhuber, J.: Long short-term memory. Neural computation 9 (8), 1735-1780 (1997)
|
| 216 |
+
14. Jaderberg, M., Simonyan, K., Zisserman, A., et al.: Spatial transformer networks. In: Advances in neural information processing systems. pp. 2017-2025 (2015)
|
| 217 |
+
15. Jain, H., Prabhu, Y., Varma, M.: Extreme multi-label loss functions for recommendation, tagging, ranking & other missing label applications. In: Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining. pp. 935-944. ACM (2016)
|
| 218 |
+
16. Kipf, T.N., Welling, M.: Semi-supervised classification with graph convolutional networks. In: International Conference on Learning Representations (ICLR) (2017)
|
| 219 |
+
17. Li, Q., Qiao, M., Bian, W., Tao, D.: Conditional graphical lasso for multi-label image classification. In: Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition. pp. 2977-2986 (2016)
|
| 220 |
+
|
| 221 |
+
18. Li, X., Zhao, F., Guo, Y.: Multi-label image classification with a probabilistic label enhancement model. In: Proceedings of the Thirtieth Conference on Uncertainty in Artificial Intelligence. pp. 430-439. UAI'14, AUAI Press, Arlington, Virginia, United States (2914), http://dl.acm.org/citation.cfm?id=3020751.3020796
|
| 222 |
+
19. Li, Y., Huang, C., Loy, C.C., Tang, X.: Human attribute recognition by deep hierarchical contexts. In: European Conference on Computer Vision. pp. 684-700. Springer (2016)
|
| 223 |
+
20. Lin, T.Y., Maire, M., Belongie, S., Hays, J., Perona, P., Ramanan, D., Doll´ ar, P., Zitnick, C.L.: Microsoft coco: Common objects in context. In: European conference on computer vision. pp. 740-755. Springer (2014)
|
| 224 |
+
21. Liu, L., Guo, S., Huang, W., Scott, M.: Decoupling category-wise independence and relevance with self-attention for multi-label image classification. In: ICASSP 2019. pp. 1682-1686 (05 2019). https://doi.org/10.1109/ICASSP.2019.8683665
|
| 225 |
+
22. Paszke, A., Gross, S., Chintala, S., Chanan, G., Yang, E., DeVito, Z., Lin, Z., Desmaison, A., Antiga, L., Lerer, A.: Automatic differentiation in pytorch. In: NIPS Workshop (2017)
|
| 226 |
+
23. Ren, S., He, K., Girshick, R., Sun, J.: Faster r-cnn: Towards real-time object detection with region proposal networks. In: Advances in neural information processing systems. pp. 91-99 (2015)
|
| 227 |
+
24. Simonyan, K., Zisserman, A.: Very deep convolutional networks for large-scale image recognition. arXiv preprint arXiv:1409.1556 (2014)
|
| 228 |
+
25. Tommasi, T., Patricia, N., Caputo, B., Tuytelaars, T.: A deeper look at dataset bias. In: Domain adaptation in computer vision applications, pp. 37-55. Springer (2017)
|
| 229 |
+
26. Torralba, A., Efros, A.A.: Unbiased look at dataset bias. In: CVPR 2011. pp. 1521-1528. IEEE (2011)
|
| 230 |
+
27. Wang, J., Yang, Y., Mao, J., Huang, Z., Huang, C., Xu, W.: Cnn-rnn: A unified framework for multi-label image classification. In: Proceedings of the IEEE conference on computer vision and pattern recognition. pp. 2285-2294 (2016)
|
| 231 |
+
28. Wang, M., Luo, C., Hong, R., Tang, J., Feng, J.: Beyond object proposals: Random crop pooling for multi-label image recognition. IEEE Transactions on Image Processing 25 (12), 5678-5688 (2016)
|
| 232 |
+
29. Wang, Y., He, D., Li, F., Long, X., Zhou, Z., Ma, J., Wen, S.: Multi-label classification with label graph superimposing. arXiv preprint arXiv:1911.09243 (2019)
|
| 233 |
+
30. Wang, Z., Chen, T., Li, G., Xu, R., Lin, L.: Multi-label image recognition by recurrently discovering attentional regions. In: Proceedings of the IEEE international conference on computer vision. pp. 464-472 (2017)
|
| 234 |
+
31. Wei, Y., Xia, W., Lin, M., Huang, J., Ni, B., Dong, J., Zhao, Y., Yan, S.: Hcp: A flexible cnn framework for multi-label image classification. IEEE transactions on pattern analysis and machine intelligence 38 (9), 1901-1907 (2015)
|
| 235 |
+
32. Yang, H., Tianyi Zhou, J., Zhang, Y., Gao, B.B., Wu, J., Cai, J.: Exploit bounding box annotations for multi-label object recognition. In: Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition. pp. 280-288 (2016)
|
| 236 |
+
33. Yang, X., Li, Y., Luo, J.: Pinterest board recommendation for twitter users. In: Proceedings of the 23rd ACM international conference on Multimedia. pp. 963-966. ACM (2015)
|
| 237 |
+
34. Zhang, J., Wu, Q., Shen, C., Zhang, J., Lu, J.: Multilabel image classification with regional latent semantic dependencies. IEEE Transactions on Multimedia 20 (10), 2801-2813 (2018)
|
| 238 |
+
|
| 239 |
+
35. Zhou, B., Khosla, A., Lapedriza, A., Oliva, A., Torralba, A.: Learning deep features for discriminative localization. In: Computer Vision and Pattern Recognition (2016)
|
| 240 |
+
36. Zhu, F., Li, H., Ouyang, W., Yu, N., Wang, X.: Learning spatial regularization with image-level supervisions for multi-label image classification. In: Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition. pp. 5513-5522 (2017)
|
| 241 |
+
37. Zitnick, C.L., Doll´ ar, P.: Edge boxes: Locating object proposals from edges. In: European conference on computer vision. pp. 391-405. Springer (2014)
|
text-versions/attention-markdown/2012.11879_FcaNet Frequency Channel Attention Netwo.md
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2012.11879 Fcanet Frequency Channel Attention Netwo
|
| 2 |
+
|
| 3 |
+
## FcaNet: Frequency Channel Attention Networks
|
| 4 |
+
|
| 5 |
+
Zequn Qin 1 , Pengyi Zhang 1 , Fei Wu 1 , 2 , Xi Li 1 , 2 * 1 College of Computer Science, Zhejiang University, 2
|
| 6 |
+
|
| 7 |
+
Shanghai Institute for Advanced Study, Zhejiang University
|
| 8 |
+
|
| 9 |
+
zequnqin@gmail.com, pyzhang@zju.edu.cn, wufei@cs.zju.edu.cn, xilizju@zju.edu.cn
|
| 10 |
+
|
| 11 |
+
## Abstract
|
| 12 |
+
|
| 13 |
+
Attention mechanism, especially channel attention, has gained great success in the computer vision field. Many works focus on how to design efficient channel attention mechanisms while ignoring a fundamental problem, i.e., channel attention mechanism uses scalar to represent channel, which is difficult due to massive information loss. In this work, we start from a different view and regard the channel representation problem as a compression process using frequency analysis. Based on the frequency analysis, we mathematically prove that the conventional global average pooling is a special case of the feature decomposition in the frequency domain. With the proof, we naturally generalize the compression of the channel attention mechanism in the frequency domain and propose our method with multi-spectral channel attention, termed as FcaNet. FcaNet is simple but effective. We can change a few lines of code in the calculation to implement our method within existing channel attention methods. Moreover, the proposed method achieves state-of-the-art results compared with other channel attention methods on image classification, object detection, and instance segmentation tasks. Our method could consistently outperform the baseline SENet, with the same number of parameters and the same computational cost. Our code and models will are publicly available at https: //github.com/cfzd/FcaNet .
|
| 14 |
+
|
| 15 |
+
## 1. Introduction
|
| 16 |
+
|
| 17 |
+
As an important and challenging problem in feature modeling, attention mechanisms for convolutional neural networks (CNNs) have recently attracted considerable attention and are widely used in many fields like computer vision [40] and natural language processing [34]. In principle, they aim at selectively concentrating on some important information and have many types of variants (e.g., spatial attention, channel attention, and self-attention) corresponding to different feature dimensions. Due to the simplicity and effectiveness in feature modeling, channel attention directly learns to attach importance weights with different channels, becoming a popular and powerful tool for the deep learning community.
|
| 18 |
+
|
| 19 |
+
* Corresponding author.
|
| 20 |
+
|
| 21 |
+
Figure 1. Classification accuracy comparison on ImageNet. With the same number of parameters and computational cost, our method consistently outperforms the baseline SENet.
|
| 22 |
+
|
| 23 |
+
<!-- image -->
|
| 24 |
+
|
| 25 |
+
Typically, a core step of channel attention approaches is to use a scalar for each channel to conduct the calculation due to the constrained computational overhead, and global average pooling (GAP) becomes the de-facto standard choice in the deep learning community because of its simplicity and efficiency. Nevertheless, every rose has its thorn. The simplicity of GAP makes it hard to well capture complex information for various inputs. Some methods like CBAM [39] and SRM [23] further use global max pooling and global standard deviation pooling to enhance the performance of GAP. Different from previous works, we consider the scalar representation of a channel as a compression problem. Namely, the information of a channel should be compactly encoded by a scalar while preserving the representation ability of the whole channel as much as possible. In this way, how to effectively compress a channel with a scalar due to the constrained computational overhead is a major difficulty, and it is crucial to channel attention.
|
| 26 |
+
|
| 27 |
+
With the above motivation, we propose to use the discrete cosine transform (DCT) to compress channels in the channel attention mechanism for the following reasons: 1) DCT is a widely used data compression method in signal processing, especially with digital images and videos. Many widely used image and video formats like JPEG, HEIF, MPEG, and H.26x use DCT to realize data compression. DCT has a strong energy compaction property [1, 30], so it could achieve high data compression ratio with high quality [2, 22]. This property meets the demand of the channel attention that representing a channel with a scalar. 2) DCT can be implemented with an element-wise multiplication, and it is differentiable. In this way, it can be easily integrated into CNNs. 3) Surprisingly, DCT can be viewed as a generalization of GAP. Mathematically, GAP (showing the effectiveness in SENet [21]) is only equivalent to the lowest frequency components of DCT, leaving many other potentially useful frequency components unexplored. This strongly motivates us to tailor DCT for the channel attention mechanism.
|
| 28 |
+
|
| 29 |
+
In this paper, we further propose a simple, novel, but effective multi-spectral channel attention (MSCA) framework based on the above discussions. In order to better compress channels and explore the components left out by GAP, we propose to tailor DCT and use multiple but limited frequency components of DCT for the channel attention mechanism. Note that although we use multi-spectral channel attention, each channel is still represented by only one scalar. Along with the MSCA framework, how to select the frequency component of DCT for each channel is important. In this way, we propose three kinds of frequency component selection criteria to fulfill and validate the MSCA framework, which are LF (Low Frequency based selection), TS (Two-Step selection), and NAS (Neural Architecture Search selection). With these selection criteria, our method achieves state-of-the-art performance against the other channel attention ones.
|
| 30 |
+
|
| 31 |
+
In a word, the main contribution of this work can be summarized as follows.
|
| 32 |
+
|
| 33 |
+
- Weregard the channel attention as a compression problem and introduce DCT in the channel attention. We then prove that conventional GAP is a special case of DCT. Based on this proof, we generalize the channel attention in the frequency domain and propose our method with the multi-spectral channel attention framework, termed as FcaNet.
|
| 34 |
+
- We propose three kinds of frequency component selection criteria along with the proposed multi-spectral channel attention framework to fulfill FcaNet.
|
| 35 |
+
- Extensive experiments demonstrate the proposed
|
| 36 |
+
|
| 37 |
+
method achieves state-of-the-art results on both ImageNet and COCO datasets, with the same computational cost as SENet. The results on ImageNet are shown in Fig. 1.
|
| 38 |
+
|
| 39 |
+
## 2. Related Work
|
| 40 |
+
|
| 41 |
+
Attention Mechanism in CNNs In [40], a visual attention method is first proposed to model the importance of features in the image caption task. Then many methods start to focus on the attention mechanism. A residual attention network [35] is proposed with a spatial attention mechanism using downsampling and upsampling. Besides, SENet [21] proposes the channel attention mechanism. It performs GAP on the channels and then calculates the weights of each channel using fully connected layers. What's more, GE [20] uses spatial attention to better exploit the feature context, and A 2 -Net [7] builds a relation function for image or video recognition.
|
| 42 |
+
|
| 43 |
+
Inspired by these works, a series of works like BAM [28], DAN [9], CBAM [39], scSE [32], and CoordAttention [19] are proposed to fuse spatial attention [45] and channel attention. Among them, CBAM claims that GAP could only get a sub-optimal feature because of the loss of information. For addressing this problem, it uses both the GAP and the global max pooling and gains significant performance improvement. Similarly, SRM [23] also propose to use GAP with global standard deviation pooling. Motivated by CBAM, GSoP [11] introduces a second-order pooling method for downsampling. NonLocal [37] proposes to build a dense spatial feature map. AANet [3] proposes to embed the attention map with position information into the feature. SkNet [24] introduces a selective channel aggregation and attention mechanism, and ResNeSt [42] proposes a similar split attention method. Due to the complicated attention operation, these methods are relatively large. To improve efficiency, GCNet [4] proposes to use a simple spatial attention module and replace the original spatial downsampling process. ECANet [36] introduces onedimensional convolution layers to reduce the redundancy of fully connected layers and obtains more efficient results.
|
| 44 |
+
|
| 45 |
+
Besides these works, many methods try to extend the attention mechanism to specific tasks, like multi-label classification [14], saliency detection [44], visual explanation [10], and super-resolution [43].
|
| 46 |
+
|
| 47 |
+
Frequency Domain Learning Frequency analysis has always been a powerful tool in the signal processing field. In recent years, some applications of introducing frequency analysis in the deep learning field emerge. In [8, 13], frequency analysis is introduced in the CNNs by JPEG encoding. Then, DCT is incorporated in [41] to reduce communication bandwidth. There are also some applications in the model compression and pruning tasks like [6, 27, 38].
|
| 48 |
+
|
| 49 |
+
## 3. Method
|
| 50 |
+
|
| 51 |
+
In this section, we first revisit the formulation of DCT and channel attention. Then, based on these works, we elaborate on the derivation of our multi-spectral channel attention framework. Meanwhile, along with the multi-spectral channel attention framework, three kinds of frequency components selection methods are proposed.
|
| 52 |
+
|
| 53 |
+
## 3.1. Revisiting DCT and Channel Attention
|
| 54 |
+
|
| 55 |
+
We first elaborate on the definitions of discrete cosine transform and channel attention mechanism.
|
| 56 |
+
|
| 57 |
+
Discrete Cosine Transform (DCT) Typically, the basis function of two-dimensional (2D) DCT [1] is:
|
| 58 |
+
|
| 59 |
+
<!-- formula-not-decoded -->
|
| 60 |
+
|
| 61 |
+
Then the 2D DCT can be written as:
|
| 62 |
+
|
| 63 |
+
<!-- formula-not-decoded -->
|
| 64 |
+
|
| 65 |
+
in which f 2 d ∈ R H × W is the 2D DCT frequency spectrum, x 2 d ∈ R H × W is the input, H is the height of x 2 d , and W is the width of x 2 d . Correspondingly, the inverse 2D DCT can be written as:
|
| 66 |
+
|
| 67 |
+
<!-- formula-not-decoded -->
|
| 68 |
+
|
| 69 |
+
Please note that in Eqs. 2 and 3, some constant normalization factors are removed for simplicity, which will not affect the results in this work.
|
| 70 |
+
|
| 71 |
+
Channel Attention The channel attention mechanism is widely used in CNNs. It uses scalar to represent and evaluate the importance of each channel. Suppose X ∈ R C × H × W is the image feature tensor in networks, C is the number of channels, H is the height of the feature, and W is the width of the feature. As discussed in Sec. 1, we treat the scalar representation in channel attention as a compression problem since it has to represent the whole channel while only one scalar can be used. In this way, the attention mechanism can be written as:
|
| 72 |
+
|
| 73 |
+
<!-- formula-not-decoded -->
|
| 74 |
+
|
| 75 |
+
where att ∈ R C is the attention vector, sigmoid is the Sigmoid function, fc represents the mapping functions like fully connected layer or one-dimensional convolution, and compress : R C × H × W ↦→ R C is a compression method. After obtaining the attention vector of all C channels, each channel of input X is scaled by the corresponding attention value:
|
| 76 |
+
|
| 77 |
+
<!-- formula-not-decoded -->
|
| 78 |
+
|
| 79 |
+
in which ˜ X is the output of attention mechanism, att i is the i -th element of attention vector, and X : ,i, : , : is the i -th channel of input.
|
| 80 |
+
|
| 81 |
+
Typically, global average pooling is the de-facto compression method [21, 36] for its simplicity and effectiveness. There are also compression methods like global max pooling [39] and global standard deviation pooling [23].
|
| 82 |
+
|
| 83 |
+
## 3.2. Multi-Spectral Channel Attention
|
| 84 |
+
|
| 85 |
+
In this section, we first theoretically discuss the problem of existing channel attention mechanisms. Based on the theoretical analysis, we then elaborate on the network design of the proposed method.
|
| 86 |
+
|
| 87 |
+
Theoretical Analysis of Channel Attention As discussed in Sec. 3.1, DCT can be viewed as a weighted sum of inputs. We further prove that GAP is actually a special case of 2D DCT.
|
| 88 |
+
|
| 89 |
+
Theorem 1. GAPis a special case of 2D DCT, and its result is proportional to the lowest frequency component of 2D DCT.
|
| 90 |
+
|
| 91 |
+
Proof. Suppose h and w in Eq. 2 are 0 , we have:
|
| 92 |
+
|
| 93 |
+
<!-- formula-not-decoded -->
|
| 94 |
+
|
| 95 |
+
In Eq. 6, f 2 d 0 , 0 represents the lowest frequency component of 2D DCT, and it is proportional to GAP. In this way, Theorem 1 is proved. ■
|
| 96 |
+
|
| 97 |
+
Multi-Spectral Channel Attention Module Based on the theoretical analysis and Theorem 1, we can see that using GAP in the channel attention mechanism means only the lowest frequency information is preserved. And all components from other frequencies are discarded, which also encode the useful information patterns in representing the channels and should not be left out.
|
| 98 |
+
|
| 99 |
+
To better compress channels and introduce more information, we propose to generalize GAP to more frequency
|
| 100 |
+
|
| 101 |
+
Γ+
|
| 102 |
+
|
| 103 |
+
Γ+
|
| 104 |
+
|
| 105 |
+
Γ6ΓHΓOΓHΓFΓWΓHΓG
|
| 106 |
+
|
| 107 |
+
Γ(ΓOΓHΓPΓHΓQΓWΓıΓZΓLΓVΓH
|
| 108 |
+
|
| 109 |
+
Γ0ΓXΓOΓWΓLΓSΓOΓLΓFΓDΓWΓLΓRΓQ
|
| 110 |
+
|
| 111 |
+
<!-- image -->
|
| 112 |
+
|
| 113 |
+
(b)
|
| 114 |
+
|
| 115 |
+
Multi-spectral channel attention
|
| 116 |
+
|
| 117 |
+
Figure 2. Illustration of existing channel attention and multi-spectral channel attention. For simplicity, the 2D DCT indices are represented in the one-dimensional format. We can see that our method uses multiple frequency components with the selected DCT bases, while SENet only uses GAP in channel attention. Best viewed in color.
|
| 118 |
+
|
| 119 |
+
components of 2D DCT and compress more information with multiple frequency components of 2D DCT, including the lowest frequency component, i.e., GAP.
|
| 120 |
+
|
| 121 |
+
First, the input X is split into many parts along the channel dimension. Denote [ X 0 , X 1 , · · · , X n -1 ] as the parts, in which X i ∈ R C ′ × H × W , i ∈ { 0 , 1 , · · · , n -1 } , C ′ = C n , and C should be divisible by n . For each part, a corresponding 2D DCT frequency component is assigned, and the 2D DCTresults can be used as the compression results of channel attention. In this way, we have:
|
| 122 |
+
|
| 123 |
+
<!-- formula-not-decoded -->
|
| 124 |
+
|
| 125 |
+
in which [ u i , v i ] are the frequency component 2D indices corresponding to X i , and Freq i ∈ R C ′ is the C ′ -dimensional vector after the compression. The whole com- pression vector can be obtained by concatenation:
|
| 126 |
+
|
| 127 |
+
<!-- formula-not-decoded -->
|
| 128 |
+
|
| 129 |
+
in which Freq ∈ R C is the obtained multi-spectral vector. The whole multi-spectral channel attention framework can be written as:
|
| 130 |
+
|
| 131 |
+
<!-- formula-not-decoded -->
|
| 132 |
+
|
| 133 |
+
From Eqs. 8 and 9, we can see that our method generalizes the original GAP method to a framework with multiple frequency components. By doing so, the channel information after compression is effectively enriched for representation. The overall illustration of our method is shown in Fig. 2.
|
| 134 |
+
|
| 135 |
+
Criteria for Choosing Frequency Components There exists an important problem of how to choose frequency component indices [ u i , v i ] for each part X i . In order to fulfill the multi-spectral channel attention, we propose three kinds of criteria, which are FcaNet-LF (Low Frequency), FcaNet-TS (Two-Step selection), and FcaNet-NAS (Neural Architecture Search).
|
| 136 |
+
|
| 137 |
+
FcaNet-LF means FcaNet with low-frequency components. As we all know, many compression methods use low-frequency information of DCT to compress information. Moreover, some methods [21, 41] have shown CNNs prefer low-frequency information. In this way, the first criterion for choosing frequency components is to only select low-frequency components.
|
| 138 |
+
|
| 139 |
+
FcaNet-TS means FcaNet selects components within a two-step selection scheme. Its main idea is to first determine the importance of each frequency component and then investigate the effects of using different numbers of frequency components. Namely, we evaluate the results of each frequency component in channel attention individually. Finally, we choose the Top-k highest performance frequency components based on the evaluation results.
|
| 140 |
+
|
| 141 |
+
FcaNet-NAS means FcaNet with searched components. For this criterion, we use neural architecture search to search the best frequency component for channels. For each part X i , a set of continuous variables α = { α ( u,v ) } are assigned to search components. The frequency components of this part can be written as:
|
| 142 |
+
|
| 143 |
+
<!-- formula-not-decoded -->
|
| 144 |
+
|
| 145 |
+
in which O is the set containing all 2D DCT frequency component indices. After training, the frequency component for X i is derived by ( u ∗ i , v ∗ i ) = arg max ( u,v ) ∈ O { α ( u,v ) } .
|
| 146 |
+
|
| 147 |
+
The ablation studies about these criteria can be seen in Sec. 4.2.
|
| 148 |
+
|
| 149 |
+
## 4. Experiments
|
| 150 |
+
|
| 151 |
+
In this section, we first elaborate on the details of our experiments. Second, we show the ablation studies about FcaNet. Third, we give discussions about how the information is compressed in our framework, complexity, and code implementation. At last, we investigate the effectiveness of our method on the task of image classification, object detection, and instance segmentation.
|
| 152 |
+
|
| 153 |
+
## 4.1. Implementation Details
|
| 154 |
+
|
| 155 |
+
To evaluate the results of the proposed FcaNet on ImageNet [33], we employ four widely used CNNs as backbone models, including ResNet-34, ResNet-50, ResNet-101, and ResNet-152. We follow the data augmentation and hyperparameter settings in [16] and [17]. Concretely, the input images are cropped randomly to 224 × 224 with random horizontal flipping. We use an SGD optimizer with a momen- tum of 0.9, a weight decay of 1e-4, and a batch size of 128 per GPU at training time. For large models like ResNet-101 and ResNet-152, the batch size is set to 64. The learning rate is set to 0.1 for a batch size of 256 with the linear scaling rule [12]. All models are trained within 100 epochs with cosine learning rate decay and label smoothing. Notably, for training efficiency, we use the Nvidia APEX mixed precision training toolkit.
|
| 156 |
+
|
| 157 |
+
To evaluate our method on MS COCO [26] using Faster R-CNN [31] and Mask R-CNN [15]. We use the implementation of detectors from the MMDetection [5] toolkit and employ its default settings. During training, the shorter side of the input image is resized to 800. All models are optimized using SGD with a weight decay of 1e-4, a momentum of 0.9, and a batch size of 2 per GPU within 12 epochs. The learning rate is initialized to 0.01 and is decreased by the factor of 10 at the 8th and 11th epochs, respectively.
|
| 158 |
+
|
| 159 |
+
All models are implemented in PyTorch [29] framework and with eight Nvidia RTX 2080Ti GPUs.
|
| 160 |
+
|
| 161 |
+
## 4.2. Ablation Study
|
| 162 |
+
|
| 163 |
+
As discussed in Sec. 3.2, we propose three kinds of criteria, including FcaNet-LF (Low Frequency), FcaNet-TS (Two-Step selection), and FcaNet-NAS (Neural Architecture Search). In this section, we first show the ablations about these variants. Then we discuss the relation between FcaNet and fully learnable channel attention.
|
| 164 |
+
|
| 165 |
+
The effects of individual frequency components For FcaNet-TS, the first step is to determine the importance of each frequency component. To investigate the effects of different frequency components individually in channel attention, we only use one frequency component at a time. We divide the whole 2D DCT frequency space into 7 × 7 parts since the smallest feature map size is 7 × 7 on ImageNet. In this way, there are in total of 49 experiments. To speed up the experiments, we first train a standard ResNet50 network for 100 epochs as the base model. Then we add channel attention to the base model with different frequency components to verify the effects 1 . All added models are trained within 20 epochs with a similar optimization setting in Sec. 4.1, while the learning rate is set to 0.02.
|
| 166 |
+
|
| 167 |
+
As shown in Fig. 3, we can see that using lower frequency could have better performance, which is intuitive and verifies the success of SENet. This also verifies the conclusion [41] that deep networks prefer low-frequency information. Nevertheless, interestingly, we can see that nearly all frequency components (except the highest component) have very small gaps ( < = 0 . 5% Top-1 accuracy) between the lowest one, i.e., vanilla channel attention with GAP. This shows that other frequency components can also cope well with the channel attention mechanism, and it is effective to generalize the channel attention in the frequency domain.
|
| 168 |
+
|
| 169 |
+
1 A new version of Fig.3 without any validation data will be updated in the next version soon.
|
| 170 |
+
|
| 171 |
+
Figure 3. Top-1 accuracies on ImageNet using different frequency components in channel attention individually.
|
| 172 |
+
|
| 173 |
+
<!-- image -->
|
| 174 |
+
|
| 175 |
+
| Low Frequency High Frequency High Frequency Low Frequency 76.69 76.55 76.49 76.37 76.39 76.51 76.38 76.48 76.26 76.47 76.30 76.19 76.28 76.40 76.30 76.32 76.36 76.30 76.26 76.28 76.21 76.39 76.31 76.31 76.34 76.19 76.36 76.21 76.44 76.31 76.28 76.22 76.27 76.27 76.34 76.44 76.28 76.31 76.33 76.31 76.33 76.27 76.53 76.32 76.28 76.34 76.28 76.30 75.72 |
|
| 176 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 177 |
+
|
| 178 |
+
The effects of different numbers of frequency components For FcaNet-LF, we verify the results of using K lowest-frequency components. For FcaNet-TS, we select Top-K highest performance frequency components in Fig. 3. For simplicity, K could be 1, 2, 4, 8, 16, or 32.
|
| 179 |
+
|
| 180 |
+
Figure 4. Top1 accuracy with different numbers of components. Since FcaNet-NAS searches and determines frequency components automatically, it is not included in this experiment.
|
| 181 |
+
|
| 182 |
+
<!-- image -->
|
| 183 |
+
|
| 184 |
+
As shown in Fig. 4, we can see two phenomena. 1) All experiments with multi-spectral attention have a significant performance gain compared with the one only using the GAP in channel attention. This verifies our idea of using multiple frequency components in channel attention. 2) For FcaNet-LF and FcaNet-TS, the settings with 2 and 16 frequency components gain the best performance, respectively. In this way, we use these settings in our method and all other experiments.
|
| 185 |
+
|
| 186 |
+
Comparison with fully learnable channel attention As shown in Eq. 7, we use the 2D DCT basis functions to compress channels. The 2D DCT basis functions B u i ,v i h,w can be simply regarded as a tensor containing DCT coefficients. In this way, a natural question is that how about directly learning a tensor to compress channels. We compare our method with three different kinds of tensors, which are Fixed tensor with Random initialization (FR), Learned tensor with Random initialization (LR), and Learned tensor with DCT initialization (LD). In this case, our method can be viewed as a Fixed tensor with DCT initialization (FD).
|
| 187 |
+
|
| 188 |
+
Figure 5. Comparison with fully learnable channel attention. FR means a Fixed tensor with Random initialization, LR means a Learned tensor with Random initialization, LD means a Learned tensor with DCT initialization, and FD means a Fixed tensor with DCT initialization, which is our method. For settings with the random initialization, the error bar is shown.
|
| 189 |
+
|
| 190 |
+
<!-- image -->
|
| 191 |
+
|
| 192 |
+
The comparison is shown in Fig. 5. We can see that all settings with the DCT initialization (LD, FD) outperform the ones without DCT (FR, LR). Moreover, the setting with fixed DCT initialization (ours) even outperforms the fully learnable channel attention methods (LR, LD), which shows the effectiveness of using DCT to compress channels.
|
| 193 |
+
|
| 194 |
+
## 4.3. Discussion
|
| 195 |
+
|
| 196 |
+
How the multi-spectral framework compresses and embeds more information In Sec. 3.2, we show that only using GAP in channel attention is actually discarding information of all other frequency components except the lowest one, i.e., GAP. In this way, generalizing channel attention in the frequency domain and using the multi-spectral framework could naturally embed more information in the channel attention mechanism.
|
| 197 |
+
|
| 198 |
+
Besides the above derivation, we also give a thought experiment to show that more information could be embedded. As we all know, deep networks are redundant [18, 46].
|
| 199 |
+
|
| 200 |
+
Table 1. Comparison of different attention methods on ImageNet. All results are reproduced and trained with the same training setting except AANet, which has no official code.
|
| 201 |
+
|
| 202 |
+
| Method Years Backbone Parameters FLOPS Train FPS Test FPS Top-1 acc Top-5 acc ResNet [16] CVPR16 ResNet-34 21.80 M 3.68 G 2898 3840 74.58 92.05 SENet [21] CVPR18 21.95 M 3.68 G 2729 3489 74.83 92.23 ECANet [36] CVPR20 21.80 M 3.68 G 2703 3682 74.65 92.21 FcaNet-LF 21.95 M 3.68 G 2717 3356 74.95 92.16 FcaNet-TS 21.95 M 3.68 G 2717 3356 75.02 92.07 FcaNet-NAS 21.95 M 3.68 G 2717 3356 74.97 92.34 ResNet [16] CVPR16 ResNet-50 25.56 M 4.12 G 1644 3622 77.27 93.52 SENet [21] CVPR18 28.07 M 4.13 G 1457 3417 77.86 93.87 CBAM [39] ECCV18 28.07 M 4.14 G 1132 3319 78.24 93.81 GSoPNet1 * [11] CVPR19 28.29 M 6.41 G 1095 3029 79.01 94.35 GCNet [4] ICCVW19 28.11 M 4.13 G 1477 3315 77.70 93.66 AANet [3] ICCV19 25.80 M 4.15 G - - 77.70 93.80 ECANet [36] CVPR20 25.56 M 4.13 G 1468 3435 77.99 93.85 FcaNet-LF 28.07 M 4.13 G 1430 3331 78.43 94.15 FcaNet-TS 28.07 M 4.13 G 1430 3331 78.57 94.10 FcaNet-NAS 28.07 M 4.13 G 1430 3331 78.46 94.09 ResNet [16] CVPR16 ResNet-101 44.55 M 7.85 G 816 3187 78.72 94.30 SENet [21] CVPR18 49.29 M 7.86 G 716 2944 79.19 94.50 AANet [3] ICCV19 45.40 M 8.05 G - - 78.70 94.40 ECANet [36] CVPR20 44.55 M 7.86 G 721 3000 79.09 94.38 FcaNet-LF 49.29 M 7.86 G 705 2936 79.46 94.60 FcaNet-TS 49.29 M 7.86 G 705 2936 79.63 94.63 FcaNet-NAS 49.29 M 7.86 G 705 2936 79.53 94.64 ResNet [16] CVPR16 ResNet-152 60.19 M 11.58 G 559 2721 79.39 94.74 SENet [21] CVPR18 66.77 M 11.60 G 508 2566 79.84 94.82 AANet [3] ICCV19 61.60 M 11.90 G - - 79.10 94.60 ECANet [36] CVPR20 60.19 M 11.59 G 515 2619 79.86 94.80 FcaNet-LF 66.77 M 11.60 G 502 2387 80.13 94.90 FcaNet-TS 66.77 M 11.60 G 502 2387 80.02 94.89 FcaNet-NAS 66.77 M 11.60 G 502 2387 79.96 94.94 |
|
| 203 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 204 |
+
|
| 205 |
+
* Please note that although GSoPNet1 has higher performance, the computational cost is 1.5 times larger than ours. Our method still outperforms GSoPNet1 when compared with the same computational cost. A detailed comparison can be found in the supplementary files.
|
| 206 |
+
|
| 207 |
+
If two channels are redundant for each other, we can only get the same information using GAP. However, in our multispectral framework, it is possible to extract more information from redundant channels because different frequency components contain different information. In this way, the proposed multi-spectral framework could embed more information in the channel attention mechanism.
|
| 208 |
+
|
| 209 |
+
Complexity analysis We analyze the complexity of our method from two aspects: the number of parameters and the computational cost.
|
| 210 |
+
|
| 211 |
+
For the number of parameters, our method has no extra parameters compared with the baseline SENet because the weights of 2D DCT are pre-computed constant.
|
| 212 |
+
|
| 213 |
+
For the computational cost, our method has a negligible extra cost and can be viewed as having the same computa- tional cost as SENet. With ResNet-34, ResNet-50, ResNet101, and ResNet-152 backbone, the relative computational cost increases of our method are 0 . 04% , 0 . 13% , 0 . 11% , and 0 . 11% compared with SENet, respectively. More results can be found in Table 1.
|
| 214 |
+
|
| 215 |
+
A Few lines of code change Another important property of the proposed multi-spectral framework is that it can be easily carried out with existing channel attention implementations. The only difference between our method and SENet is the channel compression method (GAP vs. multi-spectral 2D DCT). As described in Sec. 3.1 and Eq. 7, 2D DCT can be viewed as a weighted sum of inputs. It can be simply implemented by element-wise multiplication and summation. In this way, our method could be easily integrated into arbitrary channel attention methods.
|
| 216 |
+
|
| 217 |
+
Table 2. Object detection results of different methods on COCO val 2017.
|
| 218 |
+
|
| 219 |
+
| Method Detector Parameters FLOPs AP AP 50 AP 75 AP S AP M AP L ResNet-50 Faster-RCNN 41.53 M 215.51 G 36.4 58.2 39.2 21.8 40.0 46.2 SENet 44.02 M 215.63 G 37.7 60.1 40.9 22.9 41.9 48.2 ECANet 41.53 M 215.63 G 38.0 60.6 40.9 23.4 42.1 48.0 FcaNet-LF 44.02 M 215.63 G 39.0 61.3 41.9 23.4 42.5 49.7 FcaNet-TS 44.02 M 215.63 G 39.0 61.1 42.3 23.7 42.8 49.6 FcaNet-NAS 44.02 M 215.63 G 39.0 60.9 42.3 23.0 42.9 49.9 ResNet-101 Faster-RCNN 60.52 M 295.39 G 38.7 60.6 41.9 22.7 43.2 50.4 SENet 65.24 M 295.58 G 39.6 62.0 43.1 23.7 44.0 51.4 ECANet 60.52 M 295.58 G 40.3 62.9 44.0 24.5 44.7 51.3 FcaNet-LF 65.24 M 295.58 G 41.3 63.4 44.9 24.6 45.6 53.6 FcaNet-TS 65.24 M 295.58 G 41.2 63.3 44.6 23.8 45.2 53.1 FcaNet-NAS 65.24 M 295.58 G 41.2 63.3 44.9 24.7 45.2 53.0 ResNet-50 Mask-RCNN 44.17 M 261.81 G 37.2 58.9 40.3 22.2 40.7 48.0 SENet 46.66 M 261.93 G 38.7 60.9 42.1 23.4 42.7 50.0 GCNet 46.69 M 261.94 G 39.4 61.6 42.4 - - - ECANet 44.17 M 261.93 G 39.0 61.3 42.1 24.2 42.8 49.9 FcaNet-LF 46.66 M 261.93 G 40.3 61.9 43.9 24.9 43.6 52.2 FcaNet-TS 46.66 M 261.93 G 40.3 62.0 44.1 25.2 43.9 52.0 FcaNet-NAS 46.66 M 261.93 G 40.3 61.9 43.9 24.9 43.6 52.2 |
|
| 220 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 221 |
+
|
| 222 |
+
## 4.4. Image Classification on ImageNet
|
| 223 |
+
|
| 224 |
+
We compare our FcaNet with the state-of-the-art methods using ResNet-34, ResNet-50, ResNet-101, and ResNet152 backbones on ImageNet, including SENet [21], CBAM [39], GSoP-Net1 [11], GCNet [4], AANet [3], and ECANet [36]. The evaluation metrics include both efficiency (i.e., network parameters, floating point operations per second (FLOPs), and frame per second (FPS)) and effectiveness (i.e., Top-1/Top-5 accuracy). As shown in Table 1, our method achieves the best performance nearly in all experimental settings.
|
| 225 |
+
|
| 226 |
+
## 4.5. Object Detection on MS COCO
|
| 227 |
+
|
| 228 |
+
Besides the classification task on ImageNet, we also evaluate our method on object detection task to verify its effectiveness and generalization ability. We use our FcaNet with FPN [25] as the backbone (ResNet-50 and ResNet101) of Faster R-CNN and Mask R-CNN and test their performance on the MS COCO dataset. SENet, CBAM, GCNet, and ECANet are used for comparison.
|
| 229 |
+
|
| 230 |
+
As shown in Table 2, our method could also achieve the best performance with both Faster-RCNN and MaskRCNN framework. Identical to the classification task on ImageNet, FcaNet could also outperform SENet by a large margin with the same number of parameters and computational cost. Compared with the SOTA method ECANet, FcaNet could outperform it by 0.9-1.3% in terms of AP.
|
| 231 |
+
|
| 232 |
+
## 4.6. Instance Segmentation on MS COCO
|
| 233 |
+
|
| 234 |
+
Besides the object detection, we then test our method on the instance segmentation task. As shown in Table 3, our method outperforms other methods by a more considerable margin. Specifically, FcaNet outperforms GCNet by 0.5% AP, while the gaps between other methods are roughly 0.10.2%. These results verify the effectiveness of our method.
|
| 235 |
+
|
| 236 |
+
Table 3. Instance segmentation results of different methods using Mask R-CNN on COCO val 2017.
|
| 237 |
+
|
| 238 |
+
| Method AP AP 50 AP 75 ResNet-50 34.1 55.5 36.2 SENet 35.4 57.4 37.8 GCNet 35.7 58.4 37.6 ECANet 35.6 58.1 37.7 FcaNet-LF 36.3 58.3 38.6 FcaNet-TS 36.2 58.6 38.1 FcaNet-NAS 36.3 58.3 38.6 |
|
| 239 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 240 |
+
|
| 241 |
+
## 5. Conclusion
|
| 242 |
+
|
| 243 |
+
In this paper, we study a fundamental problem of channel attention, that is, how to represent channels and regard this problem as a compression process. We have proved that GAP is a special case of DCT and proposed the FcaNet with the multi-spectral attention module, which generalizes the existing channel attention mechanism in the frequency domain. Meanwhile, we have explored different combinations of frequency components in our multi-spectral frame- work and proposed three criteria for frequency components selection. With the same number of parameters and computational cost, our method could consistently outperform SENet. We also have achieved state-of-the-art performance on image classification, object detection, and instance segmentation compared with other channel attention methods. Moreover, FcaNet is simple yet effective. Our method could be implemented with only a few lines of code change based on existing channel attention methods.
|
| 244 |
+
|
| 245 |
+
## Acknowledgements
|
| 246 |
+
|
| 247 |
+
This work is supported in part by National Key Research and Development Program of China under Grant 2020AAA0107400, Zhejiang Provincial Natural Science Foundation of China under Grant LR19F020004, key scientific technological innovation research project by Ministry of Education, and National Natural Science Foundation of China under Grant U20A20222.
|
| 248 |
+
|
| 249 |
+
## References
|
| 250 |
+
|
| 251 |
+
- [1] Nasir Ahmed, T Natarajan, and Kamisetty R Rao. Discrete cosine transform. IEEE Trans. Comput. , 100(1):90-93, 1974. 2, 3
|
| 252 |
+
- [2] Mario Barbero, H Hofmann, and ND Wells. Dct source coding and current implementations for hdtv. EBU Technical Review , (251):22-33, 1992. 2
|
| 253 |
+
- [3] Irwan Bello, Barret Zoph, Ashish Vaswani, Jonathon Shlens, and Quoc V Le. Attention augmented convolutional networks. In Int. Conf. Comput. Vis. , pages 3286-3295, 2019. 2, 7, 8
|
| 254 |
+
- [4] Yue Cao, Jiarui Xu, Stephen Lin, Fangyun Wei, and Han Hu. Gcnet: Non-local networks meet squeeze-excitation networks and beyond. In IEEE Conf. Comput. Vis. Worksh. , pages 0-0, 2019. 2, 7, 8
|
| 255 |
+
- [5] Kai Chen, Jiaqi Wang, Jiangmiao Pang, Yuhang Cao, Yu Xiong, Xiaoxiao Li, Shuyang Sun, Wansen Feng, Ziwei Liu, Jiarui Xu, Zheng Zhang, Dazhi Cheng, Chenchen Zhu, Tianheng Cheng, Qijie Zhao, Buyu Li, Xin Lu, Rui Zhu, Yue Wu, Jifeng Dai, Jingdong Wang, Jianping Shi, Wanli Ouyang, Chen Change Loy, and Dahua Lin. MMDetection: Open mmlab detection toolbox and benchmark. arXiv preprint arXiv:1906.07155 , 2019. 5
|
| 256 |
+
- [6] Wenlin Chen, James Wilson, Stephen Tyree, Kilian Q Weinberger, and Yixin Chen. Compressing convolutional neural networks in the frequency domain. In SIGKDD , pages 14751484, 2016. 2
|
| 257 |
+
- [7] Yunpeng Chen, Yannis Kalantidis, Jianshu Li, Shuicheng Yan, and Jiashi Feng. Aˆ 2-nets: Double attention networks. In Adv. Neural Inform. Process. Syst. , pages 352-361, 2018. 2
|
| 258 |
+
- [8] Max Ehrlich and Larry S Davis. Deep residual learning in the jpeg transform domain. In Int. Conf. Comput. Vis. , pages 3484-3493, 2019. 2
|
| 259 |
+
- [9] Jun Fu, Jing Liu, Haijie Tian, Yong Li, Yongjun Bao, Zhiwei Fang, and Hanqing Lu. Dual attention network for scene
|
| 260 |
+
10. segmentation. In IEEE Conf. Comput. Vis. Pattern Recog. , pages 3146-3154, 2019. 2
|
| 261 |
+
- [10] Hiroshi Fukui, Tsubasa Hirakawa, Takayoshi Yamashita, and Hironobu Fujiyoshi. Attention branch network: Learning of attention mechanism for visual explanation. In IEEE Conf. Comput. Vis. Pattern Recog. , pages 10705-10714, 2019. 2
|
| 262 |
+
- [11] Zilin Gao, Jiangtao Xie, Qilong Wang, and Peihua Li. Global second-order pooling convolutional networks. In IEEE Conf. Comput. Vis. Pattern Recog. , pages 3024-3033, 2019. 2, 7, 8
|
| 263 |
+
- [12] Priya Goyal, Piotr Doll´ ar, Ross Girshick, Pieter Noordhuis, Lukasz Wesolowski, Aapo Kyrola, Andrew Tulloch, Yangqing Jia, and Kaiming He. Accurate, large minibatch sgd: Training imagenet in 1 hour. arXiv preprint arXiv:1706.02677 , 2017. 5
|
| 264 |
+
- [13] Lionel Gueguen, Alex Sergeev, Ben Kadlec, Rosanne Liu, and Jason Yosinski. Faster neural networks straight from jpeg. In Adv. Neural Inform. Process. Syst. , pages 39333944, 2018. 2
|
| 265 |
+
- [14] Hao Guo, Kang Zheng, Xiaochuan Fan, Hongkai Yu, and Song Wang. Visual attention consistency under image transforms for multi-label image classification. In IEEE Conf. Comput. Vis. Pattern Recog. , pages 729-739, 2019. 2
|
| 266 |
+
- [15] Kaiming He, Georgia Gkioxari, Piotr Doll´ ar, and Ross Girshick. Mask r-cnn. In Int. Conf. Comput. Vis. , pages 29612969, 2017. 5
|
| 267 |
+
- [16] Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep residual learning for image recognition. In IEEE Conf. Comput. Vis. Pattern Recog. , pages 770-778, 2016. 5, 7
|
| 268 |
+
- [17] Tong He, Zhi Zhang, Hang Zhang, Zhongyue Zhang, Junyuan Xie, and Mu Li. Bag of tricks for image classification with convolutional neural networks. In IEEE Conf. Comput. Vis. Pattern Recog. , pages 558-567, 2019. 5
|
| 269 |
+
- [18] Yihui He, Xiangyu Zhang, and Jian Sun. Channel pruning for accelerating very deep neural networks. In Int. Conf. Comput. Vis. , pages 1389-1397, 2017. 6
|
| 270 |
+
- [19] Qibin Hou, Daquan Zhou, and Jiashi Feng. Coordinate attention for efficient mobile network design. arXiv preprint arXiv:2103.02907 , 2021. 2
|
| 271 |
+
- [20] Jie Hu, Li Shen, Samuel Albanie, Gang Sun, and Andrea Vedaldi. Gather-excite: Exploiting feature context in convolutional neural networks. In Adv. Neural Inform. Process. Syst. , pages 9401-9411, 2018. 2
|
| 272 |
+
- [21] Jie Hu, Li Shen, and Gang Sun. Squeeze-and-excitation networks. In IEEE Conf. Comput. Vis. Pattern Recog. , pages 7132-7141, 2018. 2, 3, 5, 7, 8
|
| 273 |
+
- [22] William Lea. Video on demand . House of Commons Library, 1994. 2
|
| 274 |
+
- [23] HyunJae Lee, Hyo-Eun Kim, and Hyeonseob Nam. Srm: A style-based recalibration module for convolutional neural networks. In Int. Conf. Comput. Vis. , pages 1854-1862, 2019. 1, 2, 3
|
| 275 |
+
- [24] Xiang Li, Wenhai Wang, Xiaolin Hu, and Jian Yang. Selective kernel networks. In IEEE Conf. Comput. Vis. Pattern Recog. , pages 510-519, 2019. 2
|
| 276 |
+
- [25] Tsung-Yi Lin, Piotr Doll´ ar, Ross Girshick, Kaiming He, Bharath Hariharan, and Serge Belongie. Feature pyramid
|
| 277 |
+
|
| 278 |
+
networks for object detection. In IEEE Conf. Comput. Vis. Pattern Recog. , pages 2117-2125, 2017. 8
|
| 279 |
+
|
| 280 |
+
- [26] Tsung-Yi Lin, Michael Maire, Serge Belongie, James Hays, Pietro Perona, Deva Ramanan, Piotr Doll´ ar, and C Lawrence Zitnick. Microsoft coco: Common objects in context. In Eur. Conf. Comput. Vis. , pages 740-755, 2014. 5
|
| 281 |
+
- [27] Zhenhua Liu, Jizheng Xu, Xiulian Peng, and Ruiqin Xiong. Frequency-domain dynamic pruning for convolutional neural networks. In Adv. Neural Inform. Process. Syst. , pages 1043-1053, 2018. 2
|
| 282 |
+
- [28] Jongchan Park, Sanghyun Woo, Joon-Young Lee, and In So Kweon. Bam: Bottleneck attention module. arXiv preprint arXiv:1807.06514 , 2018. 2
|
| 283 |
+
- [29] Adam Paszke, Sam Gross, Francisco Massa, Adam Lerer, James Bradbury, Gregory Chanan, Trevor Killeen, Zeming Lin, Natalia Gimelshein, Luca Antiga, et al. Pytorch: An imperative style, high-performance deep learning library. In Adv. Neural Inform. Process. Syst. , pages 8026-8037, 2019. 5
|
| 284 |
+
- [30] K Ramamohan Rao and Ping Yip. Discrete cosine transform: algorithms, advantages, applications . Academic press, 2014. 2
|
| 285 |
+
- [31] Shaoqing Ren, Kaiming He, Ross Girshick, and Jian Sun. Faster r-cnn: Towards real-time object detection with region proposal networks. In Adv. Neural Inform. Process. Syst. , pages 91-99, 2015. 5
|
| 286 |
+
- [32] Abhijit Guha Roy, Nassir Navab, and Christian Wachinger. Recalibrating fully convolutional networks with spatial and channel 'squeeze and excitation' blocks. IEEE Medical Imaging , pages 540-549, 2018. 2
|
| 287 |
+
- [33] Olga Russakovsky, Jia Deng, Hao Su, Jonathan Krause, Sanjeev Satheesh, Sean Ma, Zhiheng Huang, Andrej Karpathy, Aditya Khosla, Michael Bernstein, Alexander C. Berg, and Li Fei-Fei. Imagenet large scale visual recognition challenge. Int. J. Comput. Vis. , pages 211-252, 2015. 5
|
| 288 |
+
- [34] Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin. Attention is all you need. In Adv. Neural Inform. Process. Syst. , pages 5998-6008, 2017. 1
|
| 289 |
+
- [35] Fei Wang, Mengqing Jiang, Chen Qian, Shuo Yang, Cheng Li, Honggang Zhang, Xiaogang Wang, and Xiaoou Tang. Residual attention network for image classification. In IEEE Conf. Comput. Vis. Pattern Recog. , pages 3156-3164, 2017. 2
|
| 290 |
+
- [36] Qilong Wang, Banggu Wu, Pengfei Zhu, Peihua Li, Wangmeng Zuo, and Qinghua Hu. Eca-net: Efficient channel attention for deep convolutional neural networks. In IEEE Conf. Comput. Vis. Pattern Recog. , pages 11534-11542, 2020. 2, 3, 7, 8
|
| 291 |
+
- [37] Xiaolong Wang, Ross Girshick, Abhinav Gupta, and Kaiming He. Non-local neural networks. In IEEE Conf. Comput. Vis. Pattern Recog. , pages 7794-7803, 2018. 2
|
| 292 |
+
- [38] Yunhe Wang, Chang Xu, Shan You, Dacheng Tao, and Chao Xu. Cnnpack: Packing convolutional neural networks in the frequency domain. In Adv. Neural Inform. Process. Syst. , pages 253-261, 2016. 2
|
| 293 |
+
- [39] Sanghyun Woo, Jongchan Park, Joon-Young Lee, and In So Kweon. Cbam: Convolutional block attention module. In Eur. Conf. Comput. Vis. , pages 3-19, 2018. 1, 2, 3, 7, 8
|
| 294 |
+
- [40] Kelvin Xu, Jimmy Ba, Ryan Kiros, Kyunghyun Cho, Aaron Courville, Ruslan Salakhudinov, Rich Zemel, and Yoshua Bengio. Show, attend and tell: Neural image caption generation with visual attention. In Int. Conf. Mach. Learn. , pages 2048-2057, 2015. 1, 2
|
| 295 |
+
- [41] Kai Xu, Minghai Qin, Fei Sun, Yuhao Wang, Yen-Kuang Chen, and Fengbo Ren. Learning in the frequency domain. In IEEE Conf. Comput. Vis. Pattern Recog. , pages 17401749, 2020. 2, 5
|
| 296 |
+
- [42] Hang Zhang, Chongruo Wu, Zhongyue Zhang, Yi Zhu, Zhi Zhang, Haibin Lin, Yue Sun, Tong He, Jonas Mueller, R Manmatha, et al. Resnest: Split-attention networks. arXiv preprint arXiv:2004.08955 , 2020. 2
|
| 297 |
+
- [43] Yulun Zhang, Kunpeng Li, Kai Li, Lichen Wang, Bineng Zhong, and Yun Fu. Image super-resolution using very deep residual channel attention networks. In Eur. Conf. Comput. Vis. , pages 286-301, 2018. 2
|
| 298 |
+
- [44] Ting Zhao and Xiangqian Wu. Pyramid feature attention network for saliency detection. In IEEE Conf. Comput. Vis. Pattern Recog. , pages 3085-3094, 2019. 2
|
| 299 |
+
- [45] Xizhou Zhu, Dazhi Cheng, Zheng Zhang, Stephen Lin, and Jifeng Dai. An empirical study of spatial attention mechanisms in deep networks. In Int. Conf. Comput. Vis. , pages 6688-6697, 2019. 2
|
| 300 |
+
- [46] Zhuangwei Zhuang, Mingkui Tan, Bohan Zhuang, Jing Liu, Yong Guo, Qingyao Wu, Junzhou Huang, and Jinhui Zhu. Discrimination-aware channel pruning for deep neural networks. In Adv. Neural Inform. Process. Syst. , pages 875-886, 2018. 6
|
text-versions/attention-markdown/2101.07715_Meningioma segmentation in T1weighted MR.md
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2101.07715 Meningioma Segmentation In T1Weighted Mr
|
| 2 |
+
|
| 3 |
+
## MENINGIOMA SEGMENTATION IN T1-WEIGHTED MRI LEVERAGING GLOBAL CONTEXT AND ATTENTION MECHANISMS
|
| 4 |
+
|
| 5 |
+
## David Bouget
|
| 6 |
+
|
| 7 |
+
Department of Medical Technology SINTEF Trondheim, Norway david.bouget@sintef.no
|
| 8 |
+
|
| 9 |
+
## André Pedersen
|
| 10 |
+
|
| 11 |
+
Department of Medical Technology
|
| 12 |
+
|
| 13 |
+
SINTEF Trondheim, Norway andre.pedersen@sintef.no
|
| 14 |
+
|
| 15 |
+
## Ole Solheim
|
| 16 |
+
|
| 17 |
+
Department of Neurosurgery St. Olavs hospital Trondheim, Norway ole.solheim@ntnu.no
|
| 18 |
+
|
| 19 |
+
## Sayied Abdol Mohieb Hosainey
|
| 20 |
+
|
| 21 |
+
Department of Neurosurgery Bristol Royal Hospital for Children Bristol, United Kingdom s.a.m.h@live.no
|
| 22 |
+
|
| 23 |
+
## Ingerid Reinertsen
|
| 24 |
+
|
| 25 |
+
Department of Medical Technology SINTEF Trondheim, Norway ingerid.reinertsen@sintef.no
|
| 26 |
+
|
| 27 |
+
January 20, 2021
|
| 28 |
+
|
| 29 |
+
## ABSTRACT
|
| 30 |
+
|
| 31 |
+
Purpose: Meningiomas are the most common type of primary brain tumor, accounting for approximately 30% of all brain tumors. A substantial number of these tumors are never surgically removed but rather monitored over time. Automatic and precise meningioma segmentation is therefore beneficial to enable reliable growth estimation and patient-specific treatment planning.
|
| 32 |
+
|
| 33 |
+
Methods: In this study, we propose the inclusion of attention mechanisms on top of a U-Net architecture used as backbone: (i) Attention-gated U-Net (AGUNet) and (ii) Dual Attention U-Net (DAUNet), using a 3D MRI volume as input. Attention has the potential to leverage the global context and identify features' relationships across the entire volume. To limit spatial resolution degradation and loss of detail inherent to encoder-decoder architectures, we studied the impact of multi-scale input and deep supervision components. The proposed architectures are trainable end-to-end and each concept can be seamlessly disabled for ablation studies.
|
| 34 |
+
|
| 35 |
+
Results: The validation studies were performed using a 5-fold cross validation over 600 T1-weighted MRI volumes from St. Olavs University Hospital, Trondheim, Norway. Models were evaluated based on segmentation, detection, and speed performances and results are reported patient-wise after averaging across all folds. For the best performing architecture, an average Dice score of 81.6% was reached for an F1-score of 95.6%. With an almost perfect precision of 98%, meningiomas smaller than 3 ml were occasionally missed hence reaching an overall recall of 93%.
|
| 36 |
+
|
| 37 |
+
Conclusion: Leveraging global context from a 3D MRI volume provided the best performances, even if the native volume resolution could not be processed directly due to current GPU memory limitations. Overall, near-perfect detection was achieved for meningiomas larger than 3 ml which is relevant for clinical use. In the future, the use of multi-scale designs and refinement networks should be further investigated to improve the performance. A larger number of cases with meningiomas below 3 ml might also be needed to improve the performance for the smallest tumors.
|
| 38 |
+
|
| 39 |
+
K eywords 3D segmentation, Attention, Deep Learning, Meningioma, MRI, Clinical diagnosis
|
| 40 |
+
|
| 41 |
+
## 1 Introduction
|
| 42 |
+
|
| 43 |
+
Primary brain tumors, characterised by an uncontrolled growth and division of cells, can be grouped into two main categories: gliomas and meningiomas. Gliomas are the brain tumors with the highest mortality rate [1], while meningiomas account for one-third of all operated central nervous system tumors [2]. Many meningiomas are nevertheless never surgically removed, but may be encountered as incidental findings on neuroimaging. The prevalence rate of meningiomas in the general population undergoing 1.5T non-enhanced MRI scans is 0.9% [3], while the increase in incidence is presumably due to higher detection rates from a widespread use of Magnetic Resonance Imaging (MRI) in the general population [4]. According to the EANO consensus guidelines [5], asymptomatic patients can be managed through observation. MRI follow-ups of benign meningiomas (i.e., WHO grade I) should be done annually, then every two years after five years. Surgery is then usually indicated if a follow-up shows tumor growth. Today, growth assessment in a clinical setting is routinely based on eyeballing or crude measures of tumor diameters [6]. Manual segmentation by radiologists is time-consuming, tedious, and subject to intra/inter-rater variations difficult to characterize [7] and is therefore rarely done in clinical routine. Systematic and consistent brain tumor segmentation and measurements through (semi-)automatic methods are therefore of utmost importance. Patient-specific follow-up plans could potentially be enabled by an increased sensibility of growth measures and estimation of future growth. In addition, assessing the growth pattern on individual level may be informative with respect to treatment indication, as a majority may exhibit a self-limiting growth pattern [8]. In addition, segmentation is key for assessing treatment responses after radiotherapy or surgery. MRI represents the gold standard for medical imaging due to its non-invasiveness and widespread availability, most often using contrast-enhanced T1-weighted sequences where the tumor border is more easily distinguishable [5]. Alternatively, the fluid-attenuated inversion recovery (FLAIR) sequence can complement the diagnosis by better capturing the edema region for the cerebrospinal fluid. Nevertheless, inherent downsides can be associated with MRI acquisitions such as intensity inhomogeneity [9], variations from the use of different acquisition scanners [10], or variations in the acquisitions (e.g., field-of-view, slice thickness, or resolution). In T1-weighted MRI, meningiomas are often sharply circumscribed with a strong contrast enhancement, making them clear to identify. However, small meningiomas might resemble other contrast-enhanced structures such as blood vessels, hindering the detection task. In order to alleviate radiologists' burden to annotate large contrast-enhanced meningiomas, while at the same time to help detecting smaller and unusual meningiomas, automatic segmentation methods are paramount.
|
| 44 |
+
|
| 45 |
+
In recent years, automatic and end-to-end semantic segmentation has known considerable improvements through the development of encoder-decoder fully convolutional neural network architectures (FCNs) [11, 12, 13]. By restoring the feature map of the last deconvolution layer to the size of the initial input sample, predictions can be generated for each voxel. While such architectures provide near radiologist-level performances on some medical image analysis tasks [14, 15], multi-stage cascading induces a loss of local information leading to excessive and redundant low-level features. The most effective solution to boost the segmentation performance is to combine local and global information to preserve consistency in the feature maps. However, 3D medical volumes are typically too sizable to fit on GPU memory at their original resolution, and the amount of parameters for the corresponding model would be considerable. Different trade-offs have been investigated such as splitting the 3D volume into a series of patches or slabs by which some global context can be leveraged while good local information is retained [16]. Capturing the entire global context from a full 3D volume is important for a model to understand the spatial relationships between the different anatomical structures. Aggregating multi-scale contexts and using various dilated convolutions and pooling operations [17, 18], enlarging kernel size to capture richer global information [19], or fusing semantic features at different levels [20] can cope with information loss but are unable to leverage overall relationships between structures. To address shortcomings from feature maps consistency and loss of information when using multi-stage cascading architectures, attention mechanisms have been utilized with great success [21, 22, 23]. Attention modules can be seamlessly coupled with regular FCN architectures for end-to-end training, with the benefit of letting the model learn to focus on the segmentation targets without significant computational overhead nor additional model parameters. Optimally coupled with each deconvolution block, attention can be designed to capture features' dependencies spatially, channel-wise, or across any other dimension [21]. Alternatively, multiple models operating on different input shapes or focusing on different aspects during training can be fused as a post-processing step, called an ensemble, to generate the final prediction map [24]. Global context and local refinement can virtually be obtained separately at the cost of longer training and inference time, and higher model complexity. However, ensembling has not always shown to produce better overall segmentation performance compared to a single model's use [25].
|
| 46 |
+
|
| 47 |
+
Few studies have investigated the task of meningioma segmentation in-depth, more often focusing on gliomas given the open access to the BRATS challenge dataset [26]. A combination of support vector machine and graph cut has been used for multi-modal and multi-class segmentation, but results were reported on a meager set of 15 patients [27]. In consecutive studies, Laukamp et al. used different neural network architectures (e.g., DeepMedic, BioMedIA) over 3D volumes on their own multi-modal dataset [28, 29]. Good segmentation performance was obtained, but heavy preprocessing techniques such as atlas registration and skull-stripping were performed. In their study, Pereira et al. reported benefits from normalization and simple data augmentation for brain tumor segmentation [30]. In our previous work, leveraging a whole MRI volume, rather than slab-wise, has shown to boost the overall segmentation performance [31]. However, using a regular 3D U-Net or multi-scale architecture still resulted in the loss of information in the encoding path which remained to be addressed. Over the last years, almost all brain tumor segmentation studies were based around deep learning [32]. Simple 3D CNN architectures [33, 34], multi-scale approaches [35, 36], and ensemble of multiple models [24] have been explored. While they achieve better segmentation performance, are more robust to hyperparameters, and generalize better; the potential from using a whole 3D MRI volume remains yet to be fully explored.
|
| 48 |
+
|
| 49 |
+
In this paper, we focus on reducing the information loss for encoder-decoder architectures using combinations of attention, multi-scale, and deep supervision schemes. Our contributions are: (i) the investigation of architectures able to better understand global context, (ii) validation studies focusing on meningioma volumes for clinical and diagnostic use, and (iii) online availability for our trained models along with the inference script.
|
| 50 |
+
|
| 51 |
+
## 2 Methods
|
| 52 |
+
|
| 53 |
+
## 2.1 Related work
|
| 54 |
+
|
| 55 |
+
Typically, semantic features are extracted along the encoding path for encoder-decoder architectures. The field-of-view is progressively enlarged via strided convolutions or pooling operations, hence provoking some loss of detail. In the decoding path, extracted features are exploited in order to solve the task at hand (i.e., classification, segmentation). At the end of the encoding path, the feature maps are the richest in global relationships, but limited spatial details are preserved due to cascaded convolutions and nonlinearities. In order to recover fine-grained details, symmetrical architectures, such as U-Net, propagate feature maps across corresponding encoder and decoder at the same level, also known as long skip connections. In general, efficient architectures optimally use global and contextual information from high-level features and border information from low-level features to resolve small details [37]. Attention mechanisms focus on identifying salient image regions and amplifying their influence while filtering away irrelevant and potentially confusing information from other regions, making the prediction more contextualised [38]. Hard attention, stochastic and non-differentiable, relies on sampling-based training making optimizing models more difficult. Soft attention, probabilistic and amenable to training by backpropagation, can be by contrast seamlessly integrated into current CNN architectures, which has been applied in numerous tasks such as text understanding and semantic segmentation [39, 40, 41].
|
| 56 |
+
|
| 57 |
+
In a main body of work, a single attention gating is performed at every level along the decoding path. Attention feature maps are often concatenated with the feature maps from the long skip connection [22, 42], but propagating the lowest-level feature maps in an upward fashion with short skip connection has also been investigated for computing the attention feature maps [43]. In a second body of work, authors have investigated the computation of specific attention feature maps to focus on position, channel, or class dependencies. Fu et al. presented a dual attention network for scene segmentation where position and channel attention modules are computed at the bottom of a ResNet encoding path [21]. The generation of the final probability map, right after and without a matching decoding path, is detrimental to the spatial segmentation quality. Following the same idea, Mou et al. added a complete ResNet decoding path after position and channel attention computation, improving the spatial reconstruction [44]. Attempts have been made to include dual attention modules at every stage of a ResNet architecture, either from the skip connection feature maps from the encoder path [23], or in the decoder path after concatenation with the feature maps from the previous level [45]. The use of dilated convolutions, or the addition of a significant dropout over the attention feature maps, appear necessary to deal with the substantial amount of parameters and prevent training hurdles (e.g., overfitting, slow convergence). Finally, other hybrid attention schemes have been explored, for example in the context of aerial image segmentation with concepts such as class channel attention to exploit dependencies between classes and generate class affinity maps [46].
|
| 58 |
+
|
| 59 |
+
To compensate for the loss of detail inherent to consecutive pooling operations, new architecture designs or layers have been proposed. In order to preserve details in the encoding path, various multi-scale attempts have been made, such as infusing down-sampled version of the input volume in each encoder block [42], using atrous convolutions and pyramid spatial pooling to enlarge the receptive fields [17, 37], or by concatenating the feature maps from each encoder block and using the created multi-scale feature maps for guiding in an upward skip connection fashion [45]. In the latter case, complementary low-level information and high-level semantics are encoded jointly in a more powerful representation. Conversely, intermediate feature maps generated at each level of an encoder-decoder architecture can be leveraged instead of computing the loss simply from the last decoder step, commonly referred to as Deep Supervision (DS). The rationale is that the feature maps from hidden layers of a deep network can serve as a proxy to improve the overall segmentation quality and sensitivity of the model, while alleviating the problem of vanishing gradients [47]. The final loss is computed as a weighted average between the losses from each level whereby each can contribute equally [42], or with weights defined as trainable parameters. Intermediate losses can be computed separately from the raw feature maps and the attention feature maps, before tallying the final loss across all levels [45]. In general, the combination of multi-resolution and deep supervision has shown to improve convergence (i.e., better optimum and faster solving) for inverse problems [48].
|
| 60 |
+
|
| 61 |
+
## 2.2 Dataset
|
| 62 |
+
|
| 63 |
+
In a previous study [31], we introduced a dataset of 698 Gd-enhanced T1-weighted MRI volumes acquired on 1.5T and 3T scanners in the catchment region of the Department of Neurosurgery at St. Olavs University hospital, Trondheim, Norway. In this study, we kept the 600 high-resolution MRI volumes having a maximum spacing of 2 mm along the z-axis. Of those 600 patients, 276 underwent surgery to resect the meningioma, while the remaining 324 were followed at the outpatient clinic. In the dataset, MRI volume dimensions covered [240; 512] × [224; 512] × [18; 290] voxels and the voxel sizes ranged between [0 . 47; 1 . 05] × [0 . 47; 1 . 05] × [0 . 60; 2 . 00] mm 3 . The volumes of the surgically resected meningiomas were on average larger ( 30 . 92 ± 33 . 10 ml), compared to the untreated meningiomas followed at the outpatient clinic ( 7 . 62 ± 13 . 67 ml). Overall, meningioma volumes ranged between [0 . 07 , 167 . 99] ml for an average value of 18 . 33 ± 27 . 20 ml.
|
| 64 |
+
|
| 65 |
+
Figure 1: Illustration of the Attention-Gated U-Net (AGUNet), with multi-scale input and deep supervision. The representation features three levels for viewing purposes, but five levels have been used in the studies.
|
| 66 |
+
|
| 67 |
+
<!-- image -->
|
| 68 |
+
|
| 69 |
+
## 2.3 Architecture design
|
| 70 |
+
|
| 71 |
+
In this work, we opted for a U-Net architecture as backbone, which we set to five levels and used filter sizes of [16 , 32 , 128 , 256 , 256] for each level, respectively. Our first proposed architecture, named AGUNet and illustrated in Fig. 1, integrates an attention-gated mechanism to U-Net. Our second architecture, named DAUNet and illustrated in Fig. 2, integrates a dual attention module to U-Net. In addition, both architectures are combining multi-scale input and deep supervision support. For viewing purposes and clarity, we chose to display our proposed architectures with only three levels. The proposed design is modular whereby the backbone can be changed (e.g., U-Net, ResNet) and each main module (i.e., multi-scale input, attention mechanism, and deep supervision) can be toggled, hence enabling seamless end-to-end training while providing unbiased and comparable results. The specifics of each module are presented in the following subsections.
|
| 72 |
+
|
| 73 |
+
## 2.3.1 Attention mechanisms
|
| 74 |
+
|
| 75 |
+
In our first architecture, attention gates were incorporated to each decoder step of the architecture in order to highlight salient features passing through the skip connections, as described previously [22]. The attention gating is performed before the concatenation operation in order to merge only relevant activations, disambiguated from irrelevant responses in skip connections by performing gating from information extracted at a coarser scale. At each decoder level, the feature maps from the previous level (i.e., coarser scale) are first resampled to match the shape of the skip connection feature maps, using a transpose convolution operation with a 3 × 3 × 3 kernel size (cf. green block in Fig. 1). Inside the attention gate (cf. yellow block in Fig. 1), the upsampled feature maps (denoted as g ) and the feature maps from the skip connection (denoted as x l ) are processed to generate the gating signal which is applied to x l in order to generate the gated feature maps for the current level ˆ x l . Linear transformations without spatial support (i.e., 1 × 1 × 1 convolutions) are performed to limit the computational complexity and amount of trainable parameters, similarly to non-local blocks [49]. We chose to include an attention gate on the lowest-level feature maps (i.e. first skip connection) even though limited benefits are expected since the input data tend to not be represented in a high-enough dimensional space [38].
|
| 76 |
+
|
| 77 |
+
As second architecture, a dual attention scheme with position and channel attention modules was integrated to the U-Net architecture. Due to GPU-memory limitations and to reduce the computational complexity, the attention feature maps are only computed once at the end of the encoding path rather than at every decoder level. The position attention module, or spatial attention module, encodes a wider range of contextual information into local features to enhance their representation capability. The channel attention module exploits inter-dependencies between channel maps to emphasize inter-dependant feature maps and improve the feature representation of specific semantics, as presented by Fu et al. [21]. For training efficiency, a spatial dropout operation with a rate of 0.5 and linear transformations are performed on the raw attention feature maps, generating the final Attention Feature Maps (AFMs). In a variant, named DAGUNet, the attention feature maps are propagated upward and concatenated at each decoder level to guide the computation of feature maps at the higher levels (cf. green arrow in Fig. 2). Transferring the bottom attention feature maps requires less trainable parameters overall than computing the dual attention blocks at every decoder step, while still benefiting from them.
|
| 78 |
+
|
| 79 |
+
## 2.3.2 Multi-scale and deep supervision
|
| 80 |
+
|
| 81 |
+
For our multi-scale approach, we opted to exploit down-sampled versions of the initial network input, at every level in the encoding path, by performing consecutive average pooling operations with a 3 × 3 × 3 kernel size. Each down-sampled volume is then concatenated to the feature maps coming from the previous encoding level, before generating the feature maps for the current level, in order to preserve spatial details. For our deep supervision scheme, the ground truth volume is recursively down-sampled to match the size of the feature maps at each corresponding decoder level, where an intermediate loss L x is computed. The final loss, represented as L Tot in Fig. 1, is the weighted sum from all intermediate losses. In this study, we did not set the weights as trainable parameters, not to favor the feature maps from any level, and kept a uniform weighting strategy.
|
| 82 |
+
|
| 83 |
+
## 2.4 Training strategies
|
| 84 |
+
|
| 85 |
+
The MRI volumes were all preprocessed using the following steps: (i) resampling to an isotropic spacing of 1 mm 3 using spline interpolation order 1 from NiBabel 1 , (ii) clipping tightly around the patient's head, (iii) volume resizing to 128 × 128 × 144 voxels using spline interpolation order 1, and (iv) normalizing intensities to the range [0 , 1] . A typical data augmentation approach was favored, where the following transforms were applied to each input sample with a probability of 50%: horizontal and vertical flipping, random rotation in the range [ -20 ◦ , 20 ◦ ] , translation up to 10% of the axis dimension, zoom between [80 , 120]% in the axial plane.
|
| 86 |
+
|
| 87 |
+
1 https://github.com/nipy/nibabel
|
| 88 |
+
|
| 89 |
+
Figure 2: Illustration of the Dual Attention U-Net (DAUNet), with multi-scale input, deep supervision, and the same Conv3D block as described in the first architecture. The representation features three levels for viewing purposes, but five levels have been used in the studies.
|
| 90 |
+
|
| 91 |
+
<!-- image -->
|
| 92 |
+
|
| 93 |
+
All models were trained from scratch using the Adam optimizer with an initial learning rate of 10 -3 and training was stopped after 30 consecutive epochs without validation loss improvement. The main loss function used was the class-average Dice loss, excluding the background. Additionally, we experimented with the Focal Tversky Loss (FTL), where the Tversky similarity index helps balance false positive and false negative predictions more flexibly, while the focal aspect increases the contribution of hard training examples in the loss computation [42]. We used α = 0 . 7 and β = 0 . 3 for the Tversky index to minimize false negative predictions, and γ = 2 . 0 as focal parameter. Unless specified otherwise, all models were saved based on the minimum overall validation loss, which corresponds to L Tot if deep supervision is enabled.
|
| 94 |
+
|
| 95 |
+
Given the sizable memory footprint, all models were trained using two samples in a batch. In order to improve generalization, and because mini-batches up to 32 elements have shown to produce better models [50], we used the concept of accumulated gradients to effectively increase the batch size. For a specified number of accumulated gradient steps (n), each batch is run sequentially using the same model weights for calculating the gradients. When the n steps are performed, the accumulated sum of gradients from each step amounts to the same gradients as if computed over the larger batch size, ensuring that the model weights are properly updated. For our studies, we chose to perform 16 steps, enabling us to use a batch size of 32.
|
| 96 |
+
|
| 97 |
+
## 3 Validation studies
|
| 98 |
+
|
| 99 |
+
In this work, we focus on maximizing the segmentation and detection performance while investigating runtime and potential for diagnostic purposes and clinical use. A 5-fold cross-validation approach was followed whereby at every iteration three folds were used for training, one for validation, and one for testing. Each fold was populated in order to exhibit a similar meningioma volume distribution, as described in our previous study [31].
|
| 100 |
+
|
| 101 |
+
Metrics and measurements: For quantifying the performance, we used: (i) the Dice score, (ii) the F1-score, and (iii) the training/inference speed. The Dice score is used to assess the quality of the pixel-wise segmentation (in %), while the F1-score assesses the harmonic average of recall and precision (in %). Finally, the training speed, the inference speed, and the total processing speed to generate results for a new MRI volume, are all reported in seconds. For the segmentation task, the Dice score is computed between the ground truth and a binary representation of the probability map generated by a trained model. The binary representation is computed for ten different equally-spaced probability thresholds (PT), in the range [0 , 1] . A connected components approach, coupled to a pairing strategy, was employed to compute the recall and precision values. Such step is mandatory for the minority of multifocal meningiomas, but also to separate the correct prediction over a meningioma from the false positives per patient, enabling to also report the true positive Dice (Dice-TP). Pooled estimates, computed from each fold's results, are computed for each measurement [51], and reported with mean and standard deviation.
|
| 102 |
+
|
| 103 |
+
(i) Ablation study: Comparison of segmentation performances using various combinations of the methodological components introduced in Section 2, whereby the name given to each experiment is a concatenation of components' abbreviations. The architectures to choose from are: regular U-Net (UNet), attention-gated U-Net (AGUNet), dual attention U-Net (DAUNet), and dual attention guided U-Net (DAGUNet), combined with multi-scale input (MS), deep supervision (DS), and the use of accumulated gradients (AG). If not specified otherwise, the Dice loss function is used and the best model is selected based on the total loss L Tot. Usage of the focal Tversky loss is indicated by the TFL tag, while saving the best model based on the loss from the upper level is indicated by the Top tag.
|
| 104 |
+
|
| 105 |
+
(ii) Segmentation and detection performances study: A comparison is performed between the best trained model for each of the main designs: slab-wise U-Net (UNet-Slabs) and PLS-Net studied previously [31], full volume U-Net (UNet-FV) and the best method identified in the ablation study (Ours). All models were compared using the exact same methodology considering only the probability threshold PT, without any consideration toward the absolute size or relative overlap of the meningioma candidates.
|
| 106 |
+
|
| 107 |
+
(iii) Volume-based performances analysis: To study the potential for clinical use in the hospital or outpatient clinic, performances are analyzed over different meningioma groups based on volume. Limitations such as challenging meningiomas and potential outliers are also described.
|
| 108 |
+
|
| 109 |
+
(iv) Speed performances study: For the different experiments considered in the first two validation studies, a deeper analysis around speed is conducted. The model complexity as total number of parameters and the training behaviour as s.epoch -1 (in seconds), best epoch, and total training time (in hours), are first considered. The pure inference speed is reported when using GPU and CPU (in s). Finally, the total elapsed time required to generate predictions for a new patient is reported as processing time (in s), obtained with GPU support. The operations required to prepare the data to be sent through the network, to initialize the environment, to load the trained model, and to reconstruct the probability map in the referential space of the original volume are accounted for. The experiment has been repeated 10 consecutive times over the same MRI volume for each model, using a representative sample of 256 × 256 × 192 voxels with 1 . 0 × 1 . 0 × 1 . 0 mmspacing.
|
| 110 |
+
|
| 111 |
+
## 4 Results
|
| 112 |
+
|
| 113 |
+
Models were trained across different machines using either an NVIDIA Quadro P5000 (16GB) or a Tesla P100 PCIe (16GB) dedicated GPU, and regular hard-drives. For inference and processing speed computation, an Intel Xeon @3.70 GHz (6 cores) CPU and an NVIDIA Quadro P5000 GPU were used. Implementation was done in Python
|
| 114 |
+
|
| 115 |
+
3.6 using TensorFlow v1.13.1, Cuda 10.0, and the Imgaug Python library for the data augmentation methods [52]. Due to randomness during weight initialization and optimization, a fixed seed was set to make comparisons between experiments fair and reproducible. Trained models and inference code are made publically available at https: //github.com/dbouget/mri\_brain\_tumor\_segmentation .
|
| 116 |
+
|
| 117 |
+
## 4.1 Ablation study
|
| 118 |
+
|
| 119 |
+
Table 1: Performances obtained by component ablation, averaged over the five folds. The components are: regular U-Net (UNet), attention-gated U-Net (AGUNet), dual attention U-Net (DAUNet), dual attention guided U-Net (DAGUNet), multi-scale input (MS), deep supervision (DS), and the use of accumulated gradients (AG).
|
| 120 |
+
|
| 121 |
+
| Experiment PT Dice Dice-TP F1 Recall Precision (i) UNet-FV 0.5 76 . 91 ± 28 . 98 84 . 77 ± 16 . 22 93 . 19 ± 01 . 70 90 . 70 ± 01 . 90 95 . 86 ± 02 . 28 (ii) AGUNet-AG 0.4 75 . 14 ± 30 . 38 84 . 21 ± 16 . 57 92 . 15 ± 01 . 74 89 . 21 ± 02 . 38 95 . 35 ± 02 . 37 (iii) AGUNet-DS-AG 0.4 80 . 72 ± 24 . 98 86 . 79 ± 12 . 19 94 . 73 ± 00 . 76 93 . 02 ± 02 . 01 96 . 63 ± 02 . 95 (iv) AGUNet-MS-DS 0.4 81 . 64 ± 25 . 33 87 . 69 ± 12 . 12 95 . 58 ± 02 . 24 93 . 03 ± 04 . 13 98 . 39 ± 01 . 43 (v) AGUNet-MS-DS-AG 0.4 79 . 49 ± 26 . 38 87 . 02 ± 11 . 59 94 . 23 ± 00 . 88 91 . 69 ± 01 . 73 96 . 93 ± 01 . 04 (vi) AGUNet-MS-DS-AG-Top 0.5 79 . 89 ± 26 . 52 86 . 64 ± 13 . 75 94 . 53 ± 08 . 23 92 . 19 ± 02 . 21 97 . 07 ± 01 . 67 (vii) AGUNet-MS-DS-AG-FTL 0.7 74 . 27 ± 30 . 29 84 . 21 ± 14 . 47 91 . 27 ± 01 . 50 88 . 20 ± 02 . 96 94 . 66 ± 01 . 94 (viii) DAUNet-MS-DS-AG 0.5 78 . 43 ± 27 . 56 85 . 92 ± 13 . 73 92 . 99 ± 02 . 76 91 . 19 ± 04 . 71 95 . 04 ± 02 . 89 (ix) DAGUNet-MS-DS 0.4 81 . 54 ± 24 . 95 87 . 15 ± 13 . 34 95 . 24 ± 01 . 33 93 . 52 ± 02 . 39 97 . 06 ± 00 . 83 (x) DAGUNet-MS-DS-AG 0.4 80 . 74 ± 24 . 89 86 . 79 ± 12 . 00 94 . 78 ± 00 . 99 93 . 03 ± 01 . 91 96 . 63 ± 00 . 76 |
|
| 122 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 123 |
+
|
| 124 |
+
Patient-wise segmentation and detection performances for the different architectural designs considered are summarized in Table 1, where the first row provides baseline results using the backbone architecture only. The greatest impact comes from the deep supervision component increasing the Dice score by about 5% and the F1-score by 2.5% between experiments (ii) and (iii). From the multi-scale input approach, less than 1% improvement for the same metric is reported, as can be seen between experiments (iii) and (iv). It is worth mentioning that models trained using deep supervision produce comparable results whether saved based on the best total loss or the best loss from the upper level only (cf. experiments (v) and (vi)). The use of attention modules does not further improve the results (cf. experiments (i) and (ii)). Similarly, no added value has been recorded when using a more complex dual attention scheme (experiment x), rather than attention gating (experiment v). A similar conclusion can be drawn for the use of the accumulated gradients strategy, degrading slightly the overall segmentation performances, for a reduction in standard deviation across detection results (cf. experiments (iv) and (v)). While the implementation seems correct, identifying the best batch size is difficult and heavily dependant on the dataset size and diversity. However, for our second architecture with dual attention, propagating the attention feature maps upward seems to be beneficial with a 1-2% increase across the different measurements when compared to no propagation (cf. experiments (viii) and (x)). The attempt to use the Focal Tversky loss instead of Dice loss was not conclusive as all metrics are lower in experiment (vii) compared to experiment (v).
|
| 125 |
+
|
| 126 |
+
Overall, we consider the best performing model to be obtained by experiment (iv), reaching the highest scores for all but one metric. As we do favor detection performances over pixel-wise segmentation accuracy, our AGUNet-MS-DS model is also reaching the highest F1-score with 95.58%. In the rest of the paper, we refer to AGUNet-MS-DS (experiment (iv)) as Ours.
|
| 127 |
+
|
| 128 |
+
## 4.2 Segmentation and detection performances study
|
| 129 |
+
|
| 130 |
+
For the four different training concepts considered, segmentation performances have been reported in Table 2. The UNet-Slabs approach yields surprisingly competitive recall performances with only a 2% shortfall compared to our best-performing method. However, an inherent limitation of slabbing a 3D volume is the probable generation of a larger amount of false positives per patient, as can be seen by the 20% difference in precision between the same two approaches. While the PLS-Net architecture drastically increases the precision from leveraging a full 3D volume, its shallow architecture is not able to compete in terms of overall pixel-wise segmentation or recall performances. Nevertheless, it indicates how well global spatial relationships can be modelled and how beneficial it can be for a 3D segmentation task. The simple U-Net architecture over an entire 3D volume (UNet-FV), building upon the strengths of UNet-Slabs and PLS-Net, boosts performances in every aspect. Employing advanced mechanisms such as attention, deep supervision, or multi-scale input provides slight improvements in detection performances, going from an F1-score of 93.2% up to 95.6%. Yet, the highest benefit can be witnessed for the pixel-wise segmentation task, with an overall Dice score reaching 81.64%, up by almost 5%.
|
| 131 |
+
|
| 132 |
+
Table 2: Segmentation and detection performances obtained with the four main designs considered, averaged over the five folds. The first two designs were introduced and detailed in our previous study [31].
|
| 133 |
+
|
| 134 |
+
| Experiment PT Dice Dice-TP F1 Recall Precision UNet-Slabs 0.6 74 . 41 ± 29 . 04 81 . 72 ± 18 . 19 82 . 74 ± 02 . 65 91 . 04 ± 03 . 87 75 . 91 ± 02 . 89 PLS-Net 0.5 71 . 69 ± 33 . 41 83 . 46 ± 17 . 96 89 . 87 ± 01 . 79 85 . 88 ± 03 . 02 94 . 31 ± 01 . 03 UNet-FV 0.5 76 . 91 ± 28 . 98 84 . 77 ± 16 . 22 93 . 19 ± 01 . 70 90 . 70 ± 01 . 90 95 . 86 ± 02 . 28 Ours 0.4 81 . 64 ± 25 . 33 87 . 69 ± 12 . 12 95 . 58 ± 02 . 24 93 . 03 ± 04 . 13 98 . 39 ± 01 . 43 |
|
| 135 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 136 |
+
|
| 137 |
+
Figure 3: Prediction examples for a patient from each fold, one per line. The raw Dice is reported, in white, for the optimal probability threshold identified for each model.
|
| 138 |
+
|
| 139 |
+
<!-- image -->
|
| 140 |
+
|
| 141 |
+
Visual comparisons are provided in Fig. 3 between the four methods for five different patients, one per row, featuring meningiomas located in uncommon regions of the brain or with a small volume. For the first patient displayed, the meningioma is almost completely outside the brain and has grown between the eye sockets up the back of the nose, location relatively rare and under-represented in our dataset. As such, the best Dice score is obtained with the UNet-Slabs approach, which brings more focus to local intensity gradients. The use of more global information with the UNet-FV approach reduces prediction probabilities further away from the brain, while the use of attention mechanisms with our best approach lowers the Dice score to half of the UNet-Slabs value. Even though the impact of attention mechanisms could not be overall witnessed from the values reported in Table 1, the results on this patient represent a perfect exemplification. Attention mechanisms seem to have learned to limit the predictions within the brain or its outskirts from the training examples, as not many meningiomas in our dataset are outgrowing this far from the brain. The patients featured in the second and fifth rows are representative for difficult meningiomas that are either small or oddly located, where only our best approach is able to perform a reasonable pixel-wise segmentation.
|
| 142 |
+
|
| 143 |
+
## 4.3 Volume-based performances analysis
|
| 144 |
+
|
| 145 |
+
Based on tumor volume, we grouped the meningiomas from our dataset into ten equally-populated bins and reported Dice performances for each bin using a box plot, as shown in Fig. 4. The average Dice score for the largest meningiomas, with a volume of at least 17.5 ml, has not changed much across the four methods considered and hovers above 90%. However, the number of undetected or poorly segmented large meningiomas is lessened with our best method, as can be seen by the reduced number of dots outside the whiskers of each box plot. With our best approach, we reach an overall recall of 93%, which increases to 98% considering only meningiomas larger than 3 ml. We have identified eleven undetected cases with a volume larger than 3 ml, and two examples are provided in the second row of Fig. 5. Both a non-enhancing intraosseus meningioma (to the left) and a partly calcified meningioma (to the right) are featured. All eleven cases are exhibiting some extent of contrast impediment compared to typical contrast-enhancing meningiomas (cf. first row of Fig. 5), which explains why our network struggles. Considering that the average meningioma in an hospital setting has a volume of 30 . 92 ml and the performances on meningiomas larger than 3 ml, our proposed approach appears suitable and relevant. The most significant results of our best appraoch can be observed for meningiomas smaller than 3 ml, where the average Dice scores has been clearly improved. Starting from an average Dice of 46% and recall of 62.7% with PLS-Net, our best approach reaches an average Dice of 63.3% and recall of 78.9%. In Fig. 5, two representative meningiomas smaller than 3 ml and left unsegmented by all methods, are illustrated in the third row. Locations around brain borders (e.g., eye socket, or brainstem) and close to larger blood vessels are especially challenging. In addition, using down-sampled MRI volumes with limited spatial resolution reduces such meningiomas to a very limited number of voxels the model can compute features from. Incidental findings of meningiomas' first appearance, when below 3 ml, remains challenging and unreliable for broad clinical use. However, patients followed at the outpatient clinic have developed meningiomas of 7 . 62 ml on average, suggesting potential benefit from automatic segmentation using our models.
|
| 146 |
+
|
| 147 |
+
Figure 4: Segmentation performances for the four main designs represented with box plots. Ten equally-populated bins, based on tumor volumes, have been used to group the meningiomas.
|
| 148 |
+
|
| 149 |
+
<!-- image -->
|
| 150 |
+
|
| 151 |
+
Figure 5: Segmentation examples showing side-by-side the axial, coronal, and sagittal views respectively, where the automatic segmentation is shown in red and the manual annotation is shown in blue. The top row illustrates two properly segmented meningiomas with to the right a meningioma adjacent to the enhancing superior sagittal sinus and falx. The middle row shows to the left a non-enhancing meningioma exhibiting intraosseus growth and hyperostosis, and to the right a partly calcified, partly enhancing meningioma. The bottom row illustrates two meningiomas, with a volume smaller than 3 ml, left undetected.
|
| 152 |
+
|
| 153 |
+
<!-- image -->
|
| 154 |
+
|
| 155 |
+
## 4.4 Speed performances study
|
| 156 |
+
|
| 157 |
+
The model complexity, training convergence aspects, inference speed, and processing speed are reported in Table 3. Multiple GPUs with slightly different specifications (e.g., memory clock speed and bandwidth) were used for training, and other CPU-demanding algorithms were episodically ran concurrently. As a result, the speeds per epoch and total train time reported cannot be directly and objectively compared but orders of magnitude are nonetheless relevant to consider. The PLS-Net architecture is converging in less than 100 epochs, the fastest of all designs, but even with the smallest amount of total parameters its complex operations results in a total training time about three times longer than any full volume U-Net design for worse segmentation performances due to its shallowness (cf. experiments (ii) and (iii)). Training in a slab-wise fashion inherently increases the number of training samples which considerably lengthen the elapsed time per epoch by a tenfold compared to the fastest iterating design (cf. experiments (i) and (iii)). However, the convergence behaviour is not impacted as about 120 epochs are necessary, which is on-par with the various full volume designs such as experiment (vii). It is worth noting that while using accumulated gradients did not improve overall segmentation and detection performances, the models converge faster thanks to a better generalization from seeing more samples at every epoch (cf. experiments (vi) and (vii)). The combination of complex architectural designs and accumulated gradients enables convergence in about 110 epochs at best, which is equivalent to a more than reasonable total training time of 18 hours. Given the use of full volume inputs, the relatively small dataset size, and the quickly increasing total number of model parameters with advanced designs, one must trade carefully between model complexity and dataset size to prevent overfitting or similar convergence hurdles.
|
| 158 |
+
|
| 159 |
+
Regarding inference, doubling the number of parameters within a similar architecture does not alter the speed as can be seen between experiments (iv) and (ix), but only the shallow architecture from PLS-Net can go below the second.
|
| 160 |
+
|
| 161 |
+
Table 3: Model complexity, training convergence, and runtime performances for the different architecture designs studied, averaged across the five folds. All values in the table are reported with GPU support.
|
| 162 |
+
|
| 163 |
+
| Experiment # params s. epoch - 1 (s) Best epoch Train time (h) Inference (s) Processing (s) (i) UNet-Slabs [31] 14.75 M 4 103 ± 313 120 ± 40 160 . 2 ± 44 . 3 3 . 74 ± 0 . 03 15 . 53 ± 0 . 16 (ii) PLS-Net [31] 0.25 M 1 944 ± 47 91 ± 23 62 . 6 ± 12 . 5 0 . 92 ± 0 . 01 10 . 95 ± 0 . 05 (iii) UNet-FV 5.89 M 374 ± 4 . 7 171 ± 24 21 . 0 ± 02 . 5 2 . 03 ± 0 . 04 12 . 12 ± 0 . 08 (iv) AGUNet-AG 16.41 M 437 ± 3 . 6 138 ± 28 20 . 5 ± 03 . 5 3 . 88 ± 0 . 04 13 . 84 ± 0 . 13 (v) AGUNet-DS-AG 16.41 M 434 ± 3 . 4 149 ± 27 21 . 7 ± 03 . 3 3 . 59 ± 0 . 06 14 . 13 ± 0 . 21 (vi) AGUNet-MS-DS 18.66 M 472 ± 3 . 5 160 ± 78 25 . 0 ± 10 . 3 3 . 69 ± 0 . 04 14 . 35 ± 0 . 15 (vii) AGUNet-MS-DS-AG 18.66 M 508 ± 8 . 1 120 ± 29 21 . 4 ± 04 . 1 3 . 71 ± 0 . 04 14 . 46 ± 0 . 22 (viii) DAUNet-MS-DS-AG 25.72 M 434 ± 3 . 3 118 ± 52 18 . 0 ± 06 . 2 3 . 13 ± 0 . 04 13 . 85 ± 0 . 17 (ix) DAGUNet-MS-DS-AG 30.96 M 476 ± 3 . 3 112 ± 14 18 . 9 ± 01 . 9 3 . 32 ± 0 . 06 16 . 13 ± 0 . 28 |
|
| 164 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 165 |
+
|
| 166 |
+
When running experiment (ix) on CPU, the inference speed reaches on average 8 . 66 ± 0 . 09 seconds, slightly more than doubled compared to GPU usage. The largest gap between CPU and GPU usage happens when running experiment (ii). With regards to the total processing time for a new patient's MRI volume, around 15 seconds are necessary to provide segmentation predictions using a GPU, which would be fast enough not to hinder day-to-day clinical practice. Interestingly, and when considering computers deprived of high-end GPUs, the processing time on CPU remains similar with 15 . 39 ± 0 . 15 seconds for experiment (ix). When running inference on the GPU for only one patient, the environment has to be initialized at first and the model loaded, making it speed-wise comparable with pure CPU usage. The serious bottlenecks when using computers with average specifications could be the RAM availability and the CPU parameters (e.g., frequency, number of cores).
|
| 167 |
+
|
| 168 |
+
## 5 Discussion
|
| 169 |
+
|
| 170 |
+
In this study, we investigated different deep learning architectures for segmenting meningiomas in T1-weighted MRI volumes, relying on attention mechanisms and global relationships. Directly leveraging an entire 3D volume has the clear benefit of boosting overall segmentation and detection performances, especially in terms of precision. Having access to global context and spatial relationships across the whole brain helps the model to better discriminate between contrast-enhanced meningiomas and bright anatomical structures (e.g., blood vessels), which drastically reduces the number of false positive predictions per patient. Nevertheless, the lack of satisfactory spatial resolution from the use of a down-sampled input volume can prove to be detrimental which rationalizes predictions using the slab-wise strategy to be more accurate pixel-wise on some occasions. In order to build upon the strengths from each approach, while inhibiting their limitations regarding precision and pixel-wise segmentation accuracy, performing some extent of ensembling could bear potential. However, improved segmentation performance would come at the expense of the speed performance and additional complexity. The more models in the ensemble are, the longer training and inference computation takes.
|
| 171 |
+
|
| 172 |
+
By extending a regular U-Net backbone architecture with various designs, we managed to further improve segmentation and detection performances. However, the only noticeable and clear contribution seems to come from the use of deep supervision. Setting trainable weights in the loss function to let the model learn how to best balance the loss from the probability map at each decoder level has not been attempted in this study. We hypothesize overweighting the coarse feature maps might favor recall while overweighting the fine feature maps would favor pixel-wise segmentation, and believe further investigation is of interest. Not supported by numbers, the effect of attention schemes has been qualitatively observed whereby predictions appear to be restricted to the brain itself or its close boundaries. From training examples, the model learned global spatial relationships to define some no-prediction zones where meningiomas are unlikely to occur. While such observations warrant a proper behaviour from the use of attention schemes, a greater variability in the training samples to feature meningiomas in all possible location might also be implied. Conversely, having witnessed some extent of brain-clipping effect using attention mechanisms can be considered as an indication for unsuitability towards meningioma segmentation. Given the possibility for meningiomas to potentially grow outward from every border of the brain, heavier preprocessing such as brain-masking used for glioma segmentation is inadvisable here as it would clip away parts of the tumor. The use of multi-scale inputs also brought limited visible improvement, but the training samples fed to our architectures were already down-sampled from the original 3D MR volumes, starting the training with a degraded spatial resolution.
|
| 173 |
+
|
| 174 |
+
For the time being, training our best architecture with the native MRI volume resolution is too challenging because of memory limitation on even high-end GPUs due to the sizable memory footprint. Nonetheless, working with down-sampled input volumes seems like the best trade-off solution as both recall and precision are favored.
|
| 175 |
+
|
| 176 |
+
Detecting each and every meningioma accurately is critical as the actual pixel-wise segmentation task is more than often eased by the relatively good contrast and non-diffuse aspect of such tumors. The current segmentation and detection performances are satisfactory for clinical use either as a tool for surgical planning or growth estimation. As indicated by an average Dice score above 90% for meningiomas bigger than 3 ml, when the average volume for patients having undergone surgery is 30.92 ml, automatic measurements regarding the tumor aspect (i.e., volume, short-axis) and location (i.e., brain hemisphere and lobe) can be automatically generated. For meningiomas with a volume below 3 ml, somewhat worse performances were obtained. Detection of early meningiomas appears to be feasible but further improvements are needed for real and trustworthy use. As the average volume from patients followed at the outpatient clinic is 7.62 ml, the current performances open for automatic and systematic growth computation and follow-up over time at a larger scale while reducing inter/intra-observer variability and being less time-consuming for clinicians. The utmost challenging task remains the detection of tiny meningiomas exhibiting visual similarities with blood vessels, sometimes placed side-by-side or overlapping with them. The smallest meningiomas are also featured in a wider range of location (e.g., along the brainstem), and their total volume is only represented by a handful of voxels given the initial volume down-sampling. To address shortcomings from the latter, a finer down-sampling would help retain a superior spatial resolution but finding the proper balance between memory requirement and a prominent risk of overfitting would be challenging. Furthermore, broadening the dataset with additional samples featuring small meningiomas in a vaster range of locations might help the trained models generalize better. Alternatively, the use of other MR sequences such as FLAIR could help better distinguish between tumor and vessels. However, a larger panel of MR sequences might not be available at all time and processing only T1-weighted volumes makes our approach more generic and easy to use. Lastly, improving the architecture to make a better use of features available at the different input scales might be considered.
|
| 177 |
+
|
| 178 |
+
To allow for exact comparison with the results from our previous study [31], the dataset was not altered after the identification of outliers where meningiomas would not show with proper contrast, and which could be considered to be excluded from future studies. At it stands, the 11 outliers out of 600 volumes are additional noise during training and are a hindrance for the training process. By excluding them during validation, we would virtually reach 100% recall with our best performing model for meningiomas bigger than 3 ml. In the validation studies, we chose to only rely on the threshold value PT, applied over the prediction map, to report the segmentation performance results. Given the almost perfect precision and high Dice scores obtained with the different full volume approaches, using an additional detection threshold, whereby a true positive is acknowledged only if the Dice score is above the given threshold, was not deemed necessary. Only few meningiomas have poor pixel segmentation and extent coverage (i.e., Dice score below 50%), whilst the near-perfect precision ascertains the detection to be at least part of a meningioma.
|
| 179 |
+
|
| 180 |
+
Even with sophisticated architectures and heavier designs, models are extremely fast to train and are converging in under 20 hours. Using an entire 3D volume as input compared to a slabbing strategy also speeds up training as less training samples are processed during each epoch. In addition, generalization schemes such as accumulated gradients help the model converge faster and reach a better optimum as can be seen by the reduction in standard deviation for the segmentation and detection measurements. Interestingly, the inference speed is not heavily impacted by large variations in model complexity and these two parameters do not linearly correlate. Our dual attention guided architecture has 100 times more parameters than the shallow PLS-Net architecture, yet the inference speed is only multiplied by 3 reaching at most 3.7 seconds which is still fast enough and relevant for clinical use. The biggest hurdle for deployment in hospitals would be the large variability in hardware from low/mid-end computers and where shallower architectures like PLS-Net could thrive. The current disparity in performances, around 6% F1-score difference, remains too high for such consideration at the moment and further investigation in that direction is warranted.
|
| 181 |
+
|
| 182 |
+
## 6 Conclusion
|
| 183 |
+
|
| 184 |
+
In this paper, we pushed forward the investigations around spatial relationships and global context for the task of meningioma segmentation in T1-weighted MRI volumes. Integrated into a regular U-Net backbone, we experimented with concepts such as attention mechanisms, multi-scale input, and deep supervision. Improved segmentation and detection performances have been demonstrated when moving from slab-wise to more sophisticated and complex approaches leveraging the entire 3D volume. Almost perfect detection results for clinically relevant meningiomas were obtained, whereas the smallest meningiomas, with a volume below 3 ml, remained challenging given the limited spatial resolution and limited amount of voxels to compute features from. In future work, special care should be brought towards the training dataset, as in many applications the bottleneck for improving performances lies in the data diversity more than the method's design [53]. Nevertheless, smarter handling of multi-scale features should be investigated, such as spatial pyramid pooling, to better leverage the raw spatial resolution. Alternative loss function designs, using adaptive weighting or new concepts, might also improve the pixel-wise segmentation, especially around tumor borders.
|
| 185 |
+
|
| 186 |
+
## Conflict of interest statement
|
| 187 |
+
|
| 188 |
+
The authors declare that the research was conducted in the absence of any commercial or financial relationships that could be construed as a potential conflict of interest.
|
| 189 |
+
|
| 190 |
+
## Informed consent
|
| 191 |
+
|
| 192 |
+
Informed consent was obtained from all individual participants included in the study.
|
| 193 |
+
|
| 194 |
+
## Acknowledgments
|
| 195 |
+
|
| 196 |
+
This work was funded by the Norwegian National Advisory Unit for Ultrasound and Image-Guided Therapy (usigt.org).
|
| 197 |
+
|
| 198 |
+
## References
|
| 199 |
+
|
| 200 |
+
- [1] Stefan Bauer, Roland Wiest, Lutz-P Nolte, and Mauricio Reyes. A survey of mri-based medical image analysis for brain tumor studies. Physics in Medicine & Biology , 58(13):R97, 2013.
|
| 201 |
+
- [2] Quinn T Ostrom, Gino Cioffi, Haley Gittleman, Nirav Patil, Kristin Waite, Carol Kruchko, and Jill S BarnholtzSloan. Cbtrus statistical report: primary brain and other central nervous system tumors diagnosed in the united states in 2012-2016. Neuro-oncology , 21(Supplement\_5):v1-v100, 2019.
|
| 202 |
+
- [3] Meike W Vernooij, M Arfan Ikram, Hervé L Tanghe, Arnaud JPE Vincent, Albert Hofman, Gabriel P Krestin, Wiro J Niessen, Monique MB Breteler, and Aad van der Lugt. Incidental findings on brain mri in the general population. New England Journal of Medicine , 357(18):1821-1828, 2007.
|
| 203 |
+
- [4] Ole Solheim, Magne Torsteinsen, Tom Børge Johannesen, and Asgeir Store Jakola. Effects of cerebral magnetic resonance imaging in outpatients on observed incidence of intracranial tumors and patient survival: a national observational study. Journal of neurosurgery , 120(4):827-832, 2014.
|
| 204 |
+
- [5] Roland Goldbrunner, Giuseppe Minniti, Matthias Preusser, Michael D Jenkinson, Kita Sallabanda, Emmanuel Houdart, Andreas von Deimling, Pantelis Stavrinou, Florence Lefranc, Morten Lund-Johansen, et al. Eano guidelines for the diagnosis and treatment of meningiomas. The Lancet Oncology , 17(9):e383-e391, 2016.
|
| 205 |
+
- [6] Erik Magnus Berntsen, Anne Line Stensjøen, Maren Staurset Langlo, Solveig Quam Simonsen, Pål Christensen, Viggo Andreas Moholdt, and Ole Solheim. Volumetric segmentation of glioblastoma progression compared to bidimensional products and clinical radiological reports. Acta Neurochirurgica , 162(2):379-387, 2020.
|
| 206 |
+
- [7] Elisabetta Binaghi, Valentina Pedoia, and Sergio Balbi. Collection and fuzzy estimation of truth labels in glial tumour segmentation studies. Computer Methods in Biomechanics and Biomedical Engineering: Imaging & Visualization , 4(3-4):214-228, 2016.
|
| 207 |
+
- [8] Maziar Behbahani, Geir Olve Skeie, Geir Egil Eide, Annbjørg Hausken, Morten Lund-Johansen, and Bente Sandvei Skeie. A prospective study of the natural history of incidental meningioma-hold your horses! Neuro-Oncology Practice , 6(6):438-450, 2019.
|
| 208 |
+
- [9] Nicholas J Tustison, Brian B Avants, Philip A Cook, Yuanjie Zheng, Alexander Egan, Paul A Yushkevich, and James C Gee. N4itk: improved n3 bias correction. IEEE transactions on medical imaging , 29(6):1310-1320, 2010.
|
| 209 |
+
- [10] László G Nyúl, Jayaram K Udupa, and Xuan Zhang. New variants of a method of mri scale standardization. IEEE transactions on medical imaging , 19(2):143-150, 2000.
|
| 210 |
+
- [11] Vijay Badrinarayanan, Alex Kendall, and Roberto Cipolla. Segnet: A deep convolutional encoder-decoder architecture for image segmentation. IEEE transactions on pattern analysis and machine intelligence , 39(12):24812495, 2017.
|
| 211 |
+
- [12] Jonathan Long, Evan Shelhamer, and Trevor Darrell. Fully convolutional networks for semantic segmentation. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 3431-3440, 2015.
|
| 212 |
+
- [13] Olaf Ronneberger, Philipp Fischer, and Thomas Brox. U-net: Convolutional networks for biomedical image segmentation. In International Conference on Medical image computing and computer-assisted intervention , pages 234-241. Springer, 2015.
|
| 213 |
+
- [14] Wenjia Bai, Matthew Sinclair, Giacomo Tarroni, Ozan Oktay, Martin Rajchl, Ghislain Vaillant, Aaron M Lee, Nay Aung, Elena Lukaschuk, Mihir M Sanghvi, et al. Human-level cmr image analysis with deep fully convolutional networks. 2017.
|
| 214 |
+
|
| 215 |
+
- [15] Fangzhou Liao, Ming Liang, Zhe Li, Xiaolin Hu, and Sen Song. Evaluate the malignancy of pulmonary nodules using the 3-d deep leaky noisy-or network. IEEE transactions on neural networks and learning systems , 30(11):3484-3495, 2019.
|
| 216 |
+
- [16] Zeynettin Akkus, Alfiia Galimzianova, Assaf Hoogi, Daniel L Rubin, and Bradley J Erickson. Deep learning for brain mri segmentation: state of the art and future directions. Journal of digital imaging , 30(4):449-459, 2017.
|
| 217 |
+
- [17] Liang-Chieh Chen, George Papandreou, Florian Schroff, and Hartwig Adam. Rethinking atrous convolution for semantic image segmentation. arXiv preprint arXiv:1706.05587 , 2017.
|
| 218 |
+
- [18] Hengshuang Zhao, Jianping Shi, Xiaojuan Qi, Xiaogang Wang, and Jiaya Jia. Pyramid scene parsing network. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 2881-2890, 2017.
|
| 219 |
+
- [19] Chao Peng, Xiangyu Zhang, Gang Yu, Guiming Luo, and Jian Sun. Large kernel matters-improve semantic segmentation by global convolutional network. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 4353-4361, 2017.
|
| 220 |
+
- [20] Guosheng Lin, Anton Milan, Chunhua Shen, and Ian Reid. Refinenet: Multi-path refinement networks for high-resolution semantic segmentation. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 1925-1934, 2017.
|
| 221 |
+
- [21] Jun Fu, Jing Liu, Haijie Tian, Yong Li, Yongjun Bao, Zhiwei Fang, and Hanqing Lu. Dual attention network for scene segmentation. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , pages 3146-3154, 2019.
|
| 222 |
+
- [22] Ozan Oktay, Jo Schlemper, Loic Le Folgoc, Matthew Lee, Mattias Heinrich, Kazunari Misawa, Kensaku Mori, Steven McDonagh, Nils Y Hammerla, Bernhard Kainz, et al. Attention u-net: Learning where to look for the pancreas. arXiv preprint arXiv:1804.03999 , 2018.
|
| 223 |
+
- [23] Junlong Cheng, Shengwei Tian, Long Yu, Hongchun Lu, and Xiaoyi Lv. Fully convolutional attention network for biomedical image segmentation. Artificial Intelligence in Medicine , page 101899, 2020.
|
| 224 |
+
- [24] Xue Feng, Nicholas J Tustison, Sohil H Patel, and Craig H Meyer. Brain tumor segmentation using an ensemble of 3d u-nets and overall survival prediction using radiomic features. Frontiers in Computational Neuroscience , 14:25, 2020.
|
| 225 |
+
- [25] Guilherme Aresta, Teresa Araújo, Scotty Kwok, Sai Saketh Chennamsetty, Mohammed Safwan, Varghese Alex, Bahram Marami, Marcel Prastawa, Monica Chan, Michael Donovan, et al. Bach: Grand challenge on breast cancer histology images. Medical image analysis , 56:122-139, 2019.
|
| 226 |
+
- [26] Bjoern H Menze, Andras Jakab, Stefan Bauer, Jayashree Kalpathy-Cramer, Keyvan Farahani, Justin Kirby, Yuliya Burren, Nicole Porz, Johannes Slotboom, Roland Wiest, et al. The multimodal brain tumor image segmentation benchmark (brats). IEEE transactions on medical imaging , 34(10):1993-2024, 2014.
|
| 227 |
+
- [27] Elisabetta Binaghi, Valentina Pedoia, and Sergio Balbi. Meningioma and peritumoral edema segmentation of preoperative mri brain scans. Computer Methods in Biomechanics and Biomedical Engineering: Imaging & Visualization , 6(4):362-370, 2018.
|
| 228 |
+
- [28] Kai Roman Laukamp, Frank Thiele, Georgy Shakirin, David Zopfs, Andrea Faymonville, Marco Timmer, David Maintz, Michael Perkuhn, and Jan Borggrefe. Fully automated detection and segmentation of meningiomas using deep learning on routine multiparametric mri. European radiology , 29(1):124-132, 2019.
|
| 229 |
+
- [29] Kai Roman Laukamp, Lenhard Pennig, Frank Thiele, Robert Reimer, Lukas Görtz, Georgy Shakirin, David Zopfs, Marco Timmer, Michael Perkuhn, and Jan Borggrefe. Automated meningioma segmentation in multiparametric mri. Clinical Neuroradiology , pages 1-10, 2020.
|
| 230 |
+
- [30] Sérgio Pereira, Adriano Pinto, Victor Alves, and Carlos A Silva. Brain tumor segmentation using convolutional neural networks in mri images. IEEE transactions on medical imaging , 35(5):1240-1251, 2016.
|
| 231 |
+
- [31] David Bouget, André Pedersen, Sayied Abdol Mohieb Hosainey, Johanna Vanel, Ole Solheim, and Ingerid Reinertsen. Fast meningioma segmentation in t1-weighted mri volumes using a lightweight 3d deep learning architecture. arXiv preprint arXiv:2010.07002 , 2020.
|
| 232 |
+
- [32] Ali I¸ sın, Cem Direko˘ glu, and Melike ¸ Sah. Review of mri-based brain tumor image segmentation using deep learning methods. Procedia Computer Science , 102:317-324, 2016.
|
| 233 |
+
- [33] Andriy Myronenko. 3d mri brain tumor segmentation using autoencoder regularization. In International MICCAI Brainlesion Workshop , pages 311-320. Springer, 2018.
|
| 234 |
+
- [34] Fabian Isensee, Philipp Kickingereder, Wolfgang Wick, Martin Bendszus, and Klaus H Maier-Hein. No new-net. In International MICCAI Brainlesion Workshop , pages 234-244. Springer, 2018.
|
| 235 |
+
|
| 236 |
+
- [35] Konstantinos Kamnitsas, Christian Ledig, Virginia FJ Newcombe, Joanna P Simpson, Andrew D Kane, David K Menon, Daniel Rueckert, and Ben Glocker. Efficient multi-scale 3d cnn with fully connected crf for accurate brain lesion segmentation. Medical image analysis , 36:61-78, 2017.
|
| 237 |
+
- [36] Yanwu Xu, Mingming Gong, Huan Fu, Dacheng Tao, Kun Zhang, and Kayhan Batmanghelich. Multi-scale masked 3-d u-net for brain tumor segmentation. In International MICCAI Brainlesion Workshop , pages 222-233. Springer, 2018.
|
| 238 |
+
- [37] Haiwei Sang, Qiuhao Zhou, and Yong Zhao. Pcanet: Pyramid convolutional attention network for semantic segmentation. Image and Vision Computing , 103:103997, 2020.
|
| 239 |
+
- [38] Saumya Jetley, Nicholas A. Lord, Namhoon Lee, and Philip H. S. Torr. Learn to pay attention, 2018.
|
| 240 |
+
- [39] Zhouhan Lin, Minwei Feng, Cicero Nogueira dos Santos, Mo Yu, Bing Xiang, Bowen Zhou, and Yoshua Bengio. A structured self-attentive sentence embedding. arXiv preprint arXiv:1703.03130 , 2017.
|
| 241 |
+
- [40] Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin. Attention is all you need. In Advances in neural information processing systems , pages 5998-6008, 2017.
|
| 242 |
+
- [41] Guosheng Lin, Chunhua Shen, Anton Van Den Hengel, and Ian Reid. Efficient piecewise training of deep structured models for semantic segmentation. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 3194-3203, 2016.
|
| 243 |
+
- [42] Nabila Abraham and Naimul Mefraz Khan. A novel focal tversky loss function with improved attention u-net for lesion segmentation. In 2019 IEEE 16th International Symposium on Biomedical Imaging (ISBI 2019) , pages 683-687. IEEE, 2019.
|
| 244 |
+
- [43] Jo Schlemper, Ozan Oktay, Michiel Schaap, Mattias Heinrich, Bernhard Kainz, Ben Glocker, and Daniel Rueckert. Attention gated networks: Learning to leverage salient regions in medical images, 2019.
|
| 245 |
+
- [44] Lei Mou, Yitian Zhao, Li Chen, Jun Cheng, Zaiwang Gu, Huaying Hao, Hong Qi, Yalin Zheng, Alejandro Frangi, and Jiang Liu. Cs-net: channel and spatial attention network for curvilinear structure segmentation. In International Conference on Medical Image Computing and Computer-Assisted Intervention , pages 721-730. Springer, 2019.
|
| 246 |
+
- [45] Ashish Sinha and Jose Dolz. Multi-scale self-guided attention for medical image segmentation. IEEE Journal of Biomedical and Health Informatics , 2020.
|
| 247 |
+
- [46] Ruigang Niu. Hmanet: Hybrid multiple attention network for semantic segmentation in aerial images. arXiv preprint arXiv:2001.02870 , 2020.
|
| 248 |
+
- [47] Chen-Yu Lee, Saining Xie, Patrick Gallagher, Zhengyou Zhang, and Zhuowen Tu. Deeply-supervised nets. In Artificial intelligence and statistics , pages 562-570, 2015.
|
| 249 |
+
- [48] Feng Wang, Alberto Eljarrat, Johannes Müller, Trond R Henninen, Rolf Erni, and Christoph T Koch. Multiresolution convolutional neural networks for inverse problems. Scientific reports , 10(1):1-11, 2020.
|
| 250 |
+
- [49] Xiaolong Wang, Ross Girshick, Abhinav Gupta, and Kaiming He. Non-local neural networks. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 7794-7803, 2018.
|
| 251 |
+
- [50] Dominic Masters and Carlo Luschi. Revisiting small batch training for deep neural networks. arXiv preprint arXiv:1804.07612 , 2018.
|
| 252 |
+
- [51] Peter R Killeen. An alternative to null-hypothesis significance tests. Psychological science , 16(5):345-353, 2005.
|
| 253 |
+
- [52] Alexander B. Jung, Kentaro Wada, Jon Crall, Satoshi Tanaka, Jake Graving, Christoph Reinders, Sarthak Yadav, Joy Banerjee, Gábor Vecsei, Adam Kraft, Zheng Rui, Jirka Borovec, Christian Vallentin, Semen Zhydenko, Kilian Pfeiffer, Ben Cook, Ismael Fernández, François-Michel De Rainville, Chi-Hung Weng, Abner Ayala-Acevedo, Raphael Meudec, Matias Laporte, et al. imgaug. https://github.com/aleju/imgaug , 2020. Online; accessed 01-Feb-2020.
|
| 254 |
+
- [53] Johannes Hofmanninger, Florian Prayer, Jeanny Pan, Sebastian Rohrich, Helmut Prosch, and Georg Langs. Automatic lung segmentation in routine imaging is a data diversity problem, not a methodology problem. arXiv preprint arXiv:2001.11767 , 2020.
|
text-versions/attention-markdown/2103.03404_Attention is Not All You Need Pure Atten.md
ADDED
|
@@ -0,0 +1,601 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2103.03404 Attention Is Not All You Need Pure Atten
|
| 2 |
+
|
| 3 |
+
## Attention is not all you need: pure attention loses rank doubly exponentially with depth
|
| 4 |
+
|
| 5 |
+
| Yihe Dong Google yihed@google.com Jean-Baptiste Cordonnier EPFL jean-baptiste.cordonnier@epfl.ch Andreas Loukas EPFL andreas.loukas@epfl.ch |
|
| 6 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 7 |
+
|
| 8 |
+
## Abstract
|
| 9 |
+
|
| 10 |
+
Attention-based architectures have become ubiquitous in machine learning. Yet our understanding of the reasons for their effectiveness remains limited. This work proposes a new way to understand self-attention networks: we show that their output can be decomposed into a sum of smaller terms, each involving the operation of a sequence of attention heads across layers. Using this decomposition, we prove that self-attention possesses a strong inductive bias towards 'token uniformity'. Specifically, without skip connections or multi-layer perceptrons (MLPs), the output converges doubly exponentially to a rank-1 matrix. On the other hand, skip connections and MLPs stop the output from degeneration. Our experiments verify the identified convergence phenomena on different variants of standard transformer architectures 1 .
|
| 11 |
+
|
| 12 |
+
## 1 Introduction
|
| 13 |
+
|
| 14 |
+
The attention mechanism [BCB15] was initially developed to better learn long-range sequential knowledge, and found effective use in transformer networks [VSP + 17]. Since then, attention-based architectures have permeated across data domains machine learning applications, such as in natural language processing [DCLT18, POT16], speech recognition [LZL + 20], and computer vision [RPV + 19, BZV + 19]. As such, it is vital to develop tools to understand the inner workings of transformers and attention in general, both to shed light on existing models, and to design more effective future models.
|
| 15 |
+
|
| 16 |
+
This work provides new insights about the operation and inductive bias of networks built by stacking multiple self-attention layers. Surprisingly, we find that pure self-attention networks (SANs), i.e., transformers with skip connections and multi-layer perceptrons (MLPs) disabled, lose expressive power doubly exponentially with respect to network depth. More specifically, we prove that the output converges with a cubic rate to a rank one matrix that has identical rows. While we derive the convergence bounds in part by using properties of stochastic matrices, our results go beyond what one would expect based on standard results. In particular, by leveraging the cascading effects of specifically stacking self-attention modules, we show exponentially faster convergence than what standard theory prescribes. Furthermore, while previous studies have considered the rank of individial self-attention matrices [WLK + 20, KVPF20, CLJ20a], our results are the first to address conditions under which the entire network converges to rank one .
|
| 17 |
+
|
| 18 |
+
This raises the question, why do transformers work? Our analysis indicates that skip connections play a key role in mitigating rank collapse, and MLPs can slow down the convergence by increasing their Lipschitz constant. We characterize these counteracting forces by proving upper and lower bounds of this convergence behavior under SAN architectural variants that resemble transformers. Our results reveal a previously unknown vital utility of skip connections, beyond facilitating optimization and gradient flow [HZRS16a, BFL + 18].
|
| 19 |
+
|
| 20 |
+
[1 Our code is publicly available at https://github.com/twistedcubic/attention-rank-collapse](https://github.com/twistedcubic/attention-rank-collapse)
|
| 21 |
+
|
| 22 |
+
Figure 1: Two paths in a deep Self-Attention Network (SAN) with H heads and L layers. At each layer, a path can go through one of the heads or bypass the layer. Adding an MLP block after each attention layer forms the transformer architecture.
|
| 23 |
+
|
| 24 |
+
<!-- image -->
|
| 25 |
+
|
| 26 |
+
In the process, we develop a new path decomposition to study self-attention networks. Namely, we decompose a SAN into a linear combination of weakly-interdependent paths , where each 'path' corresponds to a deep single-head SAN. Intuitively, one can view the self-attention heads in each layer of the original network as different gateways, and a path follows a sequence of gateway choices, one gateway per layer (Figure 1). Coupled with the rank collapse analysis, our results suggest that deep SANs with skip connections behave like an ensemble of weakly-dependent shallow networks.
|
| 27 |
+
|
| 28 |
+
Our main contributions are as follows: (1) We present a systematic study of building blocks of the transformer, revealing opposing impacts between self-attention and the counteracting forces: skip connections and MLP, in contributing and preventing a rank collapse in transformers. As a corollary, this reveals a previously unknown vital effect of skip connections beyond facilitating optimization. (2) We propose a new method for analyzing SANs via a path decomposition , revealing SANs as an ensemble of shallow networks. (3) We verify our theory with experiments on common transformer architectures.
|
| 29 |
+
|
| 30 |
+
Notation. In the sequel, bold-face lower/upper-case letters denote vectors and matrices, respectively. We denote the ℓ 1 , ℓ ∞ -composite norm of a matrix X as ∥ X ∥ 1 , ∞ = √ ∥ X ∥ 1 ∥ X ∥ ∞ . We note that ℓ 1 , ∞ is not a proper norm as it does not satisfy the triangle inequality, though it is absolutely homogeneous and positive definite. We also use the shorthand notation [ H ] = (1 , · · · , H ).
|
| 31 |
+
|
| 32 |
+
## 2 Attention doubly exponentially loses rank
|
| 33 |
+
|
| 34 |
+
We start by studying self-attention networks (SANs) built exclusively out of multi-head self-attention layers. We prove that SANs converge exponentially (with depth) to a rank-1 matrix that makes all tokens identical.
|
| 35 |
+
|
| 36 |
+
Our analysis in § 2.1 relies on an unconventional way to express the output of a multi-head SAN as a sum of single-head networks. We refer to the latter as paths , where each path is denoted by a sequence of attention heads (see Figure 1). A proof sketch of why rank collapse occurs is given in § 2.2, whereas the main rank collapse result is presented in § 2.3.
|
| 37 |
+
|
| 38 |
+
## 2.1 The path decomposition argument
|
| 39 |
+
|
| 40 |
+
Let X be a n × d in input matrix consisting of n tokens. A SAN is built out of L multi-head self-attention layers, each having H heads. The output of the h -th self-attention head can be written as
|
| 41 |
+
|
| 42 |
+
<!-- formula-not-decoded -->
|
| 43 |
+
|
| 44 |
+
Above, W V,h is a d in × d v value weight matrix and the n × n row-stochastic matrix P h is given by
|
| 45 |
+
|
| 46 |
+
<!-- formula-not-decoded -->
|
| 47 |
+
|
| 48 |
+
where (1) the key and query weight matrices W K,h and W Q,h are of size d in × d qk , (2) W QK,h = W Q,h W ⊤ K,h , and (3) the softmax operates independently on each row of its input. We obtain the final equation by noting that softmax is shift-invariant and disregarding terms that provide a constant contribution across rows [CLJ20a].
|
| 49 |
+
|
| 50 |
+
The output of each SAN layer is formed by concatenating the individual outputs of all H attention heads (along the last dimension) and linearly projecting them onto a subspace of appropriate size:
|
| 51 |
+
|
| 52 |
+
<!-- formula-not-decoded -->
|
| 53 |
+
|
| 54 |
+
where we set W h = W V,h W ⊤ O,h and b O = ∑ h b O,h .
|
| 55 |
+
|
| 56 |
+
Let X l be the output of the l -th layer and fix X 0 = X . As is common practice, we let all layers consist of the same number of heads.
|
| 57 |
+
|
| 58 |
+
Excluding biases 1 b ⊤ O,h , the SAN output is given by
|
| 59 |
+
|
| 60 |
+
<!-- formula-not-decoded -->
|
| 61 |
+
|
| 62 |
+
which, after unrolling the recursion backwards, yields:
|
| 63 |
+
|
| 64 |
+
<!-- formula-not-decoded -->
|
| 65 |
+
|
| 66 |
+
The above equations have a clear interpretation if we think of the SAN as a directed acyclic graph, with nodes corresponding to self-attention heads and directed edge connecting heads of consecutive layers.
|
| 67 |
+
|
| 68 |
+
We formalize this intuition in the following:
|
| 69 |
+
|
| 70 |
+
Theorem 2.1 (Path decomposition of SAN) . The output of a depth L self-attention network with H heads per layer (including biases and skip connections) is given by
|
| 71 |
+
|
| 72 |
+
<!-- formula-not-decoded -->
|
| 73 |
+
|
| 74 |
+
where P path = P L h L · · · P 1 h 1 is an input-dependent stochastic matrix, whereas W path = W 1 h 1 · · · W L h L and b do not depend on the input.
|
| 75 |
+
|
| 76 |
+
Proof. The proof follows from the fact that the set of row-stochastic matrices is closed under multiplication (i.e., P L h L · · · P i h i is row-stochastic) and, moreover, for any row-stochastic matrix P , we have P 1 = 1 .
|
| 77 |
+
|
| 78 |
+
Each term in (1) describes a path of length L across heads of different layers
|
| 79 |
+
|
| 80 |
+
<!-- formula-not-decoded -->
|
| 81 |
+
|
| 82 |
+
and there are a total of H L such paths without skip connections.
|
| 83 |
+
|
| 84 |
+
The path decomposition thus describes the action of a multi-head SAN as the combination of simpler single-head networks. To gain intuition on path interdependence, it helps to split the operations performed into two types: those that act across tokens (multiplication from left) and those that apply independently on each token (multiplication from right). As seen, though paths can interact through token mixing (since P path matrices jointly depend on X ), token-wise operations are independent. We can also notice that biases are not particularly meaningful: their total contribution amounts to the single term 1 b ⊤ independently of the number of layers or heads used.
|
| 85 |
+
|
| 86 |
+
In the following we show that each path converges rapidly (as a function of length) to a rank-1 matrix with identical rows. Interestingly, this convergence is so dominant that adding more layers to the SAN does not help: though the number of paths is increased exponentially, each path degenerates doubly exponentially, leading also to a rank-1 output.
|
| 87 |
+
|
| 88 |
+
## 2.2 Convergence of single-head SAN
|
| 89 |
+
|
| 90 |
+
Before tackling the full SAN, it is instructive to consider the behavior of each path separately. We examine, in particular, how the residual
|
| 91 |
+
|
| 92 |
+
<!-- formula-not-decoded -->
|
| 93 |
+
|
| 94 |
+
changes during the forward pass.
|
| 95 |
+
|
| 96 |
+
As the following result shows, the residual norm converges to zero surprisingly quickly (doubly exponentially with a cubic rate):
|
| 97 |
+
|
| 98 |
+
Theorem 2.2 (Simplified) . For any single-head SAN consisting of L layers with ∥ W l QK ∥ 1 ∥ W l V ∥ 1 , ∞ ≤ β and for a term γ that depends on the attention entries, we have that
|
| 99 |
+
|
| 100 |
+
<!-- formula-not-decoded -->
|
| 101 |
+
|
| 102 |
+
which amounts to a doubly exponential convergence to a rank-1 matrix.
|
| 103 |
+
|
| 104 |
+
For the full theorem, we refer the reader to the Appendix.
|
| 105 |
+
|
| 106 |
+
Note that the bound in Eq 2 guarantees ∥ res(SAN( X )) ∥ 1 , ∞ convergence for all inputs of small residual whenever 4 γβ < √ d qk . In practice, our experiments imply that the region for convergence can be much greater.
|
| 107 |
+
|
| 108 |
+
The identified cubic rate of convergence is significantly faster than what would be expected when analyzing products of stochastic matrices (linear rate). As a rule of thumb, to achieve a decline of three orders of magnitude, say from 1000 to 1, one could expect a linear rate of convergence to require roughly a dozen iterations, whereas a cubic rate can do so in just two or three iterations. The reason why we get a cubic rate is that the rank of attention matrices depends also on the rank of the input. As we show, the self-attention heads mix tokens faster when formed from a low-rank matrix. This phenomenon becomes stronger as we build deeper SANs, leading to a cascading effect.
|
| 109 |
+
|
| 110 |
+
We provide a proof sketch bellow. Detailed proofs can be found in the Appendix.
|
| 111 |
+
|
| 112 |
+
Proof sketch. To analyze how the formation of P h is affected by the rank of the input, we start by writing X = 1 x ⊤ + R for R = res( X ) and expanding the attention matrix accordingly:
|
| 113 |
+
|
| 114 |
+
<!-- formula-not-decoded -->
|
| 115 |
+
|
| 116 |
+
Invoking once more the shift-invariance property of the softmax, the above can be simplified to
|
| 117 |
+
|
| 118 |
+
<!-- formula-not-decoded -->
|
| 119 |
+
|
| 120 |
+
for some appropriate r . Observe that if the matrix within the softmax was 1 r ⊤ , then P h would also degenerate to a rank-1 matrix: softmax( 1 r ⊤ ) = 1 q ⊤ and the convergence would happen instantly.
|
| 121 |
+
|
| 122 |
+
The proof builds on this observation by showing that if E = R W QK √ d qk R ⊤ is small then P h is almost rank-1:
|
| 123 |
+
|
| 124 |
+
<!-- formula-not-decoded -->
|
| 125 |
+
|
| 126 |
+
where D is diagonal and D ii = max j | δ ⊤ i E ( δ j -δ j ′ ) | . Thus, we have
|
| 127 |
+
|
| 128 |
+
<!-- formula-not-decoded -->
|
| 129 |
+
|
| 130 |
+
and, moreover, ∥ res( P h X ) ∥ ≤ 2 ∥ D 1 q ⊤ R ∥ . The proof concludes by bounding the above term and applying the argument recursively over successive layers.
|
| 131 |
+
|
| 132 |
+
## 2.3 Exponential convergence for attention networks
|
| 133 |
+
|
| 134 |
+
We now move on to analyse the convergence of SANs with multiple heads per layer.
|
| 135 |
+
|
| 136 |
+
Our main result is as follows:
|
| 137 |
+
|
| 138 |
+
Theorem 2.3 (Simplified) . Consider a depthL and widthH self-attention network without skip connections. Suppose that ∥ W l QK,h ∥ 1 ∥ W l h ∥ 1 , ∞ ≤ β for all heads h ∈ [ H ] and layers l ∈ [ L ] , and let γ be a term that depends on the attention entries. We have
|
| 139 |
+
|
| 140 |
+
<!-- formula-not-decoded -->
|
| 141 |
+
|
| 142 |
+
which amounts to a doubly exponential rate of convergence.
|
| 143 |
+
|
| 144 |
+
The bound guarantees convergence of SAN( X ) to rank one when 4 γβH < √ d qk . Our experiments show that this is a rather pessimistic estimate, as, in practice, we observe widespread convergence of output to rank-1.
|
| 145 |
+
|
| 146 |
+
Remark 1. Implications for Xformers. There has been a surge of architectural variants - that we collectively refer to as Xformers - aimed to improve the vanilla transformer [VSP + 17] by reducing the quadratic self-attention complexity. The rank collapse result of Theorem 2.3 carries interesting implications for these architectures. One such variant relies on low-rank or kernel-based approximations to the full attention matrix [KVPF20, WLK + 20, CLD + 20], in which case the paths likely converge even faster to rank one due to the imposed low-rankedness. Another variant only computes a subset of the attention matrix entries using particular patterns [ZGD + 20, CGRS19], such as random patterns, in which case one expects the paths to converge more slowly, as randomization tends to increase the rank of the output.
|
| 147 |
+
|
| 148 |
+
## 3 Mechanisms that counteract rank collapse
|
| 149 |
+
|
| 150 |
+
Our findings raise a pertinent questionwhy do attention-based networks work in practice if attention degenerates to a rank-1 matrix doubly exponentially with depth? Aiming to obtain a deeper understanding, we focus on the transformer architecture [VSP + 17] and expand our analysis by incorporating the three important components of transformers that SANs lack: skip connections , multi-layer perceptrons , and layer normalization .
|
| 151 |
+
|
| 152 |
+
We adopt a methodical approach where the modifications to the SAN architecture are introduced one at a time. For each case, we re-derive the convergence bounds and discuss the observed effect.
|
| 153 |
+
|
| 154 |
+
## 3.1 Skip connections are crucial
|
| 155 |
+
|
| 156 |
+
A simple modification to the path decomposition argument for SAN suffices to take into account skip connections. Specifically, we indicate the event that a path has skipped a layer by setting h = 0 on the corresponding notation:
|
| 157 |
+
|
| 158 |
+
<!-- formula-not-decoded -->
|
| 159 |
+
|
| 160 |
+
where we have fixed P 0 = I and W 0 = I .
|
| 161 |
+
|
| 162 |
+
As observed, skip connections dramatically diversify the path distribution. Denote by P l the set of paths of length l . With skip connections enabled, we have
|
| 163 |
+
|
| 164 |
+
<!-- formula-not-decoded -->
|
| 165 |
+
|
| 166 |
+
paths of length l (whereas before we had only length L paths). We hypothesize that it is the presence of short paths that stops SAN from degenerating to rank-1.
|
| 167 |
+
|
| 168 |
+
While we can derive an upper bound for the residual similar to above (which we do in the Appendix for completeness) such an upper bound is vacuously large. Indeed, it is more informative to have a lower bound on the residual, to align with practice, where SANs with skip connections do not suffer rank collapse. We present the following simple lower bound:
|
| 169 |
+
|
| 170 |
+
Claim 3.1. Consider a depthL and widthH self-attention network with skip connections. There exist infinitely many parameterizations for which ∥ res ( X L ) ∥ ≥ ∥ res ( X ) ∥ . The preceeding holds even for L →∞ and β arbitrarily small.
|
| 171 |
+
|
| 172 |
+
The proof is elementary: by the path decomposition, there is always a path that skips all layers, i.e. the path with length 0, preserving the residual. It then follows that, for any parametrization that renders the contribution of the SAN layers orthogonal to the input, we will have ∥ res( X L ) ∥ ≥ ∥ res( X ) ∥ . A simple example of such a parametrization can be recovered by setting W l V = 0 for every l ∈ [ L ], in which case ∥ res( X L ) ∥ = ∥ res( X ) ∥ .
|
| 173 |
+
|
| 174 |
+
A tight lower bound to the residual in the presence of skip connections is highly nontrivial, and we pose it as an open challenge to the community.
|
| 175 |
+
|
| 176 |
+
Remark 2. SANs as ensembles of shallow networks. It can be deduced from Theorem 2.3 that the SANs with skip connections enabled heavily rely on short paths (since the residual rapidly declines as the path length becomes larger). In other words, SANs behave like ensembles of shallow single-head self-attention networks. The phenomenon was previously identified for ResNets [VWB16a] (though the latter study didn't study the rank-collapse phenomenon). Here, the components of this ensemble are inter-dependent, as each attention head participates in many paths of different lengths. Experimental results in § 4 support this implication. The supplementary material also provides a study of the paths distribution across several common architectures.
|
| 177 |
+
|
| 178 |
+
## 3.2 Multi-layer perceptrons (MLP) help
|
| 179 |
+
|
| 180 |
+
We now study how using an MLP affects the residual. In particular, we focus on SANs with layers written as
|
| 181 |
+
|
| 182 |
+
<!-- formula-not-decoded -->
|
| 183 |
+
|
| 184 |
+
Note that, to keep the notation compact, we use f l to denote both the MLP as well as the output bias.
|
| 185 |
+
|
| 186 |
+
In our subsequent analysis, we use λ l, 1 , ∞ to denote the Lipschitz constant of f l with respect to ℓ 1 , ∞ norm. Note that, though finding the exact constant can be NP-hard even for shallow MLPs [SV18], since f l comprises of linear transformations with Lipschitz nonlinearities, f l is generally Lipschitz.
|
| 187 |
+
|
| 188 |
+
Corollary 3.2 (Simplified) . Consider a depthL and widthH SAN with MLP. Suppose that ∥ W l QK,h ∥ 1 ∥ W l h ∥ 1 , ∞ ≤ β for all h ∈ [ H ] and l ∈ [ L ] , let γ be a term that depends on the attention entries, and fix λ l, 1 , ∞ ≤ λ . We have that
|
| 189 |
+
|
| 190 |
+
<!-- formula-not-decoded -->
|
| 191 |
+
|
| 192 |
+
which amounts to a doubly exponential rate of convergence.
|
| 193 |
+
|
| 194 |
+
As seen, though the effect of MLP is less drastic than that of skip connections, the convergence rate in Cor 3.2 can be controlled by the Lipschitz constants λ f, 1 , ∞ of the MLPs: the more powerful the MLPs are the slower the convergence becomes. This reveals a tug-of-war between the self-attention layers and the the MLPs, which due to their nonlinearity can increase the rank. § 4 shows that indeed MLPs counteract convergence in experiments.
|
| 195 |
+
|
| 196 |
+
We should emphasize that using MLPs to counteract the rank-collapse is not without drawbacks: While increasing the Lipschitz constants slows down residual convergence, it also renders the model less robust and more sensitive to input perturbations [CKSN18]. Larger Lipschitz constants may also pose greater challenges to optimization, as they lead to larger gradient variance.
|
| 197 |
+
|
| 198 |
+
## 3.3 Layer normalization plays no role
|
| 199 |
+
|
| 200 |
+
Layer normalization is accomplished by rescaling and shifting the input across the feature dimension:
|
| 201 |
+
|
| 202 |
+
<!-- formula-not-decoded -->
|
| 203 |
+
|
| 204 |
+
where b LN is the mean of each column SA( X ) and D LN is a diagonal matrix with entries corresponding to the (possibly scaled or shifted) standard deviation of each column SA( X ).
|
| 205 |
+
|
| 206 |
+
Figure 2: Relative norm of the residual along the depth for three models before and after training. Pure attention (SAN) converges rapidly to a rank-1 matrix. Adding MLP blocks and skip connection gives a transformer. Skip connections play a critical role in mitigating rank collapse (i.e., a zero residual).
|
| 207 |
+
|
| 208 |
+
<!-- image -->
|
| 209 |
+
|
| 210 |
+
By setting ˜ W h = W h D -1 LN and ˜ b O = b O -b LN , the above is re-written as
|
| 211 |
+
|
| 212 |
+
<!-- formula-not-decoded -->
|
| 213 |
+
|
| 214 |
+
which is identical to the equation before layer normalization was applied, though now ˜ W h and ˜ b O are input dependent. Since right multiplication cannot increase the rank of a matrix, we conclude that layer normalization does not mitigate the rank collapse.
|
| 215 |
+
|
| 216 |
+
## 4 Experiments
|
| 217 |
+
|
| 218 |
+
Our experiments first test the rank collapse phenomenon in several well-known transformers architectures ( § 4.1). We also visually illustrate the inductive bias of some architectural variants of transformers with a toy example in § 4.2 and test the paths effectiveness with respect to length in § 4.3. Additional results can be found in the Appendix.
|
| 219 |
+
|
| 220 |
+
## 4.1 Rank collapse in real architectures
|
| 221 |
+
|
| 222 |
+
To verify our theoretical predictions, we examine the residual of three well-known transformer architectures: BERT [DCLT18], Albert [LCG + 19], and XLNet [YDY + 19]. Figure 2 plots the relative residual ∥ res(SAN( X l ) ∥ 1 , ∞ / ∥ SAN( X l ) ∥ 1 , ∞ , of each layer's output before and after the networks have been trained.
|
| 223 |
+
|
| 224 |
+
Figure 3: Applying a trained single-layer transformer module recurrently, to models of increasing hidden dimension (horizontal direction) and across architectural variants (vertical direction). The two light background paths illustrate the two training trajectories, for which the starting points are ( -0 . 3 , 0) and (0 . 3 , 0). Each figure contains the same number of steps. Consistent with the theory in § 3, convergence slows down or stops as the dimension increases (since β ≥ ∥ W l QK ∥ 1 ∥ W l V ∥ 1 , ∞ is generally larger), as well as when either MLP or skip connections are added.
|
| 225 |
+
|
| 226 |
+
<!-- image -->
|
| 227 |
+
|
| 228 |
+
To compute these ratios we ran the network on 32 samples of 128 tokens excerpts of biographies from Wikipedia [LGA16] and display the mean and standard deviation.
|
| 229 |
+
|
| 230 |
+
The experiments confirm that, as soon as the skip connections are removed, all networks exhibit a rapid rank collapse. Though MLPs do not seem to help in the mitigation of convergence, we caution that the observation is not an accurate portrayal of how trained transformers behave: removing the skip connections introduces a drastic distribution shift in the MLP input. We expect that the convergence will slow down if the network is retrained.
|
| 231 |
+
|
| 232 |
+
## 4.2 Visualizing the bias of different architectures
|
| 233 |
+
|
| 234 |
+
To empirically investigate the inductive bias of the different components of the transformer architecture, we study the behavior of a single-layer transformer when applied recurrently (akin to the universal transformer [DGV + 19]) to predict a simple 2D circular sequence.
|
| 235 |
+
|
| 236 |
+
Specifically, we train a single-layer transformer to sequentially predict two circular arcs in R 2 of radius 0 . 3, starting at ( -0 . 3 , 0) and (0 . 3 , 0), respectively, each directed counter-clockwise and consisting of 1000 points (illustrated as gray trajectories). An input sample consists of a sequence of two opposing points on the circle, one from the top arc and the other from the bottom arc. We apply teacher-forcing at each step, meaning we give the network the ground truth coordinates of the two current points, and train it to predict the next two points. The model attempts to minimize the MSE loss between the predicted points and the ground truth points on the trajectories. At inference time, we don't apply teacher-forcing, and simply feed the model output as input for the next step.
|
| 237 |
+
|
| 238 |
+
Since this recurrent application of a single-layer transformer can be reparametrized to be equivalent to a multi-layer transformer without skip connections, we hypothesize that at inference time the predicted trajectories of the two arcs will converge to the same point (indicating a rank collapse) , rather than following the training trajectories. Note that the setting has also been intentionally constructed to enable training even without skip connections (by using teacher forcing) and thus to disentangle the two distinct benefits of skip connections: their ability to improve optimization and their mitigation of rank collapse.
|
| 239 |
+
|
| 240 |
+
We trained the network until it could perfectly memorize the next step on the circular trajectories with near-zero loss. Figure 3 demonstrates the trajectories predicted at inference time (i.e., without teacher forcing). As seen on the top row, without MLP or skip connections the network exhibits rank collapse. Theorem 2.2 predicts that the convergence is slower when β ≥ ∥ W l QK ∥ 1 ∥ W l V ∥ 1 , ∞ increases. Indeed, as the hidden dimension increases from 32 to 128 (leading to larger β at initialization), the convergence slows down, becoming hardly observable for dimension 128.
|
| 241 |
+
|
| 242 |
+
We conclude that, in accordance to our analysis, adding MLP or skip connections either stops or drastically slows down rank collapse. As observed, skip connections tend to slow down points from moving. The latter phenomenon is because in this setting skip connections introduce a bias towards remaining in the same position. On the other hand, adding MLPs does not exhibit the same bias.
|
| 243 |
+
|
| 244 |
+
## 4.3 Path effectiveness
|
| 245 |
+
|
| 246 |
+
SANs can be seen as ensembles of paths of different lengths (from 0 to L ), each involving a different sequence of self-attention heads. Our analysis of SAN with skip connections indicates that path expressivity decreases with path length, even if the number of non-linear operations involved increases. To test this hypothesis, we isolate paths of different lengths and evaluate their predictive power.
|
| 247 |
+
|
| 248 |
+
Tasks. We considered the following three tasks to test path effectiveness with respect to length:
|
| 249 |
+
|
| 250 |
+
- Sequence memorization. To solve this task, a model needs to memorize a pre-determined mapping from natural language sentences and random label sequences of the same length. We use random tokens (rather than actual labels) to make this purely a test of expressiveness of a network by way of memorizing training data, rather than confounding effects such as generalizability. The models tested are trained to minimize the cross entropy loss between predicted and the ground truth labels. The training data consist of 500 English sentences from Wikipedia and News sources [DGM06, WSM + 19], which are tokenized using the SentencePiece tokenizer [KR18] into a vocabulary of size 30522 with 128 tokens per sequence. Each sequence is mapped to a random binary sequence of the same length.
|
| 251 |
+
- Learning to sort . Given an input sequence of letters, this task learns to sort the letters in alphabetical ordering (similar task have been studied before [FO ˇ S19]). Specifically, the model's output for each input letter is used to determine the position of that letter in the predicted ordering. Each input sequence, of length 8, is created by sampling uniformly randomly, with replacement, from an alphabet of size 10. The training and test sets consist of 1000 and 200 sequences, respectively. To ensure robustness with respect to hyperparameters, we experimented with a variety of settings (adjusting the model depth, number of heads, and the difficulty of the task by changing the alphabet size and sequence length) and observed consistent behavior.
|
| 252 |
+
- Convex hull prediction . This task was inspired by the work of [VFJ15]. Given a sequence of N points uniformly distributed in [0 , 1] × [0 , 1] and shifted by a random bivariate standard normal, this task predicts the convex hull of these points. Specifically, for each point in the set, the model predicts whether it's part of the convex hull. The training set consists of 10 , 000 sequences of points in [0 , 1] × [0 , 1], each of length 10.
|
| 253 |
+
|
| 254 |
+
In all three tasks, we report the test-set per-token label prediction accuracy as the evaluation metric.
|
| 255 |
+
|
| 256 |
+
Figure 4: To determine how much of the expressive power can be attributed to short vs long paths, we examine the performance of subsets of paths of different lengths (rather than of the entire SAN). Performance can be seen to consistently deteriorate with respect to path length, supporting our hypothesis that short paths are responsible for the majority of the expressive power.
|
| 257 |
+
|
| 258 |
+
<!-- image -->
|
| 259 |
+
|
| 260 |
+
Path effectiveness test. We measure the effectiveness of individual paths by a 'path disentanglement' procedure that we apply at inference time: the procedure isolates the weights involved and the output of an individual path ( P L h L · · · P 1 h 1 ) X ( W 1 h 1 · · · W L h L ) for any given sequence of heads h 1 , · · · , h L ∈ [ H ∪ 0] L . After the transformer has been successfully trained to solve each task (without modifications), we use this procedure to determine the output of a randomly sampled set of paths of a given length. We then evaluate the task performance based solely on the normalized sum of this subset of paths (rather than from all paths). Note that the training remains unaltered and uses all heads simultaneously, therefore ensuring that each path learns to its full effectiveness.
|
| 261 |
+
|
| 262 |
+
Figure 4 illustrates the resulting performance across all three tasks. We test different subset sizes and report the average and standard deviation of five repetitions. For reference, we also plot the accuracy of a naive classifier as well as of the entire trained model (i.e., before the path decomposition). As observed, short paths carry predictive power, with length-1 paths attaining accuracy above 0.8,0.6, and, 0.65 in the memorization, sorting, and convex hull tasks, respectively. On the other hand, the output of longer paths is not much better than a random guess (red horizontal lines). We note that, since there is a class imbalance in the convex hull task, we use a majority class predictor to obtain a random baseline. Though the difference in accuracy between short and long paths is less pronounced for the convex hull task, we observe that the variance of the long paths is significantly larger, rendering them not much better than a random guess. Length zero paths attain very small variance, but contain no useful information about the task (likely because they do not exploit global information).
|
| 263 |
+
|
| 264 |
+
The depths ( L ), number of heads ( H ), and hidden dimensions ( d ) for the three models are: L :6, H :2, d :250 for memorization, L :6, H :2, d :48 for sorting, and L :6, H :3, d :84 for convex hull. It's important to note that for all three tasks, while higher peak accuracies are attainable with increased model capacity and training time, our focus is to study the effects of path length on performance. Indeed, the trend for degenerating performance as path length increases stayed consistent across model sizes in all experiments.
|
| 265 |
+
|
| 266 |
+
The rapidly diminishing effectiveness of paths with respect to length indicates that the transformer relies almost exclusively on short paths. In other words, the transformer behaves like an ensemble of shallow networks. Furthermore, the results indicate that there is underutilized capacity in long paths, and suggest that one way to make them, and hence the transformer, more effective, is to prevent the long paths from losing rank.
|
| 267 |
+
|
| 268 |
+
## 5 Related works
|
| 269 |
+
|
| 270 |
+
Skip connections were first introduced in ResNets [HZRS16a], ever since, it has been used to facilitate optimization in deep networks [HZRS16b, VWB16b, BFL + 18]. In particular, skip connections tackle the vanishing gradient problem, by allowing the gradient to flow bypass the skipped layers during backpropagation. The original motivation of using skip connections in transformers follow the same reasoning on facilitating optimization [VSP + 17]. With the paths decomposition for transformers, we discover an additional surprising importance of skip connections: they prevent the transformer output from degenerating to rank one exponentially quickly with respect to network depth.
|
| 271 |
+
|
| 272 |
+
Veit et al. ([VWB16b]) introduced an analogous interpretation for residual networks as a collection of paths of varying lengths, and found that the length of the effective paths in deep residual networks are much shorter than the total network depth, due to the gradients used for parameter updates coming overwhelmingly from these short paths. Our finding suggests that SANs rely on short paths to avoid rank collapse. On the other hand, Daneshmand et al. [DKB + 20] studied rank collapse in randomly initialized linear and ReLU networks and showed that batch normalization is an effective mitigation strategy.
|
| 273 |
+
|
| 274 |
+
Some recent works have approximated the attention matrix with low-rank factorizations [WLK + 20, TBM + 20] or kernel methods [KVPF20, CLD + 20], to reduce the quadratic self-attention complexity. Our work is orthogonal to these works, by studying the rank of the network's output (rather than of the attention matrix).
|
| 275 |
+
|
| 276 |
+
There have been other recent advances in understanding the theory behind transformers: [PMB19, DGV + 19] proved Turing universality, [CLJ20b] provided necessary and sufficient conditions for attention to simulate convolution. A linearized form of self-attention was also found to exhibit a depth phase transition [LWS + 20]; and the Lipschitz constant of self-attention was analyzed by [KPM20].
|
| 277 |
+
|
| 278 |
+
Perhaps the convergence to rank one of a path should come as no surprise: each path component contains row-stochastic matrices as a result of the softmax attention, and [AT77] showed the exponential convergence of products of stochastic matrices to rank one. While the intuition behind stochastic matrices driving convergence still applies, in deep attention networks these matrices interact in more complex ways than what classical analyses consider. As we show, because of these interactions the rank collapses much faster than what would be expected based on classical analyses (cubic vs linear rate).
|
| 279 |
+
|
| 280 |
+
## 6 Conclusion
|
| 281 |
+
|
| 282 |
+
This work exposes competing forces over rank collapse in self-attention networks, namely self-attention vs skip connections and MLPs. In the process, we develop a path decomposition for SANs, which modularizes the study of self-attention and is of independent interest to additional applications. These results open the door for many exciting future directions. For instance, how can one leverage the token-uniformity inductive bias revealed to design more effective networks, perhaps better at utilizing long paths? What are some practical implications for width-depth trade-off? How do we prove meaningful lower bounds of residue convergence for transformers? Answering these questions has broad implications in advancing the state of the art in deep learning.
|
| 283 |
+
|
| 284 |
+
Acknowledgements. Andreas Loukas would like to thank the Swiss National Science Foundation for supporting him in the context of the project 'Deep Learning for Graph-Structured Data' (grant number PZ00P2 179981). Jean-Baptiste Cordonnier is supported by the Swiss Data Science Center (SDSC).
|
| 285 |
+
|
| 286 |
+
## References
|
| 287 |
+
|
| 288 |
+
- [AT77] Jac M. Anthonisse and Henk Tijms. Exponential convergence of products of stochastic matrices. In Journal of Mathematical Analysis and Applications , 1977.
|
| 289 |
+
- [BCB15] Dzmitry Bahdanau, Kyunghyun Cho, and Yoshua Bengio. Neural machine translation by jointly learning to align and translate. In International Conference on Learning Representations , 2015.
|
| 290 |
+
- [BFL + 18] David Balduzzi, Marcus Frean, Lennox Leary, JP Lewis, Kurt Wan-Duo Ma, and Brian McWilliams. The shattered gradients problem: If resnets are the answer, then what is the question?, 2018.
|
| 291 |
+
- [BMR + 20] Tom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah, Jared Kaplan, Prafulla Dhariwal, Arvind Neelakantan, Pranav Shyam, Girish Sastry, Amanda Askell, Sandhini Agarwal, Ariel Herbert-Voss, Gretchen Krueger, Tom Henighan, Rewon Child, Aditya Ramesh, Daniel M. Ziegler, Jeffrey Wu, Clemens Winter, Christopher Hesse, Mark Chen, Eric Sigler, Mateusz Litwin, Scott Gray, Benjamin Chess, Jack Clark, Christopher Berner, Sam McCandlish, Alec Radford, Ilya Sutskever, and Dario Amodei. Language models are few-shot learners. 2020.
|
| 292 |
+
- [BZV + 19] Irwan Bello, Barret Zoph, Ashish Vaswani, Jonathon Shlens, and Quoc V. Le. Attention augmented convolutional networks. In International Conference on Computer Vision , 2019.
|
| 293 |
+
- [CGRS19] Rewon Child, Scott Gray, Alec Radford, and Ilya Sutskever. Generating long sequences with sparse transformers. 2019.
|
| 294 |
+
- [CKSN18] Zac Cranko, Simon Kornblith, Zhan Shi, and Richard Nock. Lipschitz networks and distributional robustness. arXiv preprint arXiv:1809.01129 , 2018.
|
| 295 |
+
- [CLD + 20] Krzysztof Choromanski, Valerii Likhosherstov, David Dohan, Xingyou Song, Jared Davis, Tamas Sarlos, David Belanger, Lucy Colwell, and Adrian Weller. Masked language modeling for proteins via linearly scalable long-context transformers. 2020.
|
| 296 |
+
- [CLJ20a] Jean-Baptiste Cordonnier, Andreas Loukas, and Martin Jaggi. Multi-head attention: Collaborate instead of concatenate. 2020.
|
| 297 |
+
- [CLJ20b] Jean-Baptiste Cordonnier, Andreas Loukas, and Martin Jaggi. On the relationship between self-attention and convolutional layers. In International Conference on Learning Representations , 2020.
|
| 298 |
+
- [DBK + 21] Alexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn, Xiaohua Zhai, Thomas Unterthiner, Mostafa Dehghani, Matthias Minderer, Georg Heigold, Sylvain Gelly, Jakob Uszkoreit, and Neil Houlsby. An image is worth 16x16 words: Transformers for image recognition at scale. In International Conference on Learning Representations , 2021.
|
| 299 |
+
- [DCLT18] Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. Bert: Pre-training of deep bidirectional transformers for language understanding. CoRR , 2018.
|
| 300 |
+
- [DGM06] Ido Dagan, Oren Glickman, and Bernardo Magnini. The pascal recognising textual entailment challenge. In Machine Learning Challenges. Evaluating Predictive Uncertainty, Visual Object Classification, and Recognising Tectual Entailment , pages 177-190, 2006.
|
| 301 |
+
- [DGV + 19] Mostafa Dehghani, Stephan Gouws, Oriol Vinyals, Jakob Uszkoreit, and glyph[suppress] Lukasz Kaiser. Universal transformers. In International Conference on Learning Representations , 2019.
|
| 302 |
+
- [DKB + 20] Hadi Daneshmand, Jonas Kohler, Francis Bach, Thomas Hofmann, and Aurelien Lucchi. Batch normalization provably avoids ranks collapse for randomly initialised deep networks. Advances in Neural Information Processing Systems , 33:18387-18398, 2020.
|
| 303 |
+
|
| 304 |
+
- [FO ˇ S19] Karlis Freivalds, Em¯ ıls Ozoli¸ nˇ s, and Agris ˇ Sostaks. Neural shuffle-exchange networks - sequence processing in o(n log n) time. In H. Wallach, H. Larochelle, A. Beygelzimer, F. Alch´ e-Buc, E. Fox, and R. Garnett, editors, Advances in Neural Information Processing Systems , volume 32, pages 6630-6641. Curran Associates, Inc., 2019.
|
| 305 |
+
- [HZRS16a] Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep residual learning for image recognition. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 770-778, 2016.
|
| 306 |
+
- [HZRS16b] Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Identity mappings in deep residual networks. In European conference on computer vision , pages 630-645. Springer, 2016.
|
| 307 |
+
- [KPM20] Hyunjik Kim, George Papamakarios, and Andriy Mnih. The lipschitz constant of self-attention. arXiv preprint arXiv:2006.04710 , 2020.
|
| 308 |
+
- [KR18] Taku Kudo and John Richardson. Sentencepiece: A simple and language independent subword tokenizer and detokenizer for neural text processing. In Empirical Methods in Natural Language Processing , 2018.
|
| 309 |
+
- [KVPF20] Angelos Katharopoulos, Apoorv Vyas, Nikolaos Pappas, and Fran¸ cois Fleuret. Transformers are RNNs: Fast autoregressive transformers with linear attention. 2020.
|
| 310 |
+
- [LCG + 19] Zhenzhong Lan, Mingda Chen, Sebastian Goodman, Kevin Gimpel, Piyush Sharma, and Radu Soricut. Albert: A lite bert for self-supervised learning of language representations. arXiv preprint arXiv:1909.11942 , 2019.
|
| 311 |
+
- [LGA16] R´ emi Lebret, David Grangier, and Michael Auli. Generating text from structured data with application to the biography domain. CoRR , abs/1603.07771, 2016.
|
| 312 |
+
- [LWS + 20] Yoav Levine, Noam Wies, Or Sharir, Hofit Bata, and Amnon Shashua. Limits to depth efficiencies of self-attention. arXiv preprint arXiv:2006.12467 , 2020.
|
| 313 |
+
- [LZL + 20] Haoneng Luo, Shiliang Zhang, Ming Lei, , and Lei Xie. Simplified self-attention for transformerbased end-to-end speech recognition. In CoRR , 2020.
|
| 314 |
+
- [PMB19] Jorge Perez, Javier Marinkovic, and Pablo Barcelo. On the turing completeness of modern neural network architectures. In International Conference on Learning Representations , 2019.
|
| 315 |
+
- [POT16] Ankur Parikh and Jakob Uszkoreit Oscar T¨ ackstr¨ om, Dipanjan Das. A decomposable attention model for natural language inference. In EMNLP , 2016.
|
| 316 |
+
- [RPV + 19] Prajit Ramachandran, Niki Parmar, Ashish Vaswani, Irwan Bello, Anselm Levskaya, and Jon Shlens. Stand-alone self-attention in vision models. In Neural Information Processing Systems , 2019.
|
| 317 |
+
- [RSR + 20] Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, and Peter J. Liu. Exploring the limits of transfer learning with a unified text-to-text transformer. Journal of Machine Learning Research , 21(140):1-67, 2020.
|
| 318 |
+
- [SDCW19] Victor Sanh, Lysandre Debut, Julien Chaumond, and Thomas Wolf. Distilbert, a distilled version of BERT: smaller, faster, cheaper and lighter. CoRR , abs/1910.01108, 2019.
|
| 319 |
+
- [SS20] Timo Schick and Hinrich Sch¨ utze. It's not just size that matters: Small language models are also few-shot learners. arXiv preprint arXiv:2009.07118 , 2020.
|
| 320 |
+
- [SV18] Kevin Scaman and Aladin Virmaux. Lipschitz regularity of deep neural networks: analysis and efficient estimation. arXiv preprint arXiv:1805.10965 , 2018.
|
| 321 |
+
|
| 322 |
+
- [SYS + 20] Zhiqing Sun, Hongkun Yu, Xiaodan Song, Renjie Liu, Yiming Yang, and Denny Zhou. Mobilebert: a compact task-agnostic BERT for resource-limited devices. In Dan Jurafsky, Joyce Chai, Natalie Schluter, and Joel R. Tetreault, editors, Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics, ACL 2020, Online, July 5-10, 2020 , pages 2158-2170. Association for Computational Linguistics, 2020.
|
| 323 |
+
- [TBM + 20] Yi Tay, Dara Bahri, Donald Metzler, Da-Cheng Juan, Zhe Zhao, , and Che Zheng. Synthesizer: Rethinking self-attention in transformer models. 2020.
|
| 324 |
+
- [VFJ15] Oriol Vinyals, Meire Fortunato, and Navdeep Jaitly. Pointer networks. In Proceedings of the 28th International Conference on Neural Information Processing Systems-Volume 2 , pages 2692-2700, 2015.
|
| 325 |
+
- [VSP + 17] Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser, and Illia Polosukhin. Attention is all you need. In Advances in Neural Information Processing Systems , 2017.
|
| 326 |
+
- [VWB16a] Andreas Veit, Michael Wilber, and Serge Belongie. Residual networks behave like ensembles of relatively shallow networks. In Proceedings of the 30th International Conference on Neural Information Processing Systems , pages 550-558, 2016.
|
| 327 |
+
- [VWB16b] Andreas Veit, Michael Wilber, and Serge Belongie. Residual networks behave like ensembles of relatively shallow networks. In Advances in Neural Information Processing Systems , 2016.
|
| 328 |
+
- [WLK + 20] Sinong Wang, Belinda Li, Madian Khabsa, Han Fang, and Hao Ma. Linformer: Self attention with linear complexity. 2020.
|
| 329 |
+
- [WSM + 19] Alex Wang, Amanpreet Singh, Julian Michael, Felix Hill, Omer Levy, and Samuel R. Bowman. Glue: A multi-task benchmark and analysis platform for natural language understanding. In International Conference on Learning Representations , 2019.
|
| 330 |
+
- [YDY + 19] Zhilin Yang, Zihang Dai, Yiming Yang, Jaime Carbonell, Russ R Salakhutdinov, and Quoc V Le. Xlnet: Generalized autoregressive pretraining for language understanding. Advances in Neural Information Processing Systems , 32:5753-5763, 2019.
|
| 331 |
+
- [ZGD + 20] Manzil Zaheer, Guru Guruganesh, Avinava Dubey, Joshua Ainslie, Chris Alberti, Santiago Ontanon, Philip Pham, Anirudh Ravula, Qifan Wang, Li Yang, and Amr Ahmed. Big bird: Transformers for longer sequences. In Advances in Neural Information Processing Systems , 2020.
|
| 332 |
+
|
| 333 |
+
## A Deferred Proofs
|
| 334 |
+
|
| 335 |
+
We build our argument step by step, by first considering a single-head self-attention layer in § A.1 and then moving to deeper networks with single and multiple heads in § A.3 and § A.4. The results are extended to take into account skip connections and MLPs in § A.5 and § A.6
|
| 336 |
+
|
| 337 |
+
## A.1 Single-layer and single-head
|
| 338 |
+
|
| 339 |
+
We consider a single-head self-attention layer:
|
| 340 |
+
|
| 341 |
+
<!-- formula-not-decoded -->
|
| 342 |
+
|
| 343 |
+
We focus in particular on how the residual changes. As discussed previously, the value bias can be safely ignored since it does not contribute to the residual.
|
| 344 |
+
|
| 345 |
+
The following is proved:
|
| 346 |
+
|
| 347 |
+
Lemma A.1. The residual abides to:
|
| 348 |
+
|
| 349 |
+
<!-- formula-not-decoded -->
|
| 350 |
+
|
| 351 |
+
with γ selected such that √ max i,j,j ′ | A ij -A ij ′ | ∑ i max j,j ′ | A ij -A ij ′ | ≤ γ max j,j ′ ∑ i | A ij -A ij ′ | and | E ij -E ij ′ | ≤ 1 . 256 with E = res ( X ) W QK √ d qk res ( X ) ⊤ .
|
| 352 |
+
|
| 353 |
+
The unscaled attention scores are computed as follows,
|
| 354 |
+
|
| 355 |
+
<!-- formula-not-decoded -->
|
| 356 |
+
|
| 357 |
+
and following [CLJ20a], we can use the softmax shift invariance property to prune the terms constant over the columns and obtain,
|
| 358 |
+
|
| 359 |
+
<!-- formula-not-decoded -->
|
| 360 |
+
|
| 361 |
+
with W QK = W Q W ⊤ K and b QK = W K b Q .
|
| 362 |
+
|
| 363 |
+
We use the shorthand notation R := res( X ) and R ′ := res( X ′ ).
|
| 364 |
+
|
| 365 |
+
The attention matrix can be written as
|
| 366 |
+
|
| 367 |
+
<!-- formula-not-decoded -->
|
| 368 |
+
|
| 369 |
+
Using the shift-invariance property of the softmax operator, the first term above can be safely ignored since it is constant across columns. We therefore have that
|
| 370 |
+
|
| 371 |
+
<!-- formula-not-decoded -->
|
| 372 |
+
|
| 373 |
+
where we have set r := R W ⊤ QK √ d qk x + R b QK √ d qk .
|
| 374 |
+
|
| 375 |
+
Setting E = R W QK √ d qk R ⊤ and ˜ A = 1 r ⊤ , the input reweighted by the attention probibilities PX is given by
|
| 376 |
+
|
| 377 |
+
<!-- formula-not-decoded -->
|
| 378 |
+
|
| 379 |
+
<!-- formula-not-decoded -->
|
| 380 |
+
|
| 381 |
+
<!-- formula-not-decoded -->
|
| 382 |
+
|
| 383 |
+
<!-- formula-not-decoded -->
|
| 384 |
+
|
| 385 |
+
<!-- formula-not-decoded -->
|
| 386 |
+
|
| 387 |
+
<!-- formula-not-decoded -->
|
| 388 |
+
|
| 389 |
+
where the inequality above is entry-wise and follows from Lemma A.3 whenever | E ij -E ij ′ | ≤ 1 . 256. Similarly PX ≥ 1 ( x ⊤ +softmax( r ) ⊤ R ) -2 D 1 softmax( r ) ⊤ R , where we again invoke Lemma A.3.
|
| 390 |
+
|
| 391 |
+
Therefore, the (entry-wise) distance of the output of the self-attention layer SA ( X ) = PXW V from being constant across tokens is at most:
|
| 392 |
+
|
| 393 |
+
<!-- formula-not-decoded -->
|
| 394 |
+
|
| 395 |
+
where r ′ = ( x + R ⊤ softmax( r )) W V .
|
| 396 |
+
|
| 397 |
+
Now we bound the right hand side of the above inequality. For the ℓ 1 norm we obtain:
|
| 398 |
+
|
| 399 |
+
<!-- formula-not-decoded -->
|
| 400 |
+
|
| 401 |
+
where the last step is due to ∥ softmax( r ) ∥ 1 = 1 and ∥ AB ∥ 1 ≤ ∥ A ∥ 1 ∥ B ∥ 1 , implying ∥ SA ( X ) -1 ( r ′ ) ⊤ ∥ 1 ≤ 2 ∥ D 1 ∥ 1 ∥ R ∥ 1 ∥ W V ∥ 1 .
|
| 402 |
+
|
| 403 |
+
On the other hand, an analogous argument gives the following bound on the ℓ ∞ norm of the residual:
|
| 404 |
+
|
| 405 |
+
<!-- formula-not-decoded -->
|
| 406 |
+
|
| 407 |
+
Combining the two norms we obtain:
|
| 408 |
+
|
| 409 |
+
<!-- formula-not-decoded -->
|
| 410 |
+
|
| 411 |
+
Moreover, by the definition of D as in Lemma A.3 and under the current Lemma's definition, we have that
|
| 412 |
+
|
| 413 |
+
<!-- formula-not-decoded -->
|
| 414 |
+
|
| 415 |
+
The above imply
|
| 416 |
+
|
| 417 |
+
<!-- formula-not-decoded -->
|
| 418 |
+
|
| 419 |
+
which is equivalent to the main claim.
|
| 420 |
+
|
| 421 |
+
## A.2 Multiple-heads and single-layer
|
| 422 |
+
|
| 423 |
+
Lemma A.2. In the setting of Lemma A.1, the residual of the output of a H -heads attention layer abides to:
|
| 424 |
+
|
| 425 |
+
<!-- formula-not-decoded -->
|
| 426 |
+
|
| 427 |
+
where ∥ W QK,h ∥ 1 ∥ W h ∥ 1 , ∞ ≤ β for all heads h ∈ [ H ] .
|
| 428 |
+
|
| 429 |
+
Proof. The output of a multi-head attention layer is
|
| 430 |
+
|
| 431 |
+
<!-- formula-not-decoded -->
|
| 432 |
+
|
| 433 |
+
where W h := W V,h W O,h as in the main text and P h is computed using the heads parameters W QK,h and b QK,h . The proof proceeds similarly to Section A.2 until eq. 11,
|
| 434 |
+
|
| 435 |
+
<!-- formula-not-decoded -->
|
| 436 |
+
|
| 437 |
+
where r ′′ = ∑ h ( x + R ⊤ softmax( r h )) W h .
|
| 438 |
+
|
| 439 |
+
The elementwise inequality implies inequalities for ℓ 1 and ℓ ∞ norms and applying the triangle inequality on the sum, we obtain
|
| 440 |
+
|
| 441 |
+
<!-- formula-not-decoded -->
|
| 442 |
+
|
| 443 |
+
and a similar expression for the ℓ ∞ norm. The rest of the proof proceeds similarly as the single head proof.
|
| 444 |
+
|
| 445 |
+
## A.3 Single-head and multiple-layers
|
| 446 |
+
|
| 447 |
+
We next consider how the residual changes after L layers of the form: X l = SA l 1 ( X l -1 ) .
|
| 448 |
+
|
| 449 |
+
Corollary 2.2. In the setting of Lemma A.1, for any single-head SAN consisting of L layers with ∥ W l QK, 1 ∥ 1 ≤ β for every l ∈ [ L ] , the residual is bounded by
|
| 450 |
+
|
| 451 |
+
<!-- formula-not-decoded -->
|
| 452 |
+
|
| 453 |
+
which amounts to a doubly exponential convergence to a rank-1 matrix.
|
| 454 |
+
|
| 455 |
+
Proof. Unfolding the recursion backwards from the last layer to the first and applying Lemma A.1 we obtain:
|
| 456 |
+
|
| 457 |
+
<!-- formula-not-decoded -->
|
| 458 |
+
|
| 459 |
+
<!-- formula-not-decoded -->
|
| 460 |
+
|
| 461 |
+
<!-- formula-not-decoded -->
|
| 462 |
+
|
| 463 |
+
<!-- formula-not-decoded -->
|
| 464 |
+
|
| 465 |
+
<!-- formula-not-decoded -->
|
| 466 |
+
|
| 467 |
+
<!-- formula-not-decoded -->
|
| 468 |
+
|
| 469 |
+
matching the theorem statement.
|
| 470 |
+
|
| 471 |
+
## A.4 Multiple-head and multiple-layers
|
| 472 |
+
|
| 473 |
+
Corollary 2.3 (mutli-head multi-layer) . In the setting of Lemma A.1, consider a depthL SAN with H heads per layer. Fix ∥ W l QK,h ∥ 1 ∥ W l h ∥ 1 , ∞ ≤ β for all h ∈ [ H ] and l ∈ [ L ] . The output residual is bounded by
|
| 474 |
+
|
| 475 |
+
<!-- formula-not-decoded -->
|
| 476 |
+
|
| 477 |
+
which indicates that the output convergences to a rank-1 matrix doubly exponentialy.
|
| 478 |
+
|
| 479 |
+
Proof. The proof procceeds recursively as for Theorem 2.2 in the single head case but using the bound on single-layer multi-heads residuals from Lemma A.2.
|
| 480 |
+
|
| 481 |
+
## A.5 SAN with skip connections
|
| 482 |
+
|
| 483 |
+
As noted in the main text, a lower bound on the residual better aligns with practice, where SANs with skip connections do not suffer rank collapse. For consistency with the other analyses and as one way to illustrate residual growth, we provide a (vacuously large) upper bound on the residual for SANs with skip connections.
|
| 484 |
+
|
| 485 |
+
Corollary 3.1 (SAN with skip connections) . In the setting of Lemma A.1, consider a depthL SAN with H heads per layer and skip connections. Fix ∥ W l QK,h ∥ 1 ∥ W l h ∥ 1 , ∞ ≤ β for all heads h ∈ [ H ] and layers l ∈ [ L ] . The output residual is bounded by
|
| 486 |
+
|
| 487 |
+
<!-- formula-not-decoded -->
|
| 488 |
+
|
| 489 |
+
which does not indicate convergence.
|
| 490 |
+
|
| 491 |
+
Proof. For a SAN with skip connections, the residual bound for a single-head single-layer SAN from lemma A.1 now becomes:
|
| 492 |
+
|
| 493 |
+
<!-- formula-not-decoded -->
|
| 494 |
+
|
| 495 |
+
To obtain a multi-layer bound, we unfold the recursion backwards.
|
| 496 |
+
|
| 497 |
+
Let us consider a single head model first and fix ∥ W l QK,h ∥ 1 ∥ W l h ∥ 1 , ∞ ≤ β for all l ∈ [ L ]. We have that:
|
| 498 |
+
|
| 499 |
+
<!-- formula-not-decoded -->
|
| 500 |
+
|
| 501 |
+
Now we unroll this bound across layers to write it in terms of res( X ). At the k th step of unrolling, the max is one of the two terms in Eq 24: either 4 γ β √ d qk ∥ res( X L -k ) ∥ 3 1 , ∞ or ∥ res( X L -k ) ∥ 1 , ∞ , i.e. we make a binary choice. Thus unrolling through all L layers corresponds to a path from the root to the maximum leaf in a depthL complete binary tree. Each leaf has the form ( 8 γ β √ d qk ) 3 l -1 2 2 3 l ( L -l ) ∥ res( X ) ∥ 3 l 1 , ∞ , where l indicates the number of times the term 4 γ β √ d qk ∥ res( X L -k ) ∥ 3 1 , ∞ is chosen as the max. Note the ordering of these choices does not matter, only the number of times a term is chosen. Consequently, the residual bound is the maximum amongst such leaf terms:
|
| 502 |
+
|
| 503 |
+
<!-- formula-not-decoded -->
|
| 504 |
+
|
| 505 |
+
We now apply this bound to H heads, we use Lemma A.2, which for a single layer gives:
|
| 506 |
+
|
| 507 |
+
<!-- formula-not-decoded -->
|
| 508 |
+
|
| 509 |
+
Therefore, accounting for the factor of H in above, we obtain a residual bound for a depthL widthH SAN with skip connections:
|
| 510 |
+
|
| 511 |
+
<!-- formula-not-decoded -->
|
| 512 |
+
|
| 513 |
+
<!-- formula-not-decoded -->
|
| 514 |
+
|
| 515 |
+
which concludes the proof.
|
| 516 |
+
|
| 517 |
+
## A.6 SAN with MLP
|
| 518 |
+
|
| 519 |
+
We now study how using an MLP affects the residual. Recall we focus on SANs with layers written as
|
| 520 |
+
|
| 521 |
+
<!-- formula-not-decoded -->
|
| 522 |
+
|
| 523 |
+
Note that, to keep the notation compact, we use f l to encompass both the MLP as well as the output bias. In our subsequent analysis, we use λ l, 1 , ∞ to denote the Lipschitz constant of f l with respect to ℓ 1 , ∞ norm.
|
| 524 |
+
|
| 525 |
+
The proof proceeds the same way as in § A.1. For clarity, we point out the differences with proof in § A.1 without repeating details that remain the same.
|
| 526 |
+
|
| 527 |
+
Theorem 3.2 (SAN with MLP) . In the setting of Lemma A.1, consider a depthL and widthH SAN with MLP. Moreover, let ∥ W l QK,h ∥ 1 ∥ W l h ∥ 1 , ∞ ≤ β for all h ∈ [ H ] and l ∈ [ L ] and fix λ l, 1 , ∞ ≤ λ . We then have that
|
| 528 |
+
|
| 529 |
+
<!-- formula-not-decoded -->
|
| 530 |
+
|
| 531 |
+
which amounts to a doubly exponential rate of convergence. with respect to the ℓ 1 , ∞ norm.
|
| 532 |
+
|
| 533 |
+
Proof. With an MLP as formulated in Eq 25, we have W h := W V W O in place of just the value weight W V , as defined in the main text. As before, let R denote res( X ).
|
| 534 |
+
|
| 535 |
+
The proof proceeds the same way as in Lemma A.1, until Eq 11, where we handle the multi-head case the same way as in Eq A.2 to obtain the entrywise inequality:
|
| 536 |
+
|
| 537 |
+
<!-- formula-not-decoded -->
|
| 538 |
+
|
| 539 |
+
As in the proof of A.2, this elementwise inequality implies the corresponding inequality in matrix norms ℓ 1 and ℓ ∞ , to each of which we apply the triangle inequality to yield:
|
| 540 |
+
|
| 541 |
+
<!-- formula-not-decoded -->
|
| 542 |
+
|
| 543 |
+
for p ∈ [1 , ∞ ].
|
| 544 |
+
|
| 545 |
+
We now use the fact that f ( 1 r ′⊤ ) also takes the form 1 r ′′⊤ for some vector r ′′ . Indeed, f encompasses weight matrix multiplications, bias addition, and entrywise nonlinearities, all of which preserve the fact that f ( 1 r ′⊤ ) is constant across rows. Therefore,
|
| 546 |
+
|
| 547 |
+
<!-- formula-not-decoded -->
|
| 548 |
+
|
| 549 |
+
Subsequently, just like for the single-head single-layer proof, we bound ∥ D h 1 softmax( r h ) ⊤ RW h ∥ p in the above by
|
| 550 |
+
|
| 551 |
+
<!-- formula-not-decoded -->
|
| 552 |
+
|
| 553 |
+
<!-- formula-not-decoded -->
|
| 554 |
+
|
| 555 |
+
As we have shown before, ∥ D h 1 ∥ 1 , ∞ can be bounded above by 2 γ √ d qk ∥ R ∥ 1 ∥ W QK,h ∥ 1 ∥ R ∥ ∞ . Applying this to both Eq 28 and Eq 29, and combining the two as in Lemma A.1, yields the bound:
|
| 556 |
+
|
| 557 |
+
<!-- formula-not-decoded -->
|
| 558 |
+
|
| 559 |
+
Finally, we recursively unroll the bound across layers to obtain a residual bound in terms of res( X ):
|
| 560 |
+
|
| 561 |
+
<!-- formula-not-decoded -->
|
| 562 |
+
|
| 563 |
+
which concludes the proof.
|
| 564 |
+
|
| 565 |
+
## A.7 A technical lemma
|
| 566 |
+
|
| 567 |
+
Lemma A.3. Suppose that P is the row-stochastic matrix associated with A and let ˜ P be the one associated with ˜ A = A -E for some matrix E with | E ij -E ij ′ | ≤ 1 . 256 for every i, j, j ′ . Then
|
| 568 |
+
|
| 569 |
+
<!-- formula-not-decoded -->
|
| 570 |
+
|
| 571 |
+
with the diagonal matrix D having D ii = max j,j ′ | δ ⊤ i E ( δ j -δ j ′ ) | and the inequality taken entry-wise.
|
| 572 |
+
|
| 573 |
+
Proof. Let us start by the definition of the row-stochastic matrix:
|
| 574 |
+
|
| 575 |
+
<!-- formula-not-decoded -->
|
| 576 |
+
|
| 577 |
+
The above, implies that for every i, j we have:
|
| 578 |
+
|
| 579 |
+
<!-- formula-not-decoded -->
|
| 580 |
+
|
| 581 |
+
which can be further relaxed to
|
| 582 |
+
|
| 583 |
+
<!-- formula-not-decoded -->
|
| 584 |
+
|
| 585 |
+
which holds for | E ij -E ij ′ | ≤ 1 . 256. Notice also that
|
| 586 |
+
|
| 587 |
+
<!-- formula-not-decoded -->
|
| 588 |
+
|
| 589 |
+
both of which are at most max j ′ | δ ⊤ i E ( δ j -δ j ′ ) | , from which the claim follows.
|
| 590 |
+
|
| 591 |
+
## B Additional results
|
| 592 |
+
|
| 593 |
+
## B.1 The path length distribution of transformers
|
| 594 |
+
|
| 595 |
+
Figure 5: Distribution of the path length for a diverse selection of transformer architectures (encoder only) with different depths and widths. The legends are sorted by the total number of heads in the architecture L × H. We provide the following architecture: GPT-3 [BMR + 20], T5 [RSR + 20], Bert [DCLT18], ViT [DBK + 21], DistilBert [SDCW19], MobileBert [SYS + 20].
|
| 596 |
+
|
| 597 |
+
<!-- image -->
|
| 598 |
+
|
| 599 |
+
As we saw in § 2.1, transformers can be viewed as an interdependent ensemble of simpler networks (or paths) each of different depth (or length). Aiming to gain more insight about the ensemble structure in practice, Fig 5 visualizes the path length distribution in various commonly-used architectures.
|
| 600 |
+
|
| 601 |
+
Based on the exponential decay of path effectiveness result, we hypothesize that models that focus overwhelmingly on long paths are less efficient than models with a more diverse path distribution. The long-paths models are furthermore likely to be less robust, as they require larger MLP Lipschitz constants to counteract the token-uniformity inductive bias caused by self-attention, as described in § 3. It is perhaps no coincidence that the intentionally more efficient models, such as DistilBert or MobileBert, have some of the most diverse path distributions; and that for the most extreme long-paths-focused model, GPT3, studies found that its model size can be reduced by several orders of magnitude and achieve similar performance [SS20]. We leave these exciting directions for future work.
|
text-versions/attention-markdown/2104.01541_Attention Backend for Automatic Speaker .md
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2104.01541 Attention Backend For Automatic Speaker
|
| 2 |
+
|
| 3 |
+
## ATTENTION BACK-END FOR AUTOMATIC SPEAKER VERIFICATION WITH MULTIPLE ENROLLMENT UTTERANCES
|
| 4 |
+
|
| 5 |
+
Chang Zeng 1 , 2 , Xin Wang 1 , Erica Cooper 1 , Xiaoxiao Miao 1 , Junichi Yamagishi 1 , 2
|
| 6 |
+
|
| 7 |
+
1 National Institute of Informatics, Japan 2 SOKENDAI, Japan
|
| 8 |
+
|
| 9 |
+
## ABSTRACT
|
| 10 |
+
|
| 11 |
+
Probabilistic linear discriminant analysis (PLDA) or cosine similarity have been widely used in traditional speaker verification systems as back-end techniques to measure pairwise similarities. To make better use of multiple enrollment utterances, we propose a novel attention back-end model, which can be used for both textindependent (TI) and text-dependent (TD) speaker verification, and employ scaled-dot self-attention and feed-forward self-attention networks as architectures that learn the intra-relationships of the enrollment utterances. In order to verify the proposed attention back-end, we conduct a series of experiments on CNCeleb and VoxCeleb datasets by combining it with several sate-of-the-art speaker encoders including TDNN and ResNet. Experimental results using multiple enrollment utterances on CNCeleb show that the proposed attention back-end model leads to lower EER and minDCF score than the PLDA and cosine similarity counterparts for each speaker encoder and an experiment on VoxCeleb indicate that our model can be used even for single enrollment case.
|
| 12 |
+
|
| 13 |
+
Index Terms -Speaker verification, TDNN, ResNet, Attention
|
| 14 |
+
|
| 15 |
+
## 1. INTRODUCTION
|
| 16 |
+
|
| 17 |
+
Automatic speaker verification (ASV) is a task that determines whether input speech is uttered by a claimed speaker or not. Until recently, generative models such as GMM-UBM [1] and i-vector [2] with PLDA [3] were dominant for this task. With the development of deep learning, these models have been replaced by neural networks. A good example is neural speaker embeddings [4, 5] extracted from a hidden layer of a neural speaker encoder network, such as x-vectors [6, 7], and it is reported that these have outperformed conventional i-vectors. For the case of x-vectors, speaker embedding vectors are extracted from the first fully-connected layer after a statistical pooling layer of TDNN [5]. PLDA is adopted as a back-end model for handling the channel mismatch between enrollment speakers and evaluation speech. In addition to TDNN, ResNet [8] with metric learning loss [9, 10] or discriminative training loss of softmax [11, 12] is also a popular choice for extracting speaker embeddings. Some of them use simple cosine similarity between enrollment speakers and evaluation speech as a back-end model.
|
| 18 |
+
|
| 19 |
+
The objective of this paper is to explore a new way of better handling multiple enrollment utterances and then propose a new backend model that can use a varying number of embedding vectors corresponding to multiple enrollment utterances directly. In a realworld setting, enrollment speakers may provide multiple utterances to register their identity. We hypothesize that intra-variations of enrollment utterances contain important information such as expected acoustic variations of the enrolled speakers. Even though the traditional generative PLDA can combine multiple enrollment utterances for a better representation of a speaker, there is still room for fully using intra-variations of enrollment utterances. Therefore, we propose a new back-end model based on scaled-dot self-attention and feed-forward self-attention networks to learn intra-variations.
|
| 20 |
+
|
| 21 |
+
In the proposed back-end model, multiple speaker embedding vectors are first stacked as a matrix that is used as the input for multihead scaled-dot self-attention, which estimates the self-attention probabilities of the input matrix. The self-attention matrix is then multiplied with the speaker embedding matrix in order to get bias parameters that emphasize or de-emphasize not only multiple enrollment utterances but also individual dimensions of their embedding vectors. The second step is multi-head feed-forward self-attention for aggregating the matrix modified using the multi-head scaleddot self-attention described above into one representative vector. Finally, cosine scoring using the representative vector and one extracted from an evaluation trial is done with a learnable logistic transform for better score calibration. This network is trained using the weighted loss of normal binary cross-entropy and a recently proposed generalized end-to-end (GE2E) loss for ASV [13]. Note that our attention back-end model, which uses attention mechanism on the utterance-level , is different from previous work [14, 15] in which attention mechanism was applied to frame-level aggregation.
|
| 22 |
+
|
| 23 |
+
Experiments are conducted on two ASV datasets, including the well explored VoxCeleb [16, 17] and new multi-genre CNCeleb [18, 19]. Our proposed attention-based back-end is first evaluated for a single enrollment case on VoxCeleb and further analyzed for a multiple enrollment case on CNCeleb. The remainder of the paper is organized as follows. Cosine similarity and PLDA are briefly reviewed in Section 2. Section 3 gives details on the proposed attention back-end model. The experimental setup and results are outlined in Section 4. Finally, conclusions are presented in Section 5.
|
| 24 |
+
|
| 25 |
+
## 2. CONVENTIONAL BACK-END MODELS
|
| 26 |
+
|
| 27 |
+
## 2.1. Cosine similarity
|
| 28 |
+
|
| 29 |
+
Cosine similarity can be used to evaluate how close of two speaker embeddings distributed in hyper-sphere and this serves as the simplest back-end. It has been frequently used as a scoring method for ASV systems trained using discriminative loss functions [9, 11, 20] that minimizes intra-class distance and maximizes inter-class distance. This scoring method is just an inter-product of a pair of speaker embedding vectors 1 to be scored and computed as follows.
|
| 30 |
+
|
| 31 |
+
<!-- formula-not-decoded -->
|
| 32 |
+
|
| 33 |
+
As for the case of multi-session enrollment, which means using multiple enrollment utterances per speaker, a frequently made choice is to average speaker embedding c n = 1 K ∑ K k =1 e m . Here, K is the number of enrollment utterances per speaker. Alternatively, a speaker embedding may be extracted from concatenated waveform or acoustic features.
|
| 34 |
+
|
| 35 |
+
1 In this paper, all vectors are assumed to be column vectors.
|
| 36 |
+
|
| 37 |
+
## 2.2. Probabilistic linear discriminant analysis
|
| 38 |
+
|
| 39 |
+
Probabilistic Linear Discriminant Analysis (PLDA) is also a frequently used back-end model. PLDA was first introduced to ASV in [21] to decompose the speaker embedding of an utterance n into a global mean µ , latent variable h n and residual term ϵ n as shown below.
|
| 40 |
+
|
| 41 |
+
<!-- formula-not-decoded -->
|
| 42 |
+
|
| 43 |
+
In Gaussian PLDA (GPLDA), where both the latent variable h and residual term ϵ are assumed to follow Gaussian distributions, that is, h ∼ N (0 , I ) and ϵ ∼ N (0 , Σ ) , where I and Σ represent identity and covariance matrices, respectively, the score of a pair of speaker embeddings is given as follows for a single-session enrollment case:
|
| 44 |
+
|
| 45 |
+
<!-- formula-not-decoded -->
|
| 46 |
+
|
| 47 |
+
<!-- formula-not-decoded -->
|
| 48 |
+
|
| 49 |
+
<!-- formula-not-decoded -->
|
| 50 |
+
|
| 51 |
+
<!-- formula-not-decoded -->
|
| 52 |
+
|
| 53 |
+
<!-- formula-not-decoded -->
|
| 54 |
+
|
| 55 |
+
where { µ , F , Σ } are trainable parameters and estimated on the basis of the EM algorithm.
|
| 56 |
+
|
| 57 |
+
There are several ways of handling the multi-session enrollment case with PLDA [22, 23]. According to results reported in [22, 23], we adopt the averaging and concatenating of multiple speaker embeddings as well as an extended PLDA formulation [23] as strategies to handle multiple enrollment utterances in our baseline model.
|
| 58 |
+
|
| 59 |
+
## 3. ATTENTION BACK-END
|
| 60 |
+
|
| 61 |
+
In this section, we explain how the proposed model uses attention mechanisms to measure pairwise similarity, including the detailed architecture of the model and its loss functions, which are illustrated in Fig. 1.
|
| 62 |
+
|
| 63 |
+
## 3.1. Model architecture
|
| 64 |
+
|
| 65 |
+
Suppose a speaker has K enrollment utterances. With a speaker encoder Enc ( · ) , we get K enrollment embedding vectors { e 1 , · · · , e K } , where e k = Enc ( x ( k ) 1: T ) ∈ R D , and x ( k ) 1: T is the waveform data of the k -th enrollment utterance. Since K varies across speakers, we need to aggregate { e 1 , · · · , e K } into a single vector h ∈ R D using two different attention mechanisms in sequence. Specifically, after stacking a matrix E = [ e 1 , · · · , e K ] ⊤ ∈ R K × D , we use multi-head scaled dot self-attention (SDSA) [24] to transform E into a hidden matrix H ∈ R K × D . With d 1 attention heads, we get
|
| 66 |
+
|
| 67 |
+
<!-- formula-not-decoded -->
|
| 68 |
+
|
| 69 |
+
where the i -th head matrix H i ∈ R K × D d 1 is computed by
|
| 70 |
+
|
| 71 |
+
<!-- formula-not-decoded -->
|
| 72 |
+
|
| 73 |
+
The query, key, and value matrices are set to Q i = EW Q i , K i = EW i K , and V i = EW V i , respectively, and they all have the shape of K × D d 1 . The matrices { W Q i , W i K , W V i , W O } are trainable parameters of the attention mechanism. The multiple heads in Eq.
|
| 74 |
+
|
| 75 |
+
Fig. 1 . Back-end architecture. Dashed boxes show detailed implementation of two multi-head attention blocks.
|
| 76 |
+
|
| 77 |
+
<!-- image -->
|
| 78 |
+
|
| 79 |
+
(8) are expected to attend to information from different representation subspaces at different positions.
|
| 80 |
+
|
| 81 |
+
Given H from Eq. (8), the second multi-head feed-forward selfattention (FFSA) mechanism aggregates it into the single representative embedding vector h by
|
| 82 |
+
|
| 83 |
+
<!-- formula-not-decoded -->
|
| 84 |
+
|
| 85 |
+
The j -th head vector h j ∈ R D d 2 is computed as
|
| 86 |
+
|
| 87 |
+
<!-- formula-not-decoded -->
|
| 88 |
+
|
| 89 |
+
where v j ∈ R D 2 and W j ∈ R D 2 × D d 2 are trainable parameters, and ˜ H j ∈ R K × D d 2 is a sub-matrix of H , i.e., H = [ ˜ H 1 , ˜ H 2 , · · · , ˜ H d 2 ] . This is inspired by the multi-head attentionbased aggregation proposed in [25].
|
| 90 |
+
|
| 91 |
+
After obtaining the representative vector for an enrollment speaker, the cosine similarity score between an evaluation speaker embedding, which is denoted as q = Enc ( y 1: T ) , and the representative vector h is calculated. Further, a logistic regression (LR) is used for better calibration as shown below:
|
| 92 |
+
|
| 93 |
+
<!-- formula-not-decoded -->
|
| 94 |
+
|
| 95 |
+
<!-- formula-not-decoded -->
|
| 96 |
+
|
| 97 |
+
where P ( q , h ) denotes the probability of q and h belonging to the same speaker and also serves as the final score for decision making, and a and b are trainable parameters.
|
| 98 |
+
|
| 99 |
+
Table 1 . Composition of pairs of (test-trial, enrollment-data) for training back-end model and ground-truth labels from mini-batch. A, B, and C are speaker IDs, and 1, 2, 3 and 4 are his or her audio IDs. ✓ and × denote test and enrollment audio files, respectively.
|
| 100 |
+
|
| 101 |
+
| A B C 1 2 3 4 1 2 3 4 1 2 3 4 Test Enroll Label Trials to be used for training ✓ × × × q A 1 h A 1 P ✓ × × × q A 1 h B 1 N ✓ × × × q A 1 h C 1 N × ✓ × × q A 2 h A 2 P ✓ × × × q A 2 h B 2 N ✓ × × × q A 2 h C 2 N . . . × × × ✓ q C 4 h A 4 N × × × ✓ q C 4 h B 4 N × × × ✓ q C 4 h C 4 P |
|
| 102 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 103 |
+
|
| 104 |
+
## 3.2. Loss functions
|
| 105 |
+
|
| 106 |
+
In the training stage, speakers in a mini-batch can be seen as either target or non-target speakers, and all audio files included in one mini-batch can be used to define various positive and negative pairs. Table 1 illustrates one example of forming pairs of (test-trial, enrollment-data) . In this example, one mini-batch of data has 3 speakers A , B , and C , and each speaker has 4 embeddings whose index ranges from 1 to 4. There are numerous ways of composing the pairs, but we here consider only the following cases. For positive pairs where the test trial and enrollment data are from the same speaker, one test trial is selected from the speaker's data, and the rest are left for enrollment. For negative pairs where the speaker of the test trial is different from that of the enrollment data, we consider only pairs marked by (test-trial= ✓ , enroll=( × , × , × )) of other speakers included in a mini-batch.
|
| 107 |
+
|
| 108 |
+
Using the above positive and negative pairs included in a minibatch, we optimize the proposed attention back-end. The loss function for the optimization is a weighted sum of binary cross-entropy (BCE) and generalized end-to-end (GE2E) loss [13] functions given below to train our model.
|
| 109 |
+
|
| 110 |
+
<!-- formula-not-decoded -->
|
| 111 |
+
|
| 112 |
+
As shown in Table 1, let us define q lm as a speaker embedding vector extracted from the m -th test trial of speaker l and h nm as a vector h of Eq. (10) based on an enrollment set m , which contains multiple audio files uttered by speaker n . The BCE loss can be computed as
|
| 113 |
+
|
| 114 |
+
̸
|
| 115 |
+
|
| 116 |
+
<!-- formula-not-decoded -->
|
| 117 |
+
|
| 118 |
+
where I ( · ) is an indicator function that returns one when its argument is true and zero otherwise. In addition to BCE, GE2E [13] is also used for reducing intra-class variance and enlarging inter-class variance. In the original GE2E loss, an averaged speaker embedding is computed per speaker as a centroid. Here, we treated a vector h of Eq. (10) as a centroid instead of a simple mean. Given this revision, the GE2E loss is given by
|
| 119 |
+
|
| 120 |
+
<!-- formula-not-decoded -->
|
| 121 |
+
|
| 122 |
+
Table 2 . VoxCeleb verification performance results with TDNN and different back-ends
|
| 123 |
+
|
| 124 |
+
| Back-end EER(%) minDCF(0.01) minDCF(0.001) Cosine 10.51 0.7928 0.8718 PLDA 3.14 0.3456 0.5567 Proposed 3.26 0.3323 0.5134 |
|
| 125 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------|
|
| 126 |
+
|
| 127 |
+
## 4. EXPERIMENTS
|
| 128 |
+
|
| 129 |
+
Datasets We conducted our experiments on two totally different datasets: VoxCeleb1&2 and CNCeleb1&2, which are English and Chinese datasets, respectively. VoxCeleb1&2 contains 7,363 speakers, whose voice comes from interviews, and is split into 7,323 speakers for training data and 40 speakers for testing data according to the official trial protocol. For trial pairs in the V oxCeleb1 test data, each speaker only has one enrollment utterance. Different from VoxCeleb, the CNCeleb1&2 dataset includes in-the-wild speech utterances of 3,000 speakers in 11 different genres, which leads to complex and composite inter-session variations, both intrinsic (i.e., speaking style, physiological status) and extrinsic (i.e., recording device, background noise) [19]. The official protocol uses 2,800 speakers for training and 200 speakers whose identity was enrolled in multiple sessions for evaluation. MUSAN [26] and RIRs [27] datasets were both used to augment the above datasets.
|
| 130 |
+
|
| 131 |
+
Baseline Our experiments used a few well-testified DNN models to extract fixed-length speaker embeddings: TDNN [6], TDNN with attentive statistics pooling (TDNN-ASP) [14], ECAPA-TDNN [28], and ResNet [8]. All TDNN variants used plain softmax loss, while the ResNet used am-softmax loss [20]. The TDNN models were trained by using an SGD optimizer with 0.01 learning rate. As for ResNet, it was trained by using an SGD optimizer with 0.1 learning rate. Both of them were trained for 20 epochs with 0.1 learning rate decay every 8 epochs. During the back-end training, all the speaker encoders were frozen. The GPLDA back-end was trained by using a subset of training data, which consisted of 100,000 speaker embeddings selected randomly from the training data. First, a linear discriminative analysis (LDA) transformation matrix was trained to reduce the dimension of the speaker embedding from 512 to 400. Then, the output of LDA was used to train a GPLDA model in which the dimension of the latent factor is 150.
|
| 132 |
+
|
| 133 |
+
Back-end training A balanced batch strategy was adopted to train the attention back-end model. For each mini-batch, assuming it has M speakers and K speaker embeddings per speaker, the size of one mini-batch was M × K . In our experiment, M and K were set to 256 and 5, respectively. When one mini-batch of data was fed into the back-end model, it was rearranged to form speaker verification trials that had multiple enrollment utterances (or embedding vectors) as described in Section 3.2 and the ratio of positive samples to negative samples was 1 : ( M -1) . The proposed model was trained for 40 epochs by using an SGD optimizer with a cyclical learning rate scheduler [29], which changed learning rate from 0.00001 to 0.00003 every 2,000 updating steps. The hyper-parameter λ , which is the weight of two loss functions, was set to 0.6. In the testing phase, the output of Eq. (12) served as a decision score.
|
| 134 |
+
|
| 135 |
+
## 4.1. Results
|
| 136 |
+
|
| 137 |
+
Although the main advantage of the proposed method is that multiple enrollment utterances can be used, we first confirmed the performance of the proposed back-end using a single enrollment case on the VoxCeleb dataset. This ensures the generalization capability of our proposed back-end with respect to the number of enrollment utterances. Table 2 shows the result for the TDNN speaker encoder on the VoxCeleb dataset. We can see that the attention back-end gave a number comparable to that of PLDA in terms of EER. Moreover, in terms of minDCF(0.01 and 0.001), the proposed model slightly outperformed PLDA model by 3.8% and 7.8%, respectively, in relative. Although the proposed architecture is motivated by the use of multiple enrollment utterances, it also works reasonably well for the single enrollment case.
|
| 138 |
+
|
| 139 |
+
Table 3 . CNCeleb verification performance results of two encoders with different back-ends
|
| 140 |
+
|
| 141 |
+
| Spk encoder Back-end Enroll process. EER(%) minDCF(0.01) TDNN Cosine Concat 20.82 0.8114 TDNN Cosine Mean 19.86 0.8350 TDNN [19] PLDA Concat 12.52 - TDNN PLDA Concat 12.09 0.6105 TDNN PLDA Mean 13.29 0.6522 TDNN PLDA Multi-session 21.35 0.8417 TDNN Proposed Attention 10.12 0.5649 ResNet Cosine Concat 12.46 0.5484 ResNet Cosine Mean 11.86 0.5045 ResNet PLDA Concat 15.66 0.5890 ResNet PLDA Mean 14.56 0.5692 ResNet PLDA Multi-session 21.91 0.8082 ResNet Proposed Attention 10.77 0.4983 TDNN-ASP PLDA Concat 11.63 0.6157 TDNN-ASP PLDA Mean 10.67 0.5990 TDNN-ASP Proposed Attention 9.90 0.5606 ECAPA-TDNN PLDA Concat 10.54 0.5806 ECAPA-TDNN PLDA Mean 9.51 0.5665 ECAPA-TDNN Proposed Attention 8.93 0.5043 |
|
| 142 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 143 |
+
|
| 144 |
+
In the following experiments, we focus on CNCeleb since this dataset has multiple enrollment utterances per speaker, and the acoustic conditions of the enrollment data may vary significantly. Therefore, it is a suitable dataset for evaluating the proposed methods. The first and the second groups of Table 3 shows the EER and minDCF(0.01) results for various back-end models using TDNN or ResNet encoders trained on CNCeleb, respectively. The third line of this table is the best result of others' work that we are aware of so far for this dataset. From the table, we first see that PLDA variants were better than cosine similarity variants for the TDNN encoder, whereas cosine similarity variants were more suitable for the discriminatively trained ResNet encoder, as reported in the literature. We can then see that our attention back-end model had a lower EER and minDCF score than the PLDA and cosine similarity variants for each speaker encoder type. The DET curves of these two speaker encoders with different back-end methods are shown in Figure 2.
|
| 145 |
+
|
| 146 |
+
We also combined our attention back-end with TDNN-ASP and ECAPA-TDNNmodels, which contained frame-level attention module. The result for the third group of Table 3 indicates that the utterance-level attention module included in our proposed model was complementary to the frame-level attention used in the speaker encoders in the third group. Also, we can confirm that our attention back-end had better performance than PLDA back-end again.
|
| 147 |
+
|
| 148 |
+
## 4.2. Ablation study
|
| 149 |
+
|
| 150 |
+
To explore the contribution of each component of our back-end for performance improvement, we conducted an ablation experiment whose result is shown in Table 4. This study also used the CNCeleb dataset. The proposed model can be divided into five components (SDSA, FFSA, LR, BCE and GE2E) as shown in the first line of the table. In each ablation study, we removed one component from the model except the FFSA, which was substituted with a simple mean ResNet operation for aggregation.
|
| 151 |
+
|
| 152 |
+
Fig. 2 . DET curves for combinations of TDNN and ResNet speaker encoders and several different back-end models.
|
| 153 |
+
|
| 154 |
+
<!-- image -->
|
| 155 |
+
|
| 156 |
+
Table 4 . Ablation experiment results on CNCeleb with TDNN speaker encoder.
|
| 157 |
+
|
| 158 |
+
| Systems EER(%) DCF(0.01) DCF(0.001) SDSA + FFSA + LR + BCE + GE2E 10.12 0.5649 0.7127 FFSA + LR + BCE + GE2E 19.55 0.8095 0.9046 SDSA + mean + LR + BCE + GE2E 10.26 0.5876 0.7270 SDSA + FFSA + BCE + GE2E 48.32 1.0000 1.0000 SDSA + FFSA + LR + GE2E 12.74 0.5937 0.7350 SDSA + FFSA + LR + BCE 10.28 0.5896 0.7402 |
|
| 159 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 160 |
+
|
| 161 |
+
From the second and the third lines of the table, it was confirmed that two self-attention mechanisms both contributed to the improvement. Concretely, both SDSA for summarizing intra-variations of multiple speaker embeddings and FFSA for aggregation contributed to the performance, and SDSA seemed to have a more important role. Additionally, from the fourth line, we can also see that LR for calibration was another essential component of the proposed model. The first, fifth and sixth lines of the table indicates interesting tendencies of our loss function using the weighted sum of BCE and GE2E. From a comparison of the fifth and sixth lines, we see that the proposed model using BCE loss only had a lower EER than that using GE2E loss only, while one using GE2E loss resulted in a lower minDCF(0.001) value. Combining BCE and GE2E thus resulted in the lowest values for all the metrics.
|
| 162 |
+
|
| 163 |
+
## 5. CONCLUSION
|
| 164 |
+
|
| 165 |
+
In this paper, we proposed a new attention back-end model for speaker verification using a varying number of multiple enrollment utterances and compared it with other back-end methods. The proposed back-end uses two types of attention, SDSA and FFSA, and they are trained based on weighted BCE and GE2E loss. For the CNCeleb dataset, the proposed attention back-end model was combined with several speaker encoders including TDNN and ResNet, and they were compared with PLDA or cosine similarity counterparts. The proposed model showed superiority and resulted in a lower EER and minDCF score than the PLDA and cosine similarity methods for each speaker encoder type. The experimental results on the VoxCeleb dataset show that the proposed back-end has comparable performance to conventional PLDA scoring even for the case of a single enrollment utterance.
|
| 166 |
+
|
| 167 |
+
Acknowledgement This study is supported by JST CREST Grants (JPMJCR18A6, JPMJCR20D3), MEXT KAKENHI Grants (16H06302, 18H04120, 18H04112, 18KT0051), Japan, and Google AI for Japan program.
|
| 168 |
+
|
| 169 |
+
## 6. REFERENCES
|
| 170 |
+
|
| 171 |
+
- [1] Douglas A Reynolds, Thomas F Quatieri, and Robert B Dunn, 'Speaker verification using adapted gaussian mixture models,' Digital signal processing , vol. 10, no. 1-3, pp. 19-41, 2000.
|
| 172 |
+
- [2] Najim Dehak, Patrick J Kenny, R´ eda Dehak, Pierre Dumouchel, and Pierre Ouellet, 'Front-end factor analysis for speaker verification,' IEEE Transactions on Audio, Speech, and Language Processing , vol. 19, no. 4, pp. 788-798, 2010.
|
| 173 |
+
- [3] Sergey Ioffe, 'Probabilistic linear discriminant analysis,' in European Conference on Computer Vision . Springer, 2006, pp. 531-542.
|
| 174 |
+
- [4] Ehsan Variani, Xin Lei, Erik McDermott, Ignacio Lopez Moreno, and Javier Gonzalez-Dominguez, 'Deep neural networks for small footprint text-dependent speaker verification,' in 2014 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP) . IEEE, 2014, pp. 4052-4056.
|
| 175 |
+
- [5] David Snyder, Daniel Garcia-Romero, Daniel Povey, and Sanjeev Khudanpur, 'Deep neural network embeddings for textindependent speaker verification.,' in Interspeech , 2017.
|
| 176 |
+
- [6] David Snyder, Daniel Garcia-Romero, Gregory Sell, Daniel Povey, and Sanjeev Khudanpur, 'X-vectors: Robust dnn embeddings for speaker recognition,' in 2018 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP) . IEEE, 2018, pp. 5329-5333.
|
| 177 |
+
- [7] Desh Raj, David Snyder, Daniel Povey, and Sanjeev Khudanpur, 'Probing the information encoded in x-vectors,' in 2019 IEEE Automatic Speech Recognition and Understanding Workshop (ASRU) . IEEE, 2019, pp. 726-733.
|
| 178 |
+
- [8] Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun, 'Deep residual learning for image recognition,' in Proceedings of the IEEE conference on computer vision and pattern recognition , 2016, pp. 770-778.
|
| 179 |
+
- [9] Chao Li, Xiaokong Ma, Bing Jiang, Xiangang Li, Xuewei Zhang, Xiao Liu, Ying Cao, Ajay Kannan, and Zhenyao Zhu, 'Deep speaker: an end-to-end neural speaker embedding system,' arXiv preprint arXiv:1705.02304 , vol. 650, 2017.
|
| 180 |
+
- [10] Joon Son Chung, Jaesung Huh, Seongkyu Mun, Minjae Lee, Hee Soo Heo, Soyeon Choe, Chiheon Ham, Sunghwan Jung, Bong-Jin Lee, and Icksang Han, 'In defence of metric learning for speaker recognition,' in Interspeech , 2020.
|
| 181 |
+
- [11] Weiyang Liu, Yandong Wen, Zhiding Yu, Ming Li, Bhiksha Raj, and Le Song, 'Sphereface: Deep hypersphere embedding for face recognition,' in Proceedings of the IEEE conference on computer vision and pattern recognition , 2017, pp. 212220.
|
| 182 |
+
- [12] Feng Wang, Jian Cheng, Weiyang Liu, and Haijun Liu, 'Additive margin softmax for face verification,' IEEE Signal Processing Letters , vol. 25, no. 7, pp. 926-930, 2018.
|
| 183 |
+
- [13] Li Wan, Quan Wang, Alan Papir, and Ignacio Lopez Moreno, 'Generalized end-to-end loss for speaker verification,' in 2018 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP) . IEEE, 2018, pp. 4879-4883.
|
| 184 |
+
- [14] Koji Okabe, Takafumi Koshinaka, and Koichi Shinoda, 'Attentive statistics pooling for deep speaker embedding,' in Interspeech , 2018.
|
| 185 |
+
- [15] Yingke Zhu, Tom Ko, David Snyder, Brian Mak, and Daniel Povey, 'Self-attentive speaker embeddings for textindependent speaker verification.,' in Interspeech , 2018.
|
| 186 |
+
- [16] A. Nagrani, J. S. Chung, and A. Zisserman, 'Voxceleb: a largescale speaker identification dataset,' in Interspeech , 2017.
|
| 187 |
+
- [17] J. S. Chung, A. Nagrani, and A. Zisserman, 'Voxceleb2: Deep speaker recognition,' in Interspeech , 2018.
|
| 188 |
+
- [18] Yue Fan, JW Kang, LT Li, KC Li, HL Chen, ST Cheng, PY Zhang, ZY Zhou, YQ Cai, and Dong Wang, 'Cn-celeb: a challenging chinese speaker recognition dataset,' in 2020 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP) . IEEE, 2020, pp. 7604-7608.
|
| 189 |
+
- [19] Lantian Li, Ruiqi Liu, Jiawen Kang, Yue Fan, Hao Cui, Yunqi Cai, Ravichander Vipperla, Thomas Fang Zheng, and Dong Wang, 'Cn-celeb: multi-genre speaker recognition,' arXiv preprint arXiv:2012.12468 , 2020.
|
| 190 |
+
- [20] Hao Wang, Yitong Wang, Zheng Zhou, Xing Ji, Dihong Gong, Jingchao Zhou, Zhifeng Li, and Wei Liu, 'Cosface: Large margin cosine loss for deep face recognition,' in Proceedings of the IEEE conference on computer vision and pattern recognition , 2018, pp. 5265-5274.
|
| 191 |
+
- [21] Daniel Garcia-Romero and Carol Y Espy-Wilson, 'Analysis of i-vector length normalization in speaker recognition systems,' in Interspeech , 2011.
|
| 192 |
+
- [22] Kong Aik Lee, Anthony Larcher, Chang Huai You, Bin Ma, and Haizhou Li, 'Multi-session plda scoring of i-vector for partially open-set speaker detection,' in Interspeech , 2013.
|
| 193 |
+
- [23] Padmanabhan Rajan, Anton Afanasyev, Ville Hautam¨ aki, and Tomi Kinnunen, 'From single to multiple enrollment i-vectors: Practical plda scoring variants for speaker verification,' Digital Signal Processing , vol. 31, pp. 93-101, 2014.
|
| 194 |
+
- [24] Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Lukasz Kaiser, and Illia Polosukhin, 'Attention is all you need,' in NIPS , 2017.
|
| 195 |
+
- [25] Zhouhan Lin, Minwei Feng, Cicero Nogueira dos Santos, Mo Yu, Bing Xiang, Bowen Zhou, and Yoshua Bengio, 'A structured self-attentive sentence embedding,' in ICLR , 2017.
|
| 196 |
+
- [26] David Snyder, Guoguo Chen, and Daniel Povey, 'MUSAN: A Music, Speech, and Noise Corpus,' 2015, arXiv:1510.08484v1.
|
| 197 |
+
- [27] Tom Ko, Vijayaditya Peddinti, Daniel Povey, Michael L Seltzer, and Sanjeev Khudanpur, 'A study on data augmentation of reverberant speech for robust speech recognition,' in 2017 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP) . IEEE, 2017, pp. 5220-5224.
|
| 198 |
+
- [28] Brecht Desplanques, Jenthe Thienpondt, and Kris Demuynck, 'Ecapa-tdnn: Emphasized channel attention, propagation and aggregation in tdnn based speaker verification,' in Interspeech , 2020.
|
| 199 |
+
- [29] Leslie N Smith, 'Cyclical learning rates for training neural networks,' in 2017 IEEE winter conference on applications of computer vision (WACV) . IEEE, 2017, pp. 464-472.
|
text-versions/attention-markdown/2104.09497_Attention in Attention Network for Image.md
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2104.09497 Attention In Attention Network For Image
|
| 2 |
+
|
| 3 |
+
## Attention in Attention Network for Image Super-Resolution
|
| 4 |
+
|
| 5 |
+
Haoyu Chen, Jinjin Gu, Zhi Zhang
|
| 6 |
+
|
| 7 |
+
下午
|
| 8 |
+
|
| 9 |
+
2021/11/2
|
| 10 |
+
|
| 11 |
+
11:40
|
| 12 |
+
|
| 13 |
+
teaser4.svg
|
| 14 |
+
|
| 15 |
+
Fig. 1: Performance comparison between our A 2 N and other state-of-the-art lightweight networks (blue circle) on Urban100 with a scale factor of 2.
|
| 16 |
+
|
| 17 |
+
<!-- image -->
|
| 18 |
+
|
| 19 |
+
low frequencies can even get better performance. This shows that not all attention modules have the same contribution, the use of some attention modules can even cause performance drops. Based on the above findings, we propose a novel low-consumption dynamic attention module called attention in attention (A 2 ) structure, which is divided into attention branch and non-attention branch. The attention branch is used to enhance useful information, and the non-attention branch aims to learn beneficial information that is ignored by attention modules. We propose a dynamic attention module to dynamically allocate the weights of two branches, make full use of the information of the two branches, enhance the high contribution information and suppress the redundant information. This module works in both training and inference phases. Experiments have proved that the A 2 structure is better than the traditional attention structure.
|
| 20 |
+
|
| 21 |
+
Overall, the contributions of this work are three-fold:
|
| 22 |
+
|
| 23 |
+
file:///Users/haoyu/Downloads/teaser4.svg
|
| 24 |
+
|
| 25 |
+
- 1) We quantify the effectiveness of attention layers across different stages in neural networks and propose a valid strategy for pruning attention layers.
|
| 26 |
+
- 2) We propose low-consumption attention in attention (A 2 ) structure, which can produce sum-to-one attention weights for its internal branches. The weights are dynamically determined by the input features. A 2 structure greatly improves the capacity of the attention network with little parameters overhead. It can be easily applied to other methods at a very low cost, which has great potential value.
|
| 27 |
+
|
| 28 |
+
Abstract -Convolutional neural networks have allowed remarkable advances in single image super-resolution (SISR) over the last decade. Among recent advances in SISR, attention mechanisms are crucial for high performance SR models. However, attention mechanism remains unclear on why and how it works in SISR task. In this work, we attempt to quantify and visualize attention mechanisms in SISR and show that not all attention modules are equally beneficial. We then propose attention in attention network (A 2 N) for more efficient and accurate SISR. Specifically, A 2 N consists of a non-attention branch and a coupling attention branch. A dynamic attention module is proposed to generate weights for these two branches to suppress unwanted attention adjustments dynamically, where the weights could change adaptively according to the input features. This allows attention modules to specialize to beneficial examples without otherwise penalties and thus greatly improve the capacity of the attention network with few parameters overhead. Experimental results demonstrate that our final model -A 2 N could achieve superior trade-off performances comparing with state-of-the-art networks of similar sizes.
|
| 29 |
+
|
| 30 |
+
Index Terms -Image super-resolution, attention mechanism, deep learning.
|
| 31 |
+
|
| 32 |
+
## I. INTRODUCTION
|
| 33 |
+
|
| 34 |
+
I MAGE super-resolution (SR) is a low-level computer vision problem, which aims at recovering a high-resolution (HR) image from a low-resolution (LR) observation. In recent years, SR methods based on deep convolution neural networks (CNNs) have achieved significant success. Recently, advanced methods begin to aggregate attention mechanism into the SR model, e.g. , channel attention and spatial attention [12], [17], [23], [32], [38]. The introduction of attention mechanisms greatly improves the performance of these networks and some works [3], [38] argue that this improvement is due to the recalibration of the feature responses towards the most informative and important components of the inputs. We naturally raise two questions: 1) what kind of features would attention mechanisms response to? 2) is it always beneficial to enhance these features?
|
| 35 |
+
|
| 36 |
+
In this paper, we answer the first question by assessing the most valuable areas highlighted by attention. We observed that for an SR network, the attention modules in the early layers of the network tend to enhance the low-frequency bands of the features, the blocks in-between have mixed responses, and the end attention modules enhance the highfrequency components of the feature maps such as edges and textures. For the second question, the ablation experiments on the attention module reveal interesting conclusions. Only conducting attention operations at early layers brings very limited improvement, and ablating these modules that focus on
|
| 37 |
+
|
| 38 |
+
Fig. 2: Attention block heatmaps. Due to the limited space, we chose several representative blocks, each columns indicates the first, third, sixth, tenth attention block, respectively. The three rows are averaged input feature map, averaged output feature map, and the averaged attention map for each attention layer, respectively. For the feature maps, the white area in the feature map indicates zero values, the red area indicates positive values, and the blue area indicates negative values. For the attention maps, brighter colors represent a higher attention coefficient.
|
| 39 |
+
|
| 40 |
+
<!-- image -->
|
| 41 |
+
|
| 42 |
+
- 3) We propose an A 2 network (A 2 N) based on A 2 structure, which demonstrates superior performance compared to baseline networks. Indicated by local attribution map, an SR network interpretation method, A 2 network also utilizes a wider range of information for better SR results. [10].
|
| 43 |
+
|
| 44 |
+
## II. RELATED WORK
|
| 45 |
+
|
| 46 |
+
## A. Deep CNN for SR
|
| 47 |
+
|
| 48 |
+
Recently, CNN-based methods for single image superresolution (SISR) have achieved significant promotion. The network design is one of the most important parts in SR problem. Pioneer work of SRCNN [8] first introduced a shallow three-layer convolutional neural network for image SR, which shows superior performance of deep learning. After this work, the network architecture is constantly improving. By introducing residual learning to ease the training difficulty, Kim et al . proposed deeper models VDSR [15] and DRCN [16] with more than 16 layers. MADNet [18] proposes a dense lightweight for stronger multiscale feature expression. Lan et al . [19] uses novel local wider residual blocks to effectively extract the image features for SISR and proposes a cascading residual network. EDSR [20] achieves significant improvement by removing unnecessary modules (batch normalization) in residual networks. For the sake of fusing low-level and highlevel features to provide richer information and details for reconstructing, RDN [40], CARN [2], MemNet [28] and ESRGAN [33] also adopted dense connections in layer-level and block-level. Liu et al . [22] propose a novel residual feature aggregation framework to fully utilize the hierarchical features on the residual branches.
|
| 49 |
+
|
| 50 |
+
## B. Attention Mechanism
|
| 51 |
+
|
| 52 |
+
Attention mechanism in deep learning is similar to the attention mechanism of human vision. It can be viewed as a means of biasing the allocation of available computational resources towards the most informative components of a signal [11]. Attention mechanism usually contains a gating function to generate a feature mask. It has been applied to many computer vision tasks, such as image captioning [5], [35] and image classification [11], [30]. Wang et al. [31] initially proposed non-local operation for capturing longrange dependencies, it computes the response at a position as a weighted sum of the features at all positions. Hu et al. [11] focus on the channel relationship and propose a novel architectural unit, Squeeze-and-Excitation (SE) block, that adaptively recalibrates channel-wise feature responses. Woo et al. [34] provided a study on the combination of channel and spatial attention.
|
| 53 |
+
|
| 54 |
+
In recent years, several works proposed to investigate the effect of attention mechanism on low-level vision tasks. [21] first attempt to incorporate non-local operations into a recurrent neural network for image restoration. RNAN [39] proposed residual local and non-local attention blocks in the mask branch in order to obtain non-local mixed attention. Channel attention is another popular way to embed attention mechanism. RCAN [38] exploits the interdependencies among feature channels by generating different attention for each channel-wise feature. Some works utilize both channel attention and non-local attention. SAN [7] performed regionlevel non-local operations for reducing computational burden, and proposed second-order channel attention by considering second-order statistics of features.
|
| 55 |
+
|
| 56 |
+
TABLE I: The correlation coefficients between the attention map and the output feature of high-pass filters of the corresponding feature map for each attention block. Red/Blue text: maximum and minimum value. The bottom two rows are the mean and standard deviation of each attention map.
|
| 57 |
+
|
| 58 |
+
| Filter Correlation Coefficients with the Input Feature Block 1 Block 2 Block 3 Block 4 Block 5 Block 6 Block 7 Block 8 Block 9 Block 10 Laplace Operator -0.270 -0.082 0.323 0.281 0.296 0.158 -0.098 0.100 0.184 0.433 Scharr Operator -0.395 -0.122 0.398 0.355 0.412 0.206 -0.079 0.073 0.255 0.435 Sobel Operator -0.393 -0.153 0.371 0.334 0.379 0.175 -0.109 0.090 0.196 0.491 Mean of Attention Map 0.208 0.126 0.078 0.106 0.065 0.035 0.048 0.039 0.051 0.086 Std of Attention Map 0.125 0.070 0.042 0.081 0.055 0.039 0.060 0.039 0.027 0.075 |
|
| 59 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 60 |
+
|
| 61 |
+
<!-- image -->
|
| 62 |
+
|
| 63 |
+
Block 1 Block 2 Block 3 Block 4 Block 5 Block 6 Block 7 Block 8 Block 9 Block 10
|
| 64 |
+
|
| 65 |
+
Fig. 3: The correlation coefficients between the attention map and the output feature of high-pass filters of the corresponding feature map for each attention block.
|
| 66 |
+
|
| 67 |
+
## III. MOTIVATION
|
| 68 |
+
|
| 69 |
+
Given an intermediate feature map F ∈ R C × H × W , where C , H , and W are the number of channels, height, and width of the features, respectively. Attention mechanism infers an attention map function M A , where M A ( F ) ∈ R C ′ × H ′ × W ′ , the size of C ′ , H ′ and W ′ depend on the type of attention function. For example, channel attention generates a 1D ( R C × 1 × 1 ) channel-wise attention vector [11], [12], [26], [34], [38]. Spatial attention generates a 2D ( R 1 × H × W ) attention mask, [12], [26], [34]. Channel-spatial attention generates 3D ( R C × H × W ) attention map, [39], [41]. We naturally raise two questions: (1) Which part of an image tends to have a higher or lower attention coefficient? (2) Are attention mechanisms always beneficial to SR models?
|
| 70 |
+
|
| 71 |
+
## A. Attention Heatmap
|
| 72 |
+
|
| 73 |
+
Previous work [38] suggests that information in the LR space has abundant low-frequency and valuable highfrequency components, all features are treated equally without using the attention mechanism in the networks, while attention can help the network pay more attention to the highfrequency features. The high-frequency components would usually be regions, being full of edges, texture, and other details [38]. However, to our best knowledge, few works truly prove the above assumptions. To answer the first question, we conduct experiments to understand the behavior of the attention mechanism in SR. We construct a simple attentionbased model, which consists of ten attention blocks. Each attention block uses a channel- and spatial-wise attention layer so that every pixel has an individual attention coefficient. We use the sigmoid function as the gating function so that the attention coefficient can be scaled into [0 , 1] . We visualize some feature maps and attention maps in Fig. 2. TABLE I lists correlation coefficients between the attention map and the high-pass filtering results to the corresponding feature map. Note that this is not a highly accurate method to measure the exact attention response, but our intention is to quantify the relative high-pass correlation across different layers. Based on the observations from the visualized attention maps in Fig. 2 and TABLE I, we show that attentions learnt at different layers vary a lot with respect to their relative depth in the neural network. For example, the first and tenth attention blocks show opposite responses. The attention modules in the first two layers tend to enhance the low-frequency bands of the features, while the last two layers enhance the high-frequency features. The blocks in-between have mixed responses.
|
| 74 |
+
|
| 75 |
+
TABLE II: Attention layer importance measurement. The first column indicates the insertion stage of the residual attention blocks.
|
| 76 |
+
|
| 77 |
+
| Attention Block Index # Parameter PSNR All 9.2 M 28.65 None 4.4 M 28.60 { 1,2,3,4,5 } 6.8 M 28.60 { 6,7,8,9,10 } 6.8 M 28.65 { 2,4,6,8,10 } 6.8 M 28.63 |
|
| 78 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 79 |
+
|
| 80 |
+
## B. Ablating Attention
|
| 81 |
+
|
| 82 |
+
Based on the above results, we may be able to maximize the use of attention while minimizing the number of additional parameters. An intuitive idea is to preserve attention layers only at performance-critical layers. However, the above qualitative analysis is not a valid method to quantify the realistic effect of attention layers. To quantitatively measure the effectiveness of attention layers, we propose a dynamic attention framework. An attention block, regardless of its type mentioned previously in Section II-B, can be downgraded to a non-attentional block by simply removing the attention generator operation.
|
| 83 |
+
|
| 84 |
+
Fig. 4: Overview of attention in attention network (A 2 N).
|
| 85 |
+
|
| 86 |
+
<!-- image -->
|
| 87 |
+
|
| 88 |
+
We have conducted a series of experiments with certain attention layers turned off. The results are shown in TABLE II, where the first column indicates residual attention blocks that are enabled. For example, { 1, 2, 3, 4, 5 } means attention layers in the first five blocks are residual attention blocks while others are turned off and downgraded to basic residual blocks. The results lead to an interesting result: the relative block depth matters a lot in the decision of where to insert attention blocks. Enabling { 6, 7, 8, 9, 10 } blocks with attention is effectively achieving the same PSNR as tuning on every block but with much fewer parameters. This experiment further proves that spending budget on attention uniformly across the network is sub-optimal.
|
| 89 |
+
|
| 90 |
+
Fig. 5: Dynamic Attention Module.
|
| 91 |
+
|
| 92 |
+
<!-- image -->
|
| 93 |
+
|
| 94 |
+
## IV. METHOD
|
| 95 |
+
|
| 96 |
+
Previous models [12], [38], [41] with fixed attention layers have attention maps activated all the time, regardless of image content. We have shown in Sec. III-B that the effectiveness of attention layers varies at different locations in the neural network. Our motivation here is to create non-attentional shortcut branches for counter-part attention branches with mixing weights generated dynamically through an additional evaluation module using the same input features as ordinary layers.
|
| 97 |
+
|
| 98 |
+
## A. Network Architecture
|
| 99 |
+
|
| 100 |
+
As shown in Figure 4, the network architecture of our proposed method, consists of three parts: shallow feature extraction, attention in attention block deep feature extraction, and reconstruction module. The input and output image is denoted as I LR and I SR . Follow [20], we use a single convolution layer in shallow feature extraction module. We can then formulate x 0 = f ext ( I LR ) , where f ext ( · ) is a convolution layer with 3 × 3 kernel size to extract the shallow feature from the input LR image I LR , x 0 is the extracted feature map.
|
| 101 |
+
|
| 102 |
+
We construct our deep feature extractor as a chained subnetwork using A 2 B.
|
| 103 |
+
|
| 104 |
+
<!-- formula-not-decoded -->
|
| 105 |
+
|
| 106 |
+
where f A 2 B ( · ) denotes the attention in attention block. A 2 B combines non-attention branch and attention branch with dynamic weights determined by the input feature.
|
| 107 |
+
|
| 108 |
+
After deep feature extraction, we upscale the deep feature x n via the reconstruction module. In the reconstruction module, we first use nearest-neighbor interpolation for upsampling, then we use a simplified channel-spatial attention layer between two convolution layers. This simplified attention layer only uses one 1 × 1 convolution and sigmoid function to generate the attention map. We also use global connection, in which a nearest-neighbor interpolation is performed on the input I LR . The final model produces high resolution result by applying the reconstruction signal to upsampled output:
|
| 109 |
+
|
| 110 |
+
<!-- formula-not-decoded -->
|
| 111 |
+
|
| 112 |
+
f rec ( · ) is the reconstruction module, f up ( · ) is the bilinear interpolation. I SR is the final SR output.
|
| 113 |
+
|
| 114 |
+
## B. Attention in Attention Block (A 2 B)
|
| 115 |
+
|
| 116 |
+
We have discussed and dynamic contribution from different attention layers in section III-B, nevertheless, it is infeasible to manually determine the topological structure of attention modules. Inspired by the dynamic kernel [6] which use dynamic convolution to aggregate multiple parallel convolution kernels dynamically based upon their attentions, here we propose a learnable dynamic attention module to automatically drop some unimportant attention features and balance the attention branch and non-attention branch. More specifically, each dynamic attention module controls the dynamic weighted contribution from the attention and the non-attention branch using weighted summation. As depicted in Figure 5. Dynamic attention module generates weights by using the same input feature of its block as two independent branches. Formally, we have:
|
| 117 |
+
|
| 118 |
+
<!-- formula-not-decoded -->
|
| 119 |
+
|
| 120 |
+
Fig. 6: Architecture of the attention in attention block (A 2 B).
|
| 121 |
+
|
| 122 |
+
<!-- image -->
|
| 123 |
+
|
| 124 |
+
where x na n is the output of non-attention branch, and x attn n is the output of the attention branch. f 1 × 1 ( · ) donates 1 × 1 kernel convolution. π na and π attn are weights of non-attention branch and attention branch respectively, they are computed by the network according to the input feature, instead of two fixed values which are artificially set.
|
| 125 |
+
|
| 126 |
+
To compute the dynamic weights, we have:
|
| 127 |
+
|
| 128 |
+
<!-- formula-not-decoded -->
|
| 129 |
+
|
| 130 |
+
where f da ( · ) is the dynamic attention module. The dynamic attention module can be viewed in detail in Figure 9. It firstly squeezes the input x n -1 using global average pooling. The connecting layers consist of two fully connected layers with a ReLU activation. We use global pooling to increase receptive field, which allows dynamic attention module to capture features from the whole image, section V-D gives experiments to prove this. It is worth mentioning that the dynamic attention module is also used in the inference stage, once the input feature changes, the weights of the two branches also change.
|
| 131 |
+
|
| 132 |
+
As investigated in [6], constraining the dynamic weights can facilitate the learning of the dynamic attention modules. Specifically, we have the sum-to-one constraint π na n + π attn n = 1 . This sum-to-one constraint for the dynamic weights can compress the kernel space. It significantly simplifies the learning of π . Therefore, a softmax function is followed to generate normalized attention weights for the two branches.
|
| 133 |
+
|
| 134 |
+
The overall structure of our proposed attention in attention block in shown in Figure 9. ⊗ combines feature and attention map by element-wise multiplication, ⊕ computes weighted summation over two branches as Eq. 3.
|
| 135 |
+
|
| 136 |
+
## V. EXPERIMENTS
|
| 137 |
+
|
| 138 |
+
In this section, we compare our method with state-of-the-art SISR algorithms on five commonly used benchmark datasets. Besides, we conduct ablation study to validate and analyze the effectiveness of our proposed method.
|
| 139 |
+
|
| 140 |
+
Fig. 7: left The most enhanced attention maps. right The most suppressed attention maps. The weight value π attn and the block index are shown under the attention maps.
|
| 141 |
+
|
| 142 |
+
<!-- image -->
|
| 143 |
+
|
| 144 |
+
## A. Datasets and Metrics
|
| 145 |
+
|
| 146 |
+
We use DIV2K dataset [1] as our training dataset, which contains 800 training images. The LR images are obtained by the bicubic downsampling of HR images. For testing stage, we use five standard benchmark datasets: Set5 [4], Set14 [36], B100 [24], Urban100 [13] and Manga109 [25]. The SR results are evaluated by peak signal to noise ratio (PSNR) and the structural similarity index (SSIM) on the Y channel of YCbCr space.
|
| 147 |
+
|
| 148 |
+
## B. Implementation Details
|
| 149 |
+
|
| 150 |
+
Now we specify the implementation details of our proposed A 2 N. We design two variants of A 2 N, denoted as A 2 N and A 2 N-M. On the non-attention branch, we use 3 × 3 convolution for A 2 N and 1 × 1 convolution for A 2 N-M. For both variants, we set the number of A 2 B as 16. Features in A 2 B have 40 filters, except for that in the upsampling block, where C = 24. For the training process, data augmentation is performed on the 800 training images, which are randomly rotated by 90 ◦ , 180 ◦ , 270 ◦ , and flipped horizontally.
|
| 151 |
+
|
| 152 |
+
## C. Results
|
| 153 |
+
|
| 154 |
+
To demonstrate the effect of our proposed A 2 structure, we compare our two-branch A 2 structure with a one-trunk structure. The results are shown in TABLE III. If we only keep the attention branch, similar to previous models, 28.646 dB is obtained with 810K parameters. Using our A 2 structure, the performance increased by 0.05 dB with only 200K extra parameters; If we reduce the number of channels of our method to 32, A 2 performs better with 132K fewer parameters. The results also prove once again that not all attention layers are making positive contributions.
|
| 155 |
+
|
| 156 |
+
We also show results in TABLE IV to evaluate the performance of A 2 structure on the multi-branch model. Cases 1-4 are two-branch models without A 2 structure, features from two branches are fused by an addition operation. Cases 5-8 modify cases 1-4 by applying A 2 structure. As we can see, for cases 1-4, the combination of non-attention and channelspatial attention has the best performance. Therefore, we use channel-spatial attention in the attention branch. For cases 14, the non-attention branch combine with spatial attention or channel-spatial attention (cases 6 and 7) gains more than 0.05 dB by only about 7K parameters cost. Therefore, the dynamic attention module performs well when used in models without pooling or downsampling layers.
|
| 157 |
+
|
| 158 |
+
We compare our method with various SR methods of similar model sizes: SRCNN [8], FSRCNN [9], DRRN [27], VDSR
|
| 159 |
+
|
| 160 |
+
TABLE III: The effect of A 2 structure. Test on Set14 ( × 4).
|
| 161 |
+
|
| 162 |
+
| Branch Branch Fusion Performance Non-attention Attention Addition Concatenation Adaptive-Weight A 2 (1 × 1 conv) A 2 (3 × 3 conv) Parameter (K) PSNR A 2 N-non-attn-only • 208 28.515 Single branch A 2 N-attn-only (baseline) • 810 28.646 A 2 N-Addition • • • 1,040 28.651 A 2 N-Concatenation • • • 1,092 28.642 Two Branches, without A 2 A 2 N-Adaptive-Weights • • • 1,040 28.648 A 2 N-S (Fewer Channels ) • • • 678 28.651 A 2 N-M • • • 843 28.695 A 2 A 2 N • • • 1,047 28.707 |
|
| 163 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 164 |
+
|
| 165 |
+
TABLE IV: Ablation study: effect of different components. Test on Set14 ( × 4).
|
| 166 |
+
|
| 167 |
+
| Case Index 1 2 3 4 5 6 7 8 non-attention • • • • • • channel attention • • • • spatial attention • • • • channel-spatial attention • • A 2 • • • • Parameter (K) 787 1,035 1,040 791 794 1,042 1,047 798 PSNR 28.634 28.649 28.651 28.583 28.600 28.629 28,707 28.642 Gain from A 2 - - - - -0.034 -0.020 +0.056 +0.059 |
|
| 168 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 169 |
+
|
| 170 |
+
- [15], MemNet [28], IMDN [14], A 2 F-M [32], AWSRN-M
|
| 171 |
+
- [29], SRMDNF [37], CARN [2], MADNet [18] and DRCN
|
| 172 |
+
- [16]. We also selected 3 large networks for reference, ERN
|
| 173 |
+
|
| 174 |
+
[19], RCAN [38], and EDSR [20]. TABLE VIII shows quantitative comparisons for × 2, × 3, and × 4 SR. Note that we only compare models which have a similar number of parameters to our models in this table. Our A 2 N can achieve comparable or better results than state-of-the-art methods for all scaling factors. In particular, A 2 N-M, which has about 200K fewer parameters than A 2 F-M and AWSRN-M, achieves better results than these models on most datasets. For Manga109 ( × 3 ), the PSNR of A 2 N-M is 0.15 dB higher than the PSNR of AWSRN-M. For more difficult scenarios, such as scales 3 and 4, the advantages of our method are more obvious. The performance on more challenging datasets such as Urban100 and Manga109 is more than 0.2 dB higher than that of IMDN.
|
| 175 |
+
|
| 176 |
+
It should be noted that our core contribution is to dynamically adjust attention to make it play a greater potential, not in terms of lightweight. Therefore, we have not made improvements in terms of lightweight. And in order to better prove the effectiveness of our Dynamic Attention Module, we also did not make a special design for the attention branch, but used the simplest channel-spatial attention. We prove the effectiveness of the Dynamic Attention Module in sections 1 and 2 below, and prove its effect on large models in section 3.
|
| 177 |
+
|
| 178 |
+
TABLE V: Results of different methods used in non-attention branch. A 2 N-attn-only: no non-attention branch. A 2 N-no-op: pass through in non-attention branch. Test on Set14 ( × 4).
|
| 179 |
+
|
| 180 |
+
| Method Operation Parameter PSNR A 2 N-attn-only - 810K 28.646 A 2 N-no-op - 817K 28.660 A 2 N-M 1 × 1 Conv 843K 28.695 A 2 N 3 × 3 Conv 1047K 28.707 |
|
| 181 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 182 |
+
|
| 183 |
+
Figure 7 shows the visual comparison for upscaling factor × 4. We can see that our method achieves better performance than others, it can recover high frequency details more accurately. For image 'zebra', our method can restore zebra stripes accurately. For the details of the buildings, in image '78004', the windows are restored more clearly and accurately. For image 'img092', only our method can restore the direction of the fringe correctly.
|
| 184 |
+
|
| 185 |
+
## D. Discussion
|
| 186 |
+
|
| 187 |
+
We use the weight prediction in the dynamic attention layer to sample the enhanced and suppressed attention signals. Figure 7 shows the two attention maps with the top two weights and the two attention maps with the smallest weights. For each row, the attention maps selected by the highest and second-highest weights are listed on the left, while the right depicts the two attention maps with the smallest weights. As we can see, for attention maps with high weights, the edge and texture components of the feature map can be accurately located, while the attention maps with lower weights can not found it accurately. These results demonstrate the effectiveness of the dynamic attention module, which can automatically determine the weights of the two branches based on the input features.
|
| 188 |
+
|
| 189 |
+
Fig. 8: Results of the LAM for SR network interpretation. The LAM maps represent the importance of each pixel in the input LR image w.r.t. the SR of the patch marked with a red box. We illustrate the area of contribution in red color.
|
| 190 |
+
|
| 191 |
+
<!-- image -->
|
| 192 |
+
|
| 193 |
+
Comparison with Other Fusion Methods. Most SR models fuse features by addition [17] or concatenation [14], [41]. Some methods [16], [29], [32] give adaptive weights to each feature, which means the independent weights will be learned automatically when training the model. To demonstrate the effectiveness of our method, we compare our dynamic attention module with other mainstream feature fusion methods: addition, concatenation, and adaptive weights. TABLE III shows that within a similar parameter number, A 2 structure has a considerable improvement over other fusion methods. If we reduce the channel number to 32, even with about 400K fewer parameters, A 2 Ncan still obtain a better result than other fusion Methods. It demonstrates that the dynamic attention module is a better feature fusion method than other methods.
|
| 194 |
+
|
| 195 |
+
TABLE VI: Test on 150 images which are proposed from LAM [10]. The DI reflects the range of involved pixels. A higher DI represents a wider range of attention.
|
| 196 |
+
|
| 197 |
+
| Model DI PSNR FSRCNN 0.797 20.30 CARN 1.807 21.27 IMDN 14.643 21.23 A 2 F 12.58 21.43 A 2 N-attn-only 2.54 21.33 A 2 N-non-attn-only 1.56 20.99 A 2 N-Addition 2.75 21.37 A 2 N-Concatenation 2.70 21.38 A 2 N-AdaptiveWeights 2.43 21.33 A 2 N 14.77 21.44 |
|
| 198 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 199 |
+
|
| 200 |
+
Results of Local Attribution Maps. The proposed method can make good use of the information in the input LR image. Recently, Gu et al [10] propose a novel attribution approach called local attribution map (LAM), which performs attribution analysis of SR networks and aims at finding the input pixels that strongly influence the SR results. The results are summarised to diffusion index (DI), an evaluation metric that measures the ability of extraction and utilization of the information in the LR image. A larger DI indicates more pixels are involved. LAM highlights the pixels which have the greatest impact on the SR results. For the same local patch, if the LAM map involves more pixels or a larger range, it can be considered that the SR network has extracted and used the information from more pixels. We follow the suggested setting, and in TABLE VI we show the PSNR and DI performances for some SR networks test on these images. Among all the models, A 2 N has the highest DI and PSNR. We can notice that using the dynamic attention module makes DI much higher than other models. Fig. 8 shows the LAM results, which visualize the importance of pixels. The LAM results indicate that CARN and channel-spatial attention model only utilize very limited information, Our A 2 N can utilize a wider range of information for better SR results for models without downsampling.
|
| 201 |
+
|
| 202 |
+
## E. Ablation Study
|
| 203 |
+
|
| 204 |
+
Choice of channel width in Non-attention Branch. In A 2 N, we use 3 × 3 convolution to extract features, in A 2 NM, 1 × 1 convolution is used. We compare the results of 1 × 1 convolution, 3 × 3 convolution, and pass-through.
|
| 205 |
+
|
| 206 |
+
Fig. 9: Visual comparison for upscaling factor × 4.
|
| 207 |
+
|
| 208 |
+
<!-- image -->
|
| 209 |
+
|
| 210 |
+
Fig. 10: Results of base model and our A 2 structure on different model size. Our method can get higher PSNR under the similar parameter number.
|
| 211 |
+
|
| 212 |
+
<!-- image -->
|
| 213 |
+
|
| 214 |
+
From our experimental results shown in TABLE V, even without any operations, A 2 structure is still better than the onetrunk attention structure. Compare with the one-trunk structure and 1 × 1 convolution, 1 × 1 convolution gain 0.049 dB
|
| 215 |
+
|
| 216 |
+
TABLE VII: Results of base model and our A 2 structure on different model size. The baseline model denotes models with only one attention trunk. Test on Set14 ( × 4).
|
| 217 |
+
|
| 218 |
+
| #channel #block Model PSNR 40 16 baseline 28.646 A 2 N-M 28.695 (+0.049) A 2 N 28.707 (+0.061) 64 32 baseline 28.728 (+0.082) A 2 N-M 28.751 (+0.105) A 2 N 28.769 (+0.123) 64 64 baseline 28.782 (+0.136) A 2 N-M 28.797 (+0.151) A 2 N 28.815 (+0.169) |
|
| 219 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 220 |
+
|
| 221 |
+
improvement with only 33K parameters. It achieves a great trade-off between parameter number and performance. The results of w/o operation and 1 × 1 convolution also prove that convolution in non-attention branch truly contributes to the network, it can extract the effective features that the attention branch cannot extract, so that it can complement the features of attention branch. These comparisons firmly demonstrate the effectiveness of A 2 structure.
|
| 222 |
+
|
| 223 |
+
Results on Large Model. We conduct experiments on three different sizes of models to analyse the effectiveness of our A 2 structure. We chose the model which only keeps the attention branch to compare with A 2 N. We change the number of channels and A 2 B and get three sizes of models: large, medium, and small. From our experimental results shown in TABLE VII and Fig. 10, smaller models with A 2 structure will gain more bonus than larger models, since for large models the PSNR tends to be saturated. A 2 structure could also conspicuously improve their performance for large models. Note that the cost of A 2 structure is almost negligible, these improvements are outstanding. From Fig. 10, our method can always get higher PSNR under a similar parameter number.
|
| 224 |
+
|
| 225 |
+
## VI. CONCLUSIONS
|
| 226 |
+
|
| 227 |
+
In this work, we show that not all attention modules are equally beneficial, the use of some attention modules can even cause a performance drop. The findings can help later people better use and understand attention in image super-resolution tasks. We than propose attention in attention network (A 2 N) and building block A 2 B for image SR. A 2 structure allows for more aggressive pixel-wise attention adjustments and could dynamically adjust the contribution of attention layers, allowing them to be penalized less frequently. Experiments have demonstrated that our method could achieve superior performances compared with state-of-the-art SR models of similar sizes.
|
| 228 |
+
|
| 229 |
+
## REFERENCES
|
| 230 |
+
|
| 231 |
+
- [1] Eirikur Agustsson and Radu Timofte. Ntire 2017 challenge on single image super-resolution: Dataset and study. In The IEEE Conference on Computer Vision and Pattern Recognition (CVPR) Workshops , July 2017.
|
| 232 |
+
- [2] Namhyuk Ahn, Byungkon Kang, and Kyung-Ah Sohn. Fast, accurate, and lightweight super-resolution with cascading residual network. In Proceedings of the European Conference on Computer Vision (ECCV) , pages 252-268, 2018.
|
| 233 |
+
- [3] Parichehr Behjati, Pau Rodriguez, Armin Mehri, Isabelle Hupont, Carles Fern´ andez Tena, and Jordi Gonzalez. Hierarchical residual attention network for single image super-resolution. arXiv preprint arXiv:2012.04578 , 2020.
|
| 234 |
+
- [4] Marco Bevilacqua, Aline Roumy, Christine Guillemot, and Marie Line Alberi-Morel. Low-complexity single-image super-resolution based on nonnegative neighbor embedding. 2012.
|
| 235 |
+
- [5] Long Chen, Hanwang Zhang, Jun Xiao, Liqiang Nie, Jian Shao, Wei Liu, and Tat-Seng Chua. Sca-cnn: Spatial and channel-wise attention in convolutional networks for image captioning. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 5659-5667, 2017.
|
| 236 |
+
- [6] Yinpeng Chen, Xiyang Dai, Mengchen Liu, Dongdong Chen, Lu Yuan, and Zicheng Liu. Dynamic convolution: Attention over convolution kernels. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition , pages 11030-11039, 2020.
|
| 237 |
+
- [7] Tao Dai, Jianrui Cai, Yongbing Zhang, Shu-Tao Xia, and Lei Zhang. Second-order attention network for single image super-resolution. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 11065-11074, 2019.
|
| 238 |
+
- [8] Chao Dong, Chen Change Loy, Kaiming He, and Xiaoou Tang. Image super-resolution using deep convolutional networks. IEEE transactions on pattern analysis and machine intelligence , 38(2):295-307, 2015.
|
| 239 |
+
- [9] Chao Dong, Chen Change Loy, and Xiaoou Tang. Accelerating the super-resolution convolutional neural network. In European conference on computer vision , pages 391-407. Springer, 2016.
|
| 240 |
+
- [10] Jinjin Gu and Chao Dong. Interpreting super-resolution networks with local attribution maps. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition , 2021.
|
| 241 |
+
- [11] Jie Hu, Li Shen, and Gang Sun. Squeeze-and-excitation networks. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 7132-7141, 2018.
|
| 242 |
+
- [12] Yanting Hu, Jie Li, Yuanfei Huang, and Xinbo Gao. Channel-wise and spatial feature modulation network for single image super-resolution. IEEE Transactions on Circuits and Systems for Video Technology , 30(11):3911-3927, 2019.
|
| 243 |
+
- [13] Jia-Bin Huang, Abhishek Singh, and Narendra Ahuja. Single image super-resolution from transformed self-exemplars. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 5197-5206, 2015.
|
| 244 |
+
- [14] Zheng Hui, Xinbo Gao, Yunchu Yang, and Xiumei Wang. Lightweight image super-resolution with information multi-distillation network. In Proceedings of the 27th ACM International Conference on Multimedia , pages 2024-2032, 2019.
|
| 245 |
+
- [15] Jiwon Kim, Jung Kwon Lee, and Kyoung Mu Lee. Accurate image super-resolution using very deep convolutional networks. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 1646-1654, 2016.
|
| 246 |
+
- [16] Jiwon Kim, Jung Kwon Lee, and Kyoung Mu Lee. Deeply-recursive convolutional network for image super-resolution. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 1637-1645, 2016.
|
| 247 |
+
- [17] Jun-Hyuk Kim, Jun-Ho Choi, Manri Cheon, and Jong-Seok Lee. Ram: Residual attention module for single image super-resolution. arXiv preprint arXiv:1811.12043 , 2, 2018.
|
| 248 |
+
- [18] Rushi Lan, Long Sun, Zhenbing Liu, Huimin Lu, Cheng Pang, and Xiaonan Luo. Madnet: A fast and lightweight network for single-image super resolution. IEEE transactions on cybernetics , 51(3):1443-1453, 2020.
|
| 249 |
+
- [19] Rushi Lan, Long Sun, Zhenbing Liu, Huimin Lu, Zhixun Su, Cheng Pang, and Xiaonan Luo. Cascading and enhanced residual networks for accurate single-image super-resolution. IEEE Transactions on Cybernetics , 51(1):115-125, 2021.
|
| 250 |
+
- [20] Bee Lim, Sanghyun Son, Heewon Kim, Seungjun Nah, and Kyoung Mu Lee. Enhanced deep residual networks for single image superresolution. In Proceedings of the IEEE conference on computer vision and pattern recognition workshops , pages 136-144, 2017.
|
| 251 |
+
- [21] Ding Liu, Bihan Wen, Yuchen Fan, Chen Change Loy, and Thomas S Huang. Non-local recurrent network for image restoration. In Advances in Neural Information Processing Systems , pages 1673-1682, 2018.
|
| 252 |
+
- [22] Jie Liu, Wenjie Zhang, Yuting Tang, Jie Tang, and Gangshan Wu. Residual feature aggregation network for image super-resolution. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition , pages 2359-2368, 2020.
|
| 253 |
+
- [23] Hailong Ma, Xiangxiang Chu, and Bo Zhang. Accurate and efficient single image super-resolution with matrix channel attention network. In Proceedings of the Asian Conference on Computer Vision , 2020.
|
| 254 |
+
- [24] David Martin, Charless Fowlkes, Doron Tal, and Jitendra Malik. A database of human segmented natural images and its application to evaluating segmentation algorithms and measuring ecological statistics. In Proceedings Eighth IEEE International Conference on Computer Vision. ICCV 2001 , volume 2, pages 416-423. IEEE, 2001.
|
| 255 |
+
- [25] Yusuke Matsui, Kota Ito, Yuji Aramaki, Azuma Fujimoto, Toru Ogawa, Toshihiko Yamasaki, and Kiyoharu Aizawa. Sketch-based manga retrieval using manga109 dataset. Multimedia Tools and Applications , 76(20):21811-21838, 2017.
|
| 256 |
+
- [26] Jongchan Park, Sanghyun Woo, Joon-Young Lee, and In So Kweon. Bam: Bottleneck attention module. arXiv preprint arXiv:1807.06514 , 2018.
|
| 257 |
+
- [27] Ying Tai, Jian Yang, and Xiaoming Liu. Image super-resolution via deep recursive residual network. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 3147-3155, 2017.
|
| 258 |
+
- [28] Ying Tai, Jian Yang, Xiaoming Liu, and Chunyan Xu. Memnet: A persistent memory network for image restoration. In Proceedings of the IEEE international conference on computer vision , pages 4539-4547, 2017.
|
| 259 |
+
- [29] Chaofeng Wang, Zheng Li, and Jun Shi. Lightweight image superresolution with adaptive weighted learning network. arXiv preprint arXiv:1904.02358 , 2019.
|
| 260 |
+
- [30] Fei Wang, Mengqing Jiang, Chen Qian, Shuo Yang, Cheng Li, Honggang Zhang, Xiaogang Wang, and Xiaoou Tang. Residual attention network for image classification. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 3156-3164, 2017.
|
| 261 |
+
|
| 262 |
+
TABLE VIII: Quantitative results (PSNR/SSIM) of state-of-the-art SR methods for all upscaling factors × 2, × 3, and × 4. Red/Blue text: best/second-best among all methods (excluding models with parameters greater than 2M).
|
| 263 |
+
|
| 264 |
+
| Scale Size Scope Model Params MutiAdds Set5 Set14 B100 Urban100 Manga109 FSRCANN [9] 0.01M 6G 37.00/0.9558 32.63/0.9088 31.53/0.8920 29.88/0.9020 36.67/0.9710 SRCNN [8] 0.06M 52.7G 36.66/0.9542 32.45/0.9067 31.36/0.8879 29.50/0.8946 35.60/0.9663 DRRN [27] 0.3M 6797G 37.74/0.9591 33.23/0.9136 32.05/0.8973 31.23/0.9188 37.92/0.9760 VDSR [15] 0.7M 612.6G 37.53/0.9587 33.03/0.9124 31.90/0.8960 30.76/0.9140 37.22/0.9729 MemNet [28] 0.7M 2662.4G 37.78/0.9597 33.28/0.9142 32.08/0.8978 31.31/0.9195 - IMDN [14] 0.7M 158.8G 38.00/0.9605 33.63/0.9177 32.19/0.8996 32.17/0.9283 38.88/0.9774 A2N-M (Ours) 0.8M 200.3G 38.06/0.9601 33.73/0.9190 32.22/0.8997 32.34/0.9300 38.80/0.9765 MADNet- L F [18] 0.9M 187.1G 37.85/0.9600 33.39/0.9161 32.05/0.8981 31.59/0.9234 - < 1M A2F-M [32] 1M 224.2G 38.04/0.9607 33.67/0.9184 32.18/0.8996 32.27/0.9294 38.87/0.9774 A2N (Ours) 1M 247.5G 38.06/0.9608 33.75/0.9194 32.22/0.9002 32.43/0.9311 38.87/0.9769 AWSRN-M [29] 1M 244.1G 38.04/0.9605 33.66/0.9181 32.21/0.9000 32.23/0.9294 38.66/0.9772 SRMDNF [37] 1.5M 347.7G 37.79/0.9600 33.32/0.9150 32.05/0.8980 31.33/0.9200 - CARN [2] 1.6M 222.8G 37.76/0.9590 33.52/0.9166 32.09/0.8978 31.92/0.9256 - < 2M DRCN [16] 1.8M 17974G 37.63/0.9588 33.04/0.9118 31.85/0.8942 30.75/0.9133 37.63/0.9723 ERN [19] 9.5M - 38.18/0.9610 33.88/0.9195 32.30/0.9011 32.66/0.9332 - RCAN [38] 16M - 38.27/0.9614 34.12/0.9216 32.41/0.9027 33.34/0.9384 39.44/0.9786 2 > 9M EDSR [20] 40.7M - 38.11/0.9602 33.92/0.9195 32.32/0.9013 32.93/0.9351 39.10/0.9773 FSRCANN [9] 0.01M 6G 37.00/0.9558 32.63/0.9088 31.53/0.8920 29.88/0.9020 36.67/0.9710 SRCNN [8] 0.06M 52.7G 32.75/0.9090 29.28/0.8209 28.41/0.7863 26.24/0.7989 30.59/0.9107 DRRN [27] 0.3M 6797G 34.03/0.9244 29.96/0.8349 28.95/0.8004 27.53/0.8378 32.74/0.9390 VDSR [15] 0.7M 612.6G 33.66/0.9213 29.77/0.8314 28.82/0.7976 27.14/0.8279 32.01/0.9310 MemNet [28] 0.7M 2662.4G 34.09/0.9248 30.00/0.8350 28.96/0.8001 27.56/0.8376 - IMDN [14] 0.7M 71.5G 34.36/0.9270 30.32/0.8417 29.09/0.8046 28.17/0.8519 33.61/0.9445 A2N-M (Ours) 0.8M 96.6G 34.50/0.9279 30.41/0.8438 29.13/0.8058 28.35/0.8563 33.79/0.9458 < 1M MADNet- L F [18] 0.9M 88.4G 34.14/0.9251 30.20/0.8395 28.98/0.8023 27.78/0.8439 - A2F-M [32] 1M 100G 34.50/0.9278 30.39/0.8427 29.11/0.8054 28.28/0.8546 33.66/0.9453 A2N (Ours) 1M 117.5G 34.47/0.9279 30.44/0.8437 29.14/0.8059 28.41/0.8570 33.78/0.9458 AWSRN-M [29] 1.1M 116.6G 34.42/0.9275 30.32/0.8419 29.13/0.8059 28.26/0.8545 33.64/0.9450 SRMDNF [37] 1.5M 156.3G 34.12/0.9250 30.04/0.8370 28.97/0.8030 27.57/0.8400 - CARN [2] 1.6M 118.8G 34.29/0.9255 30.29/0.8407 29.06/0.8034 28.06/0.8493 - < 2M DRCN [16] 1.8M 17974G 33.82/0.9226 29.76/0.8311 28.80/0.7963 27.15/0.8276 32.31/0.9328 ERN [19] 9.5M - 34.62/0.9285 30.51/0.8450 29.21/0.8080 28.61/0.8614 - RCAN [38] 16M - 34.74/0.9299 30.65/0.8482 29.32/0.8111 29.09/0.8702 34.44/0.9499 3 > 9M EDSR [20] 43.1M - 34.65/0.9280 30.52/0.8462 29.25/0.8093 28.80/0.8653 34.17/0.9476 FSRCANN [9] 0.01M 4.6G 30.71/0.8657 27.59/0.7535 26.98/0.7150 24.62/0.7280 27.90/0.8517 SRCNN [8] 0.06M 52.7G 30.48/0.8628 27.49/0.7503 26.90/0.7101 24.52/0.7221 27.66/0.8505 DRRN [27] 0.3M 6797G 31.68/0.8888 28.21/0.7720 27.38/0.7284 25.44/0.7638 29.46/0.8960 VDSR [15] 0.7M 612.6G 31.35/0.8838 28.01/0.7674 27.29/0.7251 25.18/0.7524 28.83/0.8809 MemNet [28] 0.7M 2662.4G 31.74/0.8893 28.26/0.7723 27.40/0.7281 25.50/0.7630 - IMDN [14] 0.7M 40.9G 32.21/0.8948 28.58/0.7811 27.56/0.7353 26.04/0.7838 30.45/0.9075 < 1M A2N-M (Ours) 0.8M 60.6G 32.27/0.8963 28.70/0.7842 27.61/0.7376 26.28/0.7919 30.59/0.9103 MADNet- L F [18] 1M 54.1G 32.01/0.8925 28.45/0.7781 27.47/0.7327 25.77/0.7751 - A2F-M [32] 1M 56.7G 32.28/0.8955 28.62/0.7828 27.58/0.7364 26.17/0.7892 30.57/0.9100 A2N (Ours) 1M 72.4G 32.30/0.8966 28.71/0.7842 27.61/0.7374 26.27/0.7920 30.67/0.9110 AWSRN-M [29] 1.3M 72G 32.21/0.8954 28.65/0.7832 27.60/0.7368 26.15/0.7884 30.56/0.9093 SRMDNF [37] 1.6M 89.3G 31.96/0.8930 28.35/0.7770 27.49/0.7340 25.68/0.7730 - CARN [2] 1.6M 90.9G 32.13/0.8937 28.60/0.7806 27.58/0.7349 26.07/0.7837 - < 2M DRCN [16] 1.8M 17974G 31.53/0.8854 28.02/0.7670 27.23/0.7233 25.14/0.7510 28.98/0.8816 ERN [19] 9.5M - 32.39/0.8975 28.75/0.7853 27.70/0.7398 26.43/0.7966 - RCAN [38] 16M - 32.63/0.9002 28.87/0.7889 27.77/0.7436 26.82/0.8087 31.22/0.9173 4 > 9M EDSR [20] 43.7M - 32.46/0.8968 28.80/0.7876 27.71/0.7420 26.64/0.8033 31.02/0.9148 |
|
| 265 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 266 |
+
|
| 267 |
+
- [31] Xiaolong Wang, Ross Girshick, Abhinav Gupta, and Kaiming He. Nonlocal neural networks. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 7794-7803, 2018.
|
| 268 |
+
- [32] Xuehui Wang, Qing Wang, Yuzhi Zhao, Junchi Yan, Lei Fan, and Long Chen. Lightweight single-image super-resolution network with attentive auxiliary feature learning. In Proceedings of the Asian Conference on Computer Vision , 2020.
|
| 269 |
+
- [33] Xintao Wang, Ke Yu, Shixiang Wu, Jinjin Gu, Yihao Liu, Chao Dong, Yu Qiao, and Chen Change Loy. Esrgan: Enhanced super-resolution generative adversarial networks. In Proceedings of the European Conference on Computer Vision (ECCV) , pages 0-0, 2018.
|
| 270 |
+
- [34] Sanghyun Woo, Jongchan Park, Joon-Young Lee, and In So Kweon. Cbam: Convolutional block attention module. In Proceedings of the European conference on computer vision (ECCV) , pages 3-19, 2018.
|
| 271 |
+
- [35] Kelvin Xu, Jimmy Ba, Ryan Kiros, Kyunghyun Cho, Aaron Courville, Ruslan Salakhudinov, Rich Zemel, and Yoshua Bengio. Show, attend and tell: Neural image caption generation with visual attention. In International conference on machine learning , pages 2048-2057. PMLR, 2015.
|
| 272 |
+
- [36] Jianchao Yang, John Wright, Thomas S Huang, and Yi Ma. Image super-resolution via sparse representation. IEEE transactions on image processing , 19(11):2861-2873, 2010.
|
| 273 |
+
- [37] Kai Zhang, Wangmeng Zuo, and Lei Zhang. Learning a single convolutional super-resolution network for multiple degradations. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , pages 3262-3271, 2018.
|
| 274 |
+
- [38] Yulun Zhang, Kunpeng Li, Kai Li, Lichen Wang, Bineng Zhong, and Yun Fu. Image super-resolution using very deep residual channel attention networks. In Proceedings of the European Conference on Computer Vision (ECCV) , pages 286-301, 2018.
|
| 275 |
+
- [39] Y Zhang, K Li, K Li, B Zhong, and Y Fu. Residual non-local attention networks for image restoration. In International Conference on Learning Representations , 2019.
|
| 276 |
+
- [40] Yulun Zhang, Yapeng Tian, Yu Kong, Bineng Zhong, and Yun Fu. Residual dense network for image super-resolution. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 2472-2481, 2018.
|
| 277 |
+
- [41] Hengyuan Zhao, Xiangtao Kong, Jingwen He, Yu Qiao, and Chao Dong. Efficient image super-resolution using pixel attention. arXiv preprint arXiv:2010.01073 , 2020.
|
| 278 |
+
|
| 279 |
+
## VII. BIOGRAPHY SECTION
|
| 280 |
+
|
| 281 |
+
Haoyu Chen received his B Eng. degree in computer science and engineering from the Chinese University of Hong Kong, Shenzhen, in 2021. His research interests include computer vision, image processing and image generation.
|
| 282 |
+
|
| 283 |
+
<!-- image -->
|
| 284 |
+
|
| 285 |
+
Jinjin Gu received his B.Eng. degree in computer science and engineering from the Chinese University of Hong Kong, Shenzhen, in 2020. He is currently pursuing a Ph.D. degree in Engineering and IT with the University of Sydney. His research interests include computer vision, image processing, interpretability of deep learning algorithms and the applications of machine learning in industrial.
|
| 286 |
+
|
| 287 |
+
<!-- image -->
|
| 288 |
+
|
| 289 |
+
Zhi Zhang received his B.S. degree in electronic and information technology from Beijing Jiaotong University, Beijing, China, in 2012, and the M.S. and Ph.D. degrees in computer engineering from the University of Missouri-Columbia, Columbia, MO, USA, in 2014 and 2018, respectively. He joined Amazon AI in 2018 in pursuing highly efficient deep learning frameworks and toolkits. His current research interests include object detection, segmentation, and deep network acceleration.
|
text-versions/attention-markdown/2105.14103_An Attention Free Transformer.md
ADDED
|
@@ -0,0 +1,448 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2105.14103 An Attention Free Transformer
|
| 2 |
+
|
| 3 |
+
## An Attention Free Transformer
|
| 4 |
+
|
| 5 |
+
Shuangfei Zhai Apple Inc. szhai@apple.com Walter Talbott Apple Inc. wtalbott@apple.com
|
| 6 |
+
|
| 7 |
+
Chen Huang Apple Inc. chen-huang@apple.com Hanlin Goh Apple Inc. hanlin@apple.com
|
| 8 |
+
|
| 9 |
+
## Josh Susskind
|
| 10 |
+
|
| 11 |
+
Nitish Srivastava Apple Inc. nitish\_srivastava@apple.com
|
| 12 |
+
|
| 13 |
+
Ruixiang Zhang ∗ Apple Inc., MILA ruixiang\_zhang2@apple.com
|
| 14 |
+
|
| 15 |
+
Apple Inc. jsusskind@apple.com
|
| 16 |
+
|
| 17 |
+
## Abstract
|
| 18 |
+
|
| 19 |
+
We introduce Attention Free Transformer (AFT), an efficient variant of Transformers [1] that eliminates the need for dot product self attention. In an AFT layer, the key and value are first combined with a set of learned position biases, the result of which is multiplied with the query in an element-wise fashion. This new operation has a memory complexity linear w.r.t. both the context size and the dimension of features, making it compatible to both large input and model sizes. We also introduce AFT-local and AFT-conv, two model variants that take advantage of the idea of locality and spatial weight sharing while maintaining global connectivity. We conduct extensive experiments on two autoregressive modeling tasks (CIFAR10 and Enwik8) as well as an image recognition task (ImageNet-1K classification). We show that AFT demonstrates competitive performance on all the benchmarks, while providing excellent efficiency at the same time.
|
| 20 |
+
|
| 21 |
+
## 1 Introduction
|
| 22 |
+
|
| 23 |
+
Self attention mechanisms, represented by Transformers [1], have driven the advancement of various machine learning problems, including language understanding [2, 3] and computer vision applications [4-6]. Different from classic model architectures such as Convolutional Neural Nets (CNNs) or Recurrent Neural Nets (RNNs), Transformers enable direct interaction between every pair of elements within a sequence, which makes them especially powerful at capturing long term dependencies.
|
| 24 |
+
|
| 25 |
+
However, Transformers require high computational costs. The cause of this challenge is the need to perform attention operations that have quadratic time and space complexity w.r.t. the context size. This makes it difficult for Transformers to scale to inputs with large context sizes. A number of recent works have been dedicated to addressing the scalability issue of Transformers [7-13]. The common idea here is to approximate the full attention operation, with the techniques ranging from sparsity, locality sensitive hashing, low rank decomposition, kernel approximation, etc..
|
| 26 |
+
|
| 27 |
+
In this paper, we propose a computational module that does not use or approximate the standard dot product attention. We hence name our model the attention free transformer (AFT). Similar to dot product attention, AFT is composed of the interaction of three quantities, namely the query, key and value ( Q,K,V ). The difference is that, in AFT the key and value (context) are first combined
|
| 28 |
+
|
| 29 |
+
∗ work done while interning at Apple.
|
| 30 |
+
|
| 31 |
+
Figure 1: Left: average relative 2d attention maps from a pretrained 12 layer 6 head ViT [5]. Right: relative position biases learned by a AFT-conv with comparable size. Each row represents a layer (with layer index ranging from {0, 2, 4, 6, 8, 10}); Each column represents a head. See the Appendix for a more complete version.
|
| 32 |
+
|
| 33 |
+
<!-- image -->
|
| 34 |
+
|
| 35 |
+
Table 1: Complexity comparison with different Transformers: Reformer [8], Linear Transformer [11], Performer [13] (only variants that support the causal mode are shown). Here T, d denote the sequence length and feature dimension, respectively. Model Time Space
|
| 36 |
+
|
| 37 |
+
| Transformer O ( T 2 d ) O ( T 2 + Td ) Reformer O ( T log Td ) O ( T log T + Td ) Linear Transformer O ( Td 2 ) O ( Td + d 2 ) Performer O ( Td 2 log d ) O ( Td log d + d 2 log d ) AFT-simple O ( Td ) O ( Td ) AFT-full O ( T 2 d ) O ( Td ) AFT-local (AFT-conv) O ( Tsd ) , s < T O ( Td ) |
|
| 38 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 39 |
+
|
| 40 |
+
together with a set of learned position biases. The query is then combined with the reduced context with element-wise multiplication. See Figure 2 for an illustration.
|
| 41 |
+
|
| 42 |
+
AFT maintains direct interaction between any two points in the context, which is a major advantage of dot product attention. In fact, AFT can be interpreted as performing attention where the number of attention heads is the same as the model's feature dimension, whereas the attention maps do not need to be explicitly computed (see Sec. 3.1 for details). This results in a memory complexity linear w.r.t. both the input and model sizes.
|
| 43 |
+
|
| 44 |
+
The rearranged computational ordering of Q,K,V is also found in recent 'linearized attention" works [11, 13-15]. The difference is that AFT combines k and v in an element-wise fashion, while all the linear attention papers rely on matrix dot products. The latter approach results in an complexity quadratic to the model's feature dimension, which is unfriendly to large model sizes. See Table 1 for the complexity analysis of AFT in comparison to other variants.
|
| 45 |
+
|
| 46 |
+
Empirically, we observed that trained Transformers tend to demonstrate extensive local patterns (see Fig. 1). This motivates us to propose two variants of AFT: AFT-local and AFT-conv. In AFT-local, the learned position biases are constrained to a local region, while global connectivity is maintained. AFT-conv further extends this design by imposing spatial weight sharing, effectively making it a variant of CNN with global receptive field. We show that the locality constraint not only provides better parameter and computational efficiency, but also greatly improves model's performance in all tasks.
|
| 47 |
+
|
| 48 |
+
We perform experiments with AFT on image auto-regressive modeling, character level language modeling, and image classification tasks. We show that AFT provides competitive performance, often matching or beating standard Transformers and other variants, while providing excellent efficiency. We also provide extensive ablation studies to several design choices of AFT, and discuss its unique properties such as compatibility with Transformers, sparsity and variable sized inputs.
|
| 49 |
+
|
| 50 |
+
## 2 Multi-Head Attention
|
| 51 |
+
|
| 52 |
+
At the core of Transformers is the Multi-Head Attention (MHA) operation. In the mode of self attention, given an input sequence X ∈ R T × d , and the number of heads h , MHA performs a scaled dot product attention for each head i , defined as:
|
| 53 |
+
|
| 54 |
+
<!-- formula-not-decoded -->
|
| 55 |
+
|
| 56 |
+
where W Q i ∈ R d × d k , W i K ∈ R d × d k , W V i ∈ R d × d v are linear transformations for head i , and σ is the non-linearity by default set as the softmax function (applied to each row of a matrix). d k , d v are dimensions for key and value, respectively. MHA concatenates the output of h attention heads along the channel dimension, resulting in feature dimension hd v . Unless otherwise mentioned, we assume d k = d v and h = d d k . This means the query, key and value are the same dimension within each head, and the output dimension matches that of the input.
|
| 57 |
+
|
| 58 |
+
## 3 Methodology
|
| 59 |
+
|
| 60 |
+
## 3.1 Attention Free Transformer
|
| 61 |
+
|
| 62 |
+
We now define Attention free transformer (AFT), which is a plugin replacement of MHA without the need of changing other architectural aspects of Transformers. Given the input X , AFT first linearly transforms them into Q = XW Q , K = XW K , V = XW V , then performs following operation 2 :
|
| 63 |
+
|
| 64 |
+
where ⊙ is the element-wise product; σ q is the nonlinearity applied to the query with default being sigmoid; w ∈ R T × T is the learned pair-wise position biases (see Figure 2 for an illustration).
|
| 65 |
+
|
| 66 |
+
<!-- formula-not-decoded -->
|
| 67 |
+
|
| 68 |
+
Explained in words, for each target position t , AFT performs a weighted average of values, the result of which is combined with the query with element-wise multiplication. In particular, the weighting is simply composed of the keys and a set of learned pair-wise position biases. This provides the immediate advantage of not needing to compute and store the expensive attention matrix, while maintaining the global interactions between query and values as MHA does.
|
| 69 |
+
|
| 70 |
+
In order to further see AFT's relationship to MHA, we can rewrite Equation 2 as:
|
| 71 |
+
|
| 72 |
+
<!-- formula-not-decoded -->
|
| 73 |
+
|
| 74 |
+
Here we use the superscript i to index the feature dimension of a matrix; < · , · > denotes the dot product of vectors. In this rearranged form, we are able to express AFT in terms of attention again. Specifically, for each position, we have an attention vector a i t ∈ R T for each dimension, composed of Q,K,w . In other words, AFT can be interpreted as performing implicit attention with as many heads as feature dimensions, where the attention matrices take a factorized form.
|
| 75 |
+
|
| 76 |
+
## 3.2 AFT variants: locality, weight sharing and parameterization
|
| 77 |
+
|
| 78 |
+
AFT-full. We denote the basic version of AFT defined in Equation 2 as AFT-full.
|
| 79 |
+
|
| 80 |
+
AFT-local. In many applications, locality is an important inductive bias, which has been exploited by CNNs and recent works in Transformers [4, 7]. In addition, we found that trained standard Transformers tend to demonstrate extensive local attention patterns. To be concrete, we visualized an ImagenetNet pretrained Vision Transformer (ViT) [5], which consists of 12 layers each with 6 heads. For the sake of visualization, we ignore the classification tokens, and reshape each layer's attention tensors to shape 6 × 196 × 196 (the spatial size of the ViT's feature maps is 14 × 14 ). We then sampled 256 images from the ImageNet validation set. For each layer and each head, we compute the average relative 2d attentions, averaged across query positions and images. This results in a set of attention maps of size 12 × 6 × 27 × 27 3 . The result is shown in Figure 1 (left), where we show the attentions for every 2 layers (see the Appendix for the full visualization). We see that the relative attention maps demonstrate strong local patterns (as indicated by the sharpness), especially in the lower layers. This motivates a variant of AFT, dubbed AFT-local, where we only apply a learned set of relative position biases locally:
|
| 81 |
+
|
| 82 |
+
3 12 is #layers, 6 is #heads, 27 × 27 is relative 2d attention size from feature map 14 × 14
|
| 83 |
+
|
| 84 |
+
2 we use the non-masked mode for illustration, and the masked/causal mode can be constructed by limiting the range of the summation.
|
| 85 |
+
|
| 86 |
+
Figure 2: An illustration of AFT defined in Equation 2, with T = 3 , d = 2 .
|
| 87 |
+
|
| 88 |
+
<!-- image -->
|
| 89 |
+
|
| 90 |
+
<!-- formula-not-decoded -->
|
| 91 |
+
|
| 92 |
+
Here s ≤ T is a local window size. AFT-local provides further computational savings, both wrt the number of parameters and time/space complexity. Note that different from local Transformers (e.g., [7]), AFT-local maintains global connectivity regardless of the window size s . In the experiments we verify the effectiveness of this design choice.
|
| 93 |
+
|
| 94 |
+
AFT-simple. An extreme form of AFT-local is when s = 0 , i.e., no position bias is learned. This gives rise to an extremely simple version of AFT, where we have:
|
| 95 |
+
|
| 96 |
+
<!-- formula-not-decoded -->
|
| 97 |
+
|
| 98 |
+
In this version, the context reduction is further simplified to element-wise operations and global pooling. AFT-simple is similar to linearized attention [11, 13, 14], which is formulated as Y t = φ ( Q t ) ∑ T t ′ =1 ( φ ( K t ′ ) T V t ′ ) φ ( Q t ) ∑ T t ′ =1 φ ( K t ) T . However, it is easy to see that AFT-simple completely gets rid of the need for dot products operations, which results in a complexity of O ( Td ) rather than O ( Td 2 ) .
|
| 99 |
+
|
| 100 |
+
AFT-conv. We can also further extend the idea of locality to incorporate spatial weight sharing, i.e., convolution. This variant is especially relevant to vision tasks, as it is often desirable to extend a pretrained model to variable sized inputs. Specifically, we let the value of w t,t ′ to be dependent only on the relative positions of t and t ′ , w.r.t. to a given spatial grid (1d or 2d). Similar to CNNs, we can also learn multiple sets of position biases (we reuse the notion of heads for reference). To account for the growth of #parameters as #heads increases, we adopt a design choice to tie the dimensionality of K with #heads. This makes AFT-conv amendable to an implementation relying on depth-wise separable convolutions, global pooling and element-wise operations.
|
| 101 |
+
|
| 102 |
+
We now show an example of AFT-conv with 1d inputs, 2d and 3d inputs can be derived similarly. We denote a model configuration as AFT-conv-h-s, where h is the number of heads and s is the 1d local window size. We now have w ∈ R h × s , Q,V ∈ R T × h × d h , K ∈ R T × h . For each head i = 1 , 2 , ..., h , we have:
|
| 103 |
+
|
| 104 |
+
Here Y i t ∈ R d h , Q i , V i ∈ R T × d h , K i ∈ R T , w i ∈ R s ; conv1d ( x, w ) is depth-wise separable 1d convolution operation where the convolutional filter w is shared across channel dimension 4 .
|
| 105 |
+
|
| 106 |
+
<!-- formula-not-decoded -->
|
| 107 |
+
|
| 108 |
+
4 Equation 6 can also be implemented with fully connected operations, e.g., einsum, which might yield better efficiency in practice.
|
| 109 |
+
|
| 110 |
+
Note that Equation 6 can be readily interpreted as a specialized convolutional layer with 1) global connectivity, 2) non-negative convolutional weights and 3) sophisticated divisive/multiplicative gating mechanism. We show experimentally that all of the three aspects contribute significantly to AFT-conv's performance.
|
| 111 |
+
|
| 112 |
+
Parameterization. Empirically, we find that it is important to parameterize the position biases w properly. For AFT-full and AFT-local, we adopt a factorized form of w as:
|
| 113 |
+
|
| 114 |
+
<!-- formula-not-decoded -->
|
| 115 |
+
|
| 116 |
+
where d ′ is a small embedding dimension (e.g., 128). This simple factorization not only greatly reduces the parameter counts ( 2 Td ′ vs T 2 ), but also empirically improves model's performance in both training and testing.
|
| 117 |
+
|
| 118 |
+
For AFT-conv, the factorization trick is non-applicable. We instead adopt a simple re-parameterization, where for each head i , we let
|
| 119 |
+
|
| 120 |
+
<!-- formula-not-decoded -->
|
| 121 |
+
|
| 122 |
+
where γ ∈ R h , β ∈ R h are learnable gain and bias parameters, both initialized as 0.
|
| 123 |
+
|
| 124 |
+
## 4 Related Work
|
| 125 |
+
|
| 126 |
+
Since the Transformer was introduced, there have been numerous attempts to address the major source of inefficiency in the architecture, the quadratic cost of the attention operation. Improving this operation can enable larger context sizes and more efficient implementations. For a comprehensive, recent survey of efficient transformers, see [16].
|
| 127 |
+
|
| 128 |
+
Approximating the dot product. [11, 13, 14] propose to approximate the exponential kernel with inner product of projections, which leads to a linearized attention operation of complexity O ( Td 2 ) . The d 2 term of these models however makes it difficult to scale with model size, which is not a problem for AFT. Reformers [8] apply LSH as an approximation to the dot product, where AFT completely gets rid of it.
|
| 129 |
+
|
| 130 |
+
Sparse, local attention. Sparse Transformers [7] and Image Transformer [17] proposes to use fixed sparse or local context patterns. Attention models in vision tasks (often combined with convolutions) use image structure to help handcraft relevant spatial patterns to attend [18-22]. AFT-local also borrows the locality idea, but we put it as a bias rather than hard constraint. This allows AFTlocal/AFT-conv to take advantage of the full context, rather than relying only on a subset.
|
| 131 |
+
|
| 132 |
+
Context compression. Other approaches try to learn context patterns. Adaptive-Span Transformers [23] learn a range for each attention head within which to attend. Routing transformers [24] use clustering to compute dot-product attention only over a subset of elements within the same cluster. The Linformer [10] reduces the length of the context by compressing the keys and values with a linear layer. Compressive Transformers [9] compute and update reduced representations of the input that are far enough back in the input sequence, and attend to those compressed representations. AFT is largely complementary to these approaches, as our focus is to improve the complexity of any given sequence from the operation level.
|
| 133 |
+
|
| 134 |
+
Eliminating dot product attention . Instead of limiting the number of comparisons, other methods change the operation used to compute attention. The Synthesizer [12] uses attention weights predicted from inputs, rather than derived from dot-product interactions. The LightConv module introduced in [25] proposes to replace the dot product self-attention with dynamic lightweight depthwise convolution, where the weights are normalized across temporal dimension. The Sinkhorn Transformer [26] uses a differentiable sorting operation to identify relevant comparisons that may not be local in the original sequence order. AFT offers a different approach along this line, while highlighting strong empirical performance and efficiency.
|
| 135 |
+
|
| 136 |
+
MLPs for vision. Concurrent works [27, 28] explore the use of MLP inplace of the attention operation for vision tasks. While AFT can be viewed in a similar way, it is also equipped with a more sophisticated gating mechanism. In particular, the weighting of values are composed of both the key and position biases, which are normalized to non-negative values (similar to attention). This allows AFT to be a plugin module to existing Transformers without any architectural changes and extra tuning. Besides, AFT-conv inherits the valuable properties of CNNs, allowing it to achieve excellent parameter efficiency, strong performance as well as ability to handle variable sized inputs.
|
| 137 |
+
|
| 138 |
+
Table 2: NLL results on CIFAR10, evaluated by bits/dim, the lower the better. Speed and memory are measured during training time, with a batch size of 32 across 8 V100 GPUs. AFT achieve the state-of-the-art result in this setting, with significant improvements wrt speed and memory over standard Transformer, Sparse Transformer [7] and Image Transformer [17].
|
| 139 |
+
|
| 140 |
+
| Method L d h Train loss Test loss Iters/Sec GB/GPU PixelCNN - - - 3.08 3.14 PixelCNN++ - - - - 2.92 PixelSNAIL - - - - 2.85 Sparse Transformer strided 128 256 2 - 2.80 Image Transformer local2d 12 512 4 - 2.90 1.61 22.3 Transformer 12 512 4 2.90 2.88 1.35 30.6 Transformer 24 256 2 2.90 2.86 1.36 30.4 AFT-local-256 12 512 1 2.78 2.80 1.68 11.4 AFT-local-256 24 256 1 2.75 2.74 1.67 12.8 AFT-simple 24 256 1 2.82 2.89 2.15 9.5 |
|
| 141 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 142 |
+
|
| 143 |
+
Table 3: The effect of factorized parameterization of the position bias, evaluated by autoregressive modeling on CIFAR10.
|
| 144 |
+
|
| 145 |
+
| #params/layer Train loss Test loss Non Factorized 9.6M 2.82 2.84 Factorized (default) 0.6M 2.75 2.74 |
|
| 146 |
+
|------------------------------------------------------------------------------------------------------------------|
|
| 147 |
+
|
| 148 |
+
## 5 Experiments
|
| 149 |
+
|
| 150 |
+
We conduct experiments on three tasks: image autoregressive modeling (Sec. 5.1), character level language modeling (Sec. 5.2) and image classification (Sec. 5.3). The first two benchmarks use the causal model (or decoder model) of AFT, while the last one uses the encoding model. All the experiments are designed in the plug and play fashion, where we obtain a baseline Transformer architecture for the specific task and replace the attention module with an AFT module. Hyperparameters such as initialization, learning rate scheduling are also directly inherited from the Transformer counterparts. Unless otherwise mentioned, all experiments are conducted on 8 × V100 GPU machines.
|
| 151 |
+
|
| 152 |
+
## 5.1 Image Autoregressive Modeling
|
| 153 |
+
|
| 154 |
+
In our first set of experiments, we consider the problem of image autoregressive modeling by minimizing the negative log likelihood (NLL). Similar to [17], we represent an RGB image as a sequence of length H × W × 3 , with H,W being the height and width, respectively. Each sub-pixel is represented as a 256-way discrete variable. We use CIFAR10 as the benchmarking dataset.
|
| 155 |
+
|
| 156 |
+
Our reference Transformer design largely follows that of [4], where a transformer block consists of an attention layer (AFT layer in our case) with residual connection and a 2 layer MLP with residual connections (with the feedforward dimension multiplier set to 4). Layer Normalization (LN) [29] is applied in a 'pre-act" fashion. We adopt learned position embeddings, and use a set of shared token embeddings and prediction heads across RGB. We use AFT-local with the factorized parameterization for this experiment. The hidden dimension for the factorization is 64 , with u, v initialized with N (0 , 10 -2 ) ; the local (1d) window size s is 256.
|
| 157 |
+
|
| 158 |
+
We use AdamW [30], and follow a standard warmup learning rate schedule as in [1]. We use an initial learning rate of 3 × 10 -3 a weight decay of 0 . 1 applied to all linear transformations weights, and a dropout rate of 0.1. We adopt simple data augmentation. During training, we first randomly flip each image horizontally, then add or subtract a value in the range [ -10 , 10] from all its subpixels, and clip resulting pixel values to [0 , 255] . We use cross entropy loss, and a default batch size of 128 for 200 training epochs.
|
| 159 |
+
|
| 160 |
+
Table 4: Enwik8 results, measured in bits per character (bpc), the lower the better. Baselines compared are Reformer [8], Synthesizer [12] (its best performing dense version), Linear Transformer [11] and Performer [13]. L, d, h, T denote number of blocks (depth), dimension of features, number of heads, and sequence length, respectively. Speed and memory are measured during training time, with a batch size of 128 on a 8 V100 GPU node. Both Linear Transformer and Performer are implemented with customized CUDA kernels (github.com/idiap/fast-transformers), and all other models are implemented in native Pytorch.
|
| 161 |
+
|
| 162 |
+
| Method L d h T Train bpc Test bpc Iters/Sec GB/GPU Transformer 12 512 8 1024 0.977 1.137 1.42 29.4 Transformer 24 256 4 1024 1.039 1.130 1.57 28.3 Reformer 12 512 8 1024 1.04 1.195 1.05 20.9 Synthesizer 12 512 8 1024 0.994 1.298 1.49 29.9 Linear Transformer 12 512 8 1024 0.981 1.207 1.46 10.6 Performer 12 512 8 1024 1.002 1.199 1.44 10.1 AFT-local-32 12 512 1 1024 0.854 1.180 1.85 11.3 AFT-local-32 24 256 1 1024 0.972 1.154 2.04 11.2 AFT-simple 24 256 1 1024 1.046 1.209 2.61 9.6 |
|
| 163 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 164 |
+
|
| 165 |
+
Comparing with the state of the art. CIFAR10 is a crowded benchmark for image autoregressive modeling, and we compare with a few competitive baselines, as shown in Table 2. Note that CIFAR10 has an unrolled sequence length of 3072, which is already prohibitive to train a full Transformer with reasonable size. For the standard Transformer model, we adopt two configurations (L=12, d=512, h=4 and L=24, d=256, h=2), with batch size 32 which is the largest one we can fit on a 8xV100 GPU node. Another baseline is Image Transformer [17], which restricts attention to local2d windows of size of 256. We also compare to Sparse Transformers [7], which restrains attention to pre-specified sparse subsets of context elements.
|
| 166 |
+
|
| 167 |
+
From Table2, we see that AFT-local outperforms all the Transformer baselines. We also observe that the deeper but narrower architecture is more effective than the shallow but wide baseline. Our best model also achieves the state-of-the-art result on CIFAR10 in this setting, outperforming a much larger Sparse Transformer model. Efficiency wise, we benchmarked the Transformer variants against AFT on a 8 V100 GPU node 5 . All our variants are faster than standard Transformer and Image Transformer, while consuming only half of the memory 6 . Perhaps surprisingly, AFT-simple also achieves very competitive performance, even outperforming the Image Transformer, while offering excellent speed and memory efficiency.
|
| 168 |
+
|
| 169 |
+
The effect of factorization. We also provide ablations on the role of the factorized parameterization of AFT. To do this, we retrained the best performing model from Table 2 ( i.e., AFT-local-256, L=24, d=256) with a naively parameterized w , initialized with N (0 , 10 -2 ) . From Table 3, we see that the factorized version not only provides significant parameter savings, but also improves the model's performance both on training and testing.
|
| 170 |
+
|
| 171 |
+
| Table 5: Training and testing bpc w.r.t. the local window size for AFT-local. Win size 0 1 2 4 8 32 64 128 256 512 1024 Train bpc 1.046 1.043 1.009 0.990 0.983 0.972 0.981 0.985 0.986 0.988 0.991 Test bpc 1.209 1.205 1.176 1.165 1.162 1.154 1.160 1.165 1.164 1.171 1.173 |
|
| 172 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 173 |
+
|
| 174 |
+
5 We use a batch size of 32 which is the largest batch size Image Transformer can fit
|
| 175 |
+
|
| 176 |
+
6 Fair speed/memory comparison against Sparse Transformer is infeasible, as it relies on a set of advanced implementation tricks such as mixed precision and gradient checkpointing, whereas AFT is implemented with standard Pytorch utilities ran in full precision.
|
| 177 |
+
|
| 178 |
+
Table 6: Increasing T on Enwik8. Both training and testing loss are improved as T increases.
|
| 179 |
+
|
| 180 |
+
| T 1024 2048 4096 Train bpc 0.972 0.951 0.945 Test bpc 1.154 1.135 1.134 |
|
| 181 |
+
|--------------------------------------------------------------------------------------|
|
| 182 |
+
|
| 183 |
+
## 5.2 Language Modeling
|
| 184 |
+
|
| 185 |
+
We apply AFT to character level language modeling on Enwik8 [31], which is another popular benchmark for auto-regressive modeling. We follow the standard preprocessing procedures and training/validation/test splits as in [32]. Our base Transformer reference is a 12 layer 512 dimensional 8 head architecture with 2048 feed forward dimensions. For the first set of experiments, we use sequence length of 1024 . Our training protocol is largely the same as the previous experiment, except that we increase the weight decay to 0.5 and train for 100 epochs with batch size 128. We evaluate the AFT-local with a window size of 32 and d ′ = 256 . We also compare to several efficient Transformer baselines, namely Reformer [8], Synthesizer [12] , Linear Transformer [11] and Performer [13]. From Table 4, we see that with the base L = 12 , d = 512 architecture, AFT achieves the lowest training bits per character (bpc), which is an indicator for high model capacity. Its test performance is slightly worse than that of the basic Transformer, but outperforms all other Transformer variants. The deeper and narrower architecture of AFT strikes the best balance across parameter, speed, memory and performance. Its test bpc is only 0.024 away from the full Transformer's, while only consuming a third of the memory and provides a 44% speedup. AFT-simple again demonstrates competitive performance and excellent efficiency.
|
| 186 |
+
|
| 187 |
+
On the local window size. In order to validate the effect of local window size, we performed additional experiments with the L = 24 , d = 256 architecture, fixing everything but varying the local window size s . We show the results in Table 5, where we see that both the training and testing bpc forms a U-shape w.r.t. the window size, with 32 achieving the best performance. This further confirms that locality is indeed an effective inductive bias across tasks.
|
| 188 |
+
|
| 189 |
+
Longer sequence size. We are also interested in AFT's ability to adapt to longer sequence sizes. Due to its simplicity, one might even expect a degradation of performance as T increases. To this end, we trained the AFT-local-32, L=24, d=256 model with T increased to 2048 and 4096. The results are shown in Table 6. We see that AFT is able to take advantage of larger sequence sizes and yield consistently lower training and testing loss as T increases.
|
| 190 |
+
|
| 191 |
+
## 5.3 Image Classification
|
| 192 |
+
|
| 193 |
+
We then test the non-causal version of AFT, focusing on an image classification task. We adopt the Vision Transformer architecture [5], and perform experiments on the Imagent 1K classification dataset. We adopt training setting and hyper parameters (batch size, data augmentation, regularization and learning rate scheduling) from DeiT [6].
|
| 194 |
+
|
| 195 |
+
In a nutshell, A ViT splits an image into 16 × 16 non-overlapping patches, then linearly projects each patch with shared weights to the equivalence of token embeddings. A learned class token is appended to the resulting representation, resulting in a sequence of length T = 1 + H/ 16 W/ 16 . A linear classification head is attached to the final layer's class token to obtain the final outputs. See [5] for more details of the model configuration. All the experiments are conducted on the ImageNet-1K dataset, without using extra data.
|
| 196 |
+
|
| 197 |
+
Since the sequence size is relatively small in this task ( T = 197 for input sizes of 224 × 224 ), we first experiment with AFT-full. The hidden dimension of factorized position bias is set as d ′ = 128 . Besides, we also experiment with AFT-conv. In this setting, we also remove the use of position embedding and class token, and apply global average pooling after the final layer's output, which is then fed into the classification linear layer. This modification not only simplifies the model design, but also makes AFT-conv fully convolutional , which is absent from Transformer and its variants.
|
| 198 |
+
|
| 199 |
+
We compare against two baseline Transformer configurations, with the 'tiny" (L=12, d=192, h=3) and 'small" (L=12, d=384, h=6) configurations, respectively. We also consider Lambda Networks [15], which is closely related to the linearized attention line of work. Similar to AFT-conv, we remove the class token and apply global average pooling instead. We use a publicly available implementation 7 , and apply the full context mode with the key projection dimension | k | = 16 (this setting invokes the faster linear implementation). We also apply BatchNorm to the query, key projections as recommended by [15].
|
| 200 |
+
|
| 201 |
+
7 github.com/lucidrains/lambda-networks, released under MIT License
|
| 202 |
+
|
| 203 |
+
Table 7: Imagenet 1K classification results with the Transformer architecture from DeiT [6], cropsize is 224 . Speed and memory consumption are measured in inference mode on a V100 GPU, batch size is 256.
|
| 204 |
+
|
| 205 |
+
| Model Kernel Heads Top1 Acc #Params (MB) Images/Sec Mem (GB) ResNet50 [33] 3 - 76.9 25.6 1257 6.5 DeiT tiny [6] - 3 72.2 5.7 2507 1.9 DeiT small [6] - 6 79.9 22.1 1010 2.9 Lambda tiny [15] - 3 72.4 4.8 2157 2.7 Lambda small [15] - 6 80.0 17.7 1057 5.8 AFT-full tiny - 1 72.4 6.3 2523 1.8 AFT-full small - 1 79.8 22.6 1011 2.6 AFT-conv tiny 11 32 73.9 5.4 2359 1.8 AFT-conv tiny 11 192 74.8 5.9 2365 2.2 AFT-conv small 11 16 80.2 20.3 989 2.5 AFT-conv small 11 384 80.8 22.5 936 3.2 AFT-conv small 15 384 81.0 23.0 936 3.2 |
|
| 206 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 207 |
+
|
| 208 |
+
Our result is shown in Table 7. We first see that AFT-full achieves comparable performance with the baseline Transformer DeiT in both configurations, while with better memory footprint and similar speed. AFT-conv significantly improves the top-1 accuracy of both configurations (2.%6, 1.1% absolute improvement for 'tiny" and 'small", respectively), with similar or smaller parameter counts. Compared to Lambda Networks, all AFT variants achieve comparable or better accuracy, with comparable speed and much smaller memory footprints.
|
| 209 |
+
|
| 210 |
+
Visualization. We also tried to visualize the position biases ( exp( w ) -1 to be precise) learned by AFT-conv, as shown in Figure 1 (right). Note that interesting local, symmetric sparse patterns emerge. We show in the Appendix that we can regularize the position biases to achieve more sparsity. We also show an extreme version of AFT-conv, where each head is assigned one non-zero context points, while still keep good accuracy. This effectively transforms convolution into indexing.
|
| 211 |
+
|
| 212 |
+
Variable size inputs. AFT-conv is fully convolutional, which means that it can handle an input size different from that in training. We tested an AFT-conv model (last row of Table 7, trained with crop size 224) on a larger crop size of 384. This results in an improved accuracy of 81 . 6 , compared with the original 81 . 0 . This makes AFT-conv well suited for the pretraining finetuning workflows, as often seen in Vision tasks.
|
| 213 |
+
|
| 214 |
+
Compatibility with Transformers. Although AFT is not designed to directly approximate MHA, they do share considerable similarity in that the value vectors are aggregated with learned nonnegative weighting in both models. We hypothesize that representations learned by one model can be transferred to another. To test this, we obtain a pretrained 'DeiT base" model with crop size 384. We then train an AFT-conv by initializing its weights with that of the DeiT model, excluding the position embeddings, the class token, key and query projections. We use a batch size of 64 and train the model for 100 epochs. As a control, we also train a randomly initialized AFT-conv for the same number of epochs. The results are shown in Table 8. Interestingly, we see that the finetuned version of AFT-conv achieves significantly higher accuracy than that randomly initialized version. The resulting model is also more accurate, faster and memory efficient than the original DeiT model.
|
| 215 |
+
|
| 216 |
+
Global connectivity. AFT-conv (as well as AFT-local) maintains global connectivity regardless of the local kernel size, which is distinctive from sparse and local attention works. To see the benefit of this design, we trained a degenerate variant of AFT-conv, where we modify Equation 4 to assign -∞ values to w t,t ′ outside the local window (zero weights after exponentiation). When evaluating this baseline with kernel size 7, it gives a Top 1 accuracy of 79.9, compared to the default AFT-conv's 80.8 with the same setting, which is a 0.9% drop (we observe the same trend consistently in various configurations). We hypothesize that this technique can also be extended to local and sparse Transformers, but will leave it as future work.
|
| 217 |
+
|
| 218 |
+
## 6 Conclusions
|
| 219 |
+
|
| 220 |
+
We have introduced the Attention Free Transformer that replaces dot product attention with an efficient new operation. We have demonstrated strong results on a set of standard benchmarks with excellent efficiency. We believe that our model opens a new design space for Transformer-like models, and will see impact in various areas where self attention are needed.
|
| 221 |
+
|
| 222 |
+
Table 8: Finetuning AFT-conv for 100 epochs from a pretrained 'DeiT base" on 384 × 384 crops. 'ft" and 'rand" stand for finetuning and random initialization, respectively.
|
| 223 |
+
|
| 224 |
+
| Model Kernel Heads Top1 Acc #Params (MB) Images/Sec Mem (GB) Deit base [33] - 12 82.9 86.9 89.6 13.6 AFT-conv ft 25 32 83.4 79.7 98.5 8.9 AFT-conv rand 25 32 81.6 79.7 98.5 8.9 |
|
| 225 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 226 |
+
|
| 227 |
+
## References
|
| 228 |
+
|
| 229 |
+
- [1] Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin. Attention is all you need. In Advances in neural information processing systems , pages 5998-6008, 2017.
|
| 230 |
+
- [2] Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. Bert: Pre-training of deep bidirectional transformers for language understanding. arXiv preprint arXiv:1810.04805 , 2018.
|
| 231 |
+
- [3] Alec Radford, Karthik Narasimhan, Tim Salimans, and Ilya Sutskever. Improving language understanding by generative pre-training.
|
| 232 |
+
- [4] Mark Chen, Alec Radford, Rewon Child, Jeff Wu, and Heewoo Jun. Generative pretraining from pixels.
|
| 233 |
+
- [5] Alexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn, Xiaohua Zhai, Thomas Unterthiner, Mostafa Dehghani, Matthias Minderer, Georg Heigold, Sylvain Gelly, et al. An image is worth 16x16 words: Transformers for image recognition at scale. arXiv preprint arXiv:2010.11929 , 2020.
|
| 234 |
+
- [6] Hugo Touvron, Matthieu Cord, Matthijs Douze, Francisco Massa, Alexandre Sablayrolles, and Hervé Jégou. Training data-efficient image transformers & distillation through attention. arXiv preprint arXiv:2012.12877 , 2020.
|
| 235 |
+
- [7] Rewon Child, Scott Gray, Alec Radford, and Ilya Sutskever. Generating long sequences with sparse transformers. CoRR , abs/1904.10509, 2019.
|
| 236 |
+
- [8] Nikita Kitaev, L. Kaiser, and Anselm Levskaya. Reformer: The efficient transformer. ArXiv , abs/2001.04451, 2020.
|
| 237 |
+
- [9] Jack W. Rae, Anna Potapenko, Siddhant M. Jayakumar, and T. Lillicrap. Compressive transformers for long-range sequence modelling. ArXiv , abs/1911.05507, 2020.
|
| 238 |
+
- [10] Sinong Wang, Belinda Z. Li, Madian Khabsa, Han Fang, and Hao Ma. Linformer: Self-attention with linear complexity. ArXiv , abs/2006.04768, 2020.
|
| 239 |
+
- [11] A. Katharopoulos, A. Vyas, N. Pappas, and F. Fleuret. Transformers are rnns: Fast autoregressive transformers with linear attention. In Proceedings of the International Conference on Machine Learning (ICML) , 2020.
|
| 240 |
+
- [12] Yi Tay, Dara Bahri, Donald Metzler, Da-Cheng Juan, Zhe Zhao, and Che Zheng. Synthesizer: Rethinking self-attention in transformer models, 2020.
|
| 241 |
+
- [13] Krzysztof Choromanski, Valerii Likhosherstov, David Dohan, Xingyou Song, Andreea Gane, Tamas Sarlos, Peter Hawkins, Jared Davis, Afroz Mohiuddin, Lukasz Kaiser, David Belanger, Lucy Colwell, and Adrian Weller. Rethinking attention with performers, 2020.
|
| 242 |
+
- [14] Hao Peng, Nikolaos Pappas, Dani Yogatama, Roy Schwartz, Noah Smith, and Lingpeng Kong. Random feature attention. In International Conference on Learning Representations , 2021.
|
| 243 |
+
|
| 244 |
+
- [15] Irwan Bello. Lambdanetworks: Modeling long-range interactions without attention. In International Conference on Learning Representations , 2021.
|
| 245 |
+
- [16] Yi Tay, Mostafa Dehghani, Dara Bahri, and Donald Metzler. Efficient transformers: A survey, 2020.
|
| 246 |
+
- [17] Niki Parmar, Ashish Vaswani, Jakob Uszkoreit, Łukasz Kaiser, Noam Shazeer, Alexander Ku, and Dustin Tran. Image transformer. arXiv preprint arXiv:1802.05751 , 2018.
|
| 247 |
+
- [18] Huiyu Wang, Y. Zhu, B. Green, H. Adam, A. Yuille, and Liang-Chieh Chen. Axial-deeplab: Stand-alone axial-attention for panoptic segmentation. ArXiv , abs/2003.07853, 2020.
|
| 248 |
+
- [19] Zilong Huang, Xinggang Wang, Lichao Huang, C. Huang, Yunchao Wei, and Wenyu Liu. Ccnet: Criss-cross attention for semantic segmentation. 2019 IEEE/CVF International Conference on Computer Vision (ICCV) , pages 603-612, 2019.
|
| 249 |
+
- [20] Zhen Zhu, Mengdu Xu, Song Bai, Tengteng Huang, and X. Bai. Asymmetric non-local neural networks for semantic segmentation. 2019 IEEE/CVF International Conference on Computer Vision (ICCV) , pages 593-602, 2019.
|
| 250 |
+
- [21] Lang Huang, Y. Yuan, Jianyuan Guo, Chao Zhang, X. Chen, and Jingdong Wang. Interlaced sparse self-attention for semantic segmentation. ArXiv , abs/1907.12273, 2019.
|
| 251 |
+
- [22] Prajit Ramachandran, Niki Parmar, Ashish Vaswani, I. Bello, Anselm Levskaya, and Jonathon Shlens. Stand-alone self-attention in vision models. ArXiv , abs/1906.05909, 2019.
|
| 252 |
+
- [23] Sainbayar Sukhbaatar, E. Grave, P. Bojanowski, and Armand Joulin. Adaptive attention span in transformers. In ACL , 2019.
|
| 253 |
+
- [24] Aurko Roy, M. Saffar, Ashish Vaswani, and David Grangier. Efficient content-based sparse attention with routing transformers. ArXiv , abs/2003.05997, 2020.
|
| 254 |
+
- [25] Felix Wu, Angela Fan, Alexei Baevski, Yann Dauphin, and M. Auli. Pay less attention with lightweight and dynamic convolutions. ArXiv , abs/1901.10430, 2019.
|
| 255 |
+
- [26] Yi Tay, Dara Bahri, L. Yang, Donald Metzler, and D. Juan. Sparse sinkhorn attention. ArXiv , abs/2002.11296, 2020.
|
| 256 |
+
- [27] Ilya Tolstikhin, Neil Houlsby, Alexander Kolesnikov, Lucas Beyer, Xiaohua Zhai, Thomas Unterthiner, Jessica Yung, Andreas Steiner, Daniel Keysers, Jakob Uszkoreit, Mario Lucic, and Alexey Dosovitskiy. Mlp-mixer: An all-mlp architecture for vision, 2021.
|
| 257 |
+
- [28] Hanxiao Liu, Zihang Dai, David R. So, and Quoc V. Le. Pay attention to mlps, 2021.
|
| 258 |
+
- [29] Jimmy Lei Ba, Jamie Ryan Kiros, and Geoffrey E Hinton. Layer normalization. arXiv preprint arXiv:1607.06450 , 2016.
|
| 259 |
+
- [30] Ilya Loshchilov and Frank Hutter. Decoupled weight decay regularization, 2019.
|
| 260 |
+
- [31] Matt Mahoney. Large text compression benchmark, 2011.
|
| 261 |
+
- [32] Zihang Dai, Z. Yang, Yiming Yang, J. Carbonell, Quoc V. Le, and R. Salakhutdinov. Transformer-xl: Attentive language models beyond a fixed-length context. ArXiv , abs/1901.02860, 2019.
|
| 262 |
+
- [33] Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep residual learning for image recognition, 2015.
|
| 263 |
+
- [34] Eric Jang, Shixiang Gu, and Ben Poole. Categorical reparameterization with gumbel-softmax, 2017.
|
| 264 |
+
|
| 265 |
+
Figure 3: Exponentiated position biases learned by AFT-full, trained on ImageNet-1K, shown from layer 1, 2, ..., 12, arranged from top left to bottom right. Each image is of size 197 × 197 , where the first element corresponds to the class token, and the remaining 196 correspond to the 14 × 14 positions. We see that local, sparse patterns are learned without explicit supervision.
|
| 266 |
+
|
| 267 |
+
<!-- image -->
|
| 268 |
+
|
| 269 |
+
Table 9: The effect of factorized parameterization of AFT-full. Table 10: The effect of reprameterization of AFT-
|
| 270 |
+
|
| 271 |
+
| Train loss Top 1 Acc Non Factorized 3.17 78.2 Factorized (default) 3.08 79.8 Train loss Top 1 Acc Naive param 3.11 79.4 Reparameterized (default) 2.94 80.8 |
|
| 272 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 273 |
+
|
| 274 |
+
## 7 Additional Ablations
|
| 275 |
+
|
| 276 |
+
We conducted more experiments on the ImageNet-1K classification settings.
|
| 277 |
+
|
| 278 |
+
Factorization of w . We first verify the importance of the factorized parameterization of AFT-full. As shown in Tab 9, the non factorized parameterization of AFT-full achieves worse training and test performance than the factorized version.
|
| 279 |
+
|
| 280 |
+
Reparameterization of w . For AFT-conv, we by default apply the reprameterization as described in Sec. 3.2. We verify that this design effectively improves the model's performance, as shown in Table 10.
|
| 281 |
+
|
| 282 |
+
Kernel size. We also experimented with varying the local window size based on AFT-conv small (384 heads). The results are shown in Tab 11. Note that AFT-conv achieves comparable performance to the Deit reference even with a very small kernel size of 3 × 3 .
|
| 283 |
+
|
| 284 |
+
Table 11: Varying kernel size for AFT-conv.
|
| 285 |
+
|
| 286 |
+
| Kernel 3 7 11 15 25 27 DeiT small Train loss 3.02 2.94 2.94 2.93 2.93 2.94 3.01 Top 1 Acc 79.9 80.8 80.8 81.0 80.7 81.0 79.9 |
|
| 287 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 288 |
+
|
| 289 |
+
conv (kernel size 7 × 7 ).
|
| 290 |
+
|
| 291 |
+
Figure 4: Image completion with the AFT-local trained on CIFAR10 autoregressive modeling task. Top: masked images from the test set. Bottom: completed images.
|
| 292 |
+
|
| 293 |
+
<!-- image -->
|
| 294 |
+
|
| 295 |
+
Table 12: Top 1 accuracy of AFT-conv without the query term (w/o q). This results in significant performance drops.
|
| 296 |
+
|
| 297 |
+
| Kernel 11 15 with q (default) 80.8 81.0 w/o q 79.3 79.5 |
|
| 298 |
+
|-------------------------------------------------------------------|
|
| 299 |
+
|
| 300 |
+
Contribution of the query. The query term contributes a small fraction to the computation of AFT, but it contributes significantly to AFT's performance. We conducted an additional experiment with AFT-conv (384 heads, kernel size in 11 × 11 and 15 × 15 ), where we remove the query term. The result is shown in Tab 12.
|
| 301 |
+
|
| 302 |
+
Visualizing the key. The keys play a central role in AFT, as they provide content dependent reweighting for effective context reduction. In order to understand their behavior, we visualized the feature maps for a AFT-conv model on randomly sampled images from the validation set of ImageNet-1K, as shown in Fig. 9, 10, 11, 12. Interestingly, we see that the keys gradually evolve to 'object detectors" as the layer level goes up.
|
| 303 |
+
|
| 304 |
+
Figure 5: The full set of average relative 2d attention maps learned by a pretrained ViT model (with 12 layers and 6 heads) on ImageNet-1K. Each row corresponds to a layer and each column corresponds to a head. Each attention map is of size 27 × 27 , with the class token excluded.
|
| 305 |
+
|
| 306 |
+
<!-- image -->
|
| 307 |
+
|
| 308 |
+
Figure 6: Exponentiated position biases learned by AFT-conv, trained on ImageNet-1K. Each row corresponds to a layer, each column corresponds to a head (the first 16 are shown). This model has top 1 accuracy of 80 . 8% .
|
| 309 |
+
|
| 310 |
+
<!-- image -->
|
| 311 |
+
|
| 312 |
+
Figure 7: Exponentiated position biases learned by AFT-conv (kernel size 11 × 11 ) with sparsity regularization , trained on ImageNet-1K. Each row corresponds to a layer, each column corresponds to a head (the first 16 are shown). This model has top 1 accuracy of 80 . 9% .
|
| 313 |
+
|
| 314 |
+
<!-- image -->
|
| 315 |
+
|
| 316 |
+
Figure 8: Exponentiated position biases learned AFT-conv (kernel size 11 × 11 ) with Gumbel softmax sampling , trained on ImageNet-1K. Each row corresponds to a layer, each column corresponds to a head (the first 16 are shown). This model has top 1 accuracy of 79 . 9% .
|
| 317 |
+
|
| 318 |
+
<!-- image -->
|
| 319 |
+
|
| 320 |
+
## 8 Sparsity
|
| 321 |
+
|
| 322 |
+
The position biases learned by AFT-conv (kernel size 11 × 11 ) as shown in Figure 6 demonstrates interesting sparsity patterns, which suggests great potential for quantization and pruning. To this end, we experimented with a simple sparsity promoting regularization term:
|
| 323 |
+
|
| 324 |
+
<!-- formula-not-decoded -->
|
| 325 |
+
|
| 326 |
+
Where we simply minimize the entropy for each head, with the softmax distribution using w i as the logits. We combining reg ( w ) with the cross entropy loss with a small weighting ( 0 . 001 ) and train with the AFT-conv with kernel size 11 and 384 heads. This results in a slight improvement in accuracy (due to its regularization effect) of 80 . 9 vs 80 . 8 , as well as sparser looking position biases. The visualization is shown in Fig. 7. We see that the position biases are much more sparsely distributed as expected.
|
| 327 |
+
|
| 328 |
+
Encouraged by this, we continued to push the sparsity to an extreme form. Now for each head, we only assign a learned relative position bias for a single position . To do this, during training, we multiply the position biases w for each layer and each head with a sample from its corresponding Gumbel softmax distribution [34]:
|
| 329 |
+
|
| 330 |
+
<!-- formula-not-decoded -->
|
| 331 |
+
|
| 332 |
+
where τ is the temperature term for Gumbel softmax, and we set it as 0.5; gumbel ( w i ; τ ) produces a (sparse) sample with the same shape as w i . During inference, the Gumbel softmax is replaced with hard max, i.e., a one hot vector is returned. This results in a model with top 1 accuracy 79 . 9 , with less than 1 point drop compared with the unregularized model. The position biases are visualized in Fig. 8. This extreme model variant makes it possible to implement the context reduction of K,V with a combination of global average pooling and indexing, which has the same complexity as AFT-simple but maintains strong performance (comparable to that of the standard Transformer).
|
| 333 |
+
|
| 334 |
+
Figure 9: Top : sample image from the validation set of ImageNet-1K. Bottom : visualization of the keys for AFT-conv, with each row corresponding to a layer, each column corresponding to a head.
|
| 335 |
+
|
| 336 |
+
<!-- image -->
|
| 337 |
+
|
| 338 |
+
<!-- image -->
|
| 339 |
+
|
| 340 |
+
Figure 10: Top : sample image from the validation set of ImageNet-1K. Bottom : visualization of the keys for AFT-conv, with each row corresponding to a layer, each column corresponding to a head.
|
| 341 |
+
|
| 342 |
+
<!-- image -->
|
| 343 |
+
|
| 344 |
+
<!-- image -->
|
| 345 |
+
|
| 346 |
+
Figure 11: Top : sample image from the validation set of ImageNet-1K. Bottom : visualization of the keys for AFT-conv, with each row corresponding to a layer, each column corresponding to a head.
|
| 347 |
+
|
| 348 |
+
<!-- image -->
|
| 349 |
+
|
| 350 |
+
<!-- image -->
|
| 351 |
+
|
| 352 |
+
Figure 12: Top : sample image from the validation set of ImageNet-1K. Bottom : visualization of the keys for AFT-conv, with each row corresponding to a layer, each column corresponding to a head.
|
| 353 |
+
|
| 354 |
+
<!-- image -->
|
| 355 |
+
|
| 356 |
+
<!-- image -->
|
| 357 |
+
|
| 358 |
+
1
|
| 359 |
+
|
| 360 |
+
Figure 1: Exponentiated position biases learned by AFT-full, trained on ImageNet-1K, shown from layer 1, 2, ..., 12, arranged from top left to bottom right. Each image is of size 197 × 197 , where the first element corresponds to the class token, and the remaining 196 correspond to the 14 × 14 positions. We see that local, sparse patterns are learned without explicit supervision.
|
| 361 |
+
|
| 362 |
+
<!-- image -->
|
| 363 |
+
|
| 364 |
+
Table 1: The effect of factorized parameterization of AFT-full. Table 2: The effect of reprameterization of AFTconv (kernel size 7 × 7 ).
|
| 365 |
+
|
| 366 |
+
| Train loss Top 1 Acc Non Factorized 3.17 78.2 Factorized (default) 3.08 79.8 Train loss Top 1 Acc Naive param 3.11 79.4 Reparameterized (default) 2.94 80.8 |
|
| 367 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 368 |
+
|
| 369 |
+
## 1 Additional Ablations
|
| 370 |
+
|
| 371 |
+
- We conducted more experiments on the ImageNet-1K classification settings. 2
|
| 372 |
+
- Factorization of w . We first verify the importance of the factorized parameterization of AFT-full. 3
|
| 373 |
+
|
| 374 |
+
As shown in Tab 1, the non factorized parameterization of AFT-full achieves worse training and test 4 performance than the factorized version. 5
|
| 375 |
+
|
| 376 |
+
Reparameterization of w . For AFT-conv, we by default apply the reprameterization as described in 6 Sec. 3.2. We verify that this design effectively improves the model's performance, as shown in Table 7 2. 8
|
| 377 |
+
|
| 378 |
+
Kernel size. We also experimented with varying the local window size based on AFT-conv small 9 (384 heads). The results are shown in Tab 3. Note that AFT-conv achieves comparable performance 10 to the Deit reference even with a very small kernel size of .
|
| 379 |
+
|
| 380 |
+
3 × 3 11
|
| 381 |
+
|
| 382 |
+
Table 3: Varying kernel size for AFT-conv.
|
| 383 |
+
|
| 384 |
+
| Kernel 3 7 11 15 25 27 DeiT small Train loss 3.02 2.94 2.94 2.93 2.93 2.94 3.01 Top 1 Acc 79.9 80.8 80.8 81.0 80.7 81.0 79.9 |
|
| 385 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 386 |
+
|
| 387 |
+
Figure 2: Image completion with the AFT-local trained on CIFAR10 autoregressive modeling task. Top: masked images from the test set. Bottom: completed images.
|
| 388 |
+
|
| 389 |
+
<!-- image -->
|
| 390 |
+
|
| 391 |
+
Table 4: Top 1 accuracy of AFT-conv without the query term (w/o q). This results in significant performance drops.
|
| 392 |
+
|
| 393 |
+
| Kernel 11 15 with q (default) 80.8 81.0 w/o q 79.3 79.5 |
|
| 394 |
+
|-------------------------------------------------------------------|
|
| 395 |
+
|
| 396 |
+
Figure 3: The full set of average relative 2d attention maps learned by a pretrained ViT model (with 12 layers and 6 heads) on ImageNet-1K. Each row corresponds to a layer and each column corresponds to a head. Each attention map is of size 27 × 27 , with the class token excluded.
|
| 397 |
+
|
| 398 |
+
<!-- image -->
|
| 399 |
+
|
| 400 |
+
Figure 4: Exponentiated position biases learned by AFT-conv, trained on ImageNet-1K. Each row corresponds to a layer, each column corresponds to a head (the first 16 are shown). This model has top 1 accuracy of 80 . 8% .
|
| 401 |
+
|
| 402 |
+
<!-- image -->
|
| 403 |
+
|
| 404 |
+
Figure 5: Exponentiated position biases learned by AFT-conv (kernel size 11 × 11 ) with sparsity regularization , trained on ImageNet-1K. Each row corresponds to a layer, each column corresponds to a head (the first 16 are shown). This model has top 1 accuracy of 80 . 9% .
|
| 405 |
+
|
| 406 |
+
<!-- image -->
|
| 407 |
+
|
| 408 |
+
Figure 6: Exponentiated position biases learned AFT-conv (kernel size 11 × 11 ) with Gumbel softmax sampling , trained on ImageNet-1K. Each row corresponds to a layer, each column corresponds to a head (the first 16 are shown). This model has top 1 accuracy of 79 . 9% .
|
| 409 |
+
|
| 410 |
+
<!-- image -->
|
| 411 |
+
|
| 412 |
+
## 2 Sparsity 21
|
| 413 |
+
|
| 414 |
+
The position biases learned by AFT-conv (kernel size 11 × 11 ) as shown in Figure 4 demonstrates 22 interesting sparsity patterns, which suggests great potential for quantization and pruning. To this end, 23 we experimented with a simple sparsity promoting regularization term: 24
|
| 415 |
+
|
| 416 |
+
<!-- formula-not-decoded -->
|
| 417 |
+
|
| 418 |
+
Where we simply minimize the entropy for each head, with the softmax distribution using w i as 25 the logits. We combining reg ( w ) with the cross entropy loss with a small weighting ( 0 . 001 ) and 26 train with the AFT-conv with kernel size 11 and 384 heads. This results in a slight improvement 27 in accuracy (due to its regularization effect) of 80 . 9 vs 80 . 8 , as well as sparser looking position 28 biases. The visualization is shown in Fig. 5. We see that the position biases are much more sparsely 29 distributed as expected. 30
|
| 419 |
+
|
| 420 |
+
Encouraged by this, we continued to push the sparsity to an extreme form. Now for each head, we 31 only assign a learned relative position bias for a single position . To do this, during training, we 32 multiply the position biases w for each layer and each head with a sample from its corresponding 33 Gumbel softmax distribution [ ? ]: 34
|
| 421 |
+
|
| 422 |
+
<!-- formula-not-decoded -->
|
| 423 |
+
|
| 424 |
+
where τ is the temperature term for Gumbel softmax, and we set it as 0.5; gumbel ( w i ; τ ) produces a 35 (sparse) sample with the same shape as w i . During inference, the Gumbel softmax is replaced with 36 hard max, i.e., a one hot vector is returned. This results in a model with top 1 accuracy 79 . 9 , with less 37 than 1 point drop compared with the unregularized model. The position biases are visualized in Fig. 38 6. This extreme model variant makes it possible to implement the context reduction of K,V with a 39 combination of global average pooling and indexing, which has the same complexity as AFT-simple 40 but maintains strong performance (comparable to that of the standard Transformer). 41
|
| 425 |
+
|
| 426 |
+
Figure 7: Top : sample image from the validation set of ImageNet-1K. Bottom : visualization of the keys for AFT-conv, with each row corresponding to a layer, each column corresponding to a head.
|
| 427 |
+
|
| 428 |
+
<!-- image -->
|
| 429 |
+
|
| 430 |
+
<!-- image -->
|
| 431 |
+
|
| 432 |
+
Figure 8: Top : sample image from the validation set of ImageNet-1K. Bottom : visualization of the keys for AFT-conv, with each row corresponding to a layer, each column corresponding to a head.
|
| 433 |
+
|
| 434 |
+
<!-- image -->
|
| 435 |
+
|
| 436 |
+
<!-- image -->
|
| 437 |
+
|
| 438 |
+
Figure 9: Top : sample image from the validation set of ImageNet-1K. Bottom : visualization of the keys for AFT-conv, with each row corresponding to a layer, each column corresponding to a head.
|
| 439 |
+
|
| 440 |
+
<!-- image -->
|
| 441 |
+
|
| 442 |
+
<!-- image -->
|
| 443 |
+
|
| 444 |
+
Figure 10: Top : sample image from the validation set of ImageNet-1K. Bottom : visualization of the keys for AFT-conv, with each row corresponding to a layer, each column corresponding to a head.
|
| 445 |
+
|
| 446 |
+
<!-- image -->
|
| 447 |
+
|
| 448 |
+
<!-- image -->
|
text-versions/attention-markdown/2106.01451_Attentionbased Contextual Language Model.md
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2106.01451 Attentionbased Contextual Language Model
|
| 2 |
+
|
| 3 |
+
## Attention-based Contextual Language Model Adaptation for Speech Recognition
|
| 4 |
+
|
| 5 |
+
Richard Diehl Martinez, Scott Novotney, Ivan Bulyko, Ariya Rastrow, Andreas Stolcke, Ankur Gandhe
|
| 6 |
+
|
| 7 |
+
Amazon Alexa, Seattle, WA, USA
|
| 8 |
+
|
| 9 |
+
{ mrtimri,snovotne,ibbulyko,arastrow,stolcke,aggandhe } @amazon.com
|
| 10 |
+
|
| 11 |
+
## Abstract
|
| 12 |
+
|
| 13 |
+
Language modeling (LM) for automatic speech recognition (ASR) does not usually incorporate utterance level contextual information. For some domains like voice assistants, however, additional context, such as time at which an utterance was spoken, provides a rich input signal. We introduce an attention mechanism for training neural speech recognition language models on both text and nonlinguistic contextual data 1 . When applied to a large de-identified dataset of utterances collected by a popular voice assistant platform, our method reduces perplexity by 7.0% relative over a standard LM that does not incorporate contextual information. When evaluated on utterances extracted from the long tail of the dataset, our method improves perplexity by 9.0% relative over a standard LM and by over 2.8% relative when compared to a state-of-theart model for contextual LM.
|
| 14 |
+
|
| 15 |
+
## 1 Introduction
|
| 16 |
+
|
| 17 |
+
Conventional automatic speech recognition (ASR) systems include a language model (LM) and an acoustic model (AM). The LM component is trained separately, typically on large amounts of transcribed utterances that have been collected by an existing speech recognition system.
|
| 18 |
+
|
| 19 |
+
Voice assistants have become ubiquitous and crucially rely on ASR systems to convert user inputs to text. They often collect utterances spoken by users, along with associated de-identified contextual information. We hypothesize that these additional data, such as the time at which an utterance was spoken, provide a useful input signal for a LM. As an example, knowing that an utterance was spoken on December 25th, a LM should learn that the word 'christmas' rather than 'easter' is more likely to follow the phrase 'lookup cookie recipes for'.
|
| 20 |
+
|
| 21 |
+
1 We make a large portion of our code available under: https://github.com/amazon-research/contextual-attentionnlm
|
| 22 |
+
|
| 23 |
+
To-date, some voice assistants have leveraged coarse geographic information for improving location search queries (Bocchieri and Caseiro, 2010; Lloyd and Kristjansson, 2012). These past efforts, however, have largely focused on improving a particular skill of an ASR system, and not the system's speech recognition in general.
|
| 24 |
+
|
| 25 |
+
In this paper, we focus on adapting recurrent neural network language models (RNN-LMs) to use both text and non-linguistic contextual data for speech recognition in general. While, outside of ASR, transformer-based (Vaswani et al., 2017) language models have largely replaced RNN-LMs, RNNs remain dominant in ASR architectures such as connectionist temporal classification (Graves et al., 2006), and RNN-T (Graves, 2012; He et al., 2019).
|
| 26 |
+
|
| 27 |
+
The most common method for incorporating nonlinguistic information into a RNN-LM is to learn a representation of the context that is concatenated with word embeddings as input to the model. This concatenation-based approach has been used in a variety of domains including text classification (Yogatama et al., 2017), personalized conversational agents (Wen et al., 2013), and voice search queries (Ma et al., 2018).
|
| 28 |
+
|
| 29 |
+
Recently, attention mechanisms, initially developed for machine translation (Bahdanau et al., 2014; Luong et al., 2015), have been used by neural LMs to adaptively condition their predictions on certain non-linguistic contexts. Tang et al. (2016) use an attention module that attends to wordlocation information to predict the polarity of a sentence. Similarly, Zheng et al. (2019) use an attention mechanism over learned personality trait embeddings, in order to generate personalized dialogue responses.
|
| 30 |
+
|
| 31 |
+
The aforementioned approaches learn a representation of the context that is directly used as input to a neural LM. In contrast to these methods, Jaech and Ostendorf (2018a) adapt the weight- matrix used in an RNN model to a given contextual input. The authors propose decomposing the weight-matrix into a set of left and right basis tensors which are then multiplied by a learned context embedding to produce a new weight-matrix. Factorizing the weight-matrix enables a larger fraction of a model's parameters to adjust to a given contextual signal. This factorization-based approach has proven effective in generating automatic completions of sentences that are personalized for particular users (Jaech and Ostendorf, 2018b).
|
| 32 |
+
|
| 33 |
+
We introduce an attention mechanism that augments both the concatenation-based and factorization-based approaches to condition a neural LM on context. The attention mechanism that we propose builds up a dynamic context representation over the course of processing an utterance. The resulting embedding can be used as an additional input to either the concatenation-based or factorization-based model.
|
| 34 |
+
|
| 35 |
+
Our experiments focus primarily on conditioning neural LMs on datetime context. We concentrate on datetime information because of its widespread availability in many ASR systems. Our approach, however, can generalized to any type of context. To underscore this point we also provide results for conditioning LMs on geolocation information and dialogue prompts that are commonly available in ASR systems.
|
| 36 |
+
|
| 37 |
+
We evaluate our method on a large de-identified dataset of transcribed utterances. Compared to a standard model that does not include contextual information, using our method to contextualize a neural LM on datetime information achieves a relative reduction in perplexity of 7.0%, and a relative reduction in perplexity of 9.0% when evaluated on the tail of this dataset. Moreover, our attention mechanism can improve state-of-the-art methods for conditional LMs by over 2.8% relative in terms of perplexity.
|
| 38 |
+
|
| 39 |
+
## 2 Data
|
| 40 |
+
|
| 41 |
+
We use a corpus of over 5,000 hours of deidentified, transcribed English utterances, collected over several years. Each utterance also contains associated information about the year, month, day, and hour that the utterance was spoken. The datetime information is reported according to the local time zone of each given user. Any information about the device or the speaker from which an utterance originates has been removed. We randomly split our dataset into a training set, development set and test set, using a partition ratio of 90/5/5 and we ensure that each partition contains more than 500 hours worth of data.
|
| 42 |
+
|
| 43 |
+
## 3 Context Representation
|
| 44 |
+
|
| 45 |
+
A typical utterance in our dataset might look like this:
|
| 46 |
+
|
| 47 |
+
2020-12-23 07:00 play christmas music.
|
| 48 |
+
|
| 49 |
+
In the example above, we can infer that the utterance 'play christmas music' was spoken on December 23, 2020 at 7 in the morning local time. In order to condition a LM on this datetime information, we consider two methods for transforming the contextual information into a continuous vector representation:
|
| 50 |
+
|
| 51 |
+
1. Learned embeddings: We first consider creating tokens for the month number, week number, day of the week and hour that an utterance was spoken. In the example above, we would transform the datetime information into tokens representing: month-12, week-52, wednesday, 7am. These tokens are subsequently used as input to the model, where they are passed through an embedding layer to generate context embeddings. These embeddings are initialized as random vectors, and trained along with the rest of the model. We experiment with different ways of parsing the information, such as encoding weekday versus weekend, or morning versus evening, but find this information is largely entailed within our method for processing datetime information.
|
| 52 |
+
2. Feature-engineered representation: Additionally, we consider transforming the datetime information into a single 8-dimensional feature-engineered vector, where the dimensions of the vector are defined as
|
| 53 |
+
|
| 54 |
+
<!-- formula-not-decoded -->
|
| 55 |
+
|
| 56 |
+
Since the datetime context is continuous and cyclical, this approach explicitly encodes tem- poral proximity in the date and time information.
|
| 57 |
+
|
| 58 |
+
## 3.1 Input Representation
|
| 59 |
+
|
| 60 |
+
We assume as input to a model a sequence of either word or subword tokens, w i for i ∈ { 1 , . . . , n } , that are converted by an embedding layer into embeddings x i ∈ R e for i ∈ { 1 , . . . , n } , where n is the length of the input sequence and e is the dimensionality of the word embeddings.
|
| 61 |
+
|
| 62 |
+
We additionally represent the contextual information as either:
|
| 63 |
+
|
| 64 |
+
1. A set, M , of four learned context embeddings M = { m 1 , m 2 , m 3 , m 4 } , where m 1 is an encoding of the month information, m 2 is an encoding of the week information, m 3 is an encoding of the day of the week information, and m 4 is an encoding of the hour of the day information. When using the concatenationbased or factorization-based approaches without attention, we first concatenate the embeddings together, m = [ m 1 ; m 2 ; m 3 ; m 4 ] , and use the resulting vector as input to the model.
|
| 65 |
+
2. A set, M , containing a single embedding M = { m } , where m represents an 8dimensional feature-engineered contextual datetime representation, as described in the previous section.
|
| 66 |
+
|
| 67 |
+
## 4 Model
|
| 68 |
+
|
| 69 |
+
In this section, we first describe the architecture of the concatenation-based and factorization-based approaches. We then introduce our attentionmechanism that can be used to augment both of these approaches. The notation we use to describe architectures assumes a 1-layer RNN model. The methods we discuss, however, can be applied to each layer of a multi-layer RNN model.
|
| 70 |
+
|
| 71 |
+
## 4.1 Concatenation-based LM Adaptation
|
| 72 |
+
|
| 73 |
+
The concatenation-based approach learns a weight matrix W m of dimensionality R f × d , where f represents the size of the context representation and d represents the hidden-dimensionality of the RNN model. In practice, f is either a hyperparameter when datetime context is represented as learned embeddings, or f = 8 when this context is represented as a feature-engineered vector. When representing contextual information as learned embeddings, recall that we first concatenate the embeddings together before passing these into the model. In this case, f is four-times the size of each individual context embedding.
|
| 74 |
+
|
| 75 |
+
Astandard RNN model without contextual information keeps track of a hidden-state at time-step t , h t , that is calculated as
|
| 76 |
+
|
| 77 |
+
<!-- formula-not-decoded -->
|
| 78 |
+
|
| 79 |
+
where x t represents the word embedding at timestep t , b is a bias vector, W x ∈ R e × d , and W h ∈ R d × d .
|
| 80 |
+
|
| 81 |
+
In the concatenation-based approach, this hidden-state is adapted in the following manner
|
| 82 |
+
|
| 83 |
+
<!-- formula-not-decoded -->
|
| 84 |
+
|
| 85 |
+
Notice that the expression above can be equivalently calculated by concatenating the matrices W m and W x , as well as the vectors m and x t
|
| 86 |
+
|
| 87 |
+
<!-- formula-not-decoded -->
|
| 88 |
+
|
| 89 |
+
To generate a prediction, ˆ y t for a word at time-step t , h t is passed through a projection layer, W v ∈ R d ×| V | to match the dimension of the vocabulary size | V | , before applying a softmax layer
|
| 90 |
+
|
| 91 |
+
<!-- formula-not-decoded -->
|
| 92 |
+
|
| 93 |
+
## 4.2 Factorization-based LM Adaptation
|
| 94 |
+
|
| 95 |
+
Unlike the concatenation-based approach, which directly inserts contextual information into the RNN cell, the factorization-based method adapts the weight matrices W x , W h of the RNN model. Compared to the concatenation-based architecture, this approach adapts a larger fraction of the RNN model's parameters.
|
| 96 |
+
|
| 97 |
+
The adaption process involves learning basis tensors W ( L ) x ′ , W ( R ) x ′ and W ( L ) h ′ , W ( R ) h ′ . These basis tensors are of fixed rank r , where r is a tuned hyperparameter. The left adaptation tensors, W ( L ) x ′ , W ( L ) h ′ , are of dimensionality R f × e × r , and R f × d × r , respectively. The right adaptation tensors, W ( R ) x ′ , W ( R ) h ′ are both of dimensionality R r × d × f . We can now use the contextual representation to interpolate the two sets of basis tensors to produce two new weight matrices, W ′ x and W ′ h , where
|
| 98 |
+
|
| 99 |
+
<!-- formula-not-decoded -->
|
| 100 |
+
|
| 101 |
+
The resulting matrices W ′ x , W ′ h are now used as the weights in the RNN cell. A prediction, ˆ y t , is generated in the same manner as in the concatenation-based model.
|
| 102 |
+
|
| 103 |
+
## 4.3 Attention Mechanism
|
| 104 |
+
|
| 105 |
+
We propose an attention mechanism that augments both the concatenation-based and factorizationbased approaches. We apply this mechanism to the context embeddings at each time-step of the RNN model, in order to adapt the context representation dynamically. We hypothesize that at certain time-steps within an utterance, attending to particular datetime information will facilitate the model's predictions more than other information.
|
| 106 |
+
|
| 107 |
+
For instance, assume a LM is given the phrase 'what temperature will it be on friday'. By the time the model has observed the words 'what temperature will', we would expect the model to condition the predictions of the remaining words primarily on the hour and day information. Using an attention mechanism enables us to dynamically weight the importance that the model places on particular datetime context as the model processes an utterance.
|
| 108 |
+
|
| 109 |
+
We assume as input to the attention mechanism the same set M of context representations. However, in the case where datetime information is represented as a feature-engineered vector, we augment M to include an 8-dimensional vector of all 0s: M = { m, 0 } . We do so because our attention mechanism builds a dynamic representation of the context by interpolating over multiple context embeddings. Thus, the attention mechanism can act as a learnable gate to limit the non-linguistic context passed into the model. We also experiment with adding a similar vector of all 0s in the case where context embeddings are learned, but find no improvement.
|
| 110 |
+
|
| 111 |
+
Figure 1: Model architecture of the concatenationbased model using attention. Datetime context is encoded as learned embeddings, and the input word embedding at time-step t is used as the query vector at t .
|
| 112 |
+
|
| 113 |
+
<!-- image -->
|
| 114 |
+
|
| 115 |
+
In addition to the set M , the attention mechanism takes in a query vector, q t , for each time-step t . We propose two methods for defining this query
|
| 116 |
+
|
| 117 |
+
1. Let q t = x t , where x t is the embedding for the input word at time-step t .
|
| 118 |
+
2. Let q t = h t , where h t is the hidden state of the RNN model at time-step t .
|
| 119 |
+
|
| 120 |
+
Importantly, when q t is chosen such that q t = x t , we can parallelize the computation of the attention mechanism for all time-steps before running a forward pass through the model. This cannot be done when q t = h t , as the attention mechanism can only be computed sequentially for each hidden state of the model.
|
| 121 |
+
|
| 122 |
+
Regardless of the choice of q t , the attention mechanism first computes a score for each context embedding m i ∈ M for a given q t . To compute this score, we learn a weight matrix W a . The size of W a is R f × e if q t = x t , or R f × d if q t = h t .
|
| 123 |
+
|
| 124 |
+
For a given m i ∈ M and q t , we calculate a score as
|
| 125 |
+
|
| 126 |
+
<!-- formula-not-decoded -->
|
| 127 |
+
|
| 128 |
+
We then define the alignment score as
|
| 129 |
+
|
| 130 |
+
<!-- formula-not-decoded -->
|
| 131 |
+
|
| 132 |
+
The alignment scores are finally used to build up a dynamic representation of the context, m ′ t , for a given time-step.
|
| 133 |
+
|
| 134 |
+
<!-- formula-not-decoded -->
|
| 135 |
+
|
| 136 |
+
We can now use this constructed context, as the context input to either the concatenation-based or the factorization-based approach.
|
| 137 |
+
|
| 138 |
+
In Figure 1 we illustrate how the attention mechanism augments the concatenation-based approach. For an utterance like 'turn alarm off', we showcase how the model builds a dynamic representation of the datetime context, at a given time-step t ( t = 2 in the figure).
|
| 139 |
+
|
| 140 |
+
## 5 Experimental Setup
|
| 141 |
+
|
| 142 |
+
We used a 1-recurrent-layer LSTM model (Hochreiter and Schmidhuber, 1997) as the base model in all of our experiments. Both the concatenationbased and factorization-based methods can be easily adapted to use an LSTM cell. Models were trained using the Adam optimizer with an initial learning rate of 0.001, and a standard cross entropy loss function. Each of the LMs was trained for
|
| 143 |
+
|
| 144 |
+
Table 1: Test set perplexities of contextual LMs based on datetime information, with relative reductions compared to the Default LSTM model that does not use contextual datetime information. We bold best results within each type of method, and underline best results overall. Improvements in perplexity from using our attention mechanism are statistically significant.
|
| 145 |
+
|
| 146 |
+
| Method Context Approach Attention Query Relative Perplexity Reduction Full Head Tail Default NA NA 0% 0% 0% Prepend Embeddings NA 0.83% 2.54% 0.12% Prepend Feature-engineered NA 1.20% 2.30% 0.74% Concat Embeddings NA 6.82% 2.82% 8.68% Concat Embeddings Hidden 7.00% 2.83% 8.91% Concat Embeddings Word 7.02% 2.89% 8.96% Concat Feature-engineered NA 6.82% 2.65% 8.71% Concat Feature-engineered Hidden 7.0% 2.71% 8.97% Concat Feature-engineered Word 6.94% 2.60% 8.94% Factor Embeddings NA 3.29% 2.26% 3.93% Factor Embeddings Hidden 4.82% 2.53% 5.96% Factor Embeddings Word 5.40% 2.58% 6.71% Factor Feature-engineered NA 5.44% 2.00% 7.10% Factor Feature-engineered Hidden 5.57% 2.31% 6.82% Factor Feature-engineered Word 5.05% 2.25% 6.31% |
|
| 147 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 148 |
+
|
| 149 |
+
400,000 batch update steps, using a batch-size of 256. The training of each model was conducted on a single V100 GPU, with 16GB of memory on a Linux cluster, and took roughly 6 hours to train. Implementation of the model and training procedure was written in PyTorch and native PyTorch libraries. We used a fixed dimensionality of 512 for word, context and hidden state embeddings. We initially experimented with smaller and larger embedding sizes (50, 100, 1024), but found that 512 generally provided a good tradeoff between model performance and compute resources required to train a model. We set the rank of the basis tensors in the factorization-approach to 5, after experimenting with rank sizes 2, 3, 10, 15, 20. In practice, we found that the larger the rank size the less stable the training procedure became. Other hyperparameters, such as the initial learning rate, were selected via random search. We initialized random weights using Xavier-He weight initialization (He et al., 2015).
|
| 150 |
+
|
| 151 |
+
## 6 Results
|
| 152 |
+
|
| 153 |
+
## 6.1 Datetime
|
| 154 |
+
|
| 155 |
+
We evaluated our models on a heldout set of utterances that were randomly sampled from the full dataset. The utterances in our training and evaluation set were collected in the same time-range. We also defined the head and tail subsets of our development set, representing, respectively, the top 5% most frequently occurring utterances, and utterances occurring only once.
|
| 156 |
+
|
| 157 |
+
We used two metrics for our evaluations: perplexity and word error rate. Perplexity is a common statistic widely used in language modeling and speech recognition to measure how well a language model predicts a sample of text (Jelinek et al., 1977). Word error rate, on the other hand, measures the Levenshtein (minimum edit) distance between a recognized word sequence and a reference word sequence. In practice, these two statistics have been shown to be correlated by a power law relationship (Klakow and Peters, 2002).
|
| 158 |
+
|
| 159 |
+
In Table 1, we report the relative decrease in perplexity of models that leveraged datetime context compared to a baseline LSTM model that did not use any contextual information. We additionally trained a simple baseline, Prepend , which was comprised of a standard LSTM model that treated datetime context as input tokens that were prepended to the input texts.
|
| 160 |
+
|
| 161 |
+
In reporting our results, we distinguish between the two forms of representing contextual information: either as learned embeddings or as a featureengineered representation. We also differentiate between the two variants of encoding the query vector used by the attention mechanism: either by using the hidden state vector, or the input embedding at a given time-step.
|
| 162 |
+
|
| 163 |
+
Figure 2: Perplexity confidence bounds at a 95% confidence level for the best-performing concatenation-based and factorization-based models with and without attention. Bounds are evaluated on the full, head and tail partitions of the evaluation set. Perplexity reductions are relative to the Default LSTM model that does not use contextual datetime information.
|
| 164 |
+
|
| 165 |
+
<!-- image -->
|
| 166 |
+
|
| 167 |
+
For the concatenation-based model, we found that adding our attention mechanism led to further reductions in perplexity, regardless of the type of query vector or context representation used. We obtained the best results when representing datetime information as learned embeddings and using the input embedding at a given time-step as the query vector.
|
| 168 |
+
|
| 169 |
+
We corroborated these results by computing 95% confidence intervals for the best-performing concatenation-based models with and without attention. Confidence intervals were calculated by running the training algorithm 10 times for each model type. Figure 2 visualizes the intervals.
|
| 170 |
+
|
| 171 |
+
In the case of the factorization-based approach, we achieved the lowest perplexity when the attention mechanism used the hidden state of the RNN model as the query vector and datetime information was represented as a feature-engineered vector. Again, we found that on the full dataset the improvement in perplexity by using our attention mechanism was statistically significant.
|
| 172 |
+
|
| 173 |
+
In nearly every experiment we ran, we found that our attention mechanism further reduced perplexity. The use of attention led to the largest relative improvement in the factorization-based approach when using learned context embeddings. In this instance, perplexity was reduced by 2.8% on the tail of our evaluation set, and by 2.1% on the full dataset.
|
| 174 |
+
|
| 175 |
+
Table 2: We report relative improvement (decrease) in WER compared to the Default LSTM model that does not use contextual information. Context representation approaches are feature-engineered (FE) or embeddings (Emb).
|
| 176 |
+
|
| 177 |
+
| Method Context Attention WERR (%) Approach Query Full Tail Default NA NA 0.0 0.0 Prepend FE NA 0.0 0.0 Concat Emb Word 1.1 1.2 Factor FE Hidden 0.8 0.8 |
|
| 178 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 179 |
+
|
| 180 |
+
In addition to evaluating the models on relative reductions in perplexity, we also validated the downstream performance of a hybrid CTC-HMM (Graves et al., 2006) ASR system that incorporated contextual information in its LM component. As the LM component of this system, we used the bestperforming models within each category of method that we report in Table 1. Table 2 summarizes the results. We evaluated the relative WER reduction(WERR) on a large test set of de-identified, transcribed utterances representative of general user interactions with Alexa, as well as on the tail of this dataset. As in Table 1, the concatenationbased model with attention mechanism achieved the largest reductions in WER.
|
| 181 |
+
|
| 182 |
+
## 6.2 Other Non-Linguistic Context
|
| 183 |
+
|
| 184 |
+
So far, our experiments have focused exclusively on conditioning neural LMs on datetime context. We underscore, however, that the contextual mechanism we introduce can be applied to any type of contextual information that can be represented as embeddings. To illustrate this point we train two neural LMs using two other types of context: geolocation information and dialogue prompts.
|
| 185 |
+
|
| 186 |
+
Table 3: We report relative improvement (decrease) in WER and (decrease) in perplexity (PPL) compared to the Default LSTM model that does not use contextual information. We report results on both the full test dataset as well as utterances from the tail of the dataset. The best results are underlined.
|
| 187 |
+
|
| 188 |
+
| Context Type Relative PPL Reduction (%) WERR (%) Full Tail Full Tail Default 0.0 0.0 0.0 0.0 Datetime 11.4 11.6 1.6 1.7 Geo-hash 12.4 12.5 0.5 1.0 Dialogue Prompt 13.9 14.1 0.3 0.6 |
|
| 189 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 190 |
+
|
| 191 |
+
We train the LMs on a subset of the utterances of the initial dataset which also contain utterancelevel geo-hash information and dialogue prompt information. The geo-hash information 2 associated with each utterance encodes a very rough estimate of the geolocation of a user's device. Dialogue prompts indicate whether a transcribed utterance was an initial query to the dialog system or if it was a follow-up turn.
|
| 192 |
+
|
| 193 |
+
We learn embeddings to represent both the geohash and the dialogue prompt information. We ingest both types of contexts via the concatenationbased approach, using word-embeddings as the attention queries. We evaluate these models on a test set of de-identified utterances representative of user interactions with Alexa. Table 3 summarizes the results. In general, we find that conditioning neural LMs on each of the different types of context reduces perplexity and WER.
|
| 194 |
+
|
| 195 |
+
## 7 Analysis
|
| 196 |
+
|
| 197 |
+
In this section, we focus once again on datetime information to better understand how contextual LMs use datetime signal.
|
| 198 |
+
|
| 199 |
+
## 7.1 Datetime Context Signal
|
| 200 |
+
|
| 201 |
+
The first question we hope to answer is: to what extent can the relative improvements in perplexity and WER in the models that incorporate datetime context be explained by the additional signal from the context versus the additional parameters that these models contain?
|
| 202 |
+
|
| 203 |
+
To answer this question, we randomly shuffled the datetime information associated with each ut- terance in our training and test sets. For each of our best-performing models in a given category of method (prepend, concat, or factor), we retrained and evaluated those models on the dataset containing shuffled datetime information.
|
| 204 |
+
|
| 205 |
+
2 We use a two integer precision geo-hash.
|
| 206 |
+
|
| 207 |
+
In Table 4, we report the relative degradation (i.e., a negative reduction) in perplexity resulting from evaluating these models on the shuffled datetime contexts. In general, if a model uses datetime information as an additional signal, we would expect the performance of the model to decrease when the datetime context is shuffled.
|
| 208 |
+
|
| 209 |
+
Table 4: Relative degradation in perplexity (PPL) of models that incorporate datetime information when that context is randomly shuffled. Context representations are feature-engineered (FE) or embeddings (Emb).
|
| 210 |
+
|
| 211 |
+
| Method Context Approach Attention Query Relative PPL Reduction (%) Full Tail Prepend FE NA -1.5 -1.2 Concat Emb Word -1.6 -1.2 Factor FE Hidden -1.4 -1.0 |
|
| 212 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 213 |
+
|
| 214 |
+
We observed the overall largest relative degradation in perplexity, when using the concatenationbased model. Recall that when trained on correct datetime information this was our best-performing model overall in terms of both perplexity and WER, indicating that the performance of this model can be attributed in part to its use of contextual information.
|
| 215 |
+
|
| 216 |
+
## 7.1.1 Visual Analysis
|
| 217 |
+
|
| 218 |
+
In addition to these results, we visualize how the contextual LMs leverage datetime contexts. For a given utterance, we can evaluate the probability of the words in the utterance as we vary the datetime information associated with the utterance. In Figure 3, we evaluate the conditional probability of the word 'snooze' in an utterance following the start-of-sentence token, as we vary the hour of day information associated with this utterance. As we would expect, the probability of this 'snooze' is highest in the morning (between 5 and 6 am), as users are waking up and snoozing their alarms. As we move away from the morning hours, the conditional probability of the word 'snooze' decreases substantially, reaching a low-point by the afternoon and evening. The horizontal blue dashed line indicates the conditional probability of the word 'snooze' following the start-of-sentence token when evaluated with a LM that does not ingest datetime information. This analysis further corroborates that the trained contextual LMs successfully condition their predictions on datetime information.
|
| 219 |
+
|
| 220 |
+
Figure 3: Changing conditional probability of the word 'snooze' as the associated hour of day information varies.
|
| 221 |
+
|
| 222 |
+
<!-- image -->
|
| 223 |
+
|
| 224 |
+
## 7.2 Attention Weights
|
| 225 |
+
|
| 226 |
+
We next seek to understand how the attention mechanism constructs a dynamic representations of datetime context. To do so, we visualize the weights of the attention mechanism as an utterance is processed by the model. For a given utterance like 'play me best christmas songs' spoken in December, we highlight the changing weight placed on each of the datetime information. Figure 4 shows this analysis.
|
| 227 |
+
|
| 228 |
+
Figure 4: Changing attention weights placed on particular context embeddings over the course of an utterance.
|
| 229 |
+
|
| 230 |
+
<!-- image -->
|
| 231 |
+
|
| 232 |
+
When the model processes the start-of-sentence token, the attention mechanism weights each of the datetime information roughly equally. However as the model processes the subsequent words 'play me best', the attention begins to shift towards using more of the month information (i.e., that this utterance was spoken in December), and away from hour and day information. This would suggest that conditioning on the fact that the utterance was spoken in December can help the model predict the type of media to play.
|
| 233 |
+
|
| 234 |
+
Once the model observes the word 'christmas', it places all of the attention on the month information, indicating the model has successfully learned that 'christmas' is a word strongly associated with a particular month (i.e., December). Finally when the word 'songs' is ingested, the model substantially reduces the weight placed on month information and in turn increases the weight on hour information. This shift might indicate that the model has learned to condition the type of music users listen to to the hour of the day. Overall, the behavior of the attention mechanism is consistent with our initial hypothesis that certain types of datetime information can benefit a contextual LM model more than others over the course of an utterance.
|
| 235 |
+
|
| 236 |
+
## 8 Related Work
|
| 237 |
+
|
| 238 |
+
Within the domain of ASR, Biadsy et al. (2017) have explored using an adaptive-training approach to incorporate non-linguistic features into a maximum entropy LM. They propose first training the parameters of a LM that are associated with text data, then freezing those parameter and learning parameters associated with multiple types of nonlinguistic features.
|
| 239 |
+
|
| 240 |
+
Zhang et al. (2019) and Yoon et al. (2017) propose a similar two-pronged approach for personalizing conversational neural LMs. They propose first pretraining a RNN-LM on a large dataset of conversational data, then finetuning the model on data associated with a particular user.
|
| 241 |
+
|
| 242 |
+
More recently, Jain et al. (2020) and Liu et al. (2020) propose attention mechanisms for conditioning RNN-T and hybrid ASR systems on words that are likely to occur in an utterance.
|
| 243 |
+
|
| 244 |
+
Another related line of research has explored learning utterance embeddings for dialogue systems using Gaussian mixture models that are enhanced with utterance-level context, such as intent (Yan et al., 2020).
|
| 245 |
+
|
| 246 |
+
Outside of ASR, our work directly builds upon the concatenation-based (Mikolov and Zweig, 2012) and factorization-based (Jaech and Ostendorf, 2018a) approaches to condition RNN-LMs on sentence context. The concatenation-based ap- proach has been adopted as a common method for incorporating non-linguistic context into a neural LM(Yogatama et al., 2017; Wen et al., 2013; Ma et al., 2018; Ghosh et al., 2016). Methods that apply low-rank matrix factorization to RNNs are somewhat newer, and were first explored by Kuchaiev and Ginsburg (2017).
|
| 247 |
+
|
| 248 |
+
Our contribution lies first in the application of these models to ASR, and secondly their extension with an attention mechanism. The attention mechanism we propose builds on the global attention model proposed by Luong et al. (2015). While attention-based models have been used to condition neural models on particular aspects or traits (Zheng et al., 2019; Tang et al., 2016), we focus on contextual information that benefits ASR systems.
|
| 249 |
+
|
| 250 |
+
## 9 Conclusion
|
| 251 |
+
|
| 252 |
+
In this paper, we introduce an attention-based mechanism to condition neural LMs for ASR on non-linguistic contextual information. The proposed model dynamically builds up a representation of contextual information that can be ingested into a RNN-LM via a concatenation-based or factorization-based approach. We find that incorporating datetime context into a LM can yield a relative reduction in perplexity of 9.0% over a model that does not incorporate context. Moreover, the attention mechanism we propose can improve state-of-the-art contextual LM models by over 2.8% relative in terms of perplexity. While we focus on datetime information, we demonstrate that our approach can be applied to any type of non-linguistic context, such as geolocation and dialogue prompts.
|
| 253 |
+
|
| 254 |
+
## References
|
| 255 |
+
|
| 256 |
+
- Dzmitry Bahdanau, Kyunghyun Cho, and Yoshua Bengio. 2014. Neural machine translation by jointly learning to align and translate. CoRR abs/1409.1257 .
|
| 257 |
+
- Fadi Biadsy, Mohammadreza Ghodsi, and Diamantino Caseiro. 2017. Effectively building tera scale MaxEnt language models incorporating non-linguistic signals. In Proc. Interspeech .
|
| 258 |
+
- E. Bocchieri and D. Caseiro. 2010. Use of geographical meta-data in ASR language and acoustic models. In 2010 IEEE International Conference on Acoustics, Speech and Signal Processing , pages 51185121.
|
| 259 |
+
- Shalini Ghosh, Oriol Vinyals, Brian Strope, Scott Roy, Tom Dean, and Larry Heck. 2016. Contextual
|
| 260 |
+
- LSTM (CLSTM) models for large scale NLP tasks. arXiv preprint arXiv:1602.06291 .
|
| 261 |
+
- Alex Graves. 2012. Sequence transduction with recurrent neural networks. In Proceedings of the 29th International Conference on Machine Learning (ICML) .
|
| 262 |
+
- Alex Graves, Santiago Fern´ andez, Faustino Gomez, and J¨ urgen Schmidhuber. 2006. Connectionist temporal classification: Labelling unsegmented sequence data with recurrent neural networks. In Proceedings of the 23rd International Conference on Machine Learning (ICML) , pages 369-376.
|
| 263 |
+
- Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. 2015. Delving deep into rectifiers: Surpassing human-level performance on ImageNet classification. In Proceedings of the IEEE International Conference on Computer Vision , pages 1026-1034.
|
| 264 |
+
- Yanzhang He, Tara N Sainath, Rohit Prabhavalkar, Ian McGraw, Raziel Alvarez, Ding Zhao, David Rybach, Anjuli Kannan, Yonghui Wu, Ruoming Pang, et al. 2019. Streaming end-to-end speech recognition for mobile devices. In ICASSP 2019-2019 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP) , pages 6381-6385. IEEE.
|
| 265 |
+
- Sepp Hochreiter and J¨ urgen Schmidhuber. 1997. Long short-term memory. Neural Computation , 9(8):1735-1780.
|
| 266 |
+
- Aaron Jaech and Mari Ostendorf. 2018a. Low-rank RNN adaptation for context-aware language modeling. Transactions of the Association for Computational Linguistics , 6:497-510.
|
| 267 |
+
- Aaron Jaech and Mari Ostendorf. 2018b. Personalized language model for query auto-completion. In Proceedings of the Annual Meeting of the Association for Computational Linguistics (ACL) , pages 700705.
|
| 268 |
+
- Mahaveer Jain, Gil Keren, Jay Mahadeokar, and Yatharth Saraf. 2020. Contextual RNN-T for open domain ASR. In Proc. Interspeech .
|
| 269 |
+
- Fred Jelinek, Robert L Mercer, Lalit R Bahl, and James K Baker. 1977. Perplexity-a measure of the difficulty of speech recognition tasks. The Journal of the Acoustical Society of America , 62(S1):S63S63.
|
| 270 |
+
- Dietrich Klakow and Jochen Peters. 2002. Testing the correlation of word error rate and perplexity. Speech Communication , 38(1-2):19-28.
|
| 271 |
+
- Oleksii Kuchaiev and Boris Ginsburg. 2017. Factorization tricks for LSTM networks. CoRR abs/1703.10722 .
|
| 272 |
+
- Da-Rong Liu, Chunxi Liu, Frank Zhang, Gabriel Synnaeve, Yatharth Saraf, and Geoffrey Zweig. 2020. Contextualizing ASR lattice rescoring with hybrid pointer network language model. In Proc. Interspeech .
|
| 273 |
+
- Matthew I Lloyd and Trausti Kristjansson. 2012. Acoustic model adaptation using geographic information. US Patent 8,219,384.
|
| 274 |
+
- Minh-Thang Luong, Hieu Pham, and Christopher D Manning. 2015. Effective approaches to attentionbased neural machine translation. In Conference on Empirical Methods in Natural Language Processing (EMNLP) .
|
| 275 |
+
- Min Ma, Shankar Kumar, Fadi Biadsy, Michael Nirschl, Tomas Vykruta, and Pedro Moreno. 2018. Modeling non-linguistic contextual signals in LSTM language models via domain adaptation. In 2018 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP) , pages 6094-6098. IEEE.
|
| 276 |
+
- Tomas Mikolov and Geoffrey Zweig. 2012. Context dependent recurrent neural network language model. In 2012 IEEE Spoken Language Technology Workshop (SLT) , pages 234-239. IEEE.
|
| 277 |
+
- Duyu Tang, Bing Qin, and Ting Liu. 2016. Aspect level sentiment classification with deep memory network. In Conference on Empirical Methods in Natural Language Processing (EMNLP) .
|
| 278 |
+
- Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin. 2017. Attention is all you need. In Advances in Neural Information Processing Systems (NeurIPS) , pages 5998-6008.
|
| 279 |
+
- Tsung-Hsien Wen, Aaron Heidel, Hung-Yi Lee, Yu Tsao, and Lin-Shan Lee. 2013. Recurrent neural network based personalized language modeling by social network crowdsourcing. In Proc. Interspeech .
|
| 280 |
+
- Guangfeng Yan, Lu Fan, Qimai Li, Han Liu, Xiaotong Zhang, Xiao-Ming Wu, and Albert YS Lam. 2020. Unknown intent detection using Gaussian mixture model with an application to zero-shot intent classification. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics (ACL) , pages 1050-1060.
|
| 281 |
+
- Dani Yogatama, Chris Dyer, Wang Ling, and Phil Blunsom. 2017. Generative and discriminative text classification with recurrent neural networks. arXiv preprint arXiv:1703.01898 .
|
| 282 |
+
- Seunghyun Yoon, Hyeongu Yun, Yuna Kim, Gyu-tae Park, and Kyomin Jung. 2017. Efficient transfer learning schemes for personalized language modeling using recurrent neural network. Association for the Advancement of Artificial Intelligence (AAAI) Workshop .
|
| 283 |
+
- Wei-Nan Zhang, Qingfu Zhu, Yifa Wang, Yanyan Zhao, and Ting Liu. 2019. Neural personalized response generation as domain adaptation. World Wide Web , 22(4):1427-1446.
|
| 284 |
+
- Yinhe Zheng, Guanyi Chen, Minlie Huang, Song Liu, and Xuan Zhu. 2019. Personalized dialogue generation with diversified traits. CoRR abs/1901.09672 .
|
text-versions/attention-markdown/2107.00135_Attention Bottlenecks for Multimodal Fus.md
ADDED
|
@@ -0,0 +1,409 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2107.00135 Attention Bottlenecks For Multimodal Fus
|
| 2 |
+
|
| 3 |
+
## Attention Bottlenecks for Multimodal Fusion
|
| 4 |
+
|
| 5 |
+
Arsha Nagrani Shan Yang Anurag Arnab Aren Jansen Cordelia Schmid Chen Sun
|
| 6 |
+
|
| 7 |
+
{anagrani, shanyang, aarnab, arenjansen, cordelias,
|
| 8 |
+
|
| 9 |
+
Google Research
|
| 10 |
+
|
| 11 |
+
## Abstract
|
| 12 |
+
|
| 13 |
+
Humans perceive the world by concurrently processing and fusing highdimensional inputs from multiple modalities such as vision and audio. Machine perception models, in stark contrast, are typically modality-specific and optimised for unimodal benchmarks, and hence late-stage fusion of final representations or predictions from each modality ( 'late-fusion' ) is still a dominant paradigm for multimodal video classification. Instead, we introduce a novel transformer based architecture that uses 'fusion bottlenecks' for modality fusion at multiple layers. Compared to traditional pairwise self-attention, our model forces information between different modalities to pass through a small number of bottleneck latents, requiring the model to collate and condense relevant information in each modality and share what is necessary. We find that such a strategy improves fusion performance, at the same time reducing computational cost. We conduct thorough ablation studies, and achieve state-of-the-art results on multiple audio-visual classification benchmarks including Audioset, Epic-Kitchens and VGGSound. All code and models will be released.
|
| 14 |
+
|
| 15 |
+
## 1 Introduction
|
| 16 |
+
|
| 17 |
+
Simultaneous multimodal sensations are a crucial enabler of human perceptual learning [57]. For artificial learning systems, however, designing a unified model for modality fusion is challenging due to a number of factors: (i) variations in learning dynamics between modalities [63], (ii) different noise topologies, with some modality streams containing more information for the task at hand than others, as well as (iii) specialised input representations. The difference in input representations between audio and vision is particularly stark - many state of the art audio classification methods rely on short term Fourier analysis to produce log-mel spectrograms, often using them as inputs to CNN architectures designed for images [29, 55]. These time-frequency representations have different distributions to images - multiple acoustic objects can have energy at the same frequency, and the translation invariances of CNNs may no longer be a desired property (while an acoustic object can be shifted in time, a shift in frequency could alter the meaning entirely). In contrast, the visual stream in a video is three-dimensional (two spatial and one temporal), and while different spatial regions of the image correspond to different objects, there is the unique challenge of high redundancy across multiple frames. Hence input representations, and consequently neural network architectures and benchmarks tend to vary wildly for different modalities. For simplicity, the dominant paradigm for multimodal fusion therefore often consists of an ad-hoc scheme that involves integrating separate audio and visual networks via their output representations or scores i.e. 'late-fusion' [25, 49].
|
| 18 |
+
|
| 19 |
+
In this work, we present a new transformer based model for audiovisual fusion in video. Despite originally being proposed for NLP tasks, there has been recent interest in transformers [61] as universal perceptual models [32], due to their ability to model dense correlations between tokens, at the same time making few assumptions about their inputs (and because continuous perceptual inputs can be tokenised). By dividing dense continuous signals into patches and rasterising them
|
| 20 |
+
|
| 21 |
+
chensun}@google.com to 1D tokens, transformers have been shown to perform competitively for image (ViT [18]) and video classification (ViViT [6]), and more recently, audio classification (AST [26]). Because these models are able to elegantly handle variable length sequences, a natural first extension would be to feed in a sequence of both visual and auditory patches to a transformer, with minimal changes to the architecture. This 'early fusion' model allows free attention flow between different spatial and temporal regions in the image, as well as across frequency and time in the audio spectrogram. While theoretically appealing, we hypothesise that full pairwise attention at all layers of the model is not necessary because audio and visual inputs contain dense, fine-grained information, much of which is redundant. This is particularly the case for video , as shown by the performance of 'factorised' versions of [6]. Such a model would also not scale well to longer videos due to the quadratic complexity of pairwise attention with token sequence length. To mitigate this, we propose two methods to restrict the flow of attention in our model. The first follows from a common paradigm in multimodal learning, which is to restrict cross-modal flow to later layers of the network, allowing early layers to specialise in learning and extracting unimodal patterns. Henceforth this is is referred to as 'mid fusion' (Fig. 1, middle left), where the layer at which cross-modal interactions are introduced is called the 'fusion layer'. The two extreme versions of this are 'early fusion' (all layers are cross-modal) and 'late fusion' (all are unimodal) which we compare to as a baselines. Our second idea (and main contribution), is to restrict cross-modal attention flow between tokens within a layer. We do this by allowing free attention flow within a modality, but force our model to collate and 'condense' information from each modality before sharing it with the other. The core idea is to introduce a small set of latent fusion units that form an 'attention bottleneck', through which cross-modal interactions within a layer must pass. We demonstrate that this 'bottlenecked' version, which we name Multimodal Bottleneck Transformer ( MBT ), outperforms or matches its unrestricted counterpart, but with lower computational cost.
|
| 22 |
+
|
| 23 |
+
Figure 1: Cross-modal Fusion . Unlike late fusion (left), where no cross-modal information is exchanged in the model until after the classifier, we investigate two pathways for the exchange of cross-modal information. The first is via standard pairwise self attention across all hidden units in a layer, but applied only to later layers in the model - mid fusion (middle, left). We also propose the use of 'fusion bottlenecks' (middle, right) that restrict attention flow within a layer through tight latent units. Both forms of restriction can be applied in conjunction (Bottleneck Mid Fusion) for optimal performance (right). We show B = 2 bottleneck units and 3 hidden units per modality. Grey boxes indicate tokens that receive attention flow from both audio and video tokens.
|
| 24 |
+
|
| 25 |
+
<!-- image -->
|
| 26 |
+
|
| 27 |
+
Concretely, we make the following contributions: (i) We propose a new architecture ( MBT ) for audiovisual fusion. Our model restricts the flow of cross-modal information between latent units through tight fusion 'bottlenecks', that force the model to collect and 'condense' the most relevant inputs in each modality (and therefore share only that which is necessary with the other modality). This avoids the quadratic scaling cost of full pairwise attention, and leads to performance gains with less compute; (ii) We apply MBT to image and spectogram patches (Fig. 2), and explore a number of ablations related to the fusion layer, the sampling of inputs and data size; and finally (iii) We set the new state-of-the-art for video classification across a number of popular audio-visual benchmarks, including AudioSet [24], Epic-Kitchens100 [14] and VGGSound [12]. On the Audioset dataset, we outperform the current state of the art by 5.9 mAP (12.7% relative improvement).
|
| 28 |
+
|
| 29 |
+
## 2 Related work
|
| 30 |
+
|
| 31 |
+
Audiovisual learning: Audiovisual multimodal learning has a rich history, both before and during the deep learning era [53]. Given the limited available data and computational resources, early work focused on relatively simple early-stage (e.g. stacking hand-designed features) and late-stage
|
| 32 |
+
|
| 33 |
+
Figure 2: A Multimodal Fusion Transformer applied to audiovisual inputs. The input sequence consists of image and spectrogram patches. These are then projected into tokens and appended to special CLS (classification) and FSN (fusion bottleneck) tokens. Our transformer encoder then uses self attention to model unimodal information, and restricts cross-modal information flow via cross attention with the bottleneck tokens at multiple layers of the network.
|
| 34 |
+
|
| 35 |
+
<!-- image -->
|
| 36 |
+
|
| 37 |
+
(e.g. score fusion) techniques [13]. Deep learning has allowed more sophisticated strategies in which modality-specific or joint latents are implicitly learned to mediate the fusion. The result has enabled major advances in a range of downstream supervised audiovisual tasks [48, 38, 19]. In the supervised setting, multiple modality-specific convolution networks can be jointly trained, whose intermediate activations are then combined by summation [36] or via 'lateral connections' [64]. In the unsupervised setting, audiovisual learning is commonly used to learn good unimodal representations, with a popular pretraining task being to synchronise signals from different modalities via a contrastive loss [4, 5, 7, 49, 33, 2, 3], however each modality is usually encoded separately under this setup. Multimodal transformers: The self attention operation of transformers provides a natural mechanism to connect multimodal signals. Multimodal transformers have been applied to various tasks including audio enhancement [19, 60], speech recognition [27], image segmentation [66, 60], crossmodal sequence generation [43, 41, 56], image and video retrieval [28, 23, 8], visual navigation [51] and image/video captioning/classification [46, 59, 58, 40, 31]. For many works, the inputs to transformers are the output representations of single modality CNNs [39, 23] - unlike these works we use transformer blocks throughout, using only a single convolutional layer to rasterise 2D patches. The tokens from different modalities are usually combined directly as inputs to the transformers [42], for example, the recently released Perceiver model [32] introduces an iterative attention mechanism which takes concatenated raw multimodal signals as inputs, which corresponds to our 'early fusion' baseline. In contrast, we carefully examine the impact of different modality fusion strategies, including limiting cross-modal attention flow to later layers of our model, and 'channeling' cross-modal connections through bottlenecks in our proposed Multimodal Bottleneck Transformer (MBT).
|
| 38 |
+
|
| 39 |
+
## 3 Multimodal fusion transformers
|
| 40 |
+
|
| 41 |
+
In this section we describe our proposed Multimodal Bottleneck Transformer (MBT). We begin by summarising the recently proposed Vision Transformer (ViT) [18] and Audio Spectrogram Transformer (AST) [26], developed for image and audio classification respectively, in Sec. 3.1. We then describe our extension to the audio-visual fusion case. We discuss three different token fusion strategies (Sec. 3.2), and finally discuss the fusion pathway in the entire model (Sec. 3.3), which involves restricting multimodal fusion to certain layers of the model.
|
| 42 |
+
|
| 43 |
+
## 3.1 The ViT and AST architectures
|
| 44 |
+
|
| 45 |
+
Vision Transformer (ViT) [18] (and a recent extension to audio - Audio Spectrogram Transformer (AST) [26]) adapts the Transformer architecture [61], originally designed for natural language processing, to process 2D inputs with minimal changes. The key insight is to extract N nonoverlapping patches from the RGB image (or the audio spectrogram), x i ∈ R h × w , and convert them into a series of 1D tokens z i ∈ R d , as follows:
|
| 46 |
+
|
| 47 |
+
<!-- formula-not-decoded -->
|
| 48 |
+
|
| 49 |
+
Here, E is a linear projection mapping each token to R d , z cls is a special token prepended to this sequence so that its representation at the final layer can be passed to a classifier for classification tasks [17], and p ∈ R ( N +1) × d is a learned positional embedding added to the tokens to retain positional information (as all subsequent self-attention operations are permutation invariant).
|
| 50 |
+
|
| 51 |
+
The tokens are then passed through an encoder consisting of a sequence of L transformer layers. Each transformer layer consists of Multi-Headed Self-Attention (MSA), Layer Normalisation (LN) and Multilayer Perceptron (MLP) blocks applied using residual connections. We denote a transformer layer, z l +1 = Transformer( z l ) as
|
| 52 |
+
|
| 53 |
+
<!-- formula-not-decoded -->
|
| 54 |
+
|
| 55 |
+
<!-- formula-not-decoded -->
|
| 56 |
+
|
| 57 |
+
Here, the MSA operation [61] computes dot-product attention [61] where the queries, keys and values are all linear projections of the same tensor, MSA( X ) = Attention( W Q X , W K X , W V X ) . We further define Multi-Headed Cross Attention (MCA) between two tensors, X and Y , where X forms the query and Y forms the keys and values which are used to reweight the query as MCA( X , Y ) = Attention( W Q X , W K Y , W V Y ) . This will be used in our multimodal case, as described next.
|
| 58 |
+
|
| 59 |
+
## 3.2 Multimodal transformer
|
| 60 |
+
|
| 61 |
+
We now describe our extension to the multimodal case. We begin by discussing three different token fusion strategies.
|
| 62 |
+
|
| 63 |
+
## 3.2.1 Fusion via vanilla self-attention
|
| 64 |
+
|
| 65 |
+
We begin by describing a 'vanilla' fusion model, which simply consists of the regular transformer applied to multimodal inputs. Our method of tokenising video is straightforward - given a video clip of length t seconds, we uniformly sample F RGB frames and convert the audio waveform into a single spectrogram. We then embed each frame and the spectrogram independently following the encoding proposed in ViT [18], and concatenate all tokens together into a single sequence.
|
| 66 |
+
|
| 67 |
+
Formally, if we have extracted a total of N v RGB patches from all F sampled frames, x rgb ∈ R N v × d , and N a spectrogram patches, x spec ∈ R N a × d , our sequence of tokens is
|
| 68 |
+
|
| 69 |
+
z = [ z rgb || z spec ] where z rgb = g ( x rgb ; E rgb , z cls-rgb ) and z spec = g ( x spec ; E spec , z cls-spec ) . (4) Here, [ z rgb || z spec ] denotes the concatenation of the tokens for each modality. We use different projections E rgb and E spec for RGB and spectrogram patches respectively, and prepend a separate classification token for each modality.
|
| 70 |
+
|
| 71 |
+
Our multimodal encoder then applies a series of transformer layers in the same manner as above. Attention is allowed to flow freely through the network, i.e. each RGB token can attend to all other RGB and spectrogram tokens as follows: z l +1 = Transformer( z l ; θ ) with model parameters θ . Here Transformer refers to a standard transformer layer with vanilla self-attention blocks.
|
| 72 |
+
|
| 73 |
+
## 3.2.2 Fusion with modality-specific parameters
|
| 74 |
+
|
| 75 |
+
We can generalise this model by allowing each modality to have its own dedicated parameters θ rgb and θ spec, but still exchange information via the attention mechanism. For this purpose, we define a Cross-Transformer layer:
|
| 76 |
+
|
| 77 |
+
<!-- formula-not-decoded -->
|
| 78 |
+
|
| 79 |
+
where the Cross-Transformer employs the generalised cross-attention operation that takes two sets of inputs z 1 and z 2 that are not necessarily overlapping. This layer follows the original transformer layer with the difference being that Eq. 2 becomes
|
| 80 |
+
|
| 81 |
+
<!-- formula-not-decoded -->
|
| 82 |
+
|
| 83 |
+
Finally, note that we have explicitly defined the parameters, θ rgb and θ spec of the cross-transformer layers in Eq. 5 as they are different for each modality. However, when θ rgb and θ spec are equal, ( θ rgb = θ spec = θ ), the computation defined in Eq. 5 is equivalent to Sec. 3.2.1.
|
| 84 |
+
|
| 85 |
+
## 3.2.3 Fusion via attention bottlenecks
|
| 86 |
+
|
| 87 |
+
In order to tame the quadratic complexity of pairwise attention, we next introduce a small set of B fusion bottleneck tokens z fsn = [ z 1 fsn , z 2 fsn , . . . , z B fsn ] to our input sequence (see Fig. 2). The input sequence is now
|
| 88 |
+
|
| 89 |
+
<!-- formula-not-decoded -->
|
| 90 |
+
|
| 91 |
+
We then restrict all cross-modal attention flow in our model to be via these bottleneck tokens. More formally for layer l , we compute token representations as follows:
|
| 92 |
+
|
| 93 |
+
<!-- formula-not-decoded -->
|
| 94 |
+
|
| 95 |
+
<!-- formula-not-decoded -->
|
| 96 |
+
|
| 97 |
+
Here i indexes each modality, in this case RGB and Spec, and z rgb and z spec can only exchange information via the bottleneck z fsn within a transformer layer. We first create modality specific temporary bottleneck fusion tokens ˆ z fsn i , which are updated separately and simultaneously with audio and visual information (Equation 8). The final fusion tokens from each cross-modal update are then averaged in Equation 9. We also experiment with asymmetric updates for the bottleneck tokens (see appendix) and found performance was robust to this choice. We keep the number of bottleneck tokens in the network to be much smaller than the total number of latent units per modality ( B ≪ N v and B ≪ N a ). Because all cross-modal attention flow must pass through these units, these tight 'fusion' bottlenecks force the model to condense information from each modality and share that which is necessary. As we show in the experiments, this increases or maintains performance for multimodal fusion, at the same time reducing computational complexity. We also note that our formulation is generic to the type and the number of modalities.
|
| 98 |
+
|
| 99 |
+
## 3.3 Where to fuse: early, mid and late
|
| 100 |
+
|
| 101 |
+
The above strategies discuss fusion within a layer, and in most transformer architectures (such as ViT), every layer consists of an identical set of operations. A common paradigm in multimodal learning, however, is to restrict early layers of a network to focus on unimodal processing, and only introduce cross-modal connections at later layers. This is conceptually intuitive if we believe lower layers are involved in processing low level features, while higher layers are focused on learning semantic concepts - low-level visual features such as edges and corners in images might not have a particular sound signature, and therefore might not benefit from early fusion with audio [64].
|
| 102 |
+
|
| 103 |
+
This can be implemented with our model as follows: We initially perform vanilla self-attention among tokens from a single modality for L f layers. Thereafter, we concatenate all latent tokens together, z L f = [ z L f rgb || z L f spec ] and pass them through the remaining L -L f layers where the tokens are fused according to Sec. 3.2. Here, L f = 0 corresponds to an 'early-fusion' model, L f = L a 'late-fusion' model, and 0 < L f < L a 'mid-fusion' one. More formally, this can be denoted as
|
| 104 |
+
|
| 105 |
+
<!-- formula-not-decoded -->
|
| 106 |
+
|
| 107 |
+
where Multimodal -Transformer( · ) can refer to either of the 3 fusion strategies described in Sec 3.2.
|
| 108 |
+
|
| 109 |
+
## 3.4 Classification
|
| 110 |
+
|
| 111 |
+
For all model variants described above, we pass output representations of the CLS tokens z L cls-rgb and z L cls-spec to the same linear classifier and average the pre-softmax logits.
|
| 112 |
+
|
| 113 |
+
## 4 Experiments
|
| 114 |
+
|
| 115 |
+
We apply MBT to the task of video classification. In this section we first describe the datasets used to train and test multimodal fusion and their respective evaluation protocols (Sec. 4.1), then discuss implementation details (Sec. 4.2). We then ablate the key design choices in our model (Sec. 4.3), before finally comparing our model to the state of the art (Sec. 4.4).
|
| 116 |
+
|
| 117 |
+
## 4.1 Datasets and evaluation protocol
|
| 118 |
+
|
| 119 |
+
We experiment with three video classification datasets - AudioSet [24], Epic-Kitchens-100 [14] and VGGSound [12], described in more detail below. Results on two additional datasets Moments in Time [47] and Kinetics [35] are provided in the appendix.
|
| 120 |
+
|
| 121 |
+
AudioSet [24] consists of almost 2 million 10-second video clips from YouTube, annotated with 527 classes. Like other YouTube datasets, this is a dynamic dataset (we only use the clips still available online). This gives us 20,361 clips for the balanced train set (henceforth referred to as mini-AudioSet or miniAS) and 18,589 clips for the test set. This test set is exactly the same as recent works we compare to, including Perceiver [32]. Instead of using the 2M unbalanced training set, we train on a (slightly more) balanced subset consisting of 500K samples (AS-500K). Details are provided in the appendix. Because each sample has multiple labels, we train with a binary cross-entropy (BCE) loss and report mean average precision (mAP) over all classes, following standard practice.
|
| 122 |
+
|
| 123 |
+
Epic-Kitchens 100 [14] consists of egocentric videos capturing daily kitchen activities. The dataset consists of 90,000 variable length clips spanning 100 hours. We report results for action recognition following standard protocol [14] - each action label is a combination of a verb and noun, and we predict both using a single network with two 'heads', both trained with a cross-entropy loss. The top scoring verb and action pair predicted by the network are used, and Top-1 action accuracy is the primary metric. Actions are mainly short-term (average length is 2.6s with minimum length 0.25s). VGGSound [12] contains almost 200K video clips of length 10s, annotated with 309 sound classes consisting of human actions, sound-emitting objects and human-object interactions. Unlike AudioSet, the sound source for each clip is 'visually present' in the video. This was ensured during dataset creation through the use of image classifiers. After filtering clips that are no longer available on YouTube, we end up with 172,427 training and 14,448 test clips. We train with a standard crossentropy loss for classification and report Top-1 and Top-5 classification accuracy.
|
| 124 |
+
|
| 125 |
+
## 4.2 Implementation details
|
| 126 |
+
|
| 127 |
+
Our backbone architecture follows that of ViT [18] identically, specifically we use ViT-Base (ViT-B, L = 12 , N H = 12 , d = 3072 ) 1 initialised from ImageNet-21K [16], however we note that our method is agnostic to transformer backbone. Unless otherwise specialised, we use B = 4 bottleneck tokens for all experiments with bottleneck fusion. Bottleneck tokens are initialized using a Gaussian with mean of 0 and standard deviation of 0.02, similar to the positional embeddings in the public ViT [18] code. We randomly sample clips of t seconds for training. RGB frames for all datasets are extracted at 25 fps. For AudioSet and VGGSound we sample 8 RGB frames over the sampling window of length t with a uniform stride of length ( t × 25) / 8 . We extract 16 × 16 patches from each frame of size 224 × 224 , giving us a total of 8 × 14 × 14 = 1568 patches per video. For Epic-Kitchens (because the segments are shorter), we sample 32 frames with stride 1. Audio for all datasets is sampled at 16kHz and converted to mono channel. Similar to [26], we extract log mel spectrograms with a frequency dimension of 128 computed using a 25ms Hamming window with hop length 10ms. This gives us an input of size 128 × 100 t for t seconds of audio. Spectrogram patches are extracted with size 16 × 16 , giving us 50 × 8 = 400 patches for 8 seconds of audio. For images we apply the standard data augmentations used in [6] (random crop, flip, colour jitter), and for spectrograms we use SpecAugment [50] with a max time mask length of 192 frames and max frequency mask length of 48 bins following AST [26]. We set the base learning rate to 0 . 5 and train for 50 epochs, using Mixup [67] with α = 0 . 3 and stochastic depth regularisation [30] with probability p = 0 . 3 . All models (across datasets) are trained with a batch size of 64 , synchronous SGD with momentum of 0 . 9 , and a cosine learning rate schedule with warmup of 2 . 5 epochs on TPU accelerators using the Scenic library [15].
|
| 128 |
+
|
| 129 |
+
Inference: Following standard practice, we uniformly sample multiple temporal crops from the clip and average per-view logits to obtain the final result. The number of test crops is set to 4.
|
| 130 |
+
|
| 131 |
+
## 4.3 Ablation analysis
|
| 132 |
+
|
| 133 |
+
In this section we investigate the impact of the different architectural choices in MBT. Unless otherwise specified, we use the mini-AudioSet split for training and report results on the AudioSet eval split. More ablations on backbone size and pretraining initalisation can be found in the appendix.
|
| 134 |
+
|
| 135 |
+
1 L is the number of transformer layers, N H is the number of self-attention heads with hidden dimension d .
|
| 136 |
+
|
| 137 |
+
## 4.3.1 Fusion strategies
|
| 138 |
+
|
| 139 |
+
We implement all the three fusion strategies described in Sec. 3.2:
|
| 140 |
+
|
| 141 |
+
(i) Vanilla self-attention - Unrestricted pairwise attention between all latent units within a layer;
|
| 142 |
+
|
| 143 |
+
(ii) Vanilla cross-attention with separate weights: Same as above, but we now have separate weights for each modality. The latent units are updated via pairwise attention with all other latent units from both modalities; and finally
|
| 144 |
+
|
| 145 |
+
(iii) Bottleneck fusion: Here all cross-modal attention must pass through bottleneck fusion latents. Note that these three fusion strategies only describe attention flow between tokens within a layer. For strategies (ii) and (iii), we also conduct experiments showing the impact of restricting cross-modal attention to layers after a fixed fusion layer L f . We investigate models with different fusion layers,
|
| 146 |
+
|
| 147 |
+
L f = 0 , 2 , 4 , 6 , 8 , 10 , 12 , and present the results in Fig. 3. 2
|
| 148 |
+
|
| 149 |
+
Sharing weights for both modalities: We first investigate the impact of sharing the encoder weights for both modalities (strategy (i) vs (ii)). The results can be found in Fig. 7 in the appendix. When modalities are fused at earlier layers, using separate encoders improves performance. For models with later fusion layers, performance is similar for both models. We hence use separate modality weights for further experiments.
|
| 150 |
+
|
| 151 |
+
Fusion layer: We then investigate the impact of varying the fusion layer L f , for the latter two strategies: (ii) Vanilla Cross-Attention and (iii) Bottleneck Fusion. We conduct experiments with L f = 0 , 2 , 4 , 6 , 8 , 10 , 12 . We fix the input span t to 4s and the number of bottleneck tokens B to 4 . We conduct 3 runs for each experiment and report mean and std deviation. As can be seen from Fig. 3 (left), 'mid fusion' outperforms both early ( L f = 0 ) and late fusion ( L f = 12 ), with optimal performance obtained by using fusion layer L f = 10 for vanilla cross-attention and L f = 8 for bottleneck attention. This suggests that the model benefits from restricting cross-modal connections to later layers, allowing earlier layers to specialise to learning unimodal features, however still benefits from multiple layers of cross-modal information flow. In appendix D , we confirm that mid fusion outperforms late fusion across a number of different datasets.
|
| 152 |
+
|
| 153 |
+
Attention bottlenecks: In Fig. 3, we also examine the effect of bottleneck attention vs vanilla cross-attention for multimodal fusion. We find that for all values of L f restricting flow to bottlenecks improves or maintains performance, with improvements more prominent at lower values of L f . At L f = 10 , both perform similarly, note that at this stage we only have 3 fusion layers in the model. Our best performing model uses attention bottlenecks with L f = 8 , and we fix this for all further experiments. We also compare the amount of computation, measured in GFLOPs, for both fusion strategies (Fig. 3, right). Using a small number of bottleneck tokens (in our experiments B = 4 ) adds negligible extra computation over a late fusion model, with computation remaining largely constant with varying fusion layer L f . This is in contrast to vanilla cross-fusion, which has a non-negligible computational cost for every layer it is applied to. We note that for early fusion ( L f = 0 ), bottleneck fusion outperforms vanilla cross-attention by over 2 mAP, with less than half the computational cost. Number of bottleneck tokens B : We experiment with B = 4 , 36 , 64 , 256 and 1024 , and find that performance is relatively consistent (all within 0.5 mAP). We hence fix the number of tokens to B = 4 for all experiments. It is interesting that with such a small number of cross-modal connections through only 4 hidden units ( B = 4 ) at each cross-modal layer, we get large performance gains over late fusion (Fig. 3), highlighting the importance of allowing cross-modal information to flow at multiple layers of the model.
|
| 154 |
+
|
| 155 |
+
## 4.3.2 Input sampling and dataset size
|
| 156 |
+
|
| 157 |
+
In this section we investigate the impact of different modality sampling strategies. We also compare to single modality baselines - the visual-only and audio-only baselines consist of a vanilla transformer model applied to only the RGB or spectrogram patches respectively.
|
| 158 |
+
|
| 159 |
+
Sampling window size t : An advantage of our transformer based model is that we can easily input variable length token sequences. We experiment with varying the sampling window t with the following values t = 2 , 4 , 6 and 8 seconds (note that all videos in AudioSet are 10s), and show results in Fig. 4 3 . At inference, we uniformly sample multiple windows covering the entire video. While the number of spectrogram patches N a changes with t , we keep the number of RGB patches N v fixed by changing the stride of frames (to avoid running out of memory). Our results indicate that the performance of both the audio and audio-visual fusion model increases with input span, however the performance of the visual-only model slightly decreases (we hypothesize that this is due to the increased fixed stride, meaning fewer frames are randomly sampled during training). We fix t = 8 s in all further experiments.
|
| 160 |
+
|
| 161 |
+
2 Note that L f = 12 refers to late fusion, where logits are only aggregated after the classifiers, and neither fusion strategy (ii) nor (iii) is applied, but we show results on the same plot for convenience.
|
| 162 |
+
|
| 163 |
+
3 Averaged over 3 runs. Because error bars are small in the plot we also provide them in Table 6 in the appendix.
|
| 164 |
+
|
| 165 |
+
<!-- image -->
|
| 166 |
+
|
| 167 |
+
Figure 3: The impact of using attention bottlenecks for fusion on performance (left) and compute (right) at different fusion layers L f on AudioSet, using clip span t = 4 and B = 4 bottleneck tokens. Attention bottlenecks improve performance at lower computational cost.
|
| 168 |
+
|
| 169 |
+
Figure 4: The effect of varying input clip span t on the AudioSet test set.
|
| 170 |
+
|
| 171 |
+
<!-- image -->
|
| 172 |
+
|
| 173 |
+
Figure 5: The effect of training data size on the AudioSet test set.
|
| 174 |
+
|
| 175 |
+
<!-- image -->
|
| 176 |
+
|
| 177 |
+
Synchronous vs asynchronous sampling: Given that auditory and visual events may not always be perfected aligned in videos [36], we also investigate asynchronous sampling of different modalities. Here input windows are sampled independently from the entire video clip for each modality. Results are provided in Fig. 8 in the appendix. We find performance to be largely robust to either case, and so for simplicity we use synchronised sampling for all further experiments.
|
| 178 |
+
|
| 179 |
+
Modality MixUp: While applying Mixup regularization [67] to training, we note that there are two different ways to apply it for multimodal inputs - the standard approach is to sample one set of mixup weights from a Beta distribution using the parameter α , and use it to generate all virtual modality-label pairs [67]. We also explore a modified version which we call modality mixup , which samples an independent weight for each modality. Modality mixup imposes stronger augmentation than standard mixup, leading to a slight improvement (42.6 mAP to 43.9 mAP) on AudioSet.
|
| 180 |
+
|
| 181 |
+
Impact of dataset size: We show the impact of varying the number of training samples in Fig. 5, and find a monotonic increase with dataset size (more steeply for audio-only than visual-only).
|
| 182 |
+
|
| 183 |
+
## 4.4 Results
|
| 184 |
+
|
| 185 |
+
Comparison to single modality performance: We compare MBT to visual-only and audio-only baselines on AudioSet (Table 1), Epic-Kitchens (Table 2) and VGGSound (Table 3). Note we use the best parameters obtained via the ablations above, i.e. bottleneck fusion with t = 8 , B = 4 , F l = 8 and modality mixup. For all datasets, multimodal fusion outperforms the higher-performing single modality baseline, demonstrating the value of complementary information. The relative importance of modalities for the classification labels varies (audio-only has higher relative performance for AudioSet and lower for Epic-Kitchens, while both audio and visual baselines are equally strong for VGGSound). This is (unsurprisingly) largely a function of the dataset annotation procedure and positions VGGSound as a uniquely suitable dataset for fusion. We also show that audio-visual fusion provides slight performance gains for traditionally video only datasets such as Kinetics and Moments in Time (details provided in Appendix C ). We also examine per-class performance on the Audioset dataset (Figures 9 and 10 in the Appendix), and find that for the top 60 classes (ranked by overall performance), audio-visual fusion improves performance over audio only or visual only for almost all (57 out of 60) classes, except for 'bagpiping', 'emergency vehicle' and 'didgeridoo' which have strong audio signatures. For classes such as 'bicycle' and 'shuffling cards' where audio signals are weaker, fusion improves over the audio-only baseline by over 60% in absolute AP.
|
| 186 |
+
|
| 187 |
+
Table 1: Comparison to SOTA on AudioSet [24]. We report mean average precision (mAP). We outperform works that train on the full Audioset (2M samples), while we train on only 500K samples.
|
| 188 |
+
|
| 189 |
+
| Model Training Set A only V only AV Fusion GBlend [63] MiniAS 29.1 22.1 37.8 GBlend [63] FullAS-2M 32.4 18.8 41.8 Attn Audio-Visual [21] FullAS-2M 38.4 25.7 46.2 Perceiver [32] FullAS-2M 38.4 25.8 44.2 MBT MiniAS 31.3 27.7 43.9 MBT AS-500K 41.5 31.3 49.6 |
|
| 190 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 191 |
+
|
| 192 |
+
Table 2: Comparison to SOTA on EpicKitchens-100 [14] . Modalities are A: Audio, V: Visual, F: Optical flow. † Uses pretraining on VGGSound.
|
| 193 |
+
|
| 194 |
+
| Model Modalities Verb Noun Action Damen et al. [14] A 42.1 21.5 14.8 AudioSlowFast [37] † A 46.5 22.78 15.4 TSN [62] V, F 60.2 46.0 33.2 TRN [68] V, F 65.9 45.4 35.3 TBN [36] A, V, F 66.0 47.2 36.7 TSM [45] V, F 67.9 49.0 38.3 SlowFast [22] V 65.6 50.0 38.5 MBT A 44.3 22.4 13.0 MBT V 62.0 56.4 40.7 MBT A, V 64.8 58.0 43.4 |
|
| 195 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 196 |
+
|
| 197 |
+
Comparison to state of the art: We compare MBT to previous fusion methods on AudioSet in Table 1. We outperform all previous works on fusion (even though we only train on a quarter of the training set - 500K samples), including the recently introduced Perceiver [32] which uses early fusion followed by multiple self attention layers, and Attn Audio-Visual [21] which uses self-attention fusion on top of individual modality CNNs. We compare to previous video classification methods on Epic-Kitchens in Table 2, and note that our model outperforms all previous works that use vision only, as well as TBN [36] which uses three modalities - RGB, audio and optical flow. Given VGGSound is a relatively new dataset, we compare to two existing audio-only works 4 (Table 3), and set the first audiovisual benchmark (that we are aware of) on this dataset.
|
| 198 |
+
|
| 199 |
+
Table 3: Comparison to the state of the art on VGGSound [12] . Modalities are A: Audio, V: Visual, F: Optical flow. ‡ We calculate metrics on our test set for a fair comparison using the scores provided by the authors.
|
| 200 |
+
|
| 201 |
+
| Model Modalities Top-1 Acc Top-5 Acc Chen et al ‡ [12] A 48.8 76.5 AudioSlowFast ‡ [37] A 50.1 77.9 MBT A 52.3 78.1 MBT V 51.2 72.6 MBT A,V 64.1 85.6 |
|
| 202 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 203 |
+
|
| 204 |
+
Figure 6: Attention Maps. We compute maps of the attention from the output CLS tokens to the RGB image input space for a vanilla self-attention model and MBT on the Audioset test set. For each video clip, we show the original middle frame on the left with the ground truth labels overlayed at the bottom. The attention is particularly focused on sound source regions in the video that contain motion, eg. the fingertips on the piano, the hands on the string instrument, faces of humans. The bottlenecks in MBT further force the attention to be localised to smaller regions of the images (i.e the mouth of the baby on the top left and the mouth of the woman singing on the bottom right).
|
| 205 |
+
|
| 206 |
+
<!-- image -->
|
| 207 |
+
|
| 208 |
+
Visualisation of attention maps Finally, we compute maps of the attention from the output CLS tokens to the RGB image input space using Attention Rollout [1]. Results on test images for both a vanilla fusion model and MBT trained on Audioset-mini (fusion layer L f = 8 ) are shown in Figure 6. We show the attention maps summed over all the frames in the video clip. We note that first, the model focuses on semantically salient regions in the video for audio classification, particularly regions where there is motion that creates or modifies sound, i.e. the mouth of humans making sounds, fingertips on a piano, hands and instruments. This is unlike state of the art sound source localisation techniques trained with images [11], which tend to highlight the entire object. We further note that the attention maps for MBT are more localised to these regions, showing that the tight bottlenecks do force the model to focus only on the image patches that are actually relevant for the audio classification task and which benefit from early fusion with audio.
|
| 209 |
+
|
| 210 |
+
## 5 Conclusion
|
| 211 |
+
|
| 212 |
+
We propose a new transformer architecture ( MBT ) for audiovisual fusion, and explore a number of different fusion strategies using cross-attention between latent tokens. We propose a novel strategy to restrict cross-modal attention via a small set of fusion 'bottlenecks', and demonstrate that this improves performance over vanilla cross-attention at lower computational cost, achieving state of the art results on a number of benchmarks. Future work will involve extending MBT to other modalities such as text and optical flow.
|
| 213 |
+
|
| 214 |
+
Limitations: The fusion layer is a hyperparameter and may need to be tuned specifically for different tasks and datasets. We also only explore fully supervised fusion, and future work will tackle extensions to a self-supervised learning framework.
|
| 215 |
+
|
| 216 |
+
Broader impact: Multimodal fusion strategies are important for machine learning, as fusing complementary information from different modalities can increase robustness when applied to real world applications. We also note that transformers are in general compute-heavy, which can have adverse environmental effects. We propose a token fusion method via bottlenecks that helps reduce computational complexity when applying transformers for multimodal fusion. Finally, we observe that training datasets contain biases that may render models trained on them unsuitable for certain applications. It is thus possible that people use classification models (intentionally or not) to make decisions that impact different groups in society differently, and it is important to keep this in mind when deploying, analysing and building upon these models.
|
| 217 |
+
|
| 218 |
+
4 To fairly compare to these works, we obtain the scores on the full VGGSound test set from the authors, and compute accuracy metrics on our slightly smaller test set as described in Sec. 4.1.
|
| 219 |
+
|
| 220 |
+
Acknowledgements: We would like to thank Joao Carreira for helpful discussions on the Perceiver [32].
|
| 221 |
+
|
| 222 |
+
## References
|
| 223 |
+
|
| 224 |
+
- [1] Samira Abnar and Willem Zuidema. Quantifying attention flow in transformers. arXiv preprint arXiv:2005.00928 , 2020.
|
| 225 |
+
- [2] Hassan Akbari, Linagzhe Yuan, Rui Qian, Wei-Hong Chuang, Shih-Fu Chang, Yin Cui, and Boqing Gong. Vatt: Transformers for multimodal self-supervised learning from raw video, audio and text. NeurIPS , 2021.
|
| 226 |
+
- [3] Jean-Baptiste Alayrac, Adrià Recasens, Rosalia Schneider, Relja Arandjelovi´ c, Jason Ramapuram, Jeffrey De Fauw, Lucas Smaira, Sander Dieleman, and Andrew Zisserman. Self-supervised multimodal versatile networks. In NeurIPS , 2020.
|
| 227 |
+
- [4] Relja Arandjelovic and Andrew Zisserman. Look, listen and learn. In ICCV , 2017.
|
| 228 |
+
- [5] Relja Arandjelovic and Andrew Zisserman. Objects that sound. In ECCV , 2018.
|
| 229 |
+
- [6] Anurag Arnab, Mostafa Dehghani, Georg Heigold, Chen Sun, Mario Luˇ ci´ c, and Cordelia Schmid. Vivit: A video vision transformer. ICCV , 2021.
|
| 230 |
+
- [7] Yusuf Aytar, Carl Vondrick, and Antonio Torralba. Soundnet: Learning sound representations from unlabeled video. In NeurIPS , 2016.
|
| 231 |
+
- [8] Max Bain, Arsha Nagrani, Gül Varol, and Andrew Zisserman. Frozen in time: A joint video and image encoder for end-to-end retrieval. ICCV , 2021.
|
| 232 |
+
- [9] Yunlong Bian, Chuang Gan, Xiao Liu, Fu Li, Xiang Long, Yandong Li, Heng Qi, Jie Zhou, Shilei Wen, and Yuanqing Lin. Revisiting the effectiveness of off-the-shelf temporal modeling approaches for large-scale video classification. arXiv preprint arXiv:1708.03805 , 2017.
|
| 233 |
+
- [10] Joao Carreira and Andrew Zisserman. Quo vadis, action recognition? a new model and the kinetics dataset. In CVPR , 2017.
|
| 234 |
+
- [11] Honglie Chen, Weidi Xie, Triantafyllos Afouras, Arsha Nagrani, Andrea Vedaldi, and Andrew Zisserman. Localizing visual sounds the hard way. In CVPR , 2021.
|
| 235 |
+
- [12] Honglie Chen, Weidi Xie, Andrea Vedaldi, and Andrew Zisserman. VGGSound: A large-scale audio-visual dataset. In ICASSP , 2020.
|
| 236 |
+
- [13] Tsuhan Chen and Ram R Rao. Audio-visual integration in multimodal communication. Proceedings of the IEEE , 86(5):837-852, 1998.
|
| 237 |
+
- [14] Dima Damen, Hazel Doughty, Giovanni Maria Farinella, Antonino Furnari, Evangelos Kazakos, Jian Ma, Davide Moltisanti, Jonathan Munro, Toby Perrett, Will Price, et al. Rescaling egocentric vision. arXiv preprint arXiv:2006.13256 , 2020.
|
| 238 |
+
- [15] Mostafa Dehghani, Alexey Gritsenko, Anurag Arnab, Matthias Minderer, and Yi Tay. Scenic: A JAX library for computer vision research and beyond. arXiv preprint arXiv:2110.11403 , 2021.
|
| 239 |
+
- [16] Jia Deng, Wei Dong, Richard Socher, Li-Jia Li, Kai Li, and Li Fei-Fei. Imagenet: A large-scale hierarchical image database. In CVPR , pages 248-255. Ieee, 2009.
|
| 240 |
+
- [17] Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. Bert: Pre-training of deep bidirectional transformers for language understanding. In NAACL , 2019.
|
| 241 |
+
- [18] Alexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn, Xiaohua Zhai, Thomas Unterthiner, Mostafa Dehghani, Matthias Minderer, Georg Heigold, Sylvain Gelly, et al. An image is worth 16x16 words: Transformers for image recognition at scale. arXiv preprint arXiv:2010.11929 , 2020.
|
| 242 |
+
|
| 243 |
+
- [19] Ariel Ephrat, Inbar Mosseri, Oran Lang, Tali Dekel, Kevin Wilson, Avinatan Hassidim, William T Freeman, and Michael Rubinstein. Looking to listen at the cocktail party: a speaker-independent audio-visual model for speech separation. ACM Transactions on Graphics (TOG) , 37(4):1-11, 2018.
|
| 244 |
+
- [20] Quanfu Fan, Chun-Fu Chen, Hilde Kuehne, Marco Pistoia, and David Cox. More is less: Learning efficient video representations by big-little network and depthwise temporal aggregation. arXiv preprint arXiv:1912.00869 , 2019.
|
| 245 |
+
- [21] Haytham M Fayek and Anurag Kumar. Large scale audiovisual learning of sounds with weakly labeled data. arXiv preprint arXiv:2006.01595 , 2020.
|
| 246 |
+
- [22] Christoph Feichtenhofer, Haoqi Fan, Jitendra Malik, and Kaiming He. Slowfast networks for video recognition. In ICCV , pages 6202-6211, 2019.
|
| 247 |
+
- [23] Valentin Gabeur, Chen Sun, Karteek Alahari, and Cordelia Schmid. Multi-modal transformer for video retrieval. In ECCV , volume 5. Springer, 2020.
|
| 248 |
+
- [24] Jort F Gemmeke, Daniel PW Ellis, Dylan Freedman, Aren Jansen, Wade Lawrence, R Channing Moore, Manoj Plakal, and Marvin Ritter. Audio set: An ontology and human-labeled dataset for audio events. In ICASSP , pages 776-780. IEEE, 2017.
|
| 249 |
+
- [25] Bernard Ghanem, Juan Carlos Niebles, Cees Snoek, Fabian Caba Heilbron, Humam Alwassel, Victor Escorcia, Ranjay Krishna, Shyamal Buch, and Cuong Duc Dao. The activitynet largescale activity recognition challenge 2018 summary. arXiv preprint arXiv:1808.03766 , 2018.
|
| 250 |
+
- [26] Yuan Gong, Yu-An Chung, and James Glass. AST: audio spectrogram transformer. arXiv preprint arXiv:2104.01778 , 2021.
|
| 251 |
+
- [27] David Harwath, Antonio Torralba, and James R Glass. Unsupervised learning of spoken language with visual context. NeurIPS , 2017.
|
| 252 |
+
- [28] Lisa Anne Hendricks, John Mellor, Rosalia Schneider, Jean-Baptiste Alayrac, and Aida Nematzadeh. Decoupling the role of data, attention, and losses in multimodal transformers. arXiv preprint arXiv:2102.00529 , 2021.
|
| 253 |
+
- [29] Shawn Hershey, Sourish Chaudhuri, Daniel PW Ellis, Jort F Gemmeke, Aren Jansen, R Channing Moore, Manoj Plakal, Devin Platt, Rif A Saurous, Bryan Seybold, et al. CNN architectures for large-scale audio classification. In ICASSP , pages 131-135. IEEE, 2017.
|
| 254 |
+
- [30] Gao Huang, Yu Sun, Zhuang Liu, Daniel Sedra, and Kilian Q Weinberger. Deep networks with stochastic depth. In ECCV , 2016.
|
| 255 |
+
- [31] Vladimir Iashin and Esa Rahtu. Multi-modal dense video captioning. In CVPR Workshops , pages 958-959, 2020.
|
| 256 |
+
- [32] Andrew Jaegle, Felix Gimeno, Andrew Brock, Andrew Zisserman, Oriol Vinyals, and Joao Carreira. Perceiver: General perception with iterative attention. arXiv preprint arXiv:2103.03206 , 2021.
|
| 257 |
+
- [33] Aren Jansen, Daniel PW Ellis, Shawn Hershey, R Channing Moore, Manoj Plakal, Ashok C Popat, and Rif A Saurous. Coincidence, categorization, and consolidation: Learning to recognize sounds with minimal supervision. In ICASSP , 2020.
|
| 258 |
+
- [34] Boyuan Jiang, MengMeng Wang, Weihao Gan, Wei Wu, and Junjie Yan. Stm: Spatiotemporal and motion encoding for action recognition. In ICCV , pages 2000-2009, 2019.
|
| 259 |
+
- [35] Will Kay, Joao Carreira, Karen Simonyan, Brian Zhang, Chloe Hillier, Sudheendra Vijayanarasimhan, Fabio Viola, Tim Green, Trevor Back, Paul Natsev, et al. The kinetics human action video dataset. arXiv preprint arXiv:1705.06950 , 2017.
|
| 260 |
+
- [36] Evangelos Kazakos, Arsha Nagrani, Andrew Zisserman, and Dima Damen. Epic-fusion: Audiovisual temporal binding for egocentric action recognition. In Proceedings of the IEEE/CVF International Conference on Computer Vision , pages 5492-5501, 2019.
|
| 261 |
+
|
| 262 |
+
- [37] Evangelos Kazakos, Arsha Nagrani, Andrew Zisserman, and Dima Damen. Slow-fast auditory streams for audio recognition. In ICASSP , pages 855-859. IEEE, 2021.
|
| 263 |
+
- [38] Yelin Kim, Honglak Lee, and Emily Mower Provost. Deep learning for robust feature generation in audiovisual emotion recognition. In ICASSP . IEEE, 2013.
|
| 264 |
+
- [39] Sangho Lee, Youngjae Yu, Gunhee Kim, Thomas Breuel, Jan Kautz, and Yale Song. Parameter efficient multimodal transformers for video representation learning. arXiv preprint arXiv:2012.04124 , 2020.
|
| 265 |
+
- [40] Guang Li, Linchao Zhu, Ping Liu, and Yi Yang. Entangled transformer for image captioning. In ICCV , pages 8928-8937, 2019.
|
| 266 |
+
- [41] Jiaman Li, Yihang Yin, Hang Chu, Yi Zhou, Tingwu Wang, Sanja Fidler, and Hao Li. Learning to generate diverse dance motions with transformer. arXiv preprint arXiv:2008.08171 , 2020.
|
| 267 |
+
- [42] Liunian Harold Li, Mark Yatskar, Da Yin, Cho-Jui Hsieh, and Kai-Wei Chang. Visualbert: A simple and performant baseline for vision and language. arXiv preprint arXiv:1908.03557 , 2019.
|
| 268 |
+
- [43] Ruilong Li, Shan Yang, David A Ross, and Angjoo Kanazawa. Learn to dance with aist++: Music conditioned 3d dance generation. arXiv preprint arXiv:2101.08779 , 2021.
|
| 269 |
+
- [44] Yan Li, Bin Ji, Xintian Shi, Jianguo Zhang, Bin Kang, and Limin Wang. Tea: Temporal excitation and aggregation for action recognition. In CVPR , pages 909-918, 2020.
|
| 270 |
+
- [45] Ji Lin, Chuang Gan, and Song Han. Temporal shift module for efficient video understanding. 2019 ieee. In ICCV , pages 7082-7092, 2019.
|
| 271 |
+
- [46] Jiasen Lu, Dhruv Batra, Devi Parikh, and Stefan Lee. Vilbert: Pretraining task-agnostic visiolinguistic representations for vision-and-language tasks. In NeurIPS , 2019.
|
| 272 |
+
- [47] Mathew Monfort, Alex Andonian, Bolei Zhou, Kandan Ramakrishnan, Sarah Adel Bargal, Tom Yan, Lisa Brown, Quanfu Fan, Dan Gutfreund, Carl Vondrick, et al. Moments in time dataset: one million videos for event understanding. IEEE transactions on pattern analysis and machine intelligence , 42(2):502-508, 2019.
|
| 273 |
+
- [48] Jiquan Ngiam, Aditya Khosla, Mingyu Kim, Juhan Nam, Honglak Lee, and Andrew Y Ng. Multimodal deep learning. In ICML , 2011.
|
| 274 |
+
- [49] Andrew Owens and Alexei A Efros. Audio-visual scene analysis with self-supervised multisensory features. In ECCV , 2018.
|
| 275 |
+
- [50] Daniel S Park, William Chan, Yu Zhang, Chung-Cheng Chiu, Barret Zoph, Ekin D Cubuk, and Quoc V Le. Specaugment: A simple data augmentation method for automatic speech recognition. arXiv preprint arXiv:1904.08779 , 2019.
|
| 276 |
+
- [51] Alexander Pashevich, Cordelia Schmid, and Chen Sun. Episodic transformer for vision-andlanguage navigation. In ICCV , 2021.
|
| 277 |
+
- [52] Zhaofan Qiu, Ting Yao, Chong-Wah Ngo, Xinmei Tian, and Tao Mei. Learning spatio-temporal representation with local and global diffusion. In CVPR , 2019.
|
| 278 |
+
- [53] Dhanesh Ramachandram and Graham W Taylor. Deep multimodal learning: A survey on recent advances and trends. IEEE Signal Processing Magazine , 34(6):96-108, 2017.
|
| 279 |
+
- [54] Michael S Ryoo, AJ Piergiovanni, Mingxing Tan, and Anelia Angelova. Assemblenet: Searching for multi-stream neural connectivity in video architectures. arXiv preprint arXiv:1905.13209 , 2019.
|
| 280 |
+
- [55] Justin Salamon and Juan Pablo Bello. Deep convolutional neural networks and data augmentation for environmental sound classification. IEEE Signal Processing Letters , 24(3):279-283, 2017.
|
| 281 |
+
|
| 282 |
+
- [56] Paul Hongsuck Seo, Arsha Nagrani, and Cordelia Schmid. Look before you speak: Visually contextualized utterances. In CVPR , 2021.
|
| 283 |
+
- [57] Linda Smith and Michael Gasser. The development of embodied cognition: Six lessons from babies. Artificial life , 11(1-2):13-29, 2005.
|
| 284 |
+
- [58] Chen Sun, Fabien Baradel, Kevin Murphy, and Cordelia Schmid. Learning video representations using contrastive bidirectional transformer. arXiv preprint arXiv:1906.05743 , 2019.
|
| 285 |
+
- [59] Chen Sun, Austin Myers, Carl Vondrick, Kevin Murphy, and Cordelia Schmid. Videobert: A joint model for video and language representation learning. In ICCV , 2019.
|
| 286 |
+
- [60] Efthymios Tzinis, Scott Wisdom, Aren Jansen, Shawn Hershey, Tal Remez, Daniel PW Ellis, and John R Hershey. Into the wild with audioscope: Unsupervised audio-visual separation of on-screen sounds. arXiv preprint arXiv:2011.01143 , 2020.
|
| 287 |
+
- [61] Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Lukasz Kaiser, and Illia Polosukhin. Attention is all you need. arXiv preprint arXiv:1706.03762 , 2017.
|
| 288 |
+
- [62] Limin Wang, Yuanjun Xiong, Zhe Wang, Yu Qiao, Dahua Lin, Xiaoou Tang, and Luc Van Gool. Temporal segment networks: Towards good practices for deep action recognition. In ECCV . Springer, 2016.
|
| 289 |
+
- [63] Weiyao Wang, Du Tran, and Matt Feiszli. What makes training multi-modal classification networks hard? In CVPR , pages 12695-12705, 2020.
|
| 290 |
+
- [64] Fanyi Xiao, Yong Jae Lee, Kristen Grauman, Jitendra Malik, and Christoph Feichtenhofer. Audiovisual slowfast networks for video recognition. arXiv preprint arXiv:2001.08740 , 2020.
|
| 291 |
+
- [65] Saining Xie, Chen Sun, Jonathan Huang, Zhuowen Tu, and Kevin Murphy. Rethinking spatiotemporal feature learning: Speed-accuracy trade-offs in video classification. In ECCV , 2018.
|
| 292 |
+
- [66] Linwei Ye, Mrigank Rochan, Zhi Liu, and Yang Wang. Cross-modal self-attention network for referring image segmentation. In CVPR , 2019.
|
| 293 |
+
- [67] Hongyi Zhang, Moustapha Cisse, Yann N Dauphin, and David Lopez-Paz. mixup: Beyond empirical risk minimization. arXiv preprint arXiv:1710.09412 , 2017.
|
| 294 |
+
- [68] Bolei Zhou, Alex Andonian, Aude Oliva, and Antonio Torralba. Temporal relational reasoning in videos. In ECCV , pages 803-818, 2018.
|
| 295 |
+
|
| 296 |
+
Here we provide additional ablation results on mini-Audioset (Sec. A) as well as analyse the per-class average precision of fusion over single modality baselines (Sec. B). We then provide results on two additional datasets, Moments in Time and Kinetics in Sec. C and perform some preliminary transfer learning experiments in Sec. E. Finally we provide details on the AS-500K split.
|
| 297 |
+
|
| 298 |
+
## A Ablations on mini-Audioset
|
| 299 |
+
|
| 300 |
+
In this section we expand on the ablations provided in Sec. 4.3 of the main paper. Unless otherwise specified, ablations are performed using Audioset-mini as the training set and the Audioset test set for evaluation. For most experiments we conduct 3 runs and report mean and standard deviation.
|
| 301 |
+
|
| 302 |
+
## A.1 Symmetric vs asymmetric bottleneck updates
|
| 303 |
+
|
| 304 |
+
We also experiment with an asymmetric bottleneck update. This involves replacing Eq. 8 and 9 with the following:
|
| 305 |
+
|
| 306 |
+
<!-- formula-not-decoded -->
|
| 307 |
+
|
| 308 |
+
<!-- formula-not-decoded -->
|
| 309 |
+
|
| 310 |
+
Here the bottleneck tokens are updated twice, first with visual information (Equation 10), and then with audio information (Equation 11). We also experimented with updating the bottlenecks with audio information first and compare both variations to the symmetric update in Table 4. We find performance is robust to all variations.
|
| 311 |
+
|
| 312 |
+
Table 4: Asymmetric vs symmetric bottleneck updates.
|
| 313 |
+
|
| 314 |
+
| RGB first Spec first Symmetric updates 43.42 ± 0.19 43.23 ± 0.12 43.66 ± 0.26 |
|
| 315 |
+
|--------------------------------------------------------------------------------------------|
|
| 316 |
+
|
| 317 |
+
## A.2 Backbone architecture
|
| 318 |
+
|
| 319 |
+
We experiment with three standard ViT [18] backbones, ViT-Small, ViT-Base and ViT-Large on both Audioset-mini and VGGSound. We report results in Table 5 for audiovisual fusion with our best MBT model. We find that performance increases from ViT-Small to ViT-Base, but then drops for ViT-Large. This could be due to the fact that these datasets are on the smaller side, and more data might be required to take advantage of larger models.
|
| 320 |
+
|
| 321 |
+
Table 5: Performance with varying backbones on AS-mini and VGGSound.
|
| 322 |
+
|
| 323 |
+
| Backbone AS-mini VGGSound ViT-Small 38.2 59.0 ViT-Base 43.3 64.1 ViT-Large 42.2 61.4 |
|
| 324 |
+
|---------------------------------------------------------------------------------------------------|
|
| 325 |
+
|
| 326 |
+
## A.3 The impact of weight sharing
|
| 327 |
+
|
| 328 |
+
We investigate the impact of sharing the encoder weights for both modalities (strategy (i) vs (ii)) as described in Sec. 4.3.1 . Results are provided in Fig. 7 for different fusion layers L f . When modalities are fused at earlier layers, using separate encoders improves performance. For models with later fusion layers, performance is similar for both models.
|
| 329 |
+
|
| 330 |
+
## A.4 Input sampling
|
| 331 |
+
|
| 332 |
+
Here we investigate asynchronous sampling of different modalities (where input windows are sampled independently from the entire video clip for each modality) as compared to synchronous sampling. Results are provided in Fig. 8 for different input span lengths t . Over multiple runs we find that performance is largely robust to either sampling choice. We hypothesise that asynchronous sampling provides the following trade-off: while it introduces a misalignment between the two modality inputs, slight shifts are also a good source of temporal augmentation. As the video clip span length grows, the possible options for misalignment between inputs are less severe, while the impact of additional augmentation is more evident.
|
| 333 |
+
|
| 334 |
+
In Table 6, we provide the results in numerical form used to create Fig. 4 . We perform 3 runs per experiment and report mean and standard deviation. All segments in AudioSet are 10 seconds long.
|
| 335 |
+
|
| 336 |
+
Table 6: The effect of varying input clip span t on performance.
|
| 337 |
+
|
| 338 |
+
| Span Length t 2s 4s 6s 8s Visual only 26.23 ± 0.16 25.74 ± 0.18 25.68 ± 0.02 25.43 ± 0.02 Audio only 27.10 ± 0.54 29.91 ± 0.21 30.08 ± 0.21 30.55 ± 0.22 Audio-Visual 37.95 ± 0.51 40.32 ± 0.20 41.51 ± 0.24 42.37 ± 0.44 |
|
| 339 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 340 |
+
|
| 341 |
+
## B Per class performance
|
| 342 |
+
|
| 343 |
+
We also examine per-class average precision (AP) results for our best model trained on the miniAudioset (note that this dataset has 527 classes). We first show the results for the 60 top ranked classes in Audioset (by audio-visual mAP performance) in Fig. 9. We show the per class AP using our best fusion model (MBT), as well as the performance of audio only and visual only baselines. Audio-visual fusion improves performance over audio only or visual only for almost all (57 out of 60) classes, except for 'bagpiping', 'emergency vehicle' and 'didgeridoo' which have strong audio signatures. We then analyse the top 60 classes for which fusion has the largest improvement over single modality performance, over audio-only (Figure 10, top) and visual-only (Figure 10, bottom). For some classes such as 'bicycle' and 'shuffling cards', fusion improves over the audio-only baseline by over 60% in absolute AP. The class that benefits most from audio-visual fusion over a visual-only baseline is 'Whistling' (almost 80% improvement in absolute AP).
|
| 344 |
+
|
| 345 |
+
## C Additional Datasets
|
| 346 |
+
|
| 347 |
+
In this section we report results on 2 additional datasets, Moments in Time [47] and Kinetics [35].
|
| 348 |
+
|
| 349 |
+
## C.1 Moments In Time
|
| 350 |
+
|
| 351 |
+
Moments In Time [47] consists of 800,000, 3-second clips from YouTube videos. The videos are diverse and capture dynamic scenes involving animals, objects, people, or natural phenomena. The videos are labelled with 330 verb classes, each associated with over 1,000 videos. We show results for MBT compared to single modality baselines in Table 7. Our first observation is that audio-only performance is much lower than visual-only. This is largely a function of the annotation procedure for the dataset, however we also note that clips are only 3 seconds long, and as shown in Fig. 4 , audio-only performance is heavily dependant on the span length t on Audioset, suggesting that it may be difficult to recognise audio events from shorter inputs. Our fusion model provides a further modest 1% boost to performance over the visual-only baseline.
|
| 352 |
+
|
| 353 |
+
## C.2 Kinetics
|
| 354 |
+
|
| 355 |
+
Kinetics [35] consists of 10-second videos sampled at 25fps from YouTube. We evaluate on both Kinetics 400 [35] and a commonly used subset Kinetics-Sound [4], containing 400 and 36 classes respectively. As these are dynamic datasets (videos may be removed from YouTube), we train and test on 209,552 and 17,069 videos respectively for Kinetics and report results on 1,165 videos for Kinetics-Sound. Results for MBT compared to single modality baselines are shown in Table 8. We note that on the entire Kinetics test set, our fusion model outperforms the visual only baseline by about 1% in top 1 accuracy (in line with other works [64] that demonstrate that audio for the large part does not improve performance for most Kinetics classes). This gap is widened, however, for the Difference between fusion and visual-only performance Kinetics-Sound subset of the dataset (over 4%), as expected because this subset consists of classes in Kinetics selected to have a strong audio signature [4].
|
| 356 |
+
|
| 357 |
+
Figure 7: The effect of sharing weights for vanilla fusion.
|
| 358 |
+
|
| 359 |
+
<!-- image -->
|
| 360 |
+
|
| 361 |
+
Figure 8: Asynchronous vs synchronous sampling of RGB and spectrogram inputs.
|
| 362 |
+
|
| 363 |
+
<!-- image -->
|
| 364 |
+
|
| 365 |
+
<!-- image -->
|
| 366 |
+
|
| 367 |
+
Figure 9: Per-class average precision for the top 60 classes in Audioset ranked by mAP. Best viewed in colour and zoomed in. Note how audio-visual fusion helps improve performance over audio only for almost all classes. The visual only model performs well for classes that have a stronger visual signature than audio, eg 'bicycle', 'mechanical fan', 'boat' and 'arrow'.
|
| 368 |
+
|
| 369 |
+
<!-- image -->
|
| 370 |
+
|
| 371 |
+
Figure 10: Top 60 classes that have the highest gain with fusion over a audio only (top) and visual only (bottom) baseline. Note how fusion improves the per class AP for certain classes by over 50% over a unimodal model. As expected, the classes that benefit most from visual information are 'bicycle' and 'shuffling cards' and the class that benefits most from audio is 'Whistling'.
|
| 372 |
+
|
| 373 |
+
<!-- image -->
|
| 374 |
+
|
| 375 |
+
## D Dataset Variations for MBT vs Late Fusion
|
| 376 |
+
|
| 377 |
+
In this section we further analyse the significance of our method across all the popular video classification datasets used in the paper (most ablations results are only shown for mini-Audioset in the main paper). We note that the gap between MBT and late-fusion is highly dataset dependant (see Table 9), with our method providing an even greater advantage for Epic-Kitchens (almost 6% difference in Top 1 action accuracy).
|
| 378 |
+
|
| 379 |
+
Table 7: Comparison to state of the art on Moments in Time [47]. We report top 1 and top 5 classification accuracy. AV: Refers to audio-visual fusion.
|
| 380 |
+
|
| 381 |
+
| Model Top-1 acc Top-5 acc I3D [10] 29.5 56.1 blVNet [20] 31.4 59.3 AssembleNet-101 [54] 34.3 62.7 ViViT-Base [6] 37.3 64.2 Ours (Audio-only) 8.2 18.2 Ours (Visual-only) 36.3 59.3 MBT(AV) 37.3 61.2 |
|
| 382 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 383 |
+
|
| 384 |
+
Table 8: Comparison to state of the art on Kinetics [35] and Kinetics Sound [4]. We report top-1 and top-5 classification accuracy. AV: Refers to audio-visual fusion. † Note the Kinetics-Sound test set has reduced since this work as videos have been removed from YouTube, hence this is not a direct comparison.
|
| 385 |
+
|
| 386 |
+
| Model Kinetics Kinetics-Sounds Top-1 Top-5 Top-1 Top-5 blVNet [20] 73.5 91.2 - - STM[34] 73.7 91.6 - - TEA [44] 76.1 92.5 - - TS S3D-G [65] 77.2 93.0 - - 3-stream SATT [9] 77.7 93.2 - - AVSlowFast, R101 [64] 78.8 93.6 85.0 † - LGD-3D R101 [52] 79.4 94.4 - - SlowFast R101-NL [22] 79.8 93.9 - - ViViT-Base [6] 80.0 94.0 - - Ours (Audio-only) 25.0 43.9 52.6 71.5 Ours (Visual-only) 79.4 94.0 80.7 94.9 MBT(AV) 80.8 94.6 85.0 96.8 |
|
| 387 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 388 |
+
|
| 389 |
+
## E Transfer learning
|
| 390 |
+
|
| 391 |
+
We use checkpoints pretrained on VGGSound, Kinetics400 and AS-500K and finetune them on Audioset-mini and VGGSound (note we use a ViT-B backbone for these experiments, and report results for audiovisual fusion with our best MBT model). Results are provided in Table 10. While Kinetics400 pretraining gives a slight 0.7% mAP boost on AS-mini, VGGSound initialisation gives a substantial 3% mAP boost over Imagenet Initialisation. On VGGSound, AS500K pretraining gives a more modest boost of 1.2% Top 1 Acc, while Kinetics pretraining does not help (expected as VGGSound is a larger dataset).
|
| 392 |
+
|
| 393 |
+
## F AS-500K details
|
| 394 |
+
|
| 395 |
+
The original unbalanced AudioSet training set consists of almost 2M samples, and is extremely unbalanced with most samples either labelled as speech or music. To improve training efficiency, we create a slightly more balanced subset called AudioSet-500K. The main issue is that AudioSet is multilabel, and this makes balancing difficult. We create AS-500K by greedily restricting the maximum number of samples per class to be 200K. Given the distribution of labels, this gives us a total size of 508,994 samples. We provide the full histogram of labels in Fig. 11 (note the number of samples is on a log 10 scale).
|
| 396 |
+
|
| 397 |
+
| Dataset mini-Audioset Epic-Kitchens VGGSound Moments in Time Kinetics Late Fusion 41.80 37.90 63.3 36.48 77.0 MBT 43.92 43.40 64.1 37.26 80.8 |
|
| 398 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 399 |
+
|
| 400 |
+
Table 9: MBT vs late Fusion for different datasets. For each dataset we report the widely used primary metric, i.e. Audioset: mAP, Epic-Kitchens: Top-1 action accuracy, VGGSound, Moments in Time and Kinetics: Top-1 classification accuracy.
|
| 401 |
+
|
| 402 |
+
Table 10: Transfer learning on Audioset-mini and VGGSound.
|
| 403 |
+
|
| 404 |
+
| Initialisation Checkpoint AS-mini VGGSound ImageNet init. 43.3 64.1 VGGSound init. 46.6 N/A K400 init. 44.0 64.0 AS-500K init. N/A 65.3 |
|
| 405 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 406 |
+
|
| 407 |
+
Figure 11: Class label histogram in the AudioSet-500K split.
|
| 408 |
+
|
| 409 |
+
<!-- image -->
|
text-versions/attention-markdown/2108.11637_SelfAttention for Audio SuperResolution.md
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2108.11637 Selfattention For Audio Superresolution
|
| 2 |
+
|
| 3 |
+
## SELF-ATTENTION FOR AUDIO SUPER-RESOLUTION
|
| 4 |
+
|
| 5 |
+
Nathana¨ el Carraz Rakotonirina
|
| 6 |
+
|
| 7 |
+
Universit´ e d'Antananarivo, Madagascar
|
| 8 |
+
|
| 9 |
+
<!-- image -->
|
| 10 |
+
|
| 11 |
+
(a) High-resolution
|
| 12 |
+
|
| 13 |
+
(b) Low-resolution
|
| 14 |
+
|
| 15 |
+
(c) Reconstruction
|
| 16 |
+
|
| 17 |
+
Fig. 1 : Spectrograms of the high-resolution signal, the subsampled low-resolution signal and the reconstructed signal.
|
| 18 |
+
|
| 19 |
+
attention instead of recurrent neural networks to alter the activations of the convolutions. It allows the model to efficiently incorporate long-range information. We evaluate the model on the VCTK [10] and Piano [11] datasets. Experiments show that our approach outperforms previous methods.
|
| 20 |
+
|
| 21 |
+
## 2. RELATED WORK
|
| 22 |
+
|
| 23 |
+
Audio super-resolution. Audio super-resolution, also known as bandwidth extension [2, 12], is the task of predicting high-resolution signal using a low-resolution one. It predicts the signal's high frequencies from its low frequencies. More formally, given a low-resolution audio signal x = ( x 1 /R 1 , ..., x R 1 T/R 1 ) which is sampled at a rate R 1 /T , we want to reconstruct a high-resolution version y = ( y 1 /R 2 , ..., y R 2 T/R 2 ) of x with a sampling rate R 2 > R 1 . We note r = R 2 /R 1 the upscaling factor. Spectrograms are presented in Figure 1 to illustrate it.
|
| 24 |
+
|
| 25 |
+
Early audio super-resolution models utilize matrix factorization [13, 14]. They are trained on very small datasets due to the computational cost of factorizing matrices. Dong et al. [15] use analysis dictionary learning. Learning-based methods exploit Gaussian mixture models [16-18] and linear predictive coding [19]. Li et al. [6] introduce a neural network with dense layers. The first convolutional architecture is proposed by Kuleshov et al. [7] to scale better with dataset size. Time-Frequency Network (TFNet) [20] works in both the time and frequency domain. Wang et al. [21] builds on the WaveNet model [22]. Macartney et al. [23] use the WaveU-Net [24] architecture for audio super-resolution. Some
|
| 26 |
+
|
| 27 |
+
## ABSTRACT
|
| 28 |
+
|
| 29 |
+
Convolutions operate only locally, thus failing to model global interactions. Self-attention is, however, able to learn representations that capture long-range dependencies in sequences. We propose a network architecture for audio super-resolution that combines convolution and self-attention. Attention-based Feature-Wise Linear Modulation (AFiLM) uses self-attention mechanism instead of recurrent neural networks to modulate the activations of the convolutional model. Extensive experiments show that our model outperforms existing approaches on standard benchmarks. Moreover, it allows for more parallelization resulting in significantly faster training.
|
| 30 |
+
|
| 31 |
+
Index Terms -audio super-resolution, bandwidth extension, self-attention
|
| 32 |
+
|
| 33 |
+
## 1. INTRODUCTION
|
| 34 |
+
|
| 35 |
+
Audio super-resolution is the task of reconstructing a highresolution audio signal from a low-resolution one. The sampling rate of the low-resolution signal is increased. It is also known as time series super-resolution [1] or bandwidth extension [2]. Since audio signals are long sequences, long-range dependencies need to be captured in order to obtain good performance. The architectures that are used to process sequential inputs include convolutional neural networks (CNN) [3] and recurrent neural networks (RNN) [4, 5]. Recent audio super-resolution models use deep neural network (DNN) with dense layers [6] or one-dimensional convolutions [7]. Temporal Feature-Wise Linear Modulation (TFiLM) [1] uses recurrent neural networks to modify the activations of the convolutions. However, there are limitations associated with convolutions and RNNs due respectively to limited receptive fields and the vanishing gradient problem [8]. In contrast, selfattention [9], a recent advance for sequence modeling and generative modeling tasks, is able to capture long-range information and is more parallelizable.
|
| 36 |
+
|
| 37 |
+
In this paper, we consider the use of the self-attention mechanism for the audio super-resolution task. The architecture we propose makes use of a combinations of self-attention and convolution. We introduce the Attention-based FeatureWise Linear Modulation (AFiLM) layer which relies on self- approaches [25-29] leverage generative adversarial networks (GANs) [30]. Temporal Feature-Wise Linear Modulation (TFiLM) [1] uses RNNs to alter the activations of the convolutional layers. Our approach is based on TFiLM but we use self-attention instead of RNNs.
|
| 38 |
+
|
| 39 |
+
Self-attention. Self-attention produces a weighted average of values computed from hidden units using a similarity function. It has been used for sequence modeling because of its ability to capture long-range interactions [31, 32]. The Transformer architecture [9] using only attention without any other architecture produces state-of-the-art results in Machine Translation. Recent speech enhancement approaches [3335] also use self-attention. Attention augmented convolutions [36] achieve significant improvement in discriminative visual tasks. This combination of convolution and self-attention is also applied to speech recognition [37]. Our approach is similar in that it captures both local and global dependencies of an audio sequence.
|
| 40 |
+
|
| 41 |
+
Fig. 2 : Network architecture used for audio super-resolution where K = 4 as used in our implementation. It consists of downsampling blocks, a bottleneck block and upsampling blocks.
|
| 42 |
+
|
| 43 |
+
<!-- image -->
|
| 44 |
+
|
| 45 |
+
## 3. PROPOSED METHOD
|
| 46 |
+
|
| 47 |
+
## 3.1. Network architecture
|
| 48 |
+
|
| 49 |
+
We use the following naming conventions : T and C are, respectively, the 1D spatial dimension and the number of channels. The network architecture, presented in Figure 2, follows the overall architecture of [1, 7] which is composed of K downsampling blocks, a bootleneck layer and K upsampling blocks; there are symmetric residual skip connections [38] between blocks. The bottleneck is the same as the downsampling blocks but with Dropout [39]. Each downsampling block k = 1 , 2 , ..., K contains max(2 6+ k , 512) fi lters of length min(2 7 -k + 1 , 9) with a stride of 2 . Each upsampling block k = 1 , 2 , ..., K contains max(2 7+( K -k +1) , 512) of length min(2 7 -( K -k +1) +1 , 9) .In the upsampling blocks, a one-dimensional version of the subpixel shuffling layer [40] is used for upscaling.
|
| 50 |
+
|
| 51 |
+
## 3.2. Attention-based Feature-Wise Linear Modulation layer
|
| 52 |
+
|
| 53 |
+
We present a novel neural network layer that exploits the selfattention mechanism in order to capture long-range dependencies. Feature-Wise Linear Modulation (FiLM) [41] is a neural network component that applies an affine transformation to feature maps conditioned on some input. A function called FiLM generator outputs the normalizers ( γ, β ) which modulate the activations of a neural network called FiLMed network. In Temporal Feature-Wise Linear Modulation (TFiLM) [1], the FiLM-ed network is a convolutional model and the FiLM generator network is an RNN. This is a selfconditioned model since the inputs of the FiLM generator are the activations themselves. However, RNNs are less effective in modeling very long sequences [8]. Besides, their sequential nature can be computationally limiting. On the other hand, self-attention can represent dependencies regardless of their distance in the input sequence.
|
| 54 |
+
|
| 55 |
+
We propose the Attention-based Feature-Wise Linear Modulation (AFiLM) layer which makes use of self-attention as the FiLM generator to modulate the activations of the convolutional model as depicted in Figure 3. Our FiLM genetator is the Transformer's [9] basic block. Following TFiLM, the feature map modulation is applied on a block level. The tensor of activations F ∈ R T × C is split into B blocks resulting in a block tensor F block ∈ R B × T/B × C . Max pooling is then used along the second dimension to downsample F block into a tensor F pool ∈ R B × C . The normalizers γ, β ∈ R B × C are then obtained by applying the FiLM generator. For each block b , the parameters are computed as follows:
|
| 56 |
+
|
| 57 |
+
<!-- formula-not-decoded -->
|
| 58 |
+
|
| 59 |
+
where TransformerBlock is composed of a stack of multihead self-attention and point-wise fully connected layers. Residual connections and layer normalization [42] are used in the sub-layers. After that, for each block b , the normalizers γ b and β b modulate the activations via a feature-wise affine transformation:
|
| 60 |
+
|
| 61 |
+
<!-- formula-not-decoded -->
|
| 62 |
+
|
| 63 |
+
Finally, the resulting tensor is reshaped back into its original shape ( T, C ) . Different combinations of γ and β can modulate feature maps in multiple ways. Independently of the length of the feature map, AFiLM can efficiently influence it taking into account the global interactions. Furthermore, by replacing the RNNs with self-attention, the model benefits from better parallelization which significantly speeds up training. The AFiLM layer is added at the end of each downsampling, bottleneck and upsampling block as presented in
|
| 64 |
+
|
| 65 |
+
Fig. 3 : The AFiLM layer uses a Transformer block as a FiLM generator. Element-wise multiplication and addition are performed to modulate the feature maps. This illustration uses T = 8 , C = 4 , B = 2 .
|
| 66 |
+
|
| 67 |
+
<!-- image -->
|
| 68 |
+
|
| 69 |
+
Figure 2. Our implementation uses K = 4 and a Transformer block that is composed of a stack of 4 layers with the number of heads h = 8 and hidden dimension d = 2048 .
|
| 70 |
+
|
| 71 |
+
## 4. EXPERIMENTS
|
| 72 |
+
|
| 73 |
+
## 4.1. Datasets
|
| 74 |
+
|
| 75 |
+
The model is trained and evaluated on the VCTK [10] and Piano [11] datasets. The VCTK dataset contains speech data from 109 native speakers of English with various accents. Each speaker reads out about 400 diferent sentences. There is a total of 44 hours of speech data. The Piano dataset contains 10 hours of Beethoven sonatas. Both datasets are used at a sampling rate of 16 kHz. Following previous works [1,7], we apply an order 8 Chebyshev type I low-pass filter before subsampling the high-resolution signal. The single speaker task trains the model on the first 223 recordings of VCTK Speaker 1 which is approximately 30 minutes and tests on the last 8 recordings. Concerning the multi speaker task, we train on the first 99 VCTK speakers and test on the 8 remaining ones. The Piano dataset is split into 88% training, 6% validation, and 6% testing.
|
| 76 |
+
|
| 77 |
+
## 4.2. Training details
|
| 78 |
+
|
| 79 |
+
Our model is trained for 50 epochs on patches of length 8192, as are existing audio super-resolution models. This ensures a fair comparison. The low-resolution audio signals are first processed with bicubic upscaling before they are fed into the model. The learning-rate is set to 3 × 10 -4 . The model is optimized using Adam [43] with β 1 = 0 . 9 and β 2 = 0 . 999 .
|
| 80 |
+
|
| 81 |
+
Table 1 : Quantitative evaluation of audio super-resolution models at different upsampling rates. Left/right results are SNR/LSD (higher is better for SNR while lower is better for LSD). Baseline results are those reported in [1].
|
| 82 |
+
|
| 83 |
+
| Method Scale VCTK Single VCTK Multi Piano Bicubic 2 19.0/3.5 18.0/2.9 24.8/1.8 DNN [6] 2 19.0/3.0 17.9/2.5 24.7/2.5 CNN [7] 2 19.4/2.6 18.1/1.9 25.3/2.0 TFiLM [1] 2 19.5 /2.5 19.8/1.8 25.4/2.0 AFILM 2 19.3 /2.3 20.0/1.7 25.7/1.5 Bicubic 4 15.6/5.6 13.2/5.2 18.6/2.8 DNN [6] 4 15.6/4.0 13.3/3.9 18.6/3.2 CNN [7] 4 16.4/3.7 13.1/3.1 18.8/2.3 TFiLM [1] 4 16.8/3.5 15.0/2.7 19.3/2.2 AFILM 4 17.2/3.1 15.4/2.3 20.4/2.1 Bicubic 8 12.2/7.2 9.8/6.8 10.7/4.0 DNN [6] 8 12.3/4.7 9.8/4.6 10.7/3.5 CNN [7] 8 12.7/4.2 9.9/4.3 11.1/2.7 TFiLM [1] 8 12.9/4.3 12.0/2.9 13.3 /2.6 AFILM 8 12.9/3.7 12.0/2.7 12.9 /2.5 |
|
| 84 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 85 |
+
|
| 86 |
+
## 4.3. Results
|
| 87 |
+
|
| 88 |
+
The metrics used to evaluate the model are the the signal to noise ratio (SNR) and the log-spectral distance (LSD) [44]. These are standard metrics used in the signal processing literature. Given a reference signal y and the corresponding approximation x, the SNR is defined as
|
| 89 |
+
|
| 90 |
+
<!-- formula-not-decoded -->
|
| 91 |
+
|
| 92 |
+
Table 2 : Training time evaluation. The number of seconds per epoch was obtained using an NVIDIA Tesla K80 GPU.
|
| 93 |
+
|
| 94 |
+
| Model TFiLM AFiLM Number of parameters 6.82e7 1.34e8 Seconds per epoch 370 276 |
|
| 95 |
+
|------------------------------------------------------------------------------------------|
|
| 96 |
+
|
| 97 |
+
The LSD measures the reconstruction quality of individual frequencies and is defined as
|
| 98 |
+
|
| 99 |
+
<!-- formula-not-decoded -->
|
| 100 |
+
|
| 101 |
+
where X and ˆ X are the log-spectral power magnitudes of y and x defined as X = log | S | 2 , where S is the short-time Fourier transform (STFT) of the signal. t and k are respectively index frames and frequencies.
|
| 102 |
+
|
| 103 |
+
We compare our best models with existing approaches at upscaling ratios 2, 4 and 8. The results are presented in Table 1. All the baseline results are those reported in [1]. Our contributions result in an average improvement of 0.2 dB over the TFiLM in terms of SNR. Concerning the LSD metric, our approach improves by 0.3 dB on average. This shows that our model effectively uses the self-attention mechanism to capture long-term information in the audio signal. Our attentionbased model outperforms all previous models on the multi speaker task. It is the most difficult task and is the one that benefits most from more long-term information.
|
| 104 |
+
|
| 105 |
+
Table 3 : Out-of-distribution evaluation of the model. The model is trained on the VCTK Multispeaker and Piano datasets at scale r = 2 and tested both on the same and on the other dataset. Left/right results are SNR/LSD.
|
| 106 |
+
|
| 107 |
+
| VCTK Multi (Test) Piano (Test) VCTK Multi (Train) 20.0/1.7 24.4/2.5 Piano (Train) 10.2/2.6 25.7/1.5 |
|
| 108 |
+
|--------------------------------------------------------------------------------------------------------------|
|
| 109 |
+
|
| 110 |
+
## 5. DISCUSSION
|
| 111 |
+
|
| 112 |
+
In this section, we present further analyses and discuss some important aspects of the audio super-resolution task.
|
| 113 |
+
|
| 114 |
+
Computational performance. In addition to capturing long-range dependencies, AFiLM trains faster. This is mainly due to the Transformer's ability to be more parallelizable [9]. We compare the run-time efficiency of TFiLM and AFiLM. As presented in Table 2, even though the number of parameters of AFiLM is higher, it trains on average over 34% faster than the TFiLM model. Unlike the RNN-based model, AFiLM effiently exploits the GPU resulting in much faster training.
|
| 115 |
+
|
| 116 |
+
Generalization of the super-resolution model. We investigate the model's ability to generalize to other domains. In order to do this, we switch from speech to music and the other way around. The results are presented in Table 3. As seen in previous models [1,7], the super-resolved samples contain the high frequency details but still sound noisy. The models specialize to the specific type of audio they are trained on.
|
| 117 |
+
|
| 118 |
+
## 6. CONCLUSION
|
| 119 |
+
|
| 120 |
+
In this work, we introduce the use of self-attention for the audio super-resolution task. We present the Attention-based Feature-Wise Linear Modulation (AFiLM) layer which relies on attention instead of recurrent neural networks to alter the activations of the convolutional model. The resulting model efficiently captures long-range temporal interactions. It outperforms all previous models and can be trained faster.
|
| 121 |
+
|
| 122 |
+
In future work, we want to develop super-resolution models that generalize well to different types of inputs. We also want to investigate perceptual-based models.
|
| 123 |
+
|
| 124 |
+
## 7. ACKNOWLEDGEMENTS
|
| 125 |
+
|
| 126 |
+
Wewould like to thank Bruce Basset for his helpful comments and advice.
|
| 127 |
+
|
| 128 |
+
## 8. REFERENCES
|
| 129 |
+
|
| 130 |
+
- [1] Sawyer Birnbaum, Volodymyr Kuleshov, Zayd Enam, Pang Wei W Koh, and Stefano Ermon, 'Temporal film: Capturing long-range sequence dependencies with feature-wise modulations.,' in Advances in Neural Information Processing Systems , 2019, pp. 10287-10298.
|
| 131 |
+
- [2] Per Ekstrand, 'Bandwidth extension of audio signals by spectral band replication,' in in Proceedings of the 1st IEEE Benelux Workshop on Model Based Processing and Coding of Audio (MPCA'02 . Citeseer, 2002.
|
| 132 |
+
- [3] Yann LeCun, Bernhard Boser, John S Denker, Donnie Henderson, Richard E Howard, Wayne Hubbard, and Lawrence D Jackel, 'Backpropagation applied to handwritten zip code recognition,' Neural computation , vol. 1, no. 4, pp. 541-551, 1989.
|
| 133 |
+
- [4] Jeffrey L Elman, 'Finding structure in time,' Cognitive science , vol. 14, no. 2, pp. 179-211, 1990.
|
| 134 |
+
- [5] Sepp Hochreiter and J¨ urgen Schmidhuber, 'Long shortterm memory,' Neural computation , vol. 9, no. 8, pp. 1735-1780, 1997.
|
| 135 |
+
- [6] Kehuang Li, Zhen Huang, Yong Xu, and Chin-Hui Lee, 'Dnn-based speech bandwidth expansion and its application to adding high-frequency missing features for
|
| 136 |
+
7. automatic speech recognition of narrowband speech,' in Sixteenth Annual Conference of the International Speech Communication Association , 2015.
|
| 137 |
+
- [7] Volodymyr Kuleshov, S Zayd Enam, and Stefano Ermon, 'Audio super-resolution using neural nets,' in ICLR (Workshop Track) , 2017.
|
| 138 |
+
- [8] Yoshua Bengio, Patrice Simard, and Paolo Frasconi, 'Learning long-term dependencies with gradient descent is difficult,' IEEE transactions on neural networks , vol. 5, no. 2, pp. 157-166, 1994.
|
| 139 |
+
- [9] Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin, 'Attention is all you need,' in Advances in neural information processing systems , 2017, pp. 5998-6008.
|
| 140 |
+
- [10] Junichi Yamagishi, 'English multi-speaker corpus for cstr voice cloning toolkit,' URL http://homepages. inf. ed. ac. uk/jyamagis/page3/page58/page58. html , 2012.
|
| 141 |
+
- [11] Soroush Mehri, Kundan Kumar, Ishaan Gulrajani, Rithesh Kumar, Shubham Jain, Jose Sotelo, Aaron Courville, and Yoshua Bengio, 'Samplernn: An unconditional end-to-end neural audio generation model,' arXiv preprint arXiv:1612.07837 , 2016.
|
| 142 |
+
- [12] Erik Larsen and Ronald M Aarts, Audio bandwidth extension: application of psychoacoustics, signal processing and loudspeaker design , John Wiley & Sons, 2005.
|
| 143 |
+
- [13] Dhananjay Bansal, Bhiksha Raj, and Paris Smaragdis, 'Bandwidth expansion of narrowband speech using non-negative matrix factorization,' in Ninth European Conference on Speech Communication and Technology , 2005.
|
| 144 |
+
- [14] Dawen Liang, Matthew D Hoffman, and Daniel PW Ellis, 'Beta process sparse nonnegative matrix factorization for music.,' in ISMIR , 2013, pp. 375-380.
|
| 145 |
+
- [15] Jing Dong, Wenwu Wang, and Jonathon Chambers, 'Audio super-resolution using analysis dictionary learning,' in 2015 IEEE International Conference on Digital Signal Processing (DSP) . IEEE, 2015, pp. 604-608.
|
| 146 |
+
- [16] Yan Ming Cheng, Douglas O'Shaughnessy, and Paul Mermelstein, 'Statistical recovery of wideband speech from narrowband speech,' IEEE Transactions on Speech and Audio Processing , vol. 2, no. 4, pp. 544548, 1994.
|
| 147 |
+
- [17] Hannu Pulakka, Ulpu Remes, Kalle Palom¨ aki, Mikko Kurimo, and Paavo Alku, 'Speech bandwidth extension using gaussian mixture model-based estimation of the highband mel spectrum,' in 2011 IEEE International
|
| 148 |
+
19. Conference on Acoustics, Speech and Signal Processing (ICASSP) . IEEE, 2011, pp. 5100-5103.
|
| 149 |
+
- [18] Kun-Youl Park and Hyung Soon Kim, 'Narrowband to wideband conversion of speech using gmm based transformation,' in 2000 IEEE international conference on acoustics, speech, and signal processing. Proceedings (Cat. No. 00CH37100) . IEEE, 2000, vol. 3, pp. 18431846.
|
| 150 |
+
- [19] Jeremy Bradbury, 'Linear predictive coding,' Mc G. Hill , 2000.
|
| 151 |
+
- [20] T. Y. Lim, R. A. Yeh, Y. Xu, M. N. Do, and M. Hasegawa-Johnson, 'Time-frequency networks for audio super-resolution,' in 2018 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP) , 2018, pp. 646-650.
|
| 152 |
+
- [21] Mu Wang, Zhiyong Wu, Shiyin Kang, Xixin Wu, Jia Jia, Dan Su, Dong Yu, and Helen Meng, 'Speech superresolution using parallel wavenet,' in 2018 11th International Symposium on Chinese Spoken Language Processing (ISCSLP) . IEEE, 2018, pp. 260-264.
|
| 153 |
+
- [22] Aaron van den Oord, Sander Dieleman, Heiga Zen, Karen Simonyan, Oriol Vinyals, Alex Graves, Nal Kalchbrenner, Andrew Senior, and Koray Kavukcuoglu, 'Wavenet: A generative model for raw audio,' arXiv preprint arXiv:1609.03499 , 2016.
|
| 154 |
+
- [23] Daniel Stoller, Sebastian Ewert, and Simon Dixon, 'Wave-u-net: A multi-scale neural network for endto-end audio source separation,' arXiv preprint arXiv:1806.03185 , 2018.
|
| 155 |
+
- [24] Craig Macartney and Tillman Weyde, 'Improved speech enhancement with the wave-u-net,' arXiv preprint arXiv:1811.11307 , 2018.
|
| 156 |
+
- [25] Sefik Emre Eskimez and Kazuhito Koishida, 'Speech super resolution generative adversarial network,' in ICASSP 2019-2019 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP) . IEEE, 2019, pp. 3717-3721.
|
| 157 |
+
- [26] Shichao Hu, Bin Zhang, Beici Liang, Ethan Zhao, and Simon Lui, 'Phase-aware music super-resolution using generative adversarial networks,' arXiv preprint arXiv:2010.04506 , 2020.
|
| 158 |
+
- [27] Sen Li, St´ ephane Villette, Pravin Ramadas, and Daniel J Sinder, 'Speech bandwidth extension using generative adversarial networks,' in 2018 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP) . IEEE, 2018, pp. 5029-5033.
|
| 159 |
+
- [28] Xinyu Li, Venkata Chebiyyam, Katrin Kirchhoff, and AI Amazon, 'Speech audio super-resolution for speech recognition.,' in INTERSPEECH , 2019, pp. 3416-3420.
|
| 160 |
+
- [29] Rithesh Kumar, Kundan Kumar, Vicki Anand, Yoshua Bengio, and Aaron Courville, 'Nu-gan: High resolution neural upsampling with gan,' arXiv preprint arXiv:2010.11362 , 2020.
|
| 161 |
+
- [30] Ian J Goodfellow, Jean Pouget-Abadie, Mehdi Mirza, Bing Xu, David Warde-Farley, Sherjil Ozair, Aaron Courville, and Yoshua Bengio, 'Generative adversarial networks,' arXiv preprint arXiv:1406.2661 , 2014.
|
| 162 |
+
- [31] Dzmitry Bahdanau, Kyunghyun Cho, and Yoshua Bengio, 'Neural machine translation by jointly learning to align and translate,' arXiv preprint arXiv:1409.0473 , 2014.
|
| 163 |
+
- [32] Irwan Bello, Hieu Pham, Quoc V Le, Mohammad Norouzi, and Samy Bengio, 'Neural combinatorial optimization with reinforcement learning,' arXiv preprint arXiv:1611.09940 , 2016.
|
| 164 |
+
- [33] Yuma Koizumi, Kohei Yaiabe, Marc Delcroix, Yoshiki Maxuxama, and Daiki Takeuchi, 'Speech enhancement using self-adaptation and multi-head self-attention,' in ICASSP 2020-2020 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP) . IEEE, 2020, pp. 181-185.
|
| 165 |
+
- [34] Xiang Hao, Changhao Shan, Yong Xu, Sining Sun, and Lei Xie, 'An attention-based neural network approach for single channel speech enhancement,' in ICASSP 2019-2019 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP) . IEEE, 2019, pp. 6895-6899.
|
| 166 |
+
- [35] Ritwik Giri, Umut Isik, and Arvindh Krishnaswamy, 'Attention wave-u-net for speech enhancement,' in 2019 IEEE Workshop on Applications of Signal Processing to Audio and Acoustics (WASPAA) . IEEE, 2019, pp. 249-253.
|
| 167 |
+
- [36] Irwan Bello, Barret Zoph, Ashish Vaswani, Jonathon Shlens, and Quoc V Le, 'Attention augmented convolutional networks,' in Proceedings of the IEEE International Conference on Computer Vision , 2019, pp. 3286-3295.
|
| 168 |
+
- [37] Anmol Gulati, James Qin, Chung-Cheng Chiu, Niki Parmar, Yu Zhang, Jiahui Yu, Wei Han, Shibo Wang, Zhengdong Zhang, Yonghui Wu, et al., 'Conformer: Convolution-augmented transformer for speech recognition,' arXiv preprint arXiv:2005.08100 , 2020.
|
| 169 |
+
- [38] Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun, 'Deep residual learning for image recognition,' in
|
| 170 |
+
41. Proceedings of the IEEE conference on computer vision and pattern recognition , 2016, pp. 770-778.
|
| 171 |
+
- [39] Nitish Srivastava, Geoffrey Hinton, Alex Krizhevsky, Ilya Sutskever, and Ruslan Salakhutdinov, 'Dropout: a simple way to prevent neural networks from overfitting,' The journal of machine learning research , vol. 15, no. 1, pp. 1929-1958, 2014.
|
| 172 |
+
- [40] Wenzhe Shi, Jose Caballero, Ferenc Husz´ ar, Johannes Totz, Andrew P Aitken, Rob Bishop, Daniel Rueckert, and Zehan Wang, 'Real-time single image and video super-resolution using an efficient sub-pixel convolutional neural network,' in Proceedings of the IEEE conference on computer vision and pattern recognition , 2016, pp. 1874-1883.
|
| 173 |
+
- [41] Ethan Perez, Florian Strub, Harm De Vries, Vincent Dumoulin, and Aaron Courville, 'Film: Visual reasoning with a general conditioning layer,' arXiv preprint arXiv:1709.07871 , 2017.
|
| 174 |
+
- [42] Jimmy Lei Ba, Jamie Ryan Kiros, and Geoffrey E Hinton, 'Layer normalization,' arXiv preprint arXiv:1607.06450 , 2016.
|
| 175 |
+
- [43] Diederik P Kingma and Jimmy Ba, 'Adam: A method for stochastic optimization,' arXiv preprint arXiv:1412.6980 , 2014.
|
| 176 |
+
- [44] Augustine Gray and John Markel, 'Distance measures for speech processing,' IEEE Transactions on Acoustics, Speech, and Signal Processing , vol. 24, no. 5, pp. 380-391, 1976.
|
text-versions/attention-markdown/2108.12409_Train Short Test Long Attention with Lin.md
ADDED
|
@@ -0,0 +1,438 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2108.12409 Train Short Test Long Attention With Lin
|
| 2 |
+
|
| 3 |
+
## TRAIN SHORT, TEST LONG: ATTENTION WITH LINEAR BIASES ENABLES INPUT LENGTH EXTRAPOLATION
|
| 4 |
+
|
| 5 |
+
Ofir Press 1 , 2 Noah A. Smith 1 , 3 Mike Lewis 2
|
| 6 |
+
|
| 7 |
+
1
|
| 8 |
+
|
| 9 |
+
2
|
| 10 |
+
|
| 11 |
+
Paul G. Allen School of Computer Science & Engineering, University of Washington Facebook AI Research
|
| 12 |
+
|
| 13 |
+
3 Allen Institute for AI
|
| 14 |
+
|
| 15 |
+
ofirp@cs.washington.edu
|
| 16 |
+
|
| 17 |
+
## ABSTRACT
|
| 18 |
+
|
| 19 |
+
Since the introduction of the transformer model by Vaswani et al. (2017), a fundamental question has yet to be answered: how does a model achieve extrapolation at inference time for sequences that are longer than it saw during training? We first show that extrapolation can be enabled by simply changing the position representation method, though we find that current methods do not allow for efficient extrapolation. We therefore introduce a simpler and more efficient position method, Attention with Linear Biases (ALiBi). ALiBi does not add positional embeddings to word embeddings; instead, it biases query-key attention scores with a penalty that is proportional to their distance. We show that this method trains a 1.3 billion parameter model on input sequences of length 1024 that extrapolates to input sequences of length 2048, achieving the same perplexity as a sinusoidal position embedding model trained on inputs of length 2048 but training 11% faster and using 11% less memory. ALiBi's inductive bias towards recency also leads it to outperform multiple strong position methods on the WikiText-103 benchmark. 1
|
| 20 |
+
|
| 21 |
+
## 1 INTRODUCTION
|
| 22 |
+
|
| 23 |
+
When constructing a transformer-based language model, a major design decision is the length of training sequences, denoted L herein, which has to date been equivalent to the length of inference sequences. More context, achieved by larger L , improves predictions at inference time. But longer sequences are more expensive to train on. 2
|
| 24 |
+
|
| 25 |
+
Before transformers, RNN language models were trained on shorterL sequences and assumed to generalize to longer contexts at inference time (Mikolov et al., 2010; Mikolov & Zweig, 2012; Zaremba et al., 2014). Vaswani et al. (2017), introducing the transformer, speculated that it 'may [...] extrapolate to sequence lengths longer than the ones encountered during training.' We define extrapolation as a model's ability to continue performing well as the number of input tokens during validation increases beyond the number of tokens on which the the model was trained. We find that transformer language models (LMs) that use sinusoidal position embeddings have very weak extrapolation abilities; see Figure 1.
|
| 26 |
+
|
| 27 |
+
We demonstrate that this failure to extrapolate is caused by the position embedding method. As shown in Figure 1, recent alternatives to the original sinusoidal position method (Su et al., 2021; Raffel et al., 2020) have improved extrapolation. However, the better of these, the T5 bias, is considerably slower than the sinusoidal approach and uses extra memory and parameters (Figure 2).
|
| 28 |
+
|
| 29 |
+
We therefore introduce Attention with Linear Biases (ALiBi) to facilitate efficient extrapolation. ALiBi negatively biases attention scores with a linearly decreasing penalty proportional to the distance between the relevant key and query. Our simple approach eliminates position embeddings.
|
| 30 |
+
|
| 31 |
+
[1 Code & models: https://github.com/ofirpress/attention\_with\_linear\_biases](https://github.com/ofirpress/attention_with_linear_biases)
|
| 32 |
+
|
| 33 |
+
2 Figure 7 in the appendix plots training speed, in words per second, against L .
|
| 34 |
+
|
| 35 |
+
<!-- image -->
|
| 36 |
+
|
| 37 |
+
Inference Input Tokens
|
| 38 |
+
|
| 39 |
+
Figure 1: Extrapolation: as the (validation-set's) input sequence gets longer ( x -axis), current position methods (sinusoidal, rotary, and T5) show degraded perplexity ( y -axis, lower is better), but our method (§3) does not. Models were trained on WikiText-103 with sequences of L = 512 (left) or L = 1,024 (right) tokens. T5 ran out of memory on our 32GB GPU. For more detail on exact perplexities and runtimes, see Tables 2 and 3 in the appendix.
|
| 40 |
+
|
| 41 |
+
Compared to a sinusoidal model trained on the same input length, our method requires no additional runtime or parameters and incurs a negligible (0-0.7%) memory increase. ALiBi can be implemented by changing only a few lines of existing transformer code.
|
| 42 |
+
|
| 43 |
+
Using ALiBi, a transformer LM can be trained on shortL sequences and therefore at much lower cost, and it can still be reliably applied to long sequences at runtime. For example, a 1.3 billion parameter LM trained on L = 1024 tokens with ALiBi achieves the same perplexity as a sinusoidal model trained on L = 2048 when both are tested on sequences of 2048 tokens, even though our model is 11% faster and uses 11% less memory.
|
| 44 |
+
|
| 45 |
+
Though performance peaks at around two times the number of tokens that the model was trained on, ALiBi maintains strong performance even on sequences of length 10,000. In recently explored settings where NLP training examples are given as context to an LM (Brown et al., 2020), our approach will allow exposure to more examples. Additionally, it enables generation of longer outputs.
|
| 46 |
+
|
| 47 |
+
## 2 CURRENT APPROACHES DO NOT EXTRAPOLATE EFFICIENTLY
|
| 48 |
+
|
| 49 |
+
We show for the first time that the sinusoidal position method, which technically should be able to extrapolate, in practice has very limited extrapolation capabilities. Though the rotary position method improves over the sinusoidal one, it still does not achieve satisfying results. Holding everything else constant, we are the first to observe that the T5 bias method leads to better extrapolation than either of these, and so we conclude that extrapolation ability depends heavily on the position embedding. Unfortunately, the T5 bias is computationally costly (Figure 2).
|
| 50 |
+
|
| 51 |
+
## 2.1 BACKGROUND AND EXPERIMENTAL SETUP
|
| 52 |
+
|
| 53 |
+
A transformer LM receives a list of tokens and outputs a probability distribution representing its prediction for the next token. We call the input list the current input subsequence since the inputs to language models are typically subsequences from (much longer) training or evaluation sequences. During both training and perplexity evaluation (i.e., scoring a fixed sequence), many predictions can be calculated at once; this is done using a 'causal mask' that ensures each position's prediction is influenced only by tokens to its left. Let L be the length of each input subsequence during training; it includes L predictions, which on average have access to L +1 2 tokens of (left) context. To explore a model's extrapolation abilities, we are interested in cases where sequences of length L valid > L are considered at evaluation time. When L differs between inference and training, we use L to refer to the length of subsequences during training and L valid to refer to their length at validation.
|
| 54 |
+
|
| 55 |
+
Training Memory
|
| 56 |
+
|
| 57 |
+
Figure 2: A comparison of batched training, inference speed and memory use of the sinusoidal, rotary, T5 bias, and our ALiBi position methods. The speed differences between our method and the sinusoidal are within 1% during training and 3% for inference, which is insignificant on our hardware. ALiBi uses 100MB of extra memory when training on input lengths 1024 and 3072 in this setting. Memory usage is lower in all approaches when training on 3072 tokens (compared to 1024) since we break batches into multiple updates. See Table 1 in the appendix for exact numbers.
|
| 58 |
+
|
| 59 |
+
<!-- image -->
|
| 60 |
+
|
| 61 |
+
Nonoverlapping Inference To train on or evaluate a sequence longer than L tokens, it is typical to segment the sequence into L -length subsequences and train on or evaluate them independently. Unless otherwise stated, we use nonoverlapping inference to report perplexity scores.
|
| 62 |
+
|
| 63 |
+
Extrapolation During Inference Formally, the functions that define a transformer layer are agnostic to input length; 3 they map from some arbitrary, unfixed number of input vectors to the same number of output vectors. When transformers are applied to data that is inherently sequential, like text, positional information is injected into the inputs in various ways.
|
| 64 |
+
|
| 65 |
+
Vaswani et al. (2017) discussed two options for embedding positions into vectors to be added to word embeddings: learning embeddings for specific positions and unlearned sinusoidal embeddings. They observed similar performance between these two but preferred the sinusoidal approach, which they argued might extrapolate to longer input sequences during inference. We find that this model cannot extrapolate to more than a few dozen tokens beyond L . 4
|
| 66 |
+
|
| 67 |
+
Experiment Setup We first test the extrapolation abilities of various position methods on the WikiText-103 corpus (Merity et al., 2016) using the transformer language model of Baevski & Auli (2018). We use this model because of its prominent role in recent language modeling developments (Khandelwal et al., 2020; Press et al., 2021). The training set is about 103 million tokens from English Wikipedia (half a gigabyte). The model has 16 transformer layers of dimension 1024 , with 8 heads, and a feedforward inner dimension of 4096 . This model ties the word embedding and softmax matrices (Press & Wolf, 2017; Inan et al., 2017). In our experiments, other than varying the position method and training subsequence length, we modify no other hyperparameters, including the random seed and number of training epochs (205).
|
| 68 |
+
|
| 69 |
+
## 2.2 MEASURING EXTRAPOLATION
|
| 70 |
+
|
| 71 |
+
Sinusoidal Position Embeddings Sinusoidal position embeddings (Vaswani et al., 2017; §3.5) are constant, non-learned vectors that are added to token embeddings on input to the first layer of the transformer. They are frequently used in transformer language modeling (Baevski & Auli, 2018; Lewis et al., 2021) and machine translation (Vaswani et al., 2017; Ott et al., 2018) models. We first consider the unmodified model of Baevski & Auli (2018), which uses sinusoidal position embeddings, and train it on L = 512 tokens; we then run inference with it on the validation set on L + k tokens, with k ranging from 0 to 15,000. Figure 1 (left) and the corresponding Table 2 (in the appendix) show that while the model improves perplexity up to k = 20 , performance stops improving and stays steady from k = 20 to k = 50 and then begins degrading. Similar results are obtained for a model trained with L = 1024 tokens (Figure 1 (right) and Table 3 in the appendix). That model improves for up to L valid = L +50 tokens, after which performance declines.
|
| 72 |
+
|
| 73 |
+
3 These include the embedding lookup, feedforward sublayer, and softmax layer, which act independently on vector inputs, as well as the attention sublayers, whose parameters do not depend on input length (and which must handle variable-length inputs, e.g., due to causal masking).
|
| 74 |
+
|
| 75 |
+
4 The learned positional embedding approach does not have a way to encode positions greater than L ; it therefore has no ability to extrapolate.
|
| 76 |
+
|
| 77 |
+
Rotary Position Embeddings The rotary method was introduced by Su et al. (2021) and has recently been popularized by the open source GPT-3 (Brown et al., 2020) implementation GPTJ (Wang & Komatsuzaki, 2021). Instead of adding sinusoidal embeddings at the bottom of the transformer, they multiply the keys and queries of every attention layer by sinusoidal embeddings.
|
| 78 |
+
|
| 79 |
+
Unlike the sinusoidal or learned positional embedding approach, the rotary method injects position information into the model at every layer, not just at the initial one. In addition, it adds no position information to the values of the self-attention sublayer. The output of a self-attention sublayer is a linearly transformed, weighted sum of the input value vectors; therefore, by not inserting position information into the values, the outputs of each transformer-layer contain no explicit position information. We suspect that this segregation of position information may be beneficial for extrapolation, and we draw inspiration from it in the design of our method (§3).
|
| 80 |
+
|
| 81 |
+
We apply the rotary position embedding method to our Baevski & Auli baseline. 5 The perplexity results (Figure 1 and Appendix Tables 2 and 3) are better than the sinusoidal approach: the model with L = 512 ( L = 1024 ) improves perplexity with up to k = 200 ( k = 100 ) more tokens than it saw during training, but this comes at the cost of slower training and inference (Figure 2).
|
| 82 |
+
|
| 83 |
+
T5 Bias Though most models use trained or sinusoidal position embeddings, the T5 model of Raffel et al. (2020) uses a relative position method (Shaw et al., 2018; Huang et al., 2019) that adds no position information to word embeddings (as in the previous method). Instead, it modifies the way attention values are computed. We refer to this as the 'T5 bias' method. 6 To compute attention values in the unmodified transformer, we compute the dot product of every query with every relevant key and then softmax these attention values. In this method, we compute the attention values as before, but then we add a learned, shared bias to each query-key score that is dependent on just the distance between the query and key. Therefore, all query-key scores where the query and key distance are zero (i.e., the query and key represent the same token) get a specific learned bias, all scores where the query and key are one word away get a different learned bias, and so on, up to a certain point, from where multiple different distances share the same learned bias (which might be beneficial for extrapolation). As in the rotary method, the T5 bias injects position information into the model at every layer and integrates no explicit position information into the self-attention value vectors.
|
| 84 |
+
|
| 85 |
+
Raffel et al. (2020) propose that the T5 bias may allow extrapolation, but they did not report experiments testing this. Here, we show that the T5 bias does allow language models to extrapolate. We do this by again modifying the Baevski & Auli model, this time to insert the T5 bias into it. 7
|
| 86 |
+
|
| 87 |
+
As Figure 1 shows, the T5 bias improves perplexity with longer sequences than the ones it was trained on, i.e., k = 600 ( k = 800 ) extra tokens for a model trained on L = 512 ( L = 1024 ) input tokens. Unfortunately, this impressive performance comes at a cost: training is at least twice as slow as with the sinusoidal model. Therefore, this model's extrapolation ability provides no efficiency advantage. For example, to do inference on 1024 tokens, we could either train the sinusoidal model with L = 1024 or train the T5 bias model on L = 512 tokens and extrapolate to 1024 for inference. However, the L = 1024 sinusoidal model runs at 28.5k words per second (WPS), while the L = 512 T5 bias model runs at 14.4k WPS (Appendix Table 1), so there is no speedup when training on shorter sequences with this method. 8
|
| 88 |
+
|
| 89 |
+
5 Our rotary method implementation is based on the code in https://github.com/JunnYu/ RoFormer\_pytorch , which is linked to from the official repository of Su et al. (2021): ( https: //github.com/ZhuiyiTechnology/roformer ). After we finished running our experiments with the rotary method, we were informed that the runtime of the code linked above could be optimized, making it only 2% slower than the sinusoidal approach. This optimization would not change extrapolation performance.
|
| 90 |
+
|
| 91 |
+
6 This method is similar to the one used in Parikh et al. (2016, Equation 7).
|
| 92 |
+
|
| 93 |
+
7 Our T5 bias implementation is based on the one used in HuggingFace Transformers (Wolf et al., 2020), which in turn is based on the official Mesh Tensorflow T5 code.
|
| 94 |
+
|
| 95 |
+
8 Narang et al. (2021) benchmarked the T5 bias as being just 8.7% slower than the sinusoidal approach; thus, while always incurring a runtime penalty, this method's runtime could be faster depending on the choice of hardware and software frameworks used. Narang et al. used the Tensorflow T5 library running on TPUs, while we used the PyTorch Fairseq library running on GPUs.
|
| 96 |
+
|
| 97 |
+
Figure 3: When computing attention scores for each head, our linearly biased attention method, ALiBi, adds a constant bias (right) to each attention score ( q i · k j , left). As in the unmodified attention sublayer, the softmax function is then applied to these scores, and the rest of the computation is unmodified. mis a head-specific scalar that is set and not learned throughout training. We show that our method for setting m values generalizes to multiple text domains, models and training compute budgets. When using ALiBi, we do not add positional embeddings at the bottom of the network.
|
| 98 |
+
|
| 99 |
+
<!-- image -->
|
| 100 |
+
|
| 101 |
+
## 3 ATTENTION WITH LINEAR BIASES (ALIBI)
|
| 102 |
+
|
| 103 |
+
In the transformer model of Vaswani et al. (2017), position embeddings are added to the word embeddings at the bottom of the network. For an input subsequence of length L , the attention sublayer computes the attention scores for the i th query q i ∈ R 1 × d , ( 1 ≤ i ≤ L ) in each head, given the first i keys K ∈ R i × d , where d is the head dimension:
|
| 104 |
+
|
| 105 |
+
<!-- formula-not-decoded -->
|
| 106 |
+
|
| 107 |
+
These attention scores are then multiplied by the values to return the output of the attention sublayer. 9
|
| 108 |
+
|
| 109 |
+
When using ALiBi, we do not add position embeddings at any point in the network. The only modification we apply is after the query-key dot product, where we add a static, non-learned bias: 10
|
| 110 |
+
|
| 111 |
+
<!-- formula-not-decoded -->
|
| 112 |
+
|
| 113 |
+
where scalar m is a head-specific slope fixed before training. Figure 3 offers a visualization.
|
| 114 |
+
|
| 115 |
+
For our models with 8 heads, the slopes that we used are the geometric sequence: 1 2 1 , 1 2 2 , ..., 1 2 8 . For models that require 16 heads, we interpolate those 8 slopes by geometrically averaging every consecutive pair, resulting in the geometric sequence that starts at 1 √ 2 and has the ratio of 1 √ 2 : 1 2 0 . 5 , 1 2 1 , 1 2 1 . 5 , ..., 1 2 8 . In general, for n heads, our set of slopes is the geometric sequence that starts at 2 -8 n and uses that same value as its ratio.
|
| 116 |
+
|
| 117 |
+
In §4, we observe that this set of slopes works on a wide variety of text domains and model sizes. Therefore, we do not believe that it is necessary to tune these slope values every time a new model is trained on a new dataset. This makes our method similar to the sinusoidal approach, where the hyperparameters (the start and end of the geometric progression of wavelengths) were set once by Vaswani et al. (2017) and then reused in different models of different sizes on different datasets.
|
| 118 |
+
|
| 119 |
+
ALiBi has an inductive bias towards recency; it penalizes attention scores between distant query-key pairs, with the penalty increasing as the distance between a key and a query grows. The different heads increase their penalties at different rates, depending on the slope magnitude.
|
| 120 |
+
|
| 121 |
+
We initially experimented with making the slopes trainable, but this did not yield strong extrapolation results. 11 Abrief manual exploration of around ten slope sets led us to discover the set of slopes that we finally picked. Our main insight from this exploration is that the slope sets that work best are those with slopes in the (0 , 1) range, with the slopes' density increasing as we get closer to 0 . We also found our method to be robust to slope choice. Even randomly sampling from the exponential distribution worked well in some cases (although that method had high variance).
|
| 122 |
+
|
| 123 |
+
Since ALiBi is a relative position method, we add position information at every layer to the keys and queries but not to the values, as is done in the T5 bias and rotary methods. We hypothesize that these properties might be beneficial for extrapolation.
|
| 124 |
+
|
| 125 |
+
9 For simplicity we omit the key, query, value and final output projections, dropout, and the scaling factor. √
|
| 126 |
+
|
| 127 |
+
10 The ALiBi bias is not multiplied by the d k scaling factor from Equation 1 of Vaswani et al. (2017).
|
| 128 |
+
|
| 129 |
+
11 In our experiments, trainable slopes also slowed down the training speed by 3%.
|
| 130 |
+
|
| 131 |
+
Implementation. ALiBi is easy to implement, with all changes accomplished in a few lines of code. We implement it by modifying the mask matrix by adding the linear biases to it (in practice, when training a transformer LM, query q i attends only to keys 1 to i ; this is implemented by adding a mask matrix to the query-key dot product before the softmax operation is applied). This means that there is no runtime penalty when using our method since we add no operations to the network.
|
| 132 |
+
|
| 133 |
+
Compared to the sinusoidal model trained on the same input lengths, AliBi incurs a memory increase (up to 100MB in some of our experiments): in the unmodified transformer, the mask is of size L × L ; when using ALiBi, the mask is a slightly larger n × L × L (where n is the number of heads) since the linear biases added for each head uses a different slope. But, as we show, ALiBi enables training on much smaller sequences while still achieving (and occasionally surpassing) results obtained using sinusoidal embeddings on longer sequences, which saves multiple gigabytes of memory.
|
| 134 |
+
|
| 135 |
+
## 4 RESULTS
|
| 136 |
+
|
| 137 |
+
We first show that on WikiText103 ALiBi is efficient and enables training models with short input subsequences that outperform strong baselines even when the ALiBi models extrapolate to more than six times the number of tokens that they were trained on. We then take the same hyperparameters for our method (the set of slopes) that worked on WikiText-103 and show that - with no modification - they provide strong results on a dataset in a very different domain: books. Finally, we show that a 1.3B parameter model trained with AliBi on a much larger (461 GB) dataset with much more compute provides a superior alternative to the sinusoidal method since it achieves similar perplexity scores while running faster and using less memory (since it is trained on shorter inputs).
|
| 138 |
+
|
| 139 |
+
While multiple alternatives to the position methods presented in Vaswani et al. (2017) have been proposed, few have been adopted in large (1B or more parameter) LMs since that setting is much more challenging than the smaller scale experiments. GPT-3 and Jurassic-1 (Lieber et al., 2021) use the learned position embedding method from Vaswani et al., and GPT-J uses the rotary method. Our results on the 1.3B parameter model show our method's ability to generalize to larger models, dataset sizes and training durations without retuning the hyperparameter.
|
| 140 |
+
|
| 141 |
+
## 4.1 RESULTS ON WIKITEXT-103 AND TORONTO BOOKCORPUS
|
| 142 |
+
|
| 143 |
+
Figure 4: ALiBi models trained and evaluated on varying sequence lengths on the WikiText-103 validation set and the sinusoidal baseline (not evaluated on longer sequences). All of our models outperform the sinusoidal ones even when trained on fewer tokens. Appendix Table 5 has exact perplexities, more ALiBi models (trained on fewer tokens), and results for rotary and T5 bias models.
|
| 144 |
+
|
| 145 |
+
<!-- image -->
|
| 146 |
+
|
| 147 |
+
We first develop our method on the WikiText-103 corpus (Merity et al., 2016), replacing the sinusoidal position embeddings in the language model of Baevski & Auli (2018) with ALiBi.
|
| 148 |
+
|
| 149 |
+
Figure 4 (and the corresponding Appendix Table 5) show our results for models trained with varying numbers of input subsequence tokens ( L ), extrapolating to longer subsequence lengths on the validation dataset. Our first observation is that, without extrapolation, for every L , our models outperform those using the sinusoidal method, sometimes by a significant amount. For example, the Baevski & Auli model achieves 18.67 ± 0.24 (std. dev.) perplexity when trained with L = 3072 input tokens, but our L = 3072 model achieves 17.60 perplexity (when both models evaluate with L valid = 3072).
|
| 150 |
+
|
| 151 |
+
Our second observation is that all of our models can extrapolate, and they obtain improved perplexity scores when handling more tokens than they observed during training. For example, our model trained on 512 tokens (which achieves 19.73 perplexity when evaluating subsequences of length 512 in the development set) achieves a perplexity score of 18.40 on the development set when extrapolating to subsequences of length 3072. Surprisingly, this surpasses the score that the L = 3072 sinusoidal model obtains on the development set by a statistically significant margin. Note that all our models trained on L = 512 to L = 2048 outperform the sinusoidal baseline trained on L = 3072 when extrapolating to L valid = 3072 even though those models all take much less time to train since they train on shorter subsequences (Appendix Figure 8 compares training speed to perplexity for these models)! The L = 512 model is 1.84 times faster to train and yet still outperforms the L = 3072 sinusoidal model when extrapolating to L valid = 3072 . In addition, training the L = 3072 sinusoidal model requires a GPU with more than 16 GB of memory to fit the large attention matrices, which our L = 512 outperforms even though it can be trained on a GPU with much less memory due to much smaller attention matrices.
|
| 152 |
+
|
| 153 |
+
Additionally, Table 5 (in the appendix) also shows that, for L s of 1024 and 3072, our method performs better than the rotary and T5 bias models even when L valid = L (i.e., no extrapolation is occurring). Figure 1 (and the corresponding Appendix Tables 2 and 3) more broadly explore our method vs. the other position methods. They show that the T5 bias (the best of the baselines) improves perplexity until L valid is around 2 L , but on the WikiText-103 dataset our method continually improves perplexity until at least around 3 L , with the L = 512 model improving perplexity even when L valid exceeds 12k tokens. Even when unable to improve perplexity given longer sequences, ALiBi always maintains strong performance as more tokens are added.
|
| 154 |
+
|
| 155 |
+
Appendix Table 6 shows that our results on the validation set also transfer to the test set of WikiText103. Currently, almost all models that present results on WikiText-103 use sliding window evaluation (defined in §B) to compute perplexities. We apply that method to our (and to the sinusoidal, rotary and T5 bias) models in Appendix Table 7. We find that our L = 3072 model surpasses the performance of Transformer-XL (Dai et al., 2019), the Sandwich (Press et al., 2020), and Shortformer (Press et al., 2021) models. Our results are similar to the ones obtained with staged training (Press et al., 2021) but fall short of results obtained by Routing Transformer (Roy et al., 2020) and kNN-LM (Khandelwal et al., 2020). The methods used in those models are orthogonal to ours, and we hypothesize that combining them with ours might lead to even larger performance increases.
|
| 156 |
+
|
| 157 |
+
After developing our method on WikiText-103, in Appendix Section A.3, we run one set of experiments on a different domain (books) using a similar model architecture and without modifying any of the ALiBi hyperparameters (the slopes) and show that our results fully transfer to this new domain. Our models are able to both surpass the sinusoidal baseline when not extrapolating while also outperforming it when extrapolating to longer sequences.
|
| 158 |
+
|
| 159 |
+
## 4.2 RESULTS ON THE CC100+ROBERTA CORPUS
|
| 160 |
+
|
| 161 |
+
Our final set of experiments investigates whether ALiBi transfers to a larger model trained with a larger computational budget on a larger dataset than the ones we previously used. We show that our method achieves strong results in this more challenging setting, obtaining similar performance to the sinusoidal baseline while using significantly less memory, since we train on shorter subsequences.
|
| 162 |
+
|
| 163 |
+
The dataset we choose is a combination of the datasets used to train the RoBERTa (Liu et al., 2019) implementation of BERT (Devlin et al., 2019) and the English part of the CC-100 corpus introduced in Conneau et al. (2020), for a total of 461 GB. The RoBERTa training corpus-i.e., the Toronto Book Corpus (Zhu et al., 2015), English Wikipedia, CC-News (Nagel, 2016), OpenWebText (Gokaslan & Cohen, 2019) and Stories (Trinh & Le, 2018))-is 161 gigabytes, and the English part of the CC-100 corpus is 300 gigabytes. The validation set contains 649K tokens.
|
| 164 |
+
|
| 165 |
+
Our models for this dataset have 25 transformer layers with 16 heads and a dimension of 2048, with an 8192 hidden dimension of the feedforward sublayers. These models have 1.3B parameters. We train our models for one epoch, which is 50k updates on 128 V100 GPUs.
|
| 166 |
+
|
| 167 |
+
In Figure 5 (left), we compare the validation perplexity for L valid = 1024 throughout the training process for an ALiBi model trained with L = 512 compared to the sinusoidal model trained with L = 1024. Since our model is trained on shorter sequences, it is 7% faster and uses 1.6 GB less memory. We halt training of the sinusoidal baseline when our model reaches the end of its training (one epoch). At that time, our model is just 0.06 perplexity away from the baseline even though it was trained on sequences that are half the length of those the baseline used and requires less memory.
|
| 168 |
+
|
| 169 |
+
Figure 5: On the left (right), a 1.3B-parameter ALiBi model trained on 512 (1024) and evaluated on 1024 (2048) tokens during training, compared to the sinusoidal baseline trained on 1024 (2048) tokens. The ALiBi models obtain strong results even though they use 6%-11% less memory since they train on shorter sequences. Appendix Table 11 shows memory use and end-of-training perplexities.
|
| 170 |
+
|
| 171 |
+
<!-- image -->
|
| 172 |
+
|
| 173 |
+
In Figure 5 (right), results become even more impressive, showing that our model trained on L = 1024 outperforms by 0.09 perplexity the sinusoidal model trained on L = 2048 (when evaluating with L valid = 2048) even though our model uses 3.1 GB less memory. Our model maintains a lead in perplexity over the sinusoidal model during the entire training process. By sampling five evenly distributed points across the training process, we compute that our L = 1024 model reaches a given perplexity value, on average, 11% faster than the sinusoidal model does.
|
| 174 |
+
|
| 175 |
+
Since our models in these comparisons use much less memory, they allow for stacking more layers, which would further improve performance (with negligible, if any, runtime cost). To keep our experiments as straightforward as possible, however, we do not add layers to our models.
|
| 176 |
+
|
| 177 |
+
Appendix Table 12 presents additional results comparing our models to the sinusoidal baseline when both are trained on the same L , showing that ALiBi performs similarly to the sinusoidal baseline when not extrapolating. This contrasts with the results presented on the smaller datasets, where ALiBi consistently outperforms other position methods even when not extrapolating, suggesting that ALiBi's inductive bias provides additional benefits for lower-resource language modeling.
|
| 178 |
+
|
| 179 |
+
<!-- image -->
|
| 180 |
+
|
| 181 |
+
Validation Input Length (
|
| 182 |
+
|
| 183 |
+
Lvalid
|
| 184 |
+
|
| 185 |
+
)
|
| 186 |
+
|
| 187 |
+
Figure 6: The ALiBi and sinusoidal models (with both L = 512 and 1024) trained for 50k updates (1 epoch) on the CC100+RoBERTa corpus, extrapolating on the validation set. ALiBi achieves the best results at around 2 L but maintains strong performance even up to 10000 tokens in these experiments.
|
| 188 |
+
|
| 189 |
+
Figure 6 shows that our models trained on L = 512 and L = 1024 achieve the best results when extrapolating to about double the tokens that they were trained on. Specifically, the L = 512 model (that obtains 9.79 perplexity when L valid = 512) achieves its best score (9.3) when extrapolating to
|
| 190 |
+
|
| 191 |
+
1012 tokens, and the L = 1024 model (that obtains 9.16 perplexity when L valid = 1024) achieves its best score (8.9) when extrapolating to 2024 tokens.
|
| 192 |
+
|
| 193 |
+
One possible explanation is that the subsequences the model observes during training are up to L tokens long. When performing inference on subsequences of length 2 L , half of the subsequences the model consumes are as long as the examples seen during training. When inference is performed on subsequences of length 2 L +1 or longer, less than half of the predictions the model makes are on subsequences of lengths seen during training, and that might degrade performance.
|
| 194 |
+
|
| 195 |
+
The sinusoidal model cannot extrapolate at all in this setting, with its performance degrading for both the L = 512 and 1024 models as soon as one token more than L is added during evaluation.
|
| 196 |
+
|
| 197 |
+
In Appendix B, we find that ALiBi's edge over sinusoidal embeddings is largely explained by its improved avoidance of the early token curse. We posit that future work building on ALiBi might achieve further gains by more efficiently exploiting longer histories.
|
| 198 |
+
|
| 199 |
+
## 5 RELATED WORK
|
| 200 |
+
|
| 201 |
+
In parallel with our work, Wennberg & Henter (2021) introduce a relative position method that, like our method, adds a bias to attention scores that is a function of the distance between the key and query elements. Unlike our ALiBi method, which uses a non-learned linear function, their method uses a radial-basis function, with multiple trainable parameters (in our experiments, this led to a slight decrease in runtime). In addition, they present experiments on text classification, not on language modeling. They do not explore extrapolation. The Distance Aware Transformer (Wu et al., 2021) multiplies attention scores by a bias that is a function of the distance between the key and query. This function uses a different, learned parameter in every head. They show results only on text classification. In our experiments (not presented), multiplying attention scores by the bias (instead of adding, as in ALiBi) degraded performance.
|
| 202 |
+
|
| 203 |
+
Transformer-XL (Dai et al., 2019) presented a language model that uses a cache and can attend to more tokens during inference than it was trained on (by increasing the length of the cache). However, this work presents results only where output length is limited to the L (the training length), and their relative position method is very slow (Press et al., 2021). The Longformer (Beltagy et al., 2020) adapts models trained on shorter sequences to document-level tasks. However, to achieve this they had to partially train their models on longer sequences. Our ALiBi method enables extrapolation without any additional training on longer sequences.
|
| 204 |
+
|
| 205 |
+
To our knowledge, extrapolation has not been previously explored in transformer language modeling, but it has been investigated previously and concurrently with transformers on other tasks, such as machine translation (Rosendahl et al., 2019; Neishi & Yoshinaga, 2019; Newman et al., 2020; Kiyono et al., 2021), sequence-to-sequence models trained on an artificial dataset (Hupkes et al., 2020), pretrained sequence-to-sequence models tested on arithmetic tasks (Nogueira et al., 2021, Appendix C), models trained with reinforcement learning (Lampinen et al., 2021), image, speech recognition, and machine translation models (Likhomanenko et al., 2021), and protein structure prediction (Jumper et al., 2021, Appendix 1.5).
|
| 206 |
+
|
| 207 |
+
## 6 CONCLUSION
|
| 208 |
+
|
| 209 |
+
We showed that the sinusoidal position embedding approach does not enable transformers to extrapolate to inputs longer than the ones they were trained on. We then established that extrapolation in transformers can be enabled by just changing the position method. We showed that our ALiBi method offers an extremely simple replacement for existing position approaches and allow models to extrapolate. In addition, when not extrapolating, our method achieves either better perplexity than the sinusoidal method (in models smaller than 1B parameters, trained on less data) or similar perplexity (in larger, billion parameter models trained on much more data). ALiBi is simple to implement and does not slow down runtime or require extra parameters (but does occasionally require a negligible amount of extra memory). Using our method, we sped up the training of a 1.3 billion parameter model evaluated on the same input sequence length as GPT-3 (2048).
|
| 210 |
+
|
| 211 |
+
## ACKNOWLEDGMENTS
|
| 212 |
+
|
| 213 |
+
We thank Tim Dettmers, Gabriel Ilharco, Jungo Kasai, Hao Peng, Sewon Min, Sofia Serrano, Sam Shleifer, Luke Zettlemoyer, Julian Michael, Nikolaos Pappas, Yizhong Wang, and the anonymous reviewers for their valuable feedback and fruitful discussions.
|
| 214 |
+
|
| 215 |
+
## REFERENCES
|
| 216 |
+
|
| 217 |
+
- Alexei Baevski and Michael Auli. Adaptive input representations for neural language modeling. CoRR , abs/1809.10853, 2018. URL http://arxiv.org/abs/1809.10853 .
|
| 218 |
+
- Iz Beltagy, Matthew E. Peters, and Arman Cohan. Longformer: The long-document transformer. arXiv:2004.05150 , 2020.
|
| 219 |
+
- Tom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah, Jared Kaplan, Prafulla Dhariwal, Arvind Neelakantan, Pranav Shyam, Girish Sastry, Amanda Askell, Sandhini Agarwal, Ariel Herbert-Voss, Gretchen Krueger, Tom Henighan, Rewon Child, Aditya Ramesh, Daniel M. Ziegler, Jeffrey Wu, Clemens Winter, Christopher Hesse, Mark Chen, Eric Sigler, Mateusz Litwin, Scott Gray, Benjamin Chess, Jack Clark, Christopher Berner, Sam McCandlish, Alec Radford, Ilya Sutskever, and Dario Amodei. Language models are few-shot learners, 2020.
|
| 220 |
+
- Alexis Conneau, Kartikay Khandelwal, Naman Goyal, Vishrav Chaudhary, Guillaume Wenzek, Francisco Guzm´ an, Edouard Grave, Myle Ott, Luke Zettlemoyer, and Veselin Stoyanov. Unsupervised cross-lingual representation learning at scale. Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics , 2020. doi: 10.18653/v1/2020.acl-main.747. URL http://dx.doi.org/10.18653/v1/2020.acl-main.747 .
|
| 221 |
+
- Zihang Dai, Zhilin Yang, Yiming Yang, Jaime Carbonell, Quoc Le, and Ruslan Salakhutdinov. Transformer-XL: Attentive language models beyond a fixed-length context. In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics , pp. 2978-2988, Florence, Italy, July 2019. Association for Computational Linguistics. doi: 10.18653/v1/P19-1285. URL https://aclanthology.org/P19-1285 .
|
| 222 |
+
- Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. BERT: Pre-training of deep bidirectional transformers for language understanding. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers) , pp. 4171-4186, Minneapolis, Minnesota, June 2019. Association for Computational Linguistics. doi: 10.18653/v1/N19-1423. URL https: //www.aclweb.org/anthology/N19-1423 .
|
| 223 |
+
- Aaron Gokaslan and Vanya Cohen. Openwebtext corpus. http://Skylion007.github.io/ OpenWebTextCorpus , 2019.
|
| 224 |
+
- Cheng-Zhi Anna Huang, Ashish Vaswani, Jakob Uszkoreit, Ian Simon, Curtis Hawthorne, Noam M. Shazeer, Andrew M. Dai, M. Hoffman, M. Dinculescu, and D. Eck. Music transformer: Generating music with long-term structure. In ICLR , 2019.
|
| 225 |
+
- Dieuwke Hupkes, Verna Dankers, Mathijs Mul, and Elia Bruni. Compositionality decomposed: How do neural networks generalise? Journal of Artificial Intelligence Research , 67:757-795, April 2020. doi: 10.1613/jair.1.11674. URL https://doi.org/10.1613/jair.1. 11674 .
|
| 226 |
+
- Hakan Inan, Khashayar Khosravi, and Richard Socher. Tying word vectors and word classifiers: A loss framework for language modeling. In ICLR , 2017. URL https://openreview.net/ forum?id=r1aPbsFle .
|
| 227 |
+
- J. Jumper, Richard Evans, A. Pritzel, Tim Green, Michael Figurnov, O. Ronneberger, Kathryn Tunyasuvunakool, Russ Bates, Augustin Z´ ıdek, Anna Potapenko, A. Bridgland, Clemens Meyer, Simon A A Kohl, Andy Ballard, A. Cowie, B. Romera-Paredes, Stanislav Nikolov, Rishub Jain, J. Adler, T. Back, Stig Petersen, D. Reiman, Ellen Clancy, Michal Zielinski, Martin Steinegger, Michalina Pacholska, Tamas Berghammer, S. Bodenstein, D. Silver, Oriol Vinyals, A. Senior, K. Kavukcuoglu, P. Kohli, and D. Hassabis. Highly accurate protein structure prediction with alphafold. Nature , 596:583 - 589, 2021.
|
| 228 |
+
- Urvashi Khandelwal, Omer Levy, Dan Jurafsky, Luke Zettlemoyer, and Mike Lewis. Generalization through Memorization: Nearest Neighbor Language Models. In International Conference on Learning Representations (ICLR) , 2020.
|
| 229 |
+
|
| 230 |
+
- Shun Kiyono, Sosuke Kobayashi, Jun Suzuki, and Kentaro Inui. Shape: Shifted absolute position embedding for transformers. ArXiv , abs/2109.05644, 2021.
|
| 231 |
+
- Andrew Kyle Lampinen, Stephanie C. Y. Chan, Andrea Banino, and Felix Hill. Towards mental time travel: a hierarchical memory for reinforcement learning agents. CoRR , abs/2105.14039, 2021. URL https://arxiv.org/abs/2105.14039 .
|
| 232 |
+
- Mike Lewis, Shruti Bhosale, Tim Dettmers, Naman Goyal, and Luke Zettlemoyer. Base layers: Simplifying training of large, sparse models, 2021.
|
| 233 |
+
- Opher Lieber, Or Sharir, Barak Lenz, and Yoav Shoham. Jurassic-1: Technical details and evaluation. Technical report, AI21 Labs, August 2021.
|
| 234 |
+
- Tatiana Likhomanenko, Qiantong Xu, Ronan Collobert, Gabriel Synnaeve, and Alex Rogozhnikov. CAPE: encoding relative positions with continuous augmented positional embeddings. CoRR , abs/2106.03143, 2021. URL https://arxiv.org/abs/2106.03143 .
|
| 235 |
+
- Yinhan Liu, Myle Ott, Naman Goyal, Jingfei Du, Mandar Joshi, Danqi Chen, Omer Levy, Mike Lewis, Luke Zettlemoyer, and Veselin Stoyanov. Roberta: A robustly optimized bert pretraining approach, 2019.
|
| 236 |
+
- Stephen Merity, Caiming Xiong, James Bradbury, and Richard Socher. Pointer sentinel mixture models, 2016.
|
| 237 |
+
- Tomas Mikolov and G. Zweig. Context dependent recurrent neural network language model. 2012 IEEE Spoken Language Technology Workshop (SLT) , pp. 234-239, 2012.
|
| 238 |
+
- Tomas Mikolov, M. Karafi´ at, L. Burget, J. Cernock´ y, and S. Khudanpur. Recurrent neural network based language model. In INTERSPEECH , 2010.
|
| 239 |
+
- Sebastian Nagel. Cc-news. https://commoncrawl.org/2016/10/ news-dataset-available/ , 2016.
|
| 240 |
+
- Sharan Narang, Hyung Won Chung, Yi Tay, William Fedus, Thibault Fevry, Michael Matena, Karishma Malkan, Noah Fiedel, Noam Shazeer, Zhenzhong Lan, Yanqi Zhou, Wei Li, Nan Ding, Jake Marcus, Adam Roberts, and Colin Raffel. Do transformer modifications transfer across implementations and applications?, 2021.
|
| 241 |
+
- Masato Neishi and Naoki Yoshinaga. On the relation between position information and sentence length in neural machine translation. In Proceedings of the 23rd Conference on Computational Natural Language Learning (CoNLL) , pp. 328-338, Hong Kong, China, November 2019. Association for Computational Linguistics. doi: 10.18653/v1/K19-1031. URL https://aclanthology.org/K19-1031 .
|
| 242 |
+
- Benjamin Newman, John Hewitt, Percy Liang, and Christopher D. Manning. The eos decision and length extrapolation. In BlackBoxNLP@EMNLP , 2020. URL https://nlp.stanford. edu/pubs/newman2020extrapolation.pdf .
|
| 243 |
+
- Rodrigo Nogueira, Zhiying Jiang, and Jimmy J. Li. Investigating the limitations of the transformers with simple arithmetic tasks. ArXiv , abs/2102.13019, 2021.
|
| 244 |
+
- Myle Ott, Sergey Edunov, David Grangier, and Michael Auli. Scaling neural machine translation. In Proceedings of the Third Conference on Machine Translation (WMT) , 2018.
|
| 245 |
+
- Ankur Parikh, Oscar T¨ ackstr¨ om, Dipanjan Das, and Jakob Uszkoreit. A decomposable attention model for natural language inference. In Proceedings of the 2016 Conference on Empirical Methods in Natural Language Processing , pp. 2249-2255, Austin, Texas, November 2016. Association for Computational Linguistics. doi: 10.18653/v1/D16-1244. URL https: //aclanthology.org/D16-1244 .
|
| 246 |
+
- Ofir Press and Lior Wolf. Using the output embedding to improve language models. In Proceedings of the 15th Conference of the European Chapter of the Association for Computational Linguistics: Volume 2, Short Papers , pp. 157-163, Valencia, Spain, April 2017. Association for Computational Linguistics. URL https://www.aclweb.org/anthology/E17-2025 .
|
| 247 |
+
|
| 248 |
+
- Ofir Press, Noah A. Smith, and Omer Levy. Improving transformer models by reordering their sublayers. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics , pp. 2996-3005, Online, July 2020. Association for Computational Linguistics. doi: 10.18653/v1/2020.acl-main.270. URL https://www.aclweb.org/anthology/2020. acl-main.270 .
|
| 249 |
+
- Ofir Press, Noah A. Smith, and Mike Lewis. Shortformer: Better language modeling using shorter inputs. In Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing (Volume 1: Long Papers) , pp. 5493-5505, Online, August 2021. Association for Computational Linguistics. URL https://aclanthology.org/2021.acl-long.427 .
|
| 250 |
+
- Jack W. Rae, Anna Potapenko, Siddhant M. Jayakumar, Chloe Hillier, and Timothy P. Lillicrap. Compressive transformers for long-range sequence modelling. In International Conference on Learning Representations , 2020. URL https://openreview.net/forum?id= SylKikSYDH .
|
| 251 |
+
- Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, and Peter J. Liu. Exploring the limits of transfer learning with a unified text-totext transformer. Journal of Machine Learning Research , 21(140):1-67, 2020. URL http: //jmlr.org/papers/v21/20-074.html .
|
| 252 |
+
- Jan Rosendahl, Viet Anh Khoa Tran, Weiyue Wang, and Hermann Ney. Analysis of positional encodings for neural machine translation. In International Workshop on Spoken Language Translation , Hong Kong, China, November 2019.
|
| 253 |
+
- Aurko Roy, Mohammad Saffar, Ashish Vaswani, and David Grangier. Efficient content-based sparse attention with routing transformers, 2020.
|
| 254 |
+
- Peter Shaw, Jakob Uszkoreit, and Ashish Vaswani. Self-attention with relative position representations. In Proceedings of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 2 (Short Papers) , pp. 464-468, New Orleans, Louisiana, June 2018. Association for Computational Linguistics. doi: 10.18653/v1/N18-2074. URL https://www.aclweb.org/anthology/N18-2074 .
|
| 255 |
+
- Jianlin Su, Yu Lu, Shengfeng Pan, Bo Wen, and Yunfeng Liu. Roformer: Enhanced transformer with rotary position embedding, 2021.
|
| 256 |
+
- Trieu H. Trinh and Quoc V. Le. A simple method for commonsense reasoning, 2018.
|
| 257 |
+
- Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Ł ukasz Kaiser, and Illia Polosukhin. Attention is all you need. In I. Guyon, U. V. Luxburg, S. Bengio, H. Wallach, R. Fergus, S. Vishwanathan, and R. Garnett (eds.), Advances in Neural Information Processing Systems , volume 30. Curran Associates, Inc., 2017. URL https://proceedings.neurips.cc/paper/2017/file/ 3f5ee243547dee91fbd053c1c4a845aa-Paper.pdf .
|
| 258 |
+
- Ben Wang and Aran Komatsuzaki. GPT-J-6B: A 6 Billion Parameter Autoregressive Language Model. https://github.com/kingoflolz/mesh-transformer-jax , May 2021.
|
| 259 |
+
- Ulme Wennberg and Gustav Eje Henter. The case for translation-invariant self-attention in transformer-based language models, 2021.
|
| 260 |
+
- Thomas Wolf, Lysandre Debut, Victor Sanh, Julien Chaumond, Clement Delangue, Anthony Moi, Pierric Cistac, Tim Rault, R´ emi Louf, Morgan Funtowicz, Joe Davison, Sam Shleifer, Patrick von Platen, Clara Ma, Yacine Jernite, Julien Plu, Canwen Xu, Teven Le Scao, Sylvain Gugger, Mariama Drame, Quentin Lhoest, and Alexander M. Rush. Transformers: State-of-the-art natural language processing. In Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing: System Demonstrations , pp. 38-45, Online, October 2020. Association for Computational Linguistics. URL https://www.aclweb.org/anthology/ 2020.emnlp-demos.6 .
|
| 261 |
+
|
| 262 |
+
- Chuhan Wu, Fangzhao Wu, and Yongfeng Huang. DA-transformer: Distance-aware transformer. In Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies , pp. 2059-2068, Online, June 2021. Association for Computational Linguistics. doi: 10.18653/v1/2021.naacl-main.166. URL https://aclanthology.org/2021.naacl-main.166 .
|
| 263 |
+
- Wojciech Zaremba, Ilya Sutskever, and Oriol Vinyals. Recurrent neural network regularization, 2014.
|
| 264 |
+
- Yukun Zhu, Ryan Kiros, Rich Zemel, Ruslan Salakhutdinov, Raquel Urtasun, Antonio Torralba, and Sanja Fidler. Aligning books and movies: Towards story-like visual explanations by watching movies and reading books. In Proceedings of the IEEE international conference on computer vision , pp. 19-27, 2015.
|
| 265 |
+
|
| 266 |
+
## A APPENDIX
|
| 267 |
+
|
| 268 |
+
## A.1 INTRODUCTION
|
| 269 |
+
|
| 270 |
+
The training speed of transformer LMs gets slower as the input subsequence length L increases. Figure 7 visualizes this.
|
| 271 |
+
|
| 272 |
+
Figure 7: Training speed of our model and the sinusoidal baseline trained on different amounts of input subsequence tokens L .
|
| 273 |
+
|
| 274 |
+
<!-- image -->
|
| 275 |
+
|
| 276 |
+
Table 1 contains the runtimes and memory use statistics for models using the various position methods discussed in this work.
|
| 277 |
+
|
| 278 |
+
Table 1: The speed (during training and evaluation, in words per second) and memory usage (during training) of the rotary, T5 bias, and ALiBi models compared to the sinusoidal baseline on WikiText103. Training and inference are batched, and speeds are shown for one V100 GPU.
|
| 279 |
+
|
| 280 |
+
| Position Method Train Length Speed ( ↑ ) Memory ( ↓ ) Train Eval. 512 28.5k 82.1k 15.3 GB Sinusoidal 1024 26.0k 77.8k 19.2 GB 3072 15.3k 42.4k 15.1 GB 512 20.0k 43.4k 17.8 GB Rotary 1024 17.7k 39.4k 22.8 GB 3072 11.5k 29.5k 17.8 GB 512 14.4k 21.8k 16.9 GB T5 Bias 1024 13.0k 20.2k 20.9 GB 3072 4.3k 4.9k 15.9 GB 512 28.3k 85.8k 15.3 GB ALiBi 1024 25.8k 76.4k 19.3 GB 3072 15.5k 42.2k 15.2 GB |
|
| 281 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 282 |
+
|
| 283 |
+
Tables 2, 3, and 4 show the perplexity and runtime of models using the sinusoidal, rotary T5 bias, and ALiBi position methods when extrapolating to sequences longer than the ones they were trained on. The models used in these tables were trained on L = 512 , 1024 and 3072 tokens.
|
| 284 |
+
|
| 285 |
+
Table 2: The sinusoidal, rotary, T5 bias and ALiBi models trained on L = 512 on WikiText-103 and evaluated with different values of L valid on the validation set. Bold shows the best score for each model. Inference speeds (in words per second) are from inference on a GPU with batch size of one.
|
| 286 |
+
|
| 287 |
+
| Sinusoidal Rotary T5 Bias ALiBi Inputs PPL ( ↓ ) WPS ( ↑ ) PPL ( ↓ ) WPS ( ↑ ) PPL ( ↓ ) WPS ( ↑ ) PPL ( ↓ ) WPS ( ↑ ) 512 20.05 15046 20.07 10839 19.65 11724 19.73 14726 513 19.98 14925 20.01 10806 19.57 10491 19.62 14965 522 19.93 15116 20.02 11295 19.57 9970 19.64 15316 532 19.91 15358 19.98 10854 19.53 10382 19.61 15383 542 19.91 15076 19.94 10795 19.47 12270 19.57 15301 552 19.91 16394 19.93 12267 19.47 13000 19.54 16540 562 19.91 16646 19.87 12481 19.39 12201 19.49 16385 572 19.95 16934 19.83 12668 19.36 12851 19.46 16881 582 20.13 16961 19.88 12594 19.41 13904 19.48 17064 592 20.18 17243 19.84 13007 19.36 13706 19.43 17289 602 20.40 17502 19.81 12788 19.33 14102 19.38 17141 612 20.59 17637 19.81 12601 19.27 14573 19.38 17661 712 24.86 15614 19.79 12676 19.10 13818 19.14 15637 812 30.82 17151 20.17 13954 18.94 14377 18.99 17210 912 37.42 17200 20.73 13887 18.86 15345 18.88 17619 1012 43.54 16304 21.37 13759 18.79 14240 18.73 16059 1112 50.36 16424 22.01 13891 18.77 14014 18.68 16659 1212 58.01 17294 23.02 15245 18.87 14589 18.67 17372 1312 63.62 15314 23.93 13698 18.84 13138 18.60 15698 1412 70.75 15663 24.81 13928 18.87 12857 18.59 15860 1512 76.23 15812 25.99 14248 18.91 13752 18.52 16225 2512 132.41 15254 31.58 13456 20.41 9948 18.41 15204 3512 178.97 13293 35.54 11850 22.91 7847 18.40 13329 4512 209.37 11767 39.15 10485 25.91 6146 18.41 11738 5512 240.44 10168 43.14 9020 29.54 5309 18.36 9986 6512 271.40 9052 47.81 8108 34.48 4680 18.35 9022 7512 293.02 8315 51.12 7483 39.29 4102 18.33 8324 8512 305.65 7259 54.98 6718 43.08 3660 18.34 7366 9512 336.02 6672 57.85 6211 48.90 3370 18.34 6555 10512 341.53 6126 60.77 5575 52.95 3010 18.32 6030 11512 362.74 5994 66.62 5445 61.38 2873 18.32 5882 12512 373.17 5421 69.70 4988 64.94 2602 18.31 5287 13512 382.91 5174 73.27 4692 OOM - 18.31 4962 14512 399.98 4351 75.52 4103 OOM - 18.31 4352 15512 406.01 4291 79.25 3969 OOM - 18.31 4289 |
|
| 288 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 289 |
+
|
| 290 |
+
Table 3: The sinusoidal, rotary, T5 bias and ALiBi models trained on L = 1024 on WikiText-103 and evaluated with different values of L valid on the validation set. Bold shows the best score for each model. Inference speeds (in words per second) are from inference on a GPU with batch size of one.
|
| 291 |
+
|
| 292 |
+
| Sinusoidal Rotary T5 Bias ALiBi Inputs PPL ( ↓ ) WPS ( ↑ ) PPL ( ↓ ) WPS ( ↑ ) PPL ( ↓ ) WPS ( ↑ ) PPL ( ↓ ) WPS ( ↑ ) 1024 19.34 17002 19.33 14690 18.80 14973 18.66 16951 1025 19.33 16630 19.34 14423 18.82 14635 18.67 16690 1034 19.27 16589 19.28 14351 18.74 14435 18.60 16707 1044 19.26 16760 19.27 14491 18.72 14644 18.60 16667 1054 19.23 16747 19.26 14503 18.71 14800 18.58 16833 1064 19.21 16676 19.22 14623 18.70 14498 18.55 16941 1074 19.19 16879 19.19 14464 18.65 14670 18.49 16936 1084 19.22 16942 19.23 14650 18.70 14607 18.56 17090 1094 19.24 16771 19.22 14629 18.69 14517 18.54 16880 1104 19.28 16870 19.27 14837 18.69 14635 18.52 17009 1114 19.29 16795 19.27 14879 18.69 14540 18.52 17050 1124 19.26 17312 19.18 15121 18.62 14480 18.46 17571 1224 20.54 17901 19.38 15584 18.58 14956 18.40 18013 1324 23.13 16308 19.96 14386 18.52 13726 18.33 16422 1424 26.45 16217 21.27 14385 18.48 13516 18.28 16121 1524 29.82 16377 22.59 14693 18.42 13587 18.22 16659 1624 34.27 15928 24.34 14228 18.40 12979 18.17 16053 1724 38.24 16640 25.66 14686 18.35 12976 18.15 16607 1824 42.23 16840 27.63 14918 18.30 13071 18.08 16846 1924 46.46 15071 29.64 13452 18.31 11843 18.08 15118 2024 51.09 15591 31.17 13706 18.34 11906 18.05 15557 3024 96.46 13639 35.67 12256 18.62 8480 17.92 13668 4024 144.00 12441 44.30 11203 19.44 7443 17.95 12402 5024 182.31 11431 48.31 10324 20.47 6384 17.92 11394 6024 214.02 10238 54.78 9117 21.76 5577 18.01 10119 7024 261.86 8785 62.83 7950 23.64 4867 17.93 8779 8024 284.88 8132 64.91 7355 25.79 4377 17.96 8086 9024 310.04 7045 71.91 6380 27.54 3787 17.98 7001 10024 337.48 6633 77.70 6016 29.54 3582 17.97 6583 11024 358.43 5722 81.15 5219 31.94 3170 18.02 5641 12024 375.95 5560 87.51 5072 33.35 2940 18.01 5294 13024 393.57 4691 94.74 4383 OOM - 17.98 4621 14024 403.52 4905 96.10 4546 OOM - 18.01 4827 15024 431.66 4518 99.78 4170 OOM - 17.96 4447 16024 453.32 4239 106.99 3878 OOM - 17.98 4153 |
|
| 293 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 294 |
+
|
| 295 |
+
Table 4: The sinusoidal, rotary, T5 bias and ALiBi models trained on L = 3072 on WikiText-103 and evaluated with different values of L valid on the validation set. Bold shows the best score for each model. Inference speeds (in words per second) are from inference on a GPU with batch size of one.
|
| 296 |
+
|
| 297 |
+
| Sinusoidal Rotary T5 Bias ALiBi Inputs PPL ( ↓ ) WPS ( ↑ ) PPL ( ↓ ) WPS ( ↑ ) PPL ( ↓ ) WPS ( ↑ ) PPL ( ↓ ) WPS ( ↑ ) 3072 18.67 13380 18.57 12548 18.01 8828 17.60 13866 3073 18.67 13773 18.57 12474 18.01 8483 17.59 13793 3082 18.62 13741 18.54 12388 17.95 8698 17.59 13778 3092 18.60 13742 18.48 12458 17.92 8361 17.55 13783 3102 18.65 13701 18.52 12365 17.94 8764 17.59 13747 3112 18.64 13809 18.51 12449 17.96 8665 17.59 13827 3122 18.68 13722 18.52 12432 17.98 8437 17.58 13795 3132 18.67 13825 18.54 12490 17.97 8653 17.58 13784 3142 18.69 13543 18.52 12230 17.97 8282 17.61 13572 3152 18.66 13520 18.56 12240 17.98 8608 17.59 13523 3162 18.71 13501 18.56 12253 18.04 8589 17.62 13598 3172 18.72 13563 18.55 12297 17.99 8583 17.59 13625 3272 18.87 13453 18.55 12148 17.93 8144 17.59 13482 3372 19.46 13533 18.50 12254 17.88 8442 17.52 13565 3472 20.55 13047 18.52 11868 17.95 7857 17.54 13107 3572 21.84 13128 18.50 11882 17.86 7814 17.50 13170 3672 23.04 13106 18.49 11859 17.87 7719 17.48 13196 3772 24.47 13287 18.54 11942 17.85 7579 17.49 13312 3872 25.85 12621 18.40 11272 17.82 7581 17.41 12566 3972 27.21 12379 18.48 11151 17.84 7483 17.41 12324 4072 28.59 12178 18.59 11019 17.88 6974 17.48 12212 5072 45.53 11076 18.80 9887 17.76 6230 17.33 10938 6072 65.01 10114 19.50 9049 17.68 5554 17.26 10133 7072 85.96 8647 20.60 7861 17.83 4820 17.22 8670 8072 102.74 7755 21.60 6991 18.06 4281 17.30 7729 9072 125.99 6953 22.14 6360 18.12 3823 17.26 6939 10072 133.68 6646 23.21 6068 18.37 3579 17.28 6597 11072 161.29 5663 24.39 5158 18.64 3119 17.26 5585 12072 169.55 5567 26.70 5111 18.93 2920 17.24 5397 13072 189.43 5044 29.33 4658 19.10 2735 17.15 4809 14072 203.86 4915 32.21 4616 OOM - 17.22 4866 15072 221.14 4561 33.47 4292 OOM - 17.23 4491 16072 231.29 4382 34.51 4099 OOM - 17.22 4312 |
|
| 298 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 299 |
+
|
| 300 |
+
## A.2 ALIBI RESULTS ON WIKITEXT-103
|
| 301 |
+
|
| 302 |
+
Figure 8: The training speed and validation perplexity (with L valid = 3072) for ALiBi models and the sinusoidal model trained with L = 3072. All our models trained on 512 or more tokens achieve better perplexity than the sinusoidal model even though all of them (except the L = 3072) require less time and memory to train.
|
| 303 |
+
|
| 304 |
+
<!-- image -->
|
| 305 |
+
|
| 306 |
+
Figure 8 depicts a cross section of Figure 4, showing our models with different train lengths and the sinusoidal baseline, all evaluated on L valid = 3072 tokens. We observe that all our models with 512 ≤ L < 3072 are faster to train than the sinusoidal model with L = 3072, but they all achieve greater perplexity scores on the validation set. Our model with L = 3072 trains just as fast as the sinusoidal one but bests its score by more than one perplexity point; (the standard deviation for the the sinusoidal model with L = 3072 is 0.24).
|
| 307 |
+
|
| 308 |
+
Table 5 shows the perplexity values obtained when 8 different ALiBi models, trained on L values between 64 and 3072, extrapolating to L valid values longer than the ones they were trained on. In addition, we present results for the sinusoidal, rotary and T5 bias models, with L valid = L .
|
| 309 |
+
|
| 310 |
+
Table 5: Perplexity when ALiBi extrapolates on the WikiText-103 development set. ∗ For results we present for the sinusoidal, rotary and T5 bias models, L = L valid (so we do not test the extrapolation abilities of those baselines here).
|
| 311 |
+
|
| 312 |
+
| ALiBi Evaluation Length Train Length 64 128 256 512 1024 1536 2048 3072 64 28.46 24.70 22.88 22.09 21.73 21.63 21.59 21.53 128 - 23.98 21.70 20.67 20.36 20.29 20.31 20.28 256 - - 21.29 19.89 19.29 19.13 19.10 19.03 512 - - - 19.73 18.81 18.50 18.48 18.40 1024 - - - - 18.66 18.20 18.05 17.96 1536 - - - - - 18.12 17.90 17.72 2048 - - - - - - 17.91 17.64 3072 - - - - - - - 17.60 Sinusoidal ∗ 28.03 23.81 21.45 20.05 19.34 19.05 18.87 18.67 Rotary ∗ - - - 20.07 19.33 - - 18.57 T5 Bias ∗ - - - 19.65 18.80 - - 18.01 |
|
| 313 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 314 |
+
|
| 315 |
+
Table 6 compares ALiBi to the sinusoidal, rotary and T5 bias baselines on the test set of WikiText103, and Table 7 compares ALiBi to the current state of the art models on that test set.
|
| 316 |
+
|
| 317 |
+
Table 6: Test perplexity and runtime on WikiText-103 for two of our ALiBi models and models that use the sinusoidal, rotary and T5 bias methods.
|
| 318 |
+
|
| 319 |
+
| Model Param. ↓ Train Inference Speed ↑ Speed ↑ Valid ↓ Test ↓ Sinusoidal, L = 3072 247M 15.3k 13.6k 18.67 19.38 Rotary, L = 3072 247M 11.5k 12.2k 18.57 19.28 T5 Bias, L = 3072 247M 4.3k 7.3k 18.01 18.73 ALiBi L = 512, L valid = 3072 247M 28.3k 13.6k 18.40 19.08 L = 3072, L valid = 3072 247M 15.5k 13.6k 17.60 18.30 |
|
| 320 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 321 |
+
|
| 322 |
+
Table 7: Valid and test perplexity scores on WikiText-103 for two of our ALiBi models and models that use the sinusoidal, rotary and T5 bias methods with sliding window evaluation (§B and S=512 following (Baevski & Auli, 2018; Khandelwal et al., 2020; Press et al., 2021)). The sinusoidal model presents our results from training and inference with the model of Baevski & Auli.
|
| 323 |
+
|
| 324 |
+
| Model Param. ↓ Valid ↓ Test ↓ Adaptive Inputs (Baevski & Auli, 2018) 247M 17.97 18.70 Transformer-XL (Dai et al., 2019) 257M - 18.3 Shortformer (Press et al., 2021) 247M 17.47 18.15 Sandwich Transformer (Press et al., 2020) 247M - 17.96 Staged Training (Press et al., 2021) 247M - 17.56 Compressive Transformer (Rae et al., 2020) 329M - 17.1 Routing Transformer (Roy et al., 2020) - - 15.8 kNN-LM (Khandelwal et al., 2020) 247M 15.81 15.79 Sinusoidal, L = 3072 247M 17.95 18.67 Rotary, L = 3072 247M 17.98 18.72 T5 Bias, L = 3072 247M 17.37 18.12 ALiBi L = 512, L valid = 3072 247M 18.30 19.01 L = 3072, L valid = 3072 247M 16.97 17.66 |
|
| 325 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 326 |
+
|
| 327 |
+
## A.3 RESULTS ON THE TORONTO BOOK CORPUS
|
| 328 |
+
|
| 329 |
+
To ensure that our results are not specific to the WikiText-103 corpus, we next apply our model and the baselines to a different domain while using a similar model architecture and the same ALiBi slopes as those used in the previous subsection.
|
| 330 |
+
|
| 331 |
+
Weemphasize that our set of slopes was chosen by running experiments on the WikiText-103 corpus, and here we apply that set of slopes to a model trained on a very different text domain. Throughout the entire process of developing this method, we ran only one set of experiments on this domain using the previously selected set of slopes.
|
| 332 |
+
|
| 333 |
+
Specifically, we use the Toronto BooksCorpus (Zhu et al., 2015), which has been used to train BERT (Devlin et al., 2019) (in conjuction with the English Wikipedia). The corpus is about 700M tokens (2.9 GB).
|
| 334 |
+
|
| 335 |
+
We use the same train/validation/test split as Khandelwal et al. (2020) and their tokenization, which uses BERT's vocabulary of 29K byte-pair encodings. Since the vocabulary is much smaller than WikiText-103's, we replace the adaptive word embedding and softmax of Baevski & Auli (2018) with a tied word embedding and softmax matrix (Press & Wolf, 2017; Inan et al., 2017).
|
| 336 |
+
|
| 337 |
+
Our results in Figure 9 (and Table 8) replicate our success on the WikiText-103 dataset. Our model surpasses the sinusoidal baseline when trained on the same amount of input tokens ( L ) and, in addition, our model is able to extrapolate to longer sequences at inference. This occurs even though our set of slopes was not tuned on this dataset. This result establishes the generality of ALiBi and the particular set of slopes we found and suggests that they may be used on different text domains without further hyperparameter tuning.
|
| 338 |
+
|
| 339 |
+
Figure 9: ALiBi-enabled models evaluated on different input lengths on the Toronto BookCorpus. Our models extrapolate to longer sequence lengths and outperform the sinusoidal baseline even when trained on much shorter sequences.
|
| 340 |
+
|
| 341 |
+
<!-- image -->
|
| 342 |
+
|
| 343 |
+
Tables 9 and 10 present the perplexities for our ALiBi models, the baselines, and the current state of the art on the Toronto BookCorpus validation and test sets. Our results here mirror our results on WikiText-103: we improve over the sinusoidal baseline even when AliBi is trained on fewer tokens.
|
| 344 |
+
|
| 345 |
+
Table 8: ALiBi models extrapolating on the Toronto BookCorpus development set. ∗ For the results of the sinusoidal models, L = L valid (so we do not test the extrapolation abilities of those models here).
|
| 346 |
+
|
| 347 |
+
| Evaluation Length Train Length 512 1024 3072 512 14.29 13.64 13.55 1024 - 13.86 13.52 3072 - - 13.15 Sinusoidal ∗ 14.80 14.73 14.46 |
|
| 348 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 349 |
+
|
| 350 |
+
Table 9: Validation and test perplexities on the Toronto Book Corpus dataset.
|
| 351 |
+
|
| 352 |
+
| Model Param. ↓ Valid ↓ Test ↓ Sinusoidal, L = 3072 247M 14.46 11.67 ALiBi L train = 512, L valid = 3072 247M 13.55 10.98 L train = 3072, L valid = 3072 247M 13.15 10.73 |
|
| 353 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 354 |
+
|
| 355 |
+
## A.4 RESULTS ON THE CC100+ROBERTA CORPUS
|
| 356 |
+
|
| 357 |
+
Table 11 compares our 1.3 billion parameter ALiBi models when extrapolating to two times the number of tokens that they were trained on. We use the sinusoidal model as our baseline, and train it for the same amount of time as we train the ALiBi model that we compare it to (and so since our ALiBi models run faster in this setting, the sinusoidal models complete less updates).
|
| 358 |
+
|
| 359 |
+
Table 10: Validation and test perplexities on the Toronto Book Corpus dataset with a sliding window (§B). Following (Baevski & Auli, 2018; Khandelwal et al., 2020; Press et al., 2020; 2021), we set the sliding window stride S =512.
|
| 360 |
+
|
| 361 |
+
| Model Param. ↓ Valid ↓ Test ↓ kNN-LM (Khandelwal et al., 2020) 247M 14.20 10.89 Shortformer (Press et al., 2021) 247M 13.40 10.88 Sandwich (Press et al., 2020) 247M - 10.83 Staged Training (Press et al., 2021) 247M 12.80 10.48 Sinusoidal, L = 3072 247M 14.06 11.40 ALiBi L = 512, L valid = 3072 247M 13.76 11.11 L = 3072, L valid = 3072 247M 12.70 10.40 |
|
| 362 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 363 |
+
|
| 364 |
+
Table 11: Perplexity, memory, and train time on the CC100+RoBERTa corpus for our ALiBi models and the sinusoidal baseline. We run our L = 512 (1024) model and the sinusoidal model with L = 1024 (2048) for the same amount of time. We show that our models achieve strong results even though they use 6-11% less memory.
|
| 365 |
+
|
| 366 |
+
| Training Valid PPL ↓ Memory ↓ Updates Hours ↓ L valid = 1024 L valid = 2048 Sinusoidal, L train = 1024 26.2 GB 46.7k 5.5k 9.24 - ALiBi, L train = 512 24.6 GB 50.0k 5.5k 9.30 - Sinusoidal, L train = 2048 29.3 GB 44.2k 5.9k - 9.01 ALiBi, L train = 1024 26.2 GB 50.0k 5.9k - 8.92 |
|
| 367 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 368 |
+
|
| 369 |
+
Table 12 compares our 1.3 billion parameter ALiBi models to the sinusoidal baselines, with and without extrapolation, with all models completing 50,000 updates.
|
| 370 |
+
|
| 371 |
+
Table 12: Perplexity, train time and memory use of the sinusoidal and ALiBi models on the CC100+RoBERTa corpus when all models are trained with 50k updates.
|
| 372 |
+
|
| 373 |
+
| Training Valid PPL ↓ Memory ↓ Updates Hours ↓ L valid = 512 L valid = 1024 L valid = 2048 Sinusoidal, L train = 512 24.6 GB 50.0k 5.5k 9.71 37.05 105.42 ALiBi, L train = 512 24.6 GB 50.0k 5.5k 9.79 9.30 9.54 Sinusoidal, L train = 1024 26.2 GB 50.0k 5.9k - 9.15 48.85 ALiBi, L train = 1024 26.2 GB 50.0k 5.9k - 9.16 8.92 Sinusoidal, L train = 2048 29.3 GB 50.0k 6.7k - - 8.83 ALiBi, L train = 2048 29.4 GB 50.0k 6.7k - - 8.84 |
|
| 374 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 375 |
+
|
| 376 |
+
## B ANALYSIS
|
| 377 |
+
|
| 378 |
+
In this section we investigate why ALiBi works so effectively. We find that ALiBi's decrease in perplexity when given longer sequences is largely explained by its improved avoidance of the early token curse. We hypothesize that future work building on ALiBi might achieve further gains by more efficiently exploiting longer histories.
|
| 379 |
+
|
| 380 |
+
## B.1 DEFINING SLIDING WINDOW EVALUATION AND THE EARLY TOKEN CURSE
|
| 381 |
+
|
| 382 |
+
Figure 10: Sliding window evaluation (top; blue) compared to nonoverlapping evaluation (bottom; red) on a sequence of 8 words using a model with L valid = 4. Nonoverlapping evaluation is much faster since it requires just two inference passes (as opposed to the five passes required by the siding window approach). But the sliding window approach provides more context for each prediction.
|
| 383 |
+
|
| 384 |
+
<!-- image -->
|
| 385 |
+
|
| 386 |
+
Sliding Window Inference As mentioned in Section 2, nonoverlapping inference is commonly used to evaluate sequences longer than L (the number of tokens in each training subsequence). An alternative is to use a sliding window during evaluation (Baevski & Auli, 2018).
|
| 387 |
+
|
| 388 |
+
A stride S is picked between 1 and L -1 , and the window is advanced by S tokens after each forward pass. 12 This means that L -S tokens from the previous subsequence are re-encoded, and only S new tokens are output. The advantage is that all outputs in each subsequence after the first have at least L -S previous tokens to condition on. However, since tokens must be re-encoded multiple times, this approach is much slower than the nonoverlapping one. When S = 1 , we output one token every inference pass, each using the maximal context window that the model can handle; however, this is the slowest approach. Figure 10 is a visualization of the nonoverlapping and sliding window evaluation approaches.
|
| 389 |
+
|
| 390 |
+
We use sliding window inference as a tool to analyze our models, but we note that it is normally prohibitively slow in practice (Press et al., 2021).
|
| 391 |
+
|
| 392 |
+
Early Token Curse Splitting an evaluation set into subsequences means that predictions occuring early in each subsequence cannot access many previous context tokens (appearing at the end of the previous subsequence). The result, referred to as the early token curse (Press et al., 2021), increases (i.e., degrades) perplexity scores. A workaround is to evaluate the model using a sliding window, giving each prediction more context. This solution is slow since it requires many more forward passes of the model.
|
| 393 |
+
|
| 394 |
+
## B.2 EXTRAPOLATION REDUCES THE EARLY TOKEN CURSE
|
| 395 |
+
|
| 396 |
+
We presented results showing that our ALiBi method (and, to a lesser extent, the T5 bias) allows LMs to extrapolate during inference. Two reasons could explain why these methods enable LMs to achieve better perplexity given longer input subsequences:
|
| 397 |
+
|
| 398 |
+
1. Performance improves because the models can use longer contexts to make more accurate predictions. For example, the average article length in the WikiText-103 corpus is about 3600 tokens; therefore, if a model trained on L = 512 tokens extrapolates to L valid = 3072 tokens during inference and achieves better results, that might be because it can spot patterns occurring across more than 512 tokens.
|
| 399 |
+
2. Performance improves because longer input sequences mean the early token curse is reduced. For example, during nonoverlapping evaluation on sequences of length L valid = 1000, 10% of predictions have 100 tokens of context or less. If we rerun nonoverlapping evaluation on that model with L valid = 2000 tokens, now only 5% of predictions have 100
|
| 400 |
+
|
| 401 |
+
12 Nonoverlapping inference can be viewed as sliding window inference with stride L .
|
| 402 |
+
|
| 403 |
+
tokens of context or less. So, by simply being able to handle longer sequences, a model can substantially reduce the early token curse and improve performance. 13
|
| 404 |
+
|
| 405 |
+
To better understand what might be occurring, we re-evaluate the development set of WikiText-103 with our models and the sinusoidal baseline with L = 512 , 1024 , 3072 . However, this time we use sliding window evaluation with a stride of S = 1 , meaning that we move the sliding window just one token after every inference pass, giving each prediction the maximum number of context tokens that the model can use.
|
| 406 |
+
|
| 407 |
+
Figure 11: ALiBi models evaluated on different input lengths on WikiText-103 with sliding window evaluation (with stride S = 1 ). Unlike results shown in Figure 4, where performance improves in each of our models as we increase the validation sequence length, here performance stays relatively flat as we increase L valid . This might mean that ALiBi increases performance when L valid > L not because it uses longer contexts, but because fewer tokens suffer from the early token curse. Note that as in §2, the perplexity of the sinusoidal model explodes when L valid > L even when using sliding window evaluation.
|
| 408 |
+
|
| 409 |
+
<!-- image -->
|
| 410 |
+
|
| 411 |
+
The results are shown in Figure 11 and in the corresponding Tables 13 (sinusoidal) and 15 (ALiBi).
|
| 412 |
+
|
| 413 |
+
Unsurprisingly, for the sinusoidal model, as in §2, increasing L valid causes an explosion in perplexity even when using sliding window evaluation. Our ALiBi models cannot improve perplexity when looking at longer sequences in this setting, but they keep perplexity flat when L valid increases.
|
| 414 |
+
|
| 415 |
+
This leads us to believe that our perplexity improvement when increasing L valid and using nonoverlapping evaluation is caused by explanation 2, not explanation 1. Because sliding window evaluation provides long context windows for every prediction made, it curtails the early token curse. In this setting, ALiBi's performance remains flat when L valid increases, leading us to hypothesize that the gains seen while increasing L valid in §4 were the result of larger L valid values mitigating the early token curse.
|
| 416 |
+
|
| 417 |
+
Our ALiBi results mirror what occurs in the model using the T5 bias: when using sliding window evaluation, perplexity remains relatively flat when evaluating longer sequences (see Table 14).
|
| 418 |
+
|
| 419 |
+
Our analysis reveals that when L valid > L , ALiBi might not be using contexts longer than the ones it was trained on. This highlights a research direction that could be pursued in future work.
|
| 420 |
+
|
| 421 |
+
These findings do not lessen the value of ALiBi. When L valid = L , ALiBi achieves either superior or similar results to the sinusoidal method and other alternatives even though it is simpler and requires no learned parameters. When evaluating L valid > L tokens, even if ALiBi does not attend to more than L tokens, it yields better results than the other alternatives that can be used in this case, i.e., standard nonoverlapping inference (which is cheap, but does not perform as well) and the more accurate sliding window approach (which is very slow).
|
| 422 |
+
|
| 423 |
+
13 100 tokens is an arbitrary small number used here to represent a short history context, i.e., one in which making predictions for the next output token would be harder.
|
| 424 |
+
|
| 425 |
+
Table 13: Perplexities of the sinusoidal models evaluated with sliding window evaluation with stride S = 1 on the WikiText-103 validation dataset.
|
| 426 |
+
|
| 427 |
+
| Evaluation Length ( S = 1 ) Train Length 512 1024 1536 2048 3072 512 18.35 204.42 264.74 306.19 360.12 1024 - 18.05 206.55 302.6 393.71 3072 - - - - 18.03 |
|
| 428 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 429 |
+
|
| 430 |
+
Table 14: Perplexities of the T5 bias models evaluated with sliding window evaluation with stride S = 1 on the WikiText-103 validation dataset.
|
| 431 |
+
|
| 432 |
+
| Evaluation Length ( S = 1 ) Train Length 512 1024 1536 2048 3072 512 17.92 18.51 20.36 22.62 30.77 1024 - 17.65 17.87 18.51 20.66 3072 - - - - 17.41 |
|
| 433 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 434 |
+
|
| 435 |
+
Table 15: Perplexities of the ALiBi models evaluated with sliding window evaluation with stride S = 1 on the WikiText-103 validation dataset.
|
| 436 |
+
|
| 437 |
+
| Evaluation Length ( S = 1 ) Train Length 512 1024 1536 2048 3072 512 17.98 17.92 18.2 18.28 18.3 1024 - 17.46 17.47 17.62 17.92 3072 - - - - 16.96 |
|
| 438 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
text-versions/attention-markdown/2108.13320_Neural HMMs are all you need for highqua.md
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2108.13320 Neural Hmms Are All You Need For Highqua
|
| 2 |
+
|
| 3 |
+
## NEURAL HMMS ARE ALL YOU NEED (FOR HIGH-QUALITY ATTENTION-FREE TTS)
|
| 4 |
+
|
| 5 |
+
Shivam Mehta, Éva Székely, Jonas Beskow, Gustav Eje Henter
|
| 6 |
+
|
| 7 |
+
Division of Speech, Music and Hearing, KTH Royal Institute of Technology, Stockholm, Sweden
|
| 8 |
+
|
| 9 |
+
## ABSTRACT
|
| 10 |
+
|
| 11 |
+
Neural sequence-to-sequence TTS has achieved significantly better output quality than statistical speech synthesis using HMMs. However, neural TTS is generally not probabilistic and uses nonmonotonic attention. Attention failures increase training time and can make synthesis babble incoherently. This paper describes how the old and new paradigms can be combined to obtain the advantages of both worlds, by replacing attention in neural TTS with an autoregressive left-right no-skip hidden Markov model defined by a neural network. Based on this proposal, we modify Tacotron 2 to obtain an HMM-based neural TTS model with monotonic alignment, trained to maximise the full sequence likelihood without approximation. We also describe how to combine ideas from classical and contemporary TTS for best results. The resulting example system is smaller and simpler than Tacotron 2, and learns to speak with fewer iterations and less data, whilst achieving comparable naturalness prior to the post-net. Our approach also allows easy control over speaking rate.
|
| 12 |
+
|
| 13 |
+
Index Terms -seq2seq, attention, HMMs, duration modelling, acoustic modelling
|
| 14 |
+
|
| 15 |
+
## 1. INTRODUCTION
|
| 16 |
+
|
| 17 |
+
Text-to-speech (TTS) technology has advanced tremendously in the last decade, and output speech quality has seen a number of step changes as the field evolved. Statistical parametric speech synthesis (SPSS) based on hidden Markov models (HMMs) [1], has now largely been supplanted by neural TTS [2]. Waveform-level deep learning greatly improved segmental quality over signal-processing based vocoders, while sequence-to-sequence models with attention, e.g., [3], demonstrated greatly improved prosody. Combined, as in Tacotron 2 [4], these innovations produce synthetic speech whose naturalness sometimes rivals that of recorded speech.
|
| 18 |
+
|
| 19 |
+
However, not all aspects of TTS systems have improved along the way. The integration of deep learning with positional features into HMM-based TTS increased naturalness [5], but sacrificed the ability to learn to speak and align simultaneously, instead requiring an external forced aligner. Attention-based neural TTS systems [3] reintroduced the ability to learn to align, but are not grounded in probability and require more data and time to start speaking. Furthermore, their non-monotonic attention mechanisms do not enforce a consistent ordering of speech sounds. As a result, synthesis is susceptible to skipping and stuttering artefacts (as seen in [6]), and may break down catastrophically, resulting in unintelligible gibberish.
|
| 20 |
+
|
| 21 |
+
In this article, we 1) make the case that HMM-based and neural TTS approaches can be combined to gain the benefits of both worlds. We 2) support this claim by describing a neural TTS architecture based on Tacotron 2, but with the attention mechanism replaced by a Markovian hidden state, to obtain a fully probabilistic, joint model of durations and acoustics. The model development leverages design principles from both HMM-based and sequence-to-sequence TTS. Experiments show that the model gives a speech quality on par with that of a comparable Tacotron 2 model, and produces intelligible speech already after 1k updates, a 15-fold improvement on Tacotron 2. Unlike standard Tacotron 2, it also allows control over speaking rate. For audio examples and code, please see our demo webpage.
|
| 22 |
+
|
| 23 |
+
This work was partially supported by the Wallenberg AI, Autonomous Systems and Software Program (WASP) funded by the Knut and Alice Wallenberg Foundation.
|
| 24 |
+
|
| 25 |
+
## 2. BACKGROUND
|
| 26 |
+
|
| 27 |
+
The starting point of this work is [6], which identified four key differences between HMM-based SPSS and sequence-to-sequence attention-based TTS that had a notable impact on output quality:
|
| 28 |
+
|
| 29 |
+
1. Neural vocoder with mel-spectrogram inputs
|
| 30 |
+
2. Learned front-end (the encoder)
|
| 31 |
+
3. Acoustic feedback (autroregression)
|
| 32 |
+
4. Attention instead of HMM-based alignment
|
| 33 |
+
|
| 34 |
+
Among these, items 1-3 led to improved speech quality, whereas attention sometimes made the output significantly worse. This paper incorporates aspects 1-3 into a TTS system that leverages neural HMMs [7, 8] rather than attention for sequence-to-sequence modelling. Sec. 2.1, below, describes how to add aspects 1-3 to HMMs based on prior work, with attention (aspect 4) discussed in Sec. 2.2.
|
| 35 |
+
|
| 36 |
+
## 2.1. Adding neural TTS aspects to HMM-based TTS
|
| 37 |
+
|
| 38 |
+
For aspect 1, high-quality neural vocoders are now available off the shelf. Furthermore, most of these use spectral features as input. This helps avoid flat intonation caused by explicit averaging over pitch contours, commonly seen in systems that use a separate f 0 feature to parameterise speech [6]. However, nothing prevents HMM-based TTS from using mel-spectrogram features and neural vocoders: this is just a straightforward change of acoustic features, and the HMMbased approach described in this paper uses this setup.
|
| 39 |
+
|
| 40 |
+
Another factor in the improved prosody is item 2, the learned front-end (i.e., the encoder). Again, there is nothing that prevents using this idea in a system that leverages HMMs. The HMM-based systems we introduce all use the same encoder architecture as Tacotron 2 [4] with no additional linguistic features added.
|
| 41 |
+
|
| 42 |
+
The situation for item 3, autoregression (AR), is again similar, in that AR and HMMs are not mutually exclusive. Acoustic models in HMM-based TTS systems benefit from using positional and durational information [9, 5], that increases granularity by enabling the statistics of each generated frame to be different, together with dynamic features [10] to promote continuity across time. However, positional and durational features violate the Markov assumption (e.g., they depend on the time spent in the current state), preventing realignment during TTS training. In a model like Tacotron, positional information is instead mediated and continuity enforced by autoregression. Since this only involves dependencies on observed vari- ables, it is possible to devise autoregressive models that do not violate the Markov assumption, and linear autoregressive HMMs (ARHMMs) [11] have previously been explored in HMM-based SPSS [12, 13, 14]. In this paper, we describe HMMs that, like Tacotron, use stronger, nonlinear AR models defined by a neural network.
|
| 43 |
+
|
| 44 |
+
## 2.2. Attention in TTS
|
| 45 |
+
|
| 46 |
+
In a typical sequence-to-sequence based TTS system, the attention mechanism is responsible for duration modelling and for learning to align input symbols with output frames during training. Watts et al. [6] found that the use of neural attention did not necessarily benefit TTS, and more suitable TTS attention mechanisms have recently been a focus of intense research. Only some of the relevant work can be surveyed here; please see [2] for additional references. He et al. [15] emphasised that TTS alignments should be local (each output frame is associated with a single input symbol), monotonic (never move backwards), and complete (not skip any speech sounds). HMMs are local by design, while the two other concepts map directly onto the classes of left-right and no-skip HMMs. Most neural TTS attention mechanisms do not satisfy these requirements [15, 2].
|
| 47 |
+
|
| 48 |
+
Many systems that do satisfy all three criteria rely on external tools for input-output alignment to obtain duration data (see [2] for a list), and do not jointly learn to speak and align, unlike regular HMMs or Tacotron 1/2. However, some proposals do learn to speak and align without external tools, mostly (e.g., [16, 17, 18, 19, 20, 21, 22]) by introducing duration models into neural TTS, which will be our focus here. Many of these models only optimise a lower bound on the sequence likelihood, either due to the use of variational methods (e.g., Non-Attentive Tacotron [19] and the VQ-VAEs in [20]) or by not marginalising over all possible alignments (Glow-TTS [18]). By using a mean squared error (MSE) duration loss, Glow-TTS also implicitly treats the positive, integer-valued durations (frame counts) as outcomes from a Gaussian distribution on the real line, which violates probabilistic assumptions. Our proposal avoids these issues.
|
| 49 |
+
|
| 50 |
+
AlignTTS [17] is more similar to an HMM and uses a variant of the HMM forward recursions [11], but requires a complex, four-stage training procedure that culminates in training a separate, non-probabilistic duration predictor that is used at synthesis time. AlignTTS is also parallel, while our proposal is autoregressive.
|
| 51 |
+
|
| 52 |
+
The constant-per-state transition probability of regular HMMs implicitly describes a geometric duration distribution, which is a poor fit for natural speech [23, 24]. A solution to this in SPSS was to introduce explicit duration modelling through hidden semi-Markov models (HSMMs) [23]. These sacrifice the Markovian property to describe more general duration distributions, by letting transition probabilities depend on the time spent in the current state. Independent work [21, 22] concurrent to ours proposes to integrate HSMMs into neural TTS, obtaining better results than Tacotron 2, but uses a variational approximation and again assumes a Gaussian distribution for the positive-integer frame durations. In contrast, [24] described how arbitrary discrete duration distributions can be parameterised implicitly via frame-dependent transition probabilities, and then predicted jointly with output frames in a single, joint model of durations and acoustics. This paper combines this idea with autoregression acting as an indirect, 'acoustic memory' of the time spent in a state, to obtain a fully probabilistic model with general discrete durations, that can be trained efficiently on the exact log-likelihood.
|
| 53 |
+
|
| 54 |
+
The most similar work to ours is SSNT-TTS [16], which essentially describes a neural HMM for TTS, albeit under another name. We differ in applying an HMM perspective to the approach, in integrating more SPSS ideas to improve our system, in using a different duration-generation method, in demonstrating control over speaking rate, and in reporting better TTS quality, on par with Tacotron 2.
|
| 55 |
+
|
| 56 |
+
## 3. METHOD
|
| 57 |
+
|
| 58 |
+
We now (in Sec. 3.1 and Fig. 1) describe the key modifications used to put HMMs into neural TTS such as Tacotron 2. Sec. 3.2 then describes how ideas and implementation aspects from classic HMMbased TTS can be adapted to further improve neural HMM TTS.
|
| 59 |
+
|
| 60 |
+
## 3.1. Replacing attention with neural HMMs
|
| 61 |
+
|
| 62 |
+
The location-sensitive attention [25] used by Tacotron 2 is a function that uses information from previously generated acoustic frames x 1: t -1 to select which encoder output vector(s) h n to send to the decoder, to generate the next frame x t . (We use bold font for vectorvalued quantities and index input-sequence symbols by n and output frames by t .) The attention also has an internal state, in the form of previous attention weights α 1: t -1 ,n . Fig. 1a shows the procedure to generate one frame t of output using Tacotron 2. It can be written as
|
| 63 |
+
|
| 64 |
+
<!-- formula-not-decoded -->
|
| 65 |
+
|
| 66 |
+
<!-- formula-not-decoded -->
|
| 67 |
+
|
| 68 |
+
<!-- formula-not-decoded -->
|
| 69 |
+
|
| 70 |
+
<!-- formula-not-decoded -->
|
| 71 |
+
|
| 72 |
+
Here, a t -1 represents the hidden and cell state variables of the first decoder LSTM, OutputNet is the upper part of the decoder in Fig. 1a (which contains a second LSTM), while τ t ∈ [0 , 1] is the stop token . The latter is an estimate of the probability that the current frame is the last in the utterance, terminating synthesis if τ t > 0 . 5 .
|
| 73 |
+
|
| 74 |
+
To swap in neural HMMs, we remove the dependence on g t -1 from Eq. (1), and replace attention by a probabilistic OutputNet that uses a t and the HMM state s t ∈ { 1 , . . . , N } to estimate the distribution of frame x t , by outputting the parameters θ t of an HMM emission distribution o ( θ ) . The stop token becomes a transition probability τ t ∈ [0 , 1] for s t , with s 1 = 1 . Eqs. (2)-(4) then become
|
| 75 |
+
|
| 76 |
+
<!-- formula-not-decoded -->
|
| 77 |
+
|
| 78 |
+
<!-- formula-not-decoded -->
|
| 79 |
+
|
| 80 |
+
where Bernoulli( p ) is a binary random variable on { 0 , 1 } that equals 1 with probability p . The attention state variables α t,n of Tacotron 2 have thus been replaced by a single, integer state variable s t that evolves stochastically based on τ t . This transition probability depends on the h -vector of the current state s t (through g t ) and on the entire previous acoustics x 1: t -1 (through a t ), so it can be different for every frame t even for the same state. This can model arbitrary duration distributions [24]. s t > N terminates synthesis.
|
| 81 |
+
|
| 82 |
+
The end result is a left-right no-skip neural HMM , an AR-HMM parameterised by the decoder network in Fig. 1b. The encoder turns each input sequence into a unique HMM, where each vector h n represents a state. Feeding this state vector and the AR input x 1: t -1 into the decoder yields the HMM emission distribution o ( θ t ) and nextstate transition probability τ t of state n at time t . Neural HMMs were first described concurrently by [7] and [8], the latter under the name segment-to-segment neural transduction (SSNT).
|
| 83 |
+
|
| 84 |
+
For the model to be a proper HMM satisfying the Markov property, ( θ t , τ t ) must not depend on anything other than the current state s t (through the state vector g t ) and the past observations x 1: t -1 . This necessitates an additional change to the Tacotron 2 architecture, namely removing the recurrence inside OutputNet by changing its LSTM layer to a feedforward layer, since an LSTM would propagate a dependence on past hidden states. This change also substantially reduces the number of parameters in the model.
|
| 85 |
+
|
| 86 |
+
Fig. 1 : Synthesis-time architecture diagrams. Recurrences, delays, and the cumulative attention in Eq. (2) are drawn as grey arrows.
|
| 87 |
+
|
| 88 |
+
<!-- image -->
|
| 89 |
+
|
| 90 |
+
Finally, the full Tacotron 2 architecture contains a non-causal convolutional post-net that enhances the initial AR-generated melspectrogram in a residual setup. This resembles post-filtering and global variance compensation [26] in classic SPSS. Tacotron 2 training minimises the sum of the MSEs before and after the post-net. However, the non-invertibility of the Tacotron post-net makes it incompatible with likelihood-based models like ours. A post-net can be added, but must either be trained separately, or be invertible like in [18]. We leave this as future work, and instead evaluate our proposal against Tacotron 2 output from both before and after the post-net.
|
| 91 |
+
|
| 92 |
+
## 3.2. Practical considerations
|
| 93 |
+
|
| 94 |
+
Numerical stability: When working with HMMs, it is crucial for numerical precision to perform all computations in the logarithmic domain using the 'log-sum-exp trick'. Since zeroes in these computations map to ln 0 = -∞ in the log domain, care must be taken to avoid NaN gradients in deep-learning frameworks like PyTorch.
|
| 95 |
+
|
| 96 |
+
Like classic HMM-based TTS [1], we chose to use diagonalcovariance Gaussian emission distributions o ( µ , σ ) in this work. We also used softplus (not exponential) nonlinearities for σ , with a non-zero minimum value ('variance flooring'), here clamped at 0.001, since this has been important in other generative models.
|
| 97 |
+
|
| 98 |
+
Architecture enhancements: Tacotron 2 can represent intermediate states using soft attention, since the α t,n -values have many degrees of freedom. Major HMM-based synthesisers instead use 5 sub-states per input phone and run at 200 fps [1, 9]. Tacotron 2 runs at 80 fps, i.e., 40% the framerate, hence we use 2 states per phone to get the same time resolution as these HMMs. This is implemented by doubling the size of the decoder output layer and interpreting its output as two concatenated state vectors h for each phone.
|
| 99 |
+
|
| 100 |
+
Classic HMM-based TTS includes a model of the dependencies between several adjacent frames to promote temporally smooth output [1, 12, 9]. Although Tacotron 2 and the neural HMMs in this article only take the latest frame x t -1 as AR input, the LSTM in Eq. (1) means they can remember information arbitrarily far back, which is beneficial for modelling utterance-level prosody. We also treat x 0 , the initial AR context (the 'go token'), as a learnable parameter.
|
| 101 |
+
|
| 102 |
+
Initialisation: HMMs are often initialised using a fl at start , in which all states have the same statistics [27]. By zeroing out all weights in the decoder output layer but initialising other layers as normal, all states will have the same output (zero), but different and nonzero gradients, thus enabling learning [28]. The last-layer bias values were chosen so that µ = 0 and σ = 1 for every state at the start of training, to match the global statistics of our normalised data.
|
| 103 |
+
|
| 104 |
+
Training: Neural HMM training [7] is a hybrid of old and new: We use the classic (scaled) forward algorithm [11] to compute the exact sequence log-likelihood, but then leverage backpropagation and automatic differentiation to optimise it using Adam. These parts correspond to the E step and the M step of the (generalised) EM algorithm [29], respectively. Computations during training parallelise over the states but, like Tacotron 2, are sequential across time due to the temporal recurrences.
|
| 105 |
+
|
| 106 |
+
Maximum-likelihood estimation of linear AR-HMMs can lead to unstable models [13, 12]. A similar problem exists for nonlinear, autoregressive neural TTS [2]. Tacotron 2 works around this by adding dropout to the pre-net, and we retain that solution here.
|
| 107 |
+
|
| 108 |
+
Synthesis: We can iteratively use the equations in Sec. 3.1 and randomly sample new frames x t ∼ o ( θ t ) . However, HMM-based TTSgenerally benefits from deterministically generating typical output rather than random sampling [30, 31]. For acoustics, this is done by generating the most probable output sequence [10], which is the same as the mean µ t when o ( θ t ) is Gaussian. By iteratively taking x t = µ t (red arrow in Fig. 1b), we obtain a greedy approximation of [10]. This is closely related to Tacotron 2 output generation, since it is trained using the MSE, which is minimised by the mean E [ X t ] .
|
| 109 |
+
|
| 110 |
+
SSNT-TTS found that randomly sampling transitions led to poor pause durations when synthesising [16], and classic HMM-based systems typically base the time in each state on the mean duration of the state [23]. This mean is difficult to compute with duration distributions implicitly defined through transition probabilities τ t , as here. We instead use the simple algorithm from [24, 32] for deterministic duration generation based on duration quantiles (e.g., the median rather than the mean). A quantile threshold controls speaking rate, which can be adjusted on a per-state basis, unlike [33]. For the models evaluated in this paper, informal listening showed that deterministic generation of acoustics and durations both led to clear quality improvements; examples are provided on the webpage.
|
| 111 |
+
|
| 112 |
+
## 4. EXPERIMENTS
|
| 113 |
+
|
| 114 |
+
To validate our proposal and show that neural HMMs provide notable advantages over attention in neural TTS, we performed a number of experiments (including a subjective listening test) comparing TTS using neural HMMs to a maximally similar Tacotron 2 [4] system. Synthetic speech examples from the different experiments can be found at https://shivammehta007.github.io/Neural-HMM/.
|
| 115 |
+
|
| 116 |
+
Fig. 2 : Average utterance ASR WER of validation-set resynthesis.
|
| 117 |
+
|
| 118 |
+
<!-- image -->
|
| 119 |
+
|
| 120 |
+
We based our systems on the widely used PyTorch open-source Nvidia implementation 1 of Tacotron 2. The systems were trained on the LJ Speech dataset 2 , which contains utterances (normalised text and matching audio) adapted from free audiobooks read by a female speaker of US English. We used the default train/val/test split in the repository, which designates about 23 h of audio for training. We likewise used the default text-processing, including the pronouncing dictionary (CMUdict), since this generally benefits neural TTS [34]. Output features were normalised to zero mean and unit variance over the training data, and waveforms were generated using the default, pre-trained v5 'universal' WaveGlow [35] vocoder. 3
|
| 121 |
+
|
| 122 |
+
We trained three systems: one Tacotron 2 baseline (T2) and two neural HMM systems, with either two ( NH2 ) or one ( NH1 ) state per phone. We expect NH2 to perform the best, with NH1 functioning as an ablation. All systems used the same architecture and hyperparameters (layer widths, learning rates, etc.) as the repository defaults, except that the size of the decoder output vectors was doubled to 1024 in the two-state system, since the decoder output now represents two concatenated state vectors. From the single Tacotron 2 baseline system, we synthesised two outputs: T2 + P , using the full mel-spectrogram output after the post-net, and T2 -P , using the initial mel-spectrogram prior to post-net enhancement, which is directly comparable to our neural HMMs. Model sizes for the different setups are listed in Table 1. We see that both neural HMMs are significantly smaller than Tacotron 2, even if the post-net is removed.
|
| 123 |
+
|
| 124 |
+
Each system was trained for 30k mixed-precision updates on 7 GPUs using a batch size of 6. It took approximately 14.5k updates for T2 to learn to speak coherently, whereas NH2 was intelligible after 1k updates. Fig. 2 graphs how the Google ASR word error rate (WER) of synthesising the 100 validation utterances evolves during training, including results from training on a small subset (500 utterances) of the data. Audio of speech synthesised during training is also provided on our demo webpage. We see that NH2 rapidly learns to speak intelligibly in both cases, much faster than Tacotron 2, which does not learn to speak at all on the smaller dataset. Even after the WER stabilised, we could consistently reproduce the effect where Tacotron 2 (including the best pre-trained system made available by Nvidia) degenerates into unintelligible babbling on long and short sentences, with examples provided on our webpage.
|
| 125 |
+
|
| 126 |
+
Tacotron 2 applies pre-net dropout both during training and synthesis [4], otherwise attention breaks down. Our neural HMMs retained this dropout, since it improved the speech quality in informal listening. Audio synthesised without it is provided on our webpage.
|
| 127 |
+
|
| 128 |
+
The distribution of phone durations in natural speech is skewed to the right. The median of a skewed distribution lies between the mode and the mean, and median-based duration generation therefore often gives a faster-than-average speaking rate; cf. [31]. Following the proposal in [32], the transition threshold of the deterministic duration-generation procedure was manually tuned to make the speaking rate of the NH systems match T2. The resulting thresholdquantile values were 0.57 for NH2 and 0.45 for NH1. Our webpage provides examples of speech generated with different threshold quantiles, to demonstrate speaking-rate control at synthesis time.
|
| 129 |
+
|
| 130 |
+
[1 https://github.com/NVIDIA/tacotron2/](https://github.com/NVIDIA/tacotron2/)
|
| 131 |
+
|
| 132 |
+
[2 https://keithito.com/LJ-Speech-Dataset/](https://keithito.com/LJ-Speech-Dataset/)
|
| 133 |
+
|
| 134 |
+
[3 https://github.com/NVIDIA/waveglow/](https://github.com/NVIDIA/waveglow/)
|
| 135 |
+
|
| 136 |
+
Table 1 : Models from the experiments, with number of parameters and mean opinion scores (with 95% confidence intervals) for each.
|
| 137 |
+
|
| 138 |
+
| Type Tacotron 2 Neural HMM Condition T2 + P T2 - P NH2 NH1 Size 28.2M 23.8M 15.3M 12.7M MOS 3.41 ± 0.01 3.25 ± 0.01 3.24 ± 0.01 2.68 ± 0.01 |
|
| 139 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 140 |
+
|
| 141 |
+
We conducted a subjective listening test to evaluate speech naturalness for the four conditions in Table 1. In the test, participants were presented with four parallel stimuli at a time, one from each condition (unlabelled and in random order), all speaking the same sentence. Participants were asked to rate the naturalness of each stimulus on an integer scale from 1 (worst) to 5 (best), anchored using the classic MOS labels 'Bad' through 'Excellent'. Stimuli were drawn from a pool of 9 sets of Harvard sentences [36], which are sets of 10 sentences each, designed so that each set is approximately phonetically balanced. All stimuli were loudness normalised to -20 dB LUFS following EBU R128 [37]. We manually verified that no T2 stimuli exhibited babbling due to failed attention.
|
| 142 |
+
|
| 143 |
+
We used Prolific to recruit 30 test participants ages 21 through 70, all self-reported headphone-wearing native English speakers from UK, Ireland, USA, Canada, Australia, and New Zealand. Each participant rated 3 randomly selected sets of 10 Harvard sentences, giving a grand total of 3600 ratings, 900 per condition. A completed test took on average 17 minutes and was rewarded with 3.50 GBP.
|
| 144 |
+
|
| 145 |
+
The mean opinion scores (MOS) from the test are reported in Table 1, together with 95% confidence intervals based on a Gaussian approximation. Pairwise t -tests find all conditions to be significantly different (with p< 10 -3 ) except NH2 and T2 -P ( p> 0 . 98 ), whose respective mean opinion scores differ by less than 0.002 before rounding. We can conclude that the proposed neural HMM TTS (NH2), despite being simpler and lighter, achieved a naturalness on par with the most comparable Tacotron 2 condition (T2 -P). This was not achieved by SSNT-TTS [16]. Neural HMMs were found to benefit from using two states per phone (NH2 vs. NH1), whilst Tacotron 2 improved from the use of a post-net (T2 + P vs. T2 -P).
|
| 146 |
+
|
| 147 |
+
## 5. CONCLUSION AND FUTURE WORK
|
| 148 |
+
|
| 149 |
+
We have described how classical and contemporary TTS paradigms can be combined to obtain fully probabilistic, attention-free sequenceto-sequence TTS based on neural HMMs. Our example system is smaller than Tacotron 2, yet achieves comparable naturalness, learns to speak and align faster, needs less data, and does not babble. To our knowledge, this is the first time an HMM-based system demonstrates a speech quality matching prior neural TTS. The neural HMMs also permit easy control over the speaking rate of the synthetic speech.
|
| 150 |
+
|
| 151 |
+
Future work includes stronger network architectures, e.g., based on transformers and with a separately trained post-net. It also seems compelling to combine neural HMMs with powerful distribution families such as normalising flows, either replacing the Gaussian assumption (as done for non-neural HMMs in [38]) or as a probabilistic post-net like in [18]. This may allow the naturalness of sampled speech to surpass that of deterministic output generation.
|
| 152 |
+
|
| 153 |
+
## 6. REFERENCES
|
| 154 |
+
|
| 155 |
+
- [1] H. Zen, K. Tokuda, and A. W. Black, 'Statistical parametric speech synthesis,' Speech Commun. , vol. 51, no. 11, 2009.
|
| 156 |
+
- [2] X. Tan, T. Qin, F. Soong, and T.-Y. Liu, 'A survey on neural speech synthesis,' arXiv preprint arXiv:2106.15561 , 2021.
|
| 157 |
+
- [3] Y. Wang, RJ Skerry-Ryan, D. Stanton, Y. Wu, R. J. Weiss, N. Jaitly, et al., 'Tacotron: Towards end-to-end speech synthesis,' in Proc. Interspeech , 2017.
|
| 158 |
+
- [4] J. Shen, R. Pang, R. J. Weiss, M. Schuster, N. Jaitly, Z. Yang, et al., 'Natural TTS synthesis by conditioning WaveNet on mel spectrogram predictions,' in Proc. ICASSP , 2018.
|
| 159 |
+
- [5] O. Watts, G. E. Henter, T. Merritt, Z. Wu, and S. King, 'From HMMsto DNNs: where do the improvements come from?,' in Proc. ICASSP , 2016.
|
| 160 |
+
- [6] O. Watts, G. E. Henter, J. Fong, and C. Valentini-Botinhao, 'Where do the improvements come from in sequence-tosequence neural TTS?,' in Proc. SSW , 2019.
|
| 161 |
+
- [7] K. M. Tran, Y. Bisk, A. Vaswani, D. Marcu, and K. Knight, 'Unsupervised neural hidden Markov models,' in Proc. Workshop on Structured Prediction for NLP , 2016.
|
| 162 |
+
- [8] L. Yu, J. Buys, and P. Blunsom, 'Online segment to segment neural transduction,' in Proc. EMNLP , 2016.
|
| 163 |
+
- [9] Z. Wu, O. Watts, and S. King, 'Merlin: An open source neural network speech synthesis system,' in Proc. SSW , 2016.
|
| 164 |
+
- [10] K. Tokuda, T. Yoshimura, T. Masuko, T. Kobayashi, and T. Kitamura, 'Speech parameter generation algorithms for HMMbased speech synthesis,' in Proc. ICASSP , 2000.
|
| 165 |
+
- [11] L. R. Rabiner, 'A tutorial on hidden Markov models and selected applications in speech recognition,' Proc. IEEE , vol. 77, no. 2, 1989.
|
| 166 |
+
- [12] M. Shannon, H. Zen, and W. Byrne, 'Autoregressive models for statistical parametric speech synthesis,' IEEE T. Audio Speech , vol. 21, no. 3, 2013.
|
| 167 |
+
- [13] C. Quillen, 'Autoregressive HMM speech synthesis,' in Proc. ICASSP , 2012.
|
| 168 |
+
- [14] X. Wang, S. Takaki, and J. Yamagishi, 'An autoregressive recurrent mixture density network for parametric speech synthesis,' in Proc. ICASSP , 2017.
|
| 169 |
+
- [15] M. He, Y. Deng, and L. He, 'Robust sequence-to-sequence acoustic modeling with stepwise monotonic attention for neural TTS,' Proc. Interspeech , 2019.
|
| 170 |
+
- [16] Y. Yasuda, X. Wang, and J. Yamagishi, 'Initial investigation of encoder-decoder end-to-end TTS using marginalization of monotonic hard alignments,' in Proc. SSW , 2019.
|
| 171 |
+
- [17] Z. Zeng, J. Wang, N. Cheng, T. Xia, and J. Xiao, 'AlignTTS: Efficient feed-forward text-to-speech system without explicit alignment,' in Proc. ICASSP , 2020.
|
| 172 |
+
- [18] J. Kim, S. Kim, J. Kong, and S. Yoon, 'Glow-TTS: A generative flow for text-to-speech via monotonic alignment search,' in Proc. NeurIPS , 2020.
|
| 173 |
+
- [19] J. Shen, Y. Jia, M. Chrzanowski, Y. Zhang, I. Elias, H. Zen, et al., 'Non-Attentive Tacotron: Robust and controllable neural TTS synthesis including unsupervised duration modeling,' arXiv preprint arXiv:2010.04301 , 2020.
|
| 174 |
+
- [20] Y. Yasuda, X. Wang, and J. Yamagishi, 'End-to-end textto-speech using latent duration based on VQ-VAE,' in Proc. ICASSP , 2021.
|
| 175 |
+
- [21] Y. Nankaku, K. Sumiya, T. Yoshimura, S. Takaki, K. Hashimoto, K. Oura, et al., 'Neural sequence-tosequence speech synthesis using a hidden semi-Markov model based structured attention mechanism,' arXiv preprint arXiv:2108.13985 , 2021.
|
| 176 |
+
- [22] T. Fujimoto, K. Hashimoto, Y. Nankaku, and K. Tokuda, 'Autoregressive variational autoencoder with a hidden semiMarkov model-based structured attention for speech synthesis,' in Proc. ICASSP , 2022.
|
| 177 |
+
- [23] H. Zen, K. Tokuda, T. Masuko, T. Kobayashi, and T. Kitamura, 'Hidden semi-Markov model based speech synthesis,' in Proc. SLP , 2004.
|
| 178 |
+
- [24] S. Ronanki, O. Watts, S. King, and G. E. Henter, 'Medianbased generation of synthetic speech durations using a nonparametric approach,' in Proc. SLT , 2016.
|
| 179 |
+
- [25] J. K. Chorowski, D. Bahdanau, D. Serdyuk, K. Cho, and Y. Bengio, 'Attention-based models for speech recognition,' in Proc. NIPS , 2015.
|
| 180 |
+
- [26] T. Toda and K. Tokuda, 'A speech parameter generation algorithm considering global variance for HMM-based speech synthesis,' IEICE T. Inf. Syst. , vol. 90, no. 5, 2007.
|
| 181 |
+
- [27] S. Young, G. Evermann, D. Kershaw, G. Moore, J. Odell, D. Ollason, et al., The HTK Book (for HTK Version 3.2) , 2002.
|
| 182 |
+
- [28] H. Zhang, Y. N. Dauphin, and T. Ma, 'Fixup initialization: Residual learning without normalization,' in Proc. ICLR , 2019.
|
| 183 |
+
- [29] A. P. Dempster, N. M. Laird, and D. B. Rubin, 'Maximum likelihood from incomplete data via the EM algorithm,' J. Roy. Stat. Soc. B , vol. 39, no. 1, 1977.
|
| 184 |
+
- [30] G. E. Henter, T. Merritt, M. Shannon, C. Mayo, and S. King, 'Measuring the perceptual effects of modelling assumptions in speech synthesis using stimuli constructed from repeated natural speech,' in Proc. Interspeech , 2014.
|
| 185 |
+
- [31] G. E. Henter, S. Ronanki, O. Watts, M. Wester, Z. Wu, and S. King, 'Robust TTS duration modelling using DNNs,' in Proc. ICASSP , 2016.
|
| 186 |
+
- [32] G. E. Henter, S. Ronanki, O. Watts, and S. King, 'Nonparametric duration modelling for speech synthesis with a joint model of acoustics and duration,' IEICE Tech. Rep. 414, 2017.
|
| 187 |
+
- [33] J.-S. Bae, H. Bae, Y.-S. Joo, J. Lee, G.-H. Lee, and H.-Y. Cho, 'Speaking speed control of end-to-end speech synthesis using sentence-level conditioning,' in Proc. Interspeech , 2020.
|
| 188 |
+
- [34] J. Fong, J. Taylor, K. Richmond, and S. King, 'A comparison between letters and phones as input to sequence-to-sequence models for speech synthesis,' in Proc. SSW , 2019.
|
| 189 |
+
- [35] R. Prenger, R. Valle, and B. Catanzaro, 'WaveGlow: A flow-based generative network for speech synthesis,' in Proc. ICASSP , 2019.
|
| 190 |
+
- [36] IEEE, 'IEEE recommended practice for speech quality measurements,' IEEE T. Acoust. Speech , vol. 17, no. 3, 1969.
|
| 191 |
+
- [37] EBU, 'Loudness normalisation and permitted maximum level of audio signals,' EBU Recommendation EBU R 128v4, 2020.
|
| 192 |
+
- [38] A. Ghosh, A. Honoré, D. Liu, G. E. Henter, and S. Chatterjee, 'Normalizing flow based hidden Markov models for classification of speech phones with explainability,' arXiv preprint arXiv:2107.00730 , 2021.
|
text-versions/attention-markdown/2109.07043_Attention Is Indeed All You Need Semanti.md
ADDED
|
@@ -0,0 +1,496 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2109.07043 Attention Is Indeed All You Need Semanti
|
| 2 |
+
|
| 3 |
+
## Attention Is Indeed All You Need: Semantically Attention-Guided Decoding for Data-to-Text NLG
|
| 4 |
+
|
| 5 |
+
Juraj Juraska and Marilyn Walker
|
| 6 |
+
|
| 7 |
+
Natural Language and Dialogue Systems Lab University of California, Santa Cruz
|
| 8 |
+
|
| 9 |
+
{ jjuraska,mawalker }
|
| 10 |
+
|
| 11 |
+
## Abstract
|
| 12 |
+
|
| 13 |
+
Ever since neural models were adopted in datato-text language generation, they have invariably been reliant on extrinsic components to improve their semantic accuracy, because the models normally do not exhibit the ability to generate text that reliably mentions all of the information provided in the input. In this paper, we propose a novel decoding method that extracts interpretable information from encoder-decoder models' cross-attention, and uses it to infer which attributes are mentioned in the generated text, which is subsequently used to rescore beam hypotheses. Using this decoding method with T5 and BART, we show on three datasets its ability to dramatically reduce semantic errors in the generated outputs, while maintaining their state-of-the-art quality.
|
| 14 |
+
|
| 15 |
+
## 1 Introduction
|
| 16 |
+
|
| 17 |
+
Task-oriented dialogue systems require high semantic fidelity of the generated responses in order to correctly track what information has been exchanged with the user. Therefore, their natural language generation (NLG) components are typically conditioned on structured input data, performing data-to-text generation. To achieve high semantic accuracy, neural models for data-to-text NLG have invariably been reliant on extrinsic components or methods. While large pretrained generative language models (LMs), such as GPT-2 or T5, perform better in this respect, even they do not normally generate text that reliably mentions all the information provided in the input.
|
| 18 |
+
|
| 19 |
+
In this work, we study the behavior of attention in large pretrained LMs fine-tuned for data-to-text NLG tasks. We show that encoder-decoder models equipped with cross-attention (i.e., an attention mechanism in the decoder looking back at the encoder's outputs) are, in fact, aware of the semantic constraints, yet standard decoding methods do not
|
| 20 |
+
|
| 21 |
+
@ucsc.edu
|
| 22 |
+
|
| 23 |
+
fully utilize the model's knowledge. The method we propose extracts interpretable information from the model's cross-attention mechanism at each decoding step, and uses it to infer which slots have been correctly realized in the output. Coupled with beam search, we use the inferred slot realizations to rescore the beam hypotheses, preferring those with the fewest missing or incorrect slot mentions.
|
| 24 |
+
|
| 25 |
+
To summarize our contributions, the proposed semantic attention-guided decoding method, or SEAGUIDE for short: (1) drastically reduces semantic errors in the generated text (shown on the E2E, ViGGO, and MultiWOZ datasets); (2) is domainand model-independent for encoder-decoder architectures with cross-attention, as shown on different sizes of T5 and BART; (3) works out of the box, but is parameterizable, which allows for further optimization; (4) adds only a small performance overhead over beam search decoding; and (5) perhaps most importantly, requires no model modifications, no additional training data or data preprocessing (such as augmentation, segmentation, denoising, or alignment), and no manual annotation. 1
|
| 26 |
+
|
| 27 |
+
## 2 Related Work
|
| 28 |
+
|
| 29 |
+
Several different approaches to enhancing semantic accuracy of neural end-to-end models have been proposed for data-to-text NLG over the years. The most common approach to ensuring semantic quality relies on over-generating and then reranking candidate outputs using criteria that the model was not explicitly optimized for in training. Reranking in sequence-to-sequence models is typically performed by creating an extensive set of rules, or by training a supplemental classifier, that indicates for each input slot whether it is present in the output utterance (Wen et al., 2015a; Duˇ sek and Jurˇ c´ ıˇ cek,
|
| 30 |
+
|
| 31 |
+
1 The code for SEA-GUIDE and heuristic semantic error evaluation can be found at https://github.com/ jjuraska/data2text-nlg .
|
| 32 |
+
|
| 33 |
+
2016; Juraska et al., 2018; Agarwal et al., 2018; Kedzie and McKeown, 2020; Harkous et al., 2020).
|
| 34 |
+
|
| 35 |
+
Wen et al. (2015b) proposed an extension of the underlying LSTM cells of their sequence-tosequence model to explicitly track, at each decoding step, the information mentioned so far. The coverage mechanism (Tu et al., 2016; Mi et al., 2016; See et al., 2017) penalizes the model for attending to the same parts of the input based on the cumulative attention distribution in the decoder. Chisholm et al. (2017) and Shen et al. (2019) both introduce different sequence-to-sequence model architectures that jointly learn to generate text and reconstruct the input facts. An iterative self-training process using data augmentation (Nie et al., 2019; Kedzie and McKeown, 2019) was shown to reduce semantic NLG errors on the E2E dataset (Novikova et al., 2017). Among the most recent efforts, the jointly-learned segmentation and alignment method of Shen et al. (2020) improves semantic accuracy while simultaneously increasing output diversity. Kedzie and McKeown (2020) use segmentation for data augmentation and automatic utterance planning, which leads to a reduction in semantic errors on both the E2E and ViGGO (Juraska et al., 2019) datasets.
|
| 36 |
+
|
| 37 |
+
In contrast to the above methods, our approach does not rely on model modifications, data augmentation, or manual annotation. Our method is novel in that it utilizes information that is already present in the model itself to perform semantic reranking.
|
| 38 |
+
|
| 39 |
+
Finally, related to our work is also controllable neural language generation, in which the constrained decoding strategy is often used, rescoring tokens at each decoding step based on a set of feature discriminators (Ghazvininejad et al., 2017; Baheti et al., 2018; Holtzman et al., 2018). Nevertheless, this method is typically used with unconditional generative LMs, and hence does not involve input-dependent constraints.
|
| 40 |
+
|
| 41 |
+
## 3 Semantic Attention-Guided Decoding
|
| 42 |
+
|
| 43 |
+
While we will evaluate the SEA-GUIDE method on ViGGO, E2E, and MultiWOZ, we develop the method by careful analysis of the cross-attention behavior of different pretrained generative LMs fine-tuned on the ViGGO dataset. ViGGO is a parallel corpus of structured meaning representations (MRs) and corresponding natural-language utterances in the video game domain. The MRs consist of a dialogue act (DA) and a list of slot-and- value pairs. The motivation for selecting ViGGO for developing the method was that it is the smallest dataset, but it provides a variety of DA and slot types (as shown in Table 1). The models used for the analysis were the smallest variants of T5 (Raffel et al., 2020) and BART (Lewis et al., 2020). We saved the larger variants of the models, as well as the other two datasets, for the evaluation.
|
| 44 |
+
|
| 45 |
+
## 3.1 Interpreting Cross-Attention
|
| 46 |
+
|
| 47 |
+
Attention (Bahdanau et al., 2015; Luong et al., 2015) is a mechanism that was introduced in encoder-decoder models (Sutskever et al., 2014; Cho et al., 2014) to overcome the long-range dependencies problem of RNN-based models. It allows the decoder to effectively condition its output tokens on relevant parts of the encoder's output at each decoding step. The term cross-attention is primarily used when referring to the more recent transformer-based encoder-decoder models (Vaswani et al., 2017), to distinguish it from the self-attention layers present in both the encoder and the decoder transformer blocks. The crossattention layer ultimately provides the decoder with a weight distribution at each step, indicating the importance of each input token in the current context.
|
| 48 |
+
|
| 49 |
+
Our results below will show that visualizing the attention weight distribution for individual crossattention layers in the decoder - for many different inputs - reveals multiple universal patterns, whose combination can be exploited to track the presence, or lack thereof, of input slots in the output sequence. Despite the differences in the training objectives of T5 and BART, as well as their different sizes, we observe remarkably similar patterns in their respective cross-attention behavior. Below, we describe the three most essential patterns (illustrated in Figure 1) that we use in SEA-GUIDE.
|
| 50 |
+
|
| 51 |
+
## 3.1.1 Verbatim Slot Mention Pattern
|
| 52 |
+
|
| 53 |
+
The first pattern consistently occurs in the lowest attention layer, whose primary role appears to be to retrospectively keep track of a token in the input sequence that the decoder just generated in the previous step. Figure 1a shows an example of an extremely high attention weight on the input token 'third' when the decoder is deciding which token to generate after 'What is it about third ' (which ends up being the token 'person'). This pattern, which we refer to as the verbatim slot mention pattern, can be captured by maximizing the weight over all attention heads in the decoder's first layer.
|
| 54 |
+
|
| 55 |
+
<!-- image -->
|
| 56 |
+
|
| 57 |
+
- (a) Verbatim slot mention (1 st layer).
|
| 58 |
+
- (b) Paraphrased slot mention (3 rd layer).
|
| 59 |
+
- (c) Unrealized slot mention (4 th layer).
|
| 60 |
+
|
| 61 |
+
Figure 1: Visualization of cross-attention weight distribution for the 6-layer T5-small (trained on the ViGGO dataset) in 3 different scenarios. The left column in each corresponds to the input tokens, and the right to the tokens generated by the decoder. The darker the blue background shade, the greater the attention weight. Note that the weights are aggregated across all attention heads by extracting the maximum.
|
| 62 |
+
|
| 63 |
+
Figure 2: An example of the decoder paying equal attention (in the 5 th layer of the 6-layer T5-small) to two slots in the input sequence when deciding what to generate next after 'What is it about'.
|
| 64 |
+
|
| 65 |
+
<!-- image -->
|
| 66 |
+
|
| 67 |
+
## 3.1.2 Paraphrased Slot Mention Pattern
|
| 68 |
+
|
| 69 |
+
Paraphrased slot mentions, on the other hand, are captured by the higher layers, at the moment when a corresponding token is about to be mentioned next. Essentially, as we move further up the layers, the cross-attention weights gradually shift towards input tokens that correspond to information that is most likely to follow next in the output, and capture increasingly more abstract concepts in general. Figure 1b shows an example of the RATING slot's value 'poor' paraphrased in the generated utterance as 'distasteful'; the first high attention value associated with the input token 'poor' occurs when the decoder is about to generate the 'dis' token.
|
| 70 |
+
|
| 71 |
+
At certain points during generation, however, the attention in the uppermost layers is distributed fairly evenly among multiple slots, because any of them could lead to a coherent continuation of the sentence. For example, the generated utterance in Figure 2 could have started with 'What is it about vehicular combat games played from a thirdperson perspective that. . . ', where the GENRES slot is output before the PLAYER PERSPECTIVE slot.
|
| 72 |
+
|
| 73 |
+
In order to recognize a paraphrased mention, without incorrectly capturing other slots considered, we propose averaging the cross-attention weights, using only the bottom half of the layers (e.g., layers 1 to 3 in the T5-small model).
|
| 74 |
+
|
| 75 |
+
## 3.1.3 Unrealized Slot Mention Pattern
|
| 76 |
+
|
| 77 |
+
The third pattern alleviates any undesired side effects of identifying paraphrased mentions using the second pattern, i.e., slots incorrectly assumed to be mentioned. Figure 1c illustrates an unrealized slot (PLATFORMS) being paid attention to in several decoding steps. The cross-attention weight distribution for the 'Xbox' token in the 4th layer, shows that the decoder considered mentioning the slot at step 5 (e.g., 'Since you're an Xbox fan and like multiplayer games,. . . '), as well as step 8 (e.g., '. . . into multiplayer games on Xbox, . . . '). The second pattern, depending on the sensitivity setting (see Section 3.2), might infer the PLATFORMS slot as a paraphrased mention at step 5 and/or 8.
|
| 78 |
+
|
| 79 |
+
However, the PLATFORMS slot's value is also paid attention to when the decoder is about to generate the EOS token and, importantly, without any high attention weights associated with other slots at this step. This suggests that the model is aware that it omitted that slot. However, at that point, the decoder is more confident ending the sentence than realizing the missed slot after generating a question mark. This unrealized slot mention pattern is most likely to occur in the higher cross-attention layers, but not necessarily, so it is more effective to capture it by averaging the attention weights over all layers (at the last decoding step).
|
| 80 |
+
|
| 81 |
+
Note on Boolean Slots. With any of the three patterns described above, Boolean slots, such as HAS MULTIPLAYER in Figure 1c, typically have a high attention weight associated with their name rather than the value. This observation leads to a different treatment of Boolean slots, as described in Appendix B.1.
|
| 82 |
+
|
| 83 |
+
## 3.2 Slot Mention Tracking
|
| 84 |
+
|
| 85 |
+
We use the findings of the cross-attention analysis for automatic slot mention tracking in the decoder. During decoding, for each sequence, the attention weights associated with the next token to be generated are aggregated as per Section 3.1. Using configurable thresholds , the aggregated weights are then binarized, i.e., set to 1 if above the threshold, and 0 otherwise. This determines the sensitivity of the pattern recognition. Optionally, all but the maximum weight can be set to 0 , in which case only a single input token will by implied even if the attention mass is spread evenly across multiple tokens. Finally, the indices of binarized weights of value 1 , if any, are matched with their corresponding slots depending on which slot-span in the input sequence they fall into. For details on automatically extracting slot spans, see Appendix B.1.
|
| 86 |
+
|
| 87 |
+
## 3.2.1 Mention-Tracking Components
|
| 88 |
+
|
| 89 |
+
The three mention-tracking components, each of which operates on different attention layers and uses a different weight aggregation and binarization strategy, are summarized in Table 3. These components are executed in sequence and update one common slot-tracking object.
|
| 90 |
+
|
| 91 |
+
The first component, which tracks verbatim mentions, operates on the first attention layer only, with a high binarization threshold. Slot mentions identified by this component are regarded as highconfidence. The second component tracks paraphrased mentions, which are identified as slot mentions with low confidence, due to the partial ambi- guity in mention detection using the second pattern (see Section 3.1.2). The third component only kicks in when the EOS token is the most probable next token. At that point, it identifies - with high sensitivity - slots that were not realized in the sequence (e.g., the PLATFORMS slot in Figure 1c), and removes the corresponding mention record(s). Only low-confidence mentions can be erased, while highconfidence ones are final once they are detected.
|
| 92 |
+
|
| 93 |
+
## 3.3 Semantic Reranking
|
| 94 |
+
|
| 95 |
+
Combining the slot mention tracking with beam search, for each input MR we obtain a pool of candidate utterances along with the semantic errors inferred at decoding time. We then rerank the candidates and pick the one with the fewest errors, resolving ties using the length-weighted logprobability scores determined during beam search.
|
| 96 |
+
|
| 97 |
+
## 4 Evaluation
|
| 98 |
+
|
| 99 |
+
In order to measure the proposed decoding method's performance in semantic error reduction, we first develop an automatic way of identifying erroneous slot mentions in generated utterances. In a human evaluation we establish that its performance is nearly perfect for all three datasets used for testing our models (see Section 4.1). We then use it to calculate the slot error rate (SER) automatically for all our model outputs across all datasets and configurations tested, which would be infeasible to have human annotators do.
|
| 100 |
+
|
| 101 |
+
Datasets. Besides ViGGO, which we use for finetuning the decoding (slot-tracking) parameters of the proposed SEA-GUIDE method, we evaluate its effectiveness for semantic error reduction on two unseen and out-of-domain datasets. While E2E (Novikova et al., 2017) is also a simple MR-totext generation dataset (in the restaurant domain), MultiWOZ 2.1 (Eric et al., 2020) is a dialogic corpus covering several domains from which we extract system turns only, along with their MR annotations, along the lines of Peng et al. (2020) and Kale and Rastogi (2020). Table 1 gives an overview of the datasets' properties.
|
| 102 |
+
|
| 103 |
+
Setup. In our experiments, we fine-tune T5 and BART models of varying sizes on the above datasets' training partitions, select the best model checkpoints based on the BLEU score they achieve on the respective validation set, and evaluate them on the test sets while using different decoding meth- ods for inference. For beam search decoding, including when used as part of SEA-GUIDE, we use beam size 10 and early stopping, unless stated otherwise. All of our results are averaged over three runs with random initialization. For further details on training and inference parameters, we refer the reader to Appendix A.3.
|
| 104 |
+
|
| 105 |
+
Table 1: Dataset statistics, including the total number of dialogue act (DA) and slot types. For MultiWOZ, the numbers are calculated across system turns only.
|
| 106 |
+
|
| 107 |
+
| Size Domains DAs Slots ViGGO 6,900 1 9 14 E2E 51,426 1 1 8 MultiWOZ 70,530 7 13 27 |
|
| 108 |
+
|--------------------------------------------------------------------------------------------------------|
|
| 109 |
+
|
| 110 |
+
Table 2: Human evaluation of the slot aligner's performance on each dataset. The IAA column indicates the Krippendorff's alpha reliability coefficient.
|
| 111 |
+
|
| 112 |
+
| SERSA SER CI (95%) Precision IAA ViGGO 2 . 77% 2 . 19 ± 1 . 55% 97 . 37% 1 . 00 E2E 3 . 98% 3 . 91 ± 1 . 73% 100% 1 . 00 MultiWOZ 1 . 19% 1 . 35 ± 0 . 91% 94 . 89% 0 . 90 |
|
| 113 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 114 |
+
|
| 115 |
+
## 4.1 Automatic Slot Error Evaluation
|
| 116 |
+
|
| 117 |
+
We evaluate our trained models performance with the standard NLG metrics BLEU (Papineni et al., 2002), METEOR (Lavie and Agarwal, 2007), ROUGE-L (Lin, 2004), and CIDEr (Vedantam et al., 2015), whose calculation is detailed in Appendix A.4. However, we also put substantial effort into developing a highly accurate heuristic slot aligner to calculate the semantic accuracy of generated utterances. The slot aligner is rule-based and took dozens of man-hours to develop, but it is robust and extensible to new domains, so it works on all three test datasets. Using the slot aligner, we count missed, incorrect, and repeated slot mentions, and determine the slot error rate (SER) as the percentage of these errors out of all slots.
|
| 118 |
+
|
| 119 |
+
To verify our slot aligner's performance, we take the generated utterances of one model per dataset for which it calculated a relatively high SER (indicated in the SERSA column in Table 2). We then have one of the authors and an additional expert annotator manually label all of the errors as true or false positives. This corresponds to 38, 173 and 176 errors for ViGGO, E2E and MultiWOZ, respectively. From that we calculate the precision for each dataset, which turns out to be above 94% for each of the datasets. The almost perfect inter-annotator agreement (IAA), besides validating the precision, also suggests that the SER is an objective metric, and therefore well-suited for automation.
|
| 120 |
+
|
| 121 |
+
Table 3: The final configuration of parameters used in each of the 3 mention-tracking components. The 'Bin. max.' row indicates whether only the maximum weight is kept during binarization, or all above the threshold.
|
| 122 |
+
|
| 123 |
+
| Verbatim Paraphrased Unrealized Layer agg. 1 st layer only avg. over bottom half of layers avg. Head agg. max. max. max. Bin. threshold 0.9 0.4 (T5-small) 0.3 (BART-base) 0.1 Bin. max. yes no no |
|
| 124 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 125 |
+
|
| 126 |
+
Furthermore, we take samples of 72 ( ≈ 20% ), 63 ( ≈ 10% ) and 290 ( ≈ 4% ) of the generated utterances on ViGGO, E2E and MultiWOZ, respectively, annotate them for all types of errors, and calculate the actual SER confidence intervals (middle column). Their good alignment with the slot aligner SER scores, together with the high error classification precision, leads us to the conclusion that the slot aligner performs similarly to humans in identifying semantic errors on the above datasets.
|
| 127 |
+
|
| 128 |
+
Besides SER evaluation, the slot aligner can also be used for beam reranking. Due to the handcrafted and domain-specific nature of the slot aligner, beam search with this reranking has a distinct advantage over SEA-GUIDE, which can be used for any domain out of the box. We therefore consider the results when using the slot-aligner reranking to be an upper bound for SEA-GUIDE in terms of SER.
|
| 129 |
+
|
| 130 |
+
## 4.2 SEA-GUIDE Parameter Tuning
|
| 131 |
+
|
| 132 |
+
Each of the three mention-tracking components described in Section 3.2.1 has four configurable parameters, which we tuned by testing T5-small and BART-base, fine-tuned on the ViGGO dataset and equipped with SEA-GUIDE for inference. The parameter optimization was based on the insights obtained in Section 3.1 and a subsequent grid search, with results in Table 3.
|
| 133 |
+
|
| 134 |
+
For attention weight aggregation, we experimented with summing, averaging, maximizing, and normalizing. We determined averaging over layers and maximizing over heads to be the best combination for all three components. As for the binarization thresholds, Figure 3 shows the most relevant slice of the grid search space for each component, leading to the final threshold values.
|
| 135 |
+
|
| 136 |
+
To show the effect of each slot-tracking component, we perform an ablation study with individual
|
| 137 |
+
|
| 138 |
+
<!-- image -->
|
| 139 |
+
|
| 140 |
+
(a) Threshold optimization for the 1 st component (verbatim mentions), with the other components enabled or disabled. When enabled, the 2 nd component's threshold was fixed at 0 . 3 , and that of the 3 rd at 0 . 1 . Note that the threshold of 1 . 0 is equivalent to the 1 st component being disabled, as attention weights are in the [0 . 0 , 1 . 0] range.
|
| 141 |
+
|
| 142 |
+
<!-- image -->
|
| 143 |
+
|
| 144 |
+
(b) Threshold optimization for the 2 nd component (paraphrased mentions), with the 1 st component's threshold of 0 . 2 , 0 . 5 and 0 . 8 , and that of the 3 rd component fixed at 0 . 1 .
|
| 145 |
+
|
| 146 |
+
<!-- image -->
|
| 147 |
+
|
| 148 |
+
(c) Threshold optimization for the 3 rd component (unrealized mentions), with the 2 nd component's threshold of 0 . 2 , 0 . 3 and 0 . 4 , and that of the 1 st component fixed at 0 . 5 .
|
| 149 |
+
|
| 150 |
+
Figure 3: Effects of different parameter configurations of the 3 mention-tracking components on SER and BLEU of utterances generated by BART-base finetuned on ViGGO.
|
| 151 |
+
|
| 152 |
+
Figure 4: The effect of different beam size on the SER using different reranking methods on the ViGGO dataset. With greedy search decoding, the SER is 1 . 65% and 2 . 70% for T5 and BART, respectively.
|
| 153 |
+
|
| 154 |
+
<!-- image -->
|
| 155 |
+
|
| 156 |
+
components disabled. 2 As the plot in Figure 3a demonstrates, the 1 st component by itself reduces the SER the most, but at the expense of the BLEU score, which decreases as the SER does - to the point where BLEU drops below 0 . 54 when the SER is at its lowest ( 0 . 91% ), that is with a threshold of 0 . 9 . For reference, the SER and the BLEU score achieved with beam search only are 2 . 04% and 0 . 543 , respectively. Adding the 2 nd component brings the BLEU score up to above 0 . 545 , nevertheless the SER jumps to 1 . 39% . Finally, enabling the 3 rd component too has a negligible negative effect on BLEU, but reduces the SER to 1 . 09% .
|
| 157 |
+
|
| 158 |
+
Figure 3b shows that the 2 nd component gives optimal performance when its threshold is set to around 0 . 3 . This setting maximizes BLEU, while keeping SER low. Beyond 0 . 3 the BLEU score starts dropping fast, and with a threshold of greater than 0 . 5 , the 2 nd component has barely any effect anymore. Similarly, Figure 3c shows the threshold value of 0 . 1 to be optimal in the 3 rd component, when optimizing for both metrics. Thresholds higher than 0 . 3 cut off almost all aggregated weights in this component, virtually disabling it.
|
| 159 |
+
|
| 160 |
+
## 4.3 Effects of Beam Size on SEA-GUIDE
|
| 161 |
+
|
| 162 |
+
Since SEA-GUIDE uses beam search to generate the pool of candidates that it later reranks, we analyzed the effect of increasing the beam size on the SER of the final utterances. As Figure 4 shows for the ViGGO dataset, SEA-GUIDE certainly benefits from increasing the beam size from 5 to 10, but the benefit shrinks substantially (or disappears entirely, in case of T5-small) when further increased to 20. An analysis for the E2E dataset, with similar results, is presented in Appendix B.3.
|
| 163 |
+
|
| 164 |
+
2 The 3 rd component has no effect without the 2 nd , so we do not consider the combination where only the 2 nd is disabled.
|
| 165 |
+
|
| 166 |
+
## 5 Results
|
| 167 |
+
|
| 168 |
+
To maximize the performance of the models using SEA-GUIDE, the binarization thresholds (and possibly other parameters of the mention-tracking components) can be optimized for each model and dataset on the validation set. In our evaluation, however, we focused on demonstrating the effectiveness of this decoding method out of the box. That being said, even common decoding methods, such as simple beam search or nucleus sampling (Holtzman et al., 2019), usually benefit from parameter optimization (e.g., beam size, or the p -value) whenever used with a different model or dataset.
|
| 169 |
+
|
| 170 |
+
## 5.1 SEA-GUIDE Performance
|
| 171 |
+
|
| 172 |
+
While developing the SEA-GUIDE method we analyzed the behavior of cross-attention on both the T5-small and the BART-base model; interestingly, the decoding performs best for both with nearly the same configuration. The only difference is the 2 nd component's binarization threshold (see Table 3), accounting for the fact that BART-base has 50% more attention heads than T5-small, which causes the attention weights to be more spread out.
|
| 173 |
+
|
| 174 |
+
The upper half of Table 4 compares the two models' performance with SEA-GUIDE vs. other decoding methods, as well as against three state-ofthe-art baselines. As the results show, both models, when using SEA-GUIDE, significantly reduce the number of semantic errors in the generated outputs compared to using greedy search ( ≈ 3.4 and 2.5 times in case of T5 and BART, respectively) or simple beam search ( ≈ 1.9 times both). As expected, the slot-aligner (SA) reranking achieves even better results thanks to the handcrafted rules it relies on. In addition, the overall high automatic metric scores suggest that the fluency of utterances generated using SEA-GUIDE does not suffer.
|
| 175 |
+
|
| 176 |
+
Finally, compared to the baseline models, T5small performs on par with the state-of-the-art DataTuner in terms of automatic metrics, yet maintains a 3.4-times lower SER. This corresponds approximately to K&M baseline's SER, whose automatic metrics, however, are significantly worse. BART-base outperforms T5-small according to most metrics, but its SER is more than double.
|
| 177 |
+
|
| 178 |
+
## 5.2 Cross-Model Robustness
|
| 179 |
+
|
| 180 |
+
In addition to T5-small and BART-base, we finetune a larger variant of each of the models, namely, T5-base and BART-large (see Appendix A.3 for model specifications), on the ViGGO dataset, and evaluate their inference performance when equipped with SEA-GUIDE. We do not perform any further tuning of the decoding parameters for these two models, only slightly lower the binarization thresholds (as we did for BART-base) to account for the models having more attention heads and layers. The thresholds we use for the 2 nd and 3 rd components are 〈 0 . 3 , 0 . 1 〉 and 〈 0 . 2 , 0 . 05 〉 for T5-base and BART-large, respectively.
|
| 181 |
+
|
| 182 |
+
Table 4: Models tested on the ViGGO dataset using different decoding methods: greedy search (GS), beam search with no reranking (BS), beam search with slotaligner reranking (SA), and SEA-GUIDE (SG). Baselines compared against are Slug2Slug (Juraska et al., 2019) (S2S), DataTuner (Harkous et al., 2020) (DT), and Kedzie and McKeown (2020) (K&M). The best results are highlighted in bold for each model. SER scores of baselines reported by the authors themselves, rather than calculated using our slot aligner, are highlighted in italics, and they do not correspond exactly to our SER results.
|
| 183 |
+
|
| 184 |
+
| Model BLEU MET. ROUGE CIDEr SER ↓ S2S 0.519 0.388 0.631 2.531 2.55% DT 0.536 0.394 0.640 2.700 1.68% K&M 0.485 0.380 0.592 2.454 0.46% T5-small GS 0.519 0.387 0.631 2.647 1.65% BS 0.540 0.392 0.636 2.685 0.95% SA 0.541 0.393 0.637 2.695 0.24% SG 0.541 0.393 0.637 2.695 0.49% BART-base GS 0.524 0.386 0.635 2.629 2.70% BS 0.544 0.393 0.639 2.679 2.02% SA 0.547 0.394 0.639 2.704 0.39% SG 0.545 0.393 0.639 2.698 1.07% T5-base GS 0.527 0.394 0.639 2.682 0.61% BS 0.534 0.394 0.636 2.664 0.66% SA 0.536 0.394 0.637 2.672 0.19% SG 0.536 0.394 0.637 2.670 0.46% BART-large GS 0.508 0.378 0.616 2.452 5.50% BS 0.535 0.391 0.628 2.612 1.78% SA 0.538 0.394 0.631 2.659 0.27% SG 0.533 0.391 0.627 2.613 1.41% |
|
| 185 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 186 |
+
|
| 187 |
+
The results in the lower half of Table 4 show that these two larger models, fine-tuned on ViGGO, benefit from SEA-GUIDE beyond just the effect of beam search. T5-base performs significantly better across the board than its smaller T5 variant, so there is less room for improvement to begin with. In fact, the SER using greedy search is so low ( 0 . 61% , in contrast to T5-small's 1 . 65% ) that beam search causes it to increase. Nevertheless, SEAGUIDE improves on both, while slightly boosting the other automatic metrics as well.
|
| 188 |
+
|
| 189 |
+
Table 5: Models tested on the E2E dataset, compared against the following baselines: Slug2Slug (Juraska et al., 2018), (S2S) S R 1 (Shen et al., 2019), and Kedzie and McKeown (2020) (K&M).
|
| 190 |
+
|
| 191 |
+
| Model BLEU MET. ROUGE CIDEr SER ↓ S2S 0.662 0.445 0.677 2.262 0.91% S R 1 0.686 0.453 0.708 2.370 N/A K&M 0.663 0.453 0.693 2.308 0.00% T5-small GS 0.670 0.454 0.692 2.244 1.60% BS 0.667 0.453 0.694 2.361 2.85% SA 0.675 0.453 0.690 2.341 0.02% SG 0.675 0.453 0.690 2.340 0.04% BART-base GS 0.667 0.454 0.694 2.276 1.97% BS 0.670 0.454 0.701 2.372 3.39% SA 0.680 0.453 0.695 2.350 0.02% SG 0.680 0.453 0.695 2.347 0.08% T5-base GS 0.668 0.459 0.692 2.282 1.85% BS 0.667 0.453 0.697 2.387 3.94% SA 0.682 0.454 0.691 2.375 0.03% SG 0.682 0.454 0.691 2.374 0.05% |
|
| 192 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 193 |
+
|
| 194 |
+
Table 6: Models tested on MultiWOZ, compared against the following baselines: SC-GPT (Peng et al., 2020) (SCG) and Kale and Rastogi (2020) (K&R).
|
| 195 |
+
|
| 196 |
+
| Model BLEU BLEUR MET. SER ↓ SERE ↓ SCG N/A 0.308 N/A 0.53% N/A K&R N/A 0.351 N/A N/A 1.27% T5-small GS 0.367 0.351 0.325 1.15% 1.36% BS 0.359 0.344 0.323 1.06% 1.19% SA 0.360 0.344 0.323 0.41% 0.63% SG 0.360 0.344 0.323 0.60% 0.85% BART-base GS 0.372 0.356 0.326 1.18% 1.17% BS 0.363 0.346 0.323 1.12% 1.02% SA 0.364 0.347 0.324 0.40% 0.60% SG 0.363 0.347 0.323 0.63% 0.72% |
|
| 197 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 198 |
+
|
| 199 |
+
The almost twice-as-large BART-large model performs rather poorly in our experiments, in fact, significantly underperforming its smaller variant. 3 We therefore refrain from drawing any conclusions for this model, although SEA-GUIDE offers a definite improvement in SER over simple beam search.
|
| 200 |
+
|
| 201 |
+
## 5.3 Domain Transferability
|
| 202 |
+
|
| 203 |
+
We achieve similar results when evaluating across domains. Table 5 shows that using SEA-GUIDE with all three models fine-tuned on E2E reduces the SER down to almost zero, with performance for the other metrics comparable to the state-of- the-art baseline. 4 In fact, SEA-GUIDE is nearly as effective at reducing errors in this dataset as the heuristic slot aligner (SA). Table 6 compares our models against two recent baselines on the MultiWOZ dataset, where the effectiveness of SEAGUIDE on SER reduction is comparable to that on the ViGGO dataset. All in all, on both the E2E and the MultiWOZ dataset, our models equipped with SEA-GUIDE for inference perform similarly to the best baselines for both SER and the other metrics at the same time , whereas the baselines individually perform well according to one at the expense of the other.
|
| 204 |
+
|
| 205 |
+
3 We observed that it frequently misrepresents names, such as 'Transportal Tycoon' instead of 'Transport Tycoon', which we think may be the consequence of the extremely small size of the ViGGO training set relative to the model's size.
|
| 206 |
+
|
| 207 |
+
## 5.4 Slot Error Detection Examples
|
| 208 |
+
|
| 209 |
+
Table 7 shows several utterances generated for corresponding input MRs in the video game domain, along with the errors SEA-GUIDE detected, if any. In the first example, all slots are correctly mentioned, and SEA-GUIDE agrees. This utterance was ultimately selected during reranking over the beam search's choice, 'The Room is an excellent first person point-and-click puzzle game.', which has one of the genres omitted.
|
| 210 |
+
|
| 211 |
+
The second example again showcases a successful identification of all slot mentions by SEAGUIDE, this time in an utterance where our heuristic slot aligner incorrectly found an error in the HAS LINUX RELEASE slot mention (presumably confused by the negation shortly before the keyword 'Linux').
|
| 212 |
+
|
| 213 |
+
The third example shows that SEA-GUIDE is not confused by the difference between 'excellent' (input slot value) and 'amazing' (the corresponding slot realization), and it correctly identifies that the PLAYER PERSPECTIVE slot is not mentioned.
|
| 214 |
+
|
| 215 |
+
In the fourth example, SEA-GUIDE fails to recognize the incorrect mention of the HAS LINUX RELEASE slot. This is the most common mistake our decoding method makes.
|
| 216 |
+
|
| 217 |
+
The final example does not contain any errors, yet the heuristic slot aligner was confused by the negation formulation (as 'I wish it was') and identified the AVAILABLE ON STEAM slot as incorrect, while SEA-GUIDE did not. This demonstrates the robustness of SEA-GUIDE beyond exact matching. Yet despite the individual slots being mentioned semantically correctly, the generated utterance as a whole does not sound quite right. A better utterance give opinion(NAME[The Room], RATING[excellent], GENRES[indie, point-and-click, puzzle], PLAYER PERSPECTIVE[first person])
|
| 218 |
+
|
| 219 |
+
4 We were unable to successfully train BART-large on E2E due to the memory limitations of our computational resources.
|
| 220 |
+
|
| 221 |
+
The Room is an excellent indie point-and-click puzzle game. The first person perspective makes it easy to play. Errors: N/A
|
| 222 |
+
|
| 223 |
+
verify attribute(name[Small World 2], RATING[poor], HAS LINUX RELEASE[yes])
|
| 224 |
+
|
| 225 |
+
You said earlier that you disliked Small World 2. Are you generally not fond of Linux games?
|
| 226 |
+
|
| 227 |
+
Errors: N/A
|
| 228 |
+
|
| 229 |
+
request explanation(RATING [excellent], GENRES [adventure, hack-and-slash, indie], PLAYER PERSPECTIVE [third person])
|
| 230 |
+
|
| 231 |
+
What is it about indie hack-and-slash adventure games that you find so amazing?
|
| 232 |
+
|
| 233 |
+
Errors: PLAYER PERSPECTIVE
|
| 234 |
+
|
| 235 |
+
inform(NAME[RollerCoaster Tycoon], RATING[good], GENRES[simulation, strategy], PLATFORMS[Xbox, PC], AVAILABLE ON STEAM[no], HAS LINUX RELEASE[yes], HAS MAC RELEASE[no])
|
| 236 |
+
|
| 237 |
+
RollerCoaster Tycoon is a good simulation strategy game for Xbox and PC. It is not available on Steam, Linux, or Mac.
|
| 238 |
+
|
| 239 |
+
Errors: N/A (incorrect)
|
| 240 |
+
|
| 241 |
+
give opinion(NAME [Mirror's Edge Catalyst], RATING [poor], AVAILABLE ON STEAM [no])
|
| 242 |
+
|
| 243 |
+
Mirror's Edge Catalyst is a pretty bad game, I really wish it was available on Steam.
|
| 244 |
+
|
| 245 |
+
Errors: N/A
|
| 246 |
+
|
| 247 |
+
Table 7: Examples of slot-mention tracking results using SEA-GUIDE. Each gray row is the input MR for the corresponding utterance in the subsequent row.
|
| 248 |
+
|
| 249 |
+
would be something along the lines of 'Mirror's Edge Catalyst is a disappointment, I really wish they released it on Steam as well.'.
|
| 250 |
+
|
| 251 |
+
All in all, SEA-GUIDE chooses semantically correct utterances that are fluent and adequate, except for the rare case like in the last example.
|
| 252 |
+
|
| 253 |
+
## 6 Discussion
|
| 254 |
+
|
| 255 |
+
In the previous section, we showed that SEAGUIDE is highly effective at reducing semantic errors across different models and domains, and that without compromising on the generated utterances' fluency. On datasets other than E2E, it does not quite match the performance of beam search combined with our slot aligner-based reranking, but then again, the slot aligner is a hand-crafted tool with complex rules, requiring a good deal of domain knowledge, and suffering thus significantly in scalability. While these two decoding methods have a lot in common - both being based on beam search and subsequent candidate reranking - their difference lies in the identification of slot mentions; SEA-GUIDE identifies them automatically during the decoding, utilizing the model's cross-attention weights at each step, as opposed to relying on string-matching rules post decoding, which need to be extended for any new domains.
|
| 256 |
+
|
| 257 |
+
Despite working conveniently out of the box, SEA-GUIDE does not come with a computational overhead caveat. Performing inference on a GPU, SEA-GUIDE is a mere 11-18% slower than beam search with slot aligner-based reranking, while we observed no performance difference on a CPU (see Appendix B.4 for a detailed analysis).
|
| 258 |
+
|
| 259 |
+
## 6.1 Limitations of SEA-GUIDE
|
| 260 |
+
|
| 261 |
+
SEA-GUIDE's ability to recognize slot errors is limited to missing and incorrect slot mentions, which are the most common mistakes we observed models to make on the data-to-text generation task. Duplicate slot mentions are hard to identify reliably because the decoder inherently pays attention to certain input tokens at multiple non-consecutive steps (such as in the example in Figure 1b). And arbitrary hallucinations are entirely beyond the scope of this method, as there is no reason to expect cross-attention to be involved in producing inputunrelated content, at least not in a foreseeable way.
|
| 262 |
+
|
| 263 |
+
As we see in example #4 in Table 7, Boolean slots occasionally give SEA-GUIDE a hard time, as the decoder appears not to be paying a great deal of attention to Boolean slots' values throughout the entire decoding in many cases. We plan to investigate if the performance can be improved for Boolean slots, perhaps by modifying the input format or finding a more subtle slot mention pattern.
|
| 264 |
+
|
| 265 |
+
## 7 Conclusion
|
| 266 |
+
|
| 267 |
+
We presented a novel decoding method, SEAGUIDE, that makes a better use of the crossattention component of the already complex and enormous pretrained generative LMs to achieve significantly higher semantic accuracy for data-to-text NLG, while preserving the otherwise high quality of the output text. It is an automatic method, exploiting information already present in the model, but in an interpretable way. SEA-GUIDE requires no training, annotation, data augmentation, or model modifications, and can thus be effortlessly used with different models and domains.
|
| 268 |
+
|
| 269 |
+
## Acknowledgements
|
| 270 |
+
|
| 271 |
+
We would like to thank the anonymous reviewers for their valuable feedback. This research was supported by NSF AI Institute Grant No. 1559735.
|
| 272 |
+
|
| 273 |
+
## References
|
| 274 |
+
|
| 275 |
+
- Shubham Agarwal, Marc Dymetman, and Eric Gaussier. 2018. Char2char generation with reranking for the e2e nlg challenge. In Proceedings of the 11th International Conference on Natural Language Generation , pages 451-456.
|
| 276 |
+
- Dzmitry Bahdanau, Kyunghyun Cho, and Yoshua Bengio. 2015. Neural machine translation by jointly learning to align and translate. ICLR .
|
| 277 |
+
- Ashutosh Baheti, Alan Ritter, Jiwei Li, and William B Dolan. 2018. Generating more interesting responses in neural conversation models with distributional constraints. In Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing , pages 3970-3980.
|
| 278 |
+
- Andrew Chisholm, Will Radford, and Ben Hachey. 2017. Learning to generate one-sentence biographies from wikidata. In Proceedings of the 15th Conference of the European Chapter of the Association for Computational Linguistics: Volume 1, Long Papers , pages 633-642.
|
| 279 |
+
- Kyunghyun Cho, Bart van Merri¨ enboer, C ¸ aglar G¨ ulc ¸ehre, Dzmitry Bahdanau, Fethi Bougares, Holger Schwenk, and Yoshua Bengio. 2014. Learning phrase representations using rnn encoder-decoder for statistical machine translation. In EMNLP .
|
| 280 |
+
- Ondˇ rej Duˇ sek and Filip Jurˇ c´ ıˇ cek. 2016. Sequence-tosequence generation for spoken dialogue via deep syntax trees and strings.
|
| 281 |
+
- Ondˇ rej Duˇ sek, Jekaterina Novikova, and Verena Rieser. 2018. Findings of the E2E NLG challenge. In Proceedings of the 11th International Conference on Natural Language Generation , pages 322-328, Tilburg University, The Netherlands. Association for Computational Linguistics.
|
| 282 |
+
- Mihail Eric, Rahul Goel, Shachi Paul, Abhishek Sethi, Sanchit Agarwal, Shuyang Gao, Adarsh Kumar, Anuj Goyal, Peter Ku, and Dilek Hakkani-Tur. 2020. Multiwoz 2.1: A consolidated multi-domain dialogue dataset with state corrections and state tracking baselines. In Proceedings of The 12th Language Resources and Evaluation Conference , pages 422428.
|
| 283 |
+
- Marjan Ghazvininejad, Xing Shi, Jay Priyadarshi, and Kevin Knight. 2017. Hafez: an interactive poetry generation system. In Proceedings of ACL 2017, System Demonstrations , pages 43-48.
|
| 284 |
+
- Hamza Harkous, Isabel Groves, and Amir Saffari. 2020. Have your text and use it too! end-to-end neural datato-text generation with semantic fidelity. In Proceedings of the 28th International Conference on Computational Linguistics , pages 2410-2424.
|
| 285 |
+
- Ari Holtzman, Jan Buys, Li Du, Maxwell Forbes, and Yejin Choi. 2019. The curious case of neural text degeneration. In International Conference on Learning Representations .
|
| 286 |
+
- Ari Holtzman, Jan Buys, Maxwell Forbes, Antoine Bosselut, David Golub, and Yejin Choi. 2018. Learning to write with cooperative discriminators. In Proceedings of the 56th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers) , pages 1638-1649.
|
| 287 |
+
- Juraj Juraska, Kevin Bowden, and Marilyn Walker. 2019. Viggo: A video game corpus for data-to-text generation in open-domain conversation. In Proceedings of the 12th International Conference on Natural Language Generation , pages 164-172.
|
| 288 |
+
- Juraj Juraska, Panagiotis Karagiannis, Kevin Bowden, and Marilyn Walker. 2018. A deep ensemble model with slot alignment for sequence-to-sequence natural language generation. In Proceedings of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long Papers) , pages 152-162.
|
| 289 |
+
- Mihir Kale and Abhinav Rastogi. 2020. Text-to-text pre-training for data-to-text tasks. In Proceedings of the 13th International Conference on Natural Language Generation , pages 97-102.
|
| 290 |
+
- Chris Kedzie and Kathleen McKeown. 2019. A good sample is hard to find: Noise injection sampling and self-training for neural language generation models. In Proceedings of the 12th International Conference on Natural Language Generation , pages 584-593, Tokyo, Japan. Association for Computational Linguistics.
|
| 291 |
+
- Chris Kedzie and Kathleen McKeown. 2020. Controllable meaning representation to text generation: Linearization and data augmentation strategies. In Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP) , pages 5160-5185.
|
| 292 |
+
- Alon Lavie and Abhaya Agarwal. 2007. Meteor: An automatic metric for mt evaluation with high levels of correlation with human judgments. In Proceedings of the Second Workshop on Statistical Machine Translation , pages 228-231. Association for Computational Linguistics.
|
| 293 |
+
- Mike Lewis, Yinhan Liu, Naman Goyal, Marjan Ghazvininejad, Abdelrahman Mohamed, Omer Levy, Veselin Stoyanov, and Luke Zettlemoyer. 2020. Bart: Denoising sequence-to-sequence pretraining for natural language generation, translation, and comprehension. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics , pages 7871-7880.
|
| 294 |
+
- Chin-Yew Lin. 2004. Rouge: A package for automatic evaluation of summaries. Text Summarization Branches Out .
|
| 295 |
+
- Minh-Thang Luong, Hieu Pham, and Christopher D Manning. 2015. Effective approaches to attentionbased neural machine translation. In Proceedings of
|
| 296 |
+
|
| 297 |
+
the 2015 Conference on Empirical Methods in Natural Language Processing , pages 1412-1421.
|
| 298 |
+
|
| 299 |
+
- Haitao Mi, Baskaran Sankaran, Zhiguo Wang, and Abe Ittycheriah. 2016. Coverage embedding models for neural machine translation. In Proceedings of the 2016 Conference on Empirical Methods in Natural Language Processing , pages 955-960.
|
| 300 |
+
- Feng Nie, Jin-Ge Yao, Jinpeng Wang, Rong Pan, and Chin-Yew Lin. 2019. A simple recipe towards reducing hallucination in neural surface realisation. In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics , pages 26732679.
|
| 301 |
+
- Jekaterina Novikova, Ondˇ rej Duˇ sek, and Verena Rieser. 2017. The e2e dataset: New challenges for end-toend generation. In Proceedings of the 18th Annual SIGdial Meeting on Discourse and Dialogue , pages 201-206.
|
| 302 |
+
- Kishore Papineni, Salim Roukos, Todd Ward, and WeiJing Zhu. 2002. Bleu: a method for automatic evaluation of machine translation. In ACL .
|
| 303 |
+
- Baolin Peng, Chenguang Zhu, Chunyuan Li, Xiujun Li, Jinchao Li, Michael Zeng, and Jianfeng Gao. 2020. Few-shot natural language generation for task-oriented dialog. In Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing: Findings , pages 172-182.
|
| 304 |
+
- Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, and Peter J Liu. 2020. Exploring the limits of transfer learning with a unified text-to-text transformer. Journal of Machine Learning Research , 21:1-67.
|
| 305 |
+
- Abigail See, Peter J. Liu, and Christopher D. Manning. 2017. Get to the point: Summarization with pointergenerator networks. In Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers) , pages 10731083, Vancouver, Canada. Association for Computational Linguistics.
|
| 306 |
+
- Sheng Shen, Daniel Fried, Jacob Andreas, and Dan Klein. 2019. Pragmatically informative text generation. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers) , pages 4060-4067.
|
| 307 |
+
- Xiaoyu Shen, Ernie Chang, Hui Su, Cheng Niu, and Dietrich Klakow. 2020. Neural data-to-text generation via jointly learning the segmentation and correspondence. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics , pages 7155-7165.
|
| 308 |
+
- Ilya Sutskever, Oriol Vinyals, and Quoc V. Le. 2014. Sequence to sequence learning with neural networks. In NIPS .
|
| 309 |
+
- Zhaopeng Tu, Zhengdong Lu, Yang Liu, Xiaohua Liu, and Hang Li. 2016. Modeling coverage for neural machine translation. In Proceedings of the 54th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers) , volume 1, pages 76-85.
|
| 310 |
+
- Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin. 2017. Attention is all you need. In Proceedings of the 31st International Conference on Neural Information Processing Systems , pages 6000-6010. Curran Associates Inc.
|
| 311 |
+
- Ramakrishna Vedantam, C Lawrence Zitnick, and Devi Parikh. 2015. Cider: Consensus-based image description evaluation. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 4566-4575.
|
| 312 |
+
- Tsung-Hsien Wen, Milica Gaˇ si´ c, Dongho Kim, Nikola Mrkˇ si´ c, Pei hao Su, David Vandyke, and Steve Young. 2015a. Stochastic language generation in dialogue using recurrent neural networks with convolutional sentence reranking. In SIGDIAL Conference .
|
| 313 |
+
- Tsung-Hsien Wen, Milica Gaˇ si´ c, Nikola Mrkˇ si´ c, PeiHao Su, David Vandyke, and Steve Young. 2015b. Semantically conditioned lstm-based natural language generation for spoken dialogue systems. In EMNLP .
|
| 314 |
+
|
| 315 |
+
Table 8: Overview of the dataset partitions.
|
| 316 |
+
|
| 317 |
+
| Training Validation Test ViGGO 5,103 714 1,083 E2E 42,063 4,672 4,693 MultiWOZ 55,951 7,286 7,293 |
|
| 318 |
+
|-------------------------------------------------------------------------------------------------------------------|
|
| 319 |
+
|
| 320 |
+
## A Appendix
|
| 321 |
+
|
| 322 |
+
## A.1 Additional Dataset Details
|
| 323 |
+
|
| 324 |
+
Table 8 shows the number of examples in the training, validation and test partitions of all the datasets used in the evaluation of the SEA-GUIDE method.
|
| 325 |
+
|
| 326 |
+
## A.2 Data Preprocessing
|
| 327 |
+
|
| 328 |
+
When preprocessing input meaning representations (MRs) before training a model or running inference, we first parse the dialogue act (DA) types, if present, and all slots and their values from the dataset-specific format into an intermediate list of slot-and-value pairs, keeping the original order. Although typically indicated in the MR differently from slots, we treat the DA type as any other slot (with the value being the DA type itself, and assigning it the name 'intent').
|
| 329 |
+
|
| 330 |
+
Next, we rename any slots that do not have a natural-language name (e.g., 'priceRange' to 'price range', or 'has mac release' to 'has Mac release'). Slot values are left untouched. We do this to take advantage of pretrained language models' ability to model the context when the input contains familiar words, as opposed to feeding it code names with underscores and no spaces.
|
| 331 |
+
|
| 332 |
+
Finally, we convert the updated intermediate list of slots and their values to a string. The ' | ' symbol is used for separating slot-and-value pairs from each other, while the '=' is used within each pair to separate the value from the slot name. The result for an MR from ViGGO can look as follows:
|
| 333 |
+
|
| 334 |
+
```
|
| 335 |
+
intent = request explanation | rating = poor | genres = vehicular combat | player perspective = third person
|
| 336 |
+
```
|
| 337 |
+
|
| 338 |
+
## A.3 Model and Training Parameters
|
| 339 |
+
|
| 340 |
+
The pretrained models that we fine-tuned for our experiments are the PyTorch implementations in the Hugging Face's Transformers 5 package. The models' sizes are indicated in Table 9.
|
| 341 |
+
|
| 342 |
+
We trained all models using a single Nvidia RTX 2070 GPU with 8 GB of memory and CUDA ver- sion 10.2. The training parameters too are summarized in Table 9. For all models, we used the AdamW optimizer with a linear decay after 100 warm-up steps. The maximum sequence length for both training and inference was set to 128 for ViGGO and E2E, and 160 for MultiWOZ.
|
| 343 |
+
|
| 344 |
+
5 https://huggingface.co/transformers/
|
| 345 |
+
|
| 346 |
+
Table 9: Overview of the model specifications.
|
| 347 |
+
|
| 348 |
+
| Layers Heads Hidden state size Total pa- rameters T5-small 6+6 8 512 ≈ 60M BART-base 6+6 12 768 ≈ 139M T5-base 12+12 12 768 ≈ 220M BART-large 12+12 16 1024 ≈ 406M |
|
| 349 |
+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 350 |
+
|
| 351 |
+
Table 10: Overview of the training parameters used in our experiments. Batch size and the number of epochs are indicated per dataset (ViGGO/E2E/MultiWOZ).
|
| 352 |
+
|
| 353 |
+
| Batch size Learning rate Epochs T5-small 32/64/64 2 × 10 - 4 20/20/30 BART-base 32/32/32 1 × 10 - 5 20/20/25 T5-base 16/16/ - 3 × 10 - 5 20/20/ - BART-large 16/ - / - 4 × 10 - 6 20/ - / - |
|
| 354 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 355 |
+
|
| 356 |
+
## A.4 Evaluation Metric Calculation
|
| 357 |
+
|
| 358 |
+
The four non-SER automatic metrics that we report in our results (i.e., BLEU, METEOR, ROUGE-L, and CIDEr) are calculated using the E2E evaluation script 6 developed for the E2E NLG Challenge (Duˇ sek et al., 2018). We also verified that the single-reference BLEU score calculation in the E2E script corresponds to that in the SacreBLEU 7 Python package. As a result, BLEU scores calculated either way are directly comparable.
|
| 359 |
+
|
| 360 |
+
To ensure a fair comparison with the MultiWOZ baselines (Peng et al., 2020; Kale and Rastogi, 2020), we additionally report BLEU scores calculated using the RNNLG evaluation script 8 , which their respective authors used in their own evaluation. We denote it BLEUR in our result tables. Moreover, Kale and Rastogi (2020) calculated SER on utterance level, rather than slot level, and that using exact slot value matching in the utterance. We thus wrote a script to also perform this type of naive SER evaluation, in addition to our slot aligner-based SER evaluation. We report its results as SERE.
|
| 361 |
+
|
| 362 |
+
6 https://github.com/tuetschek/e2e-metrics
|
| 363 |
+
|
| 364 |
+
7 https://pypi.org/project/sacrebleu/
|
| 365 |
+
|
| 366 |
+
8 https://github.com/shawnwun/RNNLG/
|
| 367 |
+
|
| 368 |
+
## B Additional SEA-GUIDE Evaluation
|
| 369 |
+
|
| 370 |
+
## B.1 Slot Mention Tracking Details
|
| 371 |
+
|
| 372 |
+
In order to be able to take advantage of the attention weight distribution patterns, the decoder needs to be aware of which input token span corresponds to which slot. To this end, we parse the input MRs on-the-fly - which is trivial given the structured nature of MRs - as each batch is being prepared for inference, and create a list of slot spans for each MR in the batch. 9 In fact, we indicate the spans for slot names and slot values separately, and for list-values down to individual list elements, for a higher specificity. Since Boolean slot mentions are tracked by their name rather than value, we also indicate for each slot whether it is Boolean or not. This information can be provided explicitly to the data loader, otherwise it is automatically inferred from the dataset's ontology based on all the possible values for each slot.
|
| 373 |
+
|
| 374 |
+
Note that, although our data preprocessing converts DA type indications in the MRs to the same format as slots (see any of the left columns in Figure 1), we exclude them from the slot-span lists, as they are not actual content slots to be tracked. Separator tokens (such as ' | ' or '=') present in the preprocessed MR are not included in the spans, and are, as a result, ignored during the slot mention tracking.
|
| 375 |
+
|
| 376 |
+
## B.2 Parameter Tuning for T5
|
| 377 |
+
|
| 378 |
+
When optimizing the mention-tracking components' parameters for T5-small, we observe similar trends as with BART-base (see Figure 5). One difference is that enabling the 2 nd component not only significantly increases the BLEU score, but also lowers the SER, while the 3 rd component appears to only have a negligible effect (see Figure 5a).
|
| 379 |
+
|
| 380 |
+
## B.3 Effects of Beam Size on E2E
|
| 381 |
+
|
| 382 |
+
On the E2E dataset, decoding using SEA-GUIDE is even more effective in reducing SER than on ViGGO. Across all beam sizes, its performance is comparable to beam search with slot aligner reranking, and there is also only a limited gain from increasing the beam size to 20 (see Figure 6).
|
| 383 |
+
|
| 384 |
+
It is worth noting that, using beam search with no reranking, the SER dramatically increases with the increasing beam size. This is likely caused by the relatively heavy semantic noise in the E2E
|
| 385 |
+
|
| 386 |
+
9 This is done on token level, and the result varies thus from model to model depending on its tokenizer.
|
| 387 |
+
|
| 388 |
+
<!-- image -->
|
| 389 |
+
|
| 390 |
+
(a) Threshold optimization for the 1 st component (verbatim mentions), with the other components enabled or disabled. When enabled, the 2 nd component's threshold was fixed at 0 . 3 , and that of the 3 rd at 0 . 1 . Note that the threshold of 1 . 0 is equivalent to the 1 st component being disabled, as attention weights are in the [0 . 0 , 1 . 0] range.
|
| 391 |
+
|
| 392 |
+
(b) Threshold optimization for the 2 nd component (paraphrased mentions), with the 1 st component's threshold of 0 . 2 , 0 . 5 and 0 . 8 , and that of the 3 rd component fixed at 0 . 1 .
|
| 393 |
+
|
| 394 |
+
<!-- image -->
|
| 395 |
+
|
| 396 |
+
(c) Threshold optimization for the 3 rd component (unrealized mentions), with the 2 nd component's threshold of 0 . 2 , 0 . 3 and 0 . 4 , and that of the 1 st component fixed at 0 . 5 .
|
| 397 |
+
|
| 398 |
+
<!-- image -->
|
| 399 |
+
|
| 400 |
+
Figure 5: Effects of different parameter configurations of the 3 mention-tracking components on SER and BLEU of utterances generated by T5-small fine-tuned on ViGGO.
|
| 401 |
+
|
| 402 |
+
Figure 6: The effect of different beam size on the SER using different reranking methods on the E2E dataset. With greedy search decoding, the SER is 1 . 60% and 1 . 97% for T5 and BART, respectively.
|
| 403 |
+
|
| 404 |
+
<!-- image -->
|
| 405 |
+
|
| 406 |
+
training set, resulting in more slot errors in the generated utterances the less greedy the decoding is. Some form of semantic guidance is thus all the more important for the model in this scenario.
|
| 407 |
+
|
| 408 |
+
## B.4 Inference Performance
|
| 409 |
+
|
| 410 |
+
In order to assess the computational overhead the SEA-GUIDE method introduces during inference, we measure the inference runtime of the T5-small model fine-tuned on ViGGO. For all beam searchbased methods (including SEA-GUIDE), the beam size was set to 10 , and early stopping was enabled.
|
| 411 |
+
|
| 412 |
+
The results in Figure 7a show a distinct but expected overhead across all batch sizes when running inference on a GPU. The overall increase in runtime is 11-18% over beam search with slot aligner-based reranking, which is the method computationally most similar to SEA-GUIDE, as it too involves reranking on top of beam search. The slot aligner-based reranking itself adds a constant amount of 16 seconds on top of simple beam search, which corresponds to an 11-40% increase for the range of batch sizes in the plot.
|
| 413 |
+
|
| 414 |
+
When performing the same inference on a CPU, on the other hand, the overhead SEA-GUIDE introduces to beam search is no greater than that of the slot aligner-based reranking (see Figure 7b). This suggests that further optimization of SEA-GUIDE for GPU, especially by minimizing the communication between the GPU and the CPU during the decoding, could bring the overhead of SEA-GUIDE inference on a GPU down to the same level as that of the slot aligner-based reranking.
|
| 415 |
+
|
| 416 |
+
Considering the large improvement in semantic accuracy the SEA-GUIDE method delivers in the tested models, we deem the observed computational overhead reasonable and acceptable.
|
| 417 |
+
|
| 418 |
+
<!-- image -->
|
| 419 |
+
|
| 420 |
+
(a) Inference using a GPU (RTX 2070 with 8 GB of memory).
|
| 421 |
+
|
| 422 |
+
<!-- image -->
|
| 423 |
+
|
| 424 |
+
- (b) Inference using a CPU (8-core Ryzen 7 2700X with 32 GB of RAM).
|
| 425 |
+
|
| 426 |
+
Figure 7: Runtime of T5-small performing inference on the ViGGO test set using different decoding methods and batch sizes. 'No reranking' stands for simple beam search, while 'Slot aligner' denotes beam search with slot aligner-based reranking. Model and data loading is excluded from the runtimes.
|
| 427 |
+
|
| 428 |
+
## C Slot Aligner Details
|
| 429 |
+
|
| 430 |
+
For the purposes of the slot aligner, we classified slots into five general categories ( Boolean , numeric , scalar , categorical , and list ), covering the most common types of information MRs typically convey in data-to-text NLG. Each of these categories has its own method for extracting a slot mention from an utterance, generalized enough to be applicable across all slots in the category. This design allows for a straightforward extension of the slot aligner to a new domain, as it merely needs to be indicated which of the five categories each of the slots in the new domain belongs to. Optionally, it can be provided a simple dictionary of common alternatives for specific slot values, which tends to increase the slot aligner's performance.
|
| 431 |
+
|
| 432 |
+
Although a decreased matching accuracy - es- pecially for rare slot realizations - is a trade-off for the scalable design, the slot aligner's typical application are generated model outputs, which get evaluated for semantic errors. There the slot aligner is not likely to encounter rare slot realizations frequently, if at all, due to the generalizing properties of neural NLG models. The rapid adaptability of the slot aligner to a new domain, on the other hand, is a very valuable feature.
|
| 433 |
+
|
| 434 |
+
## C.1 Boolean Slots
|
| 435 |
+
|
| 436 |
+
Boolean slots take on binary values, such as 'yes'/'no' or 'true'/'false'. Their realization in an utterance thus typically does not contain the actual value of the slot, but instead a mention of the slot name (e.g., 'is a family-friendly restaurant' for FAMILYFRIENDLY[yes], or 'not supported on Mac' for HAS MAC RELEASE[no]). Therefore, extracting a Boolean slot mention boils down to the following two steps: (1) finding a word or a phrase representing the slot, and (2) verifying whether the representation is associated with a negation or not.
|
| 437 |
+
|
| 438 |
+
The first step is straightforward, and only requires a list of possible realizations for each Boolean slot. This list rarely contains more than one element, which is the 'stem' of the slot's name (e.g., 'linux' for 'HAS LINUX RELEASE'). It can thus be populated trivially for most of the new Boolean slots. And if a Boolean slot can have multiple equivalent realizations (such as 'child friendly' or 'where kids are welcome' for the slot FAMILYFRIENDLY), they are typically not numerous and can be listed manually. Having a list of stems (we refer to all the equivalent realizations of a slot collectively as 'slot stems'), the utterance is scanned for the presence of each of them in it. If one is found, we go to the second step. A slot mention is decided to be negative if a negation cue is found to be modifying the slot stem in the utterance, and without a contrastive cue in between. It is decided to be positive if no negation cue is present within a certain distance of the stem, or there is a contrastive cue in between (see examples in Table 11).
|
| 439 |
+
|
| 440 |
+
## C.2 Numeric Slots
|
| 441 |
+
|
| 442 |
+
Slots whose value is just a number (such as RELEASE YEAR in ViGGO, or CHOICE in MultiWOZ) are in general not handled in any special way, and the value is simply matched directly in the utterance. However, there are certain numeric slot types that benefit from additional preprocessing: (1) those with a unit, and (2) years. When a nu-
|
| 443 |
+
|
| 444 |
+
- #1 There's no Linux release or multiplayer, but there is Mac support.
|
| 445 |
+
- #2 Though it's not available on Linux, it does have a Mac release as well.
|
| 446 |
+
- #3 It is available on PC and Mac but not Linux, and it can be found on Steam.
|
| 447 |
+
|
| 448 |
+
Table 11: Examples of contrastive phrases involving Boolean slots. Underlined are the stems of the Boolean slots for which the polarity is questioned. Note that in all 3 examples the mention is positive, despite the presence of contrast and negation distractors.
|
| 449 |
+
|
| 450 |
+
| CUSTOMER RATING (E2E) RATING (ViGGO) Alternative expressions low poor bad, lacking, negative,. . . average average decent, mediocre, okay,. . . - good fun, positive, solid,. . . high excellent amazing, fantastic, great,. . . |
|
| 451 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 452 |
+
|
| 453 |
+
Table 12: An example of value mapping between two similar scalar slots in the restaurant and video game domains.
|
| 454 |
+
|
| 455 |
+
meric slot represents a year, the slot aligner generates the common abbreviated alternatives for the year (e.g., ''97' for the value '1997') that it tries to match in case the original value is not found in the utterance.
|
| 456 |
+
|
| 457 |
+
## C.3 Scalar Slots
|
| 458 |
+
|
| 459 |
+
Similarly to Boolean slot aligning, scalar slot aligning consist of two steps. The first one is the same, i.e., finding a word or a phrase representing the slot (which we refer to as 'stem' in this case too, in order to maintain consistency). In the second step, however, the slot aligner looks for the slot's value, or its equivalent, occurring within a reasonable distance from the slot stem. The optional soft alignment mode skips the second step as long as a slot stem is matched in the first step.
|
| 460 |
+
|
| 461 |
+
We assume that scalar slots, even across different domains, will often have values that can be mapped to each other, as long as they are on the same or a similar scale (see Table 12). For each scalar slot, the slot aligner refers to a corresponding dictionary for possible alternative expressions of its value. With the above assumption, it is sufficient to have one dictionary per scale, or type of scale, which can be reused for similar scalar slots in different domains. The dictionaries can be quickly populated with synonyms of the values of a given scale (see the last column in the table), and thus do not necessarily require manual additions every time the system is used with a new domain. Some alternative expressions might be suitable for scalar slots in some domains better than others, but that will not be an issue in most cases, since, being synonymous, they are not likely to cause conflicts, and the slot aligner will simply not encounter certain alternative expressions in certain domains.
|
| 462 |
+
|
| 463 |
+
## C.4 Categorical Slots
|
| 464 |
+
|
| 465 |
+
Categorical slots can take on virtually any value. Nevertheless, for each such slot the values typically come from a limited, although possibly large, set of values. For instance, in the E2E dataset, the FOOD slot has 7 possible values, such as 'Italian' and 'Fast food', but technically it could take on hundreds of different values representing all of the cuisines of the world. Some values can be singleword, while others can have multiple words (e.g., 'restaurant' and 'coffee shop' as possible values for the EATTYPE slot). Due to this huge variety in possible values of categorical slots, the aligning methods need to remain very general.
|
| 466 |
+
|
| 467 |
+
Besides exact matching of the value in the utterance, the slot aligner can be instructed to perform the matching in three additional modes, besides exact, increasing its robustness while maintaining scalability. The four modes of aligning the slot with its mention work as follows:
|
| 468 |
+
|
| 469 |
+
- Exact - slot mention is identified only if it matches (case-insensitive) the slot value verbatim;
|
| 470 |
+
- All words - slot mention is identified if each of the value's tokens is found in the utterance, though they can be in an arbitrary order and they can be separated by other words;
|
| 471 |
+
- Any word -slot mention is identified by matching any of the value's tokens in the utterance;
|
| 472 |
+
- First word -slot mention is identified by matching just the value's first token in the utterance.
|
| 473 |
+
|
| 474 |
+
Note that for single-word values all four modes give the same result. The three non-exact modes offer different approaches to soft alignment for categorical slots. The choice may depend on the particular slot, and the mode can thus be specified for each slot separately, while by default the slot aligner operates in the exact-matching mode.
|
| 475 |
+
|
| 476 |
+
## MR
|
| 477 |
+
|
| 478 |
+
inform (NAME [ BioShock ], DEVELOPER [ 2K Boston ], GENRES [ action-adventure, role-playing, shooter ], HAS MULTIPLAYER [ no ], PLATFORMS [ PlayStation, Xbox, PC ], HAS LINUX RELEASE [ no ], HAS MAC RELEASE [ yes ])
|
| 479 |
+
|
| 480 |
+
## Reference utterance
|
| 481 |
+
|
| 482 |
+
Developed by 2K Boston , BioShock is a single-player shooter game that will have you role-playing through a well constructed action-adventure narrative. It is available for PlayStation , Xbox , Mac and PC , but is not available for Linux .
|
| 483 |
+
|
| 484 |
+
## Slot alignment
|
| 485 |
+
|
| 486 |
+
( 13: DEVELOPER) ( 25: NAME) ( 39: HAS MULTIPLAYER) ( 53: GENRES) ( 174: PLATFORMS) ( 191: HAS MAC RE- LEASE) ( 228: HAS LINUX RELEASE)
|
| 487 |
+
|
| 488 |
+
Table 13: An example from ViGGO that involves list slots. Notice how the individual value item mentions can be scattered across an entire sentence in a natural way. The bottom section indicates the slot mention positions determined by the slot aligner, given as the number of characters from the beginning of the utterance.
|
| 489 |
+
|
| 490 |
+
Similarly to Boolean and scalar slots, the slot aligner can search for alternative expressions of a value, if provided in the corresponding dictionary. The alternative matching is, however, more flexible here, as the alternatives in the dictionary can be multi-part, in which case the slot aligner tries to match all the parts (words/tokens/phrases) provided in the form of a list.
|
| 491 |
+
|
| 492 |
+
## C.5 List Slots
|
| 493 |
+
|
| 494 |
+
A list slot is similar to a categorical slot, the only difference being that it can have multiple individual items in its value. Two instances of a list slot, namely GENRES and PLATFORMS, can be seen in the example from the ViGGO dataset in Table 13.
|
| 495 |
+
|
| 496 |
+
The aligning procedure for list slots thus heavily relies on that of categorical slots. In order to align a list slot with the corresponding utterance, the slot aligner first parses the individual items in the slot's value. It then iterates over all of them and performs the categorical slot alignment, as described in the previous section, with each individual item. Considering the items can be scattered over multiple sentences, the slot aligner considers the position of the leftmost mention of an item as the position of the corresponding list slot.
|
text-versions/attention-markdown/2110.03183_Attention is All You Need Good Embedding.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2110.03183 Attention Is All You Need Good Embedding
|
| 2 |
+
|
| 3 |
+
## Attention is All You Need? Good Embeddings with Statistics are Enough: Large Scale Audio Understanding without Transformers/ Convolutions/ BERTs/ Mixers/ Attention/ RNNs or ....
|
| 4 |
+
|
| 5 |
+
Prateek Verma
|
| 6 |
+
|
| 7 |
+
Abstract -This paper presents a way of doing large-scale audio understanding without traditional state-of-the-art neural architectures. Ever since the introduction of deep learning for understanding audio signals in the past decade, convolutional architectures have been able to achieve state-of-the-art results surpassing traditional hand-crafted features. In the recent past, there has been a similar shift away from traditional convolutional and recurrent neural networks towards purely end-toend Transformer architectures. We, in this work, explore an approach, based on the Bag-of-Words model. Our approach does not have any convolutions, recurrence, attention, transformers, or other approaches such as BERT. We showcase an approach going against the mainstream research at the moment. We utilize micro and macro-level clustered vanilla embeddings and use an MLP head for classification. We only use feed-forward encoderdecoder models to get the bottlenecks of spectral envelops, spectral patches, and slices as well as multi-resolution spectra. A classification head (a feed-forward layer), similar to the approach in SimCLR is trained on a learned representation. Using simple codes learned on them, we show how we surpass traditional convolutional neural network architectures, and come strikingly close to outperforming powerful Transformer architectures. Our approach could have been carried out back in 2006, using the vanilla autoencoder and dimension reduction architectures, as proposed by Hinton et. al. [1]. We show that just by using this architecture, and doing simple statistics on the latent representations, we could have outperformed state of the art architectures audio understanding, like convolutional and recurrent architecture as late as 2018 [2]. This goal of this work is, hopefully to would pave way for exciting advancements in the field of representation learning without massive, end-to-end neural architectures.
|
| 8 |
+
|
| 9 |
+
Index Terms -representation learning, audio understanding, multi-scale representations, attention, clustering, bag-of-words, envelop codes, fully connected networks.
|
| 10 |
+
|
| 11 |
+
## I. INTRODUCTION
|
| 12 |
+
|
| 13 |
+
Audio understanding is a widely studied problem in domains such as signal processing, machine learning, and perception. It is to teach computers to hear as humans do, and the goal is to help develop a human-level perception in machines. With the advancement in machine learning, there has been rapid progress in making these systems reach almost humanlevel performance. For this paper, we would pose the problem as that of understanding the categories of sound present in an input signal. CNN architectures have become a standard way of learning these mappings, as shown in [3], [4], [5]. Further, with the recent success of Transformer architectures in computer vision [6], [7], [8], NLP [9], [10], [11] and audio [12], [13], [14], there has been a pivot recently on improvements on the core architecture, and adapting it for acoustic scene understanding [15]. There have been in the past approaches inspired by natural language processing such as computing a bag-of-words model [16] on features such as MFCC [17] yielding surprising strong results. We in this work take inspiration from the traditional bag-of-words model along with the powerfulness of neural net models, taking in some ways the best of two worlds. The current work is also based on the idea of learning codebook and doing some statistics on these learned code words as shown in [18], [19], [20]. In problems such as unsupervised learning/oneshot learning [21], the goal is to learn a latent representation for an input signal and use this latent representation for a variety of applications using a classification head [22], [23], [8]. Audio embeddings have been powerful to aid in a variety of applications such as speech recognition and audio understanding [24], [25], [26], conditional audio synthesis [26], [27] as well as transformation [28], [29]. This work also devises a way of coming up with a latent vector summarizing the contents of the audio signal and then using a classification head similar to [22], [23] for classification purposes. This work also draws inspiration from the idea of learning a mapping from a signal of interest to a clustered latent space as shown in [30], [31], [32]. Unlike their work which utilized UMAP [33] or vanilla latent representations, we use coded book statistics as a representation of input mel-spectrogram. There have been approaches over discrete code words for representation learning such as [34], which trained a BERT over clustered image representations.
|
| 14 |
+
|
| 15 |
+
This work has been submitted to the IEEE for possible publication. Copyright may be transferred without notice, after which this version may no longer be accessible; Submitted for review on 22 Jan 2022.
|
| 16 |
+
|
| 17 |
+
Prateek Verma is a Research Assistant with Stanford University, 450 Jane Stanford Way, Stanford CA 94305 (email: prateekv@stanford.edu).
|
| 18 |
+
|
| 19 |
+
The contributions of the paper are as follows: i) We propose a framework purely based on learned embedding and statistics based on it and achieve significant performance as compared to traditional convolutional and transformer architectures. We achieve this without having any convolutional, transformer,
|
| 20 |
+
|
| 21 |
+
1
|
| 22 |
+
|
| 23 |
+
Fig. 1. Figure capturing our proposed method and learning different codes for different representations of mel-spectogram. We divide up the audio spectrogram into 4 types of patches, namely frequency band envelop, spectral patches, spectral envelop, as well as overall coarse downsampled spectra. The manner in which we patch-up the spectrogram is as shown. We extract bottleneck latent representation for each of the type of patches, by training vanilla autoencoders. These features are individually clustered into D clusters using k-means algorithm. Finally to extract a feature vector for the input spectrogram, we use count statistics for each type of cluter present for the patches. We concatenate each of the four code word statistics to yield the final feature vector. The total sum of the count in the 4 ∗ D feture vector is equal to the total number of different types of patches present (similar to how a bag-of-words model has the total number of words over dictionary elements as the sum in the feature vector [35]). On these 4 ∗ D dimensional vectors a typical train/val/test experiment is carried out and the results are reported. In order to be fair with comparison no data augmentation was carried out, and the setup was similar to [2], [12].
|
| 24 |
+
|
| 25 |
+
<!-- image -->
|
| 26 |
+
|
| 27 |
+
mixer, attention, or recurrent blocks. ii) We compute statistics (bag-of-words [17]) over dictionary learned over various latent representations of mel-spectrogram from vanilla autoencoders. We capture various facets of audio signals, and learn a concatenated dictionary of spectral patches, spectral envelop, frequency band envelops, and overall statistics. iii) We show how we can improve the performance of our model by randomly masking the input signal, making them robust by drawing inspiration from approaches such as BERT [36].
|
| 28 |
+
|
| 29 |
+
## II. DATASET
|
| 30 |
+
|
| 31 |
+
For evaluation of our approach, we use Free-Sound 50K dataset [2] instead of widely used AudioSet [37]. It is an open dataset having over 100 hours of manually labeled samples drawn from the AudioSet ontology of 200 classes. This was done, as the audio samples are available as opposed to YouTube links, and the readers are advised to read [2] for advantages of it over AudioSet [37]. For the sake of this paper, we choose to report the results only on [2] and expect similar results to hold true on other datasets. This is shown in [37] how neural architectures having similar gains on AudioSet and FSD50K. One of the significant advantages is that it contains twice the same number of training examples in the balanced setup as AudioSet. We used the training, validation, and test split as given. The dataset has in total of about 51,197 clips. We have down-sampled all the clips to be of 16kHz. We may also mention that we have been consistent in the training and the validation setup while reporting the mean-average precision (mAP) scores as reported in [2]. Training with a longer context will result in improved performance as well as augmentation etc., and the goal is to have a fair comparison of architectures in similar setup. The training was done on 1s of audio to predict one/mutiple categories of sound out of 200, with the label of the clip assigned to all of the 1s patches in case the clip is longer. Once the model is trained, the mAP scores are reported at clip level, with the probability scores averaged on 1s chunks to predict the contents (possible classes out of 200). Thus we can compare our performance with the baseline convolutional (DenseNet, Res-Net, VGGish) [2] and Transformer architectures [12].
|
| 32 |
+
|
| 33 |
+
## III. METHODOLOGY
|
| 34 |
+
|
| 35 |
+
This section describes the methodology of how we obtained a feature vector from a mel-spectrogram input. Briefly, for every input representation, the system learns a latent representation by fully-connected vanilla auto-encoders with varying degrees of compression factor F . Once we obtain these latent features, we cluster them according to a fixed number of dictionary elements having the vocabulary D (equal to the number of clusters from k-means), assigning each input latent representation a discrete value from 0 to D -1 , according to the cluster to which it belongs. We obtain overall statistics of the counts of each of the dictionary elements similar to a bag-of-words (BOW) model. Multiple representations are concatenated, to obtain a final feature code of size 4 ∗ D , which is used to train a MLP head (instead of spectrograms) in a typical training/val/test setup (similar to [22]).
|
| 36 |
+
|
| 37 |
+
## A. Learning Latent Representations
|
| 38 |
+
|
| 39 |
+
We choose to work with mel-spectrogram input having a total of 96 bins encompassing a total range from 0 to 8kHz, as our input signals are 16 kHz. We choose a hop size of 10ms, with a window of 30ms with FFT size to be 2048, with a hanning window. For learning a latent representation for a given input, we deploy a three-layer MLP encoder with a bottleneck layer of size to be reduced by a factor of F from the input dimension. For this paper, we experiment with compression factor F = 10 and F = 20 . This bottleneck is then again passed onto a 3 layer MLP decoder to reconstruct back the same input. We used mean-square error criteria for training this auto-encoder block, with 2048 neurons of encoder and decoder with a dropout factor of 0.5. We call different encoder representations learned at a particular compression factor F , to be e pat F , e env F , e fenv F , e o F for an encoding learned for a spectral patch, spectral envelop, frequency band energy across time, and scaled down-sampled mel-spectra.
|
| 40 |
+
|
| 41 |
+
- 1) Representation of Spectral Patches: To extract embeddings from spectral patches, we draw inspiration from recent works in audio/vision Transformer [12], [6]. We take patches of size 8 frequency bins along the frequency axis, with 10 bins along time, across the mel-spectrogram which has input dimensions of 96 x 100 for each of the 1s inputs. We divide the input spectrogram equally as shown in Fig.1. For all of the training data, auto-encoders are trained on these patches, to obtain a patch level embedding e pat F . This captures the local variations present in an input mel-spectrogram. By dividing the 1s spectrogram in a grid form, we obtain 120 patch level embeddings (96*100 /(8*10)) from the 120 patches.
|
| 42 |
+
- 2) Representation of Frequency Band Envelop: We take patches of 8 mel-bins across time to model energy modulations at different frequency bands across time. This captures variations/behavior of energy in a frequency band across time. For a spectrogram, 12 such patches are obtained by equally dividing the frequency axis. These have the input dimension of 8 x 100 and obtain a bottleneck feature e fenv F as shown in Fig. 1. We thus obtain a total of 12 input bottleneck features for a given 1s spectrogram input.
|
| 43 |
+
- 3) Representation of Spectral Envelop: Similar to frequency band envelope, we learn embeddings to characteristics of spectral envelope across time. For this we take patches across 100ms encompassing the entire frequency spread of 96 mel-bins, thus having the dimension of 96 x 10. Again these patches are chosen sequentially and we obtain a bottleneck feature e env F . We get a total of 10 bottleneck vectors for any given input spectra.
|
| 44 |
+
|
| 45 |
+
4) Representation of the Whole Spectogram: Finally, given an input mel-spectrogram, we obtain its global characteristics. This is done by down-sampling and resizing the input spectrogram from 96x100 to 8x10, done by using bi-cubic interpolation. This is mainly done to capture at a very coarse level how the spectrogram 'looks'. We again follow a similar recipe of obtaining a bottleneck feature and call it e o F . We obtain only 1 bottleneck vector for every input spectra. Thus, in total, we obtain 143 latent vectors, (120+12+10+1) that describe the input spectrogram at various levels.
|
| 46 |
+
|
| 47 |
+
## B. Clustering, Code Book Generation, & Embeddings
|
| 48 |
+
|
| 49 |
+
For each family of the bottleneck features obtained, we do k-means clustering with the number of clusters fixed as D, which is a hyper-parameter. This can be easily implemented using popularly available libraries e.g. sklearn. For any given spectrogram, the goal is to obtain a discrete feature representation that can capture all of the features that we have explained above. Given any input spectra, we first obtain a total of 143 latent codes as described above at a chosen bottleneck factor F . These embeddings are clustered using k-means separately using each of the families to which they belong, i.e. we cluster i th entry in each of the embedding families, e o F ( i ) separately from e env F ( i ) . For each of the learned k-means mapping, we obtain a feature vector f of dimension D , similar to a bagof-words representation i.e. each feature vector contains the counts of how many times the embeddings fall into the bucket of the cluster centroids. Thus we obtain a D dimension vector for each of the four categories mentioned thus obtaining, f o F , f env F , f fenv F and f pat F . Each of these features f contains counts of how often the code-word of embedding from the audio spectrogram is present in a given 1s input. As expected the sum of the feature vector would be 143 equal to the total number of embeddings we have from the four families of features. This is now our representative feature vector for input instead of a spectrogram.
|
| 50 |
+
|
| 51 |
+
## C. Classification Setup & Input Code Masking
|
| 52 |
+
|
| 53 |
+
We concatenate all of the feature vectors f o F , f env F , f fenv F and f pat F to obtain a feature vector F v for a particular input spectrogram. This is a 4 ∗ D dimensional input and is used along with the label present in the dataset. As proposed in work by [22], we employ just MLP classification heads. Since we have a multi-label classification problem, use sigmoid as our final activation function, with Huber loss as our error criterion to minimize between the actual and the predicted samples, with Adam optimizer [38]. We improve the robustness further by randomly masking input features by a chosen probability p . This is as simple as replacing the actual count of the feature vector by 0 to remove the contribution of a code-book index. This makes our predictions more robust to outliers and as we will see improves the performance of our models. All of the training was carried out using Tensorflow framework [39].
|
| 54 |
+
|
| 55 |
+
## IV. RESULTS
|
| 56 |
+
|
| 57 |
+
Given a feature vector F v of dimension equal to 4*dimension of the number of codewords chosen D , we have as our input of dimension F v = 4 ∗ D . As described in the previous section F v is the concatenation of individual feature vectors obtained from all of the four features. We deploy the same strategy as what was proposed for classification head given a feature vector F v in [22]. We experiment with several combinations of hyper-parameters namely the size of the feed-forward classification head with the given labels for audio of dimension 200 with 1/0 indicating presence/absence of the category i.e. small namely 2-layer 256 dimensional fully connected architecture and large namely 2-layer 4096 dimensional model. Note that [22] used a 2-layer 2048 neuron MLP architecture. This was carried out for all 4 different sizes of code-book D : 16, 64, 256, 1024. For all of the proposed models as described above, we tweak the dropout rate [40] as a form of regularization with 0 . 1 and 0 . 4 . The results are shown in the Figure 2. We see from the plot, the best mAP
|
| 58 |
+
|
| 59 |
+
Fig. 2. mAP on the validation set of FSD 50K. For each dim D code book, MLP head w.r.t dropout rate and the number of neurons in each layer for F =10 is shown. We achieve the best value of 0.35 vs 0.39 of a Transformer architecture in [12]. A compression factor of 20 was consistently underperformed the factor 10 and is not shown here for clarity.
|
| 60 |
+
|
| 61 |
+
<!-- image -->
|
| 62 |
+
|
| 63 |
+
score is for learned 256 code words, with the classification head having 512 neurons in each layer with a dropout rate of 0.4 and a compression factor of 10. A compression factor of 20 was consistently under-performed the factor 10 and is not shown here for clarity. The choice of an intermediate number of codewords makes sense: Too few of the code-words may not be able to capture all of the variations present in the data, and too large of codewords yields to over-fitting and learning finer unnecessary details. The same holds as expected for the size of classification head, smaller models yielding much better performance as opposed to a large model possibly over-fitting the dataset. With the best performing architecture keeping it fixed, we improve the performance of the models further by making models robust to errors/outliers in various input codes.
|
| 64 |
+
|
| 65 |
+
Fig. 3. Effect of probability of dropped input tokens on mAP scores for 1s audio chunks for best performing model. Notice that there exists a optimum percentage to maximize the performance, and it was tuned over 10, 20, 25, 30, 35, 40 and 50 percent of the dropped tokens over the feature vector of size 4 ∗ D .
|
| 66 |
+
|
| 67 |
+
<!-- image -->
|
| 68 |
+
|
| 69 |
+
We randomly drop input features by a probability p and see the performance, in terms of mean average precision. Masking of inputs is not new and has been used in various contexts. As shown in BERT [36], it adds robustness to the learned embeddings. We see that there exists an optimum value of the number of tokens one should drop: too many tokens being dropped and we lose valuable information. Too few tokens dropped and we do not build the model agnostic to outliers.
|
| 70 |
+
|
| 71 |
+
We are perhaps the first ones to introduce this idea in a bag-ofwords setup. We obtain the best overall performance of about 0.38 mean average precision (mAP) score with 35% randomly dropped tokens. We also would like to note that there can exist many more values/parameters that can be tuned.
|
| 72 |
+
|
| 73 |
+
Finally, in Table 1 we report clip level scores which are obtained by averaging the probability scores as reported in [2]. We come strikingly close to baseline Transformer models, and outperform strong state of the art models as recent as 2018! It is noteable as we use all of the tools that could have been used/had access to as early as 2006. Similar to how the Transformers were improved upon from the baseline model (multi-resolution, pooling, larger models), our current model can also be improved upon in several ways, a few of them have been described in future work. We report the bestperforming model with that of convolutional neural architectures and Transformer models. Our setup achieves a comparable performance which is fascinating in itself. However, the goal of this work is simplicity: To showcase how to obtain comparable performance without utilizing any convolutional, transformer, attention, rnns, or mixer blocks [41] going against the mainstream research as a first step in this line of work, of using embeddings.
|
| 74 |
+
|
| 75 |
+
TABLE I Comparison of proposed architecture as shown in the table below for mAP metric at clip level. Our approach can outperform widely used CNNs by significant margins and comes close to the baseline Transformer models. [2]. Similar to the improvements over baseline Transformer architectures, we can in future also improve the performance in a variety of ways.
|
| 76 |
+
|
| 77 |
+
| Neural Model Architecture mAP CRNN [2] 0.41 VGG-like [2] 0.43 ResNet-18 [2] 0.37 DenseNet-121 [2] 0.42 Baseline/Wavelet Transformer [12] 0.46/0.54 Current Work 0.44 |
|
| 78 |
+
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 79 |
+
|
| 80 |
+
## V. CONCLUSION AND FUTURE WORK
|
| 81 |
+
|
| 82 |
+
We show the power of vanilla embeddings followed by code-book learning to yield representations in clustered space of the signal of interest. We achieve this by modeling the envelopes across different frequency bins, spectral envelops, patches as well as the overall spectrogram at a coarser scale. This idea can be strengthened in the future by deploying more sophisticated clustering algorithms than k-means, such as UMAP [33], DBSCAN [42] or better end to end learned code-book such as neural discrete representation learning [28]. Due to the sheer number of parameters and limited computing resources, we could not achieve large-scale hyper-parameter tuning beyond what is reported, although it would certainly help improving mAP scores. Further, bringing temporally statistics such as n-grams will help boost the performance too, similar to gains showed over a simple bag of words approach in natural language processing [43].
|
| 83 |
+
|
| 84 |
+
## ACKNOWLEDGMENTS
|
| 85 |
+
|
| 86 |
+
The author thanks Prof. J. K. Verma for help in proof reading the manuscript, the Department of Mathematics, IIT
|
| 87 |
+
|
| 88 |
+
Bombay for providing facilities. He is thankful for Prof. Stephen Boyd's lectures in Stanford ENGR 108 [44] for sowing seeds of this work, and Robert Crown Library at SLS.
|
| 89 |
+
|
| 90 |
+
## REFERENCES
|
| 91 |
+
|
| 92 |
+
- [1] Geoffrey E Hinton and Ruslan R Salakhutdinov, 'Reducing the dimensionality of data with neural networks,' science , vol. 313, no. 5786, pp. 504-507, 2006.
|
| 93 |
+
- [2] Eduardo Fonseca, Xavier Favory, Jordi Pons, Frederic Font, and Xavier Serra, 'Fsd50k: an open dataset of human-labeled sound events,' arXiv preprint arXiv:2010.00475 , 2020.
|
| 94 |
+
- [3] Shawn Hershey, Sourish Chaudhuri, Daniel PW Ellis, Jort F Gemmeke, Aren Jansen, R Channing Moore, Manoj Plakal, Devin Platt, Rif A Saurous, Bryan Seybold, et al., 'Cnn architectures for large-scale audio classification,' in 2017 ieee international conference on acoustics, speech and signal processing (icassp) . IEEE, 2017, pp. 131-135.
|
| 95 |
+
- [4] Yong Xu, Qiuqiang Kong, Wenwu Wang, and Mark D Plumbley, 'Largescale weakly supervised audio classification using gated convolutional neural network,' in 2018 IEEE international conference on acoustics, speech and signal processing (ICASSP) . IEEE, 2018, pp. 121-125.
|
| 96 |
+
- [5] Wenhao Bian, Jie Wang, Bojin Zhuang, Jiankui Yang, Shaojun Wang, and Jing Xiao, 'Audio-based music classification with densenet and data augmentation,' in Pacific Rim International Conference on Artificial Intelligence . Springer, 2019, pp. 56-65.
|
| 97 |
+
- [6] Alexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn, Xiaohua Zhai, Thomas Unterthiner, Mostafa Dehghani, Matthias Minderer, Georg Heigold, Sylvain Gelly, et al., 'An image is worth 16x16 words: Transformers for image recognition at scale,' arXiv preprint arXiv:2010.11929 , 2020.
|
| 98 |
+
- [7] Niki Parmar, Ashish Vaswani, Jakob Uszkoreit, Lukasz Kaiser, Noam Shazeer, Alexander Ku, and Dustin Tran, 'Image transformer,' in International Conference on Machine Learning . PMLR, 2018, pp. 40554064.
|
| 99 |
+
- [8] Kaiming He, Xinlei Chen, Saining Xie, Yanghao Li, Piotr Doll´ ar, and Ross Girshick, 'Masked autoencoders are scalable vision learners,' arXiv preprint arXiv:2111.06377 , 2021.
|
| 100 |
+
- [9] Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Lukasz Kaiser, and Illia Polosukhin, 'Attention is all you need,' arXiv preprint arXiv:1706.03762 , 2017.
|
| 101 |
+
- [10] Zihang Dai, Zhilin Yang, Yiming Yang, Jaime Carbonell, Quoc V Le, and Ruslan Salakhutdinov, 'Transformer-xl: Attentive language models beyond a fixed-length context,' arXiv preprint arXiv:1901.02860 , 2019.
|
| 102 |
+
- [11] Jason Wei, Maarten Bosma, Vincent Y Zhao, Kelvin Guu, Adams Wei Yu, Brian Lester, Nan Du, Andrew M Dai, and Quoc V Le, 'Finetuned language models are zero-shot learners,' arXiv preprint arXiv:2109.01652 , 2021.
|
| 103 |
+
- [12] Prateek Verma and Jonathan Berger, 'Audio transformers: Transformer architectures for large scale audio understanding. adieu convolutions,' arXiv preprint arXiv:2105.00335 , 2021.
|
| 104 |
+
- [13] Prateek Verma and Chris Chafe, 'A generative model for raw audio using transformer architectures,' arXiv preprint arXiv:2106.16036 , 2021.
|
| 105 |
+
- [14] Prafulla Dhariwal, Heewoo Jun, Christine Payne, Jong Wook Kim, Alec Radford, and Ilya Sutskever, 'Jukebox: A generative model for music,' arXiv preprint arXiv:2005.00341 , 2020.
|
| 106 |
+
- [15] Yuan Gong, Yu-An Chung, and James Glass, 'Ast: Audio spectrogram transformer,' arXiv preprint arXiv:2104.01778 , 2021.
|
| 107 |
+
- [16] Yin Zhang, Rong Jin, and Zhi-Hua Zhou, 'Understanding bag-ofwords model: a statistical framework,' International Journal of Machine Learning and Cybernetics , vol. 1, no. 1-4, pp. 43-52, 2010.
|
| 108 |
+
- [17] Stephanie Pancoast and Murat Akbacak, 'Bag-of-audio-words approach for multimedia event classification,' Tech. Rep., SRI International Menlo Park United States, 2012.
|
| 109 |
+
- [18] Prateek Verma and Julius Smith, 'A framework for contrastive and generative learning of audio representations,' arXiv e-prints , pp. arXiv2010, 2020.
|
| 110 |
+
- [19] Alexei Baevski, Steffen Schneider, and Michael Auli, 'vq-wav2vec: Self-supervised learning of discrete speech representations,' arXiv preprint arXiv:1910.05453 , 2019.
|
| 111 |
+
- [20] Alexei Baevski, Henry Zhou, Abdelrahman Mohamed, and Michael Auli, 'wav2vec 2.0: A framework for self-supervised learning of speech representations,' arXiv preprint arXiv:2006.11477 , 2020.
|
| 112 |
+
- [21] Yu Wang, Nicholas J Bryan, Justin Salamon, Mark Cartwright, and Juan Pablo Bello, 'Who calls the shots? rethinking few-shot learning for audio,' in 2021 IEEE Workshop on Applications of Signal Processing to Audio and Acoustics (WASPAA) . IEEE, 2021, pp. 36-40.
|
| 113 |
+
- [22] Ting Chen, Simon Kornblith, Mohammad Norouzi, and Geoffrey Hinton, 'A simple framework for contrastive learning of visual representations,' arXiv preprint arXiv:2002.05709 , 2020.
|
| 114 |
+
- [23] Luyu Wang and Aaron van den Oord, 'Multi-format contrastive learning of audio representations,' arXiv preprint arXiv:2103.06508 , 2021.
|
| 115 |
+
- [24] Prateek Verma, Chris Chafe, and Jonathan Berger, 'Neuralogram: A deep neural network based representation for audio signals,' arXiv preprint arXiv:1904.05073 , 2019.
|
| 116 |
+
- [25] Yu-An Chung and James R. Glass, 'Speech2vec: A sequence-tosequence framework for learning word embeddings from speech,' ArXiv , vol. abs/1803.08976, 2018.
|
| 117 |
+
- [26] Albert Haque, Michelle Guo, Prateek Verma, and Fei-Fei Li, 'Audiolinguistic embeddings for spoken sentences,' in 2019 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP) , 2019, pp. 7355-7359.
|
| 118 |
+
- [27] RJ Skerry-Ryan, Eric Battenberg, Ying Xiao, Yuxuan Wang, Daisy Stanton, Joel Shor, Ron Weiss, Rob Clark, and Rif A Saurous, 'Towards endto-end prosody transfer for expressive speech synthesis with tacotron,' in international conference on machine learning . PMLR, 2018, pp. 46934702.
|
| 119 |
+
- [28] Aaron van den Oord, Oriol Vinyals, and Koray Kavukcuoglu, 'Neural discrete representation learning,' arXiv preprint arXiv:1711.00937 , 2017.
|
| 120 |
+
- [29] Prateek Verma and Julius O Smith, 'Neural style transfer for audio spectograms,' arXiv preprint arXiv:1801.01589 , 2018.
|
| 121 |
+
- [30] Prateek Verma and Kenneth Salisbury, 'Unsupervised learning of audio perception for robotics applications: Learning to project data to tsne/umap space,' arXiv preprint arXiv:2002.04076 , 2020.
|
| 122 |
+
- [31] Yusuf Aytar, Carl Vondrick, and Antonio Torralba, 'Soundnet: Learning sound representations from unlabeled video,' Advances in neural information processing systems , vol. 29, pp. 892-900, 2016.
|
| 123 |
+
- [32] Andrew Owens, Jiajun Wu, Josh H McDermott, William T Freeman, and Antonio Torralba, 'Ambient sound provides supervision for visual learning,' in European conference on computer vision . Springer, 2016, pp. 801-816.
|
| 124 |
+
- [33] Leland McInnes, John Healy, and James Melville, 'Umap: Uniform manifold approximation and projection for dimension reduction,' arXiv preprint arXiv:1802.03426 , 2018.
|
| 125 |
+
- [34] Chen Sun, Austin Myers, Carl Vondrick, Kevin Murphy, and Cordelia Schmid, 'Videobert: A joint model for video and language representation learning,' in Proceedings of the IEEE/CVF International Conference on Computer Vision , 2019, pp. 7464-7473.
|
| 126 |
+
- [35] 'Bag-of-words model,' https://en.wikipedia.org/wiki/Bag-of-words model, Accessed: 2022-01-22.
|
| 127 |
+
- [36] Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova, 'Bert: Pre-training of deep bidirectional transformers for language understanding,' arXiv preprint arXiv:1810.04805 , 2018.
|
| 128 |
+
- [37] Jort F Gemmeke, Daniel PW Ellis, Dylan Freedman, Aren Jansen, Wade Lawrence, R Channing Moore, Manoj Plakal, and Marvin Ritter, 'Audio set: An ontology and human-labeled dataset for audio events,' in 2017 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP) . IEEE, 2017, pp. 776-780.
|
| 129 |
+
- [38] Diederik P Kingma and Jimmy Ba, 'Adam: A method for stochastic optimization,' arXiv preprint arXiv:1412.6980 , 2014.
|
| 130 |
+
- [39] Martin Abadi, Paul Barham, Jianmin Chen, Zhifeng Chen, Andy Davis, Jeffrey Dean, Matthieu Devin, Sanjay Ghemawat, Geoffrey Irving, Michael Isard, Manjunath Kudlur, Josh Levenberg, Rajat Monga, Sherry Moore, Derek G. Murray, Benoit Steiner, Paul Tucker, Vijay Vasudevan, Pete Warden, Martin Wicke, Yuan Yu, and Xiaoqiang Zheng, 'Tensorflow: A system for large-scale machine learning,' in 12th USENIX Symposium on Operating Systems Design and Implementation (OSDI 16) , 2016, pp. 265-283.
|
| 131 |
+
- [40] Nitish Srivastava, Geoffrey Hinton, Alex Krizhevsky, Ilya Sutskever, and Ruslan Salakhutdinov, 'Dropout: a simple way to prevent neural networks from overfitting,' The journal of machine learning research , vol. 15, no. 1, pp. 1929-1958, 2014.
|
| 132 |
+
- [41] Ilya Tolstikhin, Neil Houlsby, Alexander Kolesnikov, Lucas Beyer, Xiaohua Zhai, Thomas Unterthiner, Jessica Yung, Daniel Keysers, Jakob Uszkoreit, Mario Lucic, et al., 'Mlp-mixer: An all-mlp architecture for vision,' arXiv preprint arXiv:2105.01601 , 2021.
|
| 133 |
+
- [42] Martin Ester, Hans-Peter Kriegel, J¨ org Sander, Xiaowei Xu, et al., 'A density-based algorithm for discovering clusters in large spatial databases with noise.,' in kdd , 1996, vol. 96, pp. 226-231.
|
| 134 |
+
- [43] Izumi Suzuki, Yoshiki Mikami, Ario Ohsato, and Yoshihide Chubachi, 'A language and character set determination method based on ngram statistics,' ACM Transactions on Asian Language Information Processing (TALIP) , vol. 1, no. 3, pp. 269-278, 2002.
|
| 135 |
+
|
| 136 |
+
[44] 'ENGR108: Introduction to Matrix Methods Professor Stephen Boyd, Stanford University,' https://stanford.edu/class/engr108/, Accessed: 2022-01-22.
|
text-versions/attention-markdown/2110.11773_Sinkformers Transformers with Doubly Sto.md
ADDED
|
@@ -0,0 +1,494 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2110.11773 Sinkformers Transformers With Doubly Sto
|
| 2 |
+
|
| 3 |
+
## Sinkformers: Transformers with Doubly Stochastic Attention
|
| 4 |
+
|
| 5 |
+
Michael E. Sander ENS and CNRS
|
| 6 |
+
|
| 7 |
+
Pierre Ablin ENS and CNRS
|
| 8 |
+
|
| 9 |
+
## Abstract
|
| 10 |
+
|
| 11 |
+
Attention based models such as Transformers involve pairwise interactions between data points, modeled with a learnable attention matrix. Importantly, this attention matrix is normalized with the SoftMax operator, which makes it row-wise stochastic. In this paper, we propose instead to use Sinkhorn's algorithm to make attention matrices doubly stochastic. We call the resulting model a Sinkformer. We show that the rowwise stochastic attention matrices in classical Transformers get close to doubly stochastic matrices as the number of epochs increases, justifying the use of Sinkhorn normalization as an informative prior. On the theoretical side, we show that, unlike the SoftMax operation, this normalization makes it possible to understand the iterations of self-attention modules as a discretized gradient-flow for the Wasserstein metric. We also show in the infinite number of samples limit that, when rescaling both attention matrices and depth, Sinkformers operate a heat diffusion. On the experimental side, we show that Sinkformers enhance model accuracy in vision and natural language processing tasks. In particular, on 3D shapes classification, Sinkformers lead to a significant improvement.
|
| 12 |
+
|
| 13 |
+
## 1 Introduction
|
| 14 |
+
|
| 15 |
+
The Transformer (Vaswani et al., 2017), an architecture that relies entirely on attention mechanisms (Bahdanau et al., 2014), has achieved state of the art empirical success in natural language processing (NLP) (Brown et al., 2020; Radford et al., 2019; Wolf
|
| 16 |
+
|
| 17 |
+
To appear in the proceedings of the 25 th International Conference on Artificial Intelligence and Statistics (AISTATS) 2022, Valencia, Spain. PMLR: Volume 151. Copyright 2022 by the author(s).
|
| 18 |
+
|
| 19 |
+
Mathieu Blondel Google Research, Brain team
|
| 20 |
+
|
| 21 |
+
Gabriel Peyr´ e ENS and CNRS
|
| 22 |
+
|
| 23 |
+
et al., 2019) as well as in computer vision (Dosovitskiy et al., 2020; Zhao et al., 2020; Zhai et al., 2021; Lee et al., 2019). As the key building block of the Transformer, the self-attention mechanism takes the following residual form (Yun et al., 2019) given a n -sequence ( x 1 , x 2 , ..., x n ), embedded in dimension d :
|
| 24 |
+
|
| 25 |
+
<!-- formula-not-decoded -->
|
| 26 |
+
|
| 27 |
+
where K 1 := SoftMax ( C ) with C i,j := ( W Q x i ) ⊤ W K x j = x ⊤ i W ⊤ Q W K x j . Here, W Q , W K ∈ R m × d and W V ∈ R d × d are the query, key and value matrices. The SoftMax operator can be seen as a normalization of the matrix K 0 := exp( C ) as follows: K 1 ij := K 0 ij / ∑ n l =1 K 0 il for all i and j . Importantly, the matrix K 1 is row-wise stochastic: its rows all sum to 1.
|
| 28 |
+
|
| 29 |
+
In this work, we propose to take the normalization process further by successively normalizing the rows and columns of K 0 . This process is known to provably converge to a doubly stochastic matrix (i.e., whose rows and columns both sum to 1) and is called Sinkhorn's algorithm (Sinkhorn, 1964; Cuturi, 2013; Peyr´ e et al., 2019). We denote the resulting doubly stochastic matrix K ∞ . Intuitively, such a normalization relies on a democratic principle where all points are matched one to another with different degrees of intensity, so that more interactions are considered than with the SoftMax normalization, as shown in Figure 1.
|
| 30 |
+
|
| 31 |
+
Figure 1: Illustration of the different normalizations of attention matrices. We form two point clouds ( W Q x i ) 1 ≤ i ≤ 10 (green) and ( W K x j ) 1 ≤ i ≤ 10 (red). For k ∈ { 0 , 1 , ∞} , the width of the line connecting x i to x j is K k i,j . We only display connections with K k i,j ≥ 10 -12 . For K 0 , one interaction dominates. For K 1 (SoftMax), one cluster is ignored. For K ∞ (Sinkhorn), all points are involved in an interaction.
|
| 32 |
+
|
| 33 |
+
<!-- image -->
|
| 34 |
+
|
| 35 |
+
We call our Transformer variant where the SoftMax is replaced by Sinkhorn a Sinkformer . Since Sinkhorn's first iteration coincides exactly with the SoftMax, Sinkformers include Transformers as a special case. Our modification is differentiable, easy to implement using deep learning libraries, and can be executed on GPUs for fast computation. Because the set of rowwise stochastic matrices contains the set of doubly stochastic matrices, the use of doubly stochastic matrices can be interpreted as a prior. On the experimental side, we confirm that doubly stochastic attention leads to better accuracy in several learning tasks. On the theoretical side, doubly stochastic matrices also give a better understanding of the mathematical properties of self-attention maps.
|
| 36 |
+
|
| 37 |
+
To summarize, we make the following contributions.
|
| 38 |
+
|
| 39 |
+
- We show empirically that row-wise stochastic matrices seem to converge to doubly stochastic matrices during the learning process in several classical Transformers (Figure 2). Motivated by this finding, we then introduce the Sinkformer, an extension of the Transformer in which the SoftMax is replaced by the output of Sinkhorn's algorithm. In practice, our model is parametrized by the number of iterations in the algorithm, therefore interpolating between the Transformer and the Sinkformer.
|
| 40 |
+
- On the theoretical side, we show that Transformers and Sinkformers can be viewed as models acting on discrete distributions, and we show under a symmetry assumption that Sinkformers can be seen in the infinite depth limit as a Wasserstein gradient flow for an energy minimization (Proposition 2). We also show that the classical Transformer with the SoftMax operator cannot be interpreted as such a flow (Proposition 3). To the best of our knowledge, this is the first time such a connection is established. We also prove that in the infinite number of particles limit (when n goes to infinity), the iterations of Sinkformers converge to the heat equation (Theorem 1), while the corresponding equation for Transformers is nonlinear and nonlocal (Proposition 4).
|
| 41 |
+
- On the experimental side, we show that Sinkformers lead to a significant accuracy gain compared to Transformers on the ModelNet 40 3D shapes classification task. We then demonstrate better performance of Sinkformers on the NLP IMDb dataset for sentiment analysis and IWSLT'14 German to English neural machine translation tasks. Sinkformers also achieve a better accuracy than Vision Transformers on image classification tasks. Therefore, the proposed method is capable of enhancing the performance of transformers in a wide range of applications.
|
| 42 |
+
|
| 43 |
+
## 2 Background and related work
|
| 44 |
+
|
| 45 |
+
Transformers. Proposed by Vaswani et al. (2017), the Transformer is a fully attention-based architecture. Originally designed to process sequences for natural language processing (NLP), many variants have since been developed such as Vision Transformers (Dosovitskiy et al., 2020; Zhai et al., 2021), Set Transformers (Lee et al., 2019) or Point Cloud Transformers (Zhao et al., 2020). The Transformer and its variants are based on an encoder-decoder structure, where the decoder can have a more or less complex form. The encoder is fully self -attention based. After embedding and concatenating with positional encoding the original input sequence, the encoder uses a series of residual blocks that iterates relation (1) followed by a feed forward neural network applied to each x i independently. In its most complex form such as in neural machine translation, the decoder combines a selfattention based mechanisms and a cross attention one, meaning that it is given access to the encoder via another multi-head attention block.
|
| 46 |
+
|
| 47 |
+
Sinkhorn and Attention. To the best of our knowledge, using Sinkhorn's algorithm in Transformers has been done once in a different context (Tay et al., 2020). The authors propose to learn efficient and sparse attention using a differentiable algorithm for sorting and rearranging elements in the input sequence. For this purpose, they introduce a sorting network to generate a doubly-stochastic matrix (that can be seen as a relaxed version of a permutation matrix) and use it to sort the sequence in a differentiable fashion. Mialon et al. (2021) propose an embedding for sets of features in R d based on Sinkhorn's algorithm, by using the regularized optimal transport plan between data points and a reference set. Niculae et al. (2018) use doubly stochastic attention matrices in LSTM-based encoder-decoder networks but they use Frank-Wolfe or active set methods to compute the attention matrix. None of these works use Sinkhorn on self-attention maps in Transformers and provide its theoretical analysis, as we do.
|
| 48 |
+
|
| 49 |
+
Impact of bi-normalization. Theoretical properties of kernels K , which attention is an instance of, can also be studied through the operator f ↦→ f -K f . Binormalization of kernels over manifolds have already been studied in the literature, on uniform measures (Singer, 2006), weighted measures (Hein et al., 2007) and in a more general setup with associated diffusion operators (Ting et al., 2011). Milanfar (2013) proposes to approximate smoothing operators by doubly stochastic matrices using Sinkhorn's updates, leading to better performance in data analysis and signal pro- cessing. Importantly, the works of Marshall and Coifman (2019) and Wormell and Reich (2021) exactly introduce a normalization that is based on Sinkhorn's algorithm. They prove that this method models a Langevin diffusion and leads to the approximation of a symmetric operator. They also show that convergence to this operator is faster with Sinkhorn normalization than with the SoftMax normalization. In section 5, we adopt a similar point of view with a parametrized cost and show that different normalizations result in different partial differential equations (PDEs) in the infinite number of particles limit.
|
| 50 |
+
|
| 51 |
+
Infinite depth limit. Studying deep residual neural networks (ResNets) (He et al., 2016) in the infinitesimal step-size regime (or infinite depth limit) has recently emerged as a new framework for analyzing their theoretical properties. The ResNet equation
|
| 52 |
+
|
| 53 |
+
<!-- formula-not-decoded -->
|
| 54 |
+
|
| 55 |
+
can indeed be seen as a discretized Euler scheme with unit step size of the ordinary differential equation (ODE) ˙ x i = T ( x i ) (Weinan, 2017; Chen et al., 2018; Teh et al., 2019; Sun et al., 2018; Weinan et al., 2019; Lu et al., 2018; Ruthotto and Haber, 2019; Sander et al., 2021). In section 4, we adopt this point of view on residual attention layers in order to get a better theoretical understanding of attention mechanisms. This is justified by the fact that, for instance, GPT-3 (Brown et al., 2020) has 96 layers.
|
| 56 |
+
|
| 57 |
+
Neural networks on measures. The self-attention mechanism (1) acts on sets { x i } i where the ordering of the elements does not matter. An equivalent way to model such invariant architectures is to consider them as acting on probability measures or point clouds of varying cardinality (De Bie et al., 2019; Vuckovic et al., 2021; Zweig and Bruna, 2021). Specifically, a collection of points ( x i ) 1 ≤ i ≤ n , where x i ∈ R d , can also be seen as a discrete measure on R d : µ := 1 n ∑ n i =1 δ x i ∈ M ( R d ), where M ( R d ) is the set of probability measures on R d . A map T µ then acts on µ through F ( µ ) := 1 n ∑ n i =1 δ T µ ( x i ) . One notable interest of such a point of view is to consider the evolution of non ordered sets of points. Another is to consider the mean field (or large sample) limit, that is when n → ∞ , to conduct theoretical analysis (Zweig and Bruna, 2021) as when analyzing the SGD properties in the mean-field limit (Song et al., 2018).
|
| 58 |
+
|
| 59 |
+
## 3 Sinkformers
|
| 60 |
+
|
| 61 |
+
We now introduce Sinkformers, a modification of any Transformer by replacing the SoftMax operator in the attention modules by Sinkhorn's algorithm.
|
| 62 |
+
|
| 63 |
+
Attention matrices during training. In Transformers, attention matrices are row-wise stochastic. A natural question is how the sum over columns evolve during training. On 3 different models and 3 different learning tasks, we calculated the sum over columns of attention matrices in Transformers. We find out that the learning process makes the attention matrices more and more doubly stochastic, as shown in Figure 2.
|
| 64 |
+
|
| 65 |
+
Figure 2: Sum over columns of attention matrices at different training epochs (color) when training, from left to right, a ViT on MNIST (section 6.4), a fairseq Transformer on IWSLT'14 (section 6.3), and a Point Cloud Transformer on Model Net 40 (section 6.1). The majority of columns naturally sum closely to 1 .
|
| 66 |
+
|
| 67 |
+
<!-- image -->
|
| 68 |
+
|
| 69 |
+
Thus, row-wise stochastic attention matrices seem to approach doubly stochastic matrices during the learning process in classical Transformers. Therefore, it seems natural to impose double stochasticity as a prior and study theoretically and experimentally the resulting model. A process to obtain such matrices which extends the SoftMax is Sinkhorn's algorithm.
|
| 70 |
+
|
| 71 |
+
Sinkhorn's algorithm. Given a matrix C ∈ R n × n , and denoting K 0 ∈ R n × n such that K 0 = exp( C ), Sinkhorn's algorithm (Sinkhorn, 1964; Cuturi, 2013; Peyr´ e et al., 2019) iterates, starting from K 0 :
|
| 72 |
+
|
| 73 |
+
<!-- formula-not-decoded -->
|
| 74 |
+
|
| 75 |
+
where N R and N C correspond to row-wise and columnwise normalizations: ( N R ( K )) i,j := K i,j ∑ n l =1 K i,l and ( N C ( K )) i,j := K i,j ∑ n l =1 K l,j . We denote the resulting scaled matrix limit K ∞ := Sinkhorn ( C ). Note that it is doubly stochastic in the sense that K ∞ 1 n = 1 n and K ∞⊤ 1 n = 1 n . The operations in (3) are perfectly suited for being executed on GPUs (Charlier et al., 2021; Cuturi, 2013).
|
| 76 |
+
|
| 77 |
+
Sinkformers. For simplicity, we consider a one head attention block that iterates equation (1). Note that K 1 := SoftMax ( C ) is precisely the output of Sinkhorn's algorithm (3) after 1 iteration. In this paper, we propose to take Sinkhorn's algorithm several steps further until it approximately converges to a doubly stochastic matrix K ∞ . This process can be easily implemented in practice, simply by plugging Sinkhorn's algorithm into self-attention modules in existing architectures, without changing the overall structure of the network. We call the resulting drop-in replacement of a Transformer a Sinkformer. It iterates
|
| 78 |
+
|
| 79 |
+
<!-- formula-not-decoded -->
|
| 80 |
+
|
| 81 |
+
In the next two sections 4 and 5, we investigate the theoretical properties of Sinkformers. We exhibit connections with energy minimization in the space of measures and the heat equation, thereby proposing a new framework for understanding attention mechanisms. All our experiments are described in Section 6 and show the benefits of using Sinkformers in a wide variety of applications.
|
| 82 |
+
|
| 83 |
+
Computational cost and differentiation. Turning a Transformer into a Sinkformer simply relies on replacing the SoftMax by Sinkhorn, i.e., substituting K 1 with K ∞ . In practice, we use a finite number of Sinkhorn iterations and therefore use K l , where l is large enough so that K l is almost doubly stochastic. Doing l iterations of Sinkhorn takes l times longer than the SoftMax. However, this is not a problem in practice because Sinkhorn is not the main computational bottleneck and because only a few iterations of Sinkhorn are sufficient (typically 3 to 5) to converge to a doubly stochastic matrix. As a result, the practical training time of Sinkformers is comparable to regular Transformers, as detailed in our experiments.
|
| 84 |
+
|
| 85 |
+
Sinkhorn is perfectly suited for backpropagation (automatic differentiation), by differentiating through the operations of (3). The Jacobian of an optimization problem solution can also be computed using the implicit function theorem (Griewank and Walther, 2008; Krantz and Parks, 2012; Blondel et al., 2021) instead of backpropagation if the number of iterations becomes a memory bottleneck. Together with Sinkhorn, implicit differentiation has been used by Luise et al. (2018) and Cuturi et al. (2020).
|
| 86 |
+
|
| 87 |
+
Invariance to the cost function. Recall that in practice one has C i,j = ( W Q x i ) ⊤ W K x j . An important aspect of Sinkformers is that their output is unchanged if the cost is modified with non interacting terms, as the next proposition shows.
|
| 88 |
+
|
| 89 |
+
Proposition 1. Let C ∈ R n × n . Consider, for ( f, g ) ∈ R n × R n the modified cost function ˜ C i,j := C i,j + f i + g j . Then Sinkhorn ( C ) = Sinkhorn ( ˜ C ) .
|
| 90 |
+
|
| 91 |
+
A proof is available in Appendix A. A consequence of this result is that one can consider the cost ˜ C i,j := -1 2 ‖ W Q x i -W K x j ‖ 2 instead of C i,j = ( W Q x i ) ⊤ W K x j , without affecting K ∞ . A Transformer using the cost ˜ C is referred to as L2 self-attention, and is Lipschitz under some assumptions (Kim et al., 2021) and can therefore be used as an invertible model (Behrmann et al., 2019). For instance, we use ˜ C in Proposition 4.
|
| 92 |
+
|
| 93 |
+
## 4 Attention and gradient flows
|
| 94 |
+
|
| 95 |
+
In this section, we make a parallel between selfattention modules in Sinkformers and gradient flows in the space of measures. We denote M ( R d ) the probability measures on R d and C ( R d ) the continuous functions on R d . We denote ∇ the gradient operator, div the divergence, and ∆ the Laplacian, that is ∆ = div( ∇ ).
|
| 96 |
+
|
| 97 |
+
Residual maps for attention. We consider a onehead attention block operating with different normalizations. We consider the continuous counterparts of the attention matrices seen in the previous section. We denote c ( x, x ′ ) := ( W Q x ) ⊤ W K x ′ and k 0 := exp( c ). For some measure µ ∈ M ( R d ), we define the SoftMax operator on the cost c by k 1 ( x, x ′ ) = SoftMax ( c )( x, x ′ ) := k 0 ( x,x ′ ) ∫ k 0 ( x,y ) dµ ( y ) . Similarly, we define Sinkhorn's algorithm as the following iterations, starting from k 0 = exp( c ):
|
| 98 |
+
|
| 99 |
+
<!-- formula-not-decoded -->
|
| 100 |
+
|
| 101 |
+
We denote k ∞ := Sinkhorn ( c ) the resulting limit. Note that if µ is a discrete measure supported on a n sequence of particles ( x 1 , x 2 , ..., x n ), µ = 1 n ∑ n i =1 δ x i , then for all ( i, j ), k 0 ( x i , x j ) = K 0 i,j , k 1 ( x i , x j ) = K 1 i,j and k ∞ ( x i , x j ) = K ∞ i,j , so that k 0 , k 1 and k ∞ are indeed the continuous equivalent of the matrices K 0 , K 1 and K ∞ respectively.
|
| 102 |
+
|
| 103 |
+
Infinitesimal step-size regime. In order to better understand the theoretical properties of attention matrices in Transformers and Sinkformers, we omit the feed forward neural networks acting after each attention block. We consider a succession of attention blocks with tied weights between layers and study the infinite depth limit where the output is given by solving a neural ODE (Chen et al., 2018). In this framework, iterating the Transformer equation (1), the ResNet equation (2) and the Sinkformer equation (4) corresponds to a Euler discretization with step-size 1 of the ODEs
|
| 104 |
+
|
| 105 |
+
<!-- formula-not-decoded -->
|
| 106 |
+
|
| 107 |
+
where x i ( t ) is the position of x i at time t . For an arbitrary measure µ ∈ M ( R d ), these ODEs can be equivalently written as a continuity equation (Renardy and Rogers, 2006)
|
| 108 |
+
|
| 109 |
+
<!-- formula-not-decoded -->
|
| 110 |
+
|
| 111 |
+
When T µ is defined by the ResNet equation (2), T µ = T does not depend on µ . It defines an advection equation where the particles do not interact and evolve independently. When T µ is defined by the Transformer equation (1) or Sinkformer equation (4), T µ has a dependency in µ and the particles interact: the local vector field depends on the position of the other particles. More precisely we have in this case T 1 µ ( x ) = ∫ k 1 ( x, x ′ ) W V x ′ dµ ( x ′ ) for the Transformer and T ∞ µ ( x ) = ∫ k ∞ ( x, x ′ ) W V x ′ dµ ( x ′ ) for the Sinkformer. It is easily seen that when µ is discrete we recover the operators in equation (1) and (4).
|
| 112 |
+
|
| 113 |
+
Wasserstein gradient flows. A particular case of equation (5) is when T µ is a gradient with respect to the Wasserstein metric W 2 . Let F be a function on M ( R d ). As is standard, we suppose that F admits a first variation at all µ : there exists a function δ F δµ ( µ ) such that d dε F ( µ + ερ ) | ε =0 = ∫ δ F δµ ( µ ) dρ for every perturbation ρ (Santambrogio, 2017). The Wasserstein gradient of F at µ is then ∇ W F ( µ ) := ∇ ( δ F δµ ( µ )). The minimization of F on the space of measures corresponds to the PDE (5) with T µ = -∇ W F ( µ ). This PDE can be interpreted as ruling the evolution of the measure µ of particles initially distributed according to some measure µ 0 , for which the positions x ( t ) follow the flow ˙ x = -∇ W F ( µ )( x ), that minimizes the global energy F . It corresponds to a steepest descent in Wasserstein space (Jordan et al., 1998). In Proposition 2, we show in the symmetric kernel case that Sinkformers correspond to a Wasserstein gradient flow for some functional F ∞ , while Transformers do not.
|
| 114 |
+
|
| 115 |
+
Particular case. An example is when T µ does not depend on µ and writes T µ = -∇ E where E : R d → R . Under regularity assumptions, a solution of (5) then converges to a local minimum of E . This fits in the implicit deep learning framework (Bai et al., 2019), where a neural network is seen as solving an optimization problem. A typical benefit of implicit models is that the iterates x i do not need to be stored during the forward pass of the network because gradients can be calculated using the implicit function theorem: it bypasses the memory storage issue of GPUs (Wang et al., 2018; Peng et al., 2017; Zhu et al., 2017) during automatic differentiation. Another application is to consider neural architectures that include an argmin layer, for which the output is also formulated as the solution of a nested optimization problem (Agrawal et al., 2019; Gould et al., 2016, 2019).
|
| 116 |
+
|
| 117 |
+
Flows for attention. Our goal is to determine the PDEs (5) defined by the proposed attention maps. We consider the symmetric case, summarized by the following assumption:
|
| 118 |
+
|
| 119 |
+
<!-- formula-not-decoded -->
|
| 120 |
+
|
| 121 |
+
Assumption 1 means we consider symmetric kernels (by imposing W K ⊤ W Q = W Q ⊤ W K ), and that when differentiating x ↦→ exp( c ( x, x ′ )), we obtain -exp( c ) W V . We show that, under this assumption, the PDEs defined by k 0 and k ∞ correspond to Wasserstein gradient flows, whereas it is not the case for k 1 . A particular case of imposing W K ⊤ W Q = W Q ⊤ W K is when W Q = W K . This equality setting is studied by Kim et al. (2021), where the authors show that it leads to similar performance for Transformers. Since imposing W K ⊤ W Q = W Q ⊤ W K is less restrictive, it seems to be a natural assumption. Imposing W ⊤ Q W K = -W V is more restrictive, and we detail the expressions for the PDEs associated to k 0 , k 1 , k ∞ without this assumption in Appendix A. We have the following result.
|
| 122 |
+
|
| 123 |
+
Proposition 2 (PDEs associated to k 0 , k 1 , k ∞ ) . Suppose Assumption 1. Let F 0 and F ∞ : M ( R d ) → R be such that F 0 ( µ ) := 1 2 ∫ k 0 d ( µ ⊗ µ ) and F ∞ ( µ ) := -1 2 ∫ k ∞ log( k ∞ k 0 ) d ( µ ⊗ µ ) . Then k 0 , k 1 and k ∞ respectively generate the PDEs ∂µ ∂t +div( µT k µ ) = 0 with T 0 µ := -∇ W F 0 ( µ ) , T 1 µ := -∇ [log( ∫ k 0 ( · , x ′ ) dµ ( x ′ ))] and T ∞ µ := -∇ W F ∞ ( µ ) .
|
| 124 |
+
|
| 125 |
+
A proof is given in Appendix A. Proposition 2 shows that k 0 and k ∞ correspond to Wasserstein gradient flows. In addition, the PDE defined by k 1 does not correspond to such a flow. More precisely, we have the following result.
|
| 126 |
+
|
| 127 |
+
Proposition 3 (The SoftMax normalization does not correspond to a gradient flow) . One has that T 1 µ = -∇ [log( ∫ k 0 ( · , x ′ ) dµ ( x ′ ))] is not a Wasserstein gradient.
|
| 128 |
+
|
| 129 |
+
A proof is given in Appendix A, based on the lack of symmetry of T 1 µ . As a consequence of these results, we believe this variational formulation of attention mechanisms for Sinkformers (Proposition 2) provides a perspective for analyzing the theoretical properties of attention-based mechanisms in light of Wasserstein gradient flow theory (Santambrogio, 2017). Moreover, it makes it possible to interpret Sinkformers as argmin layers, which is promising in terms of theoretical and experimental investigations, and which is not possible for Transformers, according to Proposition 3.
|
| 130 |
+
|
| 131 |
+
Our results are complementary to the one of Dong et al. (2021), where the authors show that, with no skip connections and without the feed forward neural network acting after each attention block, the output of a Transformer converges doubly exponentially with depth to a rank-1 matrix. On the contrary, we propose a complementary analysis by taking skipconnections into account, as is standard in Transformers. Precisely because we consider such connections, we end up with very different behaviors. Indeed, as shown in the next section, our analysis reveals that the relative signs for W K , W Q and W V imply very different behavior, such as aggregation or diffusion. The dynamics obtained when considering skip connections are therefore richer than a rank collapse phenomenon.
|
| 132 |
+
|
| 133 |
+
## 5 Attention and diffusion
|
| 134 |
+
|
| 135 |
+
In this section, we use the same notations as in section 4. We consider the mean-field limit, where the measure µ has a density with respect to the Lebesgue measure. We are interested in how the density of particles evolves for an infinite depth self-attention network with tied weights between layers. We consider Assumption 1 and suppose that W ⊤ K W Q is positive semi-definite. For a bandwidth ε > 0, let k ∞ ε = Sinkhorn ( c/ε ), that is the attention kernel for the Sinkformer with the cost c/ε . The mapping T ∞ µ,ε : x ↦→ 1 ε ∫ k ∞ ε ( x, x ′ ) W V x ′ dµ ( x ′ ) corresponds to the continuous version of the Sinkformer where we rescale W Q W T K = -W V by ε . To better understand the dynamics of attention, we study the asymptotic regime in which the bandwidth ε → 0. In this regime, one can show that ∀ x ∈ R d , εT ∞ µ,ε ( x ) → W V x (details in Appendix A). Thus, to go beyond first order, we study the modified map T ∞ µ,ε = T ∞ µ,ε -1 ε W V . A natural question is the limit of this quantity when ε → 0, and what the PDE defined by this limit is. We have the following theorem.
|
| 136 |
+
|
| 137 |
+
Theorem 1 (Sinkformer's PDE) . Let µ ∈ M ( R d ) . Suppose that µ is supported on a compact set and has a density ρ ∈ C 3 ( R d ) . Suppose assumption 1 and that W ⊤ K W Q is positive semi-definite. Then one has in L 2 norm as ε → 0 ,
|
| 138 |
+
|
| 139 |
+
<!-- formula-not-decoded -->
|
| 140 |
+
|
| 141 |
+
In this limit, the PDE ∂ t ρ +div( ρT ∞ µ, 0 ) = 0 rewrites
|
| 142 |
+
|
| 143 |
+
<!-- formula-not-decoded -->
|
| 144 |
+
|
| 145 |
+
Aproof is available in Appendix A, making use of Theorem 1 from Marshall and Coifman (2019). We recover in Equation (6) the well-known heat equation .
|
| 146 |
+
|
| 147 |
+
We want to compare this result with the one obtained with the SoftMax normalization. In order to carry a similar analysis, we make use of a Laplace expansion result (Tierney et al., 1989; Singer, 2006). However, the kernel k 1 ε = SoftMax ( c/ε ) is not suited for using Laplace method because it does not always have a limit when ε → 0. Thus, we consider the modified cost as in Proposition 1, ˜ c ( x, x ′ ) = -‖ W Q x -W K x ′ ‖ 2 2 . The kernel ˜ k 1 ε = SoftMax (˜ c/ε ), for which we can now apply Laplace expansion result, then corresponds to the L2 self-attention formulation (Kim et al., 2021). Note that thanks to Proposition 1, ˜ k ∞ ε = k ∞ ε : Sinkorn's algorithm will have the same output for both costs. To simplify the expressions derived, we assume that W Q and W K are in R d × d and are invertible. Similarly to the analysis conducted for Sinkformers, we consider the mapping T 1 µ,ε : x ↦→ 1 ε ∫ ˜ k 1 ε ( x, x ′ ) W V x ′ dµ ( x ′ ). When ε → 0, we show that ∀ x ∈ R d , εT 1 µ,ε ( x ) → -W ⊤ Q W Q x (details in Appendix A). Thus, we consider T 1 µ,ε = T 1 µ,ε + 1 ε W ⊤ Q W Q . We have the following result. Proposition 4 (Transformer's PDE) . Let µ ∈ M ( R d ) . Suppose that µ is supported on a compact set and has a density ρ ∈ C 1 ( R d ) . Suppose assumption 1 and that W Q and W K are in R d × d and are invertible. Then one has ∀ x ∈ R d ,
|
| 148 |
+
|
| 149 |
+
<!-- formula-not-decoded -->
|
| 150 |
+
|
| 151 |
+
In this limit, the PDE ∂ t ρ +div( ρT 1 µ, 0 ) = 0 rewrites
|
| 152 |
+
|
| 153 |
+
<!-- formula-not-decoded -->
|
| 154 |
+
|
| 155 |
+
A proof is given in Appendix A. While equation (6) corresponds to the heat equation, equation (7) is different. First, it is nonlinear in ρ . Second, it is nonlocal since the evolution of the density at x depends on the value of this density at location W -1 K W Q x . Note that the linear and local aspect of Sinkformer's PDE on the one hand, and the nonlinear and nonlocal aspect of Transformer's PDE on the other hand, remain true without assuming W Q ⊤ W K = -W V (details in Appendix A).
|
| 156 |
+
|
| 157 |
+
## 6 Experiments
|
| 158 |
+
|
| 159 |
+
We now demonstrate the applicability of Sinkformers on a large variety of experiments with different modalities. We use Pytorch (Paszke et al., 2017) and Nvidia Tesla V100 GPUs. Our code is open-sourced and is available at this address: https://github. com/michaelsdr/sinkformers . All the experimental details are given in Appendix C.
|
| 160 |
+
|
| 161 |
+
Practical implementation. In all our experiments, we use existing Transformer architectures and modify the SoftMax operator in attention modules with Sinkhorn's algorithm, which we implement in log domain for stability (details in Appendix B).
|
| 162 |
+
|
| 163 |
+
## 6.1 ModelNet 40 classification
|
| 164 |
+
|
| 165 |
+
The ModelNet 40 dataset (Wu et al., 2015) is composed of 40 popular object categories in 3D. Transformers for point clouds and sets have been applied to the ModelNet 40 classification in several works, such as Set Transformers (Lee et al., 2019) or Point Cloud Transformers (Guo et al., 2021).
|
| 166 |
+
|
| 167 |
+
Set Sinkformers. Set Transformers (Lee et al., 2019) also have an encoder decoder structure with different possibilities for defining attention-based set operations. We propose to focus on the architecture that uses Induced Self Attention Block (ISAB), which bypasses the quadratic time complexity of Self Attention Blocks (SAB). More details about this architecture can be found in (Lee et al., 2019). We reproduce the ModelNet 40 classification experiment using 5000 uniformly sampled points for each shape and use a Set Transformer and a Set Sinkformer with two ISAB layers in the encoder and a decoder composed of a SAB and a Pooling by Multihead Attention (PMA) module. While the reported test accuracy is of 87 . 8% using a Set Transformer, we obtain as our best accuracy when performing 21 iterations of Sinkhorn algorithm within our Sinkformer of 89 . 1%. Results are summarized in Table 1.
|
| 168 |
+
|
| 169 |
+
Figure 3: Classification error and loss on ModelNet 40 when training a Set Transformer and a Set Sinkformer with different number of iterations in Sinkhorn's algorithm.
|
| 170 |
+
|
| 171 |
+
<!-- image -->
|
| 172 |
+
|
| 173 |
+
Moreover, we show in Figure 3 the learning curves corresponding to this experiment. Interestingly, the number of iterations within Sinkhorn's algorithm increases the accuracy of the model. Note that we only consider an odd number of iterations since we always want to have row-wise stochastic attention matrices to be consistent with the properties of the SoftMax.
|
| 174 |
+
|
| 175 |
+
Point Cloud Transformers. We also train Point Cloud Transformers (Guo et al., 2021) on ModelNet 40. This architecture achieves accuracy comparable to the state of the art on this dataset. We compare best and median test accuracy over 4 runs. Results are reported in Table 1, where we see that while the best test-accuracy is narrowly achieved for the Transformer, the Sinkformer has a slightly better median accuracy.
|
| 176 |
+
|
| 177 |
+
Table 1: Test accuracy for ModelNet 40 over 4 runs for each model.
|
| 178 |
+
|
| 179 |
+
| Model Best Median Mean Worst Set Transformer 87 . 8% 86 . 3% 85 . 8% 84 . 7% Set Sinkformer 89 . 1 % 88 . 4 % 88 . 3 % 88 . 1 % Point Cloud Transformer 93 . 2 % 92 . 5% 92 . 5% 92 . 3% Point Cloud Sinkformer 93 . 1% 92 . 8 % 92 . 7 % 92 . 5 % |
|
| 180 |
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 181 |
+
|
| 182 |
+
## 6.2 Sentiment Analysis
|
| 183 |
+
|
| 184 |
+
We train a Transformer (composed of an attentionbased encoder followed by a max-pooling layer) and a Sinkformer on the IMDb movie review dataset (Maas et al., 2011) for sentiment analysis. This text classification task consists of predicting whether a movie review is positive or negative. The learning curves are shown in Figure 4, with a gain in accuracy when using a Sinkformer. In this experiment, Sinkhorn's algorithm converges perfectly in 3 iterations (the resulting attention matrices are doubly stochastic), which corresponds to the green curve. The Sinkformer only adds a small computational overhead, since the training time per epoch is 4m 02s for the Transformer against 4m 22s for the Sinkformer.
|
| 185 |
+
|
| 186 |
+
## 6.3 Neural Machine Translation
|
| 187 |
+
|
| 188 |
+
We train a Transformer and its Sinkformer counterpart using the fairseq (Ott et al., 2019) sequence modeling toolkit on the IWSLT'14 German to English dataset (Cettolo et al., 2014). The architecture used is composed of an encoder and a decoder, both of depth 6. We plug Sinkhorn's algorithm only into the encoder part. Indeed, in the decoder, we can only pay attention to previous positions in the output sequence. For this reason, we need a mask that prevents a straightforward application of Sinkhorn's algorithm. We demonstrate that even when using the hyper-parameters used to optimally train the Transformer, we achieve a similar BLEU (Papineni et al., 2002) over 6 runs. We first train a Transformer for 30 epochs. On the evaluation set, we obtain a BLEU of 34 . 43. We then consider a Sinkformer with the weights of the trained Transformer. Interestingly, even this un-adapted Sinkformer provides a median BLEU score of 33 . 81. We then divide the learning rate by 10 and retrain for 5 additional epochs both the Transformer and the Sinkformer to obtain a median BLEU of respectively 34 . 68 and 34 . 73 (Table 2). Importantly, the runtime for one training epoch is almost the same for both models: 2m 48s (Transformer) against 2m 52s (Sinkformer).
|
| 189 |
+
|
| 190 |
+
Figure 4: Learning curves when training a Transformer and a Sinkformer on the Sentiment Analysis task on the IMDb Dataset.
|
| 191 |
+
|
| 192 |
+
<!-- image -->
|
| 193 |
+
|
| 194 |
+
Table 2: Median BLEU score over 6 runs on the IWSLT'14 German to English dataset. The score ⋆ is when evaluating the Sinkformer with the weights of the trained Transformer.
|
| 195 |
+
|
| 196 |
+
| Model Epoch 30 Epoch 35 Transformer 34 . 43 34 . 68 Sinkformer 33 . 81 ⋆ 34 . 73 |
|
| 197 |
+
|-----------------------------------------------------------------------------------------------------|
|
| 198 |
+
|
| 199 |
+
## 6.4 Vision Transformers
|
| 200 |
+
|
| 201 |
+
Vision Transformers (ViT) (Dosovitskiy et al., 2020) have recently emerged as a promising architecture for achieving state of the art performance on computer vision tasks (Zhai et al., 2021), using only attention based mechanisms by selecting patches of fixed size in images and feeding them into an attention mechanism.
|
| 202 |
+
|
| 203 |
+
Figure 5: Train (dotted) and test (plain) accuracy as a function of the number of epochs when training a ViT and its Sinkformer counterpart on the cats and dogs classification task (median over 5 runs).
|
| 204 |
+
|
| 205 |
+
<!-- image -->
|
| 206 |
+
|
| 207 |
+
Cats and dogs classification. We train a ViT and its Sinkformer counterpart on a binary cats and dogs image classification task. The evolution of the train and test accuracy is displayed in Figure 5. The median test accuracy is 79 . 0% for the Transformer against 79 . 5% for the Sinkformer, whereas the maximum test accuracy is 80 . 0% for the Transformer against 80 . 5% for the Sinkformer. We also use 3 iterations in Sinkhorn's algorithm which leads to a negligible computational overhead (training time per epoch of 3m 25s for the Sinkformer against 3m 20s for the Transformer).
|
| 208 |
+
|
| 209 |
+
## Impact of the patch size on the final accuracy.
|
| 210 |
+
|
| 211 |
+
We consider a one-layer and one-head self-attention module on the MNIST dataset, with no additional layer. The purpose is to isolate the self-attention module and study how its accuracy is affected by the choice of the patch size. Results are displayed in Figure 6. We recall that a MNIST image is of size 28 × 28. When taking only one patch of size 28, both models are equivalent because the attention matrix is of size 1. However, when the patch size gets smaller, the two models are different and the Sinkformer outperforms the Transformer.
|
| 212 |
+
|
| 213 |
+
Figure 6: Final test accuracy when training a one layer and one head self attention module on the MNIST dataset, with no feedforward neural network, when varying the patch size (median over 5 runs).
|
| 214 |
+
|
| 215 |
+
<!-- image -->
|
| 216 |
+
|
| 217 |
+
## Conclusion
|
| 218 |
+
|
| 219 |
+
In this paper, we presented the Sinkformer, a variant of the Transformer in which the SoftMax, which leads to row-wise stochastic attention, is replaced by Sinkhorn's algorithm, which leads to doubly stochastic attention. This new model is motivated by the empirical finding that attention matrices in Transformers get closer and closer to doubly stochastic matrices during the training process. This modification is easily implemented in practice by simply replacing the SoftMax in the attention modules of existing Transformers without changing any parameter in the network. It also provides a new framework for theoretically studying attention-based mechanisms, such as the interpretation of Sinkformers as Wasserstein gradient flows in the infinitesimal step size regime or as diffusion operators in the mean-field limit. On the experimental side, Sinkformers lead to better accuracy in a variety of experiments: classification of 3D shapes, sentiment analysis, neural machine translation, and image classification.
|
| 220 |
+
|
| 221 |
+
## Acknowledgments
|
| 222 |
+
|
| 223 |
+
This work was granted access to the HPC resources of IDRIS under the allocation 2020-[AD011012073] made by GENCI. This work was supported in part by the French government under management of Agence Nationale de la Recherche as part of the 'Investissements d'avenir' program, reference ANR19-P3IA-0001 (PRAIRIE 3IA Institute). This work was supported in part by the European Research Council (ERC project NORIA). We thank Marco Cuturi and D. Sculley for their comments on a draft of the paper. We thank Scott Pesme, Pierre Rizkallah, Othmane Sebbouh, Thibault S´ ejourn´ e and the anonymous reviewers for helpful feedbacks.
|
| 224 |
+
|
| 225 |
+
## References
|
| 226 |
+
|
| 227 |
+
- Agrawal, A., Amos, B., Barratt, S., Boyd, S., Diamond, S., and Kolter, Z. (2019). Differentiable convex optimization layers. arXiv preprint arXiv:1910.12430 .
|
| 228 |
+
- Bahdanau, D., Cho, K., and Bengio, Y. (2014). Neural machine translation by jointly learning to align and translate. arXiv preprint arXiv:1409.0473 .
|
| 229 |
+
- Bai, S., Kolter, J. Z., and Koltun, V. (2019). Deep equilibrium models. Advances in Neural Information Processing Systems , 32:690-701.
|
| 230 |
+
- Behrmann, J., Grathwohl, W., Chen, R. T., Duvenaud, D., and Jacobsen, J.-H. (2019). Invertible residual networks. In International Conference on Machine Learning , pages 573-582. PMLR.
|
| 231 |
+
- Blondel, M., Berthet, Q., Cuturi, M., Frostig, R., Hoyer, S., Llinares-L´ opez, F., Pedregosa, F., and Vert, J.-P. (2021). Efficient and modular implicit differentiation. arXiv preprint arXiv:2105.15183 .
|
| 232 |
+
- Brown, T. B., Mann, B., Ryder, N., Subbiah, M., Kaplan, J., Dhariwal, P., Neelakantan, A., Shyam, P., Sastry, G., Askell, A., et al. (2020). Language models are few-shot learners. arXiv preprint arXiv:2005.14165 .
|
| 233 |
+
- Cettolo, M., Niehues, J., St¨ uker, S., Bentivogli, L., and Federico, M. (2014). Report on the 11th iwslt evaluation campaign, iwslt 2014. In Proceedings of the International Workshop on Spoken Language Translation, Hanoi, Vietnam , volume 57.
|
| 234 |
+
- Charlier, B., Feydy, J., Glaun` es, J., Collin, F.-D., and Durif, G. (2021). Kernel operations on the gpu, with autodiff, without memory overflows. Journal of Machine Learning Research , 22(74):1-6.
|
| 235 |
+
- Chen, T. Q., Rubanova, Y., Bettencourt, J., and Duvenaud, D. K. (2018). Neural ordinary differential equations. In Advances in neural information processing systems , pages 6571-6583.
|
| 236 |
+
- Cuturi, M. (2013). Sinkhorn distances: Lightspeed computation of optimal transport. Advances in neural information processing systems , 26:2292-2300.
|
| 237 |
+
- Cuturi, M., Teboul, O., Niles-Weed, J., and Vert, J.P. (2020). Supervised quantile normalization for low rank matrix factorization. In International Conference on Machine Learning , pages 2269-2279. PMLR.
|
| 238 |
+
- De Bie, G., Peyr´ e, G., and Cuturi, M. (2019). Stochastic deep networks. In International Conference on Machine Learning , pages 1556-1565. PMLR.
|
| 239 |
+
- Dong, Y., Cordonnier, J.-B., and Loukas, A. (2021). Attention is not all you need: Pure attention loses rank doubly exponentially with depth. arXiv preprint arXiv:2103.03404 .
|
| 240 |
+
- Dosovitskiy, A., Beyer, L., Kolesnikov, A., Weissenborn, D., Zhai, X., Unterthiner, T., Dehghani, M., Minderer, M., Heigold, G., Gelly, S., et al. (2020). An image is worth 16x16 words: Transformers for image recognition at scale. arXiv preprint arXiv:2010.11929 .
|
| 241 |
+
- Gould, S., Fernando, B., Cherian, A., Anderson, P., Cruz, R. S., and Guo, E. (2016). On differentiating parameterized argmin and argmax problems with application to bi-level optimization. arXiv preprint arXiv:1607.05447 .
|
| 242 |
+
- Gould, S., Hartley, R., and Campbell, D. (2019). Deep declarative networks: A new hope. arXiv preprint arXiv:1909.04866 .
|
| 243 |
+
|
| 244 |
+
- Griewank, A. and Walther, A. (2008). Evaluating derivatives: principles and techniques of algorithmic differentiation . SIAM.
|
| 245 |
+
- Guo, M.-H., Cai, J.-X., Liu, Z.-N., Mu, T.-J., Martin, R. R., and Hu, S.-M. (2021). Pct: Point cloud transformer. Computational Visual Media , 7(2):187-199.
|
| 246 |
+
- He, K., Zhang, X., Ren, S., and Sun, J. (2016). Deep residual learning for image recognition. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 770-778.
|
| 247 |
+
- Hein, M., Audibert, J.-Y., and Luxburg, U. v. (2007). Graph laplacians and their convergence on random neighborhood graphs. Journal of Machine Learning Research , 8(6).
|
| 248 |
+
- Jordan, R., Kinderlehrer, D., and Otto, F. (1998). The variational formulation of the fokker-planck equation. SIAM journal on mathematical analysis , 29(1):1-17.
|
| 249 |
+
- Kim, H., Papamakarios, G., and Mnih, A. (2021). The lipschitz constant of self-attention. In International Conference on Machine Learning , pages 5562-5571. PMLR.
|
| 250 |
+
- Kingma, D. P. and Ba, J. (2014). Adam: A method for stochastic optimization. arXiv preprint arXiv:1412.6980 .
|
| 251 |
+
- Krantz, S. G. and Parks, H. R. (2012). The implicit function theorem: history, theory, and applications . Springer Science & Business Media.
|
| 252 |
+
- Lee, J., Lee, Y., Kim, J., Kosiorek, A., Choi, S., and Teh, Y. W. (2019). Set transformer: A framework for attention-based permutation-invariant neural networks. In International Conference on Machine Learning , pages 3744-3753. PMLR.
|
| 253 |
+
- Lu, Y., Zhong, A., Li, Q., and Dong, B. (2018). Beyond finite layer neural networks: Bridging deep architectures and numerical differential equations. In International Conference on Machine Learning , pages 3276-3285. PMLR.
|
| 254 |
+
- Luise, G., Rudi, A., Pontil, M., and Ciliberto, C. (2018). Differential properties of sinkhorn approximation for learning with wasserstein distance. arXiv preprint arXiv:1805.11897 .
|
| 255 |
+
- Maas, A. L., Daly, R. E., Pham, P. T., Huang, D., Ng, A. Y., and Potts, C. (2011). Learning word vectors for sentiment analysis. In Proceedings of the 49th Annual Meeting of the Association for Computational Linguistics: Human Language Technologies , pages 142-150, Portland, Oregon, USA. Association for Computational Linguistics.
|
| 256 |
+
- Marshall, N. F. and Coifman, R. R. (2019). Manifold learning with bi-stochastic kernels. IMA Journal of Applied Mathematics , 84(3):455-482.
|
| 257 |
+
- Mialon, G., Chen, D., d'Aspremont, A., and Mairal, J. (2021). A trainable optimal transport embedding for feature aggregation and its relationship to attention. In ICLR 2021-The Ninth International Conference on Learning Representations .
|
| 258 |
+
- Milanfar, P. (2013). Symmetrizing smoothing filters. SIAM Journal on Imaging Sciences , 6(1):263-284.
|
| 259 |
+
- Niculae, V., Martins, A., Blondel, M., and Cardie, C. (2018). Sparsemap: Differentiable sparse structured inference. In International Conference on Machine Learning , pages 3799-3808. PMLR.
|
| 260 |
+
- Ott, M., Edunov, S., Baevski, A., Fan, A., Gross, S., Ng, N., Grangier, D., and Auli, M. (2019). fairseq: A fast, extensible toolkit for sequence modeling. In Proceedings of NAACL-HLT 2019: Demonstrations .
|
| 261 |
+
- Papineni, K., Roukos, S., Ward, T., and Zhu, W.-J. (2002). Bleu: a method for automatic evaluation of machine translation. In Proceedings of the 40th annual meeting of the Association for Computational Linguistics , pages 311-318.
|
| 262 |
+
- Paszke, A., Gross, S., Chintala, S., Chanan, G., Yang, E., DeVito, Z., Lin, Z., Desmaison, A., Antiga, L., and Lerer, A. (2017). Automatic differentiation in pytorch.
|
| 263 |
+
- Peng, C., Zhang, X., Yu, G., Luo, G., and Sun, J. (2017). Large kernel matters-improve semantic segmentation by global convolutional network. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 4353-4361.
|
| 264 |
+
- Peyr´ e, G., Cuturi, M., et al. (2019). Computational optimal transport: With applications to data science. Foundations and Trends ® in Machine Learning , 11(5-6):355-607.
|
| 265 |
+
- Radford, A., Wu, J., Child, R., Luan, D., Amodei, D., Sutskever, I., et al. (2019). Language models are unsupervised multitask learners. OpenAI blog , 1(8):9.
|
| 266 |
+
- Renardy, M. and Rogers, R. C. (2006). An introduction to partial differential equations , volume 13. Springer Science & Business Media.
|
| 267 |
+
- Ruder, S. (2016). An overview of gradient descent optimization algorithms. arXiv preprint arXiv:1609.04747 .
|
| 268 |
+
- Ruthotto, L. and Haber, E. (2019). Deep neural networks motivated by partial differential equations. Journal of Mathematical Imaging and Vision , pages 1-13.
|
| 269 |
+
- Sander, M. E., Ablin, P., Blondel, M., and Peyr´ e, G. (2021). Momentum residual neural networks. In Proceedings of the 38th International Conference on Machine Learning , volume 139 of Proceedings of Machine Learning Research , pages 9276-9287. PMLR.
|
| 270 |
+
|
| 271 |
+
- Santambrogio, F. (2017). { Euclidean, metric, and Wasserstein } gradient flows: an overview. Bulletin of Mathematical Sciences , 7(1):87-154.
|
| 272 |
+
- Singer, A. (2006). From graph to manifold laplacian: The convergence rate. Applied and Computational Harmonic Analysis , 21(1):128-134.
|
| 273 |
+
- Sinkhorn, R. (1964). A relationship between arbitrary positive matrices and doubly stochastic matrices. The annals of mathematical statistics , 35(2):876879.
|
| 274 |
+
- Song, M., Montanari, A., and Nguyen, P. (2018). A mean field view of the landscape of two-layers neural networks. Proceedings of the National Academy of Sciences , 115:E7665-E7671.
|
| 275 |
+
- Sun, Q., Tao, Y., and Du, Q. (2018). Stochastic training of residual networks: a differential equation viewpoint. arXiv preprint arXiv:1812.00174 .
|
| 276 |
+
- Tay, Y., Bahri, D., Yang, L., Metzler, D., and Juan, D.-C. (2020). Sparse sinkhorn attention. In International Conference on Machine Learning , pages 9438-9447. PMLR.
|
| 277 |
+
- Teh, Y., Doucet, A., and Dupont, E. (2019). Augmented neural odes. Advances in Neural Information Processing Systems 32 (NIPS 2019) , 32(2019).
|
| 278 |
+
- Tierney, L., Kass, R. E., and Kadane, J. B. (1989). Fully exponential laplace approximations to expectations and variances of nonpositive functions. Journal of the american statistical association , 84(407):710-716.
|
| 279 |
+
- Ting, D., Huang, L., and Jordan, M. (2011). An analysis of the convergence of graph laplacians. arXiv preprint arXiv:1101.5435 .
|
| 280 |
+
- Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., Kaiser, glyph[suppress] L., and Polosukhin, I. (2017). Attention is all you need. In Advances in neural information processing systems , pages 59986008.
|
| 281 |
+
- Vuckovic, J., Baratin, A., and Combes, R. T. d. (2021). On the regularity of attention. arXiv preprint arXiv:2102.05628 .
|
| 282 |
+
- Wang, L., Ye, J., Zhao, Y., Wu, W., Li, A., Song, S. L., Xu, Z., and Kraska, T. (2018). Superneurons: Dynamic gpu memory management for training deep neural networks. In Proceedings of the 23rd ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming , pages 41-53.
|
| 283 |
+
- Weinan, E. (2017). A proposal on machine learning via dynamical systems. Communications in Mathematics and Statistics , 5(1):1-11.
|
| 284 |
+
- Weinan, E., Han, J., and Li, Q. (2019). A mean-field optimal control formulation of deep learning. Research in the Mathematical Sciences , 6(1):10.
|
| 285 |
+
- Wolf, T., Debut, L., Sanh, V., Chaumond, J., Delangue, C., Moi, A., Cistac, P., Rault, T., Louf, R., Funtowicz, M., et al. (2019). Huggingface's transformers: State-of-the-art natural language processing. arXiv preprint arXiv:1910.03771 .
|
| 286 |
+
- Wormell, C. L. and Reich, S. (2021). Spectral convergence of diffusion maps: Improved error bounds and an alternative normalization. SIAM Journal on Numerical Analysis , 59(3):1687-1734.
|
| 287 |
+
- Wu, Z., Song, S., Khosla, A., Yu, F., Zhang, L., Tang, X., and Xiao, J. (2015). 3d shapenets: A deep representation for volumetric shapes. In Proceedings of the IEEE conference on computer vision and pattern recognition , pages 1912-1920.
|
| 288 |
+
- Yun, C., Bhojanapalli, S., Rawat, A. S., Reddi, S. J., and Kumar, S. (2019). Are transformers universal approximators of sequence-to-sequence functions? arXiv preprint arXiv:1912.10077 .
|
| 289 |
+
- Zhai, X., Kolesnikov, A., Houlsby, N., and Beyer, L. (2021). Scaling vision transformers. arXiv preprint arXiv:2106.04560 .
|
| 290 |
+
- Zhao, H., Jiang, L., Jia, J., Torr, P., and Koltun, V. (2020). Point transformer. arXiv preprint arXiv:2012.09164 .
|
| 291 |
+
- Zhu, J.-Y., Park, T., Isola, P., and Efros, A. A. (2017). Unpaired image-to-image translation using cycleconsistent adversarial networks. In Proceedings of the IEEE international conference on computer vision , pages 2223-2232.
|
| 292 |
+
- Zweig, A. and Bruna, J. (2021). A functional perspective on learning symmetric functions with neural networks. In International Conference on Machine Learning , pages 13023-13032. PMLR.
|
| 293 |
+
|
| 294 |
+
## Appendix
|
| 295 |
+
|
| 296 |
+
In Section A we give the proofs of all the Propositions and the Theorem. In Section B we present the implementation details of Sinkformers. Section C gives details for the experiments in the paper.
|
| 297 |
+
|
| 298 |
+
## A Proofs
|
| 299 |
+
|
| 300 |
+
## A.1 Invariance to the cost function - Proof of Proposition 1
|
| 301 |
+
|
| 302 |
+
Proof. We use the variational formulation for Sinkhorn (Peyr´ e et al., 2019):
|
| 303 |
+
|
| 304 |
+
<!-- formula-not-decoded -->
|
| 305 |
+
|
| 306 |
+
<!-- formula-not-decoded -->
|
| 307 |
+
|
| 308 |
+
with
|
| 309 |
+
|
| 310 |
+
where K 0 i,j = exp( C i,j ).
|
| 311 |
+
|
| 312 |
+
We let ˜ C i,j = C ij + f i + g j . We have for K ∈ U := { K | K 1 n = K ⊤ 1 n = 1 n } that KL( K | e ˜ C ) = ∑ i,j K i,j log( K i,j e Ci,j + f i + g j ). This gives
|
| 313 |
+
|
| 314 |
+
so that
|
| 315 |
+
|
| 316 |
+
<!-- formula-not-decoded -->
|
| 317 |
+
|
| 318 |
+
This shows that KL( K | e ˜ C ) and KL( K | e C ) have the same argmin on U which implies that Sinkhorn ( C ) = Sinkhorn ( ˜ C ).
|
| 319 |
+
|
| 320 |
+
## A.2 PDEs associated with k 0 , k 1 , k ∞ - Proof of Proposition 2
|
| 321 |
+
|
| 322 |
+
Proof. Recall that for p ∈ { 0 , 1 , ∞} , we have T p µ ( x ) = ∫ k p ( x, x ′ ) W V x ′ dµ ( x ′ ).
|
| 323 |
+
|
| 324 |
+
For h ∈ C ( R d × R d ) consider
|
| 325 |
+
|
| 326 |
+
Then we have (Santambrogio, 2017)
|
| 327 |
+
|
| 328 |
+
<!-- formula-not-decoded -->
|
| 329 |
+
|
| 330 |
+
<!-- formula-not-decoded -->
|
| 331 |
+
|
| 332 |
+
We can now derive the different gradient expressions for T 0 µ , T 1 µ and T ∞ µ .
|
| 333 |
+
|
| 334 |
+
For T 0 µ : under Assumption 1, we have that f ( x, x ′ ) = e C ( x,x ′ ) is symmetric. This gives
|
| 335 |
+
|
| 336 |
+
<!-- formula-not-decoded -->
|
| 337 |
+
|
| 338 |
+
and by differentiation under the integral, under sufficient regularity assumptions on µ , this gives
|
| 339 |
+
|
| 340 |
+
<!-- formula-not-decoded -->
|
| 341 |
+
|
| 342 |
+
Since ∇ x c ( x, x ′ ) = -W V x ′ , we get
|
| 343 |
+
|
| 344 |
+
<!-- formula-not-decoded -->
|
| 345 |
+
|
| 346 |
+
For µ = 1 n ∑ n i =1 δ x i this is exactly
|
| 347 |
+
|
| 348 |
+
For T 1 µ : we have
|
| 349 |
+
|
| 350 |
+
<!-- formula-not-decoded -->
|
| 351 |
+
|
| 352 |
+
For T 2 µ : one has the dual formulation for F ∞ (Peyr´ e et al., 2019):
|
| 353 |
+
|
| 354 |
+
<!-- formula-not-decoded -->
|
| 355 |
+
|
| 356 |
+
where we denote the soft c transform as
|
| 357 |
+
|
| 358 |
+
<!-- formula-not-decoded -->
|
| 359 |
+
|
| 360 |
+
which actually depends on µ and c . One has for an optimal pair f = f c (Peyr´ e et al., 2019). In addition, one has k ∞ ( x, x ′ ) = e c ( x,x ′ )+ f ( x )+ f ( x ′ ) . The Wasserstein gradient of F ∞ is then
|
| 361 |
+
|
| 362 |
+
<!-- formula-not-decoded -->
|
| 363 |
+
|
| 364 |
+
where f is an optimal solution of (8) (which is unique up to a constant). The gradient of f can be obtained using (9) and the fact that f = f c :
|
| 365 |
+
|
| 366 |
+
<!-- formula-not-decoded -->
|
| 367 |
+
|
| 368 |
+
This finally gives
|
| 369 |
+
|
| 370 |
+
that is what we wanted to show.
|
| 371 |
+
|
| 372 |
+
## A.3 The SoftMax normalization does not correspond to a gradient flow - Proof of Proposition 3
|
| 373 |
+
|
| 374 |
+
Proof. Suppose by contradiction that T 1 µ = -∇ [log( ∫ k 0 ( · , x ′ ) dµ ( x ′ ))] is a Wasserstein gradient. This implies that there exists a function F such that, ∀ µ ∈ M ( R d ) and ∀ x ∈ R d ,
|
| 375 |
+
|
| 376 |
+
<!-- formula-not-decoded -->
|
| 377 |
+
|
| 378 |
+
<!-- formula-not-decoded -->
|
| 379 |
+
|
| 380 |
+
̸
|
| 381 |
+
|
| 382 |
+
∀ x, x ′ ∈ R d . However, δ 2 F δµ 2 ( µ ) is symmetric for all µ ∈ M ( R d ). The relationship δ 2 F δµ 2 ( µ )( x, x ′ ) = δ 2 F δµ 2 ( µ )( x ′ , x ) then implies that for all µ , x and x ′ such that k 0 ( x, x ′ ) = 0 we have
|
| 383 |
+
|
| 384 |
+
<!-- formula-not-decoded -->
|
| 385 |
+
|
| 386 |
+
Taking µ = δ y gives k 0 ( x, y ) = k 0 ( x ′ , y ), which by symmetry implies that k 0 is a constant.
|
| 387 |
+
|
| 388 |
+
This is a contradiction since k 0 ( x, x ′ ) = exp( x ⊤ W ⊤ Q W K x ′ ).
|
| 389 |
+
|
| 390 |
+
We therefore have
|
| 391 |
+
|
| 392 |
+
<!-- formula-not-decoded -->
|
| 393 |
+
|
| 394 |
+
<!-- formula-not-decoded -->
|
| 395 |
+
|
| 396 |
+
## A.4 Sinkformer's PDE - Proof of Theorem 1
|
| 397 |
+
|
| 398 |
+
Proof. Since W ⊤ Q W K is positive-definite we write it W ⊤ Q W K = A 2 where A is positive-definite. Note that thanks to Proposition 1, if κ ε ( x, x ′ ) = exp( -‖ x -x ′ ‖ 2 2 ε ), one has under Assumption 1 that κ ∞ ε ( Ax,Ax ′ ) = k ∞ ε ( x, x ′ ). For x ∈ R d , we have
|
| 399 |
+
|
| 400 |
+
<!-- formula-not-decoded -->
|
| 401 |
+
|
| 402 |
+
We perform the change of variable y = Ax ′ . This gives
|
| 403 |
+
|
| 404 |
+
<!-- formula-not-decoded -->
|
| 405 |
+
|
| 406 |
+
where C A depends only on A . We then apply Theorem 1 from Marshall and Coifman (2019) with f = W V A -1 , q ( x ) = ρ ( A -1 x ) and w = 1 C A , to obtain that
|
| 407 |
+
|
| 408 |
+
<!-- formula-not-decoded -->
|
| 409 |
+
|
| 410 |
+
in L 2 norm. Since q ( x ) = ρ ( A -1 x ) we have obtained that ∇ q q = A -1 ∇ ρ ρ ( A -1 · ) so that
|
| 411 |
+
|
| 412 |
+
<!-- formula-not-decoded -->
|
| 413 |
+
|
| 414 |
+
<!-- formula-not-decoded -->
|
| 415 |
+
|
| 416 |
+
which is exactly what we wanted to show. Note that when W V = -W ⊤ Q W K this gives the expected result. The general form for the PDE is then
|
| 417 |
+
|
| 418 |
+
<!-- formula-not-decoded -->
|
| 419 |
+
|
| 420 |
+
<!-- formula-not-decoded -->
|
| 421 |
+
|
| 422 |
+
In other words,
|
| 423 |
+
|
| 424 |
+
which gives
|
| 425 |
+
|
| 426 |
+
<!-- formula-not-decoded -->
|
| 427 |
+
|
| 428 |
+
## A.5 Transformer's PDE - Proof of Proposition 4
|
| 429 |
+
|
| 430 |
+
Proof. Let x ∈ R d and consider
|
| 431 |
+
|
| 432 |
+
<!-- formula-not-decoded -->
|
| 433 |
+
|
| 434 |
+
We perform the change of variable y = W K x ′ . This gives:
|
| 435 |
+
|
| 436 |
+
<!-- formula-not-decoded -->
|
| 437 |
+
|
| 438 |
+
Using the Laplace expansion result from Singer (2006), we obtain that
|
| 439 |
+
|
| 440 |
+
<!-- formula-not-decoded -->
|
| 441 |
+
|
| 442 |
+
By doing a Taylor expansion for the denominator, we find
|
| 443 |
+
|
| 444 |
+
<!-- formula-not-decoded -->
|
| 445 |
+
|
| 446 |
+
and
|
| 447 |
+
|
| 448 |
+
<!-- formula-not-decoded -->
|
| 449 |
+
|
| 450 |
+
Since T 1 µ,ε = T 1 µ,ε + 1 ε W ⊤ Q W Q = 1 ε ( g ε ( W Q x ) + W ⊤ Q W Q x ) and because W V W -1 K = -W Q ⊤ W K W -1 K = -W ⊤ Q we have
|
| 451 |
+
|
| 452 |
+
<!-- formula-not-decoded -->
|
| 453 |
+
|
| 454 |
+
which is exactly the expected result.
|
| 455 |
+
|
| 456 |
+
## B Implementation details
|
| 457 |
+
|
| 458 |
+
We implement Sinkhorn's algorithm in log domain for stability. Given a matrix K 0 ∈ R n × n such that K 0 i,j = e C i,j for some C ∈ R n × n , Sinkhorn's algorithm (3) approaches ( f, g ) ∈ R n × R n such that K ∞ = diag( e f ∞ ) K 0 diag( e g ∞ ) by iterating in log domain, starting from g 0 = 0 n ,
|
| 459 |
+
|
| 460 |
+
<!-- formula-not-decoded -->
|
| 461 |
+
|
| 462 |
+
<!-- formula-not-decoded -->
|
| 463 |
+
|
| 464 |
+
<!-- formula-not-decoded -->
|
| 465 |
+
|
| 466 |
+
This allows for fast and accurate computations, where log( Ke g l ) and log( K ⊤ e f l ) are computed using log-sum-exp .
|
| 467 |
+
|
| 468 |
+
## C Experimental details
|
| 469 |
+
|
| 470 |
+
## C.1 ModelNet 40 classification
|
| 471 |
+
|
| 472 |
+
Set Transformers. For our experiments on ModelNet using Set Transformers, we first prepossess the ModelNet 40 dataset. We then uniformly sample 5000 points from each element in the dataset. Our architecture is composed of two ISAB layers in the encoder and a decoder composed of a SAB and a Pooling by Multihead Attention (PMA) module. For the training, we use a batch-size of 64 and we use Adam (Kingma and Ba, 2014). The training is done over 300 epochs. The initial learning rate is 10 -3 and is decayed by a factor 10 after 200 epochs.
|
| 473 |
+
|
| 474 |
+
Point Cloud Transformers. For our experiments on ModelNet using Point Clouds Transformers, we uniformly sample 1024 points from each element in the dataset. For the training, we use a batch-size of 32 and we use SGD (Ruder, 2016). The training is done over 300 epochs. The initial learning rate is 10 -4 and is decayed by a factor 10 after 250 epochs.
|
| 475 |
+
|
| 476 |
+
## C.2 Sentiment Analysis
|
| 477 |
+
|
| 478 |
+
We use the code available at the repository nlp-turorial 1 , where a pretrained Transformer is fine-tuned on the IMDb dataset. In our experiment, we reset the parameters of the pretrained Transformer and train it from scratch on the IMDb dataset. We use an architecture of depth 6, with 8 heads. For the training, we use a batch-size of 32 and we use Adam. The training is done over 15 epochs. The initial learning rate is 10 -4 and is decayed by a factor 10 after 12 epochs.
|
| 479 |
+
|
| 480 |
+
## C.3 Neural Machine Translation
|
| 481 |
+
|
| 482 |
+
We use the Transformer from fairseq and the command for training it on the IWSLT'14 2 dataset. When fine-tuning a Sinkformer, we simply divide the original learning rate by 10.
|
| 483 |
+
|
| 484 |
+
1 https://github.com/lyeoni/nlp-tutorial/tree/master/text-classification-transformer
|
| 485 |
+
|
| 486 |
+
2 https://github.com/pytorch/fairseq/blob/main/examples/translation/README.md
|
| 487 |
+
|
| 488 |
+
## C.4 Vision Transformers
|
| 489 |
+
|
| 490 |
+
Cats and dogs classification. This experiment is done on the cats and dogs 3 dataset. For this experiment, we use a batch-size of 64 and Adam. We use an architecture of depth 6, with 8 heads, and select a patch-size of 16. The training is done over 300 epochs. The initial learning rate is 5 × 10 -5 and divided by 10 after 250 epochs.
|
| 491 |
+
|
| 492 |
+
Impact of the patch size on the final accuracy. For this experiment, we use a batch-size of 100 and Adam. We use an architecture of depth 1, with 1 heads, without non-linearity, and select different values for the patch-size. The training is done over 45 epochs. The initial learning rate is 1 × 10 -3 (resp. 2 × 10 -3 ) for the Transformer (resp. Sinkformer) and divided by 10 after 35 epochs and again by 10 after 41 epochs.
|
| 493 |
+
|
| 494 |
+
3 https://www.kaggle.com/c/dogs-vs-cats/data
|
text-versions/attention-markdown/2111.05498_Attention Approximates Sparse Distribute.md
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
text-versions/attention-markdown/2201.10801_When Shift Operation Meets Vision Transf.md
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2201.10801 When Shift Operation Meets Vision Transf
|
| 2 |
+
|
| 3 |
+
## When Shift Operation Meets Vision Transformer: An Extremely Simple Alternative to Attention Mechanism
|
| 4 |
+
|
| 5 |
+
Guangting Wang 1 * , Yucheng Zhao 1 * , Chuanxin Tang 2 * , Chong Luo 2 , Wenjun Zeng 2
|
| 6 |
+
|
| 7 |
+
1 University of Science and Technology of China 2 Microsoft Research Asia
|
| 8 |
+
|
| 9 |
+
## Abstract
|
| 10 |
+
|
| 11 |
+
Attention mechanism has been widely believed as the key to success of vision transformers (ViTs), since it provides a flexible and powerful way to model spatial relationships. However, is the attention mechanism truly an indispensable part of ViT? Can it be replaced by some other alternatives? To demystify the role of attention mechanism, we simplify it into an extremely simple case: ZERO FLOP and ZERO parameter. Concretely, we revisit the shift operation. It does not contain any parameter or arithmetic calculation. The only operation is to exchange a small portion of the channels between neighboring features. Based on this simple operation, we construct a new backbone network, namely ShiftViT, where the attention layers in ViT are substituted by shift operations. Surprisingly, ShiftViT works quite well in several mainstream tasks, e.g., classification, detection, and segmentation. The performance is on par with or even better than the strong baseline Swin Transformer. These results suggest that the attention mechanism might not be the vital factor that makes ViT successful. It can be even replaced by a zeroparameter operation. We should pay more attentions to the remaining parts of ViT in the future work. Code is available at github.com/microsoft/SPACH.
|
| 12 |
+
|
| 13 |
+
## Introduction
|
| 14 |
+
|
| 15 |
+
Designing backbone networks plays a fundamental role in computer vision. Since the revolutionary progress of AlexNet (Krizhevsky, Sutskever, and Hinton 2012), convolution neural networks (CNNs) have dominated this area for nearly 10 years. However, the recently developed Vision Transformers (ViTs) have shown potential to challenge this throne. The advantage of ViT was first demonstrated in image classification task (Dosovitskiy et al. 2020), where the ViT backbone outperforms its CNN counterparts by a remarkable margin. Thanks to the promising results, the flourish of ViT variants rapidly broadcasts to many other computer vision tasks, such as object detection, semantic segmentation, and action recognition.
|
| 16 |
+
|
| 17 |
+
Despite the impressive performances of recent ViT variants, it is still not yet clear what makes ViT good for vi- sual recognition tasks. Some conventional wisdom leans to credit the success to the attention mechanism, since it provides a flexible and powerful way to model spatial relationships. Concretely, the attention mechanism leverages a selfattention matrix to aggregate features from arbitrary locations. Compared with the convolution operation in CNN, it has two significant strengths. First, this mechanism opens a possibility to simultaneously capture both short- and longranged dependencies, and get rid of the local restriction of the convolution. Second, the interaction between two spatial locations dynamically depends on their own features, rather than a fixed convolutional kernel. Due to such good properties, some pieces of work believe it is the attention mechanism that facilitates the powerful expressive ability of ViTs.
|
| 18 |
+
|
| 19 |
+
* These authors contributed equally.
|
| 20 |
+
|
| 21 |
+
† This work was done during the internship of Guangting and Yucheng at MSRA
|
| 22 |
+
|
| 23 |
+
Copyright © 2022, Association for the Advancement of Artificial Intelligence (www.aaai.org). All rights reserved.
|
| 24 |
+
|
| 25 |
+
Figure 1: An illustration of our shift building block. We propose to replace the attention layer with a simple shift operation in vision transformers. It spatially shifts a small portion of the channels along four directions, and the rest of the channels remain unchanged.
|
| 26 |
+
|
| 27 |
+
<!-- image -->
|
| 28 |
+
|
| 29 |
+
However, are these two advantages truly the key to success? The answer is probably NOT. Some existing work proves that, even without these properties, the ViT variants can still work well. For the first one, the fully-global dependencies may not be inevitable. More and more ViTs introduce a local attention mechanism to restrict their attention scope within a small local region, e.g., Swin Transformer (Liu et al. 2021b) and Local ViT (Li et al. 2021). The experiments show that the performance does not drop due to the local restriction. Besides, another line of research investigates the necessity of the dynamic aggregation. MLP-Mixer (Tolstikhin et al. 2021) proposes to substitute the attention layer with a linear projection layer, where the linear weights are not dynamically generated. In this case, it can still reach a leading performance on the ImageNet dataset.
|
| 30 |
+
|
| 31 |
+
Nowthat both global and dynamic properties might not be crucial for the ViT framework, what is the essential reason for the success of ViT? To figure it out, we further simplify the attention layer into an extremely simple case: NO global scope, NO dynamics, and even NO parameter and NO arithmetic calculation . We desire to know whether ViT can retain the good performance under this extreme case.
|
| 32 |
+
|
| 33 |
+
Conceptually, this zero-parameter alternative must rely on the handcrafted rule to model spatial relationships. In this work, we revisit the shift operation, which we believe is one of the simplest spatial modeling module. As depicted in Figure 1, the standard ViT building block consists of two parts: the attention layer and the feed-forward network (FFN). We replace the former attention layer with a shift operation, while keeping the latter FFN part untouched. Given an input feature, the proposed building block will first shift a small portion of the channels along four spatial directions, namely left, right, top, and down. As such, the information of neighboring features is explicitly mingled by the shifted channels. Then, the subsequent FFN performs channel-wise mixing to further fuse the information from neighbors.
|
| 34 |
+
|
| 35 |
+
Based on this shift building block, we construct a ViT-like backbone network, namely ShiftViT. Surprisingly, this backbone can also work well for the mainstream visual recognition tasks. The performance is on par with or even better than the strong Swin Transformer baseline. Concretely, within the same computational budgets as Swin-T model, our ShiftViT achieves a top-1 classification accuracy of 81.7% (against Swin-T's 81.3%) on ImageNet dataset. For the dense prediction task, it attains a mean average precision (mAP) score of 45.7% (against Swin-T's 43.7%) on COCO detection dataset, and a mean IoU (mIoU) score of 46.3% (against Swin-T's 44.5%) on ADE20k segmentation dataset.
|
| 36 |
+
|
| 37 |
+
Since the shift operation is already the simplest spatial modelling module, the excellent performance must come from the remaining components, e.g., the linear layers and the activation function in FFN. These components are less studied in existing work, because they look trivial. However, to further demystify the reasons why ViT works, we argue that we should pay more attentions to these components, instead of just focusing on the attention mechanism. We hope our work can shed a new light on the ViT research. As a summary, the contributions of this work are two folds:
|
| 38 |
+
|
| 39 |
+
- We present a ViT-like backbone, where the vanilla attention layer is replaced by an extremely simple shift operation. The proposed model can achieve an even better performance than Swin Transformer.
|
| 40 |
+
- We analyze the reasons behind the success of ViTs. It hints that the attention mechanism might not be the vital
|
| 41 |
+
|
| 42 |
+
factor that makes ViT work. We should take the remaining components seriously in the future study of ViTs.
|
| 43 |
+
|
| 44 |
+
## Related Work
|
| 45 |
+
|
| 46 |
+
## Attention and Vision Transformers
|
| 47 |
+
|
| 48 |
+
Transformer architecture (Vaswani et al. 2017) is first introduced in the area of natural language processing (NLP). It solely adopts attention mechanism to build the connections between different language tokens. Thanks to the great performance, Transformers have rapidly dominated the NLP area and become the de facto standard.
|
| 49 |
+
|
| 50 |
+
Inspired by the successful application in NLP, attention mechanism has also received increasing interests from the computer vision community. The early explorations can be roughly divided into two categories. On the one hand, some literature considers attention as a plug-and-play module, which can be seamlessly integrated into the existing CNN architectures. The representative work includes non-local network (Wang et al. 2018), relation network (Hu et al. 2018), and CCNet (Huang et al. 2019). On the other hand, some pieces of work aim to substitute all convolution operations with the attention mechanism, such as local relation network (Hu et al. 2019) and self-attention network (Zhao, Jia, and Koltun 2020).
|
| 51 |
+
|
| 52 |
+
Although these two kinds of work have shown promising results, they are still built on the CNN architecture. ViT (Dosovitskiy et al. 2020) is the pioneering work that leverages a pure transformer architecture for visual recognition tasks. Thanks to its impressive performance, the community recently bursts out a rising wave of research on vision transformers. Along this line of research, the main focus is to improve the attention mechanism, so that it can satisfy the intrinsic properties of visual signals. For example, MSViT (Fan et al. 2021) builds hierarchical attention layers to obtain multi-scale features. Swin Transformers (Liu et al. 2021b) introduces a locality constrain into its attention mechanism. The related efforts also include pyramid attention (Wang et al. 2021), local-global attention (Li et al. 2021), cross attention (Chen, Fan, and Panda 2021), to name a few.
|
| 53 |
+
|
| 54 |
+
Unlike the particular interests in attention mechanism, the remaining components of ViT are less studies. DeiT (Touvron et al. 2020) has setup a standard training pipeline for vision transformers. Most follow-up work inherits its setting, and only make some modifications on the attention mechanism. Our work also follows this paradigm. However, the goal of this work is not to complex the design of attention. On the contrary, we aim to show that the attention mechanism might not be the critical part of making ViTs work. It can be even replaced by an extremely simple shift operation. We hope these results can inspire researchers to rethink the role of attention mechanism.
|
| 55 |
+
|
| 56 |
+
## MLP Variants
|
| 57 |
+
|
| 58 |
+
Our work is related to the recent multi-layer-perceptron (MLP) variants. Specifically, MLP variants propose to extract image features through a pure MLP-like architecture. They also jump out of the attention-based framework in ViT. For example, instead of using the self-attention matrix, MLP-Mixer (Tolstikhin et al. 2021) introduces a tokenmixing MLP to directly connect all spatial locations. It eliminates the dynamic property of ViT, but without losing accuracy. The follow-up work investigates more MLP designs, like the spatial gating unit (Liu et al. 2021a) or cyclic connection (Chen et al. 2021).
|
| 59 |
+
|
| 60 |
+
Figure 2: (a) The overall architecture of our ShiftViT. We follow Swin Transformer (Liu et al. 2021b) to build hierarchical representations. (b) The detail design of a shift block. We only use a simple shift operation to model spatial relationships.
|
| 61 |
+
|
| 62 |
+
<!-- image -->
|
| 63 |
+
|
| 64 |
+
Our ShiftViT can be also categorized into the pure MLP architecture, where the shift operation is viewed as a special token-mixing layer. Compared with the existing MLP work, our shift operation is even much simpler, since it contains no parameter and no FLOP. Moreover, the vanilla MLP variants fail to handle variable input size because of the fixed linear weights. Our shift operation overcomes this obstacle and therefore make the backbone feasible for more vision tasks like object detection and semantic segmentation.
|
| 65 |
+
|
| 66 |
+
## Shift Operation
|
| 67 |
+
|
| 68 |
+
Shift operation is not new in computer vision. As early as in 2017, it was proposed to be an efficient alternative to the spatial convolution operation (Wu et al. 2018). Concretely, it uses a sandwich-like architecture, two 1 × 1 convolutions and a shift operation, to approximate a K × K convolution. In the follow-up work, the shift operation is further extended into different variants, such as active shift (Jeon and Kim 2018), sparse shift (Chen et al. 2019) and partial shift (Lin, Gan, and Han 2019).
|
| 69 |
+
|
| 70 |
+
In this work, we adopt the partial shift operation (Lin, Gan, and Han 2019). It is notable that the goal of this work is not to present a novel operation. Instead of that, we integrate the existing shift operation with the popular ViT to verify the effectiveness of attention mechanism. The similar vision are shared with the concurrent work ShiftMLP (Yu et al. 2021) and AS-MLP (Lian et al. 2021), but the design details are quite different. Their building blocks are more complex, which involve some auxiliary layers like pre-transformation and post-transformation.
|
| 71 |
+
|
| 72 |
+
## Shift Operation Meets Vision Transformer Architecture Overview
|
| 73 |
+
|
| 74 |
+
For a fair comparison, we follow the architecture of Swin Transformer (Liu et al. 2021b). The architecture overview is illustrated in Figure 2 (a). Specifically, given an input image of shape H × W × 3 , it first splits the images into nonoverlapping patches. The patch size is 4 × 4 pixels. Therefore, the output of patch partition is is H 4 × W 4 tokens, where each token has a channel size of 48 .
|
| 75 |
+
|
| 76 |
+
The modules followed by can be divided into 4 stages. Each stage contains two parts: embedding generation and stacked shift blocks. For the embedding generation of the first stage, a linear projection layer is used to map each token into an embedding of channel size C . For the rest stages, we merge neighbouring patches through the convolution with a kernel size of 2 × 2 . After patch merging, the spatial size of the output is half down-sampled, while channel size is twice the input, i.e., from C to 2 C .
|
| 77 |
+
|
| 78 |
+
The stacked shift block is built by some repeated basic units. The detail design of each shift block is shown in Figure 2 (b). It composes of a shift operation, a layer normalization and a MLP network. This design is almost the same as the standard transformer block. The only difference is that we use a shift operation rather than a attention layer. For each stage, the number of shift blocks can be various, which is denoted as N 1 , N 2 , N 3 , N 4 respectively. In out implementation, we carefully choose the value of N i so that the overall model share a similar number of parameters with the baseline Swin Transformer model.
|
| 79 |
+
|
| 80 |
+
## Shift Block
|
| 81 |
+
|
| 82 |
+
The detail architecture of our shift block is depicted in Figure 2 (b). Specifically, this block consists of three sequentially-stacked components: shift operation, layer normalization and MLP network.
|
| 83 |
+
|
| 84 |
+
Shift operation has been well studied in CNNs. It can have many design choices, such as active shift (Jeon and Kim 2018) and sparse shift (Chen et al. 2019). In this work, we follow the partial shift operation in TSM (Lin, Gan, and Han 2019). The illustration is presented in Figure 1 (b). Given an input tensor, a small portion of channels will be shifted along 4 spatial directions, namely left, right, top, and down, while the remaining channels keep unchanged. After shifting, the out-of-scope pixels are simply dropped and the vacant pixels are zero padded. In this work, the shift step is set to 1 pixel.
|
| 85 |
+
|
| 86 |
+
Formally, we assume that the input feature z is of shape H × W × C , where C is the number of channels, H and W are spatial height and width, respectively. The output feature ˆ z has the same shape as input. It can be written as:
|
| 87 |
+
|
| 88 |
+
```
|
| 89 |
+
ˆ z [0 : H, 1 : W, 0 : γC ] ← z [0 : H, 0 : W -1 , 0 : γC ] ˆ z [0 : H, 0 : W -1 , γC : 2 γC ] ← z [0 : H, 1 : W,γC : 2 γC ] ˆ z [0 : H -1 , 0 : W, 2 γC : 3 γC ] ← z [1 : H, 0 : W, 2 γC : 3 γC ] ˆ z [1 : H, 0 : W, 3 γC : 4 γC ] ← z [0 : H -1 , 0 : W, 3 γC : 4 γC ] ˆ z [0 : H, 0 : W, 4 γC : C ] ← z [0 : H, 0 : W, 4 γC : C ]
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
where γ is a ratio factor to control how many percentages of channels will be shifted. In most experiments, the value of γ is set to 1 12 .
|
| 93 |
+
|
| 94 |
+
It is notable that shift operation does not hold any parameter or arithmetic calculation. The only implementation is memory copying. Therefore, shift operation is highly efficient and it is very easy to implement. The pseudo code is presented in Algorithms 1. Compared with the self-attention mechanism, shift operation is clean, neat, and more friendly to deep learning inference library like TensorRT.
|
| 95 |
+
|
| 96 |
+
The rest of the shift block is the same as the standard building block of ViT. The MLP network has two linear layers. The first one increases the channel of the input feature to a higher dimension, e.g., from C to τC . Then the second linear layer projects the high-dimensional feature into the original channel size of C . Between these two layers, we adopt GELU as the non-linear activation function.
|
| 97 |
+
|
| 98 |
+
## Architecture Variants
|
| 99 |
+
|
| 100 |
+
For a fair comparison with the baseline Swin Transformer, we also build multiple models with various number of parameters and computational complexity. Specifically, we introduce Shift-T(iny), Shift-S(mall), Shift-B(ase) variants 1 , which is corresponded to Swin-T, Swin-S and Swin-B, respectively. Shift-T is the smallest one, which shares a similar size with Swin-T and ResNet-50. Another two variants, Shift-S and Shift-B, are roughly 2 × and 4 × more complex than ShiftViT-T. The detail configurations of basic embedding channels C and number of blocks { N i } are presented as following:
|
| 101 |
+
|
| 102 |
+
- Shift-T: C = 96 , { N } = { 6 , 8 , 18 , 6 } , γ = 1 /
|
| 103 |
+
- Shift-S: C = 96 , { N } = { 10 , 18 , 36 , 10 } , γ = 1 /
|
| 104 |
+
- Shift-B: C = 128 , { N i } = { 10 , 18 , 36 , 10 } , γ = 1 /
|
| 105 |
+
|
| 106 |
+
```
|
| 107 |
+
i 12 i 12 16
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
Beside the model size, we also have a closer look at the model depth. In our proposed model, nearly all parameters are concentrated in the MLP part. Therefore, we can control the expand ratio of MLP τ to obtain a deeper network depth. If not specified, the expand ratio τ is set to 2. We have an ablation analysis to show that the deeper model achieve a better performance.
|
| 111 |
+
|
| 112 |
+
1 For simplification, we ignore the suffix of 'ViT' and use ShiftT to denote ShiftViT-T in this work.
|
| 113 |
+
|
| 114 |
+
## Algorithm 1: Pytorch-like pseudo code of shift
|
| 115 |
+
|
| 116 |
+
```
|
| 117 |
+
1 def shift(feat, gamma=1/12): 2 # feat is a tensor with a shape of 3 # [Batch, Channel, Height, Width] 4 B, C, H, W = feat.shape 5 g = int(gamma * C) 6 out = zeros_like(feat) 7 # spatially shift 8 out[:, 0*g:1*g, :, :-1] = x[:, 0*g:1*g, :, 1:] 9 out[:, 1*g:2*g, :, 1:] = x[:, 1*g:2*g, :, :-1] 10 out[:, 2*g:3*g, :-1, :] = x[:, 2*g:3*g, 1:, :] 11 out[:, 3*g:4*g, 1:, :] = x[:, 3*g:4*g, :-1, :] 12 # remaining channels 13 out[:, 4*g:, :, :] = x[:, 4*g:, :, :] 14 return out
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
## Experiments
|
| 121 |
+
|
| 122 |
+
## Implementation Details
|
| 123 |
+
|
| 124 |
+
We conduct experiments on three mainstream visual recognition benchmarks: image classification on ImageNet-1k dataset (Deng et al. 2009), object detection on COCO dataset (Lin et al. 2014) and semantic segmentation on ADE20k dataset (Zhou et al. 2019).
|
| 125 |
+
|
| 126 |
+
For image classification task, we exactly follow the protocol as in Swin Transformer (Liu et al. 2021b). An average pooling layer and a linear classification layer are appended after the backbone network. All the parameters are randomly initialized and trained for 300 epochs with an AdamW optimizer. The learning rate starts from 0.001 and gradually decay to 0 with a cosine schedule. We include all data augmentations and regularization tricks as in Swin Transformer (Liu et al. 2021b). The batch size is set to 1024.
|
| 127 |
+
|
| 128 |
+
For object detection task, there exists many off-the-shelf detection frameworks, such as Faster R-CNN, Mask R-CNN and RetinaNet. For a fair comparison with other methods, we follow the common practice of using Mask R-CNN and Cascade Mask R-CNN. In such detection frameworks, the backbone is our proposed Shift network, while the rest of components like FPN and detection head remain the same. We initialize the backbone with pretrained weights of the ImageNet-1k classifier. The training duration lasts for 12 epochs (denoted as 1 × schedule) or 36 epochs (denoted as 3 × schedule). The optimizer is AdamW, with an initial learning rate 0.0001. The batch size is 16. During training period, we utilize the multi-scale training trick, i.e., the shorter side of the input image is resized into a range from 480 pixels to 800 pixels. We report the mean average precision (mAP) metrics on the validation set of COCO dataset.
|
| 129 |
+
|
| 130 |
+
For semantic segmentation task, we evaluate our method on ADE20K dataset, which contains 20K images for training and 2K images for validation. In these experiments, the base segmentation framework is UperNet. The model is trained on the training set of ADE20K and the evaluation metric is the mean IoU (mIoU) score on the validation set. Similar to the setting of object detection, our Shift backbones are also pretrained on ImageNet-1k. The rest of settings are same as Swin-Transformer. The training batch size is 16 and we train the model for 160k iterations. For the comparison with the state-of-the-arts, we adopt the multi-scale testing strategy.
|
| 131 |
+
|
| 132 |
+
Table 1: Comparison with the baseline Swin Transformer on three mainstream tasks: image classification, object detection and semantic segmentation. The suffix /light denotes the lightweight version of our ShiftViT, where we only replace attention layers with the shift operation and keep remaining parts unchanged. The throughput speed is evaluated on a single NVidia GTX1080-Ti GPU.The gree and gray colors indicate the gain and loss, respectively.
|
| 133 |
+
|
| 134 |
+
| Model Param (M) ImageNet COCO ADE20k FLOPs Speed Top-1 Mask R-CNN 1 × Mask R-CNN 3 × UpperNet (G) (FPS) Acc.(%) AP b AP m AP b AP m mIoU ResNet-50 26 4.1 676 76.1 38.0 34.4 41.0 37.1 - Swin-T 29 4.5 356 81.3 43.7 39.5 46.0 41.6 44.5 Shift-T/light 20 3.0 790 79.4 41.3 38.0 43.2 39.2 42.6 Shift-T 29 4.5 396 81.7 (+0.4) 45.4 (+1.7) 40.9 (+1.4) 47.1 (+1.1) 42.3 (+0.7) 46.3 (+1.8) Swin-S 50 8.7 217 83.0 46.4 41.7 48.5 43.3 47.6 Shift-S/light 34 5.7 457 81.6 44.8 40.4 46.0 41.1 45.4 Shift-S 50 8.8 215 82.8 (-0.2) 47.2 (+0.8) 42.2 (+0.5) 48.6 (+0.1) 43.4 (+0.1) 47.8 (+0.2) Swin-B 88 15.4 158 83.5 46.9 42.1 48.7 43.4 48.1 Shift-B/light 60 10.2 312 82.3 45.7 41.0 46.0 41.2 45.8 Shift-B 89 15.6 154 83.3 (-0.2) 47.7 (+0.8) 42.7 (+0.6) 48.0 (-0.7) 42.8 (-0.6) 47.9 (-0.2) |
|
| 135 |
+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 136 |
+
|
| 137 |
+
Table 2: Comparison with state-of-the-art methods on the ImageNet-1k classification task.
|
| 138 |
+
|
| 139 |
+
| Model Input # Params FLOPs Top-1 resolution (M) (B) Acc. (%) CNN-based RegNetY-4G 224 2 21 4.0 80.0 RegNetY-8G 224 2 39 8.0 81.7 RegNetY-16G 224 2 84 16.0 82.9 EfficientNet-B4 380 2 19 4.2 82.9 EfficientNet-B5 456 2 30 9.9 83.6 EfficientNet-B6 528 2 43 19.0 84.0 ViT-based and MLP-based DeiT-S 224 2 22 4.6 79.8 DeiT-B 224 2 86 17.5 81.8 PVT-S 224 2 25 3.8 79.8 PVT-L 224 2 61 9.8 81.7 Swin-T 224 2 29 4.5 81.3 Swin-S 224 2 50 8.7 83.0 Swin-B 224 2 88 15.4 83.5 MLP-Mixer-B/16 224 2 79 - 76.4 gMLP-S 224 2 20 4.5 79.4 gMLP-B 224 2 73 15.8 81.6 S 2 -MLP-D 224 2 71 14.0 80.0 S 2 -MLP-W 224 2 51 10.5 80.7 AS-MLP-T 224 2 28 4.4 81.3 AS-MLP-S 224 2 50 8.5 83.1 AS-MLP-B 224 2 88 15.2 83.3 Ours Shift-T 224 2 28 4.4 81.7 Sfhit-S 224 2 50 8.5 82.8 Sfhit-B 224 2 88 15.2 83.3 |
|
| 140 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 141 |
+
|
| 142 |
+
## Comparison with Baseline
|
| 143 |
+
|
| 144 |
+
The goal of this work is to demystify the role of attention mechanism and explore whether it can be replaced by an extremely simple shift operation. Concretely, our proposed backbones are based on the architecture of Swin Transformer, which is one of the most representative ViT variants. We therefore consider Swin Transformer as the baseline model, and compare our ShiftViT to it.
|
| 145 |
+
|
| 146 |
+
For an apple-to-apple comparison, we first build a lightweight version of ShiftViT. It is nearly the same as the Swin Transformer counterpart, except that the attention layers are substituted by the shift operations. We denote this backbone with a suffix /light , because replacing attention with shift will lead to a reduction in parameters and FLOPs. The experimental results are presented in Table 1. We exhaustively compare all variants in three different sizes. The results show that the shift operation is weaker than the attention mechanism, because it does not contain any learnable parameter or arithmetic calculation. For example, the ShiftT/light model has only 20M parameters and 3.0 FLOPs, which are nearly 33% less than the Swin-T model. Therefore, there is no wonder that its performance is marginally worse than the baseline. Despite the relative gap to the baseline, it is worth noting that the absolute accuracy of the lightweight ShiftViT is not bad. Compared with the typical ResNet-50 backbone, Shift-T/light is more powerful and more efficient.
|
| 147 |
+
|
| 148 |
+
To remedy the complexity gap between shift operation and attention mechanism, we can adopt more building blocks in ShiftViT to make sure it has a similar number of parameters with the Swin baseline. In such fair comparisons, our models achieve even better results than SwinTransformer. For the small-size models, our Shift-T backbone attains an mAP score of 45.4% on COCO and an mIoU score of 46.3% on ADE20k, which outperform the Swin-T backbone by a remarkable margin. For the large-size mod- els, ShiftViT seems to be saturated. But the performance is still on par with the Swin baseline.
|
| 149 |
+
|
| 150 |
+
Although the shift operation is weaker than the attention mechanism in spatial modelling, its simple architecture allows the network to grow deeper. As such, the weakness of the shift operation is greatly alleviated. Within the same computational budget, the overall performance of ShiftViT is comparable to the attention-based Swin Transformer. These experiments prove that the attention mechanism might not be necessary for ViTs. Even an extremely simple operation can achieve the similar results.
|
| 151 |
+
|
| 152 |
+
## Comparison with State-of-the-Art
|
| 153 |
+
|
| 154 |
+
To further demonstrate the effectiveness, we compare ShiftViT backbones with existing state-of-the-art methods. For image classification task on ImageNet-1k, our proposed models are compared to three different types of models, namely CNN, ViT and MLP. The results are detailed in Table 2. Overall, our method can achieve a comparable performance with the state-of-the-arts. For ViT-based and MLPbased methods, the best performances are around 83.5% top1 accuracy, while our model achieves an accuracy of 83.3%. For CNN-based methods, our model is slightly worse than EfficientNet series, but the comparison is not fully fair because EfficientNet takes a larger input size.
|
| 155 |
+
|
| 156 |
+
Another interesting thing is the comparison with two concurrent work S 2 -MLP (Yu et al. 2021) and AS-MLP (Lian et al. 2021). These two pieces of work share the similar idea on shift operation , but they introduce some auxiliary modules into the building block, e.g., the pre- and post-projection layers. In Table 2, our performances are slightly better than these two work. It justifies our design choice that building backbone solely with a simple shift operation is good enough.
|
| 157 |
+
|
| 158 |
+
Beside the classification task, the similar performance tread can be also observed in the object detection task and semantic segmentation task. It is notable that some ViTbased and MLP-based methods cannot be easily extended to such dense prediction tasks, because the high-resolution inputs yield unaffordable computational burdens. Our method does not suffer from this obstacle thanks to the high efficiency of shift operation. As shown in Table 3 and Table 4, the advantages of our ShiftViT backbones are clear. ShiftT attains an mAP score of 47.1 on object detection and an mIoU score of 47.8 on semantic segmentation, which outperform other methods by a considerable margin.
|
| 159 |
+
|
| 160 |
+
## Ablation Analysis
|
| 161 |
+
|
| 162 |
+
In this section, we aim to explore what factors contribute to the good performance of ShiftViT. We first analyze the impact of two hyper-parameters in ShiftViT. Then, we dive into the training scheme of ViT series.
|
| 163 |
+
|
| 164 |
+
Expand ratio of MLP The previous experiments have justified our design principle, i.e., a great model depth can remedy the weakness of each building block. Generally, there exists a trade-off between the model depth and the complexity of building blocks. With a fixed computational budget, a lightweight building block can enjoy a deeper network architecture.
|
| 165 |
+
|
| 166 |
+
Table 3: Comparison with state-of-the-art methods on the COCO object detection task. Following the common practice, we couple the backbones with two detection frameworks, namely Mask R-CNN and Cascade Mask R-CNN.
|
| 167 |
+
|
| 168 |
+
| Backbone Params (M) FLOPs (G) AP b AP m Mask R-CNN 3 × Res-50 44 260 41.0 37.1 PVT-S 44 245 43.0 39.9 AS-MLP-T 48 260 46.0 41.5 Swin-T 48 264 46.0 41.6 Shift-T 48 265 47.1 42.3 Res-101 63 336 42.8 38.5 PVT-M 64 302 44.2 40.5 AS-MLP-S 69 346 47.8 42.9 Swin-S 69 354 48.5 43.3 Shift-S 70 350 48.6 43.4 Cascade Mask R-CNN 3 × Res-50 82 739 46.3 40.1 AS-MLP-T 86 745 50.1 43.5 Swin-T 86 739 50.4 43.7 Shift-T 86 743 50.3 43.4 ResX-101 101 819 48.1 41.6 AS-MLP-S 107 824 51.1 44.2 Swin-S 107 838 51.8 44.7 Shift-S 107 827 50.9 44.0 |
|
| 169 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 170 |
+
|
| 171 |
+
Table 4: Comparison with state-of-the-art methods on the ADE20k semantic segmentation task. We report the mIoU metrics on the validation set.
|
| 172 |
+
|
| 173 |
+
| Method Backbone Params FLOPs val (M) (G) mIoU DANet ResNet-101 69 1119 45.2 DNL ResNet-101 69 1249 46.0 DeepLabV3 ResNet-101 63 1021 44.1 OCRNet ResNet-101 89 1381 44.9 DeepLabV3 ResNeSt-101 66 1051 46.9 DeepLabV3 ResNeSt-200 88 1381 48.4 OCRNet HRNet-w64 71 664 45.7 UperNet ResNet-101 89 1029 44.9 UperNet Swin-T 60 945 45.8 UperNet AS-MLP-T 60 937 46.5 UperNet Shift-T 60 942 47.8 UperNet Swin-S 81 1038 49.5 UperNet AS-MLP-S 81 1024 49.2 UperNet Shift-S 81 1029 49.6 UperNet Swin-B 121 1188 49.7 UperNet AS-MLP-B 121 1166 49.5 UperNet Shift-B 121 1174 49.2 |
|
| 174 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 175 |
+
|
| 176 |
+
Table 5: Ablation analysis on the expand ratio of MLP. The first row shows the Swin-T baseline. The row with blue background denotes the default setting in our experiments. All entries share the same number of parameters and FLOPs.
|
| 177 |
+
|
| 178 |
+
| Expand Depth ImgNet COCO ADE20k Ratio Acc. (%) AP b AP m mIoU Swin 48 81.3 43.7 39.5 44.5 4 57 81.3 44.0 39.8 44.4 3 75 81.5 44.4 40.2 45.5 2 114 81.7 45.4 40.9 46.3 1 225 81.8 45.2 40.6 47.3 |
|
| 179 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 180 |
+
|
| 181 |
+
To further investigate this trade-off, we present some ShiftViT models with different depths. For ShiftViT, most parameters exist in the MLP part. We can change the expand ratio of MLP τ to control the model depth. As shown in Table 5, we choose Shift-T as our baseline model. We explore the expand ratio τ within a range from 1 to 4. It is worth noting that the parameters and FLOPs for different entries are almost the same. From Table 5, we can observe a trend that a deeper model results in a better performance. When the depth of ShiftViT increases to 225, it outperforms the 57-layer counterpart by 0.5%, 1.2% and 2.9% absolute gains on classification, detection and segmentation, respectively. This trend supports our conjecture that a powerfuland-heavy module, like attention, may not be the optimal choice for backbone. We hope it can help the future work to rethink such trade-off when designing backbones.
|
| 182 |
+
|
| 183 |
+
Percentage of shifted channels The shift operation has only one hyper-parameter, namely the percentage of shifted channels. By default, it is set to 33%. In this section, we explore some other settings. Specifically, we set the percentage of shifted channels to 20%, 25%, 33% and 50%, respectively. The results are presented in Figure 3. It shows that the final performance is not very sensitive to this hyperparameter. Shifting 25% of channels only results in 0.3% absolute loss compared to the best setting. Within the reasonable range (from 25% to 50%), all the settings achieve a better accuracy than the Swin-T baseline.
|
| 184 |
+
|
| 185 |
+
Shifted pixels In the shift operation, a small portion of channels are shifted by one pixel along four directions. To have a comprehensive exploration, we also try different shifted pixels. When the shifted pixel is zero, i.e., no shifting happens, the top-1 accuracy on the ImageNet dataset is only 72.9%, which is significantly lower than our baseline (81.7%). This is not surprising because no shifting means there is no interaction between different spatial location. Besides, if we shift two pixels in the shift operation, the model achieves 80.2% top-1 accuracy on ImageNet, which is also slightly worse than the default setting.
|
| 186 |
+
|
| 187 |
+
ViT-style training scheme Shift operation has been well studied in CNNs. However, the previous work does not show the impressive performance as ours. Shift-ResNet-50 (Wu et al. 2018) only achieve an accuracy of 75.6% on ImageNet, which is far behind our 81.7% accuracy. This gap raise a natural concern about what makes good for our ShiftViT.
|
| 188 |
+
|
| 189 |
+
Figure 3: Ablation analysis on the percentage of shifted channels. We plot the top-1 classification accuracy on ImageNet-1k. The red line indicates Swin-T baseline.
|
| 190 |
+
|
| 191 |
+
<!-- image -->
|
| 192 |
+
|
| 193 |
+
Table 6: Ablation analysis on the typical configurations of CNNs and ViTs. We gradually transfer the training configuration from the CNN's setting to the ViT's setting, and investigate how these factors influence the model performances.
|
| 194 |
+
|
| 195 |
+
| SGD ReLU BN 90ep ImageNet ↓ ↓ ↓ ↓ Top-1 Acc. AdamW GELU LN 300ep (%) 76.4 ✓ 77.9 ✓ ✓ 78.5 ✓ ✓ ✓ 78.4 ✓ ✓ ✓ ✓ 81.7 |
|
| 196 |
+
|--------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 197 |
+
|
| 198 |
+
We suspect the reason might lie in the ViT-style training scheme. Specifically, most existing ViT variants follow the setting as in DeiT (Touvron et al. 2020), which is quite different from the standard pipeline of training CNNs. For example, ViT-style scheme adopts AdamW optimizer and the training duration lasts for 300 epochs on ImageNet. As a comparison, CNN-style scheme prefers SGD optimizer and the training schedule is usually 90 epochs only. Since our model inherit the ViT-style training scheme, it is interesting to see how such differences affect the performance.
|
| 199 |
+
|
| 200 |
+
Due to the resource limitation, we cannot fully align all settings between ViT-style and CNN-style. Therefore, we pick four important factors that we believe can bring some insights, i.e. optimizer, activation function, normalization layer and training schedule. From Table 6, we can observe that such factors can significantly influence the accuracy, especially the training schedule. These results shows that the good performance of ShiftViT is partly brought by the ViTstyle training scheme. Similarly, the success of ViT may be also related to its special training scheme. We should take it seriously in the future study of ViTs.
|
| 201 |
+
|
| 202 |
+
## Conclusion
|
| 203 |
+
|
| 204 |
+
In this work, we move a small step toward demystifying the essential reason why ViT works. The experiments show that the attention mechanism might not be the vital factor for the success of ViT. We can even use an extremely simple shift operation to replace the attention layer. The proposed backbone, namely ShiftViT, can work as well as the Swin Transformer baseline. Since the shift operation is already the simplest spatial modelling module, we argue that the good performance must come from the remaining components of ViT, e.g., the FFN and the training scheme. In future work, we plan to have more analysis on such factors and investigate more ViT variants.
|
| 205 |
+
|
| 206 |
+
## References
|
| 207 |
+
|
| 208 |
+
Chen, C.-F.; Fan, Q.; and Panda, R. 2021. Crossvit: Crossattention multi-scale vision transformer for image classification. arXiv preprint arXiv:2103.14899 .
|
| 209 |
+
|
| 210 |
+
Chen, S.; Xie, E.; Ge, C.; Liang, D.; and Luo, P. 2021. Cyclemlp: A mlp-like architecture for dense prediction. arXiv preprint arXiv:2107.10224 .
|
| 211 |
+
|
| 212 |
+
Chen, W.; Xie, D.; Zhang, Y.; and Pu, S. 2019. All you need is a few shifts: Designing efficient convolutional neural networks for image classification. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition , 7241-7250.
|
| 213 |
+
|
| 214 |
+
Deng, J.; Dong, W.; Socher, R.; Li, L.-J.; Li, K.; and FeiFei, L. 2009. Imagenet: A large-scale hierarchical image database. In 2009 IEEE conference on computer vision and pattern recognition , 248-255. Ieee.
|
| 215 |
+
|
| 216 |
+
Dosovitskiy, A.; Beyer, L.; Kolesnikov, A.; Weissenborn, D.; Zhai, X.; Unterthiner, T.; Dehghani, M.; Minderer, M.; Heigold, G.; Gelly, S.; et al. 2020. An image is worth 16x16 words: Transformers for image recognition at scale. In ICLR .
|
| 217 |
+
|
| 218 |
+
Fan, H.; Xiong, B.; Mangalam, K.; Li, Y.; Yan, Z.; Malik, J.; and Feichtenhofer, C. 2021. Multiscale vision transformers. arXiv preprint arXiv:2104.11227 .
|
| 219 |
+
|
| 220 |
+
Hu, H.; Gu, J.; Zhang, Z.; Dai, J.; and Wei, Y. 2018. Relation networks for object detection. In Proceedings of the IEEE conference on computer vision and pattern recognition , 3588-3597.
|
| 221 |
+
|
| 222 |
+
Hu, H.; Zhang, Z.; Xie, Z.; and Lin, S. 2019. Local relation networks for image recognition. In Proceedings of the IEEE/CVF International Conference on Computer Vision , 3464-3473.
|
| 223 |
+
|
| 224 |
+
Huang, Z.; Wang, X.; Huang, L.; Huang, C.; Wei, Y.; and Liu, W. 2019. Ccnet: Criss-cross attention for semantic segmentation. In ICCV , 603-612.
|
| 225 |
+
|
| 226 |
+
Jeon, Y.; and Kim, J. 2018. Constructing Fast Network through Deconstruction of Convolution. Advances in Neural Information Processing Systems , 31: 5951-5961.
|
| 227 |
+
|
| 228 |
+
Krizhevsky, A.; Sutskever, I.; and Hinton, G. E. 2012. Imagenet classification with deep convolutional neural networks. NIPS , 25: 1097-1105.
|
| 229 |
+
|
| 230 |
+
Li, J.; Yan, Y .; Liao, S.; Yang, X.; and Shao, L. 2021. Localto-Global Self-Attention in Vision Transformers. arXiv preprint arXiv:2107.04735 .
|
| 231 |
+
|
| 232 |
+
Lian, D.; Yu, Z.; Sun, X.; and Gao, S. 2021. AS-MLP: An Axial Shifted MLP Architecture for Vision. arXiv preprint arXiv:2107.08391 .
|
| 233 |
+
|
| 234 |
+
Lin, J.; Gan, C.; and Han, S. 2019. Tsm: Temporal shift module for efficient video understanding. In Proceedings of the IEEE/CVF International Conference on Computer Vision , 7083-7093.
|
| 235 |
+
|
| 236 |
+
Lin, T.-Y.; Maire, M.; Belongie, S.; Hays, J.; Perona, P.; Ramanan, D.; Doll´ ar, P.; and Zitnick, C. L. 2014. Microsoft coco: Common objects in context. In European conference on computer vision , 740-755. Springer.
|
| 237 |
+
|
| 238 |
+
Liu, H.; Dai, Z.; So, D. R.; and Le, Q. V. 2021a. Pay Attention to MLPs. arXiv preprint arXiv:2105.08050 .
|
| 239 |
+
|
| 240 |
+
Liu, Z.; Lin, Y .; Cao, Y .; Hu, H.; Wei, Y .; Zhang, Z.; Lin, S.; and Guo, B. 2021b. Swin transformer: Hierarchical vision transformer using shifted windows. arXiv .
|
| 241 |
+
|
| 242 |
+
Tolstikhin, I.; Houlsby, N.; Kolesnikov, A.; Beyer, L.; Zhai, X.; Unterthiner, T.; Yung, J.; Keysers, D.; Uszkoreit, J.; Lucic, M.; et al. 2021. Mlp-mixer: An all-mlp architecture for vision. arXiv preprint arXiv:2105.01601 .
|
| 243 |
+
|
| 244 |
+
Touvron, H.; Cord, M.; Douze, M.; Massa, F.; Sablayrolles, A.; and J´ egou, H. 2020. Training data-efficient image transformers and distillation through attention. arXiv preprint arXiv:2012.12877 .
|
| 245 |
+
|
| 246 |
+
Vaswani, A.; Shazeer, N.; Parmar, N.; Uszkoreit, J.; Jones, L.; Gomez, A. N.; Kaiser, Ł.; and Polosukhin, I. 2017. Attention is all you need. In Advances in neural information processing systems , 5998-6008.
|
| 247 |
+
|
| 248 |
+
Wang, W.; Xie, E.; Li, X.; Fan, D.-P.; Song, K.; Liang, D.; Lu, T.; Luo, P.; and Shao, L. 2021. Pyramid vision transformer: A versatile backbone for dense prediction without convolutions. arXiv preprint arXiv:2102.12122 .
|
| 249 |
+
|
| 250 |
+
Wang, X.; Girshick, R.; Gupta, A.; and He, K. 2018. Nonlocal neural networks. In Proceedings of the IEEE conference on computer vision and pattern recognition , 77947803.
|
| 251 |
+
|
| 252 |
+
Wu, B.; Wan, A.; Yue, X.; Jin, P.; Zhao, S.; Golmant, N.; Gholaminejad, A.; Gonzalez, J.; and Keutzer, K. 2018. Shift: A zero flop, zero parameter alternative to spatial convolutions. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition , 9127-9135.
|
| 253 |
+
|
| 254 |
+
Yu, T.; Li, X.; Cai, Y.; Sun, M.; and Li, P. 2021. S 2 -MLP: Spatial-Shift MLP Architecture for Vision. arXiv preprint arXiv:2106.07477 .
|
| 255 |
+
|
| 256 |
+
Zhao, H.; Jia, J.; and Koltun, V. 2020. Exploring selfattention for image recognition. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition , 10076-10085.
|
| 257 |
+
|
| 258 |
+
Zhou, B.; Zhao, H.; Puig, X.; Xiao, T.; Fidler, S.; Barriuso, A.; and Torralba, A. 2019. Semantic understanding of scenes through the ade20k dataset. IJCV , 127(3): 302-321.
|
text-versions/attention-markdown/2203.10506_Attention Aided CSI Wireless Localizatio.md
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2203.10506 Attention Aided Csi Wireless Localizatio
|
| 2 |
+
|
| 3 |
+
## Attention Aided CSI Wireless Localization
|
| 4 |
+
|
| 5 |
+
Artan Salihu †‡ , Stefan Schwarz †‡ and Markus Rupp †
|
| 6 |
+
|
| 7 |
+
† Institute of Telecommunications, Technische Universit¨ at (TU) Wien
|
| 8 |
+
|
| 9 |
+
‡ Christian Doppler Laboratory for Dependable Wireless Connectivity for the Society in Motion
|
| 10 |
+
|
| 11 |
+
Email:
|
| 12 |
+
|
| 13 |
+
{ artan.salihu,stefan.schwarz,markus.rupp } @tuwien.ac.at
|
| 14 |
+
|
| 15 |
+
Abstract -Deep neural networks (DNNs) have become a popular approach for wireless localization based on channel state information (CSI). A common practice is to use the raw CSI in the input and allow the network to learn relevant channel representations for mapping to location information. However, various works show that raw CSI can be very sensitive to system impairments and small changes in the environment. On the contrary, hand-designing features may hinder the limits of channel representation learning of the DNN. In this work, we propose attention-based CSI for robust feature learning. We evaluate the performance of attended features in centralized and distributed massive MIMO systems for ray-tracing channels in two non-stationary railway track environments. By comparison to a base DNN, our approach provides exceptional performance.
|
| 16 |
+
|
| 17 |
+
Index Terms -Localization, Massive MIMO, Attention, Transformer, Deep Learning.
|
| 18 |
+
|
| 19 |
+
## I. INTRODUCTION
|
| 20 |
+
|
| 21 |
+
The deployment of massive multiple-input multiple-output (MIMO) technology in the fifth generation (5G) mobile cellular systems can enable high-accuracy positioning services, where ambitious meter-level accuracy requirements are set [1]. Recently, deep learning has become a renowned approach for achieving exceptionell localization performance [2]-[4]. Such DNN-based methods take advantage of a large amount of channel state information (CSI) available at a massive MIMO base station (BS) to train a model with the channel prints from the known locations. The model then utilizes the channel estimates of the unknown transmitter to determine its position related information.
|
| 22 |
+
|
| 23 |
+
A common approach is to use the raw CSI as an input to the DNN architecture. However, the raw CSI can be very sensitive to system impairments and slight variations in the environment. Thus, we might require a vast number of location-tagged CSI to achieve sufficiently rich representation learning of distinct locations. A variety of works have addressed the issue of imperfect channel estimates by suggesting to hand-design more robust features, mainly by exploiting the approximately sparse angleand delay-domain channel representation in a MIMO-OFDM system. For instance, the work in [2] suggests a decimated delay-domain CSI representation followed by autocorrelation to capture features that are invariant to the system impairments. Similarly, the work in [4] suggests utilizing angle-delay channel representation as input to a convolutional neural network (CNN) based model. However, hand designing the input features hinders the limits of the DNNs for achievable representation learning of the channel.
|
| 24 |
+
|
| 25 |
+
Alternatively, we can improve the feature learning process at the beginning of the DNN itself by leveraging the attention mechanism [5] and allowing the neural network to attend on different parts of the input. The attention module is at the core of every Transformer architecture. The Transformer was initially proposed in [6] for natural language processing (NLP) and recently has been successfully applied as an alternative to CNNs in computer vision [7]. While the attention mechanism has become a de facto standard for signal processing in NLP and vision, its ability for CSI feature learning in wireless communications and wireless localization, in particular, remains underexplored.
|
| 26 |
+
|
| 27 |
+
Fig. 1: Overview of the attention-aided model. We linearly embed each subcarrier, add position embeddings, and feed the representation vectors to a Transformer-like block with an attention module for feature extraction. For location estimation, we average over the attended features. Instead, we can use an extra learnable [ LID ] embedding too.
|
| 28 |
+
|
| 29 |
+
<!-- image -->
|
| 30 |
+
|
| 31 |
+
## Our Contributions
|
| 32 |
+
|
| 33 |
+
In this work, we firstly propose an efficient and a general robust feature learning process incorporated into an end-toend DNN. Our model is based on the attention mechanism, which serves as an adaptive filter for CSI features resilient to imperfect channel estimates and temporal variations in the environment. To achieve both, robustness and scalability, we show that we can use a Transformer-like architecture to feed the whole channel estimate without using convolution layers, fusion approaches, recurrence, or decimating the input channel. An overview of the proposed model is depicted in Fig. 1. Secondly, we provide a comprehensive evaluation of the proposed method by applying it to ray-tracing channels obtained along two railway tracks in carefully modeled changing surrounding environments. Finally, we present insights regarding localization accuracy in a centralized and distributed antenna system.
|
| 34 |
+
|
| 35 |
+
## II. SYSTEM MODEL
|
| 36 |
+
|
| 37 |
+
We consider uplink transmission over orthogonal frequencydivision multiplexing (OFDM) in a massive MIMO system. We assume R single-antenna transmitters placed in a space R 3 at positions u r = [ u r, 1 , u r, 2 , u r, 3 ] T with r ∈ R , where R denotes the set of user location indices and |R| = R . The base station (BS) is equipped with N r antenna elements. Alternatively, we also consider N r spatially distributed antennas among M remote radio heads (RRHs) at positions b m = [ b m, 1 , b m, 2 , b m, 3 ] T with m ∈ M , where M is the set of RRH indices and |M| = M . In case of distributed antennas, we assume that all RRHs are connected via highspeed fronthaul links to the central unit (CU), i.e., the delay between the RRHs and the CU is negligible. Further, we consider S scattering objects in the ROI at respective positions, p s = [ p s, 1 , p s, 2 , p s, 3 ] T with s ∈ S , where S denotes the set of scattering object indices and |S| = S .
|
| 38 |
+
|
| 39 |
+
## A. Dynamic Environment
|
| 40 |
+
|
| 41 |
+
In this paper, we consider that the propagation environment changes in each time snapshot t ∈ { 1 , . . . , T } . More specifically, by fixing the positions of the receiver and transmitter, we realize the time-varying conditions of the environment by altering the positions of S ′ scatterering objects, where S ′ = |S ′ | and S ′ ⊆ S . Thus, we have
|
| 42 |
+
|
| 43 |
+
<!-- formula-not-decoded -->
|
| 44 |
+
|
| 45 |
+
where z s,i is the zero-mean Gaussian noise with variance σ 2 z at i -th coordinate. Similarly, we account for the uncertainty in the position of antenna of the transmitter at t , u t r , i.e.,
|
| 46 |
+
|
| 47 |
+
<!-- formula-not-decoded -->
|
| 48 |
+
|
| 49 |
+
where n r,i is the zero-mean Gaussian noise with variance σ 2 n at i -th coordinate. Note that the variations in the position of the scatterers alter the gain, delay and angle information of the individual multi-bounce non-line-of-sight (NLOS) paths. In Fig. 2, we show an example of the RMS delay-spread, τ RMS, as well as the RMS angle of arrival spread in azimuth, ϕ RMS, for a single random u r over T = 200 time snapshots and L = 4 strongest paths. Here, the delay is normalized with respect to the strongest path. Moreover, the uncertainty in the position of antenna, allows us to account for the effect of imperfect channel estimates at the receiver. In Sec. II-B, we detail the geometric channel model and the relationship with the position parameters, where recognizing the impact of the antenna position offset in the channel is easy to perceive.
|
| 50 |
+
|
| 51 |
+
Additionally, to keep this work more general, we consider that the electromagnetic properties of the scattering objects change over time, which impacts the amplitude gain of the radar cross section (RCS) of the scattering objects. We assume that material types change randomly and have a permittivity value of ϵ κ at time t with κ ∈ K , where K is the set of material types. Finally, we also consider atmospheric attenuation in the environment. Thus, in case of a rainy period R with the probability P ( R ) , we assume additional attenuation to the line-of-sight (LOS) path.
|
| 52 |
+
|
| 53 |
+
<!-- image -->
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
(b) An example of
|
| 62 |
+
|
| 63 |
+
√
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
RMS
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
angle of arrival spread in azimuth
|
| 82 |
+
|
| 83 |
+
Fig. 2: Delay- and angle-spread at u r over T = 200 time snapshots.
|
| 84 |
+
|
| 85 |
+
## B. Channel Model
|
| 86 |
+
|
| 87 |
+
We assume that the signal from each transmitter r is received at N r antennas over a set of active subcarriers N ′ c = { k 1 , . . . , k N ′ c } subcarriers. The frequency-domain channel for the k -th subcarrier reads [8]
|
| 88 |
+
|
| 89 |
+
<!-- formula-not-decoded -->
|
| 90 |
+
|
| 91 |
+
In above, η t ℓ and τ t ℓ denote the ℓ -th path's complex gain and propagation delay at time t . The subcarrier spacing is ∆ f = B/N c , where B is the bandwidth and N c is the total number of subcarriers. The angles of arrival (AoA) in azimuth and elevation are denoted by ϕ t az,ℓ and ϕ t el,ℓ , respectively. The expression for the steering vector at the receiver is given by
|
| 92 |
+
|
| 93 |
+
<!-- formula-not-decoded -->
|
| 94 |
+
|
| 95 |
+
The array steering vectors a x ( · ) , and a z ( · ) are
|
| 96 |
+
|
| 97 |
+
with λ c = c/f c , where f c being the carrier frequency and c the speed of light, and d = λ c / 2 the antenna element spacing. In this work, we use a ray-tracer to obtain the delays, angles and path gains. The channel for the r -th user location H t r over N ′ c subcarriers can then be written as
|
| 98 |
+
|
| 99 |
+
<!-- formula-not-decoded -->
|
| 100 |
+
|
| 101 |
+
<!-- formula-not-decoded -->
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
## III. ATTENTION AIDED LOCALIZATION
|
| 106 |
+
|
| 107 |
+
## A. Problem Formulation
|
| 108 |
+
|
| 109 |
+
Our goal in this work is to solve the problem of localization of the user from the obtained imperfect channel estimates in a changing surrounding environment. To do so, we rely on deep learning and formulate the DNN as a function f Ψ ( · ) parameterized by Ψ where, given the input channel H r , we aim to learn a set of robust features and directly map them into a position estimation, ̂ u r . The set of optimal parameter values Ψ is learned by minimizing a given loss function,
|
| 110 |
+
|
| 111 |
+
<!-- formula-not-decoded -->
|
| 112 |
+
|
| 113 |
+
We view the received channel matrix H r as a set of N ′ c channel vectors of size ̂ h n ∈ C 1 × N r , where n ∈ N ′ c . We handle the complex-valued CSI as three independent real numbers, i.e., ̂ h (Re) n = Re { ̂ h n } , ̂ h (Im) n = Im { ̂ h n } , and ̂ h (Abs) n = Abs { ̂ h n } , representing the real, imaginary and absolute parts. Additionally, the whole dataset, i.e., both the training and testing sets, is scaled by dividing each part with the maximum absolute value in it, ∆ Re = max(max( {{| H t, (Re) r |} R r =1 } T t =1 )) . Similarly, we normalize the imaginary, ∆ Im , as well as the absolute part, ∆ Abs . The input representation of each subcarrier for the network depicted in Fig. 1 becomes h n ∈ R 1 × 3 N r .
|
| 114 |
+
|
| 115 |
+
## C. Transformer and Attention
|
| 116 |
+
|
| 117 |
+
We maintain the same number of D hidden units across the Transformer block shown in Fig. 3a. Therefore, we firstly project each subcarrier into an embedding through a linear layer with learnable parameters E ∈ R 3 N r × D , i.e.,
|
| 118 |
+
|
| 119 |
+
<!-- formula-not-decoded -->
|
| 120 |
+
|
| 121 |
+
A characteristic of the attention module is that it is permutation-equivariant concerning the input embedded subcarriers. However, the structure of the whole channel, i.e., the arrangement, can reveal meaningful correlations among frequency-selective subcarriers. Thus, as we use no recurrence and no convolution, we inject some information about the indices of the subcarriers into the model.
|
| 122 |
+
|
| 123 |
+
1) Subcarrier Positional Encoding: We rely on absolute positional encoding [9] to represent the arrangement of subcarriers. Specifically, we assign a learnable real-valued vector embedding g i ∈ R 1 × D to each subcarrier index i . Then, given the input channel, g i is added to the subcarrier embedding e i at position i . Hence, the input to the Transformer block becomes ˆ e i = e i + g i . By doing so, we differentiate the channel at each subcarrier and assign position dependent attention.
|
| 124 |
+
|
| 125 |
+
2) Location Identification: To add global context information on the whole channel, we can prepend to the set of subcarrier embeddings a special symbol [ LID ] . This is considered as another learnable vector, e 0 , whose representation is a compressed characterization of the whole channel from the r -th transmitter and it can be used to feed into the multi-layer
|
| 126 |
+
|
| 127 |
+
<!-- image -->
|
| 128 |
+
|
| 129 |
+
(a) Transformer block.
|
| 130 |
+
|
| 131 |
+
Fig. 3: DNN model details. a) Transformer block with the attention module for feature learning, b) MLP-head for location estimation, and c) the base-DNN we commonly used in the previous work [3].
|
| 132 |
+
|
| 133 |
+
perceptron (MLP), i.e., the MLP-head detailed in Fig. 3b for the final features to location mapping. We should note that we investigated averaging over all representations to combine the attended features as the input into the MLP-head, finding [ LID ] is sufficient but performs worse than the averaging. We report the performance in the Sec. IV. The main reason for using the special vector is future self-supervision and transferlearning investigation. In the following, we keep the [ LID ] . Thus, the set of vectors as input to the transformer block becomes C = N ′ c +1 .
|
| 134 |
+
|
| 135 |
+
3) Attention: In case of self-attention [6], we consider three input copies and project them using the same set of weights, W q = W k = W v . To this end; we write the self-attention as
|
| 136 |
+
|
| 137 |
+
<!-- formula-not-decoded -->
|
| 138 |
+
|
| 139 |
+
where α i,j is the attention coefficient between the two embeddings at positions i and j ,
|
| 140 |
+
|
| 141 |
+
<!-- formula-not-decoded -->
|
| 142 |
+
|
| 143 |
+
In above, ¯ e i = LayerNorm( ˆ e i ; γ, β ) where γ and β are hyperparameters [10].
|
| 144 |
+
|
| 145 |
+
4) MLP-head: At the output of the Transformer block of the proposed model, the representation vector ¯ o i is
|
| 146 |
+
|
| 147 |
+
<!-- formula-not-decoded -->
|
| 148 |
+
|
| 149 |
+
where ˆ o i = LayerNorm( o i + ˆ e i ; γ, β ) .
|
| 150 |
+
|
| 151 |
+
As we discussed, the input to the MLP head can be ¯ o 0 or an averaged representation over N ′ c representation vectors. In the case of ¯ o 0 , then ̂ u r = MLP 2 ( ¯ o 0 ) W 2 , where W 2 ∈ R D × D ′ is the weight matrix of the output linear layer, and D ′ is the number of output units representing the position coordinates.
|
| 152 |
+
|
| 153 |
+
## IV. SIMULATIONS AND RESULTS
|
| 154 |
+
|
| 155 |
+
In this section, we evaluate and compare the performance of the proposed approach w.r.t. various factors. In the results, we have labeled this approach as WiT, i.e., Wireless Transformer. Moreover, we discuss a few other aspects encountered during this work. Finally, we conclude this work.
|
| 156 |
+
|
| 157 |
+
## A. Scenarios and Datasets
|
| 158 |
+
|
| 159 |
+
To obtain all the multi-path related parameters for the modeled scenarios, we make use of the available shooting and bouncing ray (SBR) approach with low-angular separation [11] in the ray-tracing tool from Matlab [12]. By using the ray-tracer, we are able to simulate the temporal aspects of the scenarios under consideration by simply running T = 200 realizations with altered input geometries, changing the position of the considered moving objects, and varying over different material properties as explained in Sec. II. The initially imported scenario is from the OpenStreetMap [13], and then the 3D tool [14] is used for modeling the moving objects and changing environment. In this work, we consider two scenarios, as shown in Fig. 4. We assume a single-BS for the first scenario, S-scenario, M = 1 and R = 360 . For the second scenario, HB-scenario, we consider a DAS with M = 8 and R = 406 . In both cases N r = 64 , f c = 3 . 5GHz , L = 4 , and B = 20MHz . We consider every 16 -th subcarrier as active, where N c = 512 , N ′ c = 32 and N c ≡ N ′ c (mod 16) . The receivers are at a height of 20m . Since u r, 3 = 1 . 5m ∀ r ∈ R , we only consider D ′ = 2 during the training. We consider the default relative permittivity values ϵ κ for κ ∈ { concrete, brick, metal, wood } [15] and add the atmospheric attenuation in the event of rain with P ( R ) = 0 . 3 . The obtained sample size is RT . However, if the received power is less than -130dBm , then we discard such measurement at time t from the ray-tracer. Thus, the dataset has a total of 69 212 and 81 200 samples for S- and HB-scenario, respectively. It is worth noting that the proposed network appears not to saturate within 1800 epochs, in contrast to the base-DNN [3]. However, we limited the training range due to time constraints on limited available resources.
|
| 160 |
+
|
| 161 |
+
## B. Training Details
|
| 162 |
+
|
| 163 |
+
As shown in Fig. 3, we adopt ReLU for the intermediate non-linear operations in both MLP 1 ( · ) and MLP 2 ( · ) . The proposed network is trained for 1800 epochs with a batch size of 512. We use Adam solver with weight decay [16], and the initial learning rate is set to 3 · 10 -4 . Each layer has D = 650 units followed by a dropout rate of 0 . 1 . For the LayerNorm( · ) , the additive factor γ = 1 and the multiplicative parameter β = 0 . 0001 . The base-DNN, which we used in [3] as a backbone of the then proposed model, consists of four layers, each followed by a dropout with a dropout rate of 0 . 2 as detailed in Fig. 3c. The hidden dimensionality is kept the same, D . Early stopping is applied for training the base-DNN if the validation loss does not improve for 80 consecutive epochs. The dataset is split into 0 . 75 and 0 . 25 for training and holding out validation and testing, respectively. During the training, the location coordinate values, i.e., u r,i , are scaled within [0 , 1] . The estimates are scaled back to evaluate the performance. Performance is reported in terms of mean absolute error, MAE , and the 95 -th percentile,
|
| 164 |
+
|
| 165 |
+
TABLE I: Summarized Results
|
| 166 |
+
|
| 167 |
+
| S S HB T = 1 T = 200 T = 200 Method MAE 95 - th MAE 95 - th MAE 95 - th Base-DNN 1 . 98 5 . 16 3 . 59 8 . 83 4 . 13 10 . 01 WiT [LID] 0 . 74 1 . 88 2 . 36 6 . 54 1 . 18 2 . 83 WiT (avg.) 0 . 31 0 . 84 1 . 70 4 . 70 0 . 68 1 . 61 |
|
| 168 |
+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 169 |
+
|
| 170 |
+
## C. Localization Accuracy
|
| 171 |
+
|
| 172 |
+
<!-- formula-not-decoded -->
|
| 173 |
+
|
| 174 |
+
Next, we investigate a few aspects that impact localization performance.
|
| 175 |
+
|
| 176 |
+
1) Static Scenario: First, we investigate the impact of the learned features in the S-scenario for the static environment, T = 1 . To have a sufficient amount of training samples, the inter distance between any two locations ‖ u i -u j ‖ is much smaller than that of a dynamic scenarios. Thus, the dataset for this case consists of 72 000 channel and location pairs. The attention based features consistently perform better compared to the raw CSI and a base-DNN. The accuracy is improved by more than 50% . The localization performance, comparison to the base-DNN, and comparison to the actual test locations in R 2 is depicted in Figs. 5a, 5b, 5c and 5d.
|
| 177 |
+
|
| 178 |
+
2) Mobility Scenario: Similarly, for the dynamic scenarios and T = 200 , the proposed features, learned by the attention mechanism, are much more robust than the raw CSI and the base-DNN, reducing the localization error by a significant margin.
|
| 179 |
+
|
| 180 |
+
3) Distributed Antennas: As we mentioned earlier, for the HB-scenario we consider N r distributed antennas among M = 8 infrastructure nodes. From Fig. 5b, we can observe that the proposed approach provides significantly better performance.
|
| 181 |
+
|
| 182 |
+
4) Impact of Features Averaging: Table I shows the summarized results and the performance gap when comparing the averaging over features and the case of using the unique representation vector for each set of subcarriers. Again, the performance difference is evident in both DAS and singleBS scenarios. Yet, this compressed representation version can outperform the base-DNN.
|
| 183 |
+
|
| 184 |
+
## Discussion
|
| 185 |
+
|
| 186 |
+
A naive application of the attention mechanism would involve inputting every channel coefficient into the network, such that each real-valued channel coefficient attends to every other. With the increased number of antenna elements and subcarriers in massive MIMO, this would not scale to realistic future systems. Still, one of the critical challenges of utilizing the attention mechanism on a more extensive set of subcarriers is its efficiency due to the computation and memory complexity. Furthermore, we have noticed that the applied residual connections play a crucial role in retaining the position information on the subcarriers representation after the attention module. Without the residual connection, the information about the original structure of the channel is lost. Removing the residual connections might lead to the loss of such information after the attention module. Moreover, with randomly initialized parameters for self-attention vectors, the position has no relation to its original input.
|
| 187 |
+
|
| 188 |
+
Fig. 4: Considered railway trajectories are a) the Schwechat area (S-scenario) and near b) the Vienna central station (HB-scenario). Example of model used for ray-tracing is shown in c). Train moves parallel to the trajectory, and other objects change their position for every t too.
|
| 189 |
+
|
| 190 |
+
<!-- image -->
|
| 191 |
+
|
| 192 |
+
(c) S-scneario: Actual vs estimated (d) HB-scneario: Actual vs estimated
|
| 193 |
+
|
| 194 |
+
<!-- image -->
|
| 195 |
+
|
| 196 |
+
Fig. 5: Localization error in (a) S-scenario for T = 1 and for T = 200 and (b) HB-scenario for T = 200 time snapshots. Proposed learned features outperform the base DNN across all the locations. In c) and d) actual versus estimates in the trajectory for T = 200 are shown.
|
| 197 |
+
|
| 198 |
+
## V. CONCLUSION
|
| 199 |
+
|
| 200 |
+
We presented an end-to-end and DNN-based localization method with robust feature learning. We proposed to input each subcarrier into the network, and using the attention mechanism we were able to better capture the dependence in the CSI over the subcarriers, providing superior localization performance compared to the base-DNN with raw CSI. We investigated dynamic scenarios where the scattering events over T time snapshopts cause time variations in the channel. We showed that the proposed method is able to cope with imperfect channel estimates. In this work, we also modeled two ray-tracing based scenarios over railway tracks. Finally, we showed that the proposed method excels by even a greater margin when a distributed antenna system is considered.
|
| 201 |
+
|
| 202 |
+
## ACKNOWLEDGMENT
|
| 203 |
+
|
| 204 |
+
This work has been funded by ¨ OBB Infrastruktur AG. The financial support by the Austrian Federal Ministry for Digital and Economic Affairs, the National Foundation for Research, Technology and Development and the Christian Doppler Research Association is gratefully acknowledged.
|
| 205 |
+
|
| 206 |
+
## REFERENCES
|
| 207 |
+
|
| 208 |
+
- [1] 3GPP, 'Service requirements for the 5G system,' 3rd Generation Partnership Project (3GPP), Technical specification (TS) 22.261, 04 2018, version 18.5.0.
|
| 209 |
+
- [2] P. Ferrand, A. Decurninge, and M. Guillaud, 'DNN-based localization from channel estimates: Feature design and experimental results,' in GLOBECOM 2020 - 2020 IEEE Global Communications Conference , 2020, pp. 1-6.
|
| 210 |
+
- [3] A. Salihu, S. Schwarz, and M. Rupp, 'Towards scalable uncertainty aware dnn-based wireless localisation,' in 2021 29th European Signal Processing Conference (EUSIPCO) , 2021, pp. 1706-1710.
|
| 211 |
+
- [4] X. Sun, C. Wu, X. Gao, and G. Y. Li, 'Fingerprint-based localization for massive MIMO-OFDM system with deep convolutional neural networks,' IEEE Transactions on Vehicular Technology , vol. 68, no. 11, pp. 10 846-10 857, 2019.
|
| 212 |
+
- [5] A. Graves, 'Generating sequences with recurrent neural networks,' arXiv preprint arXiv:1308.0850 , 2013.
|
| 213 |
+
- [6] A. Vaswani, N. Shazeer, N. Parmar, J. Uszkoreit, L. Jones, A. N. Gomez, Ł. Kaiser, and I. Polosukhin, 'Attention is all you need,' Advances in neural information processing systems , vol. 30, 2017.
|
| 214 |
+
- [7] A. Dosovitskiy, L. Beyer, A. Kolesnikov, D. Weissenborn, X. Zhai, T. Unterthiner, M. Dehghani, M. Minderer, G. Heigold, S. Gelly et al. , 'An image is worth 16x16 words: Transformers for image recognition at scale,' arXiv preprint arXiv:2010.11929 , 2020.
|
| 215 |
+
- [8] R. W. Heath, N. Gonzalez-Prelcic, S. Rangan, W. Roh, and A. M. Sayeed, 'An overview of signal processing techniques for millimeter wave MIMO systems,' IEEE journal of selected topics in signal processing , vol. 10, no. 3, pp. 436-453, 2016.
|
| 216 |
+
- [9] J. Gehring, M. Auli, D. Grangier, D. Yarats, and Y. N. Dauphin, 'Convolutional sequence to sequence learning,' in International Conference on Machine Learning . PMLR, 2017, pp. 1243-1252.
|
| 217 |
+
- [10] J. L. Ba, J. R. Kiros, and G. E. Hinton, 'Layer normalization,' arXiv preprint arXiv:1607.06450 , 2016.
|
| 218 |
+
- [11] Z. Yun and M. F. Iskander, 'Ray tracing for radio propagation modeling: Principles and applications,' IEEE Access , vol. 3, pp. 1089-1100, 2015.
|
| 219 |
+
- [12] MATLAB, version 9.11.0 (R2021b) . Natick, Massachusetts: The MathWorks Inc., 2021.
|
| 220 |
+
- [13] OpenStreetMap contributors, 'Planet dump retrieved from https://planet.osm.org ,' https://www.openstreetmap.org, 2017.
|
| 221 |
+
- [14] B. O. Community, Blender - a 3D modelling and rendering package , Blender Foundation, Stichting Blender Foundation, Amsterdam, 2018.
|
| 222 |
+
- [15] P. Series, 'Effects of building materials and structures on radiowave propagation above about 100 MHz,' Recommendation ITU-R , pp. 20401, 2015.
|
| 223 |
+
- [16] I. Loshchilov and F. Hutter, 'Decoupled weight decay regularization,' arXiv preprint arXiv:1711.05101 , 2017.
|