Foundations
Matrix multiplication as transformation
Matrix multiplication composes learned changes of coordinates, while shape and rank reveal what information can pass through.
Updated
1
Concept
Matrix multiplication is easiest to understand as a transformation, not a grid-filling ritual. A matrix takes coordinates in one space and produces coordinates in another. For an input vector , each output component of is a dot product between one row of and . The rows therefore ask different learned weighted questions about the same input.
Consider
Applied to , it produces . A square drawn in the plane becomes a rectangle: the horizontal direction stretches while the vertical direction shrinks. Other matrices rotate, reflect, shear, or project. In higher-dimensional neural networks, the pictures disappear but the operation remains a learned change of representation.
A rectangular matrix can also change dimensionality. An matrix maps input features to output features. If , it may compress information; if , it embeds the input in a larger coordinate space but does not magically create independent information. The matrix’s rank measures how many independent directions survive. A low-rank map forces outputs into a smaller subspace, an idea later exploited by parameter-efficient fine-tuning.
Matrix-matrix multiplication performs many transformations or examples together. Entry of is the dot product of row of with column of . More importantly, represents composition: acts first on a vector, then . Matrix multiplication is generally not commutative. and can differ, and one may be defined when the other is not. Shape records which compositions make sense.
Neural layers commonly use . The matrix supplies a linear transformation; the bias vector translates every result. This is technically an affine transformation because zero can map to rather than zero. Bias lets a decision boundary move away from the origin. Implementations may store examples as rows and write , but this is only a convention. Clear shape annotations prevent transpose confusion.
If we stack two linear layers without anything between them, . The stack is equivalent to one matrix. Biases also combine into one affine map. Depth becomes expressive only when nonlinear functions, gating, normalization, or input-dependent routing interrupt that collapse. This is why activation functions appear between learned projections.
Matrix multiplication dominates neural computation because hardware can execute dense blocks efficiently. A batch of token vectors multiplied by one weight matrix reuses the same parameters across positions. GPUs and specialized accelerators divide large products into tiles, move them through memory hierarchies, and accumulate partial sums. The algebra is simple; performance often depends on data movement, shapes, precision, and how well operations are fused.
Transformers repeatedly apply this pattern. Embedding matrices map token identities to features. Attention projections create queries, keys, and values. Output projections recombine heads. Feed-forward layers expand and contract feature dimensions. The language-model head maps hidden states to vocabulary logits. Thinking in transformations makes the architecture legible: at every matrix, ask which space enters, which space leaves, what directions may be preserved, and what information could be lost.
2
Explain it like I am five
A theater lighting desk maps a few control sliders to many lamps. One matrix says how each slider affects red, green, and blue channels across the stage. A second matrix maps the resulting colors to camera sensors. Multiplying the matrices builds one combined cue from slider to camera. The order cannot be swapped: adjusting lights and then recording them is not the same operation as trying to light a recording.
3
Teach it back
Describe matrix multiplication as composition of transformations, explain why order matters, and state what a bias adds to a neural layer.
Minimum: 80 characters and 15 words. Your text stays only in this browser.
Saved only on this device.
Show a model answer
A matrix maps input coordinates to output coordinates through weighted sums. If A acts first and B second, BA is the combined transformation; AB usually means a different operation or may not be shape-valid. A purely linear map must send zero to zero. Adding a bias translates every output by the same learned vector, producing an affine layer y=Wx+b. Nonlinear activations between such layers prevent the whole stack from collapsing into one matrix.
4
Check your understanding
Complete the teach-back and answer the quiz correctly to finish this lesson.
Sources
- Ian Goodfellow, Yoshua Bengio, and Aaron Courville (2016). Deep Learning.