Bird
Raised Fist0
TensorFlowml~20 mins

Learning rate scheduling in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Learning Rate Scheduling Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the main purpose of learning rate scheduling in training neural networks?

Why do we use learning rate scheduling when training a neural network?

ATo gradually reduce the learning rate to help the model converge better and avoid overshooting minima.
BTo increase the learning rate over time to speed up training indefinitely.
CTo keep the learning rate constant throughout training for stable updates.
DTo randomly change the learning rate each epoch to add noise and prevent overfitting.
Attempts:
2 left
💡 Hint

Think about how changing the learning rate affects the model's ability to find the best solution.

❓ Predict Output
intermediate
2:00remaining
Output of learning rate after 5 epochs with ExponentialDecay

Given this TensorFlow learning rate schedule, what is the learning rate at epoch 5?

TensorFlow
import tensorflow as tf
initial_lr = 0.1
lr_schedule = tf.keras.optimizers.schedules.ExponentialDecay(
    initial_learning_rate=initial_lr,
    decay_steps=2,
    decay_rate=0.5,
    staircase=True
)
learning_rate_epoch_5 = lr_schedule(5).numpy()
print(round(learning_rate_epoch_5, 4))
A0.1
B0.0125
C0.05
D0.025
Attempts:
2 left
💡 Hint

Remember that with staircase=True, the learning rate changes only at multiples of decay_steps.

❓ Model Choice
advanced
2:00remaining
Which learning rate schedule is best for training a model that needs slow fine-tuning after initial fast learning?

You want a learning rate schedule that starts high and then slowly decreases to fine-tune the model. Which schedule fits best?

ACosine annealing schedule that gradually reduces learning rate following a cosine curve.
BConstant learning rate with no changes during training.
CStep decay schedule that drops learning rate sharply at fixed intervals.
DRandom learning rate changes each epoch.
Attempts:
2 left
💡 Hint

Think about smooth gradual decrease versus sudden drops.

❓ Hyperparameter
advanced
2:00remaining
Effect of increasing decay_steps in ExponentialDecay schedule

In TensorFlow's ExponentialDecay schedule, what happens if you increase the decay_steps parameter while keeping others constant?

AThe learning rate decays faster over time.
BThe learning rate decays more slowly over time.
CThe learning rate stays constant and does not decay.
DThe learning rate increases over time.
Attempts:
2 left
💡 Hint

Think about how often the decay happens with bigger decay_steps.

❓ Metrics
expert
2:00remaining
How does learning rate scheduling affect training loss and accuracy curves?

When using a learning rate schedule that reduces the learning rate over epochs, what typical pattern do you expect to see in training loss and accuracy graphs?

ATraining loss increases and accuracy decreases as learning rate lowers.
BTraining loss and accuracy fluctuate wildly with no clear trend.
CTraining loss decreases smoothly and accuracy increases steadily, with smaller improvements as learning rate lowers.
DTraining loss and accuracy remain constant throughout training.
Attempts:
2 left
💡 Hint

Consider how smaller learning rates affect model updates and convergence.

Practice

(1/5)
1. What is the main purpose of learning rate scheduling in TensorFlow training?
easy
A. To adjust the learning speed during training for better results
B. To increase the batch size automatically
C. To change the model architecture dynamically
D. To stop training early when accuracy is high

Solution

  1. Step 1: Understand learning rate scheduling concept

    Learning rate scheduling changes how fast the model learns by adjusting the learning rate during training.
  2. Step 2: Identify the main goal

    The goal is to help the model learn better and reach higher accuracy by controlling the learning speed.
  3. Final Answer:

    To adjust the learning speed during training for better results -> Option A
  4. Quick Check:

    Learning rate scheduling = adjust learning speed [OK]
Hint: Learning rate scheduling controls training speed [OK]
Common Mistakes:
  • Confusing learning rate scheduling with batch size changes
  • Thinking it changes model structure
  • Assuming it stops training early
2. Which of the following is the correct way to create an exponential decay learning rate schedule in TensorFlow?
easy
A. tf.keras.optimizers.schedules.ExponentialDecay(initial_learning_rate=0.1, decay_steps=1000, decay_rate=0.96)
B. tf.keras.optimizers.ExponentialDecay(learning_rate=0.1, steps=1000, rate=0.96)
C. tf.keras.schedules.ExponentialDecay(learning_rate=0.1, decay_steps=1000, decay_rate=0.96)
D. tf.optimizers.schedules.ExponentialDecay(initial_lr=0.1, decay_steps=1000, decay_rate=0.96)

Solution

  1. Step 1: Recall TensorFlow API for exponential decay

    The correct class is tf.keras.optimizers.schedules.ExponentialDecay with parameters initial_learning_rate, decay_steps, and decay_rate.
  2. Step 2: Match parameters and class name

    tf.keras.optimizers.schedules.ExponentialDecay(initial_learning_rate=0.1, decay_steps=1000, decay_rate=0.96) matches the correct class and parameter names exactly.
  3. Final Answer:

    tf.keras.optimizers.schedules.ExponentialDecay(initial_learning_rate=0.1, decay_steps=1000, decay_rate=0.96) -> Option A
  4. Quick Check:

    Correct class and parameters = tf.keras.optimizers.schedules.ExponentialDecay(initial_learning_rate=0.1, decay_steps=1000, decay_rate=0.96) [OK]
