Initializing weights with 0s for NN?
Initializing all weights to zero in a multi-layer neural network fails because it destroys symmetry breaking and can trap hidden layers with zero gradients. Every neuron in a layer receives identical pre-activations and identical updates—effectively collapsing the layer to a single unit—and zero downstream weights or ReLU at zero can stall gradients completely, making random Xavier or He initialization essential.
Study Card: Initializing Weights with Zeros in Neural Networks
Direct Answer
Initializing all weights to zero (or any identical constant) in a multi-layer neural network is a critical mistake, whereas initializing biases to zero is standard and safe—and single-layer convex models like linear or logistic regression work fine from zero weights. In multi-layer networks, zero weight initialization fails for two distinct reasons:
- Symmetry Collapse: If every neuron in a hidden layer starts with identical weights and biases, all neurons compute the exact same output and receive the exact same backpropagated gradient on every step, locking them into identical parameters forever and collapsing layer width to effectively neuron.
- Dead / Zero Gradients: When all layers have zero weights, forward activations in ReLU layers are zero () and backpropagated error signals vanish identically to because (and in standard frameworks). Thus, hidden weights never move off zero at all.
Instead, weights must be sampled randomly with variance calibrated to layer width—such as Xavier/Glorot or He initialization—to break symmetry while preserving signal variance across depth.
Key Terms
- Symmetry Breaking: Initializing weights with independent random draws so neurons in the same layer compute diverse features and diverge during gradient descent.
- Xavier / Glorot Initialization: Designed for linear, sigmoid, and activations, sampling weights with (or ).
- He (Kaiming) Initialization: Designed for ReLU-family activations (which zero out half the distribution), doubling the variance to .
- Dead Gradients vs. Identical Gradients: All-zero weights cause exact zero hidden gradients; non-zero constant weights (e.g., ) produce non-zero but identical gradients across neurons in a layer.
Example
Consider a 2-layer network with 4 hidden units. If all weights are initialized to 0.0, every hidden unit outputs 0 (for ReLU or ), downstream weight gradients , and hidden weight gradients . Even if hidden weights are initialized to a non-zero constant 0.1 with , all 4 columns of remain mathematically identical on every batch, preventing the 4 neurons from ever specializing in distinct edge orientations or patterns.
Code Implementation
import numpy as np
import tensorflow as tf
# Reproducible synthetic input and target
np.random.seed(42)
X = np.random.randn(4, 2).astype(np.float32)
y = np.array([[1.0], [0.0], [1.0], [0.0]], dtype=np.float32)
loss_fn = tf.keras.losses.MeanSquaredError()
# 1. All-zero weight initialization (dead zero hidden gradients)
model_zero = tf.keras.Sequential([
tf.keras.Input(shape=(2,)),
tf.keras.layers.Dense(4, activation='tanh', kernel_initializer='zeros'),
tf.keras.layers.Dense(1, kernel_initializer='zeros'),
])
# 2. Constant non-zero initialization (identical gradients -> symmetry collapse)
model_const = tf.keras.Sequential([
tf.keras.Input(shape=(2,)),
tf.keras.layers.Dense(4, activation='tanh', kernel_initializer=tf.keras.initializers.Constant(0.1)),
tf.keras.layers.Dense(1, kernel_initializer=tf.keras.initializers.Constant(0.1)),
])
# 3. Random Glorot/Xavier initialization (symmetry broken)
model_rand = tf.keras.Sequential([
tf.keras.Input(shape=(2,)),
tf.keras.layers.Dense(4, activation='tanh', kernel_initializer='glorot_uniform'),
tf.keras.layers.Dense(1, kernel_initializer='glorot_uniform'),
])
def get_layer1_weight_grad(model):
with tf.GradientTape() as tape:
preds = model(X, training=True)
loss = loss_fn(y, preds)
return tape.gradient(loss, model.trainable_variables)[0].numpy()
print("Layer-1 weight gradients with Zero Init (all zero):")
print(np.round(get_layer1_weight_grad(model_zero), 4))
print("\nLayer-1 weight gradients with Constant(0.1) Init (identical columns):")
print(np.round(get_layer1_weight_grad(model_const), 4))
print("\nLayer-1 weight gradients with GlorotUniform Init (distinct per neuron):")
print(np.round(get_layer1_weight_grad(model_rand), 4))
Related Concepts
- Bias Initialization: Biases are routinely initialized to
0(or small positive values in older ReLU heuristics) because random weights already break symmetry between neurons. - Xavier vs. He Variance Scaling: Keeping activation and gradient variances stable () across many layers prevents both vanishing and exploding gradients at step 0.
- Batch & Layer Normalization: Normalize pre-activations or activations per layer, making deep training far more resilient to initialization scale mismatches (though random symmetry breaking is still strictly required).
- Transfer Learning & Fine-Tuning: Initializing the final output projection or LoRA
Bmatrix to zero is an intentional special case—preserving the pre-trained backbone identity at step 0 while pre-trained random/learned upstream features already break symmetry.