The problem: without them, a hundred layers equal one layer
A neural network layer does two things, in this order. First a matrix multiplication, which mixes the components of the input, each output becomes a weighted average of all the inputs, as explained in How to read the formulas. Then an activation function, applied slot by slot, with no mixing at all.
That second step looks decorative. It is indispensable, and the reason fits on one line: chaining two matrix multiplications, , amounts to multiplying once by the single table . Two purely linear layers stacked are therefore exactly equivalent to one, and so are a thousand of them. The full argument, biases included, is worked through in The perceptron.
Put differently: depth buys a network nothing until you slip in, between two layers, an operation no matrix can imitate. That is the job of the activation function, and all it has to be is non-linear, anything but a plain rescaling.
It mixes nothing. It takes one number and returns one number, regardless of its neighbours. If the input is a list of 4096 numbers, the same function is applied 4096 times in parallel.
It also almost never has a learned parameter: it is a fixed operation, chosen by whoever designed the architecture, not learned from data. One exception, at the end of this page: the multiplicative gates, which do carry weights.
Sigmoid and hyperbolic tangent: the generation that saturates
The sigmoid, written , squashes any number into the range 0 to 1:
Here is the incoming number, is Euler's constant (about 2.718), and the negative exponent means that the larger gets, the tinier becomes, so the closer the result creeps to 1. In one sentence: an S-shaped curve, flat on the left, flat on the right, rising in the middle.
The hyperbolic tangent, written , is the same curve recentred: it runs from to and passes through zero in the middle. That centring is a genuine advantage, negative values stay negative instead of all being crushed towards 0.
Both share one flaw, and it is a fatal one: saturation. When is very large or very small, the curve is nearly horizontal, so its slope is nearly zero. But that slope is precisely what tells the weights upstream which way to move. No slope, no instruction, no learning.
Stack a dozen saturating layers and those tiny slopes multiply together until they vanish outright: this is the vanishing gradient, the ailment that long made deep networks untrainable, and the one that gates in recurrent architectures work around, see LSTM and GRU.
ReLU: the crudeness that unlocked depth
ReLU stands for Rectified Linear Unit. "Rectified" in the electrical sense: the signal is straightened, everything negative is cut away.
Where means "keep whichever of 0 and is larger". So: if the input is negative, the output is 0; if it is positive, the output is the input, untouched. Two straight pieces meeting at a sharp corner at zero.
It is almost crude, and that is what makes it powerful:
- No saturation on the positive side. The slope there is exactly 1, forever. The learning signal crosses the layer without being dimmed. This single property is what makes very deep networks trainable.
- Laughably cheap to compute. One comparison against zero, no exponential. Across billions of applications per request, that is not a detail.
- It switches neurons off. A good share of the outputs are exactly zero, and a zero propagates nothing. The network specialises on its own, each neuron responding to only part of the input space.
One flaw remains, a direct consequence of the third point: the dead neuron. If a neuron ends up returning 0 for every possible input, its slope is zero everywhere, it never receives a correction again, and it is lost for good.
The variants: each one fixes the one before
| Function | What it changes | The flaw it fixes |
|---|---|---|
| Leaky ReLU | a very shallow slope on the negative side instead of flat 0 | the dead neuron: a small slope keeps it reachable |
| ELU, exponential linear unit | the negative side is rounded, settling on a fixed negative value | the harsh corner, and the fact that ReLU never outputs anything negative |
| GELU, Gaussian error linear unit | the corner is replaced by a smooth curve | the sharp kink at zero, where the slope jumps from 0 to 1 at once |
| SiLU, also called Swish | multiplied by | the same smoothing as GELU, in a form that is simpler to compute |
These four differ only in how they handle the neighbourhood of zero and the negative side. None of them changes the nature of the operation: one number in, one number out.

