Visualizing Vanishing Gradients & Softmax Temperature in Neural Networks (Interactive Playground + NumPy Code)
Originally published on CatalystCode — includes an interactive browser playground where you can overlay activation curves f(z) with their exact derivatives f′(z), inspect gradient health in real time, and test Softmax te
Originally published on CatalystCode — includes an interactive browser playground where you can overlay activation curves f(z) with their exact derivatives f′(z), inspect gradient health in real time, and test Softmax temperature scaling.
Most neural network tutorials give you a static screenshot of Sigmoid, Tanh, and ReLU and tell you to memorize: "Sigmoid has vanishing gradients, ReLU has dead neurons, Transformers use GELU."
It clicks 10x faster when you actually plot the first derivative f′(z) right on top of f(z) and drag the input logit z from -5 to +5.
What Happens to Your Gradient at z = -3.0 vs. z = +3.0?
| Activation | Formula | Value at z = 3.0 | Gradient f′(3.0) | Backprop Behavior |
|---|---|---|---|---|
| Sigmoid | 1 / (1 + e^(-z)) |
0.9526 |
0.0452 |
Vanishing (< 0.05) |
| Tanh | tanh(z) |
0.9951 |
0.0099 |
Severely saturated |
| ReLU | max(0, z) |
3.0000 |
1.0000 |
Healthy (1.0 for z > 0, 0.0 dead for z < 0) |
| GELU | 0.5 · z · (1 + erf(z / √2)) |
2.9960 |
1.0119 |
Smooth non-zero gradient near 0 |
| Swish (SiLU) | z · σ(βz) |
2.8577 |
1.0881 |
Smooth self-gated gradient |
Notice why deep networks with Sigmoid stall: even at a modest logit of z = 3.0, the derivative drops below 0.05. Multiply 0.045 across 8 layers during backpropagation and the gradient shrinks to 10⁻¹¹.
Softmax & Temperature Scaling (T)
In classification and LLM token sampling, raw logits zᵢ are converted into probabilities with an optional temperature T:
import numpy as np
def softmax_with_temperature(logits, temperature=1.0):
scaled = logits / temperature
shifted = scaled - np.max(scaled)
exp_vals = np.exp(shifted)
return exp_vals / np.sum(exp_vals)
logits = np.array([2.0, 1.0, 0.1, -0.6])
print("T=0.25 (Sharp): ", np.round(softmax_with_temperature(logits, 0.25), 3))
print("T=1.00 (Standard):", np.round(softmax_with_temperature(logits, 1.00), 3))
print("T=2.20 (Soft): ", np.round(softmax_with_temperature(logits, 2.20), 3))
-
Low T (
0.25): Concentrates probability mass on the highest logit (low Shannon entropy). -
High T (
2.20): Flattens the distribution so lower-scoring classes stay competitive (high entropy).
Try the Interactive Browser Playground
In the full article on CatalystCode, you can:
- Toggle ReLU, GELU, Swish, Sigmoid, Tanh, Leaky ReLU, and ELU and overlay f(z) + dashed derivative f′(z).
- Drag sliders for z, Leaky/ELU slope α, and Swish β to watch the Backprop Gradient Health badge flip between
Healthy Flow,Vanishing, andDead Neuron. - Experiment with the Softmax Temperature Simulator and copy the matching NumPy snippet in one click.
👉 Open the Interactive Activation Function & Softmax Playground on CatalystCode
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.