Skip to content
mlmentorship

Activation functions

Trace how activations introduce breakpoints, change gradients and constrain outputs. Compare ReLU, GELU, sigmoid and gated projections.

Published · 9 min read ·Core ·Foundation
Reading depth

Summary

An activation inserts a nonlinear map between affine layers. Without it, repeated affine layers collapse into one affine map.

Take , then compare with . What changes at and ? The graphs show activation output , not the complete network output .

Optimization intuition

Flat activation regions weaken the gradient travelling backward

A flat forward response has little backward slopeReLU has zero derivative on its negative side. Sigmoid slopes become small in both tails; their forward outputs are not gradients.A flat forward response gives a smallslopeSigmoid: output zero to one0.045180.250.04518ReLU: output zero to four01Numbers are local slopes, not forwardoutputs.
Derivation

Sigmoid: two saturating tails

The slope approaches zero at both output limits.

Logistic sigmoid from negative four to positive four The sigmoid rises smoothly through one half at input zero and flattens toward output zero on the left and output one on the right. Both flat tails are labeled as saturation regions where the derivative approaches zero. left tail: σ′(h) → 0 saturated: σ′(h) → 0 σ(0) = 0.5 −404 00.51 input h output

ReLU vs exact GELU

A half-line of zero slope differs from one smooth shoulder.

ReLU and exact GELU from negative three to positive three ReLU is exactly zero with zero derivative for every negative input, then follows a straight line after zero. Exact GELU, x times the standard normal cumulative distribution, has small negative outputs, a shallow minimum near negative three quarters, passes through zero, and approaches the same positive linear trend. ReLU is solid and GELU is dashed. ReLU: inactive, g′(h) = 0 ReLU: solid GELU: dashed smooth negative shoulder both pass through (0, 0) −303 0123 input h output
Read it this way: sigmoid loses slope in both tails. ReLU keeps unit slope for positive inputs and zero slope for negative inputs. Exact GELU has a smooth negative shoulder, but its derivative can still equal zero.
Check: Where would an incoming gradient shrink or become zero? How is that different for GELU?
Read it this way: ReLU has zero derivative on its negative side. Sigmoid slopes become small in both tails; their forward outputs are not gradients.
Where does the same small input move produce almost no output change?

Trace the two inputs

Without activation, substitution gives everywhere. ReLU instead clips negative to zero.

Input Affine outputReLU outputReLU path derivative

The activated network is constant at when , and equals when . Its breakpoint is . Both branches meet there, but the derivative is not unique. Frameworks choose a derivative convention at the kink.

For positive , ReLU’s local slope is one. For negative , it is zero, removing this path’s gradient on that input. Sigmoid has derivative , which approaches zero in both tails. Full gradient flow also depends on weights and other paths.

Change the requirement

1. Keep a negative-region gradient

New task: this path repeatedly receives and needs a negative-region update.

Picture and change: replace ReLU by leaky ReLU with negative slope . This changes both values and gradients.

Check: activation output becomes with local slope , instead of zero output and slope. The complete output is , and .

Use when: persistent inactivity is observed, with the changed function acceptable for the task.

2. Change label exclusivity

New task: logits are . Choose outputs for one exclusive class versus two labels that can coexist.

Picture and change: softmax normalizes jointly; separate sigmoids produce individual Bernoulli probabilities.

Check: softmax gives ; sigmoids give . The latter need not sum to one.

Use when: target structure changes, rather than merely changing a hidden activation.

Check the loss input contract

Do not apply softmax before a cross-entropy API that expects logits. It would transform already transformed values. Check whether the API accepts logits, probabilities or log probabilities.

Try diagnosing a negative ReLU input

Does one negative input mean the unit is permanently dead?

Check your answer

No. Other inputs or upstream parameter changes can reactivate it. Persistent inactivity across relevant inputs is the concern.

The standard family

Here for ELU and for leaky ReLU.

ActivationFormulaRangeConstraint or role
SigmoidBernoulli outputs and gates; saturating tails
TanhOdd and centered at the origin, not necessarily zero-mean over data
ReLUUnit positive slope, zero negative slope
Leaky ReLUNonzero negative slope
ELU if ; otherwiseNegative outputs; smooth at zero only when
Exact GELU, normal CDF Bounded below, unbounded aboveSmall negative shoulder; not every real output is attainable
SiLU / swish with unit scaleBounded below, unbounded aboveSmooth, nonmonotone negative shoulder
SoftmaxProbability simplex interior for finite logitsCouples coordinates; not an elementwise activation

Smoothness does not guarantee gradient flow

Exact GELU has derivative , where is the normal density. It can vanish at isolated points. Exact and approximate GELU differ; match framework settings for reproducibility. Activation choice and initialization must be considered together. No activation guarantees better task accuracy from its curve alone.

References: ReLU, GELU, swish, and feedforward networks.

SwiGLU and gated activations

For row-vector batches , use and :

This has projection parameters, excluding biases, versus for a two-projection block at equal hidden width. Equal parameter budgets require adjusting width; performance comparisons must state that budget.

When to use which output activation

TaskOutput activation
Binary classificationSigmoid
Multi-class classificationSoftmax
Multi-label classificationSeparate sigmoid heads; labels need not be mutually exclusive
Regression (unbounded)Identity (no activation)
Regression (bounded )Sigmoid
Probability over a discrete distributionSoftmax
Embedding outputIdentity; normalize if the similarity objective requires it

Common pitfalls

Output constraints must match the target: softplus is positive, while ReLU can produce exact zeros and inactive gradients. Bounded sigmoid outputs do not by themselves establish calibrated probabilities.