Math Labs — Introduction
The low-level machinery underneath a language model
A large language model looks like magic from the outside, but inside it is built from a surprisingly small set of mathematical moves, repeated billions of times: vectors and their angles, matrices that transform them, weighted sums, sines and cosines, and derivatives that say how to improve. Each lab in this section isolates one of those moves in two or three dimensions, where you can see it and drag it. Put together, they are the vocabulary you need to read how an LLM actually works.Below: first, one pass through a language model, step by step, with the labs that show each step; then each lab on its own, with the one mechanism it demonstrates and where that mechanism lives inside an LLM.
1. One pass through a language model
When a model reads your prompt and predicts the next word, every token travels through the same short pipeline, repeated in dozens of stacked layers:
-
01
Words become vectors
Each token is looked up as a list of a few thousand numbers — a point in a high-dimensional space, written as coordinates in a learned basis.
-
02
Position is added
Word order is encoded with sines and cosines at many frequencies, or by rotating pairs of coordinates through angles that grow with position (RoPE).
-
03
Each sub-layer sees a normalized copy
Before attention and again before the feed-forward step, a copy of each vector is rescaled to a standard length (LayerNorm or RMSNorm), then reweighted coordinate by coordinate, so its direction carries most of the meaning — close to a point on a high-dimensional sphere. The running vector itself, the residual stream, is never normalized; each sub-layer only adds its result to it.
-
04
Attention compares tokens
Matrices project each vector into a query, a key and a value. Dot products — cosines of angles, scaled by the vectors' lengths — score how related two tokens are, and a softmax turns the scores into an average of the values.
-
05
A feed-forward layer reshapes
Each vector goes through $Wx + b$, a nonlinearity such as ReLU or GELU, and another $Wx + b$ — affine maps building a function out of hinges.
-
06
Scores become a next word
A final matrix turns the last vector into one score per word in the vocabulary, and a softmax turns those scores into probabilities.
-
07
Training nudges every number
Learning means taking the derivative of the error with respect to every weight and stepping downhill — a first-order Taylor approximation, applied billions of times.
The whole attention step from 04 fits in one line, and every symbol in it is covered by these labs: $$\text{Attention}(Q,K,V) = \text{softmax}\!\left(\frac{QK^{\mathsf T}}{\sqrt{d}}\right)V$$ $Q$, $K$ and $V$ are matrix products of the token vectors (Matrices); $QK^{\mathsf T}$ is a table of dot products, each one a scaled cosine of an angle (Unit Circle, Sphere & Rotations); and multiplying the softmax weights by $V$ is a weighted average whose weights sum to 1 (Affine Transforms).
2. What each lab contributes
In the order they appear in the menu:
3. From these labs to the AI labs
Once these mechanisms feel familiar, the AI section's labs assemble them into the parts of a real model: Activation Functions (the nonlinearity between affine layers), Latent Space (meaning as geometry in many dimensions), Attention (dot products, softmax and weighted averages working together) and Gradient Descent (how all the weights are learned). The last of them, Model Internals, opens up a real language model and shows these mechanisms at work inside it.
4. What the labs leave out
Every lab works in two or three dimensions so you can see it. A real model does the same operations in thousands of dimensions, with billions of learned weights, stacked in dozens of layers — and some of what makes it work (tokenization, the training data, scale itself) is not a matter of geometry at all. What carries over unchanged is the mechanism: the angles, projections, weighted sums and derivatives you can drag around here are the same ones running inside the model, just many more of them at once.