3.2.4Training Deep Networks

AdaGrad and RMSprop

1,525 words7 min readdifficulty · medium

Adaptive learning-rate optimizers that give each parameter its own step size, scaled by the history of its gradients.

The core problem (WHY these exist)

WHAT we want: a rule that automatically shrinks the step for parameters with big/frequent gradients and keeps large steps for parameters with small/rare gradients.

HOW: track the accumulated squared gradient per parameter, and divide the learning rate by its square root.


AdaGrad — derivation from scratch

Let gt=θLg_t = \nabla_\theta L at step tt, and consider one coordinate ii so gt,ig_{t,i} is a scalar.

Idea: the "typical size" of the gradient in coordinate ii is captured by summing its squares. Big gradients ⇒ big sum ⇒ we want a smaller effective step. The natural way to convert a "size" into a divisor is to divide by it. Squared to make it always positive and to weight large gradients more.

Define the running sum of squares: Gt,i=τ=1tgτ,i2=Gt1,i+gt,i2G_{t,i} = \sum_{\tau=1}^{t} g_{\tau,i}^2 = G_{t-1,i} + g_{t,i}^2

Then the update is:

Why G\sqrt{G} and not GG? Units. GG has units of (gradient)2^2; dividing gg by G\sqrt{G} makes the ratio dimensionless-ish and gives a well-behaved, bounded step. Dividing by GG would over-shrink.

The fatal flaw of AdaGrad

Because Gt,iG_{t,i} is a sum that only grows, Gt,i\sqrt{G_{t,i}}\to\infty, so the effective learning rate 0\to 0. In deep learning training runs for many steps, AdaGrad dies — it stops learning too early. Great for convex / sparse problems (NLP embeddings), bad for long deep-net training.


RMSprop — the fix

WHY: we don't want the entire history to accumulate forever; we want a recent estimate of gradient magnitude. Old gradients should be forgotten.

HOW: replace the growing sum with an exponentially weighted moving average (EWMA) of squared gradients. This keeps a decaying memory instead of an ever-growing sum.

Define, with decay ρ\rho (typically 0.90.9): E[g2]t,i=ρE[g2]t1,i+(1ρ)gt,i2E[g^2]_{t,i} = \rho\, E[g^2]_{t-1,i} + (1-\rho)\, g_{t,i}^2

This is a weighted average: recent squares count fully, old ones fade geometrically. Now it doesn't blow up — it settles to the recent mean-square gradient.

Because E[g2]E[g^2] stays a bounded average (not a sum), the effective learning rate stops decaying to zero — training continues.

Figure — AdaGrad and RMSprop

Worked example 1 — AdaGrad on two coordinates

Let η=0.1\eta=0.1, ϵ=0\epsilon=0. Coordinate A always has g=1g=1; coordinate B always has g=0.1g=0.1.

Step 1:

  • GA=12=1G_A = 1^2 = 1, step =0.111=0.1=\frac{0.1}{\sqrt1}\cdot1 = 0.1. Why? First gradient sets the scale.
  • GB=0.12=0.01G_B = 0.1^2 = 0.01, step =0.10.010.1=0.10.10.1=0.1=\frac{0.1}{\sqrt{0.01}}\cdot0.1 = \frac{0.1}{0.1}\cdot0.1 = 0.1.

Why interesting: even though B's raw gradient is 10× smaller, AdaGrad rescaled its step up to match A. That's the equalizing effect.

Step 2:

  • GA=2G_A = 2, step =0.1210.0707=\frac{0.1}{\sqrt2}\cdot1 \approx 0.0707. Why? History accumulated, step shrank.

Worked example 2 — RMSprop stays alive

η=0.1\eta=0.1, ρ=0.9\rho=0.9, ϵ=0\epsilon=0, constant g=1g=1.

E[g2]E[g^2] converges: at steady state E=0.9E+0.1(1)E=1E = 0.9E + 0.1(1) \Rightarrow E = 1. So step =0.111=0.1=\frac{0.1}{\sqrt1}\cdot1 = 0.1 forever. Why this step? The EWMA saturates at the true mean-square (1), giving a constant effective rate — no death. Contrast AdaGrad where Gt=tG_t=t\to\infty and step 0\to 0.


Flashcards

