Activation Functions: From Theory to Practice

Introduction

Without activation functions, neural networks are just expensive linear algebra. They become simple matrix multiplications that can't learn anything interesting. Adding the right activation function at each layer transforms them into something powerful—able to recognize patterns in images, understand language, and beat humans at complex games.

This article explains six activation functions: what they do, how they work, and when to use each one. We'll focus on practical understanding rather than mathematical proofs.

Why Activation Functions Matter

Consider a three-layer network without activation functions. Each layer performs a linear transformation: output = W₃(W₂(W₁ × input)). This simplifies to output = W × input, where W is the product of all weight matrices. No matter how many layers you stack, the network remains linear.

Activation functions break this limitation. Universal approximation theorems show that a network with a suitable non-linearity and enough hidden units can approximate continuous functions on a bounded domain to any accuracy. They say nothing about how easy such a network is to train.

f(x) f′(x)
Vanishing gradient — f′(x) ≈ 0

Binary Step Function

The binary step function outputs 0 or 1 based on whether the input is negative or positive. This was the first activation function used in early perceptrons.

f(x) = 0 if x < 0
f(x) = 1 if x ≥ 0

The Problem

The gradient is zero everywhere except at x = 0, where it's undefined. During backpropagation, gradients can't flow through this function, making training impossible with modern optimization algorithms. Additionally, the output provides no information about the magnitude of the input—only its sign.

Result: Obsolete. It was historically important but doesn't work with modern training methods.

Sigmoid Function

Sigmoid was the dominant activation function from the 1990s through the 2000s. It maps any input to a value between 0 and 1.

σ(x) = 1 / (1 + e^(-x))

The output can be interpreted as a probability. The function is smooth and differentiable, making optimization possible with gradient descent.

The Vanishing Gradient Problem

Sigmoid can work in shallow networks, but it is prone to a problem in deep ones. Its derivative is at most 0.25 and shrinks quickly away from zero: at x = 5, σ(x) ≈ 0.993 and the derivative is about 0.007. During backpropagation these factors multiply across layers, so gradients reaching early layers can become very small and slow learning. Initialization and normalization can reduce this but do not change the shape of the function.

Advantages

  • Output (0,1) is interpretable as probability
  • Smooth gradient enables optimization
  • Clear boundary at x = 0

Disadvantages

  • Vanishing gradient in extreme ranges
  • Computationally expensive (exponential)
  • Not zero-centered
Still used for binary and multi-label output layers, and as a gate inside LSTMs and GRUs. For hidden layers in deep feedforward networks, it was largely replaced by ReLU-family functions in the 2010s.

Hyperbolic Tangent (Tanh)

Tanh is sigmoid's improved cousin, outputting values between -1 and 1 instead of 0 and 1.

tanh(x) = (e^x - e^(-x)) / (e^x + e^(-x))

Zero-Centered Output

The key improvement: tanh's output is zero-centered. When inputs to a layer are zero-centered (mean close to zero), gradients flow more efficiently. This makes optimization faster than sigmoid. However, tanh still suffers from vanishing gradients in extreme ranges, just less severely.

Advantages

  • Zero-centered output improves convergence
  • Stronger gradients than sigmoid
  • Good for RNN hidden layers

Disadvantages

  • Still suffers from vanishing gradients
  • Computationally expensive
Where you find it: Recurrent networks (RNNs, LSTMs), where it is the usual hidden-state non-linearity. For deep feedforward networks, ReLU-family functions are usually preferred.

Rectified Linear Unit (ReLU)

ReLU is deceptively simple: it outputs the input if positive, zero if negative.

f(x) = max(0, x)

Despite its simplicity, ReLU was a major practical step for deep learning. Nair & Hinton (2010) and Glorot et al. (2011) studied it in deep networks, and AlexNet (2012) reported that a four-layer CNN with ReLUs reached 25% training error on CIFAR-10 six times faster than an equivalent tanh network.

Why ReLU Works

For positive inputs, the gradient is exactly 1, so ReLU does not saturate there. This reduces vanishing gradients but does not eliminate them: the gradient is zero for negative inputs, and training very deep networks still depends on initialization, normalization, and skip connections. For negative inputs, the neuron outputs zero, which creates sparsity: only some neurons activate for a given input.

The Dead Neuron Problem

If a neuron's input is negative for essentially all training examples, its gradient is zero and its weights stop updating. The neuron becomes "dead". A large learning rate can cause this. Variants like Leaky ReLU (f(x) = 0.01x for x < 0, f(x) = x otherwise) keep a small gradient for negative inputs.

Advantages

  • Computationally cheap (single comparison)
  • No saturation for positive inputs
  • Sparse activation
  • Helped make deeper networks easier to train

Disadvantages

  • Dead neuron problem
  • Not zero-centered
  • Unbounded output
ReLU remains a common default for hidden layers in CNNs and MLPs. Transformers commonly use smoother relatives such as GELU.

Linear Activation

Linear activation (also called the identity function) simply outputs the input: f(x) = x. It is most often seen in the output layer for regression, and also appears wherever a layer is meant to stay linear, such as a projection or an embedding.

When to Use

For regression problems where output can be any real number, a linear output layer is the usual choice. The hidden layers still need non-linear activations.

Sigmoid or tanh in the output layer constrains predictions to a fixed range. That is wrong for unbounded targets, but it can be appropriate when the target really is bounded. Softplus is one option for strictly positive targets.

Softmax Function

Softmax converts a vector of arbitrary values into a probability distribution where all outputs sum to 1.

softmax(x_i) = e^(x_i) / Σ(e^(x_j))

Softmax handles mutually exclusive classes. For a 10-class classification problem, the output layer has 10 neurons, and softmax converts their raw outputs into probabilities summing to 1. When several labels can be true at once, use an independent sigmoid per label instead.

The exponential in the numerator emphasizes differences between values. If one value is much larger, softmax assigns it most of the probability mass. This "winner-take-all" property makes softmax ideal for classification.

Most commonly used in the output layer for multi-class classification. It also appears inside networks: attention mechanisms use it to turn scores into weights.

Practical Recommendations

Function Output Range Best Use Status
Binary Step {0, 1} Historical only Obsolete
Sigmoid (0, 1) Binary classification output Common for outputs
Tanh (-1, 1) RNN hidden layers Still used
ReLU [0, ∞) Hidden layers (default) Common default
Linear (-∞, ∞) Regression output Common
Softmax (0, 1) Multi-class output Standard

For most problems: Start with ReLU or a close relative in hidden layers. Choose the output activation based on the task: sigmoid for binary or multi-label classification, softmax for mutually exclusive classes, and linear for unbounded regression.

Conclusion

Activation functions are fundamental to neural networks. They're what makes deep learning possible. The progression from sigmoid to ReLU represents real progress—not just in mathematics, but in practical capability.

Saturating activations made deep networks harder to train, and ReLU eased that with a very simple function. It worked alongside better initialization, normalization, data, and hardware rather than alone. Modern variants such as Leaky ReLU, GELU, and Swish are useful alternatives, and which works best is an empirical question for each architecture.

In practice, a good default is ReLU or GELU for hidden layers, with the output activation selected by your task. Treat this as a starting point, and test alternatives if training or results suggest a problem.