Running Adam Optimizer
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Running Adam Optimizer is one of the pivotal developments in the area of machine learning, particularly in the optimization of neural networks. The Adam optimizer, standing for Adaptive Moment Estimation, effectively combines the advantages of two other popular optimizers: AdaGrad and RMSProp. This optimizer is designed to work with noisy data and sparse gradients, making it highly relevant for training deep learning models.
Introduction to Adam Optimizer
The Adam optimizer was introduced by Diederik P. Kingma and Jimmy Lei Ba in 2014. It utilizes the power of adaptive learning rates per parameter, which helps in accelerating the convergence of the training process. Adam makes use of two key ideas:
- Momentum: Like SGD with momentum, Adam computes an exponentially weighted average of past gradients.
- Adaptive Learning Rate: It adjusts learning rates based on the average of past squared gradients.
Mechanisms of Adam Optimizer
Adam is an extension to stochastic gradient descent that computes adaptive learning rates for each parameter. Let's break down the key components of Adam:
• Gradient, : The gradient of the stochastic objective function at time step t.
• Two Moment Estimates: • First Moment (Mean) - :
This is an exponentially decaying average of past gradients, similar to momentum.
• Second Moment (Uncentered Variance) - :
This is an exponentially decaying average of the squares of past gradients.
• Bias-Corrected Moment Estimates: • First Moment:
• Second Moment:
• Parameter Update:
Here, is the learning rate and is a small constant to prevent division by zero.
Hyperparameters of Adam
The Adam optimizer has several hyperparameters that can be fine-tuned:
• Learning Rate (): Default is 0.001; this is a step size for moving toward the minima of the cost function.
• Exponential Decay Rates: Typically, and are the default.
• Epsilon (): A small constant (e.g., ) added to the denominator to improve numerical stability.
These hyperparameters are essential in diagnosing and troubleshooting training performance in deep neural networks.
Key Advantages of Adam
Adam is widely adopted in deep learning due to several advantages:
• Efficient: Adam requires relatively little memory and is computationally efficient.
• Invariance: Works well regardless of problem scaling due to its adaptive nature.
• Robust: Performs well when dealing with non-stationary objectives, and sparse gradients.
• Minimal Hyperparameter Tuning: Default settings are often good enough for most problems.
Comparison with Other Optimizers
| Optimizer | Advantages | Disadvantages |
| SGD | Simplicity, works well with large datasets | Fixed learning rate, sensitive to initial settings |
| Momentum | Accelerates convergence on steep paths | Can overshoot |
| AdaGrad | Well-suited for sparse data | Learning rates can become very small after many updates |
| RMSProp | Adjustable learning rates for each of the parameters over time, good for online learning | Learning rates need careful tuning |
| Adam | Combines the advantages of AdaGrad and RMSProp, adapts learning rates | May not work well with very noisy data |
Implementation Example
Here is a basic implementation of the Adam optimizer in Python using TensorFlow:
Related reading
- Running Keras with double precision fails
- Running MSIL on GPU
- Running multiple tensorflow sessions concurrently
- running nvidia-docker on Windows 10 WSL2
- Running Keras model for prediction in multiple threads
- Running session using tensorflow c api is significantly slower than using python
- Running time of algorithm A is at least On² - Why is it meaningless?
- Rush Hour puzzle - how to avoid huge search tree?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.