Sign in

ELU

Exponential Linear Unit

An activation that passes positive inputs unchanged and bends negative inputs smoothly toward a floor of −α-\alpha.

Overview

ReLU sets every negative input to zero, which also sets its slope to zero. ELU keeps the positive side of ReLU but replaces the flat negative side with an exponential curve. A slightly negative input gives a slightly negative output. A very negative input settles at −α-\alpha and goes no lower. Because outputs can be negative, the average output of a layer sits closer to zero than with ReLU, and the slope on the negative side is small but never exactly zero.

A short history

Djork-Arné Clevert, Thomas Unterthiner and Sepp Hochreiter introduced ELU in a 2015 paper. ReLU outputs are never negative, so the average activation of a layer sits above zero and shifts the inputs of the next layer. ELU lets negative inputs produce small negative outputs that level off at a floor, which pulls the average closer to zero and sped up training of deep networks without batch normalisation.

How it works

  1. Take the input xx that a layer has computed for one unit.
  2. If x>0x > 0, return xx unchanged.
  3. If x≤0x \le 0, return α (ex−1)\alpha\,(e^{x} - 1). This is 0 at x=0x = 0 and approaches −α-\alpha as xx falls.
  4. During training, multiply the incoming gradient by 1 on the positive side and by αex\alpha e^{x} on the negative side.

Watch out for

  • The exponential costs more to compute than ReLU's comparison, which matters on very small or latency-bound models.
  • For very negative inputs the slope αex\alpha e^{x} becomes tiny, so a unit pushed far below zero still learns slowly. The problem is reduced, not removed.
  • With α≠1\alpha \ne 1 the slope jumps from α\alpha to 1 at zero, so the curve has a corner there. Only α=1\alpha = 1 gives a smooth slope.

Use cases

When to use it

Feed-forward and convolutional networks where ReLU units stop learning, or where you want activations centred near zero without adding a normalisation layer.

In industry

Computer vision
Convolutional image classifiers trained without batch normalisation use ELU so that layer outputs stay centred near zero.
Reinforcement learning
Small policy and value networks for continuous control often use ELU because a smooth curve with negative outputs trains steadily on noisy returns.
Graph learning
Graph attention networks apply ELU after each attention layer when classifying nodes in citation and protein graphs.

Choosing it: what must hold

  • A network where a mean activation near zero helps, for example one with little or no normalisation.
  • Enough compute to pay for an exponential on every negative input, which is slower than ReLU.
  • Inputs scaled to a moderate range, so the negative side is used and not saturated at its floor.

When to choose something else

IfUse instead
Speed matters most and the network already uses batch or layer normalisationReLU
You want a plain feed-forward network that keeps its own activations normalisedSELU, with LeCun normal initialisation
The model is a transformerGELU

