Why does random initialization of weights in neural network work?
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
The process of random weight initialization in neural networks is crucial for their successful training and convergence. When designing a neural network, the choice of starting weights can impact the speed and outcome of the training process. Let's delve into why random initialization works and explore the technical details that make it effective.
The Need for Random Initialization
1. Breaking Symmetry
In a neural network, especially those structured with multiple layers of neurons, initializing all weights to the same value (e.g., zero) results in symmetry. When neurons in a layer have identical weights, they learn the same features during training, negating the network's ability to learn diverse representations of data. Random initialization ensures that each neuron learns unique features by providing different starting points.
2. Accelerating Convergence
Random initialization can help accelerate the convergence of gradient descent algorithms. By starting with unique weights, the error surface that the algorithm traverses during optimization becomes more navigable, allowing the optimization process to find minima more efficiently.
Theoretical Foundation
Weight Initialization Techniques
Several methods are commonly used for random weight initialization:
• Uniform distribution: Weights are chosen randomly from a uniform distribution, often constrained between a defined range, e.g., , where is the number of input units in the layer.
• Normal distribution: Weights are drawn from a Gaussian distribution with a mean of 0 and a small standard deviation, such as .
• Xavier/Glorot initialization: Proposed by Xavier Glorot and Yoshua Bengio, this initializes weights to values where the variance remains constant across layers, specifically using , where and are the input and output size of the layer.
• He initialization: Suitable for ReLU activations, it scales the weights inversely with the square root of the input size, .
Avoiding Saturation
Neural networks rely on activation functions like sigmoid or hyperbolic tangent (). Both can saturate, leading to minimal gradients and halting learning. Random initialization mitigates this by starting the network in regions of the data space where neurons are not saturated, allowing the gradient descent to take meaningful steps in reducing error.
Practical Example
Consider a simple feedforward network with one hidden layer. Here's how different initialization strategies can affect training:
- Zero Initialization: The hidden layer neurons have identical weights, so they learn the same feature. The network fails to differentiate patterns in data.
- Random Normal Initialization: Each neuron starts learning from slightly different weights, allowing diverse feature extraction, leading to better convergence.
- Glorot Initialization: Balances the scale of input and output variance, allowing a smoother start to the training process.
Summary Table
| Initialization Method | Characteristics | Suitable For |
| Zero Initialization | Leads to symmetry, ineffective training | Demonstrative/rare cases |
| Uniform Distribution | Random but consistent range, less prone to saturation issues | General use |
| Normal Distribution | Centered around zero, small initial variance | General use |
| Xavier/Glorot | Maintains variance through layers, good for sigmoid/ activations | Fully connected networks, sigmoid/ |
| He Initialization | More variance for inputs, suitable for ReLU activations | Networks using ReLU |
Conclusion
Random initialization of weights works effectively in neural networks because it promotes learning diversity, symmetry breaking, and convergence speed. Techniques like Xavier Initialization and He Initialization have provided further insight into how scaling the initial weights according to the network's architecture can improve performance. As deep learning models evolve, understanding and improving initialization strategies remain crucial for building efficient and robust networks.
Related reading
- Why does TensorFlow always use GPU 0?
- Why does TensorFlow always use GPU 0?
- Why does TensorFlow's documentation call a softmax's input logits?
- Why does the gated activation function used in Wavenet work better than a ReLU?
- why does scikitlearn says F1 score is ill-defined with FN bigger than 0?
- Why does shuffling my validation set in Keras change my model's performance?
- Why doesn't my simple pytorch network work on GPU device?
- Why doesn't the transformer use positional encoding in every layer?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.