A scalar parameter starts at θ0=1 and is trained with Adam using learning rate η=0.1, β1=0.9, β2=0.999 and ϵ=10−8. The first two gradients are g1=0.4 and g2=−0.2. What are θ1 and θ2, and what would the first step have been without bias correction?

Deep learning, Optimisers
Level L3 Intermediate. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you can run Adam by hand and explain why the bias-correction factors are needed.

Key idea

Adam keeps mt=β1mt−1+(1−β1)gt and vt=β2vt−1+(1−β2)gt2, both started at 0, so early values are biased towards zero. Dividing by 1−β1t and 1−β2t fixes this, and the update is θt=θt−1−η m^t/(v^t+ϵ).

Steps

  1. Step 1 moments. m1=0.9⋅0+0.1⋅0.4=0.04 and v1=0.999⋅0+0.001⋅0.16=0.00016.
  2. Step 1 correction. m^1=0.04/(1−0.9)=0.4 and v^1=0.00016/(1−0.999)=0.16, so v^1=0.4.
  3. Step 1 update. θ1=1−0.1⋅0.4/(0.4+10−8)≈1−0.1=0.9. A first Adam step has size about η, whatever the gradient scale.
  4. Step 2 moments. m2=0.9⋅0.04+0.1⋅(−0.2)=0.016 and v2=0.999⋅0.00016+0.001⋅0.04=0.00019984.
  5. Step 2 correction. m^2=0.016/(1−0.81)=0.0842 and v^2=0.00019984/(1−0.998001)=0.09997, so v^2=0.3162.
  6. Step 2 update. θ2=0.9−0.1⋅0.0842/0.3162=0.9−0.0266=0.8734. The sign flip in the gradient shrinks the momentum, so the step is small.
  7. Without correction, step 1 would use m1/v1=0.04/0.00016=0.04/0.01265=3.162, giving an update of 0.1×3.162=0.316, about three times too large, because v is biased towards zero much more than m.

Common mistakes

How long your answer should be

About half a page; 4 minutes.

Read this

Previous in Deep learning: How does focal loss FL⁡(pt)=−(1−pt)γlog⁡pt modify cross-entropy for extreme class imbalance, where pt is the predicted probability for the true class and γ≥0 is the focusing parameter? What is the ratio of the loss on a hard example (pt=0.1) to an easy example (pt=0.9) for γ=0 versus γ=2, and why does this help?
Next in Deep learning: You have implemented backpropagation by hand and want to test it with gradient checking. Why is the central difference J(w+h)−J(w−h)2h preferred to the forward difference, how do you compare it with your analytic gradient, and what goes wrong if h is too large or too small? Illustrate with J(w)=w3 at w=2 and h=0.1?