3.2.3Training Deep Networks

Momentum and Nesterov momentum

2,106 words10 min readdifficulty · medium3 backlinks

WHAT is the problem we are fixing?

Plain (vanilla) gradient descent update: θt+1=θtηθL(θt)\theta_{t+1} = \theta_t - \eta \, \nabla_\theta L(\theta_t)

The step depends only on the current gradient. If gradients keep flipping sign across a valley, progress cancels out. We want to remember the past to smooth this out.


Momentum — deriving it from first principles

Step 1 — Define a velocity vv as an exponentially weighted average of past gradients. Let β[0,1)\beta \in [0,1) be the momentum coefficient (how much of the past we keep): vt=βvt1+θL(θt)v_{t} = \beta\, v_{t-1} + \nabla_\theta L(\theta_t)

Why this step? Unrolling gives vt=k=0tβkL(θtk)v_t = \sum_{k=0}^{t} \beta^{\,k}\,\nabla L(\theta_{t-k}) — a weighted sum where recent gradients count most and old ones decay geometrically. That is a smoothed gradient.

Step 2 — Take a step along the velocity, not the raw gradient: θt+1=θtηvt\theta_{t+1} = \theta_t - \eta\, v_t

Figure — Momentum and Nesterov momentum

Nesterov momentum — a smarter look-ahead

Step 1 — Compute the look-ahead point (where momentum alone would carry us): θ~t=θtηβvt1\tilde\theta_t = \theta_t - \eta\,\beta\, v_{t-1}

Why this step? This is the anticipated position. Evaluating the gradient here gives more up-to-date curvature information.

Step 2 — Update velocity using the look-ahead gradient: vt=βvt1+θL(θ~t)v_t = \beta v_{t-1} + \nabla_\theta L(\tilde\theta_t)

Step 3 — Take the step: θt+1=θtηvt\theta_{t+1} = \theta_t - \eta v_t


Worked examples


Common mistakes (steel-manned)


80/20 — the essentials

Recall Feynman: explain to a 12-year-old

Imagine rolling a ball down a bumpy hill instead of taking one careful step at a time. Because the ball is heavy, it keeps rolling in the direction it's been going, so it speeds up down the long slope and doesn't get thrown around by little bumps. That's momentum. Nesterov is a slightly smarter ball that looks a little ahead to where it's about to roll, and if it sees it's about to overshoot, it slows down early. So it reaches the bottom faster and smoother than a ball that just reacts to whatever is right under it.


Flashcards

What update rule does plain gradient descent use?
θt+1=θtηL(θt)\theta_{t+1}=\theta_t-\eta\nabla L(\theta_t) — step along the raw current gradient only.
Why does plain GD zig-zag in narrow valleys?
The loss is ill-conditioned; a small η\eta needed for the steep direction is too small for the flat direction, so it oscillates across the steep walls.
Write the classical (Polyak) momentum equations.
vt=βvt1+L(θt)v_t=\beta v_{t-1}+\nabla L(\theta_t), then θt+1=θtηvt\theta_{t+1}=\theta_t-\eta v_t.
What is vtv_t intuitively?
An exponentially weighted moving average of past gradients: vt=kβkL(θtk)v_t=\sum_k \beta^k \nabla L(\theta_{t-k}).
What is the effective learning rate in a consistent direction?
η/(1β)\eta/(1-\beta) — e.g. 10η10\eta when β=0.9\beta=0.9.
How does momentum handle oscillating gradients?
Sign-flipping components largely cancel in the running average, damping the zig-zag.
How does Nesterov differ from classical momentum in one sentence?
It evaluates the gradient at the look-ahead point θtηβvt1\theta_t-\eta\beta v_{t-1} instead of at θt\theta_t.
Write the Nesterov update.
θ~t=θtηβvt1\tilde\theta_t=\theta_t-\eta\beta v_{t-1}; vt=βvt1+L(θ~t)v_t=\beta v_{t-1}+\nabla L(\tilde\theta_t); θt+1=θtηvt\theta_{t+1}=\theta_t-\eta v_t.
Why is Nesterov's look-ahead helpful?
It anticipates where momentum will carry you and corrects before overshooting, giving smoother/faster convergence.
Typical value of β\beta?
About 0.90.9 (sometimes up to 0.990.99).
What goes wrong if β\beta is too large?
The "ball" is too heavy → overshoots and orbits the minimum, slow to settle.
Steel-man: is momentum just a larger learning rate?
No — it's direction-selective: it enlarges consistent directions but cancels oscillating ones; a bigger η\eta would blow up the steep direction.
Convex convergence rate improvement from Nesterov?
O(1/t2)O(1/t^2) vs plain GD's O(1/t)O(1/t).

