Model optimization
Compile a Keras model for supervised training.
Keras · Class
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.
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.
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)| Name | Type | Description |
|---|---|---|
learning_rate | float | LearningRateSchedule | callable | Float, LearningRateSchedule, or no-argument callable providing the learning rate; default 0.001. |
beta_1 | float | constant tensor | callable | Decay rate for first-moment estimates; default 0.9. |
beta_2 | float | constant tensor | callable | Decay rate for second-moment estimates; default 0.999. |
epsilon | float | Small constant used for numerical stability; default 1e-7. |
amsgrad | bool | Whether to use the AMSGrad variant; default False. |
weight_decay | float | None | Weight-decay coefficient; default None. |
clipnorm | float | None | Per-gradient norm clipping threshold; default None. |
clipvalue | float | None | Per-gradient value clipping threshold; default None. |
global_clipnorm | float | None | Global gradient norm clipping threshold; default None. |
use_ema | bool | Whether to use exponential moving averages of weights; default False. |
ema_momentum | float | EMA momentum; default 0.99. |
ema_overwrite_frequency | int | None | Frequency for overwriting model variables with EMA values; default None. |
An Adam optimizer instance.
keras.optimizers.Adam implements the Adam optimization algorithm.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.name value labels the optimizer's momentum accumulator weights; changing it does not change the optimization algorithm.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.
Compile a Keras model for supervised training.
Use adaptive updates when gradient magnitudes differ across parameters.
Combine optimization with clipping, decay, EMA, or accumulation controls.
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.
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.
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.Optimizerkeras.optimizers.AdamWkeras.optimizers.RMSpropkeras.optimizers.Nadamkeras.optimizers.SGD