Leaky ReLU (leaky rectified linear unit) is an activation function defined as f(x) = x for positive inputs and f(x) = αx for negative inputs, where α is a small positive slope, typically 0.01. In neural networks, it modifies the standard ReLU so that negative inputs produce a small nonzero output and gradient instead of exactly zero.
The function was introduced in 2013 by Maas, Hannun and Ng in work on acoustic models for speech recognition. Its purpose is to reduce the dying ReLU problem, in which neurons become permanently inactive during training, while keeping the speed and simplicity that made ReLU the default choice in deep learning within artificial intelligence.
How Leaky ReLU transforms its input
Leaky ReLU applies a piecewise linear transformation with two regions. For any input greater than zero, the output equals the input, so the positive side behaves exactly like ReLU. For any input below zero, the output is the input multiplied by α, producing a gently sloped line instead of a flat floor.
The derivative is equally simple: 1 for positive inputs and α for negative inputs. At exactly zero the function is not differentiable, and frameworks conventionally assign one of the two slopes. Because the computation is a comparison and a multiplication, Leaky ReLU adds negligible cost compared with exponential functions such as ELU or GELU.
The table below shows sample outputs and gradients for the common setting α = 0.01.
| Input x | ReLU output | Leaky ReLU output | Leaky ReLU gradient |
|---|---|---|---|
| -10 | 0 | -0.1 | 0.01 |
| -1 | 0 | -0.01 | 0.01 |
| 0.5 | 0.5 | 0.5 | 1 |
| 3 | 3 | 3 | 1 |
Why Leaky ReLU prevents dying neurons
Leaky ReLU prevents dying neurons because the gradient never becomes exactly zero. With standard ReLU, a neuron whose pre-activation is negative for every training example outputs zero and receives zero gradient during backpropagation, so its weights stop updating and it may never recover.
Neurons usually die after a large weight update pushes the bias strongly negative, a risk that grows with high learning rates or poor weight initialization. With Leaky ReLU, a small gradient of α still flows through negative inputs, so gradient descent can pull the neuron back into the active region. The negative outputs also shift the mean activation closer to zero, which can make optimization slightly better conditioned.
The leak does not solve every gradient problem. It addresses dead units in the forward and backward pass, but it does not on its own cure the vanishing gradient problem in very deep networks, which is handled mainly by residual connections, normalization and careful initialization.
Practitioners can measure the share of dead units directly by recording, for each neuron, the fraction of a validation batch that produces a positive pre-activation. A layer in which more than a few percent of ReLU units never activate is a strong candidate for Leaky ReLU, a lower learning rate or better initialization. After switching, the same diagnostic should show nearly every unit receiving nonzero gradient.
The table below links typical symptoms observed during training to their likely cause and the role Leaky ReLU can play.
| Symptom | Likely cause | Suggested remedy |
|---|---|---|
| Many units output zero for all inputs | Dying ReLU after large updates | Switch to Leaky ReLU or lower the learning rate |
| Loss plateaus early in a GAN | Sparse discriminator gradients | Use Leaky ReLU with α of 0.2 |
| Gradients shrink with depth | Vanishing gradient problem | Add residual connections and normalization |
| Activations explode in early layers | Initialization ignores the slope | Use He initialization adjusted for α |
Choosing the negative slope and related variants
The negative slope α is a hyperparameter that controls the strength of the leak. Values between 0.01 and 0.3 are common, and the right choice depends on the architecture and the training stability required.
| Slope α | Typical setting | Effect |
|---|---|---|
| 0.01 | Default in many frameworks | Close to ReLU, minimal leak |
| 0.1 | Some detection networks | Stronger gradient flow for negatives |
| 0.2 | GAN discriminators | Keeps gradients informative for the generator |
| Learned | Parametric ReLU | Slope optimized per channel during training |
| Random range | Randomized leaky ReLU | Slope sampled in training, fixed at inference |
Parametric ReLU (PReLU), proposed in 2015, makes α a trainable parameter, often one per channel. Randomized leaky ReLU samples α from a range during training as a mild regularizer. When using He initialization, the variance formula should account for the slope by dividing by 1 + α², a detail that matters for larger α.
Leaky ReLU compared with other activation functions
Leaky ReLU sits between plain ReLU and smooth activations in both cost and behavior. The comparison below summarizes the properties that guide selection.
| Activation | Negative region | Smooth | Relative cost | Typical use |
|---|---|---|---|---|
| ReLU | Zero | No | Lowest | General convolutional networks |
| Leaky ReLU | Small linear slope | No | Very low | GANs, detection, sparse-gradient settings |
| ELU | Exponential saturation | Yes | Moderate | Networks needing zero-centered outputs |
| GELU | Small smooth dip | Yes | Moderate | Transformer feedforward layers |
| Swish | Small smooth dip | Yes | Moderate | Efficient image classifiers |
In large language models, gated variants such as SwiGLU have largely replaced simple activations, so Leaky ReLU is now more common in convolutional, generative adversarial and embedded models than in transformers.
Practical use and common mistakes
Leaky ReLU is a sensible default when dead units are observed or when gradient flow through negative values matters, as in GAN discriminators. In well-normalized modern networks, its accuracy advantage over ReLU is often small and inconsistent across benchmarks, so it should be selected by validation rather than assumption.
- Confusing framework defaults: PyTorch uses 0.01 by default, while some Keras versions used 0.3, which changes behavior noticeably.
- Applying it at the output layer: classification and regression heads usually need softmax, sigmoid or linear outputs instead.
- Setting α too large: as α approaches 1, the function becomes nearly linear and the network loses expressive nonlinearity.
- Ignoring quantization: on integer hardware the small slope may need careful scaling to avoid rounding to zero.
The simple explanation
Each artificial neuron decides how strongly to pass a signal on. Standard ReLU blocks every negative signal completely. Sometimes a neuron gets stuck in that blocked state and stops learning. Leaky ReLU lets a tiny trickle through instead.
Picture a door that never shuts fully. Even when it is mostly closed, a little air still moves. That small opening lets training notice the neuron and adjust it. The neuron stays alive and useful.
How it is used in practice
A machine learning engineer trains a generative adversarial network to create synthetic product images at 128 by 128 pixels. With standard ReLU in the discriminator, training becomes unstable after a few thousand steps: the discriminator saturates, and the generator receives almost no useful gradient.
The engineer replaces each ReLU in the discriminator with Leaky ReLU using a slope of 0.2, a widely used setting for this architecture. The discriminator now passes informative gradients even for strongly negative features, and training remains stable over the full run, producing visibly sharper and more varied images while adding no measurable cost per step.