Chapter 3 · Diagnose signal and ship

Activation functions: geometry, gradients, and failure modes

Select activation functions by signal range, gradient flow, architecture, precision, and failure mode; then diagnose saturation and dead units from telemetry.

65–90 min8 key conceptsReviewed 26 Aug 2026
01 · Production proposition

A deep incident classifier stops learning because hidden units die or saturate and the output path applies its probability activation twice.

This lesson isolates activation functions: geometry, gradients, and failure modes as one decision inside that system. The people affected are product users and operators; the learning data must carry event time, availability time, ownership, and version; and the operating envelope is the model depth, numeric precision, kernel support, and training-throughput envelope.

Decision

Choose hidden and output activations that preserve trainable signal while matching the architecture and target semantics.

Metric

Activation distributions, saturation/zero fractions, gradient norms, convergence, held-out decision quality, and kernel throughput.

Failure consequence

A deep incident classifier stops learning because hidden units die or saturate and the output path applies its probability activation twice. An unsafe release must degrade to a named baseline or the last known-good version.

02 · Intuition & prerequisites

Build the mental model before the machinery.

The core move is to treat activation functions: geometry, gradients, and failure modes as a contract between data, a computation, and an action. Default hidden activations are justified by architecture evidence, output activations match the target/loss contract, and training dashboards track activation mean, variance, zero fraction, saturation, and gradient norms by layer. The implementation becomes easier to debug once you can state which inputs exist, which state is learned, what output means, and what must remain invariant after serialization.

01

ReLU

Define it in a hand-checkable form and name the prediction-time inputs.

02

GELU

Connect it to the production metric and identify what it cannot guarantee.

03

SiLU

Stress it with a slice, a temporal boundary, and a failure-safe alternative.

04

sigmoid saturation

Stress it with a slice, a temporal boundary, and a failure-safe alternative.

05

tanh saturation

Stress it with a slice, a temporal boundary, and a failure-safe alternative.

06

dead activations

Stress it with a slice, a temporal boundary, and a failure-safe alternative.

07

gradient flow

Stress it with a slice, a temporal boundary, and a failure-safe alternative.

08

output activations

Stress it with a slice, a temporal boundary, and a failure-safe alternative.

Bring forward

Lessons 1, 2, 3, 4, 5 in this course.

03 · Formal treatment

Name every symbol. Check every shape.

Common element-wise nonlinearities is the central invariant for this lesson. The formula is useful only when its inputs match the production cutoff and its output maps to an action.

Formal treatment
ReLU(z)=max(0,z);σ(z)=11+ez;SiLU(z)=zσ(z)\operatorname{ReLU}(z)=\max(0,z);\quad \sigma(z)=\frac{1}{1+e^{-z}};\quad \operatorname{SiLU}(z)=z\,\sigma(z)

Common element-wise nonlinearities

Symbol, shape or unit contract
SymbolMeaning / shape / unit
zpre-activation tensor with shape [batch, features, …]
σlogistic sigmoid
ReLUpiecewise-linear positive gate
SiLUsmooth self-gated activation
Open derivation and numerical substitution

Start from the production quantity being optimized, substitute the observed values with their declared units, then isolate the model-controlled term. Preserve shape annotations at each step so broadcasting or aggregation cannot silently change the result.

  1. Write the named inputs: z, σ, ReLU, SiLU.
  2. Substitute one small, hand-checkable batch before vectorizing.
  3. Calculate an independent reference value and compare within a declared tolerance.
# equation → code contract
inputs = validate_shapes_and_units(batch)
value = compute_c09(inputs)
assert is_finite(value)
04 · Selection field guide

Choose from the task contract, not a favorite default.

Separate hidden activation choice from output semantics.

Hidden nonlinearities preserve trainable signal and expressive power. Output activations are part of the target and loss API contract.

Activation selection and debugging map
ActivationRange / gradientWhy choose itFailure to watchTypical role
ReLU[0, ∞); derivative 0 or 1Efficient default for many CNNs/MLPsDead units from negative pre-activationsHidden layers with matched initialization
Leaky ReLU / PReLUSmall negative slope, linear positive sideWhen dead ReLUs are observedLearned slope instability or unsupported fused kernelsCNN/MLP hidden layers
GELUSmooth, non-monotonic gateEstablished transformer defaultExtra compute or approximation differencesTransformer MLPs
SiLU / Swishz·sigmoid(z), smooth self-gatingStrong modern CNN/MLP baselineSaturation in far-negative inputs; kernel costModern CNNs and dense networks
tanh(−1,1), zero-centered, saturatingBounded recurrent candidate stateVanishing gradients at large |z|RNN state transforms or bounded latent values
sigmoid(0,1), probability/gate semanticsBinary or multilabel output; recurrent gatesSaturating hidden gradients; double activationProbabilities and gates, not universal hidden layers
softmaxSimplex across a declared axisExclusive multiclass probabilities or attention weightsWrong axis, overflow in naive code, use for multilabelReported class distribution; often fused into loss
identity / softplusUnbounded / strictly positive outputOutput link chosen from target supportArtificial bounds or exploding positive predictionsRegression output / positive scale or rate
05 · Three views of the idea

