Linear algebra for LLMsPart 3: Matrices as transformations
Inverse, determinant, null space
6 min
The determinant is an area factor
The unit square maps to a parallelogram whose area is . The shear-and-stretch from the first deck of this part doubles every area. A negative determinant means the map also flips the plane over (the reflection had ).
Write
Determinant zero: the plane collapses
. Both columns lie on one line, so the whole plane lands on that line: area 0. Rank 1, not 2.
Write
Null space: what gets destroyed
The null space is every with . Here it’s the line through . Anything along that direction is wiped out, so two inputs that differ by it give the same output. Rank + nullity = number of columns: .
Write
The inverse undoes the map
Swap the diagonal, negate the off-diagonal, divide by the determinant. That division is why means no inverse: a collapsed plane can’t be un-collapsed.
Write
Check an inverse
, so . Multiplying back gives the identity.
✏️ Your turn
Invert this
Write and , then check that .
Work it out on paper, then go to the next card to check.
Answer
Check row 1 of against the columns: and .
Orthogonal matrices invert for free
Rotations and reflections keep lengths, so undoing them is just a transpose: no division, no rounding trouble. Their determinant is .
In practice
In a transformer
You rarely invert a matrix in ML work. Most weights aren’t square (a up-projection has no inverse), and when you do need to solve , torch.linalg.solve is faster and more accurate than forming . What carries over is the idea: a map with a null space throws information away for good.
torch.linalg.det(A)
torch.linalg.solve(A, b) # x with A x = b, without forming A⁻¹
torch.linalg.pinv(W) # pseudo-inverse, for non-square W📌 Recap
Inverse, determinant, null space in one card
- : the area factor.
- ⇔ rank < n ⇔ a null space ⇔ no inverse.
- for 2×2.
- Orthogonal: .
Write