🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEtensorflow

tensorflow Documentation

LOADING ENGINE...

optimizers.RMSprop()

AI & DATA SCIENCE // optimizers-rmsprop

tf.keras.optimizers.RMSprop() is an adaptive optimizer that divides each parameter's learning rate by a running average of the magnitude of its recent gradients, helping stabilize training on noisy or non-stationary problems.

Syntax

tf.keras.optimizers.RMSprop(learning_rate=0.001)

Deep Dive Course

RMSprop, Root Mean Square Propagation, maintains a running average of the squared gradient for each parameter individually, and divides that parameter's update by the square root of this average — effectively giving parameters with consistently large gradients smaller effective steps, and parameters with small gradients comparatively larger ones, similar in spirit to Adam but without Adam's additional momentum-like first-moment tracking. It was originally designed to work well on recurrent neural networks and other settings with noisy, rapidly-changing gradients, and remains a solid, still commonly used alternative to Adam.

1Understanding optimizers.RMSprop()

RMSprop, Root Mean Square Propagation, maintains a running average of the squared gradient for each parameter individually, and divides that parameter's update by the square root of this average — effectively giving parameters with consistently large gradients smaller effective steps, and parameters with small gradients comparatively larger ones, similar in spirit to Adam but without Adam's additional momentum-like first-moment tracking. It was originally designed to work well on recurrent neural networks and other settings with noisy, rapidly-changing gradients, and remains a solid, still commonly used alternative to Adam.

💡

RMSprop is a reasonable alternative to try if Adam's training curves look unusually unstable on a particular model — the two are closely related, both dividing each parameter's step by an estimate of its recent gradient magnitude, but RMSprop lacks Adam's extra momentum-like term.

editor.html
import tensorflow as tf

optimizer = tf.keras.optimizers.RMSprop(learning_rate=0.001)
print(optimizer.learning_rate.numpy())
localhost:3000

2Practical Example

Here is a real-world application of optimizers.RMSprop() showing how it is used in production TensorFlow code.

editor.html
import tensorflow as tf
from tensorflow.keras import layers, Sequential

model = Sequential([layers.Dense(1, input_shape=(1,))])
model.compile(optimizer=tf.keras.optimizers.RMSprop(learning_rate=0.0005), loss='mse')
print(model.optimizer.learning_rate.numpy())
localhost:3000

3Best Practices

Follow these guidelines when working with optimizers.RMSprop():

1. Try RMSprop as an alternative when a model trained with Adam shows unusually unstable or oscillating loss curves

2. Keep RMSprop's default learning rate of 0.001 as a reasonable starting point, similar to Adam's default

3. Recognize that RMSprop and Adam are closely related, both scaling each parameter's step by a running average of squared gradients, which is why switching between the two rarely dramatically changes results on typical models

⚠️

Tip: RMSprop is a reasonable alternative to try if Adam's training curves look unusually unstable on a particular model — the two are closely related, both dividing each parameter's step by an estimate of its recent gradient magnitude, but RMSprop lacks Adam's extra momentum-like term.

editor.html
import tensorflow as tf

optimizer = tf.keras.optimizers.RMSprop(learning_rate=0.001)
print(optimizer.learning_rate.numpy())
localhost:3000

Examples

Example 01Basic Usage
import tensorflow as tf

optimizer = tf.keras.optimizers.RMSprop(learning_rate=0.001)
print(optimizer.learning_rate.numpy())
Example 02Advanced Example
import tensorflow as tf
from tensorflow.keras import layers, Sequential

model = Sequential([layers.Dense(1, input_shape=(1,))])
model.compile(optimizer=tf.keras.optimizers.RMSprop(learning_rate=0.0005), loss='mse')
print(model.optimizer.learning_rate.numpy())

Best Practices

  • Try RMSprop as an alternative when a model trained with Adam shows unusually unstable or oscillating loss curves
  • Keep RMSprop's default learning rate of 0.001 as a reasonable starting point, similar to Adam's default
  • Recognize that RMSprop and Adam are closely related, both scaling each parameter's step by a running average of squared gradients, which is why switching between the two rarely dramatically changes results on typical models

Interview Question

What key mechanism do RMSprop and Adam share, and what does Adam add on top of it?

Hint: Think about what each optimizer tracks about the second moment, the squared gradient, and whether either also tracks something about the first moment, the gradient's direction.

Both RMSprop and Adam maintain a running average of the squared gradient for every parameter individually, and both use that running average to scale down each parameter's effective step size in proportion to how large that parameter's recent gradients have tended to be — this shared mechanism is what gives both optimizers their adaptive, per-parameter learning rate behavior. Adam adds an additional running average of the raw gradient itself, not squared, which functions similarly to classical momentum, accumulating a sense of consistent directional movement across steps. This means Adam combines RMSprop's adaptive per-parameter scaling with a momentum-like smoothing of the update direction, while RMSprop on its own only provides the adaptive scaling without that extra directional smoothing.

Exercises

MediumPractice using optimizers.RMSprop() in a real scenario.
View Solution
import tensorflow as tf

optimizer = tf.keras.optimizers.RMSprop(learning_rate=0.001)
print(optimizer.learning_rate.numpy())

Frequently Asked Questions

What key mechanism do RMSprop and Adam share, and what does Adam add on top of it?

Both RMSprop and Adam maintain a running average of the squared gradient for every parameter individually, and both use that running average to scale down each parameter's effective step size in proportion to how large that parameter's recent gradients have tended to be — this shared mechanism is what gives both optimizers their adaptive, per-parameter learning rate behavior. Adam adds an additional running average of the raw gradient itself, not squared, which functions similarly to classical momentum, accumulating a sense of consistent directional movement across steps. This means Adam combines RMSprop's adaptive per-parameter scaling with a momentum-like smoothing of the update direction, while RMSprop on its own only provides the adaptive scaling without that extra directional smoothing.

Related Functions

optimizers-adamoptimizers-sgdmodel-compile