Inside the feed-forward: activation functions from Sigmoid to SwiGLU #Activationfunctions#SwiGLU#GELU
Six activation functions on one chart: why each replaced the last, where each is still used, and why a TFM uses SwiGLU.
Transformer foundationsEncoder architecture
An activation function decides what a neuron passes on. Its slope matters as much as its shape: backpropagation multiplies slopes layer by layer, so a function that flattens out starves deep networks of gradient.
| Function | Output range | Main idea | Weakness | Still used for |
|---|---|---|---|---|
| Sigmoid | 0 … 1 | probability-like squash | slope ≤ 0.25, saturates | output probabilities (e.g. a fraud head), LSTM/GRU gates |
| Tanh | −1 … 1 | zero-centred squash | saturates at both ends | RNN hidden states |
| ReLU | 0 … ∞ | keep positives, cut negatives | “dying” neurons below 0 | CNNs, simple MLPs |
| SiLU / Swish | ≈ −0.28 … ∞ | x gated by σ(x), smooth | slightly costlier | EfficientNet, YOLO, the SwiGLU gate |
| GELU | ≈ −0.17 … ∞ | x gated by Φ(x) | slightly costlier | BERT, GPT-2/3, ViT |
| SwiGLU | — | two learned branches, SiLU gate | one extra weight matrix | LLaMA, PaLM, TFM feed-forward |
The evolution in one line: squash (Sigmoid, Tanh) → don't squash positives (ReLU) → don't cut negatives either, gate them smoothly (SiLU, GELU) → let the network learn the gate (SwiGLU).
In a transaction foundation model: SwiGLU sits in every feed-forward block of the encoder; Sigmoid survives at the very end, turning the fraud head's score into a probability.
Transcript
Six activation functions on one chart, in the order each replaced the last. First, Sigmoid squashes every input between zero and one, like a probability.
But it flattens at both ends, so the gradient fades layer after layer: the vanishing gradient. Today it mostly turns a fraud score into a probability.
Tanh has the same S shape, centred on zero and steeper in the middle, so learning starts faster.
It still flattens at both ends, though, so deep networks still lose their gradient. It survives in the hidden states of recurrent networks.
ReLU keeps positives and cuts negatives. On the positive side the slope is exactly one, so the gradient stays full however deep you go.
The catch: below zero the slope is zero, and a neuron stuck there stops learning. Even so, it became the default in convolutional and simple feed-forward networks.
SiLU, also called Swish, brings Sigmoid back as a soft gate on the input itself: positives pass, and negatives are dimmed instead of cut.
It is smooth everywhere, with a small dip below zero, and gradients keep flowing. This curve is also the gate inside SwiGLU.
GELU uses the same gating idea, with the normal distribution as the gate: the input times the chance that a normal value falls below it.
It is almost the same curve as SiLU, and the default in BERT, in GPT two and three, and in many TFM encoders.
SwiGLU is not a new curve but a new wiring. The feed-forward layer gets two learned branches: one makes content, the other passes through SiLU and turns each value up or down.
The network learns its own gate, which is why LLaMA, PaLM and our TFM use it.
From squashing, to keeping positives, to smooth gates, to a gate the network learns for itself.
Sources
- Searching for Activation Functions — Prajit Ramachandran, Barret Zoph, Quoc V. Le, arXiv, 2017
- Gaussian Error Linear Units (GELUs) — Dan Hendrycks, Kevin Gimpel, arXiv, 2016
- GLU Variants Improve Transformer — Noam Shazeer, arXiv, 2020