Get the 2026 ML Training Cookbook | 52 recipes — GRPO, Flow Matching, World Models, and everything in between Download Now →
Transformer Architecture
A neural network architecture based entirely on self-attention, replacing recurrence with parallel attention layers for superior sequence modeling.
The Transformer is a neural network architecture introduced by Vaswani et al. (2017) that processes sequences using self-attention mechanisms rather than recurrence (RNNs) or convolution (CNNs). By replacing sequential processing with parallel attention operations, Transformers can process all positions in a sequence simultaneously, enabling significantly faster training and better utilization of modern parallel hardware (GPUs, TPUs). This architectural shift enabled the scaling that produced modern large language models.
A standard Transformer consists of an encoder and a decoder, each built from stacked layers. Each layer contains a multi-head self-attention sub-layer and a position-wise feed-forward network. Layer normalization and residual connections are applied around each sub-layer. Since attention is permutation-invariant, positional encodings (sinusoidal or learned) are added to the input embeddings to inject information about token order. Decoder layers additionally include cross-attention to attend to the encoder's output.
Modern language models use variations of the Transformer: encoder-only models (BERT) for understanding tasks, decoder-only models (GPT, Llama) for generation, and encoder-decoder models (T5, BART) for sequence-to-sequence tasks. The decoder-only architecture has become dominant for large language models due to its simplicity and effectiveness in autoregressive generation. Key innovations beyond the original Transformer include rotary positional embeddings (RoPE), grouped-query attention, and mixture-of-experts layers.
- ■Introduced by Vaswani et al. (2017); replaces recurrence with self-attention
- ■Parallel processing enables faster training and better hardware utilization
- ■Core components: multi-head attention, feed-forward layers, residual connections, layer norm
- ■Variants: encoder-only (BERT), decoder-only (GPT/Llama), encoder-decoder (T5)
- ■Decoder-only is dominant for LLMs; innovations include RoPE, GQA, MoE
A decoder-only Transformer with 96 layers and rotary positional embeddings, trained autoregressively on trillions of tokens to produce a large language model.