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

Keras · Class

optimizers.Nadam

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.

How it works

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.

Syntax

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)

Parameters

NameTypeDescription
learning_rateTensor, float, schedule, or callableA tensor, floating-point value, learning-rate schedule, or zero-argument callable supplying the learning rate; defaults to 0.001.
beta_1float, tensor, or callableDecay rate for first-moment estimates; defaults to 0.9.
beta_2float, tensor, or callableDecay rate for second-moment estimates; defaults to 0.999.
epsilonfloatSmall value used for numerical stability; defaults to 1e-7.
weight_decayfloat or NoneWeight-decay coefficient; defaults to None.
clipnormfloat or NoneMaximum norm for each gradient; defaults to None.
clipvaluefloat or NoneMaximum absolute value for each gradient element; defaults to None.
global_clipnormfloat or NoneMaximum norm for all gradients together; defaults to None.
use_emabooleanWhether to apply exponential moving averages to weights; defaults to False.
ema_momentumfloatEMA decay momentum; defaults to 0.99.
ema_overwrite_frequencyinteger or NoneHow frequently EMA weights overwrite model weights; defaults to None.
jit_compilebooleanWhether to use XLA compilation; defaults to True.

Returns

A Nadam optimizer instance.

Key points

  • Nadam is the Keras optimizer implementation of the Nadam algorithm.
  • Conceptually, Nadam combines Adam with Nesterov momentum.
  • learning_rate controls the optimizer's step size and defaults to 0.001.
  • 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.
  • use_ema is disabled by default; enabling it applies exponential moving averages to model weights.

Common mistakes

  • Setting jit_compile=True does not guarantee XLA compilation when no GPU is available.
  • Enabling use_ema changes weight handling by maintaining an exponential moving average and periodically replacing model weights with that average.

Example: Compile a model with Nadam

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.

When to use it

General neural-network training

A model needs an adaptive optimizer with momentum behavior that can improve parameter updates.

Gradient clipping and weight decay

Training requires explicit control over gradient magnitudes or regularization.

Exponential moving averages

A workflow benefits from smoothed model weights during training.

Compiled training

The runtime supports XLA and training performance may benefit from compilation.

Interview questions

QWhat is Nadam, and what are its main defaults?

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.

QWhich forms can learning_rate and the beta parameters take?

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.

QWhich additional training controls does Nadam provide?

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.Adam
  • keras.optimizers.RMSprop
  • keras.optimizers.Optimizer
  • keras.optimizers.AdamW

Source: Nadam. Checked 2026-10-15.