Output, Gated, and Special Activations: Softmax, GLU, SIREN, and More

14 minute read

Published:

TL;DR: Many important activations are not โ€œhidden-layer curvesโ€ at all. Softmax and sigmoid control outputs, GLU-style activations learn gates, shrinkage activations push values toward zero, and specialized activations such as SIREN or Gaussian RBFs are built for niche but powerful settings.

Output Activations Have a Different Job

Intuition First: In hidden layers, activations shape what the network thinks. At the output layer, activations shape what the network says. They must convert raw scores (logits) into the exact format the loss function expects. Using the wrong output activation is not just suboptimal โ€” it breaks the loss's mathematical assumptions and can make training completely undefined.

In hidden layers, activation functions mainly shape representation learning and gradient flow. At the output layer, they must match the task.

The three most important output cases

TaskTypical activationWhy
Binary classificationSigmoidTurns one logit into a probability in [0, 1]
Multi-class classificationSoftmaxConverts logits into a probability distribution that sums to 1
RegressionLinear / IdentityLeaves the output unconstrained

The softmax formula is:

\[ \operatorname{softmax}(z_i) = \frac{e^{z_i}}{\sum_j e^{z_j}} \]

Concrete step-by-step: softmax on 3 logits

Say a 3-class classifier produces logits z = [2.0, 1.0, 0.1].

StepComputationResult
Exponentiateeยฒ, eยน, e^0.17.389, 2.718, 1.105
Sum7.389 + 2.718 + 1.10511.212
Normalize7.389/11.212, 2.718/11.212, 1.105/11.2120.659, 0.242, 0.099
Check0.659 + 0.242 + 0.099= 1.000 โœ“

The original logit differences (2.0 vs 1.0 vs 0.1) are now calibrated probabilities summing to 1. Note that a 1-unit logit advantage roughly triples the probability โ€” the exponential makes the winner-take-most effect strong.

Key Insight โ€” temperature: Dividing logits by a temperature T before softmax controls sharpness. Tโ†’0 makes softmax behave like argmax (one-hot). Tโ†’โˆž makes it uniform. This is why temperature scaling is the standard post-hoc calibration technique: the model's weights stay frozen, only the output distribution is reshaped.
T = 0.5 (sharp) 88% 10% 2% C1 C2 C3 T = 1.0 (standard) 66% 24% 10% C1 C2 C3 T = 3.0 (soft) 42% 33% 25% C1 C2 C3
The same logits [2.0, 1.0, 0.1] passed through softmax at three temperatures. Low T (left) collapses probability onto the top class โ€” useful for greedy decoding. High T (right) spreads probability more evenly โ€” useful for knowledge distillation. T=1 is the standard training setting.

Why Gated Activations Became So Important

Intuition First: A classic activation like ReLU asks one question of each neuron: "should this value pass?" A gated activation asks two neurons to collaborate: one produces content, the other produces a gate score. The gate modulates how much of the content flows forward. This is conceptually identical to the gating mechanism in LSTMs and GRUs โ€” the same idea, applied at every feed-forward layer. It is why gated variants consistently outperform plain ReLU in large Transformer models.

Modern architectures often do not use a single scalar curve after an affine transform. Instead, they split the channel dimension and let one part gate another.

That gives you:

  • GLU: one linear branch gates another
  • SwiGLU: same idea, but with a SiLU/Swish-style gate
  • GeGLU: GELU gate
  • ReGLU: ReLU gate
GLU \[ \operatorname{GLU}(x) = a \otimes \sigma(b) \]
SwiGLU \[ \operatorname{SwiGLU}(x) = a \otimes \operatorname{SiLU}(b) \]
GeGLU / ReGLU \[ \operatorname{GeGLU}(x) = a \otimes \operatorname{GELU}(b), \qquad \operatorname{ReGLU}(x) = a \otimes \operatorname{ReLU}(b) \]

This family matters because large Transformers often rely more on gated feed-forward blocks than on plain ReLU-style MLPs.

<div class=โ€insight-boxโ€> Useful mental model: ReLU asks โ€œshould this neuron pass?โ€ GLU-like activations ask โ€œhow strongly should this feature gate another feature?โ€ </div>

Worked example โ€” GLU vs. plain linear, step by step:

Suppose an input vector is split into two halves: a = [1.2, โˆ’0.4, 0.8] (content) and b = [2.1, โˆ’1.5, 0.3] (gate input).

