Stage 1 of 12 · about 2.7 h
How machines learn
Parameters, vectors, loss and gradient descent, one worked number at a time.
Learning, in machine learning, means choosing a function's parameters so its predictions match data. You start by fitting a line to your own note-review times by hand. Then you move the same model into numpy matrix multiplies and rank Pocket's notes by cosine similarity, give models a loss that measures how wrong they are, and finish by deriving the gradient and letting gradient descent find the parameters for you. Every later stage, from neural networks to language models, reuses these four pieces.
- Before you start
- You finished the math toolkit, or can already use numpy arrays, take a derivative by rule and by finite difference, work with log and softmax, and compute a likelihood.
- When you finish
- pocket/stage1/ holds four working scripts, ending with fit_line.py, which fits the review-time line by gradient descent, passes a finite-difference gradient check and matches np.polyfit.
Lesson 1 · 30 min
A model is a function with parametersTell a model's inputs from its parameters, score a guess against data with mean absolute error, and improve a two-parameter line by reading its misses.
Lesson 2 · 40 min
Vectors and matrices in numpyRepresent notes and parameters as numpy arrays, rank notes by cosine similarity, and run a batch of predictions as one matrix multiply while tracking shapes.
Lesson 3 · 45 min
Measuring wrong: loss functionsCompute mean squared error for number predictions and cross-entropy for probability predictions, explain cross-entropy as average negative log-likelihood, and keep both numerically safe.
Lesson 4 · 45 min
Gradient descentDerive the MSE gradient for a line, use it to step each parameter downhill with a workable learning rate, and verify it against finite differences.