This is a great question about the Adam (Adaptive Moment Estimation) optimizer, which is one of the most widely used optimizers in deep learning. Let me break this down comprehensively.
Adam Optimizer Components
Adam combines:
Momentum: keeps running average of gradients (first moment)
RMSProp: keeps running average of squared gradients (second moment)
Bias correction: corrects for the initialization of moment estimates
Let me explain each component and the full algorithm.
Basic Update Rule Components
First Moment Estimate (Momentum):
m_t = β₁ * m_{t-1} + (1 - β₁) * g_t
where g_t is the gradient at time step t, and β₁ is the exponential decay rate (typically 0.9)
Second Moment Estimate (RMSProp):
v_t = β₂ * v_{t-1} + (1 - β₂) * g_t²
where β₂ is the exponential decay rate (typically 0.999)
Parameter Update (without bias correction):
θ_t = θ_{t-1} - α * m_t / (√(v_t) + ε)
where α is the learning rate and ε is a small constant for numerical stability
The Bias Correction Problem
This is the crucial part. At initialization:
m_0 = 0 (initialized to zero)
v_0 = 0 (initialized to zero)
Let me think about what happens at early time steps:
At t=1:
m_1 = β₁ * 0 + (1 - β₁) * g_1 = (1 - β₁) * g_1
v_1 = β₂ * 0 + (1 - β₂) * g_1² = (1 - β₂) * g_1²
With typical values (β₁ = 0.9, β₂ = 0.999), the first moment becomes just 10% of the actual gradient while the second moment is only 0.1% of the squared gradient. This severely dampens the initial updates. As training progresses, these estimates gradually build up—after 10 steps the first moment reaches roughly 65% of the gradient magnitude, and the effect diminishes further over time.
The underlying issue is that the exponential moving average hasn't had enough iterations to accumulate the full gradient signal. Using the geometric series formula, the first moment at step t equals g(1 - β₁^t), which means with β₁ = 0.9, we're only capturing 10% of the gradient at step 1, but this fraction grows exponentially closer to the true gradient as t increases.
To counteract this initialization bias, we divide both moments by their respective bias correction factors: m̂_t = m_t / (1 - β₁^t) and v̂_t = v_t / (1 - β₂^t). This rescaling ensures the parameter updates use the full gradient magnitude from the start, with the correction becoming negligible after just a few steps as the bias term approaches 1. _1 = m_1 / (1 - 0.9) = m_1 / 0.1 = 10 * m_1 = g_1` ✓
The moments start at zero, which means the initial estimates are severely underestimated. Without correction, the effective learning rate gets suppressed by a factor of (1-β^t), leading to tiny parameter updates when we need meaningful progress. The adaptive learning rate itself becomes biased too, compounding the problem. However, this correction matters most early on—after many iterations, (1 - β^t) approaches 1, making the adjustment nearly irrelevant (at t=1000 with β=0.9, the factor is already ≈1).
Adam Optimizer: Complete Overview
The Adam Update Rule
Adam (Adaptive Moment Estimation) combines momentum and RMSProp with bias correction:
python
# At each timestep t:
g_t = ∇f(θ_{t-1}) # Compute gradient
# First moment (momentum): exponential moving average of gradients
m_t = β₁ · m_{t-1} + (1 - β₁) · g_t
# Second moment (RMSProp): exponential moving average of squared gradients
v_t = β₂ · v_{t-1} + (1 - β₂) · g_t²
# Bias-corrected first moment
m̂_t = m_t / (1 - β₁^t)
# Bias-corrected second moment
v̂_t = v_t / (1 - β₂^t)
# Parameter update
θ_t = θ_{t-1} - α · m̂_t / (√v̂_t + ε)
Typical hyperparameters:
α = 0.001 (learning rate)
β₁ = 0.9 (momentum decay)
β₂ = 0.999 (RMSProp decay)
ε = 1e-8 (numerical stability)
Why Bias Correction is Needed
The Problem: Initialization Bias
Moments are initialized to zero: m₀ = 0, v₀ = 0
At the first timestep (t=1) with typical hyperparameters:
def adam_update(params, grads, m, v, t, lr=0.001, β₁=0.9, β₂=0.999, ε=1e-8):
"""
params: network parameters
grads: gradients w.r.t. parameters
m, v: first and second moment estimates (persistent across calls)
t: timestep (increments each iteration)
"""
for param, grad in zip(params, grads):
# Update biased first moment estimate
m = β₁ * m + (1 - β₁) * grad
# Update biased second moment estimate
v = β₂ * v + (1 - β₂) * (grad ** 2)
# Bias correction
m_hat = m / (1 - β₁ ** t)
v_hat = v / (1 - β₂ ** t)
# Update parameters
param = param - lr * m_hat / (np.sqrt(v_hat) + ε)
return params, m, v
Key Insights
Aspect
Effect
Why Important
Momentum (m)
Accelerates convergence in consistent directions
Smooths noisy gradients
RMSProp (v)
Per-parameter adaptive learning rates
Handles sparse gradients well
Bias Correction
Scales early updates properly
Fixes convergence in first iterations
Decay factors
1-β controls weighting of new vs. old information
Balances stability vs. responsiveness
The bias correction is most critical in the first handful of iterations but becomes negligible by t~100, explaining why Adam works so well in practice.