Neural Networks & Deep Learning Guide 2 of 6 · tap to switch
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!
Meet the five everyday activation switches (and their slopes!)
When picking an activation switch, deep learning engineers care about two questions at once:
- 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.
- 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 to0, 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
0and 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%and100%(0.0to1.0), turning raw scores into readable yes/no probabilities. - Tanh (Hyperbolic Tangent): a centered S-curve running from
-1.0to+1.0around 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!
- 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%to100%), 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 between0%and100%that adds up cleanly to100%.
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!
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!
See Analytic Formulas, Softmax & Modern SwiGLU ActivationsThesis / Reference
1. Core Hidden Activations & Derivatives:
where 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 raw output logits into a valid probability simplex summing to 1:
(Subtracting 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 with an element-wise multiplicative branch: .
See ReLU, GELU & Softmax Output Layers in PyTorchOptional Code
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.
Quick Intuition Check
Four quick real-world scenarios. No scores, just test your intuition.
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?
Why do deep 10-layer networks using Sigmoid inside every hidden layer suffer from Vanishing Gradients?
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?
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%.
Common Questions
Why do neural networks need activation functions at all?
Why did ReLU replace Sigmoid in hidden layers of deep neural networks?
What is the Dying ReLU problem and how do you fix it?
Why do modern LLMs like GPT and Gemini use GELU or SwiGLU instead of plain ReLU?
Which activation function should go on the FINAL output layer?
Related Visual Guides
Neural Networks & the Perceptron
Demystify neural networks from a single weighted switch to multi-layer perceptrons that solve XOR and approximate any curve.
Backpropagation
See how neural networks pass blame backward from a wrong guess to every weight in one efficient Chain Rule sweep.
Batch Normalization, Dropout & Weight Decay
Keep deep neural networks stable and prevent memorization using Dropout, Batch/Layer Normalization, Weight Decay, and Data Augmentation.
Written & illustrated by Muhammad Aashir Irshad · Updated December 2026 · Free open-access reference
Cite this guide in a paper, thesis, or course (BibTeX & APA)
@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}
} Irshad, M. A. (2026). Activation Functions (ReLU, Sigmoid & GELU): Interactive Visual Guide. SeeingML. https://seeingml.com/learn/activation-functions/