Calculate it small. Shape it realistically. Break it on purpose.

HAND-CALCULATED TOY

A result you can reproduce on paper

Evaluate ReLU, sigmoid, tanh, and SiLU at z ∈ {−4, −1, 0, 1, 4}; compute local gradients and mark saturated or zero-gradient regions.

  1. Write every input and unit.
  2. Substitute values into the common element-wise nonlinearities equation above.
  3. Compare the result to one simple baseline and explain the direction of the difference.
PRODUCTION-SHAPED

The same reasoning under real constraints

Choose hidden activations for an MLP and transformer, output activations for binary, multiclass, multilabel, bounded regression, and mixture parameters, then instrument activation and gradient distributions.

The production record includes the data snapshot, transformation state, artifact identity, cutoff, score, decision, and the version of the policy that consumed it.

FAILURE / COUNTEREXAMPLE

The attractive result you should reject

A deep network uses sigmoid hidden units in low precision, saturates early, while a high learning rate drives every ReLU negative and creates permanently dead channels.

Diagnostic: replay the smallest failing slice from immutable inputs, then compare each boundary rather than retuning the model.

06 · Deterministic lab

Change one assumption and make the tradeoff visible.

This lab runs predefined TypeScript only. It never executes learner code. Use the slider, numeric input, reset, live text, or table—the computation is the same.

Exact computation

Activation and gradient-flow lab

Move one exact pre-activation through four nonlinearities and compare local gradients.

PrimaryReLU 1.000
SecondarySiLU grad 0.928
DiagnosisTrainable local signal

Assumption: Scalar element-wise activations; z is the displayed control divided by 10. ReLU derivative at zero is defined as zero.

Open nonvisual data table
ItemComputed stateInterpretation
reluoutput 1.00000gradient 1.00000
sigmoidoutput 0.73106gradient 0.19661
tanhoutput 0.76159gradient 0.41997
siluoutput 0.73106gradient 0.92767
07 · Production implications

Trace the complete operating path.

  1. 01

    Validate and version ReLU.

  2. 02

    Compute activation functions: geometry, gradients, and failure modes from prediction-time-safe inputs.

  3. 03

    Persist model, feature, and configuration identities together.

  4. 04

    Serve or materialize behind explicit the model depth, numeric precision, kernel support, and training-throughput envelope.

  5. 05

    Join telemetry to mature outcomes and retain a rollback path.

Observability

Join service health, input quality, prediction distributions, slice behavior, and mature outcomes by exact version.

Cost

Measure storage, preprocessing, compute, queueing, and human review under a representative arrival pattern.

Failure modes

A deep network uses sigmoid hidden units in low precision, saturates early, while a high learning rate drives every ReLU negative and creates permanently dead channels. Add a detector, owner, mitigation, and stop condition for this class of failure.

Alternatives

Compare a rule, a simpler statistical baseline, and a different system boundary before adding model complexity.

07 · Check understanding

Explain the contract, not just the vocabulary.

Browser-graded checkpointPass ≥ 80%
01Why are activations needed between affine layers?
02Where should sigmoid commonly appear?
03What evidence suggests dead ReLU units?
08 · Apply in production

Activation pathology report

Run a controlled activation comparison and diagnose one dead, saturated, or semantically incorrect network.

  • ReLU, LeakyReLU, GELU, SiLU, and tanh comparison
  • Activation percentiles, zero/saturation rates, and gradient norms
  • Binary, multiclass, multilabel, and regression output-contract tests
  • Matched initialization/normalization and latency evidence
  • Recommended bundle with rollback trigger
Production self-review0/100

Staged hints

Failure diagnosis

  • If offline numbers look impossible, audit prediction-time availability before model code.
  • If quality is sound but the contract fails, measure the exact serialized and served path.
  • If one slice regresses, preserve that slice as a permanent release gate.

Record an honest attempt to unlock the reference solution.

09 · Sources & next depth

Read primary material with a purpose.

10 · Production resolution

Return to the opening failure.

Default hidden activations are justified by architecture evidence, output activations match the target/loss contract, and training dashboards track activation mean, variance, zero fraction, saturation, and gradient norms by layer.

For this lesson, the release evidence is a hand-checked formal result, deterministic simulation output, a ≥80% checkpoint, the production rubric, and a named fallback. The course resolves when the system can produce a small network built from forward pass through backpropagation and optimization.