Neural network formulas: a cheat sheet · Activation functions

Leaky ReLU: the “leaky” ReLU

ReLU with a tiny fix: to the left of zero the function does not zero the signal, it multiplies it by a small α. We take it apart bone by bone: why that is enough to keep neurons alive, where the He initialization with the factor 1 + α² comes from, how a network of such neurons cuts space into flat pieces, and how PReLU learns α by itself.

Javharbek Abdulatipov · 30 min read
$$\operatorname{LReLU}(x)=\max(\alpha x,\,x)=\begin{cases}x, & x>0\\ \alpha x, & x\le 0\end{cases}$$

Why we need it

ReLU is the most popular activation in deep learning: $\max(0,x)$ is instant to compute, and to the right of zero the gradient does not vanish. But it has a weak spot. To the left of zero ReLU does not dampen the signal, it zeroes it — and the gradient with it. A neuron whose input is negative on every example outputs 0, receives a zero gradient and never learns again. This is the “dying ReLU”.

Leaky ReLU is the minimal fix: to the left of zero the graph is not horizontal but slightly tilted, $\alpha x$ with a small $\alpha$ (usually from $0.01$ to $0.3$). The signal “leaks” through the closed door — hence the name.

Where it appears:

  • GAN discriminators — in DCGAN (Radford et al., 2015) every discriminator layer uses Leaky ReLU with $\alpha=0.2$;
  • YOLO detectors — the Darknet network of YOLOv2 and YOLOv3 is built on Leaky ReLU with $\alpha=0.1$;
  • graph networks — the attention coefficients in GAT are computed through Leaky ReLU with $\alpha=0.2$;
  • convolutional networks with PReLU — the variant with a learnable $\alpha$ (He et al., 2015) helped push the ImageNet top-5 error below the estimated human error for the first time;
  • any network where ReLU “dies” — the swap is one line and costs almost nothing.
The essentials in a minute

$\operatorname{LReLU}(x)=x$ for $x>0$ and $\alpha x$ for $x\le0$. The derivative is a step: $1$ on the right and $\alpha$ on the left, so the gradient never vanishes completely. The function stays piecewise linear, monotonic and almost as cheap as ReLU. With $\alpha=0$ it is ReLU, with $\alpha=1$ the identity, with a learnable $\alpha$ it is PReLU.

Intuition: a door that never closes completely

ReLU is like a door: a positive signal passes through in full, a negative one hits the closed leaf. Leaky ReLU leaves a gap — the negative signal gets through, but weakened $1/\alpha$ times. With $\alpha=0.1$ the input $-2$ becomes $-0.2$.

Drag the point along the graph. The orange “slope triangle” shows the derivative: one step of 1 along $x$ changes the value by $\alpha$ to the left of zero and by 1 to the right. Below is the derivative itself: two horizontal steps with a jump at zero. Move the $\alpha$ slider: from ReLU ($\alpha=0$) through the leaky variant to the line $y=x$ ($\alpha=1$).

Figure 1. Leaky ReLU and its derivative at $\alpha=0.1$. At $x=-2$ the value is $-0.2$ and the derivative is $0.1$. The grey dashed line is ReLU, the dotted line is $y=x$. At zero there is no derivative: it equals $\alpha$ on the left and 1 on the right; move the point to zero and the read-out shows the subdifferential $[\alpha,\,1]$ and the value $\alpha$ that PyTorch takes.
What to notice

On the left the graph is not flat, just very shallow: with $\alpha=0.01$ the input $-100$ gives only $-1$. All the nonlinearity of Leaky ReLU sits at one point — the kink at zero, where the slope switches from $\alpha$ to 1. The expressive power of a network of such neurons comes precisely from these kinks.

The formula, bone by bone

It pays to be able to write the same function in three ways — each one is useful in its own place.

1. By cases

$$\operatorname{LReLU}_\alpha(x)=\begin{cases}x, & x>0,\\ \alpha x, & x\le 0.\end{cases}$$
$x$
the neuron’s input — usually the pre-activation $z=w^\top h+b$;
$\alpha$
the slope of the negative part, a hyperparameter; usually $0<\alpha<1$;
$\alpha x$
the “leak”: a negative input is not zeroed but shrunk $1/\alpha$ times.

At $x=0$ both branches give zero, so it does not matter which branch zero belongs to: the function is continuous.

2. Through the maximum

$$\operatorname{LReLU}_\alpha(x)=\max(\alpha x,\;x)\qquad(\alpha\le 1)$$

For $x>0$ and $\alpha\le1$ we have $x\ge\alpha x$, and for $x<0$ the opposite, $\alpha x\ge x$. So the maximum picks the right branch by itself. But only when $\alpha\le1$: with $\alpha=2$ the term $2x$ wins on the right, and you get a different function. This form is handy in code (np.maximum(alpha * x, x)), but the condition is easy to forget.

3. A linear part plus the absolute value

$$\operatorname{LReLU}_\alpha(x)=\frac{1+\alpha}{2}\,x+\frac{1-\alpha}{2}\,|x|$$

Check: for $x>0$ we get $\frac{1+\alpha}{2}x+\frac{1-\alpha}{2}x=x$, for $x<0$ — $\frac{1+\alpha}{2}x-\frac{1-\alpha}{2}x=\alpha x$. This form holds for any $\alpha$ and explains the main point: Leaky ReLU is a linear function plus “a bit of absolute value”. All the nonlinearity lives in the second term, and its share $\frac{1-\alpha}{2}$ shrinks as $\alpha$ grows. At $\alpha=1$ the nonlinearity disappears completely.

Figure 2. On the left, Leaky ReLU as the upper envelope of the two lines $y=x$ and $y=\alpha x$. Move $\alpha$ above 1: the envelope (black dashes) breaks away from the real Leaky ReLU (blue line). On the right, the split into a linear part and the absolute value; at $\alpha=0.2$ the coefficients are $0.6$ and $0.4$.
$x$$\alpha=0.01$$\alpha=0.2$$\operatorname{LReLU}'(x)$
−5−0.05−1$\alpha$
−2−0.02−0.4$\alpha$
−0.5−0.005−0.1$\alpha$
0.50.50.5$1$
222$1$
555$1$

To the right of zero all variants coincide with ReLU; they differ only in how much negative signal “leaks” through.

Properties

  • Domain and range: the whole real line $\mathbb R$ (for $\alpha>0$). ReLU only takes values in $[0,\,+\infty)$.
  • Continuity and piecewise linearity: two lines glued at zero. The function is differentiable everywhere except $x=0$.
  • Strict monotonicity for $\alpha>0$: a larger input gives a larger output. Hence the function is invertible: $\operatorname{LReLU}_\alpha^{-1}(y)=y$ for $y>0$ and $y/\alpha$ for $y\le0$, i.e. $\operatorname{LReLU}_{1/\alpha}$. ReLU has no inverse: all negative inputs are glued into zero.
  • Positive homogeneity: $\operatorname{LReLU}(cx)=c\,\operatorname{LReLU}(x)$ for $c\ge0$. The scale of the input carries over to the output — hence the simple initialization formulas.
  • Lipschitz continuity with constant $\max(1,|\alpha|)$, i.e. 1 for $\alpha\le1$: $|\operatorname{LReLU}(a)-\operatorname{LReLU}(b)|\le|a-b|$.
  • Unboundedness above and below, though downwards the function grows $1/\alpha$ times more slowly.
  • Special cases: $\alpha=0$ is ReLU, $\alpha=1$ the identity, $\alpha=-1$ the absolute value $|x|$ (no longer monotonic).

Mean and spread of the output

Let the neuron’s input be $z\sim N(0,1)$. Then

$$\mathbb E\bigl[\operatorname{LReLU}(z)\bigr]=\frac{1-\alpha}{\sqrt{2\pi}},\qquad \mathbb E\bigl[\operatorname{LReLU}(z)^2\bigr]=\frac{1+\alpha^2}{2}$$

At $\alpha=0.01$ the mean is $0.395$ (ReLU: $0.399$), at $\alpha=0.2$ it is $0.319$. The larger $\alpha$, the closer the outputs are to zero mean, which makes the next layer slightly easier to train. The second moment $\frac{1+\alpha^2}{2}$ will be needed in the section on initialization.

Where these formulas come from

For $z\sim N(0,1)$ we know that $\mathbb E[z\,\mathbf 1_{z>0}]=\varphi(0)=1/\sqrt{2\pi}$, and by symmetry $\mathbb E[z\,\mathbf 1_{z<0}]=-1/\sqrt{2\pi}$. Therefore

$$\mathbb E[\operatorname{LReLU}(z)]=\mathbb E[z\mathbf 1_{z>0}]+\alpha\,\mathbb E[z\mathbf 1_{z<0}]=\frac{1}{\sqrt{2\pi}}-\frac{\alpha}{\sqrt{2\pi}}$$

Likewise $\mathbb E[z^2\mathbf 1_{z>0}]=\mathbb E[z^2\mathbf 1_{z<0}]=\tfrac12$, so $\mathbb E[\operatorname{LReLU}(z)^2]=\tfrac12+\tfrac{\alpha^2}{2}$. The second formula holds for any symmetric distribution with unit variance, the first only for the normal one.

The derivative: a step instead of a cliff

On each branch the function is linear, so the derivative is simply the slope of the branch:

$$\operatorname{LReLU}'_\alpha(x)=\begin{cases}1, & x>0,\\ \alpha, & x<0.\end{cases}$$
Derivation from the definition

For $x>0$ and small enough $h$ the point $x+h$ is positive too, and $\frac{\operatorname{LReLU}(x+h)-\operatorname{LReLU}(x)}{h}=\frac{(x+h)-x}{h}=1$. For $x<0$ we likewise get $\frac{\alpha(x+h)-\alpha x}{h}=\alpha$.

At zero the one-sided limits differ:

$$\lim_{h\to0^+}\frac{\operatorname{LReLU}(h)-0}{h}=1,\qquad \lim_{h\to0^-}\frac{\alpha h-0}{h}=\alpha$$

For $\alpha\ne1$ they do not match, so there is no derivative at zero — it is a kink.

What to do about zero in practice? At the kink there is a subgradient: for $0\le\alpha\le1$ any number $g\in[\alpha,\,1]$ defines a line $y=gx$ that lies nowhere above the graph. Libraries pick one value by convention — PyTorch takes $\alpha$ at $x=0$. An input rarely lands exactly on zero, so the choice hardly matters.

Why a step is better than a cliff

By the chain rule the gradient with respect to the weight $w_j$ of a neuron $a=\operatorname{LReLU}(z)$, $z=\sum_j w_jx_j+b$, is

$$\frac{\partial L}{\partial w_j}=\frac{\partial L}{\partial a}\cdot\operatorname{LReLU}'(z)\cdot x_j$$

For ReLU the middle factor is 0 when $z<0$; for Leaky ReLU it is $\alpha$. On the left the gradient is $1/\alpha$ times weaker, but not zero: a neuron “stuck” in the negative zone still receives an error signal.

The derivative with respect to α: a step towards PReLU

If $\alpha$ becomes a learnable parameter, we need the derivative with respect to it. It is simple too:

$$\frac{\partial\operatorname{LReLU}_\alpha(x)}{\partial\alpha}=\begin{cases}0, & x>0,\\ x, & x\le 0\end{cases}\;=\;\min(0,\,x)$$

The slope $\alpha$ learns only from examples that land on the left branch — this is how PReLU works (section 9). The second derivative in $x$ is zero everywhere except at zero: all the curvature is concentrated in the kink, and in the sense of generalized functions $\operatorname{LReLU}''(x)=(1-\alpha)\,\delta(x)$.

The dying ReLU and how Leaky cures it

How a neuron dies. Suppose that after an unlucky large step (too high a learning rate, an outlier in the data, a bad initialization) the neuron’s bias $b$ has become strongly negative. Then $z=w^\top x+b<0$ on every example, ReLU outputs 0, the derivative $\operatorname{ReLU}'(z)=0$ — and the gradients with respect to $w$, $b$ and the output weight $v$ vanish all at once. Gradient descent will not move this neuron any more: it is dead (strictly for good for a first-layer neuron under plain SGD; in deeper layers the neuron’s input changes with the earlier layers, and neurons occasionally come back). The CS231n course notes mention that with too high a learning rate as much as 40% of a network can end up dead.

Below is the cleanest possible experiment. A single neuron $f(x)=v\cdot\operatorname{act}(wx+b)$ has to learn the “hinge” $y=1.5\max(0,\,x-1)$ from 41 points on $[-3,\,3]$. Start: $w=1$, $b=-4$, $v=1$ — the kink is at $x=4$, outside the data, so $z<0$ on every example. Training is gradient descent on MSE with step $0.1$.

Figure 3. Press “Play”. The ReLU neuron (black dashes) is frozen: all its gradients are zero, and the error stays at $1.09$ forever. The Leaky ReLU neuron with $\alpha=0.1$ receives a weak gradient, its line tilts and shifts, and at step 24 the kink enters the data range. After 1500 steps the error is $0.0549$. With $\alpha=0.01$ the revival takes 135 steps, but the final error is $0.00082$.

Note the trade-off. A large $\alpha$ brings the neuron back to life quickly, but the left branch stays tilted: with $\alpha=0.1$ the final model has slope $\alpha v w\approx0.116$ on the left instead of zero, hence the residual error. A small $\alpha$ barely distorts the shape of the function, but revives more slowly.

Leaky is not a guarantee

A non-zero gradient does not mean the neuron must come back: it may stay on the left branch, working as the linear function $\alpha(w^\top x+b)$. What Leaky ReLU guarantees is different — the neuron never freezes solid and keeps learning. Against the cause of death itself, use a moderate learning rate, warmup, normalization and proper initialization.

A network of Leaky ReLUs: a piecewise-linear landscape

In a network with two inputs every neuron $\operatorname{LReLU}(w_k^\top x+b_k)$ “folds” the plane along the line $w_k^\top x+b_k=0$: on one side of it the neuron’s contribution is $1/\alpha$ times flatter than on the other. The sum of neurons $f(x)=\sum_k v_k\operatorname{LReLU}(w_k^\top x+b_k)$ is a polyhedral surface: inside every region where the set of active neurons does not change it is flat, and on the kink lines it changes slope.

Figure 4. A network of six Leaky ReLU neurons. On the left, the surface $f(x_1,x_2)$ in 3D (you can rotate it); on the right, the view from above with the six kink lines. They cut the square $[-3,\,3]^2$ into 19 linear regions. Drag the orange point: at the centre, at $(0.2,\,-0.3)$, all six neurons are off, yet the gradient is not zero: $|\nabla f|=0.100$. Set $\alpha=0$: the central region becomes flat — that is 5% of the square where a ReLU network has a zero gradient with respect to the input. At $\alpha=1$ the whole network turns into a single plane.

The number of regions does not depend on $\alpha$ (as long as $\alpha\ne1$): only the kink lines set it. What does depend on $\alpha$ is what happens where all neurons are off. With ReLU there is a plateau with zero gradient, and examples that land on it tell the network nothing. With Leaky ReLU the plateau is tilted, and the gradient there is generally non-zero.

How many regions there can be

$n$ lines in general position cut the plane into at most $1+n+\binom n2$ pieces: for $n=6$ that is 22. In the square of the figure 19 of them are visible. In deep networks the number of linear regions can grow exponentially with depth — one explanation of their expressive power.

Deep networks: He initialization for Leaky ReLU

In a deep network the signal passes through dozens of layers $z_{l+1}=W_{l+1}\operatorname{LReLU}(z_l)$. If at every layer the variance is multiplied by a number even slightly different from 1, after 50 layers this becomes an explosion or a disappearance of the signal. Let us compute that factor.

Deriving the factor

Let the weights $W_{ij}$ be independent, $\mathbb E W_{ij}=0$, $\operatorname{Var}W_{ij}=s^2$, and the inputs $z_l$ symmetric around zero. For one output $z_{l+1,i}=\sum_{j=1}^{n}W_{ij}h_j$ with $h_j=\operatorname{LReLU}(z_{l,j})$:

$$\operatorname{Var}z_{l+1}=n\,s^2\,\mathbb E[h^2]=n\,s^2\,\frac{1+\alpha^2}{2}\operatorname{Var}z_l$$

The last equality is the second moment from the section on properties: half of $z_l^2$ comes from the positive branch in full, half from the negative one, multiplied by $\alpha^2$. For the variance to be preserved, the factor must equal 1:

$$s^2=\frac{2}{(1+\alpha^2)\,n_{\text{in}}}\qquad\Longleftrightarrow\qquad g=\sqrt n\,s=\sqrt{\frac{2}{1+\alpha^2}}$$

On the backward pass the gradient is multiplied by $W^\top$ and by $\operatorname{LReLU}'(z)$, and $\mathbb E[\operatorname{LReLU}'(z)^2]=\frac{1+\alpha^2}{2}$ — the same factor. So one and the same initialization preserves both the forward signal and the gradients.

$$\operatorname{Var}z_{l+1}=\frac{g^2(1+\alpha^2)}{2}\,\operatorname{Var}z_l,\qquad g_{\text{He}}=\sqrt{\frac{2}{1+\alpha^2}}$$

With $\alpha=0$ we get the famous $g=\sqrt2$ of He (Kaiming) initialization for ReLU. For Leaky ReLU the coefficient is slightly smaller: $1.414$ at $\alpha=0.01$, $1.387$ at $\alpha=0.2$, $1.355$ at $\alpha=0.3$.

Figure 5. The RMS of the pre-activations at every layer of a random network of width 256 (the vertical scale is logarithmic). By default $\alpha=0.3$ and the weights are initialized “as for ReLU”, $g=\sqrt2$: the variance factor is $1.09$ per layer, and by layer 50 the RMS grows to $11.6$ (theory: $11.7$). With the correct $g=\sqrt{2/(1+\alpha^2)}$ the factor is 1, and at layer 50 the RMS is $1.34$ (theory: $1.35$). With $g=1$ the factor is $0.545$, and the signal fades to $3.45\cdot10^{-7}$.
In PyTorch

This is exactly what nn.init.kaiming_normal_(w, a=alpha, nonlinearity='leaky_relu') does: the standard deviation is $\sqrt{2/((1+a^2)\,n_{\text{in}})}$. The default there is a=0, i.e. the initialization for plain ReLU — for Leaky ReLU the parameter a has to be passed explicitly.

PReLU, RReLU and the whole family

How to choose $\alpha$? There are three answers.

  • A fixed $\alpha$ — the classic Leaky ReLU (Maas, Hannun, Ng, 2013, $\alpha=0.01$). Today $0.1$–$0.3$ is common: in the comparison by Xu et al. (2015) a “very leaky” variant with $\alpha=1/5.5\approx0.18$ worked better than $0.01$.
  • A learnable $\alpha$ — PReLU (Parametric ReLU, He et al., 2015). $\alpha$ becomes a parameter — one per layer or one per channel — and is learned by gradient descent together with the weights. The initial value in PyTorch is $0.25$.
  • A random $\alpha$ — RReLU (Randomized ReLU): during training $\alpha$ is drawn anew for every element of the input from the uniform distribution $U(1/8,\,1/3)$ (PyTorch’s default bounds); at inference the mean $\frac{1/8+1/3}{2}=\frac{11}{48}\approx0.229$ is used. The noise acts as regularization.

For PReLU the gradient with respect to $\alpha$ is $\min(0,\,z)$ from the section on the derivative: the slope learns only from negative inputs. Let us watch gradient descent find both the weight and the slope.

Figure 6. The two-parameter model $\operatorname{PReLU}_\alpha(wx)$ learns from 31 points generated by the “teacher” $w^*=1.5$, $\alpha^*=0.2$ with noise. On the right, the error surface $L(w,\alpha)$ (lighter means smaller). From the start $(0.5,\,1.3)$ gradient descent with step $0.05$ arrives in 87 steps at $w=1.521$, $\alpha=0.209$ with error $0.0158$ — the minimum for these noisy data (the teacher itself has error $0.0170$). Drag the start somewhere else.

PReLU adds only one parameter per channel, yet in the work of He et al., together with a new initialization, it made it possible to train very deep convolutional networks and reach a top-5 error of $4.94\%$ on ImageNet — below the estimated human error of $5.1\%$. The authors note that weight decay should not be applied to $\alpha$: it pulls $\alpha$ towards zero, that is, back to ReLU.

Smooth relatives

The kink at zero can be smoothed. ELU replaces the left line with the exponential $\alpha(e^x-1)$, which saturates at $-\alpha$ (here $\alpha$ is ELU’s own parameter, usually 1). SELU adds a scale: $\lambda\approx1.0507$ and $\alpha\approx1.6733$ are chosen so that in a fully connected network with LeCun initialization the activations keep zero mean and unit variance by themselves. GELU and SiLU are smooth and even non-monotonic functions used in today’s transformers.

Figure 7. Leaky ReLU with $\alpha=0.1$ next to its relatives. Hover the cursor: at $x=-2$ Leaky ReLU gives $-0.2$, ELU $-0.865$, SELU $-1.520$, GELU $-0.046$, SiLU $-0.238$. Switch to the derivatives: for Leaky ReLU and SELU it is a step with a jump at zero (for SELU $\lambda\alpha\approx1.758$ on the left and $\lambda\approx1.051$ on the right), for ELU, GELU and SiLU a continuous curve.
FunctionFor $x\le0$Derivative on the leftFeature
ReLU$0$$0$zero gradient, “dead” neurons
Leaky ReLU$\alpha x$$\alpha$fixed slope, usually $0.01$–$0.3$
PReLU$\alpha x$, $\alpha$ is learned$\alpha$+1 parameter per layer or channel
RReLU$\alpha x$, $\alpha\sim U(\tfrac18,\,\tfrac13)$$\alpha$noise as regularization
ELU$\alpha(e^{x}-1)$$\alpha e^{x}$continuous derivative for $\alpha=1$, saturates at $-\alpha$
SELU$\lambda\alpha(e^{x}-1)$$\lambda\alpha e^{x}$self-normalizing, $\lambda\approx1.0507$

In code

In NumPy Leaky ReLU is one line. It is safer to write np.where than np.maximum(alpha * x, x): the latter silently breaks for $\alpha>1$.

pythonimport numpy as np

def leaky_relu(x, alpha=0.01):
    # where, not maximum(alpha * x, x): this form is correct for any alpha
    return np.where(x > 0, x, alpha * x)

def leaky_relu_grad(x, alpha=0.01):
    return np.where(x > 0, 1.0, alpha)      # alpha at zero, as in PyTorch

def he_std(n_in, alpha=0.01):
    # He initialization for Leaky ReLU: Var w = 2 / ((1 + alpha²) · n_in)
    return np.sqrt(2.0 / ((1.0 + alpha**2) * n_in))

x = np.array([-3.0, -0.5, 0.0, 2.0])
print(leaky_relu(x))        # [-0.03  -0.005  0.     2.   ]
print(leaky_relu_grad(x))   # [0.01 0.01 0.01 1.  ]
print(he_std(256, 0.2))     # 0.08667190566019205
pythonimport torch
import torch.nn as nn

act = nn.LeakyReLU(negative_slope=0.01)   # 0.01 is the default
x = torch.tensor([-3.0, 0.0, 2.0], requires_grad=True)
act(x).sum().backward()
print(x.grad)                    # tensor([0.0100, 0.0100, 1.0000]) — α at zero

prelu = nn.PReLU(num_parameters=1, init=0.25)   # α is a learnable parameter
print(prelu(torch.tensor([-2.0, 3.0])).detach())  # tensor([-0.5000,  3.0000])

lin = nn.Linear(256, 256)
# std = √(2 / ((1 + a²) · 256)); the default a=0 means “as for ReLU”
nn.init.kaiming_normal_(lin.weight, a=0.2, nonlinearity="leaky_relu")
print(nn.init.calculate_gain("leaky_relu", 0.2))  # 1.3867504905630728
Library defaults differ

PyTorch nn.LeakyReLU: negative_slope=0.01. TensorFlow tf.nn.leaky_relu: alpha=0.2. Keras layers.LeakyReLU: $0.3$. The same “Leaky ReLU” in three frameworks is three different functions. When porting a model, set $\alpha$ explicitly.

Numerically Leaky ReLU is safe: no exponentials, no division, no overflow. The only subtlety is inplace=True in PyTorch: it saves memory but overwrites the input, which other operations of the graph may still need.

Common mistakes

  1. Writing max(alpha * x, x) with $\alpha>1$. The formula holds only for $\alpha\le1$; for larger $\alpha$ you get a different function. The safe form is where(x > 0, x, alpha * x).
  2. Too large an $\alpha$. As $\alpha\to1$ the share of nonlinearity $\frac{1-\alpha}{2}$ goes to zero, the function becomes almost linear, and a deep network loses expressiveness. A sensible range is from $0.01$ to $0.3$.
  3. Initializing “as for ReLU” without correcting for $\alpha$. The variance factor is $1+\alpha^2$ per layer: at $\alpha=0.3$ the RMS of the signal grows about $1.09^{24.5}\approx8.3$ times from layer 1 to layer 50 (figure 5). Pass $\alpha$ to kaiming_normal_(..., a=alpha).
  4. Hoping that Leaky ReLU alone will cure unstable training. It removes the zero gradient, but not the cause: too high a learning rate is still dangerous.
  5. Weight decay on the $\alpha$ of PReLU. It pulls $\alpha$ towards zero, and PReLU turns into ReLU. Exclude $\alpha$ from the parameter group with weight decay.
  6. Different defaults in PyTorch ($0.01$), TensorFlow ($0.2$) and Keras ($0.3$): when a model moves between frameworks, the result silently changes.
  • ReLU: the special case $\alpha=0$; more on the dying ReLU there.
  • SiLU / Swish and GELU: smooth activations that also let a small negative signal through on the left, but then fade it out.
  • Sigmoid and tanh: saturating activations; Leaky ReLU has no saturation at all, and hence no vanishing gradient caused by saturation.
  • MSE: the loss function in the experiments of figures 3 and 6.
  • SGD and Adam: too large an optimizer step is the main cause of death for ReLU neurons.

Summary

1) $\operatorname{LReLU}_\alpha(x)=x$ for $x>0$ and $\alpha x$ for $x\le0$; it equals $\max(\alpha x,x)$ for $\alpha\le1$ and $\frac{1+\alpha}{2}x+\frac{1-\alpha}{2}|x|$ for any $\alpha$. 2) The derivative is a step made of $\alpha$ and $1$: the gradient does not vanish, the neuron does not freeze. 3) The trade-off: a larger $\alpha$ revives neurons faster but brings the function closer to linear. 4) A network of Leaky ReLUs is a piecewise-linear function without flat “dead” plateaus. 5) Initialization: $\operatorname{Var}w=\frac{2}{(1+\alpha^2)\,n_{\text{in}}}$. 6) PReLU learns $\alpha$ through the gradient $\min(0,z)$.

Check yourself

1. What is $\operatorname{LReLU}(-5)$ with $\alpha=0.2$?
2. What is the derivative of Leaky ReLU for $x<0$?
3. For which $\alpha$ does $\operatorname{LReLU}_\alpha(x)=\max(\alpha x,x)$ hold?
4. A network with Leaky ReLU ($\alpha=0.3$) is initialized “as for ReLU”, $g=\sqrt2$. What is the variance factor per layer?
5. A ReLU neuron gets $z<0$ on every example. What is true?