StepGLUPlain linear (no gate)
Compute gateฯƒ(b) = [0.89, 0.18, 0.57]โ€”
Element-wise producta โŠ— ฯƒ(b) = [1.07, โˆ’0.07, 0.46]a = [1.2, โˆ’0.4, 0.8]
EffectThe โˆ’0.4 signal is suppressed to โˆ’0.07 by a low gate valueโˆ’0.4 passes through unchanged

The gate learned that the second feature is unreliable (low ฯƒ(b)=0.18) and almost entirely suppressed it. Plain linear cannot make this context-dependent decision.

<div class=โ€blog-figureโ€>

<svg xmlns=โ€http://www.w3.org/2000/svgโ€ viewBox=โ€0 0 520 175โ€ style=โ€max-width:520px;width:100%โ€><rect x=โ€1โ€ y=โ€1โ€ width=โ€518โ€ height=โ€173โ€ rx=โ€9โ€ fill=โ€#f8fafcโ€ stroke=โ€#dbe7f5โ€/> <g class=โ€glu-box glu-b1โ€> <rect x=โ€15โ€ y=โ€65โ€ width=โ€70โ€ height=โ€45โ€ rx=โ€7โ€ fill=โ€#eff6ffโ€ stroke=โ€#93c5fdโ€ stroke-width=โ€1.5โ€/> <text x=โ€50โ€ y=โ€85โ€ text-anchor=โ€middleโ€ class=โ€bx-lblโ€ fill=โ€#1e3a8aโ€>Input x</text> <text x=โ€50โ€ y=โ€100โ€ text-anchor=โ€middleโ€ class=โ€sm-lblโ€>dim d</text> </g> <path d=โ€M85,88 H120 L120,55โ€ class=โ€glu-wire glu-w1โ€/> <path d=โ€M85,88 H120 L120,120โ€ class=โ€glu-wire glu-w2โ€/> <g class=โ€glu-box glu-b1โ€> <rect x=โ€120โ€ y=โ€28โ€ width=โ€80โ€ height=โ€40โ€ rx=โ€7โ€ fill=โ€#f0fdf4โ€ stroke=โ€#86efacโ€ stroke-width=โ€1.5โ€/> <text x=โ€160โ€ y=โ€46โ€ text-anchor=โ€middleโ€ class=โ€bx-lblโ€ fill=โ€#166534โ€>Linear Wโ‚</text> <text x=โ€160โ€ y=โ€59โ€ text-anchor=โ€middleโ€ class=โ€sm-lblโ€>โ†’ a</text> </g> <g class=โ€glu-box glu-b2โ€> <rect x=โ€120โ€ y=โ€107โ€ width=โ€80โ€ height=โ€40โ€ rx=โ€7โ€ fill=โ€#fff7edโ€ stroke=โ€#fdba74โ€ stroke-width=โ€1.5โ€/> <text x=โ€160โ€ y=โ€124โ€ text-anchor=โ€middleโ€ class=โ€bx-lblโ€ fill=โ€#9a3412โ€>Linear Wโ‚‚</text> <text x=โ€160โ€ y=โ€137โ€ text-anchor=โ€middleโ€ class=โ€sm-lblโ€>โ†’ b</text> </g> <path d=โ€M200,127 H250โ€ class=โ€glu-wire glu-w2โ€/> <g class=โ€glu-box glu-b2โ€> <rect x=โ€250โ€ y=โ€107โ€ width=โ€65โ€ height=โ€40โ€ rx=โ€7โ€ fill=โ€#fef9c3โ€ stroke=โ€#fde047โ€ stroke-width=โ€1.5โ€/> <text x=โ€282โ€ y=โ€124โ€ text-anchor=โ€middleโ€ class=โ€bx-lblโ€ fill=โ€#713f12โ€>ฯƒ(b)</text> <text x=โ€282โ€ y=โ€137โ€ text-anchor=โ€middleโ€ class=โ€sm-lblโ€>gate</text> </g> <path d=โ€M200,48 H315 L315,88โ€ class=โ€glu-wire glu-w1โ€/> <path d=โ€M315,127 L315,108โ€ class=โ€glu-wire glu-w2โ€/> <g class=โ€glu-box glu-b3โ€> <circle cx=โ€315โ€ cy=โ€88โ€ r=โ€18โ€ fill=โ€#e0f2feโ€ stroke=โ€#38bdf8โ€ stroke-width=โ€1.5โ€/> <text x=โ€315โ€ y=โ€93โ€ text-anchor=โ€middleโ€ class=โ€bx-lblโ€ fill=โ€#0c4a6eโ€>โŠ—</text> </g> <path d=โ€M333,88 H400โ€ class=โ€glu-wire glu-w3โ€/> <g class=โ€glu-box glu-b4โ€> <rect x=โ€400โ€ y=โ€65โ€ width=โ€105โ€ height=โ€45โ€ rx=โ€7โ€ fill=โ€#f0fdf4โ€ stroke=โ€#4ade80โ€ stroke-width=โ€1.5โ€/> <text x=โ€452โ€ y=โ€84โ€ text-anchor=โ€middleโ€ class=โ€bx-lblโ€ fill=โ€#14532dโ€>GLU output</text> <text x=โ€452โ€ y=โ€99โ€ text-anchor=โ€middleโ€ class=โ€sm-lblโ€>a โŠ— ฯƒ(b)</text> </g> </svg>
Animated GLU data-flow. The input is projected by two independent linear layers. The content branch (a) passes through unchanged. The gate branch (b) is squashed by sigmoid to produce per-channel gate values in (0,1). The element-wise product lets the gate selectively suppress or pass each content feature โ€” all learned end-to-end.

