GELU and Swish Activations
Modern transformer architectures mostly abandoned ReLU's hard corner for smooth activations that let a small amount of negative input through, weighted by how negative it is, instead of chopping it off entirely.
Prerequisites: ReLU, Dying Units and Leaky Variants, Activation Functions
ReLU makes an all-or-nothing decision at zero: pass the input through unchanged, or kill it completely, with a sharp corner exactly at the boundary. GELU and Swish replace that hard corner with a smooth curve that makes a soft, probabilistic-flavored decision instead — mostly passing through positive inputs, mostly killing negative ones, but blending smoothly through the region near zero rather than snapping between the two. That smoothness turns out to matter for how well very deep networks, especially transformers, train.
The analogy: a bouncer with judgment versus a strict age cutoff
ReLU is a bouncer with a rigid rule: exactly 21 years old and older gets in, everyone younger is turned away, full stop, no exceptions, no partial admittance. GELU is a bouncer using judgment: someone clearly 30 gets in without hesitation, someone clearly 12 is turned away without hesitation, but someone right around the boundary — 20, 21, 22 — gets a probability-weighted decision that blends smoothly from "mostly no" to "mostly yes" rather than flipping instantly at one exact cutoff. That smooth blending region is exactly where GELU and ReLU differ, and it is also exactly the region where ReLU's derivative discontinuity caused problems.
The maths
GELU multiplies the input by the probability that a standard normal random variable is less than that input:
In plain English: scale the input down by how "likely" it is to be a large positive value under a standard bell curve — large positive gets multiplied by something close to (pass through almost unchanged), large negative gets multiplied by something close to (mostly killed), and values near zero get a smooth, partial pass-through instead of a hard cutoff.
Swish (also called SiLU) uses a similar idea with the logistic sigmoid instead of the normal CDF:
In plain English: same "scale the input by a smooth 0-to-1 gate" idea, just using the sigmoid curve as the gate instead of the normal CDF — the two functions look almost identical in shape and both smoothly interpolate ReLU's hard corner.
Crucially, unlike ReLU, both have a nonzero derivative almost everywhere, including for negative inputs — so a unit that currently outputs something small and negative still receives a usable, nonzero gradient, sidestepping the dying-unit problem from ReLU, Dying Units and Leaky Variants without needing an explicit leak parameter.
Worked example 1: comparing outputs at a few points
At (clearly positive): ReLU gives ; GELU gives ; Swish gives — all three close to , as expected for confidently positive inputs. At (moderately negative): ReLU gives exactly ; GELU gives ; Swish gives — both let a small negative signal through where ReLU kills it outright. At (strongly negative): GELU gives — essentially zero, just like ReLU, showing the smoothness is concentrated near the boundary, not spread everywhere.
Worked example 2: the derivative near zero
At exactly : ReLU's derivative jumps discontinuously from (just below zero) to (just above zero) — a genuine kink with no single well-defined value at the point itself. GELU's derivative at is , smoothly connecting the region below to the region above, with no discontinuity anywhere. This matters most for gradient-based optimizers operating near that boundary — a discontinuous derivative can make optimization landscapes locally jagged in a way a smooth derivative does not.
The sigmoid gate inside Swish is exactly this logistic curve — drag its steepness in the explorer above and watch the transition sharpen toward ReLU's hard corner or soften into a gentler blend, which is the entire tunable difference between the two families.
GELU and Swish replace ReLU's hard zero cutoff with a smooth, probability-flavored gate that multiplies the input by a value between 0 and 1, giving both a nonzero gradient almost everywhere — including for moderately negative inputs — which avoids ReLU's dying-unit failure mode without an explicit leak parameter, at the cost of slightly more computation per unit.
What this means in practice
GELU is the default activation in most modern transformer architectures (BERT, GPT-family models, and their descendants), largely because empirical results on very deep networks favored its smoothness. Swish and GELU perform similarly in most settings, and the choice between them is often more a matter of what a given codebase or paper standardized on than a large practical difference — unlike the ReLU-versus-Leaky-ReLU choice, where dying units are a concrete, diagnosable failure mode being fixed.
It's a common misconception that GELU and Swish are strictly "better" than ReLU in every setting. They cost more to compute per unit (a normal CDF or sigmoid evaluation versus a single comparison), and for many smaller or non-transformer architectures the difference in final accuracy is negligible — the choice matters most in the very deep, very large models where the smoothness genuinely changes optimization behavior, not as a universal upgrade.
Practice in interviews
Further reading
- Hendrycks & Gimpel, Gaussian Error Linear Units (GELUs) (2016)
- Ramachandran, Zoph & Le, Searching for Activation Functions (2017)