What global problem do AdaGrad/RMSprop solve?
A single global learning rate can't suit parameters with very different gradient magnitudes; they give per-parameter adaptive rates.
AdaGrad accumulator update?
Gt=Gt1+gt2G_{t}=G_{t-1}+g_t^2 (sum of all past squared gradients).
AdaGrad parameter update?
θt+1=θtηGt+ϵgt\theta_{t+1}=\theta_t-\dfrac{\eta}{\sqrt{G_t}+\epsilon}g_t.
Why does AdaGrad eventually stop learning?
GtG_t grows without bound, so η/Gt0\eta/\sqrt{G_t}\to 0; effective learning rate decays to zero.
How does RMSprop fix that?
Replaces the growing sum with an EWMA: E[g2]t=ρE[g2]t1+(1ρ)gt2E[g^2]_t=\rho E[g^2]_{t-1}+(1-\rho)g_t^2, which stays bounded.
RMSprop update?
θt+1=θtηE[g2]t+ϵgt\theta_{t+1}=\theta_t-\dfrac{\eta}{\sqrt{E[g^2]_t}+\epsilon}g_t.
Typical ρ\rho and η\eta for RMSprop?
ρ0.9\rho\approx0.9, η103\eta\approx10^{-3}.
Why square the gradient (not abs value)?
Squaring weights large gradients more and gives a differentiable, variance-like measure; \sqrt{} restores proper units.
Steady-state RMSprop step for constant gradient gg?
E[g2]g2E[g^2]\to g^2, so effective step η\to \eta (constant, unlike AdaGrad).
Role of ϵ\epsilon?
Numerical stability — avoids division by zero when accumulator is tiny.

Recall Feynman: explain to a 12-year-old

Imagine walking downhill in fog to reach the lowest point. Some directions are steep cliffs, others are gentle slopes. If you take the same size step everywhere, you'll trip on the cliffs and crawl on the slopes. AdaGrad watches how bumpy each direction has been and takes smaller steps on bumpy directions, bigger steps on smooth ones. Problem: AdaGrad remembers forever, so after a while it's taking micro-steps everywhere and basically stops. RMSprop is smarter — it only remembers the recent bumpiness and forgets old bumps, so it keeps walking at a good pace the whole way down.

Connections

  • Stochastic Gradient Descent — the baseline these improve on
  • Momentum — smooths gradients (first moment) vs these which scale by variance (second moment)
  • Adam Optimizer — literally = RMSprop + momentum + bias correction
  • Exponentially Weighted Moving Averages — the math engine behind RMSprop
  • Learning Rate Schedules — alternative/complement to adaptivity
  • Vanishing and Exploding Gradients — why per-coordinate scaling helps

Concept Map

fails on

solved by

track

sum over history

divides eta by

gives

G only grows

motivates

replaces sum with

forgets old gradients

good for

Plain SGD one global eta

Per-parameter step size needed

Adaptive learning rates

Accumulated squared gradients

AdaGrad

sqrt of G plus epsilon

Per-coordinate effective rate

Effective rate goes to zero, dies

RMSprop

EWMA of squared gradients, decay rho

Non-vanishing recent estimate

Convex / sparse NLP problems

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, normal SGD me poore network ke saare parameters ke liye ek hi learning rate hoti hai. Problem yeh hai ki kuch directions bahut steep hote hain (bade gradient) aur kuch bahut flat (chhote gradient). Ek hi step size sabko suit nahi karta — steep me oscillation, flat me movement hi nahi. AdaGrad ka idea: har parameter ko apni alag learning rate do, jo uske gradients ki history par depend kare. Formula me hum har coordinate ke squared gradients ko add karte jaate hain (GtG_t), aur η\eta ko Gt\sqrt{G_t} se divide karte hain. Bade gradient wale ko chhota step, chhote gradient wale ko bada step — automatic balancing.

Lekin AdaGrad ka ek badbad problem hai: GtG_t sirf badhta hai, kabhi ghatta nahi (kyunki sum hai). Isliye Gt\sqrt{G_t} bada hota jaata hai aur effective learning rate slowly zero ho jaati hai. Deep networks me jahan lakhon steps chalte hain, AdaGrad beech me hi "mar" jaata hai — learning ruk jaati hai.

RMSprop yahi fix karta hai. Sum ki jagah hum exponentially weighted moving average lete hain: E[g2]t=ρE[g2]t1+(1ρ)gt2E[g^2]_t = \rho E[g^2]_{t-1} + (1-\rho)g_t^2, usually ρ=0.9\rho=0.9. Matlab purane gradients ko dheere-dheere bhool jao, sirf recent bumpiness yaad rakho. Isse average bounded rehta hai, zero tak nahi jaata, aur training poori chalti rehti hai. Yaad rakho: Adam optimizer basically RMSprop + Momentum hi hai, isliye yeh concept aage bahut kaam aata hai.

Go deeper — visual, from zero

Test yourself — Training Deep Networks

Connections