</div>

<div style=โ€background:#fff7ed;border-left:4px solid #f97316;border-radius:8px;padding:.95rem 1.1rem;margin:1.25rem 0;โ€>Key Insight โ€” SwiGLU in LLaMA/GPT-4 style FFN blocks: SwiGLU(x) = (Wโ‚x) โŠ— SiLU(Wโ‚‚x). Compared to a standard two-layer MLP with a single activation, SwiGLU uses three weight matrices (Wโ‚, Wโ‚‚, Wโ‚ƒ for the final projection) but achieves better perplexity at the same parameter budget. The reason is expressivity: the gate is a full learned linear transformation, not just a fixed nonlinearity applied to the same pre-activation. This is why nearly every modern open-source LLM (LLaMA, Mistral, Gemma) uses SwiGLU in its feed-forward blocks instead of plain GELU-MLP.</div>

Diagram contrasting hidden-layer activations, output activations, and gated activations
Figure 1 โ€” Not all activations play the same role. Hidden-layer activations shape features, output activations shape the prediction object, and gated activations decide how one feature stream modulates another.

Shrinkage and Sparse Activations

Intuition First: Standard activations pass strong signals and block weak ones. Shrinkage activations go further: they push small values all the way to zero, creating genuine sparsity in the representation. Think of it as denoising โ€” treat small activations as noise and eliminate them, keep only the confidently large values. Sparsemax takes this idea to the output layer: unlike softmax which distributes probability mass everywhere, Sparsemax assigns exact zero probability to unlikely classes, producing a sparse probability vector. This is especially valuable for attention mechanisms and structured prediction.

Another family is built around sparsity or denoising:

  • TanhShrink: returns x - tanh(x)
  • SoftShrink: softly pushes small values toward zero
  • HardShrink: zeroes small values completely
  • Sparsemax: like softmax, but can produce exact zeros
  • Entmax: interpolates between dense softmax and sparse alternatives
TanhShrink \[ \operatorname{TanhShrink}(x) = x - \tanh(x) \]
SoftShrink \[ \operatorname{SoftShrink}(x) = \begin{cases} x - \lambda, & x > \lambda \\ 0, & |x| \le \lambda \\ x + \lambda, & x < -\lambda \end{cases} \]
HardShrink \[ \operatorname{HardShrink}(x) = \begin{cases} x, & |x| > \lambda \\ 0, & |x| \le \lambda \end{cases} \]

These are useful when you want more structured or selective outputs rather than dense probability mass everywhere.

Concrete example โ€” SoftShrink vs HardShrink vs Sparsemax (ฮป=0.5):

Input valueSoftShrink (ฮป=0.5)HardShrink (ฮป=0.5)Notes
2.01.52.0Large value: both pass through
0.80.30.8SoftShrink reduces, HardShrink passes
0.40.00.0Both zero โ€” below threshold
0.10.00.0Both zero โ€” below threshold
โˆ’0.6โˆ’0.1โˆ’0.6SoftShrink clips toward zero
โˆ’1.5โˆ’1.0โˆ’1.5Large negative: both pass

SoftShrink always shrinks by ฮป before zeroing; HardShrink either passes completely or zeros. SoftShrink is the classical wavelet/signal denoising shrinkage โ€” it corresponds to solving a LASSO-style proximal operator.

