Linear algebra
Neural networks are made of two things: numbers arranged in rectangles, and a few simple operations on those rectangles. This chapter is the entire toolkit. Read it slowly. Every symbol you see here is one you will see for the rest of the guide.
Vectors are just lists of numbers
A vector is an ordered list of numbers. Think of it as a column of values stacked vertically. We write it with bold lowercase letters like so it's easy to spot:
Adding and scaling vectors
Two operations are the bedrock of everything else: add two vectors, or multiply a vector by a regular (non-bold) number.
Drag the sliders below. The dashed green vector is . Watch it change as you move and .
The dot product โ measuring similarity
The dot product takes two vectors and produces a single number. Multiply matched components, then sum:
There's a beautiful geometric fact about dot products you'll use forever:
Matrices are stacks of vectors
A matrix is a rectangle of numbers. Capital letters like for matrices, two indices for each entry โ first the row, then the column:
You can read a matrix two ways, both useful:
- As stacked rows. Each row is a vector. In a neural network, each row is one neuron's weight vector.
- As stacked columns. Each column is a vector. In that view, each column is one input feature's contribution to every neuron.
Matrix multiplication = many dot products at once
To multiply two matrices , the inner dimensions must match: if is and is , then is . Each entry of is one dot product:
Step through the same kind of multiplication interactively:
| 1 | 2 | 3 |
| 4 | 5 | 6 |
| 7 | 8 |
| 9 | 10 |
| 11 | 12 |
| ยท | ยท |
| ยท | ยท |
Transpose, and one full forward pass
The transpose of a matrix flips it diagonally โ rows become columns and vice versa. We write the transpose with a little T in the upper-right:
Now the payoff. The forward pass of a single neural-network layer is just: