← Microsoft Interview Insights
I knew this one but still fumbled the train vs inference part for BatchNorm.
Start by defining both normalization techniques and explicitly stating the dimensions they normalize over. Then contrast their behavior at training and inference time, emphasizing batch size dependence, and finish with practical guidance on when to choose each.
Pro tip: Mention that LayerNorm is standard in Transformers and RNNs while BatchNorm is common in CNNs, and note that BatchNorm's running statistics can cause train-test discrepancy—this shows depth beyond textbook definitions.
Explain that BatchNorm normalizes over the batch dimension (N) for each feature/channel independently, while LayerNorm normalizes over the feature dimension (C, H, W) for each sample independently.
Detail that BatchNorm uses batch statistics during training and running averages during inference, whereas LayerNorm uses the same per-sample statistics at both times.
Highlight that BatchNorm's performance degrades with small batch sizes and is unsuitable for online learning, while LayerNorm is batch-size independent and works well with any batch size.
Recommend BatchNorm for CNNs with large batches, and LayerNorm for RNNs, Transformers, and scenarios with small or variable batch sizes.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.