Matrices & Linear Transformations
P2.math-foundations.04 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: Vectors
Where next?
Later in Mathematics Foundations
P2.math-foundations.04 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: Vectors
Later in Mathematics Foundations
A matrix is nothing more than a rectangular table of numbers arranged in rows and columns. You already know tables — a word-frequency table, a spreadsheet of co-occurrence counts, a bilingual glossary laid out in two columns. What makes a matrix special is not how it looks but what it does: a single matrix multiplication applies one systematic rule to a whole collection of word-vectors at once. Inside a Transformer, every Query, Key, and Value vector is produced by exactly this operation. This module builds the intuition with no maths background assumed.
A matrix is a rectangular table of numbers arranged in rows and columns. An "m by n" matrix simply has m rows and n columns. A single row on its own — an ordered list of numbers — is the vector you already met; a matrix is just a stack of such rows, one per word.
Why it matters — The Transformer's whole store of learned knowledge lives in matrices. The embedding table that turns each token into a vector is a big matrix — one row per word in the vocabulary. Every weight layer that reshapes meaning is a matrix too. Reading a matrix as 'a table of rules' is the single most useful mental model for the rest of this tutorial.
Here is the demo embedding matrix E: four words from our corpus, each described by four numbers. Every row is one word's vector; every column is one shared feature of meaning.
| Word | dim 0 | dim 1 | dim 2 | dim 3 |
|---|---|---|---|---|
| lions | 0.80 | −0.30 | 0.50 | 0.20 |
| animals | 0.70 | −0.20 | 0.60 | 0.10 |
| language | −0.10 | 0.90 | −0.20 | 0.80 |
| word | −0.20 | 0.80 | −0.10 | 0.70 |
Notice how the two animal words sit close together, and the two language words sit close together — the numbers already carry a hint of meaning.
This series recalls Numbers & Computer Representations, Functions & Graphs, Vectors and Matrices & Linear Transformations.
Self-check
A tokenizer turns the word river into 5120, and the model then looks up the list 0.31, −0.44, 0.07. Which kind of number is each?
Self-check
Which word names the set of outputs a function can actually produce?
Self-check
Two word vectors are combined by multiplying slot 1 with slot 1, slot 2 with slot 2, and so on, then adding all the products. What is the result called?
Self-check
A is the matrix with rows (2, 0) and (1, 3). Multiply A by the vector (1, 1). Give the second entry of the result as a whole number.
Self-check
How long is the vector (3, 4)? Give a whole number.
Self-check
ReLU keeps a positive input as it is and turns a negative input into 0. What is ReLU(−2.5) + ReLU(1.5)? Give the answer to 1 decimal place.
Self-check
A matrix has 3 rows and 4 columns. Which vector can it multiply, with the matrix written first?
Self-check
A colleague says a model with 50 million float32 weights fits in about 50 MB. What is wrong?
Self-check
Someone writes that sigmoid can output 1.7 when its input is very large. Where is the mistake?
Self-check
Ana multiplies the identity matrix, rows (1, 0) and (0, 1), by the vector (5, −2) and gets (5, 0). What went wrong?
Practise this lesson's 10 self-checks
One per screen: 10 checked on this page, 0 you reveal and mark yourself. Nothing is recorded.
Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.
Off by default. The mentor always gets your file; this only decides whether your own copy stays here. Copies live in this browser only - they do not follow you to another device, and clearing site data removes them.
A scratch console for this page's ideas — ungraded, nothing you run here is recorded.
Scratch console
A scratch console with the scientific stack (pandas, numpy, scikit-learn). Runs on the server — no network, resource-limited and measured.
Output appears here.
Loading your notes...