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. By introducing non-linearity at each layer, they enable the network to approximate any continuous function. This is why deep learning is possible.

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 works well in shallow networks, but has a critical flaw in deep networks. When x is large (say x = 5), σ(x) ≈ 0.993, and the derivative is nearly zero. During backpropagation through multiple layers, these tiny gradients multiply together. By the time the gradient reaches early layers, it's effectively zero. The network can't learn effectively.

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 classification output layers. But for hidden layers in deep networks? Replaced by ReLU 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 neural networks (RNNs, LSTMs). The zero-centered property works well for sequence models. For standard feedforward networks, ReLU outperforms it.

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 revolutionized deep learning. In 2012, a paper about deep convolutional neural networks using ReLU showed that networks could be trained 10x deeper, 100x faster than with sigmoid. This was the breakthrough moment for modern deep learning.

Why ReLU Works

For positive inputs, the gradient is always 1. This means backpropagation works efficiently through deep networks. The vanishing gradient problem? Solved. For negative inputs, the neuron is inactive (output zero), which creates sparsity—only some neurons activate for a given input. This can improve computational efficiency and generalization.

The Dead Neuron Problem

If a neuron receives mostly negative inputs during training, its weights may never update (since gradient is zero for negative inputs). The neuron becomes "dead"—permanently inactive. This led to variants like Leaky ReLU (f(x) = 0.01x for x < 0) that allow small gradients even for negative inputs.

Advantages

  • Computationally cheap (single comparison)
  • Non-vanishing gradient
  • Sparse activation
  • Enabled deep learning era

Disadvantages

  • Dead neuron problem
  • Not zero-centered
  • Unbounded output
Today (2024), ReLU is still the industry standard for hidden layers. Use this unless you have a specific reason not to.

Linear Activation

Linear activation (also called identity function) simply outputs the input: f(x) = x. It's exclusively used in the output layer for regression tasks.

When to Use

For regression problems where output can be any real number (predicting house prices, stock prices, temperature), a linear output layer is essential. The network's hidden layers use non-linear activations (ReLU, tanh), but the output layer must be linear to allow unbounded predictions.

Using sigmoid or tanh in the output layer would incorrectly constrain predictions to a fixed range.

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))

Unlike sigmoid (which handles binary classification), softmax handles multiple classes. For a 10-class classification problem, the output layer has 10 neurons. Softmax converts their raw outputs into probabilities summing to 1.

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.

Used exclusively in the output layer for multi-class classification. Not used in hidden layers.

Practical Recommendations

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

For most problems: Use ReLU in hidden layers. Choose the output activation based on the task—sigmoid for binary classification, softmax for multi-class, and linear for 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.

The vanishing gradient problem that sigmoid suffered from was blocking progress for years. ReLU solved it with elegant simplicity, enabling the deep learning revolution. Modern variants (Leaky ReLU, GELU, Swish) improve further, but standard ReLU remains the most deployed choice in production systems.

In practice, your choice is simple: ReLU for hidden layers, and select the output activation based on your task. The theory is settled. Focus on architecture, data, and training.