Softmax (dense) 70% 10% 9% 6% 5% C1 C2 C3 C4 C5 Sparsemax (sparse) 80% 20% 0% 0% 0% C1 C2 C3 C4 C5 exact zeros โ€” interpretable sparse attention
Same logits [3, 1, 0, โˆ’1, โˆ’2] through Softmax (left) vs. Sparsemax (right). Softmax distributes probability everywhere โ€” even irrelevant classes C4, C5 receive 5โ€“6%. Sparsemax projects onto the probability simplex using a thresholding operation, producing exact zeros for low-scoring classes. This is critical for sparse attention mechanisms where you want some tokens to receive literally zero weight.

Special-Purpose Activations

Some activations are not mainstream in basic classifiers, but they are extremely important in the right niche.

  • Maxout: takes the maximum over several learned affine responses
  • Sin / SIREN: uses sinusoidal activations for implicit neural representations
  • Gaussian / RBF: activates by distance from a center
  • Soft Exponential: learns whether to behave more like a log, linear, or exponential function
  • KAN / spline activations: learns the activation shape itself rather than choosing a fixed closed-form function
SIREN \[ f(x) = \sin(\omega x) \]
Gaussian / RBF \[ \phi(x) = \exp\!\left(-\frac{\|x-c\|^2}{2\sigma^2}\right) \]
Soft Exponential \[ f_\alpha(x) = \begin{cases} -\frac{\log(1-\alpha(x+\alpha))}{\alpha}, & \alpha < 0 \\ x, & \alpha = 0 \\ \frac{e^{\alpha x}-1}{\alpha} + \alpha, & \alpha > 0 \end{cases} \]

These remind us that โ€œactivation functionโ€ is a much broader design space than just ReLU vs GELU.

<div style=โ€background:#fff7ed;border-left:4px solid #f97316;border-radius:8px;padding:.95rem 1.1rem;margin:1.25rem 0;โ€>Key Insight โ€” why SIREN works for implicit representations: Modeling a continuous signal (image, shape, audio) as a neural function f(x,y)โ†’RGB requires the network to represent fine-grained detail. ReLU-based networks produce piecewise-linear outputs โ€” they cannot represent smooth higher-order derivatives. SIREN uses sin(ฯ‰x), whose derivatives are also sinusoids, so the network naturally represents smooth periodic structure at every layer. The frequency ฯ‰ controls the scale of detail captured. SIREN networks have been shown to exactly fit high-resolution images with far fewer parameters than ReLU networks because every layer contributes smoothly to all derivative orders โ€” not just the zeroth.</div>

<div class=โ€blog-figureโ€>

<svg xmlns=โ€http://www.w3.org/2000/svgโ€ viewBox=โ€0 0 520 175โ€ style=โ€max-width:520px;width:100%โ€><rect x=โ€1โ€ y=โ€1โ€ width=โ€518โ€ height=โ€173โ€ rx=โ€9โ€ fill=โ€#f8fafcโ€ stroke=โ€#dbe7f5โ€/> <text x=โ€260โ€ y=โ€17โ€ text-anchor=โ€middleโ€ class=โ€si-ttlโ€ fill=โ€#0f2a36โ€>SIREN sin(ฯ‰x) vs. ReLU piecewise approximation</text> <line x1=โ€30โ€ y1=โ€100โ€ x2=โ€500โ€ y2=โ€100โ€ class=โ€si-axโ€/> <line x1=โ€30โ€ y1=โ€20โ€ x2=โ€30โ€ y2=โ€145โ€ class=โ€si-axโ€/> <text x=โ€30โ€ y=โ€158โ€ text-anchor=โ€middleโ€ class=โ€si-lblโ€>0</text> <text x=โ€147โ€ y=โ€158โ€ text-anchor=โ€middleโ€ class=โ€si-lblโ€>ฯ€</text> <text x=โ€264โ€ y=โ€158โ€ text-anchor=โ€middleโ€ class=โ€si-lblโ€>2ฯ€</text> <text x=โ€381โ€ y=โ€158โ€ text-anchor=โ€middleโ€ class=โ€si-lblโ€>3ฯ€</text> <text x=โ€498โ€ y=โ€158โ€ text-anchor=โ€middleโ€ class=โ€si-lblโ€>4ฯ€</text> <path d=โ€M30,100 C50,100 60,30 87,30 S120,100 147,100 C165,100 175,170 200,170 S235,100 264,100 C282,100 292,30 317,30 S350,100 381,100 C399,100 409,170 434,170 S469,100 498,100โ€ class=โ€si-sinโ€/> <path d=โ€M30,100 L57,100 L57,30 L114,30 L114,100 L171,100 L171,170 L228,170 L228,100 L264,100 L264,30 L321,30 L321,100 L381,100 L381,170 L435,170 L435,100 L498,100โ€ class=โ€si-reluโ€/> <line x1=โ€40โ€ y1=โ€168โ€ x2=โ€65โ€ y2=โ€168โ€ stroke=โ€#0891b2โ€ stroke-width=โ€2.4โ€/> <text x=โ€70โ€ y=โ€172โ€ class=โ€si-legโ€ fill=โ€#0891b2โ€>SIREN sin(ฯ‰x) โ€” smooth all derivatives</text> <line x1=โ€280โ€ y1=โ€168โ€ x2=โ€305โ€ y2=โ€168โ€ stroke=โ€#94a3b8โ€ stroke-width=โ€2โ€/> <text x=โ€310โ€ y=โ€172โ€ class=โ€si-legโ€ fill=โ€#94a3b8โ€>ReLU approx โ€” piecewise, no smooth derivatives</text> </svg>
SIREN (blue, smooth) vs. a ReLU piecewise approximation of the same sinusoidal target. The SIREN represents the true smooth signal exactly because its activations have infinite-order smooth derivatives. ReLU can approximate it, but only with many more layers and with derivative discontinuities that limit precision in applications like physics-based neural fields.

