logo

What is ReLU in Machine Learning? 📂Machine Learning

What is ReLU in Machine Learning?

Definition

In machine learning, the following function is called the Rectified Linear Unit (ReLU).

$$ f(x) = x^{+} := \max \left\{ 0, x \right\} $$

ReLU.png

Explanation

In electrical and electronic engineering, this is called the ramp function. For a description of the function itself or its properties (various ways of defining it, its derivative, etc.) rather than its viewpoint as an activation function in machine learning, refer to the ramp function document.

The name 'rectification' comes from rectification in electrical engineering, where a diode passes only the positive component of an alternating current signal. Since $\operatorname{ReLU}$ likewise passes the input through as is when it is positive and cuts it off to $0$ when it is negative, it operates just like a rectifier.

History

Rectifier-type activations appeared from the earliest days of neural network research. In 1969, Fukushima used an activation that cuts negative inputs off to $0$ in a multilayered neural network for visual feature extraction1. The name ‘rectified linear unit’ originated from a paper presented by Nair and Hinton at ICML in 20102. They showed that replacing the hidden units of a restricted Boltzmann machine with rectified linear units improves performance. The following year, Glorot, Bordes, and Bengio showed that using rectifier activations instead of the sigmoid or hyperbolic tangent makes it possible to train deep neural networks well, even without the unsupervised pretraining that was regarded as essential for training deep neural networks at the time3.

Use as an Activation Function

The reasons $\operatorname{ReLU}$ is widely used as an activation function can be summarized as follows.

  • Mitigating vanishing gradients: The sigmoid function has a maximum derivative of $1/4$, and when the absolute value of the input is large, saturation occurs where the gradient approaches $0$; thus, stacking many layers inevitably causes vanishing gradients. In contrast, $\operatorname{ReLU}$ always has a derivative of $1$ in the positive region, so the gradient does not shrink as it passes through the layers, and thanks to this, much deeper neural networks can be trained.

  • Computational efficiency: Since it is done with a single comparison operation without computing an exponential function, both forward and backward propagation are much cheaper than the sigmoid family. Note that the fact that it is not differentiable at $0$ does not pose a problem in practice. In implementation, one can simply set the gradient at that point to $0$ or $1$.

  • Sparsity: A substantial portion of the output becomes exactly $0$, producing a sparse representation. Glorot et al. argue that this resembles the way actual neurons fire and is also advantageous for learning3.

Dying $\operatorname{ReLU}$ and Variants

Of course, there are drawbacks too. Since the gradient is exactly $0$ in the negative region, if the input of a certain neuron always becomes negative during training, that neuron is no longer updated. This is called the dying $\operatorname{ReLU}$ problem. To remedy this, $\operatorname{LeakyReLU}$, which leaves a small gradient $\alpha$ (usually $0.01$) in the negative region, was proposed4, and $\operatorname{PReLU}$, which learns the gradient $\alpha$ itself, followed5.

$$ \operatorname{LeakyReLU}(x) := \begin{cases} x & x \gt 0 \\ \alpha x & x \le 0 \end{cases} $$

Smooth variants that are differentiable even at $0$ include softplus and $\operatorname{GELU}$. $\operatorname{GELU}$ is defined as follows using the cumulative distribution function $\Phi$ of the standard normal distribution6, and is used as a standard in transformer-family models such as BERT and GPT.

See Also


  1. Fukushima, Kunihiko. Visual feature extraction by a multilayered network of analog threshold elements. IEEE Transactions on Systems Science and Cybernetics 5.4 (1969): 322-333. ↩︎

  2. Nair, Vinod, and Geoffrey E. Hinton. Rectified linear units improve restricted Boltzmann machines. Proceedings of the 27th International Conference on Machine Learning (ICML). 2010. ↩︎

  3. Glorot, Xavier, Antoine Bordes, and Yoshua Bengio. Deep sparse rectifier neural networks. Proceedings of the 14th International Conference on Artificial Intelligence and Statistics (AISTATS). 2011. ↩︎ ↩︎

  4. Maas, Andrew L., Awni Y. Hannun, and Andrew Y. Ng. Rectifier nonlinearities improve neural network acoustic models. ICML Workshop on Deep Learning for Audio, Speech and Language Processing. 2013. ↩︎

  5. He, Kaiming, et al. Delving deep into rectifiers: Surpassing human-level performance on ImageNet classification. Proceedings of the IEEE International Conference on Computer Vision (ICCV). 2015. ↩︎

  6. Hendrycks, Dan, and Kevin Gimpel. Gaussian error linear units (GELUs). arXiv preprint arXiv:1606.08415 (2016). $$ \operatorname{GELU}(x) := x \Phi (x) $$ ↩︎