Are Transformers universal approximators of sequence-to-sequence functions?
Chulhee Yun, Srinadh Bhojanapalli, Ankit Singh Rawat, Sashank J. Reddi, Sanjiv Kumar
Introduction
Self-attention based Transformer networks (Vaswani et al., 2017) have been at the center of the recent progress on various natural language processing (NLP) tasks, including machine translation (Vaswani et al., 2017), language modeling (Radford et al., 2018; 2019), and question answering (Devlin et al., 2018; Yang et al., 2019; Liu et al., 2019). All these tasks involve learning models that map an input sequence of tokens to an output sequence of tokens. Transformers make it feasible to train large models to approximate these sequence-to-sequence functions due to their ability to process the input tokens in a parallel way, as opposed to the sequential nature of RNNs and LSTMs.
A Transformer block consists of two kinds of layers: a self-attention layer and a token-wise feed-forward layer, with skip connections present in both layers. The self-attention layer transforms each input token embedding using a weighted combination of the embeddings of all tokens in the input sequence, where weights are generated by pairwise dot-products among the input token embeddings. The token-wise feed-forward layer then independently processes each of these modified input token embeddings without any interaction among them. Notably, Transformers employ parameter reuse across tokens, as both layers use the same parameters to process each token. Moreover, Transformers have to rely solely on the pairwise dot-products to capture interaction between the input tokens.
Given the parameter sharing and limited interactions between tokens, it is natural to wonder: what class of sequence-to-sequence functions can the Transformer networks represent? Also, what is the role of the two different kinds of layers? Are both layers needed to obtain the representation power of Transformers? In the existing literature, the advantage of Transformers has often been attributed to their capability of computing contextual embeddings/mappings of the input, as opposed to fixed word embeddings as in word2vec (Mikolov et al., 2013). Is it possible to formalize the notion of contextual mappings? If yes, can Transformers actually compute such mappings? Such questions still remain elusive.
In this paper, we provide a mathematical definition of contextual mappings and show that multi-head self-attention layers can indeed compute contextual mappings of the input sequences. We further show that this ability to compute contextual mappings coupled with the value mapping ability of the feed-forward layers makes Transformers universal approximators of any permutation equivariant sequence-to-sequence function. We also improve this result using positional encodings, and show that Transformers can represent any sequence-to-sequence function; i.e., the restriction of permutation equivariance can be removed by positional encodings.
These results on universal approximation of sequence-to-sequence functions raise a natural question: is it possible to have a more efficient architecture to compute contextual mappings, consequently, preserving the ability to universally approximate sequence-to-sequence functions? Towards this, we explore other architectures that can implement contextual mappings (to some extent), and experimentally evaluate their performance. In our experiments, we notice that the models that combine these simpler architectures with Transformers have better performance, compared to the standalone Transformers. We conclude the paper by presenting more discussion and interesting future research directions along these lines.
We prove that Transformers are universal approximators of continuous and permutation equivariant sequence-to-sequence functions with compact support (Theorem 2). We also show that, if Transformers have trainable positional encodings added to the input, then they are universal approximators of continuous sequence-to-sequence functions on a compact domain (Theorem 3).
We formalize the notion of contextual mappings and show that the attention layers can compute contextual mappings, where each unique context is mapped to a unique vector (Lemma 6).
We experimentally evaluate other simpler layers that can compute contextual mappings to some extent, such as bi-linear projections and separable convolutions, and show that substituting some of the self-attention layers with these layers can result in better performance (Section 5).
2 Related works & notation
Analysis of attention-based models. Given the popularity of Transformers, there have been numerous works trying to understand the role of attention layers in natural language processing models. One such line of work focuses on probing the output of attention layers to understand the attention mechanism and internal language representation (Hewitt & Manning, 2019; Clark et al., 2019; Coenen et al., 2019; Vig & Belinkov, 2019). Although these results give valuable insights, a consistent theoretical analysis corroborating these findings is missing.
Universal approximation theorems. Universal approximation theorems are classical results in neural network theory, dating back many decades (Cybenko, 1989; Hornik, 1991). These results show that given unbounded width, a one-hidden-layer neural network can approximate arbitrary continuous function with compact support, up to any accuracy. Other results focusing on depth appeared more recently (Lu et al., 2017; Hanin & Sellke, 2017; Lin & Jegelka, 2018). In particular, Lu et al. (2017); Hanin & Sellke (2017) consider fully-connected ReLU networks whose input dimension is , and show that networks with width and unbounded depth are universal approximators of scalar-valued continuous functions. Lin & Jegelka (2018) show that a residual network with one hidden neuron per residual block is a universal approximator of scalar-valued functions, given unbounded depth. Although Transformer networks do have residual connections, due to their heavy parameter sharing, the existing analyses for residual networks do not extend to Transformers. Sannai et al. (2019) consider universally approximating permutation invariant/equivariant functions using fully-connected ReLU networks.
Turing completeness results on Transformers. Recently, Pérez et al. (2019) have shown that Transformers with infinite precision are Turing complete, which is not the case in finite precision setting (Dehghani et al., 2018). We note that Turing completeness deals with computation on formal languages (thus discrete objects), while universal approximation focuses on functions on a continuum. In other words, these are two different concepts; and one does not imply another.
Transformer networks
We define the Transformer networks as the composition of Transformer blocks. The family of the sequence-to-sequence functions corresponding to the Transformers can be defined as:
As seen in above, both layers (cf. (1) and (2)) of a Transformer block employ parameter reuse/sharing, because each token/column undergoes the same transformations (e.g., , , or ) regardless of its position. Moreover, interactions between tokens can only be captured through pairwise dot-products in the softmax operator (cf. (1)). Given such limitations in a single Transformer block’s representation power, it is not obvious what kinds of sequence-to-sequence functions can approximate; we provide the answer to this question in the next section.
Transformers are universal approximators of sequence-to-sequence functions
The following result shows that a Transformer network with a constant number of heads , head size , and hidden layer of size can approximate any function in .
Let and , then for any given , there exists a Transformer network , such that .
Let and , then for any given , there exists a Transformer network such that we have .
Theorems 2 and 3 provide an interesting characterization of the representation power of fixed-width Transformer networks. Since the function classes and become richer as we increase the values of , our results establish that general Transformer networks are also universal approximators of sequence-to-sequence functions. Remarkably, none of the parameters depend on the input sequence length or embedding dimension .
Here, we would like to again point out that Theorems 2 and 3 appear quite surprising at a first glance, given the parameter sharing across all the tokens in a sequence, e.g., feed-forward layers are applied token-wise and the projection matrices in the self-attention layers are the same across different tokens. Furthermore, attention layers can only capture pairwise interaction between different tokens in the sequence. In the next subsection, we briefly describe one of our key steps in overcoming the aforementioned restrictions and proving universal approximation power of Transformers.
Let us consider a setting where we are interested in embedding two sentences: 1) I am happy; and 2) I am Bob. These sentences are fed to a sequence-to-sequence model as
where and denote -dimensional embedding for the tokens ‘I’, ‘am’, ‘happy’, and ‘Bob’, respectively. Since the word ‘I’ occurs in different contexts in these sentences, in order to implement arbitrary sequence-to-sequence functions, the sequence-to-sequence model should map the two occurrences of ‘I’ to different values. We formally define this requirement below.
At the first thought, we can consider getting a contextual mapping by simply averaging all the tokens, because this can capture the one-word difference (e.g., “happy” vs. “Bob”) in two different contexts. However, if there are multiple words that are different, it is not guaranteed that the average will be different. Indeed, requiring unique mappings for all the tokens for any change in any number of tokens, is a steep requirement.
While the self-attention layer does consider pair-wise interactions among different input tokens, it is not clear if this weak form of pair-wise interaction with shared projection weights is sufficient to extract the underlying context. The following result, which we sketch here, shows that self-attention layers can implement a permutation equivariant contextual mapping over almost all elements of a grid in . We defer the full statement to Section 4.2.
Lemma 6 shows that a series of self-attention layers can implement contextual mappings, despite the apparent restriction that each of them can only capture pair-wise interaction. However, the restriction of permutation equivarance still exists because attention layers are inherently permutation equivariant. Coupled with the ability of token-wise feed-forward layers to map different values in to arbitrary output values, we can prove universal approximation capability of Transformers.
2 Proof of the universal approximation theorem (Theorem 2)
Next, we outline the proof of Theorem 2 in greater detail. We refer the reader to Section C for the proof of Theorem 3, since it is a modification of Theorem 2. Even though Theorems 2 and 3 do not specifically mention the required depth for approximation, our proof techniques do characterize it, and we show that our construction is tight in the number of parameters. We defer the discussion of depth to Section 4.4.
Recall that we want to show that given a function , we can find a Transformer network such that . Without loss of generality, we can assume that the compact support of is contained in . We achieve our desired objective in three key steps:
Step 1. Approximate with piece-wise constant functions. We first use (a variant of) the classical result that any continuous function can be approximated up to arbitrary accuracy by piece-wise constant functions. For , we define the following class of piece-wise constant functions.
Step 2. Approximate with modified Transformers. We then consider a slightly modified architecture for Transformer networks, where the softmax operator and are replaced by the hardmax operator and an activation function , respectively. Here, the set of allowed activations consists of all piece-wise linear functions with at most three pieces, where at least one piece is constant. Let denote the function class corresponding to the sequence-to-sequence functions defined by the modified Transformer networks. The following result establishes that the modified Transformer networks in can closely approximate functions in .
For each and , such that .
Step 3. Approximate modified Transformers with (original) Transformers. Finally, we show that can be approximated by . Let be such that .
Theorem 2 now follows from these three steps, because we have
Choosing small enough ensures that . ∎
We refer the reader to Sections B.1 and B.2 in the supplementary material for the formal statements and proofs of Steps and , respectively. As for Step , which is the most critical step in establishing the universal approximation property of Transformers, we provide a sketch of the proof of Proposition 4 in the next section, and refer the reader to Section B.3 for the complete proof.
Proof sketch of Proposition 4: different roles of two layers
As mentioned earlier, the heavy parameter sharing in Transformers makes the goal of universally approximating sequence-to-sequence functions seemingly difficult. Both the self-attention and the feed-forward layer weights inside a Transformer block are fixed across tokens. In this section, we show that Transformers are able to overcome this architectural constraint, and compute contextual mappings of the entire input sequence just based on the pair-wise interactions. The token-wise feedforward layers then transform these contextual mappings to the desired output sequence.
We highlight these inner workings of Transformers en route to proving Proposition 4. We want to show that given a piece-wise constant function , there exists a modified Transformer network that closely approximates . We achieve this goal by establishing the following three claims, which correspond to Lemmas 5, 6, and 7.
Next, a series of self-attention layers in the modified Transformer network can take the input and implement a contextual mapping such that, for and that are not permutation of each other, all the elements in and are distinct.
Finally, a series of feed-forward layers in the modified Transformer network can map elements of the contextual embedding to the desired output value of at the input .
Before discussing these three claims in detail, we note that even though a Transformer network stacks self-attention and feed-forward layers in an alternate manner, the skip connections enable these networks to employ a composition of multiple self-attention or feed-forward layers. Furthermore, as alluded earlier, these three steps clearly highlight the different roles that self-attention and feed-forward layers play in realizing the ability to universally approximate sequence-to-sequence functions: 1) self-attention layers compute precise contextual maps; and 2) feed-forward layers then assign the results of these contextual maps to the desired output values.
2 Contextual mapping by self-attention layers
If we define an attention layer of the form , then any entry in is shifted up by , while all the other entries stay untouched. We can choose and to selectively shift certain entries, hence the name selective shift operation.
3 Function value mapping by feed-forward layers
This brings us to the final step, which demonstrates the key utility of the feed-forward layers. After the contextual mapping by self-attention layers, each token captures the entire context available in the input sequence. The following result shows that token-wise application of a composition of feed-forward layers can map these tokens to the desired output values required by the function .
4 Tightness of constructions
We showed in this section that Theorem 2 requires Transformer blocks for approximation, where is the width of the cubes. Each transformer block is of constant width, so it has parameters; this means that the total number of parameters is . We note that this exponential dependence cannot be avoided in the worse case. If we assume continuity without any additional smoothness, quantizing the domain to cubes and approximating the function with constants require memorizing real numbers, where the factor of is due to permutation equivariance. Thus, Theorem 2 is optimal in the order of parameters.
If we compare with the residual network result (Lin & Jegelka, 2018), we can consider “flattening” into a -dimensional vector and fitting the function. The proof technique in (Lin & Jegelka, 2018) requires layers, where each layer has parameters: the total parameter requirement is . This shows that Transformers can approximate permutation equivariant functions in a more efficient way than residual networks.
In Section C, our proof of Theorem 3 shows that we require layers to approximate continuous (not permutation equivariant) sequence-to-sequence functions. As seen from the argument above, this construction is also optimal in the order of parameters.
Discussion and Experiments
As detailed in Section 4, the ability of the self-attention layers to compute contextual mappings plays a crucial role in the universal approximation property. Interestingly, our analysis shows that replacing the dot-product attention in Transformers with any other component capable of computing contextual mappings should preserve this universal approximation property. This leads naturally to questions about the alternative architectures that realize certain kinds of contextual mappings at different computational and memory costs. We explore and discuss some examples of such alternatives in this section. Our preliminary empirical study demonstrates their practical utility.
Given token embeddings as input, the bi-linear projection layer computes the following update.
This layer advantageously incurs smaller number of matrix multiplications as compared to the dot-product attention. That said, the number of parameters in this layer depend on the sequence length, making it harder to reuse the model across tasks with different input sequence lengths. Moreover, the weights used to compute the contextual embeddings () are independent of the inputs (), whereas in self-attention the weights depend on . The first drawback can be addressed by replacing the linear projection with a depth-wise separable convolution layer, which is discussed in the next subsection.
2 Depth-wise separable convolutions
A depth-wise convolution layer (Sifre & Mallat, 2014; Chollet, 2017; Kaiser et al., 2017) involves convolving each dimension of with a corresponding convolution filter of size :
3 Experiments
We now present our experiments with these other architectures, with the goal of understanding the extent to which computing contextual mappings can capture the performance of Transformers. As discussed earlier, and do not implement contextual mappings (cf. Definition 3.1), so we do not expect that either or based models to have the same performance as the expensive Transformers. These models do not use input dependent weights to compute attention, and hence have weaker representation power. Instead, our goal is to see if we can use these cheaper layers to replace (some of) the expensive self-attention layers.
We follow the experimental setting from Devlin et al. (2018) to train the Transformers, with the masked language model pre-training followed by a task specific fine-tuning, and work with a layer architecture based on . We present our results on a question answering task (SQuAD) (Rajpurkar et al., 2016) and a sentence entailment task (MNLI) (Williams et al., 2018). In our first set of experiments we train models that employ and layers, instead of the self-attention layer in eq.(1). We notice that, as expected, these simpler models have weaker performance than the self-attention layer. See Table 1 in Section D for a comparison of these models on MNLI.
Next, we swap a varying number of the first few self-attention layers in with , implemented with filter reuse across dimensions (Wu et al., 2019)We refer to Section D for a complete description of the setup.. Fig. 1 illustrates the performance of these hybrid models. Interestingly, models with or convolution layers and rest the self-attention layers, perform better than models with only the self-attention layers. Note that, replacing self-attention layer with also reduces the computational cost and the number of parameters. One explanation we have is that the first few attention layers tend to attend broadly to the whole sequence (as empirically observed in (Clark et al., 2019)), and the cheaper convolution layers can perform this job more efficiently. A detailed evaluation of such hybrid architectures will be interesting future research.
Our experiments also call for a deeper understanding of the exact nature of the embeddings computed by practical attention models. Since Transformers in practice have fixed depth, we believe that they might not be able to exactly implement contextual mappings as we defined in Definition 3.1. However, there is some preliminary empirical evidence that Transformers do implement some sort of “contextual mappings.” For example, Fig. 4 of Coenen et al. (2019) presents visualizations of embeddings of a single word in different contexts (sentences). They experimentally notice that Transformers, in addition to computing contextual mappings, also map a word into semantic clusters. Formalizing and evaluating this property of Transformers is an interesting direction for future work. We again note that Wu et al. (2019) have proposed an alternative way to compute such embeddings based on dynamic convolution layers. Evaluating the mappings computed by these models should shed more light on the workings of attention models and inspire efficient and better performing architectures.
References
Appendix A Proof of Claim 1
Suppose was given as input, where is a permutation matrix. First note that
where we used . Permutation equivariance of the token-wise feed-forward layer can be shown similarly:
where was used. This analysis shows that the function class is restricted to permutation equivariant functions.
Appendix B Proof details of Theorem 2
For any given and , one can find a such that which satisfies .
Thus, the approximation is also permutation equivariant. This proves the lemma. ∎
For each and , such that .
Proof Recall that refers to the class of functions representable with composition of Transformer blocks with heads of size in self-attention layers and hidden nodes in feed-forward layers. The same notation holds for the modified Transformers .
Note that the softmax operator on a matrix can be made arbitrarily close to hardmax by scaling up . That is,
This means that by scaling up parameters inside , we can approximate arbitrarily closely. Thus, the modified self-attention layers can be approximated with the original self-attention layers of the same number of heads and head size .
Also, any arbitrary (possibly discontinuous) piecewise linear function can be approximated arbitrarily closely by four ’s. Note that as at most three pieces, and at least one of the pieces is constant. For example, consider the following function :
This function can be approximated by four ’s, as claimed by the lemma:
Also, as we make , we can approximate as closely as possible using . The cases where the second or third piece is constant can be shown similarly. This means that the modified feed-forward layers (whose activation is ) with single hidden node can be approximated with the original feed-forward layers () with four hidden nodes.
Thus, given any , there exists a function arbitrarily close to , by appropriately choosing the parameters to be large enough. This finishes the proof. ∎
B.3 Finishing proof of Proposition 4
As we have already discussed in Section 4, we establish Proposition 4 in three steps:
Finally, a group of feed-forward layers in the modified Transformer network can map elements of the contextual embedding to the desirable values, i.e., the output of on the input .
These steps are formally stated in Lemmas 5, 6, and 7 in the main text. We present the proofs of these lemmas in the subsequent sections.
With the results established in these lemmas, we are now equipped with all the tools necessary to complete the proof of Proposition 4. Let us recall the functions , and from Lemma 5, 6, and 7, respectively. We now show that the (modified) Transformer network approximates the underlying peicewise constant function over all points in its support except for a set of of measure .
B.4 Proof of Lemma 5
The proof strategy is simple; using token-wise feed-forward layers, we implement the quantization function that works on the first row of the input. Then stack another layers that quantizes the second row, and so on.
Given input , we first start by clipping in the set and mapping the intervals to . This can be done by the following layer:
Next, add layers of the following form, for .
Each layer quantizes in to , without modifying other intervals.
B.5 Proof of Lemma 6
Before starting the proof, we first describe the key component of our proof, which we refer to the selective shift operation. Consider the following function, which can be expressed with a multiplicative attention head, with head size and hardmax :
for . Note that due to , all rows of except the first row are zero. From this observation, one can define a function parametrized by and , where , which consists of two attention heads:
What this means is that, if we define an attention layer of the form , then any column satisfying is shifted up in its first coordinate by , while all the other coordinates stay untouched. We call this the selective shift operation, because we can choose and to selectively shift certain entries of the input.
For any , it is easy to check two following facts:
If for all , i.e., , then , and the map from to is a bijection.
If there exists such that , then .
Therefore, one can say that gives the “column id” for each possible value of .
The rough idea of the construction is to apply the selective shift operation to each column id, by setting in the definition of to be and choosing and for each . More concretely, we stack attention layers, with attention parts for each , in increasing order of . After that, we add an extra single-head attention layer with attention part .
B.5.1 Category 1
In the first selective shift operation, the -th entry of () is shifted by the operation, while the other entries are left untouched. The updated value is
Therefore, after the operation, the output of the layer is , and the new value of the first column results in
Let us denote the updated “column id” as . We can show that , because
The second selective shift operation is applied to , by which only one entry will be shifted. The updated value is
After updating, the new inner product of and results in
We can show that , because
and the last inequality is true because and . Since we have , and the new maximum in is now , and the new minimum is .
More generally, we can repeat this process, and show that the -th shift operation shifts by , and results in the new column id
In the general case, holds , because
Therefore, after the -th selective shift operation, is the new maximum among and is the new minimum, which makes us possible to continue the process until the -th operation.
As a result, after the whole sweep from to by the first layers, a total of shift operations are applied, and the input is mapped to a new point , where and .
We can now prove the following technical lemma, whose proof is deferred to Appendix B.5.4:
After shift operations, satisfies the following bounds:
Also, the map from (where ) to is one-to-one.
As mentioned earlier, after this sweep, there is another attention layer with attention part . Since , what it does to is that it adds to each entry in the first row of . The output of this layer is defined to be the function .
Given this result so far, it is now left to check if the constructed network is really a permutation equivariant contextual mapping, i.e., if it satisfies Properties 6.1 and 6.2 in Lemma 6.
B.5.2 Category 2
In the extreme case of , we have , so the selective shift operation applied at does not shift the entry at all; therefore, at the end of the first attention layers, .
When , let the distinct values of ’s be . The shift operation is applied times, to , and shifts one or more entries at a time. After the first layers, the output has distinct , , whose distinct values are the same as the numbers we get when we apply shift operations to a length- sequence . Then, applying the same calculations from Category 1 shows that
and it follows from the upper bound in Lemma 10 that
After the global shifting by the last layer with attention part , we get the output which satisfies
B.5.3 Category 3
Recall that the selective shift operation is applied to each element of , not to negative values. In case of Category 3, we have , and never gets shifted upwards, so it remains as the minimum for the whole time.
In case where all ’s are negative, selective shift operation never changes the input , so we get . Since we have (entry-wise), the last layer with attention part adds to each entry in the first row of , further pushing it to the negative side. Therefore, the final output satisfies .
Now consider the case where at least one is positive. Let be the index that satisfies . Then, selective shift operation does not affect , and then it shifts by
where we used at the last inequality. The next shift operations shift by even larger amount, so at the end of the first layers, we have , while for .
Here, the last layer with attention part acts differently for negative and positive ’s. For negative ’s, it adds to , pushing them further to the negative side. For positive ’s, the layer adds to , so that they are all greater than or equal to . Note that .
Therefore, in both cases, we can see that the final output satisfies , for all . This completes the verification of Property 6.4.
B.5.4 Proof of Lemma 10
Proof of lower and upper bounds on are straightforward:
For one-to-one property of the map, consider and with increasing entries, which are mapped to and , respectively. Suppose . By definition,
Now assume for contradiction that . Then, we have . However, the remaining terms have “coarse resolution”, and they can never cancel and make the sum zero, because for example, can only have values . Thus, must hold and the first term must be zero.
Similarly, assume that . Then, the second term is in the interval . Again, the remaining terms cannot cancel the second term, hence must hold. We can proceed this way, and show that must hold for all , hence proving that the map is one-to-one.
B.6 Proof of Lemma 7
so is left untouched.
If some other is a permutation of , and , then
so -th column of will turn to
which is the desired output. In conclusion, this layer maps the column to , without affecting any other columns.
Appendix C Proof of Theorem 3
Proof of Theorem 3 can be done in a similar way as Theorem 2. As in the proof of Theorem 2, there are three parts: Lemma 8, Proposition 4, and Lemma 9. The statement and proof of Lemmas 8 and 9 can be done in almost the same way, this time without permutation equivariance.
For the proof of the second part, which corresponds to Proposition 4, we construct the network in a similar way. Recall that we can assume without loss of generality that . Choose
Then, the first column of is in , second is in , and so on; this means that for all rows, the coordinates are monotonically increasing. So we can use the same technique as the proof of Proposition 4 to divide the input values into cubes, quantize them to , apply contextual mapping, and then value mapping. We describe each step in the following.
In a similar way as Lemma 5, the goal of this step is to quantize the input in to its discrete version:
This can be done by feed-forward layers. We add layers of the following form, for and :
After layers, any input entry of in is quantized to .
C.2 Contextual mapping by attention layers
By Step 1, we quantized any input to its quantized version. We call this quantized version :
As done in Lemma 6, we define and , for all . Note that, because , we have
and . Notice that this corresponds to the Category 1 in the proof of Lemma 6.
For simplicity of notation, let . We stack attention layers, with attention parts for each , in increasing order of .
These attention layers perform selective shift operations on ’s, in increasing order of . As seen in Appendix B.5.1, shift operations result in . Also, the map from to is one-to-one, which can be shown in the same way as Appendix B.5.4. Since the range of ’s are a bit different, we have a different upper bound on :
Finally, we add an extra single-head attention layer with attention part . We define the output of this layer as . In a similar way as Appendix B.5.1, this layer shifts all the layers by , thus making the intervals corresponding to different values of disjoint from each other. This ensures that different contexts are mapped to distinct numbers in , thus implementing a contextual mapping.
C.3 Function value mapping by feed-forward layers
Now, it is left to map to the desired output. As seen in the last step, each different context maps to unique numbers , which are at least apart from each other. The value mapping step can be done in a similar way as Lemma 7. The construction now requires layers because there is no permutation equivariance.
Appendix D Experimental setup
For our experiments we follow the same setting as in BERT (Devlin et al., 2018). We first pre-train the models on the masked language modeling task and the next sentence prediction task. We use English Wikipedia corpus and BooksCorpus dataset (Zhu et al., 2015) for this pre-training. We use , a 12 layer Transformer model as the baseline. This model uses an embedding size of 768 and has 12 head self-attention layers and 3072 wide feed forward layers. We train it with the Adam optimizer, with dropout and weight decay. We do pre-training for 250k steps with a batch size of 1024 and a max sequence length of 512. Pre-training takes around 2 days on 16 TPUv3 chips. We take the pre-train models and finetune them on the MNLI and SQuAD datasets separately using the same hyper-parameters as in Devlin et al. (2018). MNLI is a sentence entailment task in which, given a premise sentence, requires us to classify a hypothesis sentence into neutral, contradiction or entailment classes. We report the classification accuracy on this task. SQuAD is a question answering task, in which given a paragraph and a question, requires us to identify the answer as a span of the words in the paragraph. For this task we report both the F1 score and the Exact Match (EM) percentage. The metrics are reported on the dev sets of these datasets.
For our experiments with the depth-wise separable convolution layers, we follow the implementation in (Wu et al., 2019). We first use a GLU layer followed by the convolution layer. We use 16 separable convolution filters, of filter length 128, and reuse them, with each filter operating on 48 of the 768 dimensions of the input. This layer also has a skip connection and the output is normalized using layer normalization, similar to the self-attention layer. In our experiments, we replace the self-attention layers of the Transformers, in the lower layers, with this convolution layer. We keep the feed forward layer of the Transformer block the same.
For the experiments performed in this paper, one might consider an alternate explanation that the tasks considered maybe are easy, and do not require any advanced architecture to solve them, and even a simple architecture (bi-linear projection or separable convolution) might solve these tasks. To rule out this case we consider an even simpler architecture, namely average attention, as a baseline for our experiments.
Average attention. An average attention layer replaces the self-attention layer, and just computes the average of projections of all the other tokens. That is, we replace in (1) with a matrix full of . The model still has the skip connections and the feed-forward layers like Transformer.