Part I Β· Ch. 3 β€” Grids That Transform

Part I Β· Chapter 3 of 20

Grids That Transform

Matrices: machines that turn one vector into another


Where the weights live

Every article about large language models eventually says the same mysterious thing: the model has billions of learned weights. Billions of what, exactly, and living where? Here is the answer, up front and unglamorous: they are plain numbers, arranged in rectangular grids β€” and each grid is a little machine. This chapter opens one such machine, small enough to hold in your hand.

The object has a name. A matrix is a rectangular grid of numbers we treat as a single thing β€” and, at the same time, a machine that turns one vector into another. That is the same double life we met in Chapter 1, where a vector was an arrow and a list at once. A matrix is that idea one level up: a table and an action.

Set your expectations low, on purpose. Everything here happens with a single 2Γ—2 grid and the vectors you already own. No new arithmetic is arriving β€” a matrix runs entirely on the dot product you built last chapter. Let's meet it.

A table with a job

Picture the star of the chapter before we say a word of notation. It is a 2Γ—2 grid of four numbers, and we will keep it fixed all the way through β€” the same grid in the prose, the figures, the video, and the playground below.

A two-by-two grid of rounded cells flanked by thin brackets, entries in violet reading 1 and 2 on the top row, 3 and 0 on the bottom row, labeled bold W above. A horizontal band highlights row 1 (cells 1 and 2); a vertical band highlights column 2 (cells 2 and 0). Two callouts: W-one-two equals 2, row 1 column 2, points at the top-right cell; W-two-one equals 3, row 2 column 1, points at the bottom-left cell. Small text below reads 2 by 2, rows by columns.
The star of the chapter: W, a 2Γ—2 grid of weights. Subscripts address entries row-first β€” $W_{12}$ is row 1, column 2, so $W_{12} = 2$ and $W_{21} = 3$. Mixing those two up is the classic first stumble; this figure is here to stumble-proof you.

Now the notation, which we keep for the rest of the site. A matrix is written as a bold uppercase letter β€” $\mathbf{W}$, read aloud as "the matrix W." Our grid is:

$$\mathbf{W} = \begin{bmatrix} 1 & 2 \\ 3 & 0 \end{bmatrix}$$

In words: W is the four numbers 1, 2, 3, 0, laid out in two rows and two columns β€” top row 1 then 2, bottom row 3 then 0.

We pick out a single number with two subscripts: $W_{ij}$ means the entry in row $i$, column $j$ β€” read "the entry in row i, column j." Row first, column second, always. The two entries people most often swap are the off-diagonal ones, so confront them side by side: $W_{12} = 2$ sits in row 1, column 2 (top-right), while $W_{21} = 3$ sits in row 2, column 1 (bottom-left). Same digits in the subscript, opposite corners of the grid β€” read them slowly the first few times and the habit sticks.

One more piece of vocabulary, in a single sentence: this is a 2Γ—2 matrix β€” rows times columns, rows named first. Real models use grids shaped like 4096Γ—4096, but that changes nothing about how the machine works; it only changes how much patience you would need to run it by hand.

The machine runs: matrix Γ— vector

Time to feed the machine. Our input is the vector $\mathbf{v} = [2, 1]$ β€” the mint arrow, because input vectors are always mint on this site. The rule, in plain words before any symbols: each row of W takes the dot product with the whole input. Row 1's dot product becomes output slot 1; row 2's dot product becomes output slot 2. One dot product per output number β€” that is the entire operation.

A schematic in three groups. Left: the two-by-two grid W with violet entries 1, 2 over 3, 0; row 1 has a mint outline, row 2 a blue outline. Middle: a two-by-one column, mint entries 2 over 1, labeled bold v. Right: a two-by-one column, amber entries 4 over 6, labeled bold W v. Thin arrows curve from row 1 to the amber 4 and from row 2 to the amber 6. Below, two lines of arithmetic: row 1 colon 1 times 2 plus 2 times 1 equals 4; row 2 colon 3 times 2 plus 0 times 1 equals 6.
Matrix Γ— vector is dot products in bulk. Each row of W dots the whole input once; row 1's answer fills output slot 1, row 2's fills slot 2. Two rows, two dot products, one new vector: [4, 6].

Now do it by hand, every digit β€” this small calculation is the spine of the whole chapter.

Worked example

Row 1 of W is [1, 2]. Dot it with the input [2, 1]: multiply matching parts and add, $1 \times 2 + 2 \times 1 = 2 + 2 = 4$. That is output slot 1.

Row 2 of W is [3, 0]. Dot it with the same input [2, 1]: $3 \times 2 + 0 \times 1 = 6 + 0 = 6$. That is output slot 2.

Stack the two answers and you have the output vector, $[4, 6]$ β€” amber in the figure above, because outputs are always amber.

