What is weight initialization in neural networks?
Weight initialization is the choice of starting values for a neural network's weights before training begins. Good schemes draw small random values with a variance scaled to each layer's size, so that activations and gradients keep a stable magnitude from layer to layer. Bad choices make every neuron identical, or make signals shrink to zero or grow without bound as they pass through the network.
Every framework applies an initializer by default, and the choice matters most for deep networks. Xavier (Glorot) initialization is the standard for tanh and sigmoid layers, and He (Kaiming) initialization for ReLU layers. Transformers commonly use small normal initializations, with residual projections sometimes scaled down further by depth, as in GPT-2.
Key ideas
- Identical starting weights make neurons identical, and gradient descent cannot separate them.
- Random weights break that symmetry, but their scale must match the layer size.
- The variance of a neuron's weighted sum grows with the number of inputs it receives.
- Scaling weight variance by 1/n_in keeps activations at a stable size across layers.
- Xavier initialization suits tanh and sigmoid; He initialization suits ReLU.
- Biases are usually initialized to zero.
Common questions
What is the difference between Xavier and He initialization?
Xavier sets the weight variance to 2/(n_in + n_out), which suits activations that are roughly linear near zero, such as tanh. He sets it to 2/n_in, twice as large as LeCun's 1/n_in, to make up for ReLU discarding the negative half of its inputs. Using Xavier with deep ReLU networks makes activations shrink layer by layer.
What initialization does PyTorch use by default?
PyTorch's nn.Linear and nn.Conv layers use a Kaiming-uniform scheme with a=√5, which works out to a uniform distribution on ±1/√n_in for the weights. Biases are drawn uniformly from the same range. Many model codebases override this with explicit Xavier, He, or small normal initializations.
Should I use a normal or uniform distribution?
Either works if the variance is right. Normal and uniform initializations with matched variance give very similar results. Some codebases use a truncated normal, which redraws values beyond two standard deviations, to avoid rare large weights.
Does weight initialization matter if I use batch normalization?
Less, because batch normalization rescales each layer's activations regardless of the weight scale. Initialization still affects the earliest training steps and any layers without normalization. Residual networks also benefit from special tricks, such as starting the last layer of each block at zero so the block begins as the identity.
Related explainers
- Activation Functions — Why networks need non-linearity to learn
- Vanishing & Exploding Gradients — Why deep networks struggle and how to fix it
- Batch Normalization — Why normalizing activations speeds up deep network training
- Backpropagation — How networks learn from their mistakes
- Neural Networks — Neurons, layers, and how networks learn
- Skip Connections & ResNets — Residual learning and why deeper networks work
References
- Glorot & Bengio (2010), "Understanding the difficulty of training deep feedforward neural networks", AISTATS
- He et al. (2015), "Delving Deep into Rectifiers: Surpassing Human-Level Performance on ImageNet Classification"
- Saxe, McClelland & Ganguli (2013), "Exact solutions to the nonlinear dynamics of learning in deep linear neural networks"
- Zhang et al., "Dive into Deep Learning", section 5.4: Numerical Stability and Initialization
Last updated