Transformer Lab

Tokenize with BPE, watch attention heads, rotate positions with RoPE, size a KV cache, route tokens to experts and quantize weights.

About the Transformer Lab

The Transformer Lab takes apart the architecture behind ChatGPT, Claude and Gemini, one piece at a time. Each experiment isolates a single idea, such as how text is split into tokens or why attention scores are divided by the square root of the head size, and lets you change the numbers and see the effect immediately.

It suits students who have met the word "attention" and want to know what it actually computes, and engineers preparing for interviews where KV cache sizes and mixture-of-experts routing come up. You need no maths beyond multiplying and adding, and nothing to install: everything runs in your browser.

A good order is the one below, from the input side of a model to the output side, then the efficiency tricks that make large models affordable. Each experiment links to the lesson in the Large Language Models course that explains it in full.

Experiments in this lab

  1. Tokenization (BPE): Learn merges from text and watch words become tokens.
  2. Embeddings: Similar meanings sit close together; relations become directions.
  3. Self-attention: Queries, keys and values, with a causal mask.
  4. Why divide by √d: Large heads blow up the scores; scaling keeps softmax soft.
  5. Multi-head attention: Several heads, several patterns, same parameter count.
  6. Sinusoidal and RoPE: Give each position a signature, or rotate by position.
  7. Temperature, top-k, top-p: Turn logits into a choice, from greedy to creative.
  8. KV cache: MHA to MLA: How much memory long context costs, and how to cut it.
  9. Mixture of experts: Route each token to a few experts and keep them balanced.
  10. Quantization: INT8, FP8 and INT4, and what an outlier does to them.