Searching for Activation Functions

Prajit Ramachandran, Barret Zoph, Quoc V. Le

This paper, a notable contribution to the field of automated machine learning (AutoML), introduces Swish, an activation function discovered not by human intuition, but by an automated search algorithm. While the Rectified Linear Unit (ReLU) has been the undisputed king of activation functions for years, this work demonstrates that a simple, non-monotonic alternative can provide consistent performance boosts across a variety of complex tasks.

TL;DR

Researchers used reinforcement learning-based search to discover new activation functions, leading to the discovery of Swish ($f(x) = x \cdot \text{sigmoid}(\beta x)$). Swish is a smooth, non-monotonic function that consistently outperforms ReLU across diverse architectures like Inception and MobileNet on benchmarks like ImageNet and machine translation.

What Problem Does This Paper Address?

For nearly a decade, ReLU ($f(x) = \max(0, x)$) has been the default choice for deep learning. Its simplicity helps prevent vanishing gradients, but it has flaws—most notably the "dying ReLU" problem, where neurons can become inactive and never recover.

While many "hand-designed" alternatives like Leaky ReLU, ELU, and SELU have been proposed, their benefits are often inconsistent; a function that works for a small CNN might fail on a large Transformer. The authors sought to move away from manual design, asking: Can we use automated search techniques to find a scalar activation function that generalizes better than ReLU?

Methods

The authors designed a search space inspired by recent successes in Neural Architecture Search (NAS).

The core unit of the search space
  • The Search Space: They defined a "core unit" that takes two inputs, applies a unary function to each (e.g., $x^2$, $\sin(x)$, $\text{sigmoid}(x)$), and combines them using a binary function (e.g., addition, multiplication, or $\max$).
  • Search Strategy:
    • Exhaustive Search: For small search spaces, they tested every possible combination.
  • RNN Controller: For massive search spaces (up to $10^{12}$ possibilities), they used an RNN controller trained with Reinforcement Learning (specifically Proximal Policy Optimization) to "predict" the best-performing function strings.
  • Evaluation: Each candidate function was evaluated by training a "child network" (ResNet-20) on CIFAR-10 for 10,000 steps. The validation accuracy was then used as a reward signal to update the search algorithm.

Datasets

The authors validated their findings across several standard benchmarks:

  • CIFAR-10 and CIFAR-100: Used for the initial search and to test the robustness of the top candidates across different architectures (ResNet, Wide ResNet, DenseNet).
  • ImageNet: The primary benchmark for large-scale image classification, testing models like Inception-ResNet-v2 and MobileNet.
  • WMT 2014 English→German: Used to evaluate performance in machine translation using the Transformer architecture.

Key Insights and Ideas

Swish activation function and its first derivatives
  • The Power of Non-Monotonicity: The most surprising finding was that the best functions, including Swish, are non-monotonic. Unlike ReLU, which is flat for all negative values, Swish has a small "bump" or dip where $f(x)$ is negative for small negative inputs. This property appears to improve gradient flow during training.
  • Smoothness Matters: Swish is continuously differentiable (smooth), whereas ReLU has a sharp "elbow" at zero. This smoothness likely makes the loss landscape easier to navigate for optimizers.
  • Interpolation: Swish can be viewed as a bridge between a linear function (when $\beta=0$) and the ReLU function (as $\beta \to \infty$). By making $\beta$ a trainable parameter, the model can learn the "level of nonlinearity" needed for each layer.
  • Simplicity Generalizes: While the search found complex functions involving sines and cosines, the simplest discovered function—Swish—showed the best generalization to large-scale models.

Key Results

Swish consistently matched or exceeded ReLU performance with virtually no additional computational cost:

  • ImageNet: Simply replacing ReLU with Swish improved top-1 accuracy by 0.9% on Mobile NASNet-A and 0.6% on Inception-ResNet-v2.
  • Mobile Efficiency: The gains were particularly high on mobile-optimized models, with a 2.2% boost for the original MobileNet on ImageNet.
  • Machine Translation: On the WMT 2014 English→German task, a 12-layer Transformer using Swish-1 (fixed $\beta=1$) outperformed the ReLU baseline by 0.6 to 1.0 BLEU points across different test sets.

Limitations and Future Work

  • Search Bias: The search was conducted using a relatively small "child network" (ResNet-20). While Swish generalized well, the authors acknowledge that the "optimal" function might vary depending on the specific architecture or depth.
  • Optimization Sensitivity: The authors noted that training Swish networks sometimes requires a slightly lower learning rate than ReLU networks to maintain stability.
  • Future Directions: The paper suggests that future work could explore "many-to-one" activation functions (like max-pooling or gating) using similar automated search techniques, rather than just the scalar-to-scalar functions focused on here.

Summary updated

BibTeX
@inproceedings{ramachandran2018searching,
  author = {Prajit Ramachandran and Barret Zoph and Quoc V. Le},
  title = {{Searching for Activation Functions}},
  booktitle = {Workshops @ ICLR},
  year = {2018},
}
Figure