Optimisation and learning
Introduit
6:33
Intelligence artificielle et apprentissage automatique
This course covers the classical core of artificial intelligence, honestly measured. The first three units are the spine: search, logical reasoning and…
Narration en anglais · sous-titres en anglais et en 中文 au choix
Dans cette leçon
| English | Sens |
|---|---|
| loss surface/lɒs ˈsɜːfɪs/ | the loss plotted over all possible parameter values |
| Gradient descent/ˈɡreɪdɪənt dɪˈsent/ | repeatedly moving the parameters a small step against the gradient of the loss |
| learning rate/ˈlɜːnɪŋ reɪt/ | taux d'apprentissage |
| oscillation/ˌɒsɪˈleɪʃn/ | |
| minibatch/ˈmɪnɪbætʃ/ | a small random subset of the training data used for one update |
| Momentum/məʊˈmentəm/ | The product of mass and velocity. |
| stochastic gradient descent/stəˈtʃæstɪk ˈɡreɪdɪənt dɪˈsent/ | gradient descent that updates the parameters from one example or a small batch at a time |
| epoch/ˈiːpɒk/ | one full pass through the training data |
| Backpropagation/ˌbækprəpəˈɡeɪʃn/ | computing every weight's gradient efficiently by applying the chain rule backwards through the network |
| vanishing gradient/ˈvænɪʃɪŋ ˈɡreɪdɪənt/ | gradients shrinking towards zero as they pass back through many layers, so early layers learn very slowly |
Down the loss surface
- Gradient descent 梯度下降: $\theta_{t+1} = \theta_t - \eta \nabla L(\theta_t)$. Each step goes against the gradient, downhill.
- The learning rate 学习率 $\eta$ sets the size of each step, and the curvature of the loss surface 损失曲面 sets how hard the problem is.

