SeeingML
Neural Networks & Deep Learning Guide 2 of 6 · tap to switch
✦ Interactive Visual Guide 8 min · 4 hands-on labs · Beginner friendly

Activation Functions (ReLU, Sigmoid & GELU)

Why every neural layer needs a non-linear bend, how ReLU cured vanishing gradients, and why modern LLMs love GELU.

Stack ten magnifying glasses in a row and a straight ruler still looks straight. Put one tiny hinge in the middle, and suddenly you can fold straight lines into any shape on Earth. That hinge is an Activation Function.

Picture a smart thermostat measuring Room Discomfort. At the ideal 70°F, discomfort is zero. Turn the heat too low (66°F) and discomfort rises. Crank it too high (74°F) and discomfort rises again. Plot that on a chart and you get a clean V-shape: low in the middle, rising on both sides.

Now try predicting that V-shape with a 10-layer neural network that has no activation functions between its layers. No matter how many weights you add or how long you train, the entire network can only ever draw one flat straight line!

Why? Because plugging one straight-line rule into another (w₂ · (w₁ · x + b₁) + b₂) simply multiplies out into one combined straight line ((w₂w₁)x + b_new). Stacking pure straight-line layers always folds back into a single straight line, a trap called Linear Collapse.

Drag w1, w2, and Shift below with No Activation (Pure Linear) selected to verify the red line stays stubbornly straight, then click Turn On ReLU Hinge to watch the exact same weights fold effortlessly onto the room discomfort V-curve!

Interactive Lab 1: Room Discomfort vs. Thermostat (Linear Collapse)
Real Room Discomfort (V-Curve)Collapsed to 1 Line (y = 0.80x + 0.0)
Avg Error: 2.02
01234566°F (-4)68°F (-2)70°F (Ideal)72°F (+2)74°F (+4)Room DiscomfortThermostat Setting (Distance from Ideal 70°F)
1.5
1.2
0.0
Stuck as a straight line (Avg Error = 2.02): Drag w1, w2, and Shift as far as you like. Combining two straight-line layers always collapses into ONE straight line (current slope 0.80), so it can never rise on both the cold and hot sides. Click Turn On ReLU Hinge above to watch it fold!

Meet the five everyday activation switches (and their slopes!)