Hint: Use tf.keras.optimizers.schedules for learning rate schedules [OK]
Common Mistakes:
  • Using wrong module like tf.keras.optimizers directly
  • Incorrect parameter names like learning_rate instead of initial_learning_rate
  • Misspelling class or method names
3. What will be the learning rate after 2000 steps if you use this schedule?
schedule = tf.keras.optimizers.schedules.ExponentialDecay(
    initial_learning_rate=0.1,
    decay_steps=1000,
    decay_rate=0.5)
learning_rate = schedule(2000).numpy()
medium
A. 0.05
B. 0.01
C. 0.1
D. 0.025

Solution

  1. Step 1: Understand exponential decay formula

    Learning rate = initial_learning_rate * decay_rate^(step / decay_steps). Here, step=2000, decay_steps=1000, decay_rate=0.5.
  2. Step 2: Calculate learning rate at step 2000

    Calculate exponent: 2000 / 1000 = 2.
    Learning rate = 0.1 * (0.5)^2 = 0.1 * 0.25 = 0.025.
  3. Final Answer:

    0.025 -> Option D
  4. Quick Check:

    0.1 * 0.5^2 = 0.025 [OK]
Hint: Apply formula: lr = initial_lr * decay_rate^(step/decay_steps) [OK]
Common Mistakes:
  • Forgetting to divide step by decay_steps
  • Using decay_rate power step instead of step/decay_steps
  • Mixing up decay_rate and initial_learning_rate
4. Identify the error in this TensorFlow learning rate schedule code:
schedule = tf.keras.optimizers.schedules.ExponentialDecay(
    initial_learning_rate=0.01,
    decay_steps=500,
    decay_rate=0.9)
optimizer = tf.keras.optimizers.Adam(learning_rate=schedule())
medium
A. Adam optimizer does not accept learning rate schedules
B. schedule() is called without step argument, causing an error
C. Decay rate 0.9 is too high and causes slow decay
D. initial_learning_rate should be set in optimizer, not schedule

Solution

  1. Step 1: Check how schedule is used

    ExponentialDecay expects a step argument to compute learning rate. Calling schedule() without arguments causes an error.
  2. Step 2: Verify optimizer learning rate parameter

    Optimizer accepts schedule object directly, not schedule() call. Passing schedule() calls the function immediately without step.
  3. Final Answer:

    schedule() is called without step argument, causing an error -> Option B
  4. Quick Check:

    Call schedule without step causes error [OK]
Hint: Pass schedule object, don't call it with () in optimizer [OK]
Common Mistakes:
  • Calling schedule() instead of passing schedule object
  • Thinking decay_rate value causes error
  • Believing Adam can't use schedules
5. You want to train a model where the learning rate starts at 0.1, halves every 1000 steps, but never goes below 0.01. Which TensorFlow schedule setup achieves this?
hard
A. Use CosineDecay with initial_learning_rate=0.1 and alpha=0.01 to set minimum learning rate
B. Use ExponentialDecay with initial_learning_rate=0.1, decay_steps=1000, decay_rate=0.5 and then apply tf.keras.optimizers.schedules.PiecewiseConstantDecay with boundaries=[1000] and values=[0.1, 0.01]
C. Use ExponentialDecay with initial_learning_rate=0.1, decay_steps=1000, decay_rate=0.5 and then use tf.keras.optimizers.schedules.LearningRateSchedule subclass to clip minimum at 0.01
D. Use ExponentialDecay with initial_learning_rate=0.1, decay_steps=1000, decay_rate=0.5 and wrap it with tf.keras.optimizers.schedules.LearningRateSchedule to clip minimum at 0.01

Solution

  1. Step 1: Understand the requirement

    Learning rate halves every 1000 steps: ExponentialDecay(initial_learning_rate=0.1, decay_steps=1000, decay_rate=0.5), but never below 0.01 (needs clipping).
  2. Step 2: Evaluate schedules

    ExponentialDecay provides exact halving at multiples of decay_steps but lacks built-in minimum. Custom clipping needed.
  3. Step 3: Identify correct approach

    Use ExponentialDecay with initial_learning_rate=0.1, decay_steps=1000, decay_rate=0.5 and then use tf.keras.optimizers.schedules.LearningRateSchedule subclass to clip minimum at 0.01 subclasses LearningRateSchedule to wrap ExponentialDecay and clip with tf.maximum(..., 0.01).
  4. Final Answer:

    Use ExponentialDecay with initial_learning_rate=0.1, decay_steps=1000, decay_rate=0.5 and then use tf.keras.optimizers.schedules.LearningRateSchedule subclass to clip minimum at 0.01 -> Option C
  5. Quick Check:

    ExponentialDecay + subclass clip = halving with floor [OK]
Hint: Subclass LearningRateSchedule to clip ExponentialDecay minimum [OK]
Common Mistakes:
  • Using CosineDecay which does smooth decay, not discrete halving every 1000 steps
  • Using PiecewiseConstantDecay incorrectly for continuous exponential decay
  • Attempting to wrap without proper subclassing
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard