Learning Rate, Epochs, Batches

(लर्निंग रेट, एपॉक्स, और बैचेस)


🔶 1. Learning Rate (सीखने की रफ़्तार)

📌 Definition:

Learning Rate (η) एक hyperparameter है जो यह नियंत्रित करता है कि training के दौरान weights कितनी तेज़ी से update हों।

यह Gradient Descent के update rule का हिस्सा होता है:


🎯 Learning Rate की भूमिका:

ValueEffect
बहुत छोटा (<0.0001)Slow learning, stuck in local minima
बहुत बड़ा (>1.0)Overshooting, unstable training
सही मध्यमSmooth convergence to minimum loss

📈 Visual Explanation:

  • Low LR: धीरे-धीरे valley में पहुंचता है
  • High LR: आगे-पीछे कूदता रहता है, valley मिस कर देता है
  • Ideal LR: सीधे valley में पहुँचता है

📘 PyTorch में Learning Rate:

optimizer = torch.optim.SGD(model.parameters(), lr=0.01)

🔶 2. Epochs (Training Iterations over Dataset)

📌 Definition:

Epoch एक cycle होती है जिसमें पूरा training dataset once neural network में pass किया जाता है — forward + backward pass दोनों।

अगर आपके पास 1000 images हैं और आपने 10 epochs चलाए, तो model ने dataset को 10 बार देखा।


🎯 अधिक Epochs का मतलब:

  • Model को सीखने का ज्यादा मौका मिलता है
  • लेकिन overfitting का खतरा बढ़ता है

🔶 3. Batches और Batch Size

📌 Batch:

Dataset को छोटे-छोटे टुकड़ों (chunks) में divide करके training करना batch training कहलाता है।

हर batch पर forward और backward pass किया जाता है।

  • Batch Size: कितने samples एक साथ process होंगे
  • Common sizes: 8, 16, 32, 64, 128

🎯 Why Use Batches?

AdvantageExplanation
Memory Efficientपूरा dataset memory में लोड करने की ज़रूरत नहीं
Faster ComputationGPU पर vectorized तरीके से काम होता है
Noise helps generalizationStochastic updates model को overfitting से बचाते हैं

🔁 Relationship Between All Three:

ConceptDefinition
EpochOne full pass over the entire dataset
Batch SizeNumber of samples processed at once
IterationOne update step = One batch

Example:

  • Dataset size = 1000
  • Batch size = 100
  • Then, 1 epoch = 10 iterations
  • If we train for 10 epochs → total 100 iterations

🔧 PyTorch Code:

from torch.utils.data import DataLoader, TensorDataset
import torch

# Dummy data
X = torch.randn(1000, 10)
y = torch.randint(0, 2, (1000, 1)).float()
dataset = TensorDataset(X, y)

# DataLoader with batch size
dataloader = DataLoader(dataset, batch_size=64, shuffle=True)

# Training loop
for epoch in range(5): # 5 epochs
for batch_x, batch_y in dataloader:
# Forward pass, loss calculation, backward, step
...

📝 Summary Table:

TermMeaningTypical Value
Learning RateStep size for weight updates0.001 – 0.01
EpochOne full pass over dataset10 – 100
Batch SizeSamples per update32, 64, 128
IterationOne weight update stepdataset_size / batch_size

🎯 Objectives Recap:

  • Learning Rate = Weights कितना move करें
  • Epoch = Dataset कितनी बार pass हो
  • Batch Size = एक बार में कितने samples process हों
  • इन तीनों का tuning model performance के लिए critical है

📝 Practice Questions:

  1. Learning Rate क्या होता है और इसका काम क्या है?
  2. Batch Size और Iteration में क्या संबंध है?
  3. Overfitting का खतरा किस स्थिति में अधिक होता है: कम epochs या ज़्यादा epochs?
  4. PyTorch में DataLoader का क्या काम है?
  5. Batch training क्यों करना ज़रूरी होता है?