0.1 — Vector spaces and inner products, the ML view
Goal: Re-derive ⟨x,y⟩ = xᵀy and convince yourself a linear layer is an affine map.
1. Where the data lives
In ML, the underlying object of any data point is a vector in a finite-dimensional real vector space . A 28×28 grayscale image becomes a vector with components; a sequence of tokens in a language model, once embedded, becomes a matrix in , but each row is a vector in .
The choice of is not innocent — it commits us to three things at once: additive structure (), scalar multiplication (), and the existence of a canonical inner product, which we'll now derive.
2. Inner product via basis expansions
Fix a basis of . Every vector has a unique expansion
Suppose is equipped with a symmetric positive-definite bilinear form . By bilinearity, for ,
When the basis is orthonormal, , and the double sum collapses:
This is the form that shows up in every ML derivation: inner product is row-times-column multiplication.
3. Induced norm and angle
The norm induced by the inner product is
And the angle between and is defined implicitly by
The cosine similarity used in semantic search and embedding normalisation is this ratio. When vectors are pre-normalised to unit norm, — that's it.
4. A linear layer is an affine map
A fully connected layer with weights and bias implements the map
This is the classical definition of an affine transformation: linear () plus translation (). The bias trick — appending a to the end of and stacking as the last column of — turns an affine map into a purely linear one in the augmented space . This simplifies proofs, but in code we keep separate for efficiency (it broadcasts).
5. Where this is going
All the algebra to come — attention, softmax, layer normalisation — rests on these three facts: there is a basis, there is an inner product, and layers are affine. Internalise them; there's no shortcut.