Transformer

A neural network architecture that uses self-attention to process all parts of an input in parallel, forming the basis of most modern language and multimodal models.

Roadmap step 2 of 4: Attention and the MLP. Try it: Transformer Explainer: the transformer block ↗, LLM Visualization: a small GPT in 3D, step by step ↗

What it is

The transformer is a neural network design introduced for sequence tasks such as translation. Instead of reading input step by step, it lets every token look at every other token through self-attention. Stacks of attention and feed-forward layers, joined by residual connections and normalization, build up representations of the input. Variants exist for text, images, audio, video and more.

Why it matters

Transformers scale well with data and compute, which is why they underpin most large language models and many image, speech and video systems. Their parallel training suits modern GPUs. Their main cost is that standard attention grows quadratically with input length, which drives work on long context, linear attention and efficient inference.

How it works

Input is split into tokens, turned into embeddings, and given positional information so the model knows order. Each layer computes attention weights between tokens, mixes their information accordingly, then passes the result through a feed-forward network (MLP). Residual connections let information flow through the stack. Decoder-style models predict the next token, while encoder-style models build representations of a full input.