The Transformer is a neural network architecture for sequence modeling built entirely on attention mechanisms, dispensing with the recurrence and convolutions that dominated prior sequence models. It was introduced in June 2017 by eight researchers then at Google in the paper "Attention Is All You Need."1 Within a few years it had displaced recurrent networks across natural language processing, and it remains, as of July 2026, the foundation of essentially every frontier large language model, as well as of leading systems in vision, speech, and multimodal generation. Two properties drove this dominance: full parallelism across sequence positions in training, which let it absorb modern accelerator compute, and loss that improves predictably with scale, turning model building into a capital-allocation problem governed by scaling laws.
Role in the network
Before 2017, recurrent neural networks dominated sequence transduction, processing tokens one position at a time. The sequence-to-sequence framework of 2014 paired a recurrent encoder with a recurrent decoder, compressing the entire input into a fixed-size vector.4 This design had two structural problems: the sequential dependency limited training parallelism, since each hidden state had to wait for the previous one, and long-range dependencies were difficult to learn, since information degraded as it propagated step by step through the recurrent state.
Attention mechanisms were introduced as a patch for the second problem: Bahdanau, Cho, and Bengio showed in 2014 that letting the decoder compute a soft alignment over all encoder states, rather than relying on one compressed vector, substantially improved neural machine translation,2 and Luong, Pham, and Manning simplified the approach in 2015 with global and local variants.3 Attention here remained an accessory to recurrence; convolutional alternatives such as ByteNet and ConvS2S attacked the parallelism problem instead, but relating distant positions still cost operations growing with their distance. The Transformer's central move was to remove recurrence and convolution entirely: every position's representation becomes a direct function of every other, the maximum path length between any two tokens drops to one layer, and the computation reduces to large matrix multiplications that parallelize across the sequence.1
The original Transformer is an encoder-decoder model. Both stacks are repeated blocks with two main sublayers: multi-head self-attention and a position-wise feed-forward network, each wrapped in a residual connection followed by layer normalization. Input tokens become embedding vectors, and because pure attention is order-invariant, order information comes from positional encodings, fixed sinusoidal ones added to the token embeddings in the original paper.1
The decoder differs in two ways: its self-attention is masked so each position attends only to earlier positions, the property that makes autoregressive generation possible, and a cross-attention sublayer attends to the encoder output. At inference, generation proceeds one token at a time; since past keys and values do not change, implementations cache them (the KV cache), trading memory for computation. Managing it became a central systems problem of the LLM era, addressed by PagedAttention and grouped-query attention.1216
The architecture's computational signature is quadratic: attention compares every position with every other, so time and memory grow with the square of sequence length, a minor concern at the original contexts of a few hundred tokens that became the defining bottleneck as contexts stretched to hundreds of thousands. On WMT 2014 English-to-German translation the large configuration reached 28.4 BLEU, state of the art at the time, trained in days rather than weeks on eight GPUs, as reported by the authors.1
The mathematics
A block maps its input \(X \in \mathbb{R}^{n \times d_{\text{model}}}\), one row per position, to an output of the same shape. The attention sublayer projects every row into query, key, and value vectors and mixes them with scaled dot-product attention:1
$$\mathrm{Attention}(Q, K, V) = \mathrm{softmax}\!\left(\frac{QK^{\top}}{\sqrt{d_k}}\right)V$$| Symbol | Shape | Meaning |
|---|---|---|
| \(Q, K, V\) | \(n \times d_k\), \(n \times d_k\), \(n \times d_v\) | queries, keys, and payload values, one row per position |
| \(QK^{\top}\) | \(n \times n\) | compatibility scores between position pairs |
The row-wise softmax normalizes each score row to a distribution (the divisor \(\sqrt{d_k}\) keeps scores from saturating it as width grows), so every output row is a weighted average of value rows.1
Multi-head attention runs \(h\) such operations in parallel over separate learned projections and recombines them:
$$\mathrm{MultiHead}(X) = \mathrm{Concat}(\mathrm{head}_1, \ldots, \mathrm{head}_h)\,W^{O}, \qquad \mathrm{head}_i = \mathrm{Attention}(XW_i^{Q},\, XW_i^{K},\, XW_i^{V})$$with \(W_i^{Q}, W_i^{K} \in \mathbb{R}^{d_{\text{model}} \times d_k}\), \(W_i^{V} \in \mathbb{R}^{d_{\text{model}} \times d_v}\), and \(W^{O} \in \mathbb{R}^{hd_v \times d_{\text{model}}}\). The 2017 model used \(h = 8\) heads at \(d_k = d_v = d_{\text{model}}/h = 64\), at roughly the cost of one full-width attention.1
The feed-forward sublayer applies the same two-layer network at every position independently:
$$\mathrm{FFN}(x) = W_2\,\sigma(W_1 x + b_1) + b_2$$with \(x \in \mathbb{R}^{d_{\text{model}}}\) one position's vector, \(W_1 \in \mathbb{R}^{d_{\text{ff}} \times d_{\text{model}}}\), \(W_2 \in \mathbb{R}^{d_{\text{model}} \times d_{\text{ff}}}\), hidden width \(d_{\text{ff}} = 4\,d_{\text{model}}\), and \(\sigma\) the ReLU nonlinearity, later replaced by GELU and gated SwiGLU variants (treated at feed-forward network).1124
Each sublayer sits inside a residual connection and a normalization. The 2017 paper normalized after the residual addition (post-norm); modern large models normalize inside the residual branch (pre-norm), keeping an identity path that stabilizes deep training:121
$$\text{post-norm:}\quad x \leftarrow \mathrm{LayerNorm}(x + \mathrm{Sublayer}(x)), \qquad \text{pre-norm:}\quad x \leftarrow x + \mathrm{Sublayer}(\mathrm{LayerNorm}(x))$$where \(\mathrm{Sublayer}\) is either sublayer above, \(x \in \mathbb{R}^{n \times d_{\text{model}}}\) the block input, and \(\mathrm{LayerNorm}\) standardizes each position's \(d_{\text{model}}\)-vector before a learned scale and shift.23
Worked example: parameter count of a GPT-2-small-class model
GPT-2 small stacks 12 decoder blocks: \(d_{\text{model}} = 768\), \(h = 12\) heads, \(d_{\text{ff}} = 3072\), vocabulary 50,257, learned position embeddings for 1,024 positions.22 Per block the four attention projections hold \(4 \times 768 \times 768 = 2{,}359{,}296\) weights and the two feed-forward matrices \(2 \times 768 \times 3072 = 4{,}718{,}592\); biases and two layer norms add 9,984, for \(7{,}087{,}872\) per block and \(12 \times 7{,}087{,}872 = 85{,}054{,}464\) across the stack. The token embedding adds \(50{,}257 \times 768 = 38{,}597{,}376\), the position embedding 786,432, and the final layer norm 1,536; because GPT-2 ties its output projection to the token embedding, the unembedding adds nothing. The total, \(85{,}054{,}464 + 38{,}597{,}376 + 786{,}432 + 1{,}536 = 124{,}439{,}808\), is the commonly quoted 124 million: two thirds of each block's weights sit in the feed-forward matrices (\(4{,}718{,}592 / 7{,}087{,}872 \approx 0.67\)) and 68 percent of the total in the blocks.
Alammar's ''The Illustrated Transformer'' walks through the block visually.25
Intuition
In self-attention, each position emits query, key, and value vectors through learned projections. Attention weights are computed as scaled dot products between queries and keys, normalized with a softmax, and each position's output is the attention-weighted sum of values. Intuitively, every token asks a question of every other token and aggregates the answers. Multi-head attention runs several such operations in parallel over separate learned projections, letting different heads specialize in different relationships, such as syntactic dependencies or positional offsets, before their outputs are concatenated and projected back. The feed-forward sublayer, applied identically at every position, holds most of the parameters and is widely interpreted as the component in which factual associations are stored.
The residual stream turns depth into iterative refinement: each position's running vector is read and added to by every sublayer, kept legible by the pre-norm identity path. Because any two positions interact in one layer, long-range structure is as cheap as local, while the restriction to a few large dense matrix multiplications turns accelerator parallelism directly into training throughput.1
Variants and extensions
The architecture split into three broad lineages. Encoder-only models, from BERT in 2018, discard the decoder and are trained with masked-token objectives for understanding tasks; RoBERTa, ALBERT, and ELECTRA refined the recipe.5 Decoder-only models keep only the masked self-attention stack and train on next-token prediction, the design of the GPT series from OpenAI, from GPT-1 in 2018 through GPT-2 and GPT-3, and of essentially all contemporary large language models.67 Encoder-decoder models continue the original design for sequence-to-sequence tasks, T5 the most influential example.
Later engineering modified nearly every component, leaving the attention-block skeleton intact. Normalization moved before each sublayer (pre-norm), stabilizing deep stacks, and RMSNorm replaced full layer normalization in most open models. Sinusoidal positions gave way to learned embeddings, then to relative schemes, most prominently rotary position embeddings (RoPE), which rotate query and key vectors by position and dominate current practice.10 Gated feed-forward variants such as SwiGLU displaced the original ReLU networks.11 Mixture-of-experts layers replace the dense feed-forward network with many expert networks and a learned router, decoupling parameter count from per-token compute; the idea predates the Transformer but became standard through systems like Mixtral 8x7B and DeepSeek-V3.
A second family of extensions attacks the quadratic attention cost. Sparse attention restricts which position pairs interact, introduced for long-sequence generation in 2019.9 Sliding-window attention limits each token to a local neighborhood, used notably by Mistral 7B. Multi-query and grouped-query attention shrink the KV cache by sharing keys and values across heads,12 and Multi-head latent attention compresses the cache into a low-rank latent, introduced with DeepSeek-V2.13 FlashAttention left the mathematics unchanged but reordered computation around the GPU memory hierarchy, becoming the default implementation almost immediately.14 Work on attention sinks documented models piling attention mass onto initial tokens, an observation exploited for streaming inference and cache eviction.15
The architecture also escaped text: the Vision Transformer showed in 2020 that image patches can be treated as tokens, matching and then surpassing convolutional networks at scale.8 CLIP paired image and text Transformers for contrastive learning, Whisper applied the encoder-decoder form to speech recognition, and diffusion transformers replaced U-Nets as the backbone of image and video generators, including Sora and the successors of Stable Diffusion. Diffusion language models keep the Transformer backbone while replacing autoregressive decoding with iterative denoising. Finally, challengers to attention itself matured: state-space models such as Mamba offer linear-time sequence mixing,17 and as of 2026 they appear mainly inside hybrid architectures interleaving state-space or linear-attention layers with periodic full-attention layers.
Adoption
Virtually every prominent language model of the 2020s is a Transformer variant. The decoder-only form underlies the GPT line through GPT-4 and GPT-5, Anthropic's Claude family, Google DeepMind's Gemini family, Meta AI's Llama series, xAI's Grok, and the open-weight lines from China including DeepSeek-V3, Qwen3, Kimi K2, and GLM, most recent ones pairing the Transformer skeleton with mixture-of-experts feed-forward layers. Encoder-only Transformers descended from BERT continue to power search ranking, retrieval, and classification at industrial scale, and encoder-decoder models persist in translation and instruction-tuned workhorses like Flan-T5.
The architecture's scaling behavior, with loss falling predictably as parameters, data, and compute grow,718 is what turned it into the substrate of an industry: distributed training infrastructure, accelerator design at NVIDIA and elsewhere, and serving stacks were rebuilt around Transformer workloads. Post-training methods such as instruction tuning and reinforcement learning from human feedback turned its raw sequence predictors into assistants, and evaluation suites such as MMLU and its successors are defined against Transformer-based models. Beyond language, Transformers or Transformer-derived attention modules run vision (Vision Transformer, Segment Anything), speech (Whisper), image and video generation (DALL-E, Veo), and protein structure prediction, where AlphaFold 2's core modules are attention-based.
Limitations and critiques
The best-documented limitation is cost. Quadratic attention makes long contexts expensive to train and serve, and the KV cache makes inference memory grow linearly with context and batch size, which is why most post-2022 architecture work (grouped-query and latent attention, sliding windows, cache quantization, paged memory management) targets inference economics rather than modeling power.121314 Position-encoding schemes generalize imperfectly beyond training lengths, and models often use very long contexts unevenly, with retrieval degrading for information buried mid-context, the "lost in the middle" effect.20
A second line of critique concerns expressivity and reliability. Theoretical work places fixed-depth Transformers in restricted circuit-complexity classes, implying that certain algorithmic problems cannot be solved in a single forward pass and motivating chain-of-thought decoding and test-time compute as ways to buy the sequential computation it lacks. Length generalization on algorithmic tasks remains brittle. Critics also note that the architecture's success is inseparable from its appetite: frontier training runs consume data at internet scale and electricity at industrial scale, and the same scaling laws that reward investment concentrate capability in the few organizations able to pay.18 Interpretability remains partial: attention weights were once read as explanations, later work showed them unreliable, and mechanistic understanding of trained Transformers is an open research program. Finally, the challenger architectures of 2023 onward, state-space models and linear-attention recurrences, demonstrate that attention is not uniquely necessary for strong language modeling at matched scale, though as of 2026 none has displaced it at the frontier.17
History
The precursors were attentional add-ons to recurrent translation systems: Bahdanau, Cho, and Bengio's soft alignment mechanism, posted in September 2014, and Luong, Pham, and Manning's global and local attention in 2015.23 By 2016 attention-augmented recurrent encoder-decoders were the standard in neural machine translation, including Google's production system.
"Attention Is All You Need" was submitted to arXiv in June 2017 by Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan Gomez, Łukasz Kaiser, and Illia Polosukhin, all then at Google (Google Brain and Google Research, Gomez an intern), with a footnote declaring equal contribution in randomized order.1 According to later retrospectives, Uszkoreit had been advocating self-attention as a replacement for recurrence, Vaswani and Parmar drove the model's development, Shazeer joined late and rewrote much of the implementation, and the title riffed on the Beatles song. The paper was presented at NIPS (now NeurIPS) 2017. Dominance was not immediate: recurrent models remained competitive through 2018, and the Transformer won through the pretraining paradigm. OpenAI's GPT (June 2018) showed generative pretraining of a decoder-only Transformer transferring to downstream tasks;6 Google's BERT (October 2018) did the same for the encoder with masked-language modeling,5 and for a period encoder models (RoBERTa, XLNet, ALBERT) defined the leaderboards.
The scaling era followed. Kaplan et al. published the power-law scaling results in January 2020,18 GPT-3 demonstrated few-shot learning at 175 billion parameters that May,7 and Google's LaMDA and PaLM and DeepMind's Gopher and Chinchilla extended the program, Chinchilla's 2022 compute-optimal analysis resetting how parameters and data were balanced.19 The Megatron-LM line at NVIDIA established the tensor-parallel training patterns that made these sizes feasible. ChatGPT's launch in November 2022 moved the architecture from research into mass consumer use, and the efficiency descendants documented above, from FlashAttention (2022) through PagedAttention (2023), latent attention (2024), and state-space hybrids (2024 onward), define the current period, in which innovation chiefly targets the cost of serving long contexts.
The paper became one of the most cited in computer science, and its authors' trajectories a story of their own: all eight had left Google by mid-2023, founding or joining Adept and Essential AI (Vaswani, Parmar), Character.AI (Shazeer, who reportedly returned to Google in 2024), Inceptive (Uszkoreit), Sakana AI (Jones), Cohere (Gomez), NEAR (Polosukhin), and OpenAI (Kaiser), a diaspora often cited as emblematic of the commercial wave the paper set off.
See also
References
-
Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A., Kaiser, Ł., Polosukhin, I., "Attention Is All You Need," arXiv:1706.03762, June 2017. ↩↩↩↩↩↩↩↩↩↩
-
Bahdanau, D., Cho, K., Bengio, Y., "Neural Machine Translation by Jointly Learning to Align and Translate," arXiv:1409.0473, September 2014. ↩↩
-
Luong, M.-T., Pham, H., Manning, C., "Effective Approaches to Attention-based Neural Machine Translation," arXiv:1508.04025, August 2015. ↩↩
-
Sutskever, I., Vinyals, O., Le, Q., "Sequence to Sequence Learning with Neural Networks," arXiv:1409.3215, September 2014. ↩
-
Devlin, J., Chang, M.-W., Lee, K., Toutanova, K., "BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding," arXiv:1810.04805, October 2018. ↩↩
-
Radford, A., Narasimhan, K., Salimans, T., Sutskever, I., "Improving Language Understanding by Generative Pre-Training," OpenAI, June 2018. ↩↩
-
Brown, T., et al., "Language Models are Few-Shot Learners," arXiv:2005.14165, May 2020. ↩↩↩
-
Dosovitskiy, A., et al., "An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale," arXiv:2010.11929, October 2020. ↩
-
Child, R., Gray, S., Radford, A., Sutskever, I., "Generating Long Sequences with Sparse Transformers," arXiv:1904.10509, April 2019. ↩
-
Su, J., et al., "RoFormer: Enhanced Transformer with Rotary Position Embedding," arXiv:2104.09864, April 2021. ↩
-
Shazeer, N., "GLU Variants Improve Transformer," arXiv:2002.05202, February 2020. ↩↩
-
Ainslie, J., et al., "GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints," arXiv:2305.13245, May 2023. ↩↩↩
-
DeepSeek-AI, "DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Model," arXiv:2405.04434, May 2024. ↩↩
-
Dao, T., Fu, D., Ermon, S., Rudra, A., Ré, C., "FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness," arXiv:2205.14135, May 2022. ↩↩
-
Xiao, G., et al., "Efficient Streaming Language Models with Attention Sinks," arXiv:2309.17453, September 2023. ↩
-
Kwon, W., et al., "Efficient Memory Management for Large Language Model Serving with PagedAttention," arXiv:2309.06180, September 2023. ↩
-
Gu, A., Dao, T., "Mamba: Linear-Time Sequence Modeling with Selective State Spaces," arXiv:2312.00752, December 2023. ↩↩
-
Kaplan, J., et al., "Scaling Laws for Neural Language Models," arXiv:2001.08361, January 2020. ↩↩↩
-
Hoffmann, J., et al., "Training Compute-Optimal Large Language Models," arXiv:2203.15556, March 2022. ↩
-
Liu, N. F., et al., "Lost in the Middle: How Language Models Use Long Contexts," arXiv:2307.03172, July 2023. ↩
-
Xiong, R., et al., "On Layer Normalization in the Transformer Architecture," arXiv:2002.04745, February 2020. ↩
-
Radford, A., et al., "Language Models are Unsupervised Multitask Learners," OpenAI, February 2019. ↩
-
Ba, L. J., Kiros, J. R., and Hinton, G. E., "Layer Normalization," arXiv:1607.06450, July 2016. ↩
-
Hendrycks, D., and Gimpel, K., "Gaussian Error Linear Units (GELUs)," arXiv:1606.08415, June 2016. ↩
-
Alammar, J., "The Illustrated Transformer," jalammar.github.io/illustrated-transformer/, retrieved July 2026; visual walkthrough of the architecture. ↩