The update rule steps —
Difficulté 1/5 · 100 pièces + un petit bonus lors de la première réussite aujourd'hui
Downhill is the negative gradient, scaled by eta.
The quadratic case, exactly
- For $L(w) = (w-3)^2$: $w_{t+1} = w_t - 2\eta(w_t - 3)$. With $\eta = 0.1$ from 0: 0.6, 1.08, 1.464, 1.771, 2.017. The error shrinks by the same factor each step, towards 3.
- With $\eta = 1$: 0, 6, 0, 6 for ever (pure oscillation 振荡). With $\eta = 0.6$: 3.6, 2.88, 3.024, an oscillation that dies down. The steps are stable when $|1 - 2\eta| < 1$, that is, when $\eta < 1$.
| $\eta$ | Error × each step | Behaviour |
|---|---|---|
| 0.1 | 0.8 | smooth but slow |
| 0.25 | 0.5 | smooth, halves |
| 0.6 | −0.2 | overshoots, dies down |
| 1 | −1 | oscillates for ever |
| above 1 | beyond −1 | grows: diverges |
- The error $w - 3$ is multiplied by $1 - 2\eta$ at every step, so that one number decides everything.
On L(w) = (w-3)^2, eta = 1 gives —
Difficulté 1/5 · 100 pièces + un petit bonus lors de la première réussite aujourd'hui
|1 - 2 eta| = 1: the boundary of stability.
Pour $L(w) = (w - 3)^2$, gradient descent with $\eta = 1.2$ converges to $w = 3$.
Difficulté 1/5 · 100 pièces + un petit bonus lors de la première réussite aujourd'hui
Each step multiplies the error by $1 - 2\eta = -1.4$; since $|-1.4| > 1$ the error grows and flips sign every step. Convergence needs $\eta < 1$.
Ravines and scaling
- On the least-squares line, with mean squared error and $\eta = 0.02$, two steps from $(w, b) = (0, 0)$ reach $(0.84, 0.25)$, and a thousand steps come close to the closed-form answer $(0.9, 1.3)$.
- With $L = (x_1-1)^2 + 100(x_2-1)^2$ the surface is a narrow valley (a ravine), 100 times steeper across than along. The steep direction needs $\eta < 0.01$ to stay stable; at $\eta = 0.009$ the error along $x_1$ shrinks by only 1.8% a step.
- Standardising the features can reduce differences in curvature, making one learning rate 学习率 more effective. Judge convergence by how much the loss is still changing, not by the loss itself.
Unscaled features with 100x curvature spread force —
Difficulté 1/5 · 100 pièces + un petit bonus lors de la première réussite aujourd'hui
One rate cannot serve both curvatures - standardise features.
Minibatches and momentum
- Full gradients over $10\,000$ examples are slow, so stochastic gradient descent 随机梯度下降 steps on a random minibatch 小批量.
- With batches of $100$, one pass through the data (an epoch 轮次) is $100$ steps. The noise costs little and even helps the search leave flat regions.
- Momentum 动量 keeps a running velocity $v \leftarrow \beta v + \nabla L$ and steps by $-\eta v$. Across a ravine the zigzags cancel out; along it the steps add up.
- In a round bowl such as $(w-3)^2$, plain descent already heads straight down (with $\eta = 0.25$ the steps go 0, 1.5, 2.25, 2.625, halving the error each time), so momentum adds little there.
A dataset has 50 000 examples and the minibatch size is 250. How many steps make one epoch?
Difficulté 2/5 · 140 pièces + un petit bonus lors de la première réussite aujourd'hui
50 000 / 250 = 200 steps.
Gradient descent on L(w) = (w - 3)^2 with η = 0.25 starts at w = 1. What is w after one step?
Difficulté 2/5 · 140 pièces + un petit bonus lors de la première réussite aujourd'hui
w - 2η(w - 3) = 1 - 0.5 x (-2) = 2.
Backpropagation on one neuron
- $y = \sigma(wx + b)$ with loss $L = (y - t)^2$. The chain rule gives $\partial L/\partial w = 2(y - t) \cdot y(1 - y) \cdot x$.
- With $w = 0.5$, $x = 2$, $b = 0$ and target $t = 1$: $z = 1$, $y = 0.731$, so $\partial L/\partial w = (-0.538)(0.197)(2) = \mathbf{-0.212}$. The negative sign says "increase $w$". Backpropagation 反向传播 is this product, reused layer by layer.
$y = \sigma(wx)$, $w = 0.5$, $x = 2$, $t = 1$, $L = (y - t)^2$: $\partial L/\partial w$ (three decimals)?
Difficulté 2/5 · 140 pièces + un petit bonus lors de la première réussite aujourd'hui
$2(0.731 - 1) \times 0.731 \times 0.269 \times 2 = -0.212$.
Worked example: why deep sigmoid networks stalled
- The sigmoid's slope $y(1 - y)$ is at most 0.25. Through 10 sigmoid layers the gradient can shrink by $0.25^{10} \approx 10^{-6}$, so the early layers hardly learn. This is the vanishing gradient 梯度消失.
- ReLU, $\max(0, z)$, has slope 1 for positive inputs, so the product does not shrink by itself. Together with careful starting weights and residual connections, this made deep networks trainable.
Largest possible product of the derivatives of 5 sigmoid activations ($0.25^5$, five decimals)?
Difficulté 2/5 · 140 pièces + un petit bonus lors de la première réussite aujourd'hui
$0.25^5 = 0.000977$.
ReLU has slope 1 for every positive input.
Difficulté 1/5 · 100 pièces + un petit bonus lors de la première réussite aujourd'hui
Its derivative is 1 above zero and 0 below.
Marks that slip away
- Too large a learning rate. For $(w - 3)^2$, $\eta = 1$ jumps between $0$ and $6$ for ever, and any $\eta > 1$ diverges.
- One rate for a ravine. Steep and shallow directions need different steps; standardising the features evens them out.
- Reading minibatch noise as a bug. Each step sees only a sample, so the loss wobbles; momentum 动量 smooths it.
Recap
- $\theta_{t+1} = \theta_t - \eta \nabla L(\theta_t)$.
- On $(w-3)^2$: stable when $\eta < 1$; $\eta = 1$ oscillates for ever.
- Ravines need scaled features or momentum 动量; judge convergence by the change in the loss.
Que s’est-il passé ? Seule l’équipe du site voit ces informations.