3.1.4 · D2Neural Network Fundamentals

Visual walkthrough — Activation functions - sigmoid, tanh

2,379 words11 min readBack to topic

We will build, in order:

  1. The number line (the raw input).
  2. The exponential curve (the one ingredient).
  3. The squash into — the sigmoid.
  4. Its slope (the derivative), by watching the curve.
  5. The self-referential shortcut .
  6. Tanh as the same picture, recentered.
  7. The degenerate/edge cases (the flat tails).

Step 1 — The raw signal lives on the whole number line

WHAT. A neuron first computes one plain number, the pre-activation . We call it ; it can be any real number: , , , anything.

WHY. Before we squash anything, we must be honest about the input. The input is unbounded — it stretches to on the left and on the right. Our whole job is to tame this unbounded line into a bounded answer.

PICTURE. Look at the horizontal arrow: it never ends in either direction. The green dot at is "no opinion". Right of it, evidence for firing; left of it, evidence against.

Figure — Activation functions -  sigmoid, tanh

Step 2 — One ingredient: the exponential

WHAT. We introduce exactly one new function, . Read it as " raised to minus ", where is a fixed number.

WHY THIS TOOL and not another? We need a gadget that is:

  • always positive (so we never divide by a negative surprise),
  • huge when is very negative, and tiny when is very positive,
  • smooth (no corners), so the network can be nudged.

is the simplest function doing all three. When , , so . When , . At , . That "flips from big to small, passing through 1" is exactly the switch we want.

PICTURE. The coral curve dives from a towering height on the left down toward the floor on the right, kissing the value right at (mint dot).

Figure — Activation functions -  sigmoid, tanh

Term-by-term, the expression :

  • ::: the fixed base , chosen because its own slope equals itself — i.e. . This is the one calculus fact we will lean on.
  • ::: the "minus" flips the input, so large makes the exponent very negative, driving toward .

Step 3 — Squash it: build the sigmoid

WHAT. Define the sigmoid:

WHY this exact recipe? We want a number that lives strictly between and . Look at the denominator :

  • It is always bigger than (since ), so . ✔ never reaches 1.
  • It is always finite, so . ✔ never reaches 0.

Reading each piece where it sits:

  • the ::: the "how much evidence against" term. When it is huge (very negative ), the whole fraction .
  • the ::: the guardrail that keeps the denominator from ever hitting , so we never blow up.
  • the outer ::: the flip that turns "big denominator" into "small output".

PICTURE. The lavender S-curve: floor at on the far left, ceiling at on the far right, passing through exactly at (the green dot — "maximum uncertainty"). This is the tamed version of Step 1's endless line.

Figure — Activation functions -  sigmoid, tanh

The mirror symmetry

WHY prove it? It says the S-curve is point-symmetric about the center dot — flipping 's sign reflects the output through . We will lean on this to understand the tails.

Derivation, step by step. First, plug into the definition — every place we see , write : Now multiply top and bottom by (a legal move, since ): Now compare with . Same thing. ✔

PICTURE. The S-curve with the point and its mirror marked — both sit symmetrically across the center dot.

Figure — Activation functions -  sigmoid, tanh

Step 4 — The slope: what does "steepness" mean, and why do we want it?

WHAT. The derivative of , written , is the slope of the S-curve at each point — how much the output rises for a tiny nudge in . The little tick mark ("prime") is shorthand for "differentiate with respect to "; that is, means , the same object written two ways.

WHY do we need it AT ALL? Backpropagation learns by asking "if I wiggle a hair, how much does the output move?" That sensitivity is precisely the slope. Flat spot → wiggling does nothing → no learning there.

PICTURE. Three little tangent segments drawn on the S-curve. In the far-left tail the segment is nearly flat. Near it is steep. In the far-right tail it flattens again. The slope is biggest in the middle.

Figure — Activation functions -  sigmoid, tanh

The two calculus rules we use, in pictures.

  • Chain rule — if a value depends on through an inner box, its slope is (slope of the outer wrapping) × (slope of the inner box). Picture a nudge (a tiny change in ) entering the inner box, coming out scaled, then scaled again by the outer wrapping: the two scalings multiply. Here the outer wrapping is "take the reciprocal / raise to ", the inner box is .
  • Power rule — for , a tiny change in changes by ; picture the reciprocal curve sloping downward (bigger → smaller ), so its slope is negative, and steeper when is small.
  • Slope of — by the fact in Step 2 () plus the chain rule on the inner : .

