learning_rate and epochs are two training hyperparameters that control how a model learns from data.
Learning rate controls the step size used when updating model weights during gradient descent. After computing the gradient of the loss, the optimizer moves the weights in the opposite direction by:
new_weight = old_weight - learning_rate * gradient
A high learning rate, such as 0.1, makes training faster but can overshoot the minimum, causing unstable loss or NaN values. A very low rate, such as 0.00001, makes training stable but can be too slow or get stuck in poor local minima.
Common starting points are 0.001 for Adam and 0.01 for SGD, often with a learning rate scheduler that reduces the rate over time.
Epochs refers to the number of complete passes through the entire training dataset. If you have 10,000 training samples and a batch size of 32, one epoch contains ceil(10000 / 32) = 313 weight updates. With epochs=20, the model performs 20 * 313 = 6260 updates.
Too few epochs can cause underfitting because the model has not seen the data enough times to learn patterns. Too many epochs can cause overfitting, where the model memorizes training examples and performs worse on unseen data. A practical approach is to monitor validation loss and stop training when it stops improving, often called early stopping.
For example, a typical small CNN might start with learning_rate=0.001 and use epochs=50, but the best epoch count depends on dataset size, model complexity, and batch size. In practice, tune the learning rate first, then choose epochs using validation performance rather than fixing an arbitrary large number.