Gaussian Error Linear Units (GELUs) introduces GELU.
Searching for Activation Functions presents Swish, found by automated search over combinations of elementary functions rather than designed by hand.
Multiplicative gates: SwiGLU and its family
Recent language models do something else. Instead of applying a function to a single result, the layer computes two results from the same input, applies the activation to only one of them, and then multiplies them element-wise, slot by slot, no mixing, the operation written .
Every symbol: is the layer's input, a value computed on the text at hand. and are two distinct weight tables, two learned parameters, frozen once training ends. The is the element-wise product.
In one sentence: one branch decides how far the tap opens, the other decides what flows through it, and the result is the product of the two. The name GLU comes from Gated Linear Unit, and the Swi- prefix says that the activation used on the control branch is Swish.
The appeal: how much gets through depends on the input itself, slot by slot. An ordinary activation always filters the same way; a gate filters differently according to context. The cost: two weight tables are needed where a classic layer asked for one, so implementations shrink the layer's width to keep the parameter count comparable.
GLU Variants Improve Transformer compares these gates against the classic activations inside a transformer and proposes SwiGLU. That is where its adoption across most of today's large open models comes from.
Softmax: the special case
Softmax is nearly always filed under activation functions. That is misleading: its role is entirely different. It is not a hidden-layer non-linearity, it is a converter from scores to probabilities.
First, a word of vocabulary: a logit is a raw score, exactly as the network produces it, before any conversion. It has no unit, no bounds, and can be negative. Comparing two logits is meaningful; reading one in isolation is not.
Every symbol: is the list of logits, is the logit of candidate number , the exponential makes it positive whatever its sign, and the denominator adds up those exponentials across all candidates. In one sentence: every score is made positive, then each is divided by their total, so the results become slices of one cake.
What softmax guarantees, which is exactly what it is asked for:
- Every number coming out is positive. The exponential takes care of that.
- They sum to 1. Dividing by the total takes care of that. So they can be read as probabilities.
- It is monotonic, meaning it preserves order: the largest logit yields the largest probability. One important practical consequence, softmax never changes the ranking. A model that only wants the winning candidate, its , gets the same answer with or without softmax. Softmax earns its keep only when you actually want probabilities: to sample a word at random among the plausible ones, or to measure an error during training, see Loss functions.
Its role in attention
This is where the reader meets it most often, and it is not to produce an output word. In the attention mechanism, the model computes for each token a relevance score towards each of the others. Softmax turns that list of scores into an attention distribution: positive weights summing to 1, in other words an attention budget spent in full.
That constraint is the heart of the mechanism. Since the total is fixed, giving more attention to one token necessarily takes it away from the others. Attention is a zero-sum game, and softmax is what makes it one. The details are in Self-attention.
Which one shows up where
| Place in the model | Usual function | What is asked of it |
|---|---|---|
| Hidden layer of a recent language model | SwiGLU, or GELU | do not saturate, filter according to context |
| Hidden layer of a vision network | ReLU and its variants | do not saturate, be very cheap to compute |
| Recurrent cell (LSTM, GRU) | sigmoid for the gates, for the contents | an output between 0 and 1, readable as how far a tap is open |
| Output of a multi-class classifier | softmax | probabilities that sum to 1 |
| Output of a yes/no classifier | sigmoid | one single probability between 0 and 1 |
| Inside the attention mechanism | softmax | a fixed attention budget to divide up |
| Output of a regression, predicting a number | none | do not cap the predicted value |
Why it matters
The choice of activation function turns up often in product announcements, because it is an easy way in: the formula is short and a variant is easy to propose. The question worth asking stays the one this page has been asking throughout: which flaw of the previous function does this one fix, and at what computational cost? A variant that brings neither brings nothing.
1. Why is a hundred-layer network worth nothing without activation functions?
2. What is sigmoid saturation, and why is it a fatal flaw?
3. What is a dead neuron with ReLU?
4. A model only wants the highest-scoring word (the argmax). Does applying softmax before choosing change the winner?
5. In the attention mechanism, what does softmax guarantee?