</div>

Grid of output, gated, sparse, and special activations including Softmax, LogSoftmax, Maxout, GLU, SwiGLU, GeGLU, ReGLU, TanhShrink, SoftShrink, HardShrink, Sparsemax, Entmax, SIREN, Gaussian RBF, Soft Exponential, and spline-style activations
Figure 2 โ€” This last family is much more diverse. Some activations map logits to probabilities, some implement feature gating, some encourage sparsity, and some are designed for special function classes such as implicit fields or spline-based networks.

Common Mistakes

Four mistakes that show up constantly:
  1. Applying softmax before `CrossEntropyLoss` in PyTorch. That loss expects raw logits.
  2. Using sigmoid for mutually exclusive multi-class classification. Usually you want softmax instead.
  3. Ignoring the output activation entirely. The last-layer activation should match both the task and the loss.
  4. Assuming all gating activations are interchangeable. SwiGLU, GeGLU, and ReGLU can change optimization noticeably in large models.

Practical Recommendation Map

Use caseRecommended activation
Binary classification outputSigmoid
Multi-class classification outputSoftmax
Regression outputLinear
Transformer feed-forward blocksGELU or SwiGLU
Sparse probability-like outputsSparsemax or Entmax
Implicit neural representationsSIREN
Radial similarity modelsGaussian / RBF

What Can Go Wrong with Output and Special Activations?

Activation familyPotential problem
SoftmaxEasy to misuse with the wrong loss pipeline, especially if you apply it before losses that expect raw logits.
Sigmoid outputsWrong choice for mutually exclusive multi-class prediction, where softmax is usually the right tool.
GLU-style gatingMore expressive, but also more parameter-heavy and architecture-dependent.
Sparsemax / EntmaxUseful for sparsity, but can change optimization behavior enough that they are not just drop-in replacements for softmax.
SIREN / RBF / spline-style activationsVery powerful in the right niche, but usually a poor default if the model and task were not designed for them.

Final Takeaway

Activation functions are not a side detail. They define:

  1. how information flows forward,
  2. how gradients flow backward,
  3. what geometry the model can represent,
  4. and what kind of output object the network produces.

That is why the full story needs more than one chapter. ReLU, GELU, Softmax, SwiGLU, Sparsemax, and SIREN are not solving the same problem. They all live under the same name, but they serve very different roles.

References

  1. Dauphin, Y. N. et al. โ€œLanguage Modeling with Gated Convolutional Networks.โ€ 2017.
  2. Shazeer, N. โ€œGLU Variants Improve Transformer.โ€ 2020.
  3. Martins, A. and Astudillo, R. โ€œFrom Softmax to Sparsemax.โ€ ICML 2016.
  4. Peters, B. et al. โ€œSparse Sequence-to-Sequence Models.โ€ ACL 2019.
  5. Sitzmann, V. et al. โ€œImplicit Neural Representations with Periodic Activation Functions.โ€ NeurIPS 2020.