Module 3 · The maths the later courses assume · Lesson 10
A small neural network from scratch
The forward pass as two matrix products and a non-linearity, backpropagation as the chain rule applied layer by layer, and a training loop, first in numpy on the ticket features and then as the same model in PyTorch on CPU, scored against logistic regression with a paired test.
Setup for the exercises:Install Claude CodePython with uvThe Hollowbrook ticket dataRun Hugging Face models on CPU
By the end of this lesson you can
- Write the forward pass of a one-hidden-layer MLP as two matrix multiplications and a non-linearity, and count its parameters
- Explain backpropagation as the chain rule applied layer by layer and compute the output-layer gradient by hand for one example
- Implement the MLP and its training loop in numpy, then in PyTorch with nn.Module, autograd and an optimiser, and verify that the gradients agree
- Use a validation set for early stopping and compare the MLP with logistic regression using a paired bootstrap
- Describe what changes between this MLP and a transformer block, as a bridge to the LLM courses
