Skip to content
BIASED

Batch normalization, gradients and convolutions

Block 1 of 8~3 min

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 L(θ)\mathcal L(\theta), for us usually the negative log-likelihood averaged over a batch of training examples, and repeats one step:

θ←θ−η ∇θL(θ),\theta \leftarrow \theta - \eta\, \nabla_\theta \mathcal L(\theta),

where η>0\eta > 0 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 h0=xh_0 = x. Layer ii computes a pre-activation and applies an activation function ρ\rho, such as ReLU:

ai=wi hi−1+bi,hi=ρ(ai).a_i = w_i\, h_{i-1} + b_i, \qquad h_i = \rho(a_i).

The loss depends on w1w_1 only through h1h_1, then h2h_2, and so on up to the output. By the chain rule, each layer contributes one local factor:

∂hi∂hi−1=wi ρ′(ai),∂L∂wi=∂L∂hi ρ′(ai) hi−1.\frac{\partial h_i}{\partial h_{i-1}} = w_i\, \rho'(a_i), \qquad \frac{\partial \mathcal L}{\partial w_i} = \frac{\partial \mathcal L}{\partial h_i}\, \rho'(a_i)\, h_{i-1}.

Backpropagation organizes this computation. The forward pass computes all aia_i and hih_i and keeps them. The backward pass starts from ∂L/∂hL\partial \mathcal L / \partial h_L 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.

Answers are saved on the server and tied to this browser until you sign in.