BatchNorm, LayerNorm, dropout and weight decay
What it is
Normalization controls activation scale and can make optimisation much less sensitive to the changing distributions produced by earlier layers. BatchNorm normalizes each feature channel using batch statistics and maintains running statistics for inference, which suits many CNNs; LayerNorm normalizes across features within each example, so its behaviour does not depend on the other examples in a batch and is standard in Transformers. Dropout randomly removes activations during training to discourage co-adaptation, while weight decay continuously penalises large weights. These techniques solve different problems and can coexist, but none repairs bad labels or leakage.
Why it matters
These techniques alter optimisation and generalisation in different ways. Knowing which is doing what prevents 'regularisation' from becoming a bag of rituals. In particular, small or uneven batches can make BatchNorm statistics noisy, while LayerNorm has no running-batch state; the architecture and batch regime should guide the choice.
In the real world: Standard tools that make models train faster and generalise better to new customers' data.
Visual example
Deep learningDropout changes behaviour by mode; normalization uses stable statistics at evaluation.
import torch
import torch.nn as nn
block = nn.Sequential(
nn.Linear(256, 512, bias=False), # bias is redundant before BatchNorm
nn.BatchNorm1d(512), # optimisation: stabilise the scale
nn.ReLU(),
nn.Dropout(0.2), # generalisation: break co-adaptation
)
optimizer = torch.optim.AdamW(block.parameters(), lr=3e-4, weight_decay=0.01)Leaving dropout active at inference. It intentionally makes predictions stochastic during training and must be disabled with model.eval() for normal evaluation and serving.