Linear Algebra as Geometry
Vectors as directions, matrices as maps, and why high-dimensional space makes superposition possible.
- → Read a dot product as similarity and a matrix as a transformation of space
- → Explain rank, projections, and SVD geometrically
- → State why exponentially many almost-orthogonal directions fit in d dimensions
Directions, not lists of numbers
Every sentence you will read in an interpretability paper is about directions in activation space. “The refusal direction.” “The feature points this way.” “This head writes into the residual stream.” None of that means anything until a vector stops being a list of numbers and becomes an arrow.
So: a vector is an arrow from the origin. Its length is how strongly something is present; its direction is what that something is. GPT-2 small carries a 768-dimensional arrow at every token position — impossible to picture, but every fact below is proved in 2-D and stays true in 768-D.
The dot product of two vectors multiplies matching coordinates and adds them up. Geometrically it is something better:
Read the right-hand side term by term. and are the two lengths; is pure direction agreement — 1 for parallel, 0 for perpendicular, −1 for opposite. Big dot product means long and aligned. Zero means perpendicular: as far as this measurement is concerned, the two vectors are about unrelated things.
Projection: the shadow and the leftover
Ask a sharper question than “are these similar?”: how much of this vector lies along that direction, and what is left over? That is a projection, and it is the single most-used operation in interpretability practice.
Shine a light straight down onto a line through the origin. The shadow the vector casts on that line is
Two pieces: is a number — the signed length of the shadow — and multiplying it by turns that number back into a vector pointing along the line. Whatever is left,
is perpendicular to — always, for any . You can check it in one line: , because . So every vector splits cleanly into the part along a direction and the part that knows nothing about it.
The same formula, written as a matrix, is . Applying keeps the component along and deletes everything else; applying does the reverse — it erases that direction and keeps the rest. That second operation is exactly how directional ablation and concept erasure work in Part 5: you do not delete a neuron, you project the activation onto the subspace orthogonal to a direction and let the model continue.
Matrices are maps, and rank is how much they flatten
A matrix is not a grid of numbers. A matrix is a function that moves the whole space at once, in the most restrained way possible: grid lines stay straight and evenly spaced, and the origin stays put. That restraint is the entire content of the word linear.
Here is the trick that makes matrices readable at a glance: the columns of are where the basis vectors land. Column 1 is , column 2 is . Everything else follows, because every input is a combination of basis vectors and linear maps respect combinations:
A rank-1 matrix is an outer product: , so that . Read that right-to-left and it is a two-stage machine — measure the input against (a dot product, one number), then write that number out along . Read-then-write is the shape of nearly every component you will meet later: attention heads, MLP neurons, SAE features, LoRA updates.
The singular value decomposition says that every matrix, no matter how ugly, is three simple steps:
rotates so that the interesting directions line up with the axes; is diagonal and just stretches axis by axis, by amounts called singular values; rotates the result into its final pose. In pictures: the unit circle always becomes an ellipse, and the singular values are the ellipse's semi-axes. The number of non-zero singular values is the rank, and a small-but-nonzero means “this direction survives, but faintly.”
High-dimensional space is much roomier than it looks
Now the fact that makes modern interpretability necessary. In 2-D you can fit exactly 2 mutually perpendicular directions. In 768-D you can fit exactly 768. That sounds like a hard ceiling on how many separate things a model can represent — and it would be, if features had to be exactly perpendicular.
They do not. Drop the requirement to almost perpendicular and the ceiling explodes. Take two random unit vectors in dimensions; their cosine similarity has mean 0 and standard deviation
At that is 0.71 — random directions are all over the place. At it is 0.036. At (GPT-3 scale) it is 0.009. Two directions drawn at random in a big space are already nearly orthogonal, without anyone arranging it. And the tail is thin: the probability that a random pair exceeds falls off like , exponentially in the dimension.
Run the arithmetic the other way. If you tolerate interference up to , the number of directions you can pack grows exponentially in rather than linearly. This is the geometric content of the Johnson–Lindenstrauss lemma: any points can be squeezed into about dimensions with all distances preserved to within . The cost of an extra feature is not a whole dimension; it is a logarithm.
Play: shadows, maps, and crowded space
Three toys, in the order the lesson built them. The first makes the dot product physical. The second turns four numbers into a transformation you can watch flatten space. The third is the one that matters for the rest of the course: it measures how orthogonal random directions become as you add dimensions.
- v
- (2.40, 1.50), |v| = 2.83
- û
- (0.93, 0.37)
- proj
- (2.58, 1.04)
- resid
- (-0.18, 0.46)
area preserved (det = 1) but directions are stretched unevenly
Full rank: the circle keeps its interior, so nothing is lost — the map is invertible.
Things to try: (1) In the projection playground, drag until the shadow disappears — note that the dot product hits 0 exactly when the arrow is perpendicular, and that can be enormous and still score zero. (2) In the matrix map, press rank 1 and then nudge any single slider by 0.05: watch the ellipse pop open from a segment, i.e. rank 1 is a measure-zero accident that real weight matrices never sit exactly on. (3) In the crowded-space lab, set and look at the histogram, then walk up to 1024 and watch the whole distribution collapse into a spike at zero; check the measured spread against in the footer at every step. (4) Set and press Pack directions at , then — the number of directions you can keep grows far faster than does.
Problem set
Do the pencil problems by hand, on paper, with actual arithmetic — the point is to make these operations physical before they show up buried inside an attention head. Budget 20 minutes for the code problem.
Let and .
- Normalise to a unit vector .
- Compute , the projection , and the residual .
- Verify and that .
- What is the cosine similarity between and ? Does it change if you double ? Does the dot product?
Two token vectors (as columns): , . Weights , .
- Compute the queries and keys , then the 2×2 score matrix .
- Apply a causal mask (position 1 may not look at position 2) and softmax each row. What does token 1 attend to? Token 2?
- Now compute and verify equals the unscaled score you already found. What does that tell you about how many matrices an attention head really has?
Let .
- Show and write as an outer product . Which line is the image? Which line is sent to zero?
- Prove in one sentence that with of shape and of shape has rank at most .
- For and , how many parameters does have compared with a full update?
Let and be independent, uniformly random unit vectors in . Show that and , so the standard deviation of the cosine similarity is . Then state what this predicts for and check it in the explore widget.
In a notebook, for each : sample 2,000 random unit vectors (Gaussian entries, then divide by the norm — do not sample coordinates uniformly, that biases toward corners), compute the full pairwise cosine-similarity matrix, and report the standard deviation, the maximum absolute off-diagonal value, and a histogram.
Then answer with code: for , how many of the 2,000 vectors can you greedily keep such that all pairs satisfy , at versus versus ?
Success check: the measured standard deviation matches to within a few percent at every , and the greedy count at exhausts your 2,000 candidates while saturates in the low tens.
Using the matrix-map widget above:
- Find three different matrices with but . For each, read off the image line and describe what the map destroys.
- Start from the squash preset () and drag the bottom-right entry toward zero until nearly vanishes. Watch the condition number. Why do numerical people care about that ratio?
- Now open the figures of Toy Models of Superposition and look at the plots of . Connect what you see there to what you just did: what would perfect orthogonality look like in those plots, and what does the model do instead?
Check yourself
Go deeper
Watch the 3Blue1Brown series first — it is the visual backbone of everything above, and nothing else in this list replaces it. The rest are references you will return to rather than read straight through.