
ml basics
how machines learn, from zero: parameters, loss, gradient descent, neurons and backprop, all the way to your first tiny language model. 12 short video lessons.
- 12 short video lessons
- study kit: one page per lesson (pdf, with ad-free)
- 48 practice questions with answer key: try them right here, free
- free to watch, with ads
- 01models and parameters
- 02loss and the slope
- 03gradient descent
- 04vectors + matrices
- 05the neuron
- 06backprop
- 07overfitting and mini-batches
- 08scores to probabilities (softmax)
- 09keeping training stable
- 10the bigram model
- 11sampling + grading
- 12a longer memory (mlps and context)
try it yourself
pick a lesson, then pick an answer. wrong answers are how the knobs learn: a missed one comes back at the end.
lesson 01 · models and parameters
question 1 of 4

with w = $0.25 and b = $1.00, what does the coffee model guess for a 16 oz coffee?
answer key · all 48
01 · models and parameters
with w = $0.25 and b = $1.00, what does the coffee model guess for a 16 oz coffee?
$5.00. 16 × 0.25 + 1 = 4 + 1 = $5.00.
which change makes every coffee a bit more expensive, no matter its size?
turn b up. b is added to every guess, so raising it raises every price by the same amount.
what does "a 70b model" mean?
it has about 70 billion parameters (knobs). the b counts knobs: a model with about 70 billion parameters.
who sets the knobs, and how?
training: the model compares its guesses with real examples and nudges every knob a little, over and over. training compares guesses with real examples and nudges every knob a tiny bit, millions of times.
02 · loss and the slope
the model guesses $4 for a coffee that really costs $7. what is the squared-error loss?
9. error = 3, so loss = 3² = 9.
the slope for w is positive (nudging w up raises the loss). which way should w move?
down. the slope points uphill, so step the other way: decrease w.
why square the error instead of just using it as is?
every error becomes positive, and big misses cost much more than small ones. squaring makes every error positive (too high and too low both count) and makes big misses cost much more than small ones.
what is the gradient?
the slopes for all the knobs together, pointing where the loss goes up fastest. the gradient is the list of slopes, one per knob. it points uphill, so we step the other way.
03 · gradient descent
w = 0.5, its slope is 2, and the learning rate is 0.1. what is w after one step?
0.3. 0.5 − 0.1 × 2 = 0.3.
the loss bounces from side to side and sometimes jumps up. what is the most likely problem?
learning rate too big. a step that is too big leaps over the bottom of the valley.
which is the right order for the training loop?
predict → measure → slope → nudge. predict → measure (loss) → slope (gradient) → nudge (update), then repeat.
you have 1,000 examples and train for 5 epochs. how many times does the model see each example?
5 times. once per epoch, so 5 times (5,000 example-looks in total).
04 · vectors + matrices
[2, 0, 3] · [1, 5, 2] = ?
8. 2×1 + 0×5 + 3×2 = 2 + 0 + 6 = 8.
two word vectors have a dot product close to 0. what does that suggest?
the words are unrelated. near 0 means the vectors point at right angles: not aligned.
a matrix has rows [1, 0] and [0, 2]. multiply it by the vector [3, 4].
[3, 8]. row 1: 1×3 + 0×4 = 3. row 2: 0×3 + 2×4 = 8. result [3, 8].
why do gpus matter so much for neural networks?
most of the work is matrix multiplies, and gpus do thousands of them in parallel. most of the work is matrix multiplies, and gpus do thousands of those multiplications in parallel.
05 · the neuron
a neuron has weights [1, −2], bias 1, and input [3, 2]. what is its output after relu?
0. 1×3 + (−2)×2 + 1 = 0. relu(0) = 0.
same neuron (weights [1, −2], bias 1), input [4, 1]. output after relu?
3. 4 − 2 + 1 = 3. relu(3) = 3.
what happens if you stack ten layers with no squish between them?
it behaves like one straight-line layer. straight lines stacked stay straight: the whole stack equals one linear step.
where does an mlp show up inside a transformer?
inside every block, right after attention. inside every block, right after attention. a big share of the model’s knobs live there.
06 · backprop
why not find each slope by nudging one knob at a time?
it is far too slow with billions of knobs. one nudge per knob means billions of extra passes. backprop gets all slopes in one backward pass.
guess = size × w. for a 12 oz coffee, how much does the guess change if w goes up by 0.01?
$0.12. 12 × 0.01 = 0.12, so $0.12. the guess moves 12× as much as w.
what does each step in the chain need to know for backprop to work?
only its own local slope: how its output changes when its input changes. each step only needs its own local slope. the chain rule multiplies them together.
what do the two passes produce?
forward → the guess and the loss. backward → the slope for every knob. forward pass → the guess and the loss. backward pass → the slope for every knob.
07 · overfitting and mini-batches
training loss keeps falling, but validation loss starts rising. what is happening?
the model is overfitting. doing better on seen data and worse on unseen data is memorizing.
which pair are both fixes for overfitting?
more data, and stopping early. more data, a smaller model, or stopping early all help it stop memorizing.
you have 10,000 examples and use a 90/10 split. how many are in the validation set?
1,000. 10% of 10,000 = 1,000.
10,000 training examples, mini-batches of 32. about how many steps make one epoch?
about 313. 10,000 ÷ 32 ≈ 313 steps.
08 · scores to probabilities (softmax)
two choices with scores 0 and 0. what probabilities does softmax give?
50% and 50%. e⁰ = 1 for both, total 2: 50% and 50%.
scores [2, 1, 0.1] become [12, 11, 10.1]. what happens to the probabilities?
they stay exactly the same. adding the same amount to every score doesn’t change the gaps, so nothing changes.
why raise e to each score instead of just dividing scores by their total?
scores can be negative and e^score is always positive; it also stretches the gaps. scores can be negative, and e^score is always positive. it also stretches the gaps so the top score pulls ahead.
the model gives the right answer 5% probability. is the loss high or low?
high. low probability on the right answer means a big loss.
09 · keeping training stable
a neuron adds up 400 inputs. roughly what size should its starting weights be?
0.05. 1/√400 = 1/20 = 0.05.
the early layers of a deep network barely change during training. which problem is this?
vanishing. vanishing slopes mean the early layers get almost no learning signal.
what does normalization do to a layer’s numbers?
shifts them to average 0 and scales them to a spread of about 1. it shifts them to average 0 and scales them to a spread of about 1 (then applies a learned shift and scale).
a batch of 32 images, each 28 × 28 pixels. how many dimensions does that tensor have?
3. 3 dimensions: 32 × 28 × 28.
10 · the bigram model
which list has every bigram in the name "ava", using "." for start and end?
.a av va a.. .a av va a. (start, each pair of letters, end).
in the counts, "q" is followed by "u" 98 times and by something else 2 times. what is p(u | q)?
0.98. 98 ÷ 100 = 0.98, so 98%.
why does the bigram model make odd names?
it only sees one letter back. with only one letter of context, it can’t keep a whole name consistent.
how many cells are in the bigram table for 26 letters plus the dot?
729. 27 × 27 = 729.
11 · sampling + grading
you want a chatbot to answer a math question the same way every time. which setting fits?
low temperature (or greedy). low temperature sharpens the odds toward the top choice.
random guessing among 27 characters scores about 3.30. what is ln(27)?
about 3.30. random guessing gives every character 1/27, and the surprise is −ln(1/27) = ln(27) ≈ 3.30.
model a scores 2.45 on unseen names, model b scores 2.2. which is better?
model b: lower average surprise. model b: a lower average surprise means it gave more probability to what really came next.
why grade on text the model has never seen?
to measure real learning, not memorizing. so you measure real learning, not memorizing (the same idea as the validation set).
12 · a longer memory (mlps and context)
with 27 characters, how many possible 3-letter contexts are there?
19,683. 27³ = 19,683 (about 20,000).
what does an embedding give each letter?
a learned vector of numbers. each letter gets its own small vector, learned during training.
what is one weakness of the fixed-window mlp?
it can’t see past its window. it can’t see past its window (and a bigger window needs far more knobs, with each slot learned separately).
in "the dog, that the neighbors always talked about, was sleeping", why does a 3-word window fail?
"was" depends on "the dog", which is outside the window. "was" depends on "the dog", which is many words back, outside the window.
loading…