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

Keras · Class

optimizers.Adam

Adam is a Keras optimizer based on adaptive first- and second-moment estimates. Configure its learning rate, moment decay, numerical stability, clipping, weight decay, EMA, and accumulation behavior.

How it works

Adam updates model variables using adaptive estimates of first- and second-order gradient moments. Its configurable learning rate, moment decay factors, numerical-stability constant, clipping options, weight decay, EMA behavior, and gradient accumulation let you adapt optimization to the training setup.

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 | LearningRateSchedule | callableFloat, LearningRateSchedule, or no-argument callable providing the learning rate; default 0.001.
beta_1float | constant tensor | callableDecay rate for first-moment estimates; default 0.9.
beta_2float | constant tensor | callableDecay rate for second-moment estimates; default 0.999.
epsilonfloatSmall constant used for numerical stability; default 1e-7.
amsgradboolWhether to use the AMSGrad variant; default False.
weight_decayfloat | NoneWeight-decay coefficient; default None.
clipnormfloat | NonePer-gradient norm clipping threshold; default None.
clipvaluefloat | NonePer-gradient value clipping threshold; default None.
global_clipnormfloat | NoneGlobal gradient norm clipping threshold; default None.
use_emaboolWhether to use exponential moving averages of weights; default False.
ema_momentumfloatEMA momentum; default 0.99.
ema_overwrite_frequencyint | NoneFrequency for overwriting model variables with EMA values; default None.

Returns

An Adam optimizer instance.

Key points

  • keras.optimizers.Adam implements the Adam optimization algorithm.
  • Adam adapts updates from estimates of the first and second gradient moments.
  • learning_rate controls the step size and defaults to 0.001.
  • beta_1 controls decay of first-moment estimates and defaults to 0.9.
  • beta_2 controls decay of second-moment estimates and defaults to 0.999.
  • epsilon adds a small numerical-stability constant to the update calculation.

Common mistakes

  • The name value labels the optimizer's momentum accumulator weights; changing it does not change the optimization algorithm.

Example: Compile a model with Adam

import keras

model = keras.Sequential([
    keras.layers.Dense(1, input_shape=(4,))
])
model.compile(
    optimizer=keras.optimizers.Adam(learning_rate=0.001),
    loss="mse",
)

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

When to use it

Model optimization

Compile a Keras model for supervised training.

Adaptive gradient training

Use adaptive updates when gradient magnitudes differ across parameters.

Customized training updates

Combine optimization with clipping, decay, EMA, or accumulation controls.

Interview questions

QWhat is Adam, and what are its main defaults?

Adam is a stochastic gradient-descent optimizer that adapts updates using estimates of first- and second-order moments. Its default learning rate is 0.001, with beta values of 0.9 and 0.999.

Follow-up: How can the learning rate vary during training? Pass a LearningRateSchedule or a no-argument callable instead of a fixed numeric value.

QHow do you select the AMSGrad variant?

Set amsgrad=True to use the AMSGrad variant. The default is False, so standard Adam is used unless this option is enabled.

Follow-up: Which numerical parameter helps prevent unstable division by very small values? epsilon supplies a small constant for numerical stability.

QWhat does use_ema control?

Adam can apply exponential moving averages to model weights when use_ema=True; this option defaults to False. The EMA behavior is controlled by ema_momentum and optionally by ema_overwrite_frequency.

Follow-up: What other update controls can be configured? Weight decay, gradient clipping, loss scaling, and gradient accumulation are available parameters.

  • keras.optimizers.Optimizer
  • keras.optimizers.AdamW
  • keras.optimizers.RMSprop
  • keras.optimizers.Nadam
  • keras.optimizers.SGD

Source: Adam. Checked 2026-10-15.