Complete the code to create an exponential decay learning rate schedule.
lr_schedule = tf.keras.optimizers.schedules.ExponentialDecay(initial_learning_rate=0.1, decay_steps=100000, decay_rate=[1], staircase=True)
The decay_rate parameter controls how much the learning rate decreases at each decay step. A value less than 1 (like 0.96) means the learning rate will decay exponentially.
Complete the code to apply the learning rate schedule to the Adam optimizer.
optimizer = tf.keras.optimizers.Adam(learning_rate=[1])The learning_rate argument can accept a schedule object like lr_schedule to adjust the learning rate during training.
Fix the error in the code to correctly create a piecewise constant learning rate schedule.
boundaries = [10000, 20000] values = [0.1, 0.01, [1]] lr_schedule = tf.keras.optimizers.schedules.PiecewiseConstantDecay(boundaries, values)
The values list must have one more element than the boundaries list. The last value is the learning rate after the last boundary.
Fill both blanks to create a cosine decay learning rate schedule with restarts.
lr_schedule = tf.keras.experimental.CosineDecayRestarts(initial_learning_rate=[1], first_decay_steps=[2])
The initial_learning_rate is typically a small value like 0.1, and first_decay_steps controls how many steps before the first restart, often set to 1000.
Fill all three blanks to create a learning rate schedule that warms up linearly then decays exponentially.
def lr_warmup_decay(step): warmup_steps = [1] if step < warmup_steps: return [2] * step / warmup_steps else: return [3] * tf.math.exp(-0.1 * (step - warmup_steps))
The warmup_steps is set to 1000 steps. The learning rate warms up linearly from 0 to 0.1, then decays exponentially starting from 0.001.