The Transformer is a new simple network architecture based solely on attention mechanisms, dispensing with recurrence and convolutions entirely. Our 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. The Transformer generalizes well to other tasks, achieving state-of-the-art results after training for a fraction of the cost of the best models from the literature. Recurrent models have been firmly established as state-of-the-art approaches in sequence modeling and transduction problems such as language modeling and machine translation, but the inherently sequential nature precludes parallelization within training examples, making it a bottleneck. The Transformer addresses this bottleneck, making it a promising new direction for future research in this area of study.