Log inStart free
LESSON 5.04 · 6 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

Sigmoid and tanh

Watch a gradient shrink as it flows back through sigmoid and tanh layers.


Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 5.04 · ACTIVATION BAYSIGMOID · F(Z) FROM 0 TO 1
01
Stage 1 of 6 · The curves
The sigmoid maps any z to between 0 and 1. tanh maps z to between −1 and 1.
Explain it simply

The S-shaped line shows what one neuron does to its input z. The sigmoid squeezes every number to between 0 and 1. A big z gives almost 1, and a big negative z gives almost 0. The dashed line is tanh, so you can compare.

The sigmoid curve rises from 0 to 1. Tanh is dashed.

z, inputweightsf(z)slope, gradient
10.25−10−6−3036z →σ(z)tanh, dashed1.18−1.11−1.020.94−0.831.00Ly 0.91xsigmoid: f(z) and its slopea chain of 6 neuronsσ(z) = 1 / (1 + e^−z)10.25−10−6−3036z →σ(z)tanh, dashed1.18−1.11−1.020.94−0.831.00Ly 0.91xsigmoid: f(z) and its slopea chain of 6 neuronsσ(z) = 1 / (1 + e^−z)
Toy: x = 1 through 3, 6 or 9 one-neuron layers; seeded random weights
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
σ(z)=11+e−ztanh⁡(z)=2 σ(2z)−1\sy{a}{out}{\sigma(z)} = \frac{1}{1+e^{-\sy{z}{data}{z}}} \qquad \tanh(z) = 2\,\sigma(2z) - 1
σ(0)=0.50, σ(2)=0.88, σ(−2)=0.12\sigma(0) = 0.50,\ \sigma(2) = 0.88,\ \sigma(-2) = 0.12

The sigmoid squashes z; tanh is a stretched, shifted sigmoid.

Common mix-ups

MYTHTanh has no vanishing gradients, because its slope reaches 1.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01At weight size 1, does tanh give layer 1 a larger or a smaller share of the gradient?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.