MLCrack

    DEEP LEARNING · INTERVIEW QUESTION

    Explain batch normalization. Why does it help training?

    🟡 intermediate · CNNs

    Hint: Think about internal covariate shift, the learnable parameters γ and β, and train vs inference behavior.

    Answer

    Batch Normalization normalizes activations to zero mean and unit variance within each mini-batch, then applies learnable scale (γ\gamma) and shift (β\beta).

    x^i=xi−μBσB2+ϵ,yi=γx^i+β\hat{x}_i = \frac{x_i - \mu_B}{\sqrt{\sigma_B^2 + \epsilon}}, \quad y_i = \gamma \hat{x}_i + \beta

    Benefits

    • Original motivation: internal covariate shift — this is not an established complete explanation of its benefits
    • Allows higher learning rates — faster training
    • Acts as regularization — noise from batch statistics
    • Smooths the loss landscape — easier optimization

    Training vs Inference

    PhaseStatistics Used
    TrainingBatch mean/variance
    InferenceRunning averages

    Normalization Variants

    MethodNormalizes AcrossBest For
    BatchNormBatch dimensionCNNs (batch ≥ 16)
    LayerNormFeature dimensionTransformers, RNNs
    GroupNormChannel groupsSmall batch sizes
    InstanceNormSingle sampleStyle transfer

    Key limitation: Training needs more than one value per channel to estimate useful batch statistics. BatchNorm2d can still work at batch size 1 when spatial positions provide multiple values; inference can use stored running statistics. Use LayerNorm (preferred in Transformers) or GroupNorm instead.