Linear algebra for LLMsPart 3: Matrices as transformations
Projections
7 min
Projecting onto an axis
Drop straight down onto the horizontal axis and you land at . You kept the part of along and threw away the rest.
Projecting onto any unit vector
With : is the shadow length (Part 1), and multiplying by points it the right way. Here , so the projection is .
Write
Removing a direction
Subtract the projection and what’s left has nothing along : it’s orthogonal to . Every vector splits into a part along plus a part at 90° to it.
Write
The projection matrix
, so projecting is multiplying by : an outer product, rank 1. Projecting twice changes nothing more: . Removing the direction is .
Write
✏️ Your turn
Project and remove
Write and , then check the second is orthogonal to .
Work it out on paper, then go to the next card to check.
Answer
Onto a whole subspace
Stack orthonormal directions as the columns of (). Then keeps exactly the part of inside their span. With it’s the you just used.
Projections inside and around LLMs
In a transformer
- Ablation: deletes whatever a model stores along direction in the residual stream, to test whether it matters.
- Steering: pushes the model along a concept direction instead.
- Linear probes read a concept as : a projection onto .
- LayerNorm’s centering subtracts the mean, which is projecting out the all-ones direction : .
📌 Recap
Projections in one card
- for unit .
- is orthogonal to : the direction removed.
- (or ) has .
- Ablation, steering, probes and mean-centering are all projections.
Write