🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
💼 Servicesℹ️ About✉️ ContactView Pricing Plansfrom $10

Activation Functions — Sigmoid, ReLU, GELU and The Dead Neuron Problem

FoundationsArchitecture🟢 Free Lesson

Advertisement

DL Foundations

Activation Functions - Adding Non-Linearity to Neural Networks

Without activation functions, deep networks collapse into linear models no matter how many layers are stacked. Activation functions introduce the non-linearity that enables learning of arbitrary decision boundaries.

  • ReLU is the Default - Fast, prevents vanishing gradients, provides sparse activations for hidden layers
  • GELU for Transformers - Smooth approximation to ReLU used in BERT, GPT, and Vision Transformers
  • Dead Neuron Problem - ReLU neurons that always output zero require careful initialization and architecture choices

Activation Functions - Sigmoid, ReLU, GELU and The Dead Neuron Problem

What You'll Learn

  • 1Prove that stacked linear layers collapse to one linear map
  • 2Compare the derivatives of sigmoid, tanh, and ReLU and link each to gradient flow
  • 3Explain the dead neuron condition and three ways to prevent it
  • 4Choose an activation for a hidden stack and for a softmax, sigmoid, or regression head

Activation functions introduce non-linearity into neural networks, enabling them to learn complex patterns. Without them, a deep network would collapse into a linear model.


Why Activation Functions?

Without Activation Functions: Linear CollapseInputLinearW₁xLinearW₂(W₁x)LinearW₃(W₂W₁x)= W'xSingle linear!W₃ · W₂ · W₁ · x = W' · x (equivalent to single layer)

Sigmoid

The derivative follows from the quotient rule and never leaves the box shown below:

Carrying that factor through depth is the whole story of the vanishing gradient with sigmoids:

Ten sigmoid layers can shrink a gradient by six orders of magnitude before the first weight ever sees it. Sigmoid also saturates: for the output sits within 1 percent of its bound and the gradient is effectively zero, so saturated units stop learning entirely.


Tanh

Tanh is a shifted sigmoid and inherits a similar derivative shape with twice the peak:

Zero centering matters as much as the peak. Sigmoid outputs are always positive, so the gradients on a weight matrix arrive with the same sign and the update zig-zags along the coordinate axes. Tanh outputs average to zero near the origin, which keeps the gradient directions balanced, and that is the practical reason tanh outperformed sigmoid in hidden layers for two decades.


Activation Function Comparison

Activation Functions: Shape and Derivative ComparisonxySigmoidTanhReLUFunction Shapexy'σ' (max 0.25)tanh' (max 1.0)ReLU' (0 or 1)Derivative Shape

ReLU and Variants

ReLU changes the gradient story completely, because its derivative is the Heaviside step:

For positive units the gradient passes through at full strength no matter how deep the stack, which is why ReLU networks with hundreds of layers train while sigmoid networks stall near ten. The price is the kink at zero: the function is not differentiable exactly at , implementations pick a subgradient (usually 0), and any unit driven permanently negative becomes dead.

python
import numpy as np

def relu(x):
    return np.maximum(0.0, x)

def relu_grad(x):
    return (x > 0).astype(float)

x = np.array([-2.0, -0.5, 0.0, 0.5, 3.0])
print("relu:", relu(x))            # [0. 0. 0. 0.5 3. ]
print("grad:", relu_grad(x))       # [0. 0. 0. 1. 1.]
# Chain a gradient back: incoming grad [1, 1, 1, 1, 1] becomes [0, 0, 0, 1, 1]

The zero pattern of relu_grad is exactly what sparsity looks like: with batch inputs, a healthy ReLU layer keeps roughly 50 to 80 percent of its units firing on any given step.


GELU and Swish

Modern Activation Functions: GELU and SwishReLUGELUSwishxyGELU: Smooth ReLU approximationUsed in: BERT, GPT, ViT

Softmax

The Jacobian of softmax is dense but compact, and it is what the backward pass actually multiplies:

Multiplying it by the cross-entropy gradient collapses to , one subtraction per class, which is why frameworks fuse softmax and cross-entropy into a single fused kernel instead of forming this matrix.


When to Use Each Activation

Activation Function Selection GuideHidden LayersReLU (default)GELU (transformers)Swish (deep nets)Leaky ReLU (avoid dead neurons)Output LayerSoftmax (multi-class)Sigmoid (binary)None (regression)Multi-hot (multi-label)Special CasesMish (self-regularizing)Hardswish (mobile)PReLU (learned α)CELU (smooth ELU)

