This Machine Learning concept is the current idea: keep the same invariant visible across Intuition, Math, Code, Interactive Demo.
Machine Learning
Activation Functions and Gradient Flow
Activation functions choose both the nonlinearity and the local derivative gate that controls how gradient signal flows through a network.
Concept Structure
Activation Functions and Gradient Flow
Start with the picture, metaphor, or geometric mechanism.
Make the objects explicit and connect them with notation.
Mirror the equations with runnable implementation details.
Manipulate the mechanism and watch the idea respond.
Learner Contract
What this page should let you do.
2 prerequisites listed; refresh them before leaning on the math or code.
Explain the mechanism, trace the main notation, and test one prediction in the live demo.
Read the intuition before the notation; the math should name a mechanism you already felt.
Follow this edge after making one prediction here; the next page should reuse the result, not restart the route.
Claim/source review status
Substantive review recorded
1/1 claims have bounded review metadata; still check caveats and source scope.Metadata-derived; review may be AI-assisted. Not a human certification.01
Intuition
Build the mental picture first so the rest of the page has something to attach to.
You are here because "use ReLU" is not an explanation. An activation function is a small scalar function placed between affine layers, but it has two jobs at once: it bends the forward computation and it gates the backward gradient.
Before this, know functions and derivatives. By the end, you should be able to compare sigmoid, tanh, ReLU, GELU, and SiLU/Swish by asking two questions:
- What output shape does this activation create?
- What local derivative will backprop multiply into the gradient?
Without a nonlinearity, stacked affine layers collapse into one affine layer. With nonlinear activations, hidden units become features and deep networks can build piecewise, saturating, or smoothly gated transformations. But the derivative is the part learners often miss. If a layer's local derivative is tiny, then upstream gradient is multiplied by a tiny number. Repeat that across layers and the signal can vanish before useful learning reaches early weights.
Sigmoid and tanh are smooth squashing functions. They are nearly linear around zero, but their tails flatten, so their derivatives go toward zero when pre-activations are large in magnitude. ReLU is different: it is exactly zero on the negative side and identity on the positive side. That makes positive-side gradient flow simple, but negative units can be silent. GELU and SiLU/Swish are modern smooth relatives: instead of a hard threshold, they weight the input by a smooth gate.
The practical lesson is not a ranking table. Activation choice interacts with initialization, normalization, optimizer, architecture, and task. The local lesson is more durable: every activation leaves a fingerprint in the derivative chain.
02
Math
Translate the story into symbols, assumptions, and a derivation you can inspect.
Let a hidden layer receive a pre-activation vector
where , , , and . The activation is applied elementwise:
If is the loss, the chain rule gives
So is a local gradient gate. A forward plot without the derivative plot is only half the story.
Common choices:
The maximum sigmoid derivative is at , and it tends to as grows.
The tanh derivative reaches at , but it also tends to in both tails.
This is why ReLU can pass positive-side gradients cleanly while also creating silent negative-side units.
For smooth modern activations, let be the standard Gaussian cumulative distribution function. GELU is
and SiLU, often called Swish when written with a parameter, is
These functions multiply the input by a smooth gate instead of making a hard negative/positive cutoff.
For a depth- scalar chain with local pre-activations , the magnitude of the backward signal contains the product
That product is the whole reason derivative plots matter. Three sigmoid units in the saturated tail can shrink a gradient by orders of magnitude. Three positive ReLU units pass a product of . Three smooth gates sit somewhere between, depending on the pre-activations.
03
Code
Keep the implementation aligned with the notation so the algorithm is legible.
import math
def sigmoid(z):
return 1.0 / (1.0 + math.exp(-z))
def normal_cdf(z):
return 0.5 * (1.0 + math.erf(z / math.sqrt(2.0)))
def normal_pdf(z):
return math.exp(-0.5 * z * z) / math.sqrt(2.0 * math.pi)
activations = {
"sigmoid": (lambda z: sigmoid(z), lambda z: sigmoid(z) * (1 - sigmoid(z))),
"tanh": (math.tanh, lambda z: 1 - math.tanh(z) ** 2),
"relu": (lambda z: max(0.0, z), lambda z: 1.0 if z > 0 else 0.0),
"gelu": (lambda z: z * normal_cdf(z), lambda z: normal_cdf(z) + z * normal_pdf(z)),
"silu": (lambda z: z * sigmoid(z), lambda z: sigmoid(z) + z * sigmoid(z) * (1 - sigmoid(z))),
}
chain = [3.0, 2.4, 1.8]
for name, (_, deriv) in activations.items():
gates = [deriv(z) for z in chain]
product = math.prod(gates)
print(name, [round(g, 4) for g in gates], "chain:", f"{product:.3e}")
The code mirrors the math: backprop through repeated activations multiplies local derivatives. The numbers are a tiny witness, not a claim that one activation wins across architectures.
04
Interactive Demo
Use direct manipulation to connect the explanation to a moving system.
Use the Activation Derivative Flow Lab to choose one activation and predict the most visible derivative behavior before revealing:
- Saturates gradients: the derivative is small in the tails, so the chain product collapses.
- Passes positive gradients: positive-side ReLU derivatives pass signal, while negative-side units are silent.
- Smooth self-gate: GELU or SiLU weights the input by a smooth gate rather than a hard threshold.
Before reveal, the demo shows the activation family and the pre-activation probe but hides the exact local derivative, the three-layer chain product, and the ReLU dead-side fraction. After reveal, compare the output curve, derivative curve, and chain strip. The right question is not "which activation is best?" It is "what derivative gate did this layer just put into the learning signal?"
Live Concept Demo
Explore Activation Functions and Gradient Flow
The stage is code-native and interactive. Use it to test the explanation against the mechanism.
Manipulate one control and predict the visible change.
Commit to what Activation Functions and Gradient Flow should make visible before reading the result.
After The First Pass
Turn the concept into an inspected object.
Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.
Mechanism Storyboard
See the idea move before the page explains it
Activation functions choose both the nonlinearity and the local derivative gate that controls how gradient signal flows through a network.
Start with the picture, metaphor, or geometric mechanism.
Before reading further, choose the kind of change Activation Functions and Gradient Flow should make visible.
Visual Inquiry
Make the image answer a mathematical question
Activation functions choose both the nonlinearity and the local derivative gate that controls how gradient signal flows through a network.
Which visible object should carry the first intuition?
Pick the cue that should make Activation Functions and Gradient Flow easier to reason about before the page gives the answer.
Source Grounding
Canonical references for the mechanism on this page.
Gives ReLU, sigmoid, tanh, GELU, and Swish formulas plus derivative behavior for the classical activations.
Open sourcePedagogical source for nonlinearity, sigmoid saturation, ReLU non-saturation, and dying-ReLU caveats.
Open sourcePrimary source for GELU as x times the standard Gaussian CDF.
Open sourcePrimary source for Swish as x times sigmoid(beta x), with empirical comparison caveats.
Open sourceClaim Review
Activation functions choose both the nonlinearity and the local derivative gate that controls how gradient signal flows through a network.
Claims without a substantive review badge still need exact source-support review.
d2l-2026-activation-functions, cs231n-neural-networks-1-activations, hendrycks-2016-gelu, ramachandran-2017-swish
Use equations, runnable code, and demos to check whether the source support is operational.
D2L supports ReLU/sigmoid/tanh formulas and derivative behavior plus GELU/Swish definitions; CS231n supports nonlinearity necessity, saturation killing gradients, and dying-ReLU caveats; the GELU and Swish papers support the modern smooth activation formulas.
Sources: Dive into Deep Learning: Multilayer Perceptrons, Activation Functions, CS231n: Neural Networks Part 1, Commonly Used Activation Functions, Gaussian Error Linear Units (GELUs), Searching for Activation FunctionsToy scalar local-derivative and chain-product witness only; not a benchmark claim, optimizer recommendation, architecture ranking, finite-training guarantee, normalization analysis, or output-layer prescription.A bounded review summary is present; still check caveats and exact reference scope.Checked D2L for activation formulas and derivatives, CS231n for saturation/dead-ReLU training caveats and the nonlinearity-collapse warning, Hendrycks/Gimpel for GELU = x Phi(x), and Ramachandran/Zoph/Le for Swish = x sigmoid(beta x). Demo is a local derivative-chain witness, not an architecture benchmark or optimizer claim. GPT Pro/Oracle publication critique remains pending.
Reviewer: codex-local-primary-source-audit; reviewed 2026-07-02Source support candidates
book 2026Dive into Deep Learning: Multilayer Perceptrons, Activation FunctionsGives ReLU, sigmoid, tanh, GELU, and Swish formulas plus derivative behavior for the classical activations.
course-notes 2026CS231n: Neural Networks Part 1, Commonly Used Activation FunctionsPedagogical source for nonlinearity, sigmoid saturation, ReLU non-saturation, and dying-ReLU caveats.
paper 2016Gaussian Error Linear Units (GELUs)Primary source for GELU as x times the standard Gaussian CDF.
paper 2017Searching for Activation FunctionsPrimary source for Swish as x times sigmoid(beta x), with empirical comparison caveats.
Practice Loop
Try the idea before it explains itself
Activation functions choose both the nonlinearity and the local derivative gate that controls how gradient signal flows through a network.
Before touching the demo, predict one visible change that should happen in Activation Functions and Gradient Flow.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
A concrete answer is on the canvas.
The answer names why the claim should hold.
It touches the page context or a neighboring idea.
Research Room
Attach the question to a claim, equation, code, or demo
Pick the concept, equation, source, runnable code, claim, misconception, or demo state before asking for help. The handoff keeps that page item in context.Open the draft below to save one note and next action in this browser.
Activation Functions and Gradient Flow
What is the smallest example that makes Activation Functions and Gradient Flow click without losing the math?
Local action draftNo local draft saved yetExpand only when ready to capture one local next action
This draft stays in this browser, attached to the selected learning item.
- References to inspect: attached references on this page.
- Definition, prerequisite, and contrast concept links
- The equation or runnable code that makes the concept operational
- One demo state that shows the invariant instead of a slogan
- The learner can state the mechanism in their own words
- The learner can name the prerequisite that would repair confusion
- The learner can predict how the mechanism changes under one perturbation
I am working in Continuous Function's research reading room. Object: concept - Activation Functions and Gradient Flow Selected item key: recorded for copy. Context: Machine Learning Page anchor: recorded for copy. Open question: What is the smallest example that makes Activation Functions and Gradient Flow click without losing the math? Evidence to inspect: - References to inspect: attached references on this page. - Definition, prerequisite, and contrast concept links - The equation or runnable code that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.
concept/concept-notebook/machine-learning/activation-functions
concept:machine-learning/activation-functions