Gradient descent and backpropagation
In the topic Fitting distributions with KL we fitted a Gaussian, and maximum likelihood had a closed form: match the mean and the covariance. The models in the rest of the course are neural networks, and no such formula exists for them. They are trained by gradient descent. This topic collects just enough deep-learning background for that: how the gradient is computed, why it can vanish or explode, the normalization layers that keep it in check, and the convolutions that image models are built from.
Gradient descent takes a loss , for us usually the negative log-likelihood averaged over a batch of training examples, and repeats one step:
where is the learning rate. All the work is in the gradient.
A network is a chain of layers. Take the simplest one, with one unit per layer and input . Layer computes a pre-activation and applies an activation function , such as ReLU:
The loss depends on only through , then , and so on up to the output. By the chain rule, each layer contributes one local factor:
Backpropagation organizes this computation. The forward pass computes all and and keeps them. The backward pass starts from at the output and moves towards the input, multiplying by one local factor per layer and reading off each weight's gradient along the way. Every derivative is computed once, so the backward pass costs about as much as the forward one. With many units per layer the local factors become Jacobian matrices, but the structure is the same. In PyTorch, loss.backward() does exactly this.