Lab
A game and six toys for getting your hands on the mechanisms. They all run in your browser on toy data: they don’t replace real models, but they let you see the idea without intermediaries. At the end, a notebook for trying a real model.
Who’s that model?
MenuSee: Base stats (how to read an entry)
Keys 1–4 or arrows
Attention: who looks at whom
MenuSee: Self-attention · Causal mask · Encoder · Decoder · Transformer · BERT · GPT-2
Pick a word: the lines show which other words it “attends” to, and how strongly.
Attention matrix (rows: who asks; columns: whom)
Weights set by hand for illustration, not taken from a real model. Look at “it”: it attends mostly to “animal”, the phrase it refers to. In causal mode every word can only look back, so “animal” cannot consult “tired”.
Temperature and sampling
MenuSee: Softmax · Logits · Temperature · Sampling (top-k, top-p) · GPT-3 · ChatGPT (InstructGPT)
The cat jumped onto the…
The logits are made up. At low temperature the distribution piles onto the most likely option (almost greedy decoding); at high temperature it flattens and odd continuations appear. Top-p cuts the tail: sampling only among the most likely options that add up to p.
Byte-pair encoding (BPE)
MenuSee: Token · Tokenization · Byte-pair encoding (BPE) · Vocabulary · GPT-2
Type or paste a text. The BPE algorithm starts from single characters and, at each step, merges the most frequent neighboring pair. Move the slider to watch subwords appear.
Learned merges, in order
A real tokenizer learns tens of thousands of merges over a huge corpus; this one learns only from your text. The ▁ symbol marks the start of a word. Notice that merges follow frequency, not morphology: sometimes they match morphemes (play-, -ed, -s) and sometimes they don’t.
Vector spaces and analogies
MenuSee: Embedding · Cosine similarity · Distributional hypothesis · Vector · word2vec
Coordinates placed by hand in two dimensions so the idea is visible. Real embeddings have hundreds of dimensions, are learned from how words are distributed in a corpus, and analogies work considerably worse than this textbook example suggests (part of their apparent success depends on excluding the input words).
The perceptron learns (or not)
MenuSee: Decision boundary · Gradient descent · Nonlinearity · Perceptron · Multilayer perceptron (backprop)
Click to add points of the selected class. The perceptron fixes its weights every time it misclassifies a point: w ← w + η·(y − ŷ)·x.
With the keyboard: arrows move the crosshair, Enter adds a point.
With linearly separable data, the perceptron converges (Rosenblatt’s convergence theorem). With XOR no straight line separates the classes: the line wobbles forever. That limitation, stressed by Minsky and Papert in 1969, is only overcome with hidden layers.
A decision tree for the weather
MenuSee: Entropy and information gain · Classification · Overfitting · Decision tree (ID3/C4.5)
Information gain of each attribute at the root
Resulting tree
The 14 days of the “weather” dataset
The “weather” dataset is fictitious and tiny; Witten et al. use it throughout their book, taken from Quinlan (1986). Choosing the root by information gain gives the tree of their Figure 4.4. Try forcing a different root: the tree grows and becomes harder to read, even though it fits the training data just as well. (Witten et al., 2017, pp. 10, 106–109)
Notebooks
MenuSee: Natural language inference (NLI) · Fine-tuning · Bi-encoders and cross-encoders · Classification · BERT
Google Colab notebooks that load real models. They run on Google’s servers, not in your browser.