Matrix multiplication
Multiply matrix by vector and matrix by matrix, predict shapes like (T×d)(d×k) → T×k.
Builds on: Dot product and cosine similarity, Matrices and shapes
What the animation says
Sentences as tables
Inside a language model, every word piece of a sentence is held as a row of numbers. Stack a sentence of six pieces and you get a table: six rows, each four numbers wide. Over and over, the model must turn every row into a new row, often of a different length. It uses one shared table of numbers for all the rows. That step is matrix multiplication.
One row, every column
Start small. Take one row: one, two. The shared table W has two rows, matching that length, and three columns. Dot the row with column one: one times three, plus two times one. Five. Column two: one times zero, plus two times two. Four. Column three holds one and minus one. What comes out?
Every row, on its own
Minus one. So the row one, two becomes five, four, minus one. Two numbers in, three out: one number per column of the table. A second row, zero, one, walks across the same three columns. It gives one, two, minus one, and never looks at the first row. Each output row comes only from its own input row. Your turn: which row and which column made the circled number?
The shape rule
That's the whole rule: every entry is one left row dotted with one right column. Row i, column j of the result: row i of the left, dotted with column j of the right. Now the shapes. Two by two, times two by three, gave two by three. The inner sizes must match, because a row's length must equal a column's length. Then they vanish. The outer sizes stay: rows from the left, columns from the right. So: six by four, times four by eight. What shape comes out?
Order matters
Six by eight. The inner fours cancel; six rows and eight columns stay. Now flip the order: four by eight, times six by four. The inner sizes are eight and six. They don't match, so that product isn't even defined. Even when both orders work, the results usually differ. Order matters. Every left row, dotted with every right column. This one operation is most of the arithmetic a language model does.
Many dot products at once
The rule and the shape check
Worked example: (2×2)(2×3)
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