Skip to content

Activation Function

The small nonlinear function each neuron applies to its weighted sum. Without it, a deep network would be no more powerful than a straight line.

Also nonlinearity · ReLU · sigmoid · tanh · GELU · softmax

Role · kind
Core ideasConcept
Level
Beginner

It is each worker's rule for how excited to get. One rule: 'stay silent unless the total is positive, then shout exactly that loud' (that is ReLU).

Where it fits

+All relationships as a list

See it on the full map

How it works

A layer of a neural network multiplies its inputs by weights and adds them up. Stack two such layers and you just get another multiply-and-add, still a straight-line model. The activation function breaks that: it bends the output of each neuron, so stacking layers builds genuinely complex shapes.

The common ones:

  • ReLU (rectified linear unit): zero for negative inputs, unchanged for positive ones. Simple, fast, and the default since around 2012.
  • GELU: a smooth version of ReLU, standard in Transformers.
  • Sigmoid: squashes to 0..1. Used for a final yes/no probability, as in logistic regression.
  • Tanh: squashes to −1..1. Common in older RNNs and LSTMs.
  • Softmax: turns a list of scores into probabilities that sum to 1. Used at the output of classifiers and inside attention.

Sigmoid and tanh flatten out for large inputs, so their gradient is nearly zero there. Through many layers those small gradients multiply and vanish, which is one reason ReLU took over.

The mathReLU(z)=max⁡(0,z),σ(z)=11+e−z,softmax(z)i=ezi∑jezj\text{ReLU}(z) = \max(0, z), \qquad \sigma(z) = \frac{1}{1 + e^{-z}}, \qquad \text{softmax}(z)_i = \frac{e^{z_i}}{\sum_j e^{z_j}}

Everyday use cases

  • Case 01

    Every neural network

    ReLU and GELU sit between the layers of image models and language models alike.

Strengths, weaknesses and when to use it

Strengths

  • Gives networks the ability to model curves and complex shapes.

Weaknesses

  • Saturating functions (sigmoid, tanh) cause vanishing gradients in deep stacks.

When to use itDefault to ReLU or GELU in hidden layers; sigmoid for a single probability; softmax for multi-class outputs.

Check yourself

  1. Q01

    What is ReLU(−3)?

    Show answer

    B: 0

  2. Q02

    Why do deep networks rarely use sigmoid in hidden layers today?

    Show answer

    A: Its gradient becomes tiny for large inputs, slowing learning in deep stacks

Go deeper