Now compute. Write and apply the chain rule (outer inner): The two minus signs cancel: Reading it: the numerator is our ingredient again; the squared denominator makes the slope shrink fast whenever is far from balanced.


Step 5 — The magic shortcut:

WHAT. We rewrite the slope using only itself — no exponentials.

WHY bother? During Backpropagation we have already computed in the forward pass. If the slope can be built from that stored number, we save the whole expensive recomputation. That is why this identity is beloved.

The trick, one line at a time. Split the numerator by writing :

Term-by-term of the final form:

  • ::: how "on" the neuron is (its output height).
  • ::: how much room is left before it saturates to 1 (and, by Step 3's mirror, this equals ).
  • their product ::: the slope is largest when both factors are balanced — i.e. at .

PICTURE. The lavender S-curve and, beneath it, the coral bump . The bump peaks exactly under the steepest part of the S, at , where its height is . Away from center, at least one factor is near , so the product collapses.

Figure — Activation functions -  sigmoid, tanh

Step 6 — Same picture, recentered: tanh

WHAT. Tanh is — literally the sigmoid, stretched and shifted.

WHY this reframing? Sigmoid's whole output is positive (it lives in ), which biases every gradient of a weight vector to share one sign and causes zig-zag updates. Recentering to fixes that. Reading the transform:

  • ::: double the input first → makes the S twice as steep.
  • ::: stretch the height from to .
  • ::: slide down so the range becomes , centered on .

Check the recentering is real. Recall . Multiply top and bottom by : . Then

Now derive its slope, from first principles. We differentiate with the same chain rule as Step 4 (outer inner, and ): Substitute (just rearranging ): Reading the factors: is "room above the floor ", is "room below the ceiling " — their product is the slope, biggest when tanh is at .

PICTURE. The lavender sigmoid and the mint tanh on the same axes. Tanh passes through the origin (not ), and near it climbs four times faster — its peak slope is .

Figure — Activation functions -  sigmoid, tanh

Step 7 — The edge cases: the flat tails (where learning dies)

WHAT. We check the extremes: , , and the exact center.

WHY. The reader must never meet a scenario we skipped. The tails are not a curiosity — they are the vanishing-gradient problem.

Case by case:

  • : , so . Then . Flat.
  • : , so . Then . Flat.
  • (center): , slope — the one and only peak.
  • Concrete tail number (): , so — nearly dead.

PICTURE. The slope bump again, but now with the two tails shaded: both ends hug the floor. An arrow marks the lonely peak of at the center. Chain many such tiny slopes in a deep net and the product races to .

Figure — Activation functions -  sigmoid, tanh

The one-picture summary

Everything at once: the endless input line (Step 1) → the exponential ingredient → the S-shaped squash into → its slope bump peaking at in the middle and dying in both tails → tanh as the recentered twin.

Figure — Activation functions -  sigmoid, tanh
Recall Feynman retelling — the whole walk in plain words

Start with a number that can be anything, huge or tiny — it's the weighted sum a neuron computes. I build one helper, , which is enormous when the number is very negative and almost nothing when it's very positive. I drop it into : the stops any blow-up, the flip turns "lots of evidence against" into a value near and "lots for" into a value near . That's the S-curve — a soft yes/no dial that reads when it can't decide, and it's mirror-symmetric: flipping the input reflects the output through . Then I ask, "how touchy is this dial?" — that's the slope. Doing the calculus (multiply the outer scaling by the inner scaling — the chain rule), an astonishing thing happens: the slope equals the dial's height times how much room it has left, . So it's touchiest right in the middle (slope ) and goes numb at both ends. Tanh is the same dial, doubled and slid down so it swings from to through zero, and it's four times as touchy at the center. The catch, seen in the very last picture: when a neuron is pushed to an extreme — far out in either tail — wiggling it barely changes the output, so its slope is nearly zero. Stack many such numb neurons and Backpropagation multiplies all those tiny slopes together, driving the gradient toward zero. That vanishing gradient is exactly why very deep networks built from sigmoid or tanh stop learning — and why we start weights small (to sit near the steep center) and often switch to non-saturating activations.


Connections