General neural-network training
A model needs an adaptive optimizer with momentum behavior that can improve parameter updates.
Keras · Class
Nadam is an adaptive Keras optimizer that applies Adam-style updates with Nesterov momentum. It supports configurable learning rates, moment decay, clipping, weight decay, EMA, and optional XLA compilation.
Nadam maintains adaptive first- and second-moment estimates like Adam, while adding Nesterov momentum to the update behavior. Its learning rate and moment-decay settings can be fixed values or dynamically supplied callables, and optional weight decay, gradient clipping, EMA, and XLA compilation modify training behavior.
tf_keras.optimizers.Nadam(learning_rate=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-07, weight_decay=None, clipnorm=None, clipvalue=None, global_clipnorm=None, use_ema=False, ema_momentum=0.99, ema_overwrite_frequency=None, jit_compile=True, name="Nadam", **kwargs)| Name | Type | Description |
|---|---|---|
learning_rate | Tensor, float, schedule, or callable | A tensor, floating-point value, learning-rate schedule, or zero-argument callable supplying the learning rate; defaults to 0.001. |
beta_1 | float, tensor, or callable | Decay rate for first-moment estimates; defaults to 0.9. |
beta_2 | float, tensor, or callable | Decay rate for second-moment estimates; defaults to 0.999. |
epsilon | float | Small value used for numerical stability; defaults to 1e-7. |
weight_decay | float or None | Weight-decay coefficient; defaults to None. |
clipnorm | float or None | Maximum norm for each gradient; defaults to None. |
clipvalue | float or None | Maximum absolute value for each gradient element; defaults to None. |
global_clipnorm | float or None | Maximum norm for all gradients together; defaults to None. |
use_ema | boolean | Whether to apply exponential moving averages to weights; defaults to False. |
ema_momentum | float | EMA decay momentum; defaults to 0.99. |
ema_overwrite_frequency | integer or None | How frequently EMA weights overwrite model weights; defaults to None. |
jit_compile | boolean | Whether to use XLA compilation; defaults to True. |
A Nadam optimizer instance.
import keras
model = keras.Sequential([
keras.layers.Dense(10, activation="softmax", input_shape=(4,))
])
model.compile(
optimizer=keras.optimizers.Nadam(learning_rate=0.001),
loss="sparse_categorical_crossentropy",
)
Creates Nadam with its default learning rate and uses it when compiling a Keras model.
A model needs an adaptive optimizer with momentum behavior that can improve parameter updates.
Training requires explicit control over gradient magnitudes or regularization.
A workflow benefits from smoothed model weights during training.
The runtime supports XLA and training performance may benefit from compilation.
Nadam is an adaptive optimizer that combines Adam-style moment estimates with Nesterov momentum. Its default learning rate is 0.001, with beta_1 set to 0.9 and beta_2 set to 0.999.
Follow-up: How can the learning rate vary during training? Pass a learning-rate schedule or a zero-argument callable that returns the value to use.
The learning_rate argument accepts a tensor, floating-point value, learning-rate schedule, or zero-argument callable. The beta parameters likewise accept numeric values or callables, allowing dynamic hyperparameters.
Follow-up: What should be checked when supplying a callable? Ensure it takes no arguments and returns the actual numeric value expected by the optimizer.
Nadam exposes gradient clipping through clipnorm, clipvalue, and global_clipnorm. It also supports weight_decay, EMA settings, and jit_compile for XLA compilation.
Follow-up: What happens to jit_compile if there is no GPU? The documentation says the flag is ignored.
keras.optimizers.Adamkeras.optimizers.RMSpropkeras.optimizers.Optimizerkeras.optimizers.AdamW