Introduction to the Swish Activation Function
Swish is a widely used activation function in deep learning. It was originally introduced in the GELU paper as the Sigmoid-weighted Linear Unit (SiLU). This article explains the mathematics behind Swish and its applications, then examines its properties by comparing it with other activation functions.
1. Introduction
In deep neural networks, the choice of activation function has a significant impact on model performance. The evolution of activation functions from Sigmoid to ReLU and then to GELU reflects the deep learning field’s ongoing exploration of nonlinear transformations. Swish is a relatively new activation function that was first introduced in the GELU paper as the Sigmoid-weighted Linear Unit (SiLU) and later rediscovered and popularized by the Google Brain team.
Development History
The development of Swish/SiLU involved several key milestones:
- 2016: SiLU was first introduced in the GELU paper
- 2017: It was reintroduced in reinforcement learning as the Sigmoid-weighted Linear Unit (SiL)
- Late 2017: The Google Brain team proposed the Swish function and introduced the learnable parameter \beta
2. Mathematical Formulation of Swish
2.1 Basic Definition
Swish is a family of functions parameterized by \beta, defined as:
\begin{equation}\text{Swish}_\beta(x) = x \cdot \sigma(\beta x) = \frac{x}{1 + e^{-\beta x}}\end{equation}where \sigma(x) is the Sigmoid function:
\begin{equation}\sigma(x) = \frac{1}{1 + e^{-x}}\end{equation}When \beta = 1, Swish reduces to SiLU:
\begin{equation}\text{SiLU}(x) = \text{Swish}_1(x) = \frac{x}{1 + e^{-x}}\end{equation}The behavior of Swish depends on the value of \beta:
- When \beta = 0, the function becomes linear: f(x) = x/2
- When \beta = 1, the function is SiLU
- As \beta \to \infty, the function approaches ReLU
2.2 Calculating the Derivative
Review of the Basic Form
The basic form of the Swish function is:
\begin{equation}\text{Swish}(x) = x \cdot \sigma(\beta x)\end{equation}where \sigma(x) is the Sigmoid function:
\begin{equation}\sigma(x) = \frac{1}{1 + e^{-x}}\end{equation}Deriving the Derivative Using the Product Rule
By the product rule:
\begin{equation}\frac{\mathrm{d}}{\mathrm{dx}}[f(x)g(x)] = f'(x)g(x) + f(x)g'(x)\end{equation}Differentiating the Swish function gives:
\begin{equation}\begin{aligned}\frac{\mathrm{d}}{\mathrm{dx}}\text{Swish}(x) &= \frac{\mathrm{d}}{\mathrm{dx}}[x \cdot \sigma(\beta x)] \\&= 1 \cdot \sigma(\beta x) + x \cdot \frac{\mathrm{d}}{\mathrm{dx}}\sigma(\beta x)\end{aligned}\end{equation}The derivative of the Sigmoid function is:
\begin{equation}\frac{\mathrm{d}}{\mathrm{dx}}\sigma(x) = \sigma(x)(1-\sigma(x))\end{equation}Therefore:
\begin{equation}\frac{\mathrm{d}}{\mathrm{dx}}\sigma(\beta x) = \beta\sigma(\beta x)(1-\sigma(\beta x))\end{equation}Substituting this expression gives the derivative of Swish:
\begin{equation}\begin{aligned}\frac{\mathrm{d}}{\mathrm{dx}}\text{Swish}(x) &= \sigma(\beta x) + x\beta\sigma(\beta x)(1-\sigma(\beta x)) \\&= \sigma(\beta x) + \beta x\sigma(\beta x) - \beta x\sigma^2(\beta x) \\&= \sigma(\beta x)(1 + \beta x(1-\sigma(\beta x)))\end{aligned}\end{equation}For SiLU, the most commonly used form of Swish, setting \beta = 1 in the formula above gives:
\begin{equation}\frac{\mathrm{d}}{\mathrm{dx}}\text{SiLU}(x) = \sigma(x)(1 + x(1-\sigma(x)))\end{equation}Properties of the Derivative
The derivative of Swish has the following important properties:
- The derivative at x = 0 is 1/2
- The derivative can exceed 1 in some regions, which can amplify gradients during backpropagation
- The derivative is smooth, which helps stabilize the optimization process
3. Comparing Swish with Other Activation Functions
3.1 Comparison with ReLU
ReLU is defined as:
\begin{equation}\text{ReLU}(x) = \max(0,x)\end{equation}Compared with ReLU, Swish has the following characteristics:
- Smoothness: Swish is smooth everywhere, whereas ReLU is not differentiable at x = 0
- Negative region: Swish lets small negative values pass through, which may help information flow
- Boundedness: As x \to -\infty, Swish approaches 0 instead of cutting off abruptly like ReLU
3.2 Comparison with GELU
GELU is defined as follows:
\begin{equation}\text{GELU}(x) = x\cdot\Phi(x)\end{equation}
Swish and GELU have a few things in common:
- Both are smooth functions
- Both can be viewed as weighting the input by a probability function
- Both perform similarly in practice
Key differences:
- Computational complexity: Swish is simpler to compute
- Probabilistic interpretation: GELU uses a Gaussian distribution, while Swish uses the sigmoid function
- Parameterization: Swish introduces a learnable parameter \beta
References
- Gaussian Error Linear Units (GELUs)
- Searching for Activation Functions
- Sigmoid-Weighted Linear Units for Neural Network Function Approximation in Reinforcement Learning
- PyTorch Documentation – torch.nn.SiLU
- Wikipedia – Swish function
- Some recent activation functions mimicking ReLU
- A Brief Look at Activation Function Design in Neural Networks
- Google Brain’s New Activation Function Swish Sparks Debate: Can It Replace ReLU Directly and Outperform It?
- An Introduction to the GELU (Gaussian Error Linear Unit) Activation Function




