Part VIII — Neural Network Fundamentals, Backpropagation & Optimizers · Chapter 3

Activation functions: Sigmoid, Tanh, ReLU, GeLU & Swish

Hook

The perceptron's sign function gives a hard yes/no. What if a neuron needs to answer "mostly yes," or needs a slope to learn from at all?

Intuition
x = -2.00 — step=0, sigmoid=0.12, tanh=-0.96, ReLU=0.00

Drag the input across all four at once. Step jumps instantly between 0 and 1 — no in-between. Sigmoid and tanh curve smoothly through the middle. ReLU — short for Rectified Linear Unit — does something different again: it's flat at exactly 0 for every negative input, then rises like a plain diagonal line.

Formalize

An activation function turns a neuron's raw weighted sum into its output. Four of the most common:

step(x)={0x<01x0,σ(x)=11+ex,tanh(x),ReLU(x)=max(0,x)\text{step}(x) = \begin{cases} 0 & x<0 \\ 1 & x\ge 0 \end{cases}, \quad \sigma(x) = \frac{1}{1+e^{-x}}, \quad \tanh(x), \quad \text{ReLU}(x) = \max(0,x)
  • xx — the neuron's raw weighted sum, before activation.
  • step(x)\text{step}(x) — the perceptron's hard yes/no rule: 0 below zero, 1 at or above it.
  • σ(x)\sigma(x) — the sigmoid, a smooth curve ranging over (0,1)(0,1).
  • tanh(x)\tanh(x) — a smooth curve ranging over (1,1)(-1,1).
  • ReLU(x)\text{ReLU}(x) — zero for negative inputs, and equal to xx itself for positive ones.
  1. Step has no usable slope

    Step is what the perceptron used — but it's flat everywhere except one point, so its slope is useless for learning by gradient.

  2. Sigmoid and tanh are smooth substitutes

    Both curve smoothly through the middle, giving a real, usable slope everywhere.

  3. ReLU trades smoothness for simplicity

    It throws out smoothness for something else: dead simple to compute, and its slope never shrinks to nothing on the positive side.

Play
x = 0.50 — step=1, sigmoid=0.62, tanh=0.46, ReLU=0.50

Watch what happens right around x=0x=0. Step is discontinuous there. Sigmoid and tanh are at their steepest — right where they're most useful for learning. ReLU has a kink: flat on the left, a clean 45° line on the right.

Worked example

Tanh isn't a fourth independent shape — it's sigmoid, rescaled: tanh(x)=2σ(2x)1\tanh(x) = 2\sigma(2x)-1.

  1. Evaluate sigmoid at 2x

    At x=1x=1: σ(2)=1/(1+e2)0.881\sigma(2) = 1/(1+e^{-2}) \approx 0.881.

  2. Rescale it into tanh's range

    2(0.881)1=0.7622(0.881)-1 = 0.762 — exactly tanh(1)\tanh(1). Sigmoid ranges over (0,1)(0,1); tanh stretches and shifts that same curve to range over (1,1)(-1,1).

Checkpoint

Drag the input until sigmoid’s output reaches 0.9 (within 0.02).

x = -2.00 — sigmoid = 0.119
Drag the input to try it
Summary
σ(x)=11+ex,ReLU(x)=max(0,x)\sigma(x) = \frac{1}{1+e^{-x}}, \qquad \text{ReLU}(x) = \max(0,x)

Every neuron in every network from here on is a weighted sum fed through one of these. The choice matters enormously once networks get deep — the next chapters are about exactly what goes wrong (or right) when you stack many of these on top of each other.