The Dead Neuron Problem

Formally, a unit is dead when no sample in the training set can push it positive:

Zero gradient means the optimizer never revises the weights, so the unit cannot resurrect itself. He initialization keeps initial weights at variance so that about half the units start positive, Leaky ReLU gives the negative side a slope of so the gradient is never exactly zero, and batch normalization re-centers pre-activations every step. Any one of the three is usually enough; using all three is standard in vision backbones.


Summary

  • Activation functions introduce non-linearity, enabling deep networks to learn complex patterns
  • ReLU is the default for hidden layers: fast, prevents vanishing gradients, but causes dead neurons
  • GELU/Swish are preferred for transformers and deep networks: smooth, self-gated
  • Softmax for multi-class output, Sigmoid for binary output, None for regression
  • Dead neurons are a practical concern with ReLU; use Leaky ReLU or careful initialization to mitigate

Next: Loss Functions for Deep Learning

Common Mistakes

Stacking sigmoid in deep hidden layers

Fix: Each sigmoid multiplies the gradient by at most 0.25, so ten layers cap it at 9.5e-7; use ReLU or GELU in hidden stacks and keep sigmoid for the binary head.

Applying softmax to a two class problem

Fix: Two softmax outputs are redundant since they sum to 1; use a single logit with sigmoid or binary cross-entropy instead.

Ignoring dead ReLU units after a loss spike

Fix: Track the fraction of zero activations; above about 30 percent drop the learning rate, switch to Leaky ReLU, or check the bias initialization.

Best Practices

  • ReLU for feed-forward and CNN hidden layers, GELU or Swish for transformer blocks
  • Fuse softmax with cross-entropy in the framework so the p minus y gradient never materializes a full Jacobian
  • Log activation sparsity per layer so dead units show up as a chart, not a mystery plateau

Key Takeaways

  • Without activations, L stacked layers collapse to one matrix W prime
  • Sigmoid peaks at derivative 0.25 and is not zero centered; tanh peaks at 1 and is zero centered
  • ReLU derivative is the step function 1 on positives, which preserves gradient scale through depth but can kill units
  • Softmax plus cross-entropy backpropagates to p minus y in one subtraction, and temperature tau flattens the output

Frequently Asked Questions

Why does non-linearity buy so much capacity?

A stack of linear maps is still one linear map, so its decision boundary is a single hyperplane no matter the depth. One nonlinearity per layer lets the network bend the input space, carve disconnected regions, and approximate piecewise functions: ReLU units in one layer already give linear pieces, and stacking them multiplies the arrangement possibilities exponentially in depth.

Why is ReLU's non-differentiability at zero not a problem in practice?

A single point carries zero measure in the input distribution, so stochastic gradient descent hits it with probability zero; implementations define the derivative there as 0 or 1 and move on. What matters is the surrounding region: inputs far negative give zero gradient forever, which is the dead neuron issue rather than the technicality at the origin.

When should an output layer have no activation?

Regression heads that predict an unbounded quantity use a raw linear output, because sigmoid or softmax would clip the range to 0 to 1 or a probability simplex. If the target itself is bounded, rescale the target instead of squashing the network, and only reach for sigmoid or softmax when the output genuinely has to be a probability.

Interview Questions

Q1: Compare sigmoid and ReLU derivatives and say what each implies for depth.

Sigmoid has derivative sigma(1 - sigma) bounded by 0.25 and decaying toward 0 in the saturating tails, so a chain of them multiplies gradients toward zero. ReLU is exactly 1 on positives and 0 on negatives, so gradients pass through unchanged for active units, and only the dead units lose signal.

Q2: What condition makes a ReLU neuron dead, and how do you fix it?

When w x + b is negative for every training sample the unit outputs 0 and both weight and bias gradients are exactly zero, so it can never recover. Fix with Leaky ReLU giving a 0.01 slope on the negative side, He initialization so about half the units start positive, or batch norm re-centering the pre-activations.

Q3: Why do transformers use GELU instead of ReLU?

GELU is smooth and stochastic in the negative region, roughly x times the Gaussian CDF, which keeps gradients informative near zero instead of switching off abruptly. BERT, GPT, and ViT all report small but consistent gains from that smoothness, at the cost of a few extra FLOPs per element.

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert Deep Learning Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement