A matrix is a rectangular grid of numbers. A 2ร3 matrix has 2 rows and 3 columns:
A = โ โ
โ 2 1 0 โ
โ 0 3 1 โ
โ โ
But a matrix isn't just a table of numbers. A matrix is a function โ it takes vectors as input and produces vectors as output. Specifically, multiplying a matrix by a vector applies a linear transformation to that vector.
To multiply a matrix A (mรn) by a vector x (nร1), each row of A takes a dot product with x:
โ โ โ โ โ โ
โ a b c โ โ x โ โ ax + by + cz โ
โ d e f โ โ y โ = โ dx + ey + fz โ
โ โ โ z โ โ gx + hy + iz โ
โ
โ โ โ
Each output component is a weighted combination of all input components. The matrix tells you how to mix the inputs to get the outputs.
In 2D, we can visualize what matrices do to the entire plane. Here are the fundamental transformations:
| Matrix | Transformation | What It Does |
|---|---|---|
โ2 0โ
|
Uniform scaling | Stretches everything by ร2 |
โ2 0โ
|
Axis scaling | Stretches x-axis only โ squares become rectangles |
โ0 โ1โ
|
90ยฐ rotation | Rotates every vector counterclockwise by 90ยฐ |
โโ1 0โ
|
Reflection | Flips everything through the origin |
โ1 1โ
|
Shear | Tilts the plane โ vertical lines slant |
โ1 0โ
|
Projection | Collapses everything onto the x-axis |
In the attention mechanism, every token vector x goes through three matrix transformations:
q = WQ ยท x k = WK ยท x v = WV ยท x
Each W is a learned matrix โ its numbers are discovered during training. WQ transforms x into a "query" (what am I looking for?), WK into a "key" (what do I contain?), and WV into a "value" (what information do I carry?).
Same vector, three different transformations, three different purposes. The matrices are the model's knowledge โ they encode what the model has learned about how to represent and relate information.
What happens when you apply one transformation, then another? You get a composition of transformations โ and that composition is itself a matrix. Matrix ร matrix = composition.
If B rotates and A scales, then AยทB first rotates then scales โ in one matrix. This is why matrix multiplication matters so much: it's how we combine transformations. That's the next lesson.
Q1: In the attention mechanism, the matrix WQ transforms a token vector x into a query vector q. What is WQ, fundamentally?
A. A lookup table that maps tokens to queries B. A learned linear transformation โ a grid of numbers discovered during training C. A fixed mathematical constant like ฯ D. A random number generatorQ2: A 2ร2 matrix with zeros everywhere except a 3 in the top-left position transforms the vector [1, 1]. What is the result?
A. [1, 1] B. [3, 0] C. [3, 3] D. [0, 0]Q3: If a model has "7 billion parameters," what are those parameters?
A. Hyperparameters like learning rate and batch size B. The entries of the model's matrices โ the numbers that define its transformations C. The number of tokens in the training data D. The number of different tasks the model can perform