When picking an activation switch, deep learning engineers care about two questions at once:

  1. What output does it pass forward? (solid purple curve): how the switch reshapes a neuron’s raw score before sending it to the next layer.
  2. What is its learning slope? (optional dashed green curve): how strongly nudging the input score changes the switch’s output. In calculus, this steepness is called the derivative (f'(z)). In the next guide on Backpropagation, you will see how networks multiply these slopes layer by layer to learn! Wherever a switch goes completely flat, its learning slope drops to 0, and learning stalls because small weight nudges make zero difference.

Here are the five switches you will meet everywhere:

  • ReLU (Rectified Linear Unit): turns negative scores flat to 0 and lets positive scores pass straight through unchanged. Fast, simple, and the everyday default for most hidden layers.
  • Leaky ReLU: behaves just like ReLU for positive scores, but replaces the flat zero shelf on the left with a gentle downward tilt so negative scores still pass a small trickle instead of going completely flat.
  • GELU (Gaussian Error Linear Unit): a smooth, rounded cousin of ReLU with no sharp corner at zero. It lets slight negative scores dip gently instead of snapping to zero, making it a favorite in modern language models and AI assistants.
  • Sigmoid: squishes any score cleanly into a smooth S-curve between 0% and 100% (0.0 to 1.0), turning raw scores into readable yes/no probabilities.
  • Tanh (Hyperbolic Tangent): a centered S-curve running from -1.0 to +1.0 around zero. It is steeper in the middle than Sigmoid and keeps values balanced between negative and positive, though its outer edges still flatten out.

Click through ReLU, Sigmoid, Tanh, Leaky ReLU, and GELU below, and slide the input score from -5.0 to +5.0 to see how each switch transforms inputs. Then click Show Learning Slope (Optional) to reveal the dashed green steepness curve and spot where each switch flattens out!

Interactive Lab 2: Activation Gallery
Input +1.5 -> Output 1.50
Output value (Zero if negative, unchanged if positive)
Y-axis: -1 to 5
-1012345-4-20+2+4Output ValueNeuron Input Score (before activation switch)
Input = +1.5 · Range: 0 and up (never negative)
ReLU: Active ramp at input +1.5: ReLU passes 1.50 straight through unchanged with a steady learning slope of 1.00. Best for: most hidden layers (fast everyday default).Ready for the next layer? Click Show Learning Slope (Optional) above to see where nudging this switch passes feedback vs. goes flat.
✓ Tip
Quick Cheat Sheet: Hidden Layers vs. Final Output Layer
  • Hidden layers: Default to ReLU (fast everyday workhorse), Leaky ReLU (when neurons get stuck at zero), or GELU (smooth favorite in modern language models).
  • Final output layer: Match the switch to your task. Use None (Linear) when predicting an open-ended number like a house price, Sigmoid for a single yes/no probability (0% to 100%), or Softmax when picking one winner out of 3 or more mutually exclusive categories (like Cat, Dog, Bird, Fish, or Horse) so every class gets a probability between 0% and 100% that adds up cleanly to 100%.

Why Sigmoid killed deep networks in the 1990s (Vanishing Gradients)

Before 2010, researchers put Sigmoid inside every hidden layer because its smooth S-curve felt natural. Then they tried stacking 6 or 10 layers deep, and the earliest layers barely learned at all!

Think of a game of telephone running backward from the final answer to Layer 1. To tell early weights how to improve, each layer passes learning feedback backward (a signal called a gradient) by multiplying it by that layer’s learning slope. If every person in a 6-person line whispers at a quarter of the previous volume, the message fades into silence before it reaches the start!

Look back at Sigmoid’s learning slope above: even at its very steepest midpoint (0), Sigmoid’s slope is at most 0.25 (and drops close to 0.00 near the flat outer ends). Multiply 0.25 backward through 6 layers and Layer 1 receives only 0.25^6 = 0.00024 (just 0.02%!) of the original feedback. Across 10 layers, the signal shrinks below one-millionth (0.000001). Early weights practically freeze, a failure called Vanishing Gradients.

Toggle Sigmoid, Tanh, and ReLU below to hear how loud the learning signal stays as it travels backward from Layer 6 to Layer 1!

Interactive Lab 3: The Telephone Game Across 6 Layers (Vanishing Gradients)
Whisper / Telephone Game: Each layer whispers at 1/4 volume100% -> (x 0.25)^6 -> 0.02%
Feedback starts at 100% at the output and multiplies by the layer learning slope at every step back to Layer 1.
Backward Learning Signal Traveling Output -> Layer 6 -> Layer 1Sigmoid: learning slope is at most 0.25 per layer
Layer 6 (Closest to Output)x 0.25
Soft Voice25%
Layer 5x 0.25
Quiet Whisper6.25%
Layer 4x 0.25
Barely Audible1.56%
Layer 3x 0.25
Barely Audible0.39% (0.00391)
Layer 2x 0.25
Nearly Silent0.1% (0.00098)
Layer 1 (Earliest Input Layer)x 0.25
Nearly Silent0.02% (0.00024)
Message lost in a whisper (Layer 1 hears just 0.02%): Every step through Sigmoid multiplies the learning signal by at most 0.25. Multiplying 0.25 six times drops feedback to 0.00024 (0.02%), so Layer 1 weights barely budge (Vanishing Gradient). Click Tanh or ReLU above to hear the signal recover!

Replacing Sigmoid with ReLU (Nair & Hinton, 2010; AlexNet, 2012) kept active learning slopes at a full 1.00, letting learning feedback pass cleanly across dozens of layers and helping spark the modern Deep Learning boom!


ReLU’s one catch: the “Dying ReLU” trap

ReLU’s flat zero shelf for negative scores is wonderfully fast, yet it carries one famous catch. Suppose a big negative training step (often from a learning rate that is too high) shoves a neuron’s bias deeply negative so that every single training example lands below zero.

Because Standard ReLU is completely flat on the negative side, both the neuron’s output AND its learning slope freeze at 0.00 across all examples. With zero learning signal coming back, training can never nudge that neuron’s weights or bias up again. It stays permanently silent: a Dying ReLU.

You can prevent or rescue dead neurons by lowering the learning rate so bias shifts stay gentle, or by swapping Standard ReLU for Leaky ReLU or GELU, which keep a small non-zero learning slope alive even when scores turn negative.

The neuron below starts healthy and alive at bias = 0.0 with Standard ReLU selected. Slide the bias down below -2.2 to push all six examples negative and kill the neuron yourself, then click Leaky ReLU or GELU to revive its learning signal immediately!

Interactive Lab 4: The Dying ReLU Trap (and How Leaky ReLU / GELU Save It)
NEURON ALIVE4 of 6 examples sending a learning signal
Avg Learning Signal: 0.667
Example 1Silent
Score-1.2
Output0.00
Learning Signal0.00
Example 2Silent
Score-0.4
Output0.00
Learning Signal0.00
Example 3Active
Score+0.3
Output0.30
Learning Signal1.00
Example 4Active
Score+0.9
Output0.90
Learning Signal1.00
Example 5Active
Score+1.5
Output1.50
Learning Signal1.00
Example 6Active
Score+2.1
Output2.10
Learning Signal1.00
Bias = 0.0
-3.5 (Deeply Negative)-2.2 (Danger Zone)0.0 (Healthy Start)+1.0
Neuron alive at bias = 0.0 (4 of 6 examples learning): As long as at least some examples have positive scores, Standard ReLU passes a crisp 1.00 learning signal. Drag the bias slider left below -2.2 to push every example negative and trigger a Dying ReLU yourself!
See Analytic Formulas, Softmax & Modern SwiGLU ActivationsThesis / Reference

1. Core Hidden Activations & Derivatives:

ReLU(z)=max⁡(0,z),LeakyReLUα(z)={zz>0αzz≤0\text{ReLU}(z) = \max(0, z), \qquad \text{LeakyReLU}_\alpha(z) = \begin{cases} z & z > 0 \\ \alpha z & z \le 0 \end{cases}
σ(z)=11+e−z,σ′(z)=σ(z)(1−σ(z))≤14\sigma(z) = \frac{1}{1 + e^{-z}}, \quad \sigma'(z) = \sigma(z)\big(1 - \sigma(z)\big) \le \frac{1}{4}
GELU(z)=z Φ(z)≈12z[1+tanh⁡ ⁣(2π(z+0.044715 z3))]\text{GELU}(z) = z\,\Phi(z) \approx \frac{1}{2}z\left[1 + \tanh\!\left(\sqrt{\frac{2}{\pi}}\big(z + 0.044715\,z^3\big)\right)\right]

where Φ(z)\Phi(z) is the standard Normal CDF (Hendrycks & Gimpel, 2016). Notice how GELU smoothly weights inputs by their Gaussian percentile rather than cutting abruptly at zero.

2. Multi-Class Output Softmax: To turn CC raw output logits z∈RC\mathbf{z} \in \mathbb{R}^C into a valid probability simplex summing to 1:

Softmax⁡(z)k=ezk−max⁡jzj∑c=1Cezc−max⁡jzj\operatorname{Softmax}(\mathbf{z})_k = \frac{e^{z_k - \max_j z_j}}{\sum_{c=1}^{C} e^{z_c - \max_j z_j}}

(Subtracting max⁡jzj\max_j z_j preserves exact values while preventing floating-point exp overflow.)

3. Frontier LLM Standard (SwiGLU, Shazeer, 2020): Leading open and frontier Transformers (Llama, PaLM, Gemma) upgrade feed-forward layers to SwiGLU, combining a smooth Swish/SiLU gate SiLU⁡(z)=z σ(z)\operatorname{SiLU}(z) = z\,\sigma(z) with an element-wise multiplicative branch: SwiGLU⁡(x)=SiLU⁡(xW1)⊙(xW2)\operatorname{SwiGLU}(\mathbf{x}) = \operatorname{SiLU}(\mathbf{x}\mathbf{W}_1) \odot (\mathbf{x}\mathbf{W}_2).

See ReLU, GELU & Softmax Output Layers in PyTorchOptional Code
python
import torch.nn as nn

# Hidden layers use GELU (or ReLU / LeakyReLU); final layer outputs raw logits
# because nn.CrossEntropyLoss applies numerically stable Log-Softmax internally!
classifier = nn.Sequential(
  nn.Linear(128, 256),
  nn.GELU(),           # smooth modern activation (zero Dying ReLU)
  nn.Linear(256, 128),
  nn.GELU(),
  nn.Linear(128, 10),  # 10 raw class logits -> pass straight to CrossEntropyLoss
)

loss_fn = nn.CrossEntropyLoss()

Now the million-dollar question: how does the network adjust millions of weights?

We can push inputs forward through weights, biases, and ReLU/GELU switches to make a prediction. When that prediction is wrong, how does every single hidden weight deep inside the network figure out whether to nudge up or down?

Welcome to the engine of Deep Learning: Backpropagation.

✓ Self-Check

Quick Intuition Check

Four quick real-world scenarios. No scores, just test your intuition.

1

You build a 12-layer neural network that only multiplies inputs by weights and adds biases, with NO activation functions in between. What kinds of patterns can it learn?

Pick an option first, or peek anytime
2

Why do deep 10-layer networks using Sigmoid inside every hidden layer suffer from Vanishing Gradients?

Pick an option first, or peek anytime
3

During training with Standard ReLU, you notice that 40% of neurons in a hidden layer output 0.00 on every single training example and stop updating completely. What happened, and how can you fix it?

Pick an option first, or peek anytime
4

When training a 5-class image classifier (Cat, Dog, Bird, Fish, or Horse), putting Softmax on the final output layer ensures all 5 predicted probabilities lie between 0% and 100% and add up to 100%.

Pick an option first, or peek anytime
Quick Reference

Common Questions

Why do neural networks need activation functions at all?
Without a non-linear activation function between layers, multiplying matrix after matrix (W2 * (W1 * x)) algebraically collapses into one single linear matrix multiplication (W_combined * x). Even a 100-layer network could only draw straight lines until you add non-linearities like ReLU or GELU.
Why did ReLU replace Sigmoid in hidden layers of deep neural networks?
Sigmoid's maximum derivative is only 0.25 and drops near 0 for large positive or negative inputs, so multiplying slopes across many layers makes gradients vanish exponentially (0.25^6 = 0.00024). ReLU keeps a constant derivative of 1.0 for all positive inputs and computes in a single comparison.
What is the Dying ReLU problem and how do you fix it?
If a big gradient step pushes a neuron's bias deeply negative so every training input produces z < 0, ReLU outputs 0 with exact derivative 0 forever, permanently killing that neuron. Fixes include using a sane learning rate, He initialization, or switching to Leaky ReLU, SiLU/Swish, or GELU.
Why do modern LLMs like GPT and Gemini use GELU or SwiGLU instead of plain ReLU?
GELU (Gaussian Error Linear Unit) behaves like a smooth, probabilistic version of ReLU without a sharp kink at zero, letting small negative signals carry slight gradients. Combined with gating (SwiGLU), it delivers noticeably smoother optimization and lower perplexity in billion-parameter Transformers.
Which activation function should go on the FINAL output layer?
Match the output activation strictly to your task: None (linear) for regression predicting continuous numbers, Sigmoid for binary yes/no probability, and Softmax for mutually exclusive multi-class probabilities that sum to 100%.

Written & illustrated by Muhammad Aashir Irshad · Updated December 2026 · Free open-access reference

https://seeingml.com/learn/activation-functions/ Open GitHub issue Suggest an edit
Cite this guide in a paper, thesis, or course (BibTeX & APA)
BibTeX
@misc{irshad2026activationfunctions,
  author       = {Irshad, Muhammad Aashir},
  title        = {Activation Functions (ReLU, Sigmoid & GELU): Interactive Visual Guide},
  howpublished = {SeeingML},
  year         = {2026},
  month        = {dec},
  url          = {https://seeingml.com/learn/activation-functions/},
  note         = {Interactive visual guide}
}
APA

Irshad, M. A. (2026). Activation Functions (ReLU, Sigmoid & GELU): Interactive Visual Guide. SeeingML. https://seeingml.com/learn/activation-functions/