Skip to main content
Botmartz AI Solution PVT LTD.
Home›Engineering Insights›OPTIMIZATION
OPTIMIZATION

Weight Initialization Strategies: Xavier, He Initialization, and Training from Scratch

Bad weight initialization breaks training: dead neurons, gradient vanishing. Use Xavier init for tanh, He init for ReLU. Understand why initialization matters.

SS
Soham Sharma
AI Engineer, Botmartz · July 17, 2026 · 1 min read
Read Time
1 min
Failure Modes
5
Code Snippets
3
Runnable Notebook
1
Weight Initialization Strategies: Xavier, He Initialization, and Training from Scratch

Weight initialization determines whether training converges. Random uniform weights can lead to dead neurons (stuck at zero activation) or gradient vanishing (gradients too small). Xavier and He initialization set weight variance based on layer size and activation function.

Bad Initialization

Code Snippet
# Too large: Exploding gradients
weights = torch.randn(100, 100) * 10  # Variance too high

# Too small: Vanishing gradients
weights = torch.randn(100, 100) * 0.01  # Variance too low

Xavier Initialization

For tanh activations:

Code Snippet
# Variance = 2 / (fan_in + fan_out)
fan_in = 100
fan_out = 64
weights = torch.randn(fan_in, fan_out) * math.sqrt(2 / (fan_in + fan_out))

He Initialization

For ReLU activations:

Code Snippet
# Variance = 2 / fan_in (ReLU kills negative half)
fan_in = 100
weights = torch.randn(fan_in, 64) * math.sqrt(2 / fan_in)

# PyTorch implements this
nn.Linear(100, 64)  # Initialized with He init by default

Conclusion

Weight initialization dramatically affects training speed and convergence. Xavier and He init match activation functions and layer sizes. Understanding initialization prevents many subtle training failures. Next: understanding gradient flow with residual connections.

Closing Takeaways

✓
Measure retrieval precision and recall in isolation before touching the model.
✓
Chunk along document structure, not arbitrary character counts.
✓
Combine vector and keyword search — hybrid retrieval beats either alone.
✓
Treat evaluation as continuous infrastructure, not a launch-week report.
Try It Yourself
A runnable Google Colab notebook with the eval harness and hybrid search code from this post.
#Weight Initialization#Training#Neural Networks#Deep Learning
0 views
SS
Soham Sharma
AI Engineer at Botmartz, building enterprise RAG and agent systems in production. Contributing to open-source libraries.

Discussion (0)

No approved comments yet. Be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *

More Engineering Insights
AI AGENTS
9 min read
AI AGENTS
11 min read
OPEN SOURCE
6 min read
AI ENGINEERING
8 min read
CASE STUDIES
14 min read