Notes

GELU

Think of an activation function as a gate between neural-network layers: it decides how strongly each computed feature should continue forward. GELU makes that gate gradual rather than sharply open-or-closed, which gives deep models a smooth way to keep useful weak signals while damping less useful ones.

How GELU shapes a signal

Gaussian Error Linear Unit applies the function GELU(x) = xΦ(x), where Φ(x) is the cumulative probability of a standard normal distribution up to x. Intuitively, each value x is multiplied by a probability that rises smoothly from near zero to one. Large positive inputs pass through almost unchanged; values near zero are gently scaled; negative values are reduced but not abruptly erased. This differs from ReLU, which outputs exactly zero for every negative input.

Why smoothness helps training

Backpropagation needs derivatives to carry learning signals through many layers. GELU’s derivative changes smoothly, rather than jumping at zero as ReLU’s does. That gives optimizers such as Adam a less abrupt local landscape to navigate and avoids ReLU’s “dead neuron” behavior, where a unit stuck on the negative side produces zero output and zero gradient. GELU does not guarantee stable training by itself—bad initialization, excessive learning rates, or missing normalization can still make loss diverge—but it is a reliable component of modern deep blocks.

Where it appears in practice
  • BERT and many transformer-style feed-forward blocks use GELU after expanding hidden features, commonly alongside LayerNorm and residual connections.
  • In PyTorch, torch.nn.GELU() offers an exact implementation and a faster tanh-based approximation. The approximation is useful when activation cost matters across many layers.
  • At inference, GELU remains active; unlike dropout, it does not change behavior between training and evaluation.

Its extra arithmetic costs more than ReLU, but in large transformer-like networks that cost is usually small relative to matrix multiplications. GELU is valued because its gentle gating preserves expressive nonlinearity without introducing a hard cutoff into the network’s gradient flow.

GELU (Gaussian Error Linear Unit) is a smooth activation function that scales each input by its probability under a standard Gaussian distribution, approximated as x·Φ(x). Unlike ReLU’s hard zero threshold, GELU smoothly suppresses negative and small values while retaining useful signal. It matters because its smooth gradients and selective gating support stable optimization and strong performance in deep networks, particularly transformer architectures.

Imagine a dimmer switch rather than a simple on/off light switch. A basic AI network often needs to decide which pieces of information to pass along. GELU, short for Gaussian Error Linear Unit, is a gentle kind of “dimmer” used for that job.

It lets strong, useful signals through clearly, while softly reducing weak or less relevant ones instead of cutting them off abruptly. This makes a network’s decisions feel less harsh and can help it learn subtle patterns, such as the meaning of a word depending on the words around it. GELU is especially common in transformer-based language models, where many small clues need to be weighed together.