Softplus is a ReLU with the kink rounded off, and its derivative is the sigmoid. SiLU and GELU multiply z by a soft gate instead of a hard one, dip just below zero, and are the activations of modern transformers. Each derived, minimised and coded.
DL01.3.3L2 Intermediate25 minIn review (what this means)
The maths and code on this page are checked by automated tests on every change, but an independent reader has not signed it off yet. Spot a mistake or a confusing step? Tell us.
Derive that the derivative of softplus is the sigmoid, and bound how far softplus lies above ReLU.
Write ReLU, SiLU and GELU as z times a gate, and derive the derivatives of SiLU and GELU.
Locate the minima of SiLU and GELU numerically and explain why both functions are not monotone.
Implement the three activations from scratch with scipy.special.erf, and measure the error of the tanh approximation of GELU.
The question
BERT, one of the first large transformer language models, replaced ReLU by a function called GELU, which is ReLU with its corner sanded smooth and a small dip below zero. What is that function, where exactly is its dip, and what does a hidden unit gain from it on the backward pass?
From the last lesson
1. What value do libraries use for the derivative of ReLU at exactly \({z = 0}\)?
Show answer
0, the subgradient of smallest size; PyTorch’s rule for convex functions picks it.
2. Why does a first-layer ReLU unit that is negative on every training input never recover?
Show answer
Its slope is 0 on every example, so the gradients for all its weights and its bias are exactly zero, and gradient descent never changes them.
Intuition
ReLU’s corner and its shut gate are its two weak points. Three smooth activations keep ReLU’s shape far from zero and change it only near zero.
DL01.3.3-F1
Softplus rounds off the kink and stays above ReLU. SiLU and GELU also round it off, but dip a little below zero before rising.
Softplus is the smooth curve closest in spirit to ReLU: always positive, always rising. SiLU (also called Swish) and GELU take another route. They keep the idea of a gate, but let it open gradually. The price is a small dip below zero; the gain is that a slightly negative input still sends a gradient back.
Build it up
Step 1. ReLU as a gate. Write \({\operatorname{relu}(z) = z \cdot 1[z > 0]}\), where \({1[z > 0]}\) is 1 when the condition holds and 0 otherwise. The input \(z\) passes, multiplied by a gate that is either open or shut.
Step 2. Soften the gate. Replace the step by a smooth curve that rises from 0 to 1. With the sigmoid as gate, \({z\,\sigma(z)}\) is SiLU. With the standard normal cumulative distribution function \(\Phi\) as gate, \({z\,\Phi(z)}\) is GELU. \(\Phi(z)\) is the probability that a standard normal variable is at most \(z\); it rises from 0 to 1 like the sigmoid, a little more steeply.
DL01.3.3-F2
Three gates. ReLU’s snaps shut at 0; SiLU’s and GELU’s close smoothly, GELU’s a little faster.
Step 3. Why a dip. For a negative \(z\) the soft gate is small but not zero, so \({z \times \text{gate}}\) is a small negative number. Far to the left the gate dies away faster than \(z\) grows, and the product returns to 0. In between it must reach a lowest point.
Step 4. Softplus differently. Softplus is not a gate times \(z\). Its derivative is a gate: softplus is the function whose slope is \({\sigma(z)}\), so it climbs from slope 0 to slope 1 without ever taking a corner.
where \({\Phi(z) = \tfrac12\big(1 + \operatorname{erf}(z/\sqrt2)\big)}\), with derivative \({\varphi(z) = e^{-z^2/2}/\sqrt{2\pi}}\), the standard normal density.
The middle step divides top and bottom by \(e^{z}\). To compare with ReLU, write \({1 + e^{z} = e^{\max(0, z)}\,(1 + e^{-\abs{z}})}\), which holds for either sign of \(z\). Taking logs,
The gap \({\ln(1 + e^{-\abs{z}})}\) is largest, \({\ln 2 \approx 0.693}\), at \({z = 0}\), and it shrinks like \({e^{-\abs{z}}}\) on both sides. This form is also the stable way to compute softplus.
SiLU’s derivative and minimum. By the product rule and \({\sigma' = \sigma(1 - \sigma)}\),
Since \({\sigma(z) > 0}\), the slope is zero exactly where \({1 + z(1 - \sigma(z)) = 0}\). That needs \({z < 0}\), and has no solution in elementary functions; solving it numerically gives \({z^\ast \approx -1.278}\). At that point \({\sigma(z^\ast) = 1 + 1/z^\ast}\), so the lowest value is
For \({z < z^\ast}\) the slope is negative and the function falls; after \(z^\ast\) it rises. So SiLU is not monotone, unlike every activation of the two lessons before.
GELU’s derivative and minimum. Since \({\Phi' = \varphi}\),
GELU’s dip is shallower than SiLU’s and closer to zero.
One identity, both functions. Each gate \(g\) satisfies \({g(z) + g(-z) = 1}\) (for the sigmoid, \({\sigma(-z) = 1 - \sigma(z)}\); for \(\Phi\), by the symmetry of the normal density). Then for \({f(z) = z\,g(z)}\),
Differentiating gives \({f'(z) + f'(-z) = 1}\): the slope at \(-z\) is 1 minus the slope at \(z\). So the negative dip of each slope below zero mirrors an overshoot above 1. GELU’s slope is lowest at \({z = -\sqrt2}\), where its own derivative \({\varphi(z)\,(2 - z^2)}\) is zero, and equals \({\Phi(-\sqrt2) - \sqrt2\,\varphi(\sqrt2) \approx -0.129}\); it peaks at \({1.129}\) at \({z = \sqrt2}\).
DL01.3.3-F5
The slopes. Softplus’s slope is the sigmoid, between 0 and 1. The slopes of SiLU and GELU go a little below 0 on the left and above 1 on the right, by the same amounts.
A faster GELU. Hendrycks and Gimpel give two approximations that avoid \(\operatorname{erf}\):
and \({z\,\sigma(1.702\,z)}\), a SiLU with a steeper gate. Measured on a fine grid, the tanh form is never more than about \({4.7 \times 10^{-4}}\) from the exact GELU, the sigmoid form about \({0.020}\).
DL01.3.3-F6
The error of each approximation. Mind the scales: the tanh form is about 40 times closer.
Why transformers use them. The case is empirical, not a theorem. Hendrycks and Gimpel found GELU ahead of ReLU and ELU on every vision, language and speech task they tried; BERT adopted it, following GPT, and it became the default in transformer blocks, which DL05.4 builds. The smooth slope and the small gradient for slightly negative inputs are the usual explanations offered, stated here without proof.
Worked example
A unit at \({z = -1}\). What does each activation output, and what slope does it pass back?
DL01.3.3-F3
Values (vermillion) and slopes (green) at \({z = -1}\). Only ReLU passes back exactly nothing.
Use \({\sigma(-1) = 1/(1 + e) = 0.2689}\), \({\Phi(-1) = 0.1587}\) and \({\varphi(1) = 0.2420}\).
A unit sitting at \({z = -1}\) is shut under ReLU and learns nothing from this example. Under SiLU it passes back about 7% of the signal; under GELU about 8%, with the opposite sign, because \({z = -1}\) is to the left of GELU’s minimum, where GELU falls as \(z\) rises.
Code
From scratch, with scipy.special.erf for \(\Phi\). Softplus uses the stable form derived above.
import numpy as npfrom scipy.special import erf, expitdef softplus(z): return np.maximum(z, 0) + np.log1p(np.exp(-np.abs(z)))def silu(z): return z * expit(z)def dsilu(z): s = expit(z);return s * (1+ z * (1- s))def Phi(z): return0.5* (1+ erf(z / np.sqrt(2)))def phi(z): return np.exp(-z **2/2) / np.sqrt(2* np.pi)def gelu(z): return z * Phi(z)def dgelu(z): return Phi(z) + z * phi(z)z = np.linspace(-6, 6, 241)h =1e-6for f, df in ((softplus, expit), (silu, dsilu), (gelu, dgelu)): err = np.max(np.abs((f(z + h) - f(z - h)) / (2* h) - df(z)))print(f"{f.__name__:8s} largest slope error {err:.1e}")print("value and slope at z = -1:")for f, df in ((softplus, expit), (silu, dsilu), (gelu, dgelu)):print(f" {f.__name__:8s}{f(-1.0):+.4f}{df(-1.0):+.4f}")
softplus largest slope error 5.1e-10
silu largest slope error 6.8e-10
gelu largest slope error 5.7e-10
value and slope at z = -1:
softplus +0.3133 +0.2689
silu -0.2689 +0.0723
gelu -0.1587 -0.0833
The minima, found with scipy.optimize.minimize_scalar on the interval from \(-3\) to 0, and checked against the formulas derived above:
from scipy.optimize import minimize_scalarfor f in (silu, gelu): r = minimize_scalar(f, bounds=(-3, 0), method="bounded", options={"xatol": 1e-10})print(f"{f.__name__}: minimum {r.fun:.4f} at z = {r.x:.4f}")r_silu = minimize_scalar(silu, bounds=(-3, 0), method="bounded", options={"xatol": 1e-10})r_gelu = minimize_scalar(gelu, bounds=(-3, 0), method="bounded", options={"xatol": 1e-10})print("SiLU: min value equals z* + 1:", np.isclose(r_silu.fun, r_silu.x +1))print("GELU slope at -sqrt(2):", round(float(dgelu(-np.sqrt(2))), 4))
silu: minimum -0.2785 at z = -1.2785
gelu: minimum -0.1700 at z = -0.7518
SiLU: min value equals z* + 1: True
GELU slope at -sqrt(2): -0.1289
Last, the two quick forms of GELU, measured against the exact one on a fine grid:
tanh form: largest error 4.73e-04 at |z| = 2.70
sigmoid form: largest error 0.0203 at |z| = 2.27
There is no GELU in SciPy, so the check against a library is the softplus one above (np.logaddexp(0, z) computes \({\ln(e^0 + e^z)}\) safely). PyTorch, from DL01.7 on, has torch.nn.GELU, whose approximate="tanh" option is the tanh form.
Explore
The module’s interactive, the activation explorer, lives in lesson DL01.3.4. Set the mean to \(-1\) and the spread to 1, then switch between ReLU, SiLU and GELU: ReLU leaves 25 of the 30 units dead, while SiLU and GELU leave none and still pass back a mean slope of about 0.18 and 0.13.
Pitfalls
DL01.3.3-F4
Wrong beside right. Adding \(e^{z}\) to 1 loses its digits, and below about \({z = -37}\) all of them.
“Softplus is just log(1 + exp(z)).”
Mathematically yes; in floating point, no. For large positive \(z\), exp(z) overflows. For very negative \(z\), \({1 + e^{z}}\) rounds to 1 and the answer comes out as exactly 0 instead of about \(e^{z}\). Use np.logaddexp(0, z), or \({\max(0, z) + \ln(1 + e^{-\abs{z}})}\) with np.log1p.
“GELU and SiLU are the same function.”
They have the same form, \(z\) times a gate, with different gates. GELU’s gate \(\Phi\) is steeper than the sigmoid, so GELU’s dip is shallower (\(-0.170\) against \(-0.278\)) and nearer zero. Even the sigmoid approximation of GELU, \({z\,\sigma(1.702z)}\), uses a different scale inside the gate.
“A smooth version of ReLU is always better.”
Goodfellow et al. report that softplus, though smooth, did worse than ReLU in comparisons, and they discourage it. Smoothness alone is not the point; GELU’s and SiLU’s record is an empirical one, on particular architectures.
within about \({4.7 \times 10^{-4}}\) of the exact GELU everywhere.
Exercises
1.★ Compute softplus, SiLU and GELU at \({z = 2}\), and their slopes there, using \({\sigma(2) = 0.8808}\), \({\Phi(2) = 0.9772}\) and \({\varphi(2) = 0.0540}\).
2.★★ Show that \({\operatorname{softplus}(z) - \operatorname{softplus}(-z) = z}\), and use it to show that the slope of softplus at \(-z\) is 1 minus its slope at \(z\).
Differentiating both sides with the chain rule gives \({\operatorname{softplus}'(z) + \operatorname{softplus}'(-z) = 1}\), that is \({\sigma(z) + \sigma(-z) = 1}\).
3.★★★ Swish is \({z\,\sigma(\beta z)}\) with \({\beta > 0}\). Show that its minimum value is \({\operatorname{silu}(z^\ast)/\beta}\), where \(z^\ast\) is SiLU’s minimiser, and find where it is reached. What happens to the dip as \({\beta \to \infty}\)?
Show solution
Substitute \({u = \beta z}\): \({z\,\sigma(\beta z) = \tfrac1\beta\,u\,\sigma(u) = \tfrac1\beta\operatorname{silu}(u)}\). As \(z\) runs over the real line so does \(u\), so the minimum is \({\operatorname{silu}(z^\ast)/\beta \approx -0.278/\beta}\), reached at \({u = z^\ast}\), that is \({z = z^\ast/\beta \approx -1.278/\beta}\). As \(\beta\) grows the dip becomes shallower and moves to 0, and Swish tends to ReLU; with \({\beta = 1.702}\) it is the sigmoid approximation of GELU.
Summary card
Soften ReLU’s corner or its gate, and a negative input still sends a gradient back.
DL01.3.3-F1
Smooth corner, soft gate.
\({\operatorname{softplus}(z) = \ln(1 + e^{z})}\), slope \(\sigma(z)\), at most \(\ln 2\) above ReLU.
\({\operatorname{silu}(z) = z\,\sigma(z)}\), minimum \(-0.278\) at \({z \approx -1.278}\).
\({\operatorname{gelu}(z) = z\,\Phi(z)}\), minimum \(-0.170\) at \({z \approx -0.752}\).
Gated forms obey \({f'(z) + f'(-z) = 1}\); the tanh form of GELU is within \({4.7 \times 10^{-4}}\).
Sources and next steps
Sources. Each was opened and checked against this lesson on 15 November 2026.
Dan Hendrycks and Kevin Gimpel, Gaussian Error Linear Units (GELUs), arXiv:1606.08415, version 5 of June 2023. Section 2 defines \({x\Phi(x)}\), gives the tanh and \({x\sigma(1.702x)}\) approximations and names the SiLU \({x\sigma(x)}\); section 4 says the tanh form was used in every experiment; the abstract and section 5 report GELU ahead of ReLU and ELU on all tasks tried; appendix B says GELU became the default activation of state-of-the-art transformers after BERT and GPT.
Prajit Ramachandran, Barret Zoph and Quoc V. Le, Searching for Activation Functions, 2017: Swish, \({x \cdot \operatorname{sigmoid}(\beta x)}\), of the third exercise.
Ian Goodfellow, Yoshua Bengio and Aaron Courville, Deep Learning, chapter 6, MIT Press, 2016. Section 6.3.3 introduces softplus as a smooth rectifier, reports that it did worse than ReLU in comparisons and says its use is generally discouraged.
Simon J. D. Prince, Understanding Deep Learning, MIT Press, 2023. Figure 3.13c draws softplus, GELU and SiLU, and the notes to chapter 3 trace them and Swish to their papers.
Jacob Devlin, Ming-Wei Chang, Kenton Lee and Kristina Toutanova, BERT, NAACL 2019. Appendix A.2 says that BERT uses a GELU activation rather than the standard ReLU, following OpenAI GPT.