# Attention Is All You Need ## 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. ## Authors - Ashish Vaswani - Noam Shazeer - Niki Parmar - Jakob Uszkoreit - Llion Jones - Aidan N. Gomez - Lukasz Kaiser - Illia Polosukhin ## Introduction 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. ## Key Innovation The Transformer eschews recurrence and instead relies entirely on an attention mechanism to draw global dependencies between input and output sequences. This 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. ## Model Architecture Most competitive neural sequence transduction models have an encoder-decoder structure. Here, the encoder maps an input sequence of symbol representations to a sequence of continuous representations. Given the continuous representation, the decoder generates an output sequence of symbols one element at a time. ## Attention Mechanism 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. ## Performance On the WMT 2014 English-to-German translation task, our model achieves a BLEU score of 28.4, outperforming all existing models, including ensembles, by over 2.0 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.0. ## Conclusion We presented the Transformer, the first transduction model based entirely on attention, replacing the recurrent layers most commonly used in encoder-decoder architectures with multi-headed self-attention. This architecture allows for significantly more parallelization and achieves state-of-the-art results on machine translation tasks.