Linear algebra for LLMsPart 7: Decompositions and low rank
Eigenvectors
7 min
Directions that only stretch
Most vectors change direction when a matrix acts on them. An eigenvector doesn’t: it comes out as a multiple of itself. The factor is its eigenvalue: how much that direction is stretched (or flipped, if negative).
Write
Find them for a 2×2
is stretched by 3; by 1 (unchanged). In general, the eigenvalues solve : here , so or .
Write
See it on the plane
The grid is stretched 3× along the diagonal and left alone along . Those two lines are the only directions that don’t turn.
Symmetric matrices are the nice case
The spectral theorem: a real symmetric matrix has real eigenvalues and orthogonal eigenvectors. Put the unit eigenvectors in the columns of and the eigenvalues on the diagonal of : rotate into the eigenvector axes, stretch each axis, rotate back. Covariance matrices and are symmetric, so this always applies to them.
Write
Multiply again and again
Start anywhere and keep applying . The part along grows like , the rest like , so the direction (right column, normalized) swings toward . This is power iteration: the largest eigenvalue’s direction wins.
Write
Why deep products explode or vanish
In a transformer
Pushing a signal (or a gradient) through many layers multiplies it by many matrices. If the important eigenvalues are above 1, it grows exponentially; below 1, it shrinks to nothing. Residual connections, normalization and careful initialization all exist to keep these products near 1.
✏️ Your turn
Find the eigenvalues
What are the eigenvalues and eigenvectors of ? (Look before you compute.)
Work it out on paper, then go to the next card to check.
Answer
A diagonal matrix’s eigenvectors are the axes and its eigenvalues are the diagonal. The negative one flips as well as doubling it.
Where eigendecomposition stops
Only square matrices have eigenvalues, and a non-symmetric one may have complex eigenvalues (a rotation turns every direction) or too few eigenvectors (a shear has only one direction). Weight matrices are usually not square at all. The SVD, next, works for every matrix.
torch.linalg.eigh(S) # symmetric: real eigenvalues, orthonormal eigenvectors
torch.linalg.eig(A) # general square: may be complex📌 Recap
Eigenvectors in one card
- : a direction that only stretches; .
- Symmetric: with orthogonal eigenvectors.
- Repeated multiplication: the largest dominates; products grow or shrink like .
- Non-square or non-symmetric matrices need the SVD.
Write