A matrix as a function
See a matrix as a linear map, XW as the same map applied to every row of X, and the identity matrix.
Builds on: Matrix multiplication
What the animation says
A matrix is a machine
You can already multiply matrices and predict their shapes. Now a different question: what does multiplying by W actually do? Stop reading W as a table of numbers. Read it as a machine. A row of two numbers goes in. A row of three numbers comes out. Later, a model pushes every word's vector through the same machine at once. So let's open it up.
Rows are ingredients
Inside are the rows of W. Each row is three numbers long. Think of them as ingredients. The input is the recipe. Its first number says how much of row one to use, its second how much of row two. Take the input two, one. Two times row one gives two, zero, six. One times row two gives zero, two, one. Add them: two, two, seven. Now feed in zero, three. What comes out?
That's what linear means
None of row one, three of row two: zero, six, three. Now double an input. Two, one becomes four, two. The output doubles too: four, four, fourteen. Add two inputs. Two, one plus zero, three is two, four. And the outputs add: two, two, seven plus zero, six, three gives two, eight, ten. Scaling and adding pass straight through the machine. That is what linear means.
One map, every row
Now feed the machine a stack. X has three rows, so X times W has three rows. Row one, two, one, goes through and becomes two, two, seven. Row two, zero, three, goes through on its own and becomes zero, six, three. Same W, one row at a time. No row ever looks at its neighbours. Your turn: tap every row of X that output row three depends on, then check.
The machine that changes nothing
Output row three came only from row three of X: one, one became one, two, four. One special machine: the identity. It's square, with ones on the diagonal and zeros elsewhere. Its rows are one, zero and zero, one. So two, one gives two of the first row plus one of the second: two, one again. Nothing changes. Remember: a matrix is a linear function. It adds up its rows, weighted by the input, and applies that to every row on its own.
Rows of W are ingredients, x is the recipe
The matrix as a linear map
One map, applied row by row
Remember this
On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.
Bytewise
All courses