Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Keras · Class

Adam

Adam is a Keras optimizer based on adaptive estimates of first- and second-order gradient moments. Configure its learning rate, moment decay, clipping, EMA, and related optimization options before compiling a model.

How it works

Adam updates model variables using adaptive estimates of first- and second-order gradient moments. Its behavior can be adjusted with decay rates, numerical-stability epsilon, AMSGrad, weight decay, gradient clipping, EMA, loss scaling, and gradient accumulation options.

Syntax

keras.optimizers.Adam(learning_rate=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-07, amsgrad=False, weight_decay=None, clipnorm=None, clipvalue=None, global_clipnorm=None, use_ema=False, ema_momentum=0.99, ema_overwrite_frequency=None, loss_scale_factor=None, gradient_accumulation_steps=None, name=None, **kwargs)

Parameters

NameTypeDescription
learning_ratefloat, keras.optimizers.schedules.LearningRateSchedule, or callableLearning rate, schedule, or zero-argument callable; defaults to 0.001.
beta_1float, constant float tensor, or callableExponential decay rate for first-moment estimates; defaults to 0.9.
beta_2float, constant float tensor, or callableExponential decay rate for second-moment estimates; defaults to 0.999.
epsilonfloatSmall value used by the optimizer for numerical stability; defaults to 1e-07.
amsgradbooleanWhether to use the AMSGrad variant; defaults to False.
weight_decayfloat or NoneWeight-decay coefficient, or None to disable it.
clipnormfloat or NonePer-gradient norm clipping threshold.
clipvaluefloat or NonePer-gradient value clipping threshold.
global_clipnormfloat or NoneGlobal gradient norm clipping threshold.
use_emabooleanWhether to use exponential moving averages of model weights.
ema_momentumfloatEMA momentum; defaults to 0.99.
ema_overwrite_frequencyinteger or NoneHow often to overwrite model weights with EMA values.

Returns

An Adam optimizer instance.

Key points

  • Adam is Keras's optimizer implementation of the Adam algorithm.
  • The update adapts to gradient history through estimates of first- and second-order moments.
  • beta_1 controls decay of the first-moment estimate and defaults to 0.9.
  • beta_2 controls decay of the second-moment estimate and defaults to 0.999.
  • amsgrad is a Boolean switch for using the AMSGrad variant and defaults to False.
  • learning_rate accepts a number, a Keras learning-rate schedule, or a callable.

Common mistakes

  • The learning rate may be a schedule or a zero-argument callable, not only a fixed numeric value.
  • Setting amsgrad=True selects the AMSGrad variant rather than the default Adam update.

Example: Compile a model with Adam

import keras

model = keras.Sequential([
    keras.layers.Dense(10, activation="softmax", input_shape=(4,))
])
model.compile(
    optimizer=keras.optimizers.Adam(learning_rate=0.001),
    loss="sparse_categorical_crossentropy",
)

Creates Adam with its standard learning rate and uses it to compile a classification model.

When to use it

General model optimization

Train neural networks with a generally effective adaptive optimizer.

Scheduled learning rates

Change step sizes during training.

Gradient clipping

Limit unusually large updates.

Exponential moving averages

Track smoothed model weights during optimization.

Interview questions

QWhat is Adam in Keras?

Adam is a stochastic gradient-descent optimizer that adaptively estimates first- and second-order moments of gradients. In Keras, it is configured through the keras.optimizers.Adam class.

Follow-up: How would you vary the learning rate during training? Pass a LearningRateSchedule or a zero-argument callable as learning_rate.

QWhat are Adam's principal hyperparameters?

The default learning rate is 0.001; beta_1 and beta_2 default to 0.9 and 0.999 and control exponential decay of first- and second-moment estimates. epsilon defaults to 1e-07 and supports numerical stability.

Follow-up: What does amsgrad change? It enables the AMSGrad variant of Adam when set to True.

QHow can Adam be supplied to a Keras model?

Instantiate Adam and pass the resulting optimizer to model.compile, or use the string identifier "adam". Passing the object allows explicit configuration of optimizer parameters.

Follow-up: What happens when the string identifier is used? Keras uses the optimizer's default parameters.

  • keras.optimizers.AdamW
  • keras.optimizers.Adamax
  • keras.optimizers.Nadam
  • keras.optimizers.Optimizer

Source: Adam. Checked 2026-10-15.