WikiGalaxy

Personalize

Learning Rate Scheduling

Learning rate scheduling is a technique used in deep learning to adjust the learning rate during training. It helps in improving convergence and achieving better model performance.

  • Adaptive Learning Rate
  • Step Decay
  • Exponential Decay
  • Cosine Annealing
  • Cyclical Learning Rates

Adaptive Learning Rate

Adaptive learning rate methods adjust the learning rate based on the characteristics of the data and the model's performance. They include algorithms like AdaGrad, RMSprop, and Adam.


# Example: Using Adam Optimizer with Adaptive Learning Rate
from keras.optimizers import Adam

model.compile(optimizer=Adam(learning_rate=0.001), loss='categorical_crossentropy', metrics=['accuracy'])

Adam optimizer is commonly used because it combines the advantages of two other extensions of stochastic gradient descent, AdaGrad and RMSprop.

Step Decay

Step decay reduces the learning rate by a factor at specified intervals. This is useful for fine-tuning the model as it approaches convergence.


# Example: Step Decay Implementation
def step_decay(epoch):
    initial_lr = 0.1
    drop = 0.5
    epochs_drop = 10.0
    lr = initial_lr * math.pow(drop, math.floor((1+epoch)/epochs_drop))
    return lr

In step decay, the learning rate is reduced by half every 10 epochs, which helps in stabilizing the training process.

Exponential Decay

Exponential decay decreases the learning rate exponentially over time. This approach is effective when the model needs to quickly adapt to the data initially and then converge smoothly.


# Example: Exponential Decay in TensorFlow
learning_rate = tf.train.exponential_decay(initial_learning_rate, global_step, decay_steps, decay_rate, staircase=True)

Exponential decay is beneficial for models that require rapid learning in the initial stages followed by a slower convergence.

Cosine Annealing

Cosine annealing adjusts the learning rate following a cosine curve, which allows for periodic reductions and increases in the learning rate.


# Example: Cosine Annealing Scheduler
import torch.optim as optim
scheduler = optim.lr_scheduler.CosineAnnealingLR(optimizer, T_max=50)

Cosine annealing is particularly useful in scenarios where the model needs to escape local minima and explore new regions of the parameter space.

Cyclical Learning Rates

Cyclical learning rates involve oscillating the learning rate between a minimum and maximum value, which can help in finding better solutions in the loss landscape.


# Example: Implementing Cyclical Learning Rates
from keras.callbacks import CyclicLR

clr = CyclicLR(base_lr=0.001, max_lr=0.006, step_size=2000., mode='triangular')
model.fit(X_train, Y_train, callbacks=[clr])

Cyclical learning rates allow the model to converge faster and potentially achieve better accuracy by avoiding local minima.

logo of wikigalaxy

Newsletter

Subscribe to our newsletter for weekly updates and promotions.

Privacy Policy

 • 

Terms of Service

Copyright © WikiGalaxy 2025