Md. Asif Uddin
    Problem I.3.B01

    Five activations at five points

    numeric▲△△

    All values rounded to 4 d.p.

    STATEMENT

    Evaluate sigmoid, tanh, ReLU, LeakyReLU with slope 0.010.01, and GELU at z∈{−2, −0.5, 0, 0.5, 2}z \in \{-2,\ -0.5,\ 0,\ 0.5,\ 2\}. Then read four structural facts off the table that no single value shows.

    GIVEN

    σ(z)=11+e−z,tanh⁡(z)=ez−e−zez+e−z,ReLU(z)=max⁡(0,z)\sigma(z) = \frac{1}{1+e^{-z}}, \qquad \tanh(z) = \frac{e^{z}-e^{-z}}{e^{z}+e^{-z}}, \qquad \mathrm{ReLU}(z) = \max(0, z)LeakyReLU(z)={zz>00.01zz≤0,GELU(z)=z Φ(z)\mathrm{LeakyReLU}(z) = \begin{cases} z & z > 0\\ 0.01z & z \le 0\end{cases}, \qquad \mathrm{GELU}(z) = z\,\Phi(z)

    with Φ\Phi the standard normal CDF.

    FIND

    A 5×55\times 5 table of values, and four properties visible only across it.

    STRATEGY

    Compute the two exponential families first, since tanh follows from sigmoid; the two rectifiers need no arithmetic at all; GELU needs Φ\Phi.

    SOLUTION

    Step 1 — sigmoid. σ(−2)=1/(1+e2)=1/8.3891=0.1192\sigma(-2) = 1/(1+e^{2}) = 1/8.3891 = 0.1192. By the symmetry σ(−z)=1−σ(z)\sigma(-z) = 1 - \sigma(z), σ(2)=0.8808\sigma(2) = 0.8808 without further work. σ(0)=1/2\sigma(0) = 1/2 exactly. σ(−0.5)=1/(1+e0.5)=1/2.6487=0.3775\sigma(-0.5) = 1/(1+e^{0.5}) = 1/2.6487 = 0.3775, so σ(0.5)=0.6225\sigma(0.5) = 0.6225.

    Step 2 — tanh from sigmoid. Using tanh⁡(z)=2σ(2z)−1\tanh(z) = 2\sigma(2z) - 1: tanh⁡(0.5)=2σ(1)−1=2(0.7311)−1=0.4621\tanh(0.5) = 2\sigma(1) - 1 = 2(0.7311) - 1 = 0.4621, and tanh⁡(2)=2σ(4)−1=2(0.9820)−1=0.9640\tanh(2) = 2\sigma(4) - 1 = 2(0.9820) - 1 = 0.9640. Odd symmetry gives the negatives.

    Step 3 — the rectifiers. No arithmetic. ReLU zeroes the negatives and copies the positives; LeakyReLU scales the negatives by 0.010.01.

    Step 4 — GELU. Φ(−2)=0.0228\Phi(-2) = 0.0228, so GELU(−2)=(−2)(0.0228)=−0.0455\mathrm{GELU}(-2) = (-2)(0.0228) = -0.0455. Φ(0)=0.5\Phi(0) = 0.5 so GELU(0)=0\mathrm{GELU}(0) = 0. Φ(2)=0.9772\Phi(2) = 0.9772, giving 1.95451.9545.

    The table.

    zzσ\sigmatanh⁡\tanhReLULeakyReLUGELU
    −2.0-2.00.11920.1192−0.9640-0.96400.00000.0000−0.0200-0.0200−0.0455-0.0455
    −0.5-0.50.37750.3775−0.4621-0.46210.00000.0000−0.0050-0.0050−0.1543-0.1543
    0.00.00.50000.50000.00000.00000.00000.00000.00000.00000.00000.0000
    0.50.50.62250.62250.46210.46210.50000.50000.50000.50000.34570.3457
    2.02.00.88080.88080.96400.96402.00002.00002.00002.00001.95451.9545

    Four structural facts.

    Only sigmoid fails to pass zero to zero. σ(0)=0.5\sigma(0) = 0.5. Every other column has 0↦00 \mapsto 0. A layer of sigmoids therefore emits a nonzero mean even from centred input, and that offset compounds with depth — the historical reason tanh replaced sigmoid in hidden layers.

    Sigmoid and tanh are bounded; the rectifiers are not. At z=2z = 2 the bounded pair are already at 0.880.88 and 0.960.96, close to their ceilings, while ReLU returns 22 and would return 200200 at z=200z = 200. Boundedness is what causes saturation and also what prevents blow-up.

    GELU is not monotonic. From z=−2z = -2 to z=−0.5z = -0.5 the output falls from −0.0455-0.0455 to −0.1543-0.1543. No other column does this. GELU is a soft gate, not a soft switch, and this dip is where its behaviour genuinely differs from a smoothed ReLU.

    GELU is close to ReLU where it matters and different where it does not. At z=2z = 2 the two differ by 0.04550.0455; at z=−0.5z = -0.5 they differ by 0.15430.1543. The whole difference lives in a band around the origin, which is exactly where gradients are decided.

    Answer

    The 5×55\times5 table above. The four properties: sigmoid alone has φ(0)≠0\varphi(0) \neq 0; the bounded pair saturate while the rectifiers do not; GELU is non-monotonic on (−∞,−0.75)(-\infty, -0.75) roughly; and GELU and ReLU agree away from the origin and differ only near it.

    Check — numeric · i-3-b01-activation-values.py
    def sigmoid(z): return 1.0 / (1.0 + exp(-z))
    def gelu(z):    return 0.5 * z * (1.0 + erf(z / sqrt(2.0)))

    Prints the table above, to 4 d.p.

    Executed in CI. The digits above are the digits it printed.

    Check — sanity

    The symmetries hold. σ(−2)+σ(2)=0.1192+0.8808=1.0000\sigma(-2) + \sigma(2) = 0.1192 + 0.8808 = 1.0000 exactly, as σ(−z)=1−σ(z)\sigma(-z) = 1 - \sigma(z) requires. And tanh⁡(−2)=−tanh⁡(2)\tanh(-2) = -\tanh(2) to every printed digit.

    The identity tanh⁡(z)=2σ(2z)−1\tanh(z) = 2\sigma(2z) - 1 checks out. At z=0.5z = 0.5: 2σ(1)−1=2(0.7311)−1=0.46222\sigma(1) - 1 = 2(0.7311) - 1 = 0.4622, against tanh⁡(0.5)=0.4621\tanh(0.5) = 0.4621. The last digit differs by rounding of the intermediate, not by error.

    GELU is between 00 and zz for z>0z > 0. 0<0.3457<0.50 < 0.3457 < 0.5 and 0<1.9545<20 < 1.9545 < 2. Since Φ∈(0,1)\Phi \in (0,1) and GELU=zΦ(z)\mathrm{GELU} = z\Phi(z), that must hold — and it is the fastest way to catch a sign or scale slip.

    Where this breaks

    Every value here assumes the activation is applied to a scalar independently. That is what “elementwise” means, and it is why one table of five numbers characterises the function completely. Softmax is not elementwise — its output at one coordinate depends on all of them — so no such table exists for it, and it belongs to Chapter I.4 with the losses rather than here with the activations.

    Variation

    Add SiLU (also called Swish), z⋅σ(z)z\cdot\sigma(z), as a sixth column. Compare it with GELU at all five points and say where the two differ most.

    Draws on