Adam Optimizer › The Two Moment Estimates
Language AI HandbookAll chapters 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 :
- The first moment is the mean:
- The second moment is the mean of the square: (uncentered variance)
Adam does not compute these exactly. Instead it maintains exponential moving averages that approximate them. Let be the gradient of the loss with respect to a single parameter at step . Adam maintains:
where:
- : the first moment estimate (exponential moving average of gradients)
- : the second moment estimate (exponential moving average of squared gradients)
- : the decay rate for the first moment, typically 0.9
- : the decay rate for the second moment, typically 0.999
- : the gradient at time step
The first moment is recognizable as the velocity term from momentum. When gradients consistently point in one direction, 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 tracks the recent average of squared gradients. If a parameter has been receiving large gradients (either positive or negative), will be large. If it has received small or near-zero gradients, will be small. Squaring keeps 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 repeatedly. The second moment . The effective learning rate is scaled by . Not much amplification because this parameter is already getting strong updates.
Parameter B (sparse gradients): receives gradients like rarely. The second moment (most steps contribute zero). The effective learning rate is scaled by . This rare-but-important parameter gets a much larger effective step.
The division by 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 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.