Connections

  • Gradient Descent — the baseline momentum improves on.
  • Stochastic Gradient Descent (SGD) — momentum is usually applied to mini-batch SGD.
  • Adam Optimizer — combines momentum (1st moment) with adaptive scaling (2nd moment).
  • RMSProp — adaptive learning rates; often compared with momentum.
  • Hessian and Condition Number — why ill-conditioning makes momentum necessary.
  • Exponentially Weighted Moving Average — the math underlying velocity.
  • Learning Rate Schedules — interacts with β\beta for stability.

Concept Map

causes

uses only current gradient

needs small learning rate

motivates

amplifies signal, cancels noise

controlled by

step along velocity

effective LR eta over 1-beta

equivalent to

improved by look-ahead

gradient at look-ahead point

Ill-conditioning: high condition number

SGD zig-zags in valleys

Plain gradient descent

Slow along flat floor

Velocity: EW average of gradients

Classical Polyak momentum

Momentum coefficient beta

Theta updated by eta times v

Up to 10x speed-up

Heavy-ball rewriting

Nesterov momentum

Faster, more responsive

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, plain gradient descent ka problem ye hai ki jab loss surface ek patli (narrow) valley jaisi ho — ek direction mein bahut steep aur doosri mein bahut flat — tab wo steep walls ke beech mein zig-zag karta reh jaata hai aur minimum ki taraf slow-slow chalta hai. Isko theek karne ke liye momentum aata hai. Idea simple hai: har step pe sirf current gradient use mat karo, balki past gradients ka exponentially weighted average (velocity vv) use karo. Jo direction consistent hai, uske gradients add ho jaate hain (speed badh jaati hai), aur jo direction oscillate kar rahi hai uske plus-minus cancel ho jaate hain. Isliye ball smooth aur fast valley ke floor pe roll karta hai.

Formula yaad rakho: vt=βvt1+Lv_t = \beta v_{t-1} + \nabla L, phir θθηvt\theta \leftarrow \theta - \eta v_t. Yahan β0.9\beta \approx 0.9 hota hai, matlab ball kitna "bhaari" hai. Ek mast intuition: agar gradient constant rahe to effective learning rate η/(1β)\eta/(1-\beta) ban jaata hai — β=0.9\beta=0.9 pe seedha 10x speed-up consistent direction mein. Lekin dhyan rakho, β\beta bahut zyada (0.9990.999) rakhoge to ball itna bhaari ho jaayega ki minimum ke around ghoomta reh jaayega (overshoot).

Nesterov momentum thoda smart version hai. Classical momentum "pehle jump, phir correct" karta hai. Nesterov kehta hai — "pehle dekh le ki main jump karke kahan girunga (look-ahead point θηβv\theta - \eta\beta v), wahan ka gradient le, phir jump kar." Isse overshoot pehle hi kam ho jaata hai, jaise driver curve se pehle brake maar de. Result: smoother aur faster convergence. Ye matter isliye karta hai kyunki deep networks ki loss surfaces mostly ill-conditioned hoti hain, aur momentum/Nesterov training ko practically bahut fast bana dete hain — yahi cheez aage Adam optimizer ka bhi core banti hai.

Go deeper — visual, from zero

Test yourself — Training Deep Networks

Connections