Skip to main content
Botmartz AI Solution PVT LTD.
Home›Engineering Insights›OPTIMIZATION
OPTIMIZATION

Batch Normalization and Layer Normalization: Reducing Internal Covariate Shift

Batch norm normalizes activations during training, reducing internal covariate shift. Layer norm is the alternative for RNNs and Transformers. Understand when each applies.

SS
Soham Sharma
AI Engineer, Botmartz · July 17, 2026 · 1 min read
Read Time
1 min
Failure Modes
5
Code Snippets
3
Runnable Notebook
1
Batch Normalization and Layer Normalization: Reducing Internal Covariate Shift

Batch normalization normalizes layer inputs to zero mean/unit variance, stabilizing training and enabling higher learning rates. Layer normalization normalizes across features (instead of batch), solving the batch-size dependency problem. Understanding their trade-offs guides architecture design.

Batch Normalization

Code Snippet
# During training: normalize by batch statistics
# During inference: normalize by running statistics (computed during training)

class BatchNormModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.fc1 = nn.Linear(100, 64)
        self.bn1 = nn.BatchNorm1d(64)  # Normalize across batch dimension
        self.fc2 = nn.Linear(64, 10)
    
    def forward(self, x):
        x = self.fc1(x)
        x = self.bn1(x)  # Normalize
        x = F.relu(x)
        x = self.fc2(x)
        return x

Batch norm reduces internal covariate shift, enabling faster training.

Layer Normalization

Code Snippet
# Normalize across features (not batch)
class LayerNormModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.fc1 = nn.Linear(100, 64)
        self.ln1 = nn.LayerNorm(64)  # Normalize across feature dimension
        self.fc2 = nn.Linear(64, 10)
    
    def forward(self, x):
        x = self.fc1(x)
        x = self.ln1(x)  # Normalize
        x = F.relu(x)
        x = self.fc2(x)
        return x

Layer norm doesn't depend on batch size, making it ideal for Transformers and variable-length sequences.

Conclusion

Batch norm and layer norm both stabilize training but have different properties. Batch norm is standard for CNNs; layer norm is standard for Transformers. Understanding when to use each informs architecture choices. Next: weight initialization and their effects on training.

Closing Takeaways

✓
Measure retrieval precision and recall in isolation before touching the model.
✓
Chunk along document structure, not arbitrary character counts.
✓
Combine vector and keyword search — hybrid retrieval beats either alone.
✓
Treat evaluation as continuous infrastructure, not a launch-week report.
Try It Yourself
A runnable Google Colab notebook with the eval harness and hybrid search code from this post.
#Normalization#Batch Norm#Layer Norm#Training Stability
0 views
SS
Soham Sharma
AI Engineer at Botmartz, building enterprise RAG and agent systems in production. Contributing to open-source libraries.

Discussion (0)

No approved comments yet. Be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *

More Engineering Insights
AI AGENTS
9 min read
AI AGENTS
11 min read
OPEN SOURCE
6 min read
AI ENGINEERING
8 min read
CASE STUDIES
14 min read