Math foundations

  1. The activation

    ELU⁡(x)={x,x>0α (ex−1),x≤0\operatorname{ELU}(x) = \begin{cases} x, & x > 0 \\ \alpha\,(e^{x} - 1), & x \le 0 \end{cases}

    Identity on the positive side, a shifted exponential on the negative side. Both pieces equal 0 at x=0x = 0, so the curve has no jump.

  2. The floor

    lim⁡x→−∞ELU⁡(x)=−α\lim_{x \to -\infty} \operatorname{ELU}(x) = -\alpha

    As xx falls, exe^{x} goes to 0 and the output settles at −α-\alpha. This bounded negative part is what pulls the mean activation toward zero.

  3. Its slope

    ddxELU⁡(x)={1,x>0α ex,x≤0\frac{d}{dx}\operatorname{ELU}(x) = \begin{cases} 1, & x > 0 \\ \alpha\,e^{x}, & x \le 0 \end{cases}

    The factor backpropagation multiplies by. On the negative side it is positive for every finite xx, unlike ReLU's zero.

  4. A shortcut for the negative slope

    ddxELU⁡(x)=ELU⁡(x)+α(x≤0)\frac{d}{dx}\operatorname{ELU}(x) = \operatorname{ELU}(x) + \alpha \qquad (x \le 0)

    Since αex=α(ex−1)+α\alpha e^{x} = \alpha(e^{x} - 1) + \alpha, the slope can be read from the output already computed. Frameworks use this to save one exponential.

Symbols

xx
the input to the activation (one unit's pre-activation)
α\alpha
the positive constant that sets the negative floor; alpha in the config, default 1
exe^{x}
the exponential function

Worked by hand

Compute ELU and its slope at x=−1x = -1 and x=2x = 2 with α=1\alpha = 1. Use e−1=0.3679e^{-1} = 0.3679.

ELU⁡(−1)=1×(0.3679−1)=−0.6321\operatorname{ELU}(-1) = 1 \times (0.3679 - 1) = -0.6321
ELU⁡′(−1)=1×0.3679=0.3679\operatorname{ELU}'(-1) = 1 \times 0.3679 = 0.3679
ELU⁡(2)=2,ELU⁡′(2)=1\operatorname{ELU}(2) = 2, \qquad \operatorname{ELU}'(2) = 1

At −1-1 the output is −0.6321-0.6321 and the slope is 0.3679, which equals the output plus α\alpha. ReLU would give 0 and 0 there.

Visual example

Loading the example.

Try this

  • Move across the curve and read the output and the slope together.
  • Find where the slope is close to zero: a unit there has stopped learning.

Code sample

import numpy as np
from impl import ELU
from config import ELUConfig

act = ELU(ELUConfig(alpha=1.0))
y = act.forward(np.array([-1.0, 0.0, 2.0]))      # [-0.6321, 0.0, 2.0]
dy = act.backward(np.array([-1.0, 0.0, 2.0]))    # [0.3679, 1.0, 1.0]
Read the implementation (36 lines)
"""ELU: exponential linear unit, f(x) = x for x > 0 and alpha * (exp(x) - 1) for x <= 0.

NumPy only. `forward` computes the activation, `backward` the gradient with respect to the input.
"""
from __future__ import annotations

import numpy as np

try:
    from .config import ELUConfig
except ImportError:  # run from the template's own folder
    from config import ELUConfig

class ELU:
    """f(x) = x for x > 0, alpha * (exp(x) - 1) for x <= 0."""

    def __init__(self, config: ELUConfig | None = None) -> None:
        self.config = config or ELUConfig()

    def forward(self, x: np.ndarray) -> np.ndarray:
        """Apply the activation element by element. x: any shape. Returns the same shape."""
        x = np.asarray(x, dtype=float)
        negative = self.config.alpha * np.expm1(np.minimum(x, 0.0))  # the minimum keeps exp from overflowing
        return np.where(x > 0, x, negative)

    def backward(self, x: np.ndarray, grad_output: np.ndarray | None = None) -> np.ndarray:
        """d f / d x at x, times `grad_output` when given (the chain rule step of backpropagation).

        f'(x) = 1 for x > 0 and alpha * exp(x) for x <= 0.
        """
        x = np.asarray(x, dtype=float)
        negative = self.config.alpha * np.exp(np.minimum(x, 0.0))
        local = np.where(x > 0, 1.0, negative)
        return local if grad_output is None else local * np.asarray(grad_output, dtype=float)

    __call__ = forward
Repository
gitlab.com/designsbyduhart/solomon-templates/activation-elu
Needs
Python 3.10 and NumPy
Tests
7, run with python3 -m unittest -v

Practice

Build ELU(ELUConfig(alpha=1.0)) and call forward and backward on 201 points between -6 and 6. Check backward against a finite difference of forward. Then set alpha=0.5 and find the input where the slope jumps.

Check on learning

  1. A ReLU unit whose inputs are all negative receives no gradient. What does an ELU unit in the same position receive, and is that enough to recover?
    A way to think about it

    Evaluate the slope αex\alpha e^{x} at x=−1x = -1 and at x=−10x = -10. Recovery depends on how far below zero the inputs sit.

  2. Why might a layer whose mean output is near zero train faster than one whose outputs are all non-negative?
    A way to think about it

    Think about the next layer. If every input it receives is positive, the gradients for all weights of one unit share a sign, which forces zig-zag updates.

  3. You raise α\alpha from 1 to 3. What changes in the curve, and what new problem appears at x=0x = 0?
    A way to think about it

    Compare the slope just left of zero, α\alpha, with the slope just right of zero, 1. Consider what a jump in slope means for a smooth optimiser.

  4. When would you choose ELU over GELU or SiLU, which are also smooth and also allow negative outputs?
    A way to think about it

    Compare the negative tails. ELU saturates at a nonzero floor and is monotonic. GELU and SiLU return to zero and dip. Ask which behaviour your layer statistics need.