Attention Is All You Need
by Ashish Vaswani et al.
Audio version created with Paper2Audio.
Listen on Paper2Audio
Attention Is All You Need
Ashish Vaswani et al.
Audio by Paper2Audio; with a lot of added context
Abstract
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 W.M.T 2014 English-to-German translation task, improving over the existing best results, including ensembles, by over 2 bleu. On the W.M.T 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.
Additional context
This document introduces a pivotal shift in how machines process human language, moving away from systems that read text linearly, like a person reading a sentence from left to right. Before this work, the field relied heavily on Recurrent Neural Networks (RNNs), which processed words one by one; however, these systems often "forgot" the beginning of a long sentence by the time they reached the end and were slow to train because they couldn't handle multiple words simultaneously. By building upon earlier concepts of "attention"—a technique that allows a model to focus on the most relevant parts of an input regardless of their position—this research established a foundation for the modern era of Generative AI. This transition to a non-linear, parallelized architecture is what eventually enabled the creation of massive Large Language Models (LLMs) like GPT-4, as it allowed researchers to train models on nearly the entire internet by utilizing the immense computing power of modern GPUs.
1 Introduction
2 Definitions
Definition 1:
Transduction: The process of converting one sequence of data into another, such as translating a sentence from English to German.
Definition 2:
Encoder-decoder architecture: A model design where one part (encoder) processes the input into a compressed representation and another part (decoder) generates the output from that representation.
Recurrent neural networks, long short-term memory and gated recurrent 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. Numerous efforts have since continued to push the boundaries of recurrent language models and encoder-decoder architectures.
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 minus 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 and conditional computation, while also improving model performance in case of the latter. The fundamental constraint of sequential computation, however, remains.
Definition
Attention mechanism: A mechanism that allows a model to focus on specific, important parts of the input sequence regardless of how far apart they are.
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. In all but a few cases, however, such attention mechanisms are used in conjunction with a recurrent network.
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 P.100 GPUs.
2 Background
Definition
Multi-Head Attention: An attention approach that uses multiple 'heads' to allow the model to focus on different types of relationships in the data simultaneously.
The goal of reducing sequential computation also forms the foundation of the Extended Neural GPU, ByteNet and ConvS.2.S, 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 ConvS.2.S and logarithmically for ByteNet. This makes it more difficult to learn dependencies between distant positions. 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.
Definition
Self-attention: An attention mechanism where the model looks at different positions of the same sequence to better understand the context of a specific word.
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.
End-to-end memory networks are based on a recurrent attention mechanism instead of sequence-aligned recurrence and have been shown to perform well on simple-language question answering and language modeling tasks.
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 sequence-aligned R.N.N's 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].
3 Model Architecture
Definition
Auto-regressive: A model that generates output one element at a time, using its own previous outputs as inputs for the next step.
Most competitive neural sequence transduction models have an encoder-decoder structure. Here, the encoder maps an input sequence of symbol representations x 1 through x n to a sequence of continuous representations z equals z 1 through z n. Given z, the decoder then generates an output sequence y 1 through y m of symbols one element at a time. At each step the model is auto-regressive, consuming the previously generated symbols as additional input when generating the next.
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.
Figure 1 summary: This figure is a schematic diagram. It illustrates the architecture of the Transformer model, depicting the structural flow from inputs and shifted right outputs through embedding layers and positional encodings into a series of encoder and decoder blocks. The encoder consists of multi-head attention and feed-forward networks with residual connections and normalization, while the decoder incorporates an additional multi-head attention layer to attend to the encoder's output. The process culminates in a linear layer and a softmax function to produce output probabilities. The design indicates a reliance on attention mechanisms rather than recurrence to handle sequential data, enabling the model to process information in parallel across multiple layers.
3.1 Encoder and Decoder Stacks
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, position-wise fully connected feed-forward network.
3 Definitions
Definition 1:
Residual connection: A shortcut connection that allows information to skip one or more layers, helping to prevent data loss and making deep networks easier to train.
Definition 2:
Layer normalization: A technique to standardize the inputs to a layer, ensuring they have a consistent mean and variance to speed up training.
Definition 3:
Embedding: The process of converting a discrete token (like a word) into a continuous vector of numbers that captures its meaning.
We employ a residual connection around each of the two sub-layers, followed by layer normalization. That is, the output of each sub-layer is LayerNorm (x plus 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 equals 512.
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.
Definition
Masking: A method used in the decoder to hide future tokens in a sequence, ensuring the model only uses past information to predict the next word.
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.
3.2 Attention
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 of the values, where the weight assigned to each value is computed by a compatibility function of the query with the corresponding key.
3.2.1 Scaled Dot-Product Attention
2 Definitions
Definition 1:
Dot-product: A mathematical operation used to calculate the similarity between two vectors, often used in attention to determine how much 'focus' to put on a word.
Definition 2:
Softmax function: A function that turns a vector of numbers into a vector of probabilities that sum to 1.
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 square root of d k , and apply a softmax function to obtain the weights on the values.
Figure 2 summary: This figure consists of two architectural diagrams. The left side illustrates the internal process of Scaled Dot-Product Attention, showing a sequence of operations including matrix multiplication, scaling, optional masking, a softmax function, and a final matrix multiplication involving query, key, and value inputs. The right side depicts Multi-Head Attention, which employs multiple parallel Scaled Dot-Product Attention layers, each preceded by linear transformations of the inputs and followed by a concatenation and a final linear layer. The figure demonstrates that Multi-Head Attention is a higher-level structure that leverages multiple instances of the Scaled Dot-Product Attention mechanism to process information in parallel.
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:
Math summary: This expression calculates a scaled dot product attention mechanism. It computes the dot product of query and key matrices, divides the result by a scaling factor, applies a softmax function to determine weights, and finally multiplies these weights by the value matrix to produce the output.
The two most commonly used attention functions are additive attention, and dot-product (multiplicative) attention. Dot-product attention is identical to our algorithm, except for the scaling factor of 1 over square root of d x . 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.
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. 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. To counteract this effect, we scale the dot products by 1 divided by the square root of d k.
3.2.2 Multi-Head Attention
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.
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.
Math summary: This process calculates multi head attention by applying separate linear projections to the query, key, and value inputs for multiple attention heads. The outputs from these heads are concatenated and then multiplied by a final output weight matrix to produce the final result.
Where the projections are parameter matrices W i superscript Q in the real numbers d model times d k, W i superscript K in the real numbers d model times d k, W i superscript V in the real numbers d model times d v and W superscript O in the real numbers h times d v times d model.
In this work we employ h equals 8 parallel attention layers, or heads. For each of these we use d k equals d v equals d model divided by h equals 64. Due to the reduced dimension of each head, the total computational cost is similar to that of single-head attention with full dimensionality.
3.2.3 Applications of Attention in our Model
The Transformer uses multi-head attention in three different ways:
- 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].
- 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.
- 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 -infinity ) all values in the input of the softmax which correspond to illegal connections. See Figure 2.
3.3 Position-wise Feed-Forward Networks
Definition
ReLU activation: A simple mathematical function used in neural networks to introduce non-linearity, effectively 'turning off' negative values.
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.
Math summary: This computation performs a feed forward network operation using two linear transformations and a non linear activation. It multiplies the input values by a first set of weights and adds a bias, applies a maximum operation to remove negative values, and then multiplies the result by a second set of weights and adds a final bias.
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 equals 512, and the inner-layer has dimensionality d ff equals 2048.
3.4 Embeddings and Softmax
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 square root of d model .
3.5 Positional Encoding
Definition
Positional encoding: Added information that tells the model the position of each word in a sequence, since the Transformer doesn't process data sequentially.
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.
In this work, we use sine and cosine functions of different frequencies:
Math summary: This computation generates positional encodings by applying sine and cosine functions to a position value. The process scales the position by a frequency factor based on the dimension index to produce a unique coordinate for each input location.
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 pi to 10000 times 2 pi. 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, P.E pos plus k can be represented as a linear function of P.E pos.
We also experimented with using learned positional embeddings 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.
Table 3 summary: This table evaluates various architectural modifications to the Transformer model on an English-to-German translation task. The results indicate that while increasing the number of attention heads and adjusting their dimensions has a modest impact, significantly increasing the model dimension, feed-forward network size, or the number of layers generally improves performance, as seen in the big model. Reducing the number of layers leads to a noticeable decline in translation quality and an increase in perplexity. Changes to dropout and label smoothing also affect results, though the impact is less pronounced than scaling the model size. Replacing sinusoidal positional embeddings with learned ones yields similar performance to the base model.
4 Why Self-Attention
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 through x n to another sequence of equal length z 1 through z n, with x i and z i in R superscript d, such as a hidden layer in a typical sequence transduction encoder or decoder. Motivating our use of self-attention we consider three desiderata.
Definition
Computational complexity: A measure of the computational resources required by an algorithm as the input size grows.
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.
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. Hence we also compare the maximum path length between any two input and output positions in networks composed of the different layer types.
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 and byte-pair 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.
Table 1 summary: The table compares different neural network layer types based on their computational complexity, sequential operations, and maximum path lengths. Self-attention offers the shortest path length and minimal sequential operations but has the highest complexity relative to sequence length. Recurrent layers exhibit the highest sequential operations and path lengths, scaling linearly with sequence length. Convolutional layers provide a logarithmic path length and constant sequential operations, while restricted self-attention reduces complexity compared to full self-attention at the cost of an increased maximum path length.
A single convolutional layer with kernel width k less than n does not connect all pairs of input and output positions. Doing so requires a stack of big O of n divided by k convolutional layers in the case of contiguous kernels, or big O of log base k of n in the case of dilated convolutions, 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, however, decrease the complexity considerably, to big O of k times n times d plus n times d squared. Even with k equals 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.
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.
5 Training
This section describes the training regime for our models.
5.1 Training Data and Batching
We trained on the standard W.M.T 2014 English-German dataset consisting of about 4.5 million sentence pairs. Sentences were encoded using byte-pair encoding, which has a shared source-target vocabulary of about 37000 tokens. For English-French, we used the significantly larger W.M.T 2014 English-French dataset consisting of 36 million sentences and split tokens into a 32000 word-piece vocabulary. 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.
5.2 Hardware and Schedule
We trained our models on one machine with 8 nvidia P.100 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).
5.3 Optimizer
Definition
Adam optimizer: An optimization algorithm used to update network weights efficiently during training.
We used the Adam optimizer with beta 1 equals 0.9, beta 2 equals 0.98 and epsilon equals 10 to the power of negative 9. We varied the learning rate over the course of training, according to the formula:
Math summary: This formula calculates the learning rate by multiplying a model dimension scaling factor by the smaller of two values. The process selects either a linear increase based on warmup steps or a decrease proportional to the inverse square root of the current step number.
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 equals 4000.
5.4 Regularization
We employ three types of regularization during training:
Definition
Dropout: A regularization technique where random neurons are 'dropped' during training to prevent the model from overfitting to the training data.
Residual Dropout We apply dropout 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 .
2 Definitions
Definition 1:
Label smoothing: A technique that prevents the model from becoming too confident in its predictions by slightly smoothing the target labels.
Definition 2:
BLEU score: The standard metric for evaluating the quality of machine-translated text by comparing it to human references.
Label Smoothing During training, we employed label smoothing of value epsilon ls equals 0.1. This hurts perplexity, as the model learns to be more unsure, but improves accuracy and bleu score.
6 Results
6.1 Machine Translation
On the W.M.T 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 P.100 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.
Table 2 summary: The Transformer models, particularly the big version, outperform previous state-of-the-art models in translation quality for both English-to-German and English-to-French tasks. Notably, the Transformer achieves these superior results while requiring significantly lower training costs compared to the other models and their ensembles.
On the W.M.T 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.
Definition
Beam search: A search algorithm used during output generation to explore multiple possible word sequences and pick the most likely one.
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 alpha = 0.6 . 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.
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.
6.2 Model Variations
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.
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.
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, and observe nearly identical results to the base model.
6.3 English Constituency Parsing
Definition
Constituency parsing: The process of analyzing the grammatical structure of a sentence to create a hierarchical tree representation.
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, R.N.N sequence-to-sequence models have not been able to attain state-of-the-art results in small-data regimes.
We trained a 4-layer transformer with d model = 1024 on the Wall Street Journal (W.S.J) portion of the Penn Treebank, about 40 thousand training sentences. We also trained it in a semi-supervised setting, using the larger high-confidence and BerkleyParser corpora from with approximately 17 million sentences. We used a vocabulary of 16 thousand tokens for the W.S.J only setting and a vocabulary of 32 thousand tokens for the semi-supervised setting.
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 alpha = 0.3 for both W.S.J only and the semi-supervised setting.
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.
Table 4 summary: The Transformer parser demonstrates strong performance on English constituency parsing, outperforming most other discriminative models trained only on the WSJ dataset. When utilizing semi-supervised training, the Transformer achieves higher F1 scores than several other semi-supervised approaches, although it remains slightly behind the top-performing multi-task and generative models.
In contrast to R.N.N sequence-to-sequence models, the Transformer outperforms the Berkeley-Parser even when training only on the W.S.J training set of 40 thousand sentences.
7 Conclusion
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.
For translation tasks, the Transformer can be trained significantly faster than architectures based on recurrent or convolutional layers. On both W.M.T 2014 English-to-German and W.M.T 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.
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 goal of ours.
The code we used to train and evaluate our models is available at github.com U.R.L
Acknowledgements We are grateful to Nal Kalchbrenner and Stephan Gouws for their fruitful comments, corrections and inspiration.
You have reached the end of the main document. Additional summarized content follows
Figure 3 summary: This figure is an attention visualization map. It displays the attention weights from the word making to other tokens in a sentence within the encoder self-attention of a specific neural network layer. The visualization shows how multiple attention heads link the verb making to various other words in the sequence. The pattern indicates that the model successfully captures long-distance dependencies, as several attention heads focus on the words more and difficult, thereby linking the verb to its corresponding phrase to complete the semantic meaning of the sentence.
Figure 4 summary: This figure consists of three attention maps. The top map displays the full attention patterns for a specific head in the fifth layer of a six-layer model, while the bottom two maps isolate the attention weights specifically for the word its for two different heads in the same layer. The visualization demonstrates how the model distributes attention across a sequence of words, specifically highlighting the connections between the word its and other terms in the sentence. The sharp focus of the attention for the word its suggests that these specific heads are specialized for anaphora resolution, effectively linking a pronoun to its corresponding referent.
Figure 5 summary: This figure consists of two parallel visualization plots showing attention weights between tokens in a sentence. The plots illustrate the attention patterns of two different heads from the encoder self-attention at a specific layer, mapping the relationships between words in the input sequence. The visualizations demonstrate that different attention heads focus on different structural elements of the sentence, indicating that they have learned to perform distinct tasks in processing the linguistic data.