Adam Optimizer › The Two Moment Estimates

Michael BrenndoerferApril 24, 20253 min read
Language AI HandbookAll chapters
Part 10 of 67Neural Network Foundations
Chapter 68Adam Optimizer › The Two Moment Estimates
Reading section 3 of 18 · The Two Moment Estimates · 3 minSection 3 of 18 · 3 min

Book contents

Section 3 of 18 · 3 min read

Adam Optimizer › The Two Moment EstimatesOne section · Sections in this chapter3 / 18 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Adam names its running statistics after statistical moments. Recall that for a random variable gg:

  • The first moment is the mean: E[g]\mathbb{E}[g]
  • The second moment is the mean of the square: E[g2]\mathbb{E}[g^2] (uncentered variance)

Adam does not compute these exactly. Instead it maintains exponential moving averages that approximate them. Let gtg_t be the gradient of the loss with respect to a single parameter at step tt. Adam maintains:

mt=β1mt−1+(1−β1)gtm_t = \beta_1 m_{t-1} + (1 - \beta_1) g_t vt=β2vt−1+(1−β2)gt2v_t = \beta_2 v_{t-1} + (1 - \beta_2) g_t^2

where:

  • mtm_t: the first moment estimate (exponential moving average of gradients)
  • vtv_t: the second moment estimate (exponential moving average of squared gradients)
  • β1\beta_1: the decay rate for the first moment, typically 0.9
  • β2\beta_2: the decay rate for the second moment, typically 0.999
  • gtg_t: the gradient at time step tt

The first moment mtm_t is recognizable as the velocity term from momentum. When gradients consistently point in one direction, mtm_t builds up in that direction. When gradients oscillate, contributions cancel out. This is exactly the momentum behavior we saw in Chapter 7.

The second moment vtv_t tracks the recent average of squared gradients. If a parameter has been receiving large gradients (either positive or negative), vtv_t will be large. If it has received small or near-zero gradients, vtv_t will be small. Squaring keeps vtv_t positive and captures magnitude regardless of sign.

The Intuition Behind Dividing by the Second Moment

The Adam update will divide the first moment by the square root of the second moment. To see why this achieves adaptive learning rates, consider two parameters:

Parameter A (dense gradients): receives gradients like [0.8,0.7,0.9,0.8,...][0.8, 0.7, 0.9, 0.8, ...] repeatedly. The second moment vt≈0.64v_t \approx 0.64. The effective learning rate is scaled by 1/0.64≈1.251/\sqrt{0.64} \approx 1.25. Not much amplification because this parameter is already getting strong updates.

Parameter B (sparse gradients): receives gradients like [0.01,0.0,0.0,0.0,0.5,0.0,...][0.01, 0.0, 0.0, 0.0, 0.5, 0.0, ...] rarely. The second moment vt≈0.002v_t \approx 0.002 (most steps contribute zero). The effective learning rate is scaled by 1/0.002≈221/\sqrt{0.002} \approx 22. This rare-but-important parameter gets a much larger effective step.

The division by vt\sqrt{v_t} naturally equalizes the learning pace: parameters with large historical gradients get a small effective learning rate, and parameters with small historical gradients get a large effective learning rate. The optimizer finds a reasonable pace for each parameter without any manual tuning.

There is a useful geometric interpretation of what Adam is doing. The second moment estimate vt\sqrt{v_t} approximates the root-mean-square gradient for each parameter. Dividing by this quantity normalizes the update so that each parameter receives a step whose size is roughly proportional to the inverse of its typical gradient magnitude. In a sense, Adam is performing a diagonal approximation to the natural gradient: it rescales the gradient to account for the curvature of the loss surface along each parameter axis independently. Full natural gradient methods (like K-FAC) use the full Fisher information matrix to perform this rescaling, which is computationally prohibitive at large scale. Adam's diagonal approximation is cheap to compute and surprisingly effective in practice, capturing the most important per-axis curvature information while staying computationally tractable.