Skip to content
E
Educatum

Pros and Cons of the Sigmoid Function

Curated by Educatum AI teamLast updated:
Model Evaluation
Direct Answer

The sigmoid function maps real inputs smoothly into (0, 1), making it ideal for binary classification outputs and multiplicative gates where values represent probabilities or fractions. However, as a hidden-layer activation in deep networks it suffers from severe vanishing gradients (maximum derivative is 0.25), non-zero-centered outputs that slow optimization, and higher exponential compute cost.

Study Card: Pros and Cons of the Sigmoid Function

Direct Answer

The logistic sigmoid function and its derivative are given by:

σ(z)=11+e−z,σ′(z)=σ(z)(1−σ(z))∈(0,14]\sigma(z) = \frac{1}{1 + e^{-z}}, \qquad \sigma'(z) = \sigma(z)\big(1 - \sigma(z)\big) \in \left(0, \frac{1}{4}\right]

Pros:

  • Probability & Gating Interpretation: Outputs lie strictly in (0,1)(0, 1), making sigmoid natural for binary classification outputs (paired with binary cross-entropy) and soft gates (e.g., LSTM/GRU gates, squeeze-and-excitation).
  • Smooth & Differentiable: Provides smooth gradients everywhere with an analytical derivative expressed directly in terms of σ(z)\sigma(z).

Cons:

  • Severe Vanishing Gradients: Even at its steepest point (z=0z = 0), σ′(0)=0.25\sigma'(0) = 0.25, and for ∣z∣≳5|z| \gtrsim 5 it saturates near 00; multiplying derivatives ≤0.25\le 0.25 across LL hidden layers attenuates gradients by at least 0.25L0.25^L.
  • Non-Zero-Centered Output: Because all activations are strictly positive (σ(z)>0\sigma(z) > 0), gradients with respect to downstream weights all share the same sign as the upstream error signal, inducing inefficient zig-zagging updates during SGD.
  • Computational Expense: Requires computing exponentials compared to simple thresholding in ReLU.

Key Terms

  • Activation Function: Non-linear mapping enabling neural networks to approximate non-linear functions.
  • Vanishing Gradients: Exponential shrinkage of gradients during backpropagation through saturated or bounded-derivative layers, stalling early-layer learning.
  • Non-Zero-Centered: Strictly positive outputs that bias weight gradient signs for a given input sample.
  • Binary Classification: Predicting probabilities over two classes using sigmoid + binary cross-entropy loss.
  • Saturation: Flat regions (z≪0z \ll 0 or z≫0z \gg 0) where σ′(z)≈0\sigma'(z) \approx 0.

Example

In click-through-rate prediction, the final layer applies sigmoid to output e.g. 0.8 (80% click probability). Using sigmoid inside deep hidden layers, however, degrades training: any neuron whose weighted sum drifts to +8+8 or −8-8 yields σ′(8)≈0.00033\sigma'(8) \approx 0.00033, choking gradient backpropagation to earlier layers, while strictly positive outputs constrain downstream weight updates to move synchronously in the same sign direction on every sample.

Code Implementation

import numpy as np
import matplotlib.pyplot as plt

def sigmoid(z):
    """
    Numerically stable sigmoid supporting scalars and NumPy arrays
    without overflow warnings on large negative or positive inputs.
    """
    z = np.asarray(z, dtype=float)
    out = np.empty_like(z)
    pos = z >= 0
    out[pos] = 1.0 / (1.0 + np.exp(-z[pos]))
    exp_z = np.exp(z[~pos])
    out[~pos] = exp_z / (1.0 + exp_z)
    return out

# Generate data for plotting
z = np.linspace(-10, 10, 200)
sigmoid_z = sigmoid(z)
sigmoid_grad = sigmoid_z * (1.0 - sigmoid_z)

# Plot sigmoid function
plt.figure(figsize=(8, 5))
plt.plot(z, sigmoid_z)
plt.xlabel("z")
plt.ylabel("sigmoid(z)")
plt.title("Sigmoid Function")
plt.grid(True)

# Plot sigmoid derivative (peaks at 0.25 and vanishes in tails)
plt.figure(figsize=(8, 5))
plt.plot(z, sigmoid_grad)
plt.xlabel("z")
plt.ylabel("sigmoid'(z)")
plt.title("Derivative of Sigmoid Function (Max = 0.25)")
plt.grid(True)
plt.show()
  • Other Activation Functions: tanh solves zero-centering (with max derivative 1.0) but still saturates; ReLU and GELU avoid positive saturation and dominate modern hidden layers, while softmax generalizes sigmoid to multi-class outputs.
  • Backpropagation & Logits: In frameworks like PyTorch (BCEWithLogitsLoss), combining sigmoid and binary cross-entropy into a single log-sum-exp step ensures numerical stability and clean (p^−y)(\hat{p} - y) gradients.
  • Gradient Descent Optimization: Non-zero-centered activations explain why zero-centered activations or normalization layers (BatchNorm / LayerNorm) accelerate convergence.
  • Binary Cross-Entropy Loss: Standard paired loss that avoids the vanishing-gradient plateau produced when pairing sigmoid with MSE.
View all →

Try keywords like RoPE, FlashAttention, DPO, or Blind 75.