Skip to content
E
Educatum

Initializing weights with 0s for NN?

Curated by Educatum AI teamLast updated:
Neural Networks and Deep Learning
Direct Answer

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:

  1. 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 ∂L∂W:,j\frac{\partial \mathcal{L}}{\partial W_{:,j}} on every step, locking them into identical parameters forever and collapsing layer width HH to effectively 11 neuron.
  2. Dead / Zero Gradients: When all layers have zero weights, forward activations in ReLU layers are zero (ReLU(0)=0\text{ReLU}(0) = 0) and backpropagated error signals δ(l)=(W(l+1))⊤δ(l+1)⊙σ′(z(l))\delta^{(l)} = (W^{(l+1)})^\top \delta^{(l+1)} \odot \sigma'(z^{(l)}) vanish identically to 00 because W(l+1)=0W^{(l+1)} = 0 (and ReLU′(0)=0\text{ReLU}'(0) = 0 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 tanh⁡\tanh activations, sampling weights with Var(W)=2nin+nout\text{Var}(W) = \frac{2}{n_{\text{in}} + n_{\text{out}}} (or 1nin\frac{1}{n_{\text{in}}}).
  • He (Kaiming) Initialization: Designed for ReLU-family activations (which zero out half the distribution), doubling the variance to Var(W)=2nin\text{Var}(W) = \frac{2}{n_{\text{in}}}.
  • Dead Gradients vs. Identical Gradients: All-zero weights cause exact zero hidden gradients; non-zero constant weights (e.g., Wij=0.1W_{ij} = 0.1) 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 tanh⁡\tanh), downstream weight gradients ∂L∂W(2)=δ(2)(a(1))⊤=0\frac{\partial \mathcal{L}}{\partial W^{(2)}} = \delta^{(2)} (a^{(1)})^\top = 0, and hidden weight gradients ∂L∂W(1)=0\frac{\partial \mathcal{L}}{\partial W^{(1)}} = 0. Even if hidden weights are initialized to a non-zero constant 0.1 with tanh⁡\tanh, all 4 columns of ∇W(1)L\nabla_{W^{(1)}} \mathcal{L} 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))
  • 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 (≈1\approx 1) 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 B matrix 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.
View all →

Try keywords like RoPE, FlashAttention, DPO, or Blind 75.