Skip to content
Feb 27

Weight Initialization and Batch Normalization

MT
Mindli Team

AI-Generated Content

Weight Initialization and Batch Normalization

A neural network's success hinges not just on its architecture but on its ability to learn efficiently from the start. Poor initial conditions can doom training before it truly begins, leading to painfully slow convergence or complete failure. Two foundational techniques—weight initialization and batch normalization—work in concert to ensure stable signal propagation, accelerate training, and enable the use of higher learning rates, forming the bedrock of modern deep learning.

The Problem of Unstable Activations and Gradients

Before diving into solutions, you must understand the core problem. In a deep network, the output of one layer becomes the input to the next. If the weights (the parameters being learned) are initialized poorly, the signals passing through the network can vanish or explode exponentially with depth. This is known as the vanishing/exploding gradients problem. During backpropagation, gradients are calculated using the chain rule. If the activations are too small, the gradients shrink to zero, and weights stop updating. If they are too large, gradients become enormous, causing unstable updates that overflow numerically. The goal of intelligent initialization is to preserve the variance of activations and gradients as they flow through the network, keeping them within a manageable range.

Foundational Weight Initialization Schemes

Random initialization is necessary to break symmetry, but the scale of the randomness is critical. The two most important schemes are designed to maintain variance across layers.

Xavier/Glorot Initialization is designed for layers using sigmoid or tanh activation functions. Its core principle is to initialize weights from a distribution with a variance that is inversely proportional to the average of the number of input and output connections (fan-in and fan-out). For a layer with inputs and outputs, weights are drawn from a uniform distribution with limits or a normal distribution with mean 0 and variance . This scaling ensures that the variance of the layer's inputs is roughly equal to the variance of its outputs, preventing signal decay or blowup in the forward pass and helping stabilize backpropagation.

He Initialization (or Kaiming initialization) was developed for networks using Rectified Linear Units (ReLUs) and its variants (Leaky ReLU, etc.). The ReLU activation zeros out negative inputs, which effectively halves the variance of its output compared to a symmetric activation like tanh. To compensate for this, He initialization uses a larger variance. For a layer with inputs, weights are drawn from a normal distribution with mean 0 and variance , or a uniform distribution with limits . This adjustment ensures that the variance of the post-activation signals is preserved layer-by-layer, enabling the successful training of very deep networks with ReLUs.

Batch Normalization: Stabilizing Intermediate Activations

While smart initialization sets a good starting point, the distribution of layer inputs can shift during training—a problem known as internal covariate shift. Batch Normalization (BatchNorm) tackles this by actively normalizing the outputs of a layer during training. For a mini-batch of activations, BatchNorm applies a simple two-step process: it subtracts the batch mean and divides by the batch standard deviation, then applies a learned scale and shift.

Here, and are the mean and variance of the mini-batch, is a tiny constant for numerical stability, and and are learnable parameters. This normalization ensures that the input to the next layer has a stable, zero-mean, unit-variance distribution (which is then modulated by and ). The effects are profound: it dramatically reduces the sensitivity to poor initialization, allows for significantly higher learning rates by smoothing the optimization landscape, and acts as a mild regularizer due to the noise introduced by mini-batch statistics.

Layer Normalization and Its Domain

Batch Normalization relies on statistics computed across the batch dimension. This becomes problematic with small batch sizes (where statistics are noisy) or in sequence models like RNNs/Transformers (where batch sizes may vary and sequences have different lengths). Layer Normalization was developed as an alternative. Instead of normalizing across the batch for each feature, it normalizes across all features for each individual data point in the batch. It computes the mean and variance from the summed inputs to the neurons within a layer for a single training case. This makes it independent of the batch size and perfectly suited for recurrent networks and the transformer architectures that underpin modern large language models, where it stabilizes the hidden state dynamics over long sequences.

The Combined Effect on Training Dynamics

Initialization and normalization are not mutually exclusive; they are complementary techniques used in tandem. Proper initialization like He gives the network a stable starting point. BatchNorm then takes over during training to maintain this stability, continuously correcting for internal covariate shift. This symbiotic relationship is why you can train deep models today. Crucially, by stabilizing the gradients and activations, these techniques allow you to use higher learning rates. A higher learning rate means larger weight updates per step, which leads to faster convergence. Without BatchNorm, a high learning rate would often cause training to diverge due to unstable gradient magnitudes. With it, the training process becomes more robust and efficient, reducing the time and computational cost required to train state-of-the-art models.

Common Pitfalls

  1. Misapplying Initialization Schemes: Using Xavier initialization with ReLU layers, or He initialization with tanh layers, will lead to suboptimal signal propagation. Always match your initialization scheme to your activation function: Xavier/Glorot for tanh/sigmoid, He for ReLU and its variants.
  2. Forgetting BatchNorm's Behavior at Inference: During training, BatchNorm uses mini-batch statistics. During inference, it uses a fixed, running average of statistics collected during training. A common mistake is to not set the model to evaluation mode (model.eval() in PyTorch) before inference, which continues to use batch statistics and leads to inconsistent, often degraded, performance.
  3. Using BatchNorm with Very Small Batch Sizes: When the batch size is tiny (e.g., 1 or 2), the batch mean and variance become extremely noisy estimates of the dataset statistics. This noise can destabilize training rather than help it. In such cases, consider alternatives like Layer Normalization, Group Normalization, or simply increasing the batch size if possible.
  4. Over-reliance on Normalization for Poor Initialization: While BatchNorm is remarkably robust, it is not a magic bullet for arbitrarily bad initialization. Starting with wildly large weights can still cause numerical instability in the first forward pass before BatchNorm can act. Always use a sensible initialization scheme as your first line of defense.

Summary

  • Intelligent weight initialization (Xavier for tanh/sigmoid, He for ReLU) is essential to set the correct scale of initial weights, preventing the vanishing or exploding of signals and gradients at the start of training.
  • Batch Normalization stabilizes training by normalizing layer inputs using mini-batch statistics, reducing internal covariate shift, acting as a regularizer, and most importantly, enabling the use of higher learning rates for faster convergence.
  • Layer Normalization is a variant that normalizes across features instead of the batch dimension, making it the preferred choice for sequence models (RNNs, Transformers) and scenarios with very small or variable batch sizes.
  • These techniques work together: proper initialization provides a stable launch, and normalization maintains stability throughout the training flight, fundamentally improving the training dynamics of deep neural networks.

Write better notes with AI

Mindli helps you capture, organize, and master any subject with AI-powered summaries and flashcards.