Written as one display equation, the whole machine in a line:

$$\mathbf{W}\mathbf{v} = \begin{bmatrix} 1 & 2 \\ 3 & 0 \end{bmatrix} \begin{bmatrix} 2 \\ 1 \end{bmatrix} = \begin{bmatrix} 1 \times 2 + 2 \times 1 \\ 3 \times 2 + 0 \times 1 \end{bmatrix} = \begin{bmatrix} 4 \\ 6 \end{bmatrix}$$

In words: the top row of W dots the input to make the top output number, 4; the bottom row dots the same input to make the bottom output number, 6. The result is the new vector [4, 6].

That last move β€” "multiply matching parts, add" β€” is exactly what you did all through Chapter 2. A matrix is nothing more than dot products in bulk: two rows here, two dot products, two output slots. A 4096Γ—4096 weight grid is 4096 dot products β€” honestly all the core multiplication in a neural-network layer is.

We write this operation $\mathbf{W}\mathbf{v}$ β€” matrix on the left, vector on the right, no dot symbol between them β€” and read it "W times v" or "W applied to v." Notice what came out: the result is a new vector, not a single number. Each row contributed one number, and those answers stack into a column.

Rows are recipes

Here is the same arithmetic read a second way β€” as weighted mixing. Look at output slot 1 again: $1 \times 2 + 2 \times 1$. Read it as a recipe: "take 1 part of the input's first number and 2 parts of its second, and stir." Row 2's recipe is "$3$ parts of the first number, $0$ parts of the second" β€” row 2 completely ignores the input's second slot, because its weight there is 0. Change that 0 to something else and suddenly row 2 starts paying attention.

Say it in general, still in words, no new equation needed: every output number is a weighted blend of all the input numbers, and the matrix entries are literally the blend proportions. "Weights" is not a loose metaphor here β€” the entries really do weight the mixture. That is why the whole field calls them weights.

One sentence of foreshadowing: when a model "learns," what changes is exactly these proportions β€” the recipe numbers are the knowledge, and nothing else in the machine is adjustable. How they get adjusted is Part III's whole story.

The whole plane moves

Now zoom all the way out, to the third and most beautiful view. Instead of feeding W one vector, feed it every point of the plane at once. The square reference grid warps into a new grid of leaning parallelograms: straight lines stay straight, the origin stays exactly where it was, but the whole plane stretches and tilts. A matrix is a transformation of space.

Two square panels. Left, labeled 'before': a faint square grid with an amber arrow from the origin to (1,0) labeled [1,0] and a blue arrow to (0,1) labeled [0,1]. Right, labeled 'after W': the same grid sheared into slanted parallelograms, with an amber arrow from the origin to (1,3) labeled [1,3] equals column 1 and a blue arrow to (2,0) labeled [2,0] equals column 2.
Feed W the whole plane. Straight lines stay straight and the origin stays home, but every square leans into the same parallelogram. And the machine signs its work: [1, 0] lands on W's first column, [0, 1] on its second β€” a matrix's columns announce where the basic arrows go.

That last sentence hides the chapter's neatest secret. Where do the two most basic arrows land? Take $[1, 0]$ and run it through W: its dot products are $1 \times 1 + 2 \times 0 = 1$ and $3 \times 1 + 0 \times 0 = 3$, so it lands on $[1, 3]$ β€” exactly the first column of W. And $[0, 1]$ lands on $[2, 0]$, the second column. A matrix's columns are exactly a list of where the plane's basic arrows end up β€” so you can read its whole geometric behavior straight off its columns, without computing anything.

To feel how much the four numbers matter, meet two celebrity matrices.

Worked example: the do-nothing machine

The matrix $[[1, 0], [0, 1]]$ dots its rows with $\mathbf{v} = [2, 1]$: row 1 gives $1 \times 2 + 0 \times 1 = 2$, row 2 gives $0 \times 2 + 1 \times 1 = 1$. Output $[2, 1]$ β€” the input, unchanged. Its columns say "$[1, 0]$ stays put, $[0, 1]$ stays put," so it leaves the whole plane exactly as it found it. This is the identity matrix.

Worked example: the quarter-turn machine

The matrix $[[0, -1], [1, 0]]$ on the same $\mathbf{v} = [2, 1]$ gives $0 \times 2 + (-1) \times 1 = -1$ for the first slot and $1 \times 2 + 0 \times 1 = 2$ for the second β€” output $[-1, 2]$. That is $[2, 1]$ rotated a quarter-turn counterclockwise: same length, brand-new direction. (Note the parentheses around $(-1)$ β€” the first negative entry we have met, and a spot where a sloppy minus sign trips people; keep it clearly wrapped.)

A full-plane grid. A mint arrow points from the origin to (2,1), labeled v equals [2,1], drawn faint. A second mint arrow at full strength points to (-1,2), labeled [-1,2]. A dashed muted arc sweeps counterclockwise from the first arrow's tip to the second, showing a quarter turn, with a small right-angle marker at the origin. In the lower left, the matrix [[0,-1],[1,0]] is typeset small in violet.
Four humble numbers, one clean quarter-turn. The machine $[[0, -1], [1, 0]]$ rotates every vector 90Β° counterclockwise β€” our [2, 1] lands on [βˆ’1, 2], same length, new direction. Different entries, completely different personality.

Written out, the rotation looks like this:

$$\begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix} \begin{bmatrix} 2 \\ 1 \end{bmatrix} = \begin{bmatrix} 0 \times 2 + (-1) \times 1 \\ 1 \times 2 + 0 \times 1 \end{bmatrix} = \begin{bmatrix} -1 \\ 2 \end{bmatrix}$$

In words: the top row dots the input to give $0 \times 2 + (-1) \times 1 = -1$, and the bottom row gives $1 \times 2 + 0 \times 1 = 2$, so the arrow [2, 1] is carried to [βˆ’1, 2] β€” the same arrow, turned a quarter-circle.

So we now have three ways to see the very same four numbers. Dot-products-by-rows tells you how to compute the output. Recipes tells you what the numbers mean. Space-transformer tells you what the machine does to everything at once. Same grid, three faces.

See it move

The three views are easier to feel in motion than to read. The short video runs the machine both ways: watch each row of the violet grid lean in to dot the input, then watch the same matrix pick up the entire plane and carry it.

Watch (1:29): what to notice β€” each row of W "leans in" to dot the input, and when the whole plane transforms, the basis arrows land right on W's columns, digit for digit.

Now take the controls. The playground lets you edit W's four numbers, drag the mint input around, and watch the arithmetic, the amber output, and the whole warped plane update together.

Why the LLM cares

This is the chapter where the site's title starts to cash out. An LLM is, to a first honest approximation, a very long pipeline of matrix-times-vector operations. A token enters as a vector (we build that in Chapters 7–8) and is passed through weight matrix after weight matrix, layer after layer. Everything you just did to $[2, 1]$ by hand is what happens to a word's vector billions of times as the model reads.

That makes "billions of parameters" suddenly literal. A parameter is one matrix entry. When a spec sheet says a model has 7 billion parameters, it means: count the entries of all its weight grids, one by one, and you reach 7 billion. We bundle all of them under a single symbol, $\theta$ β€” theta, read "the parameters" β€” a letter you will see from Chapter 12 onward. We will not do any arithmetic with $\theta$ here; just meet the name.

The site's color language now pays off too: weights are violet in every figure and video from here on. When you see violet, you are looking at the learned, adjustable part of the machine β€” the numbers training gets to change.

And each of our three views previews a later chapter, one sentence each. The rows view is how attention will score words against each other. The mixing view is how a transformer layer blends information across features. The space view is how embeddings get rotated and reshaped as they rise through the layers. Every later chapter in this site is, at heart, this chapter with more rows.

What you now know

  • A matrix is a grid of numbers, written $\mathbf{W}$, with entries addressed row-first: $W_{12}$ means row 1, column 2 (so for our matrix $W_{12} = 2$ and $W_{21} = 3$).
  • Matrix Γ— vector runs on last chapter's arithmetic: each row dots the input once, and the row answers stack into the output β€” for our W and $\mathbf{v} = [2, 1]$, the rows give $1 \times 2 + 2 \times 1 = 4$ and $3 \times 2 + 0 \times 1 = 6$, so $\mathbf{W}\mathbf{v} = [4, 6]$.
  • Read each row as a recipe: every output number is a weighted blend of all the input numbers, and the entries are literally the blend proportions β€” which is why they are called weights.
  • Zoomed out, a matrix transforms the whole plane β€” lines stay lines, the origin stays put β€” and its columns tell you exactly where the basic arrows $[1, 0]$ and $[0, 1]$ land.
  • Different entries, different machine: $[[1, 0], [0, 1]]$ changes nothing, $[[0, -1], [1, 0]]$ rotates everything a quarter turn, and our $[[1, 2], [3, 0]]$ shears and stretches.
  • An LLM's "billions of parameters" are entries of weight matrices like W β€” learning means adjusting those entries, nothing more mysterious than that.

Where we're headed. Our machines so far are strong but stiff: matrices stretch, lean, and spin the plane, yet they can only do "flat" things β€” and chaining two matrices just collapses into one bigger matrix, so stacking alone buys nothing new. Real intelligence needs bends. Next chapter we meet the bendy parts: functions and their curves β€” $f(x)$ as a machine in its own right, the exponential $e^x$ and its partner $\ln x$, and the S-shaped squashing curves that get tucked between matrices to let networks bend space instead of merely leaning it.