DL0048 Adam Optimizer

Can you explain how the Adam optimizer works?

Answer

Adam (Adaptive Moment Estimation) combines momentum and RMSprop: it keeps an exponentially decaying average of the gradient (first moment, the direction) and of the squared gradient (second moment, the scale), then divides the former by the square root of the latter. The result is a per-parameter adaptive learning rate: large steps for parameters with small, consistent gradients, small steps for noisy or steep ones, plus bias correction that fixes the zero-initialization of both averages in early steps.

(1) First Moment (Momentum): m_t = \beta_1 m_{t-1} + (1-\beta_1) g_t smooths the gradient direction over time.
(2) Second Moment (RMSprop): v_t = \beta_2 v_{t-1} + (1-\beta_2) g_t^2 tracks the gradient magnitude for per-parameter scaling.
(3) Bias Correction + Update: \hat{m}_t = m_t/(1-\beta_1^t), \hat{v}_t = v_t/(1-\beta_2^t) remove the zero-init bias before the normalized step.

Mathematical Formulation:
\theta_t = \theta_{t-1} - \alpha\, \frac{\hat{m}_t}{\sqrt{\hat{v}_t} + \epsilon}

Where:

  • \theta_t are the model parameters at step t, and g_t is the gradient of the loss at that step.
  • \alpha is the learning rate (default 0.001); \epsilon \approx 10^{-8} prevents division by zero.
  • \beta_1 = 0.9 and \beta_2 = 0.999 control the decay of the first and second moment averages (paper defaults).
Contour plot of a quadratic bowl with the Adam optimizer path moving from a start point in the corner along adaptive steps that converge smoothly to the minimum at the origin.

Figure 1: Adam on a quadratic bowl: adaptive per-parameter steps converge smoothly to the minimum without the zig-zag of plain SGD.

Intuition for the Division: \hat{m}_t / \sqrt{\hat{v}_t} is roughly a signal-to-noise ratio: parameters whose gradients are large but inconsistent (high v) get small updates, while parameters with small but persistent gradients get amplified. This is what makes Adam robust to ill-scaled features and sparse gradients.


Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *