GELU Activation Function in Deep Learning: A Comprehensive Mathematical Analysis and Performance

Minhyeok LeearXiv 2023 · DOI

Introduction

Activation functions serve as the fundamental non-linear components of neural networks, dictating the flow of information and the model's capacity to learn complex representations. For several years, the Rectified Linear Unit (ReLU) has been the standard choice due to its computational efficiency and ability to mitigate vanishing gradients. However, ReLU suffers from the "dying ReLU" problem, where neurons can become permanently inactive if they fall into the zero-gradient negative regime.

Recent state-of-the-art architectures, such as BERT and GPT, have shifted toward the Gaussian Error Linear Unit (GELU). This paper explores the mathematical foundations and empirical performance of GELU, demonstrating why it has become a preferred alternative to ReLU and its variants.

Mathematical Properties

The GELU activation function is defined by the following approximation: $$GELU(x) = 0.5x \left(1 + \tanh\left(\sqrt{2/\pi}(x + 0.044715x^3)\right)\right)$$

Unlike the piecewise linear ReLU, GELU is a smooth, continuous function. As shown in Figure 1, it possesses a unique shape that combines properties of both ReLU and linear functions, but with a critical difference in the negative domain.

The GELU activation function exhibits a smooth, differentiable curve with a characteristic negative dip.

Mathematical analysis reveals that GELU is both Lipschitz continuous and Holder continuous. These properties ensure that the function's rate of change is bounded, contributing to a smoother optimization landscape. Furthermore, GELU is twice differentiable everywhere, avoiding the optimization instabilities often associated with the non-differentiable "kink" at zero in ReLU.

Experimental Methodology

To evaluate the efficacy of GELU, a 14-layer residual convolutional neural network (ResNet) was employed as a benchmark architecture. The model was trained using the Adam optimizer across three standard image classification datasets:

  • CIFAR-10: 60,000 images across 10 classes.
  • CIFAR-100: 100 classes of small images.
  • STL-10: A dataset featuring higher-resolution images designed for unsupervised feature learning.

GELU's performance was benchmarked against a comprehensive set of 20 other activation functions, including ELU, Hardswish, LeakyReLU, PReLU, and the traditional Sigmoid function.

Results and Analysis

GELU consistently outperformed all other activation functions across the tested benchmarks.

Dataset GELU Accuracy Best Competitor Accuracy ReLU Accuracy
CIFAR-10 89.52% 87.19% (ReLU) 87.19%
CIFAR-100 64.71% 64.12% (Hardswish) -
STL-10 58.48% 56.26% (LeakyReLU) -

In addition to achieving the highest accuracy, GELU also recorded the lowest test loss on CIFAR-10 (0.3685). Conversely, classic Sigmoid functions performed poorly, reaching only 33.90% accuracy on CIFAR-10, highlighting the persistent issue of vanishing gradients in deeper networks when using saturating activations.

Discussion

The Role of Negative Gradients

A distinctive feature of GELU is the small region (centered around $x \approx -0.75$) where the derivative is negative. While this might seem counterintuitive, these negative gradients can assist the model in escaping local minima during the early stages of training, potentially leading to better global optima.

Synergy with Normalization

The analysis highlights a significant interaction between GELU and normalization layers (e.g., Batch Norm or Layer Norm). Although GELU is technically unbounded for positive inputs, the presence of a preceding normalization layer effectively bounds the activations within a manageable range. This synergy helps prevent exploding gradients while maintaining the benefits of a non-saturating activation.

Computational Considerations

One trade-off for GELU's performance is its computational complexity. The inclusion of tanh and cubic terms makes it more expensive to compute than the simple max(0, x) operation of ReLU. However, in modern deep learning hardware, this overhead is often negligible compared to the overall cost of large-scale matrix multiplications, and the performance gains typically justify the cost.

Conclusion

The Gaussian Error Linear Unit (GELU) represents a significant advancement over the traditional ReLU. By providing a smooth, differentiable alternative that maintains activity in the negative regime, GELU offers superior training stability and higher final accuracy. Its widespread adoption in Transformer-based models is supported by the rigorous mathematical properties and empirical success documented in this study.

Summary updated

BibTeX
@misc{lee2023gelu,
  author = {Minhyeok Lee},
  title = {{GELU Activation Function in Deep Learning: A Comprehensive Mathematical Analysis and Performance}},
  year = {2023},
  eprint = {2305.12073},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2305.12073},
}
Figure