Transformer, step by step

Watch a sentence travel the full pipeline — tokenize, embed, attend, pass through the learned layers, and predict the next word. Press Play, or use Step to move one beat at a time.

AI FundamentalsLarge Language Models
Speed
1Tokenize
2Embed + position
3Self-attention
4Transformer layers
5Predict output
1

Tokenization

Split the text into tokens; each maps to an integer ID in the vocabulary.

2

Embedding + positional encoding

Each token ID becomes a learned vector; position information is added so order is preserved.

Position values come from sine & cosine at different rates — so position 0 is 0.00, 1.00, 0.00, 1.00… and later positions shift (fast dimensions change quickly; slow ones stay near 0 and 1).

3

Multi-head self-attention

Every token weighs how much each other token matters. Different heads capture different relationships.

Arcs point from the focus word — thicker = higher weight.
4

The learned transformer layers

The block (attention + feed-forward) repeats, refining each token's meaning in context.

Inference — one forward pass

5

Predict the next token

The final representation becomes a probability over the vocabulary; the model emits a token and repeats.

Probabilities here are illustrative — they show the mechanism, not a specific trained model.