Learning Activation Functions to Improve Deep Neural Networks

Forest Agostinelli, Matthew Hoffman, Peter Sadowski, Pierre Baldi

Introduction

Deep learning with artificial neural networks has enabled rapid progress on applications in engineering (e.g., Krizhevsky et al., 2012; Hannun et al., 2014) and basic science (e.g., Di Lena et al., 2012; Lusci et al., 2013; Baldi et al., 2014). Usually, the parameters in the linear components are learned to fit the data, while the nonlinearities are pre-specified to be a logistic, tanh, rectified linear, or max-pooling function. A sufficiently large neural network using any of these common nonlinear functions can approximate arbitrarily complex functions (Hornik et al., 1989; Cho & Saul, 2010), but in finite networks the choice of nonlinearity affects both the learning dynamics (especially in deep networks) and the network’s expressive power.

Designing activation functions that enable fast training of accurate deep neural networks is an active area of research. The rectified linear activation function (Jarrett et al., 2009; Glorot et al., 2011), which does not saturate like sigmoidal functions, has made it easier to quickly train deep neural networks by alleviating the difficulties of weight-initialization and vanishing gradients. Another recent innovation is the “maxout” activation function, which has achieved state-of-the-art performance on multiple machine learning benchmarks (Goodfellow et al., 2013). The maxout activation function computes the maximum of a set of linear functions, and has the property that it can approximate any convex function of the input. Springenberg & Riedmiller (2013) replaced the max\max function with a probabilistic max\max function and Gulcehre et al. (2014) explored an activation function that replaces the max\max function with an LPL_{P} norm. However, while the type of activation function can have a significant impact on learning, the space of possible functions has hardly been explored.

One way to explore this space is to learn the activation function during training. Previous efforts to do this have largely focused on genetic and evolutionary algorithms (Yao, 1999), which attempt to select an activation function for each neuron from a pre-defined set. Recently, Turner & Miller (2014) combined this strategy with a single scaling parameter that is learned during training.

In this paper, we propose a more powerful adaptive activation function. This parametrized, piecewise linear activation function is learned independently for each neuron using gradient descent, and can represent both convex and non-convex functions of the input. Experiments demonstrate that like other piecewise linear activation functions, this works well for training deep neural networks, and we obtain state-of-the-art performance on multiple benchmark deep learning tasks.

Adaptive Piecewise Linear Units

Here we define the adaptive piecewise linear (APL) activation unit. Our method formulates the activation function hi(x)h_{i}(x) of an APL unit ii as a sum of hinge-shaped functions,

The result is a piecewise linear activation function. The number of hinges, SS, is a hyperparameter set in advance, while the variables aisa^{s}_{i}, bisb^{s}_{i} for i1,...,Si\in{1,...,S} are learned using standard gradient descent during training. The aisa_{i}^{s} variables control the slopes of the linear segments, while the bisb_{i}^{s} variables determine the locations of the hinges.

The number of additional parameters that must be learned when using these APL units is 2SM2SM, where MM is the total number of hidden units in the network. This number is small compared to the total number of weights in typical networks.

Figure 1 shows example APL functions for S=1S=1. Note that unlike maxout, the class of functions that can be learned by a single unit includes non-convex functions. In fact, for large enough SS, hi(x)h_{i}(x) can approximate arbitrarily complex continuous functions, subject to two conditions:

Any continuous piecewise-linear function g(x)g(x) can be expressed by Equation 1 for some SS, and aia_{i}, bib_{i}, i1,...,Si\in{1,...,S}, assuming that:

There is a scalar uu such that g(x)=xg(x)=x for all xux\geq u.

There are two scalars vv and α\alpha such that xg(x)=α\nabla_{x}g(x)=\alpha for all x<vx<v.

This theorem implies that we can reconstruct any piecewise-linear function g(x)g(x) over any subset of the real line, and the two conditions on g(x)g(x) constrain the behavior of g(x)g(x) to be linear as xx gets very large or small. The first condition is less restrictive than it may seem. In neural networks, g(x)g(x) is generally only of interest as an input to a linear function wg(x)+zwg(x)+z; this linear function effectively restores the two degrees of freedom that are eliminated by constraining the rightmost segment of g(x)g(x) to have unit slope and bias 0.

Let g(x)g(x) be piecewise linear with K+2K+2 linear regions separated by ordered boundary points b0b^{0}, b1b^{1}, …,bKb^{K}, and let aka^{k} be the slope of the kk-th region. Assume also that g(x)=xg(x)=x for all xbKx\geq b^{K}. We show that g(x)g(x) can be expressed by the following special case of Equation 1:

The first term has slope a0a^{0} in the range (,b0)(-\infty,b^{0}) and elsewhere. Each element in the summation term of Equation 2 has slope aka^{k} over the range (bk1,bk)(b^{k-1},b^{k}) and elsewhere. The last three terms together have slope 11 when x(bK,)x\in(b^{K},\infty) and elsewhere. Now, g(x)g(x) and h(x)h(x) are continuous, their slopes match almost everywhere, and it is easily verified that h(x)=g(x)=xh(x)=g(x)=x for xbKx\geq b^{K}. Thus, we conclude that h(x)=g(x)h(x)=g(x) for all xx. \square

In this section we compare the proposed approach to learning activation functions with two other nonlinear activation functions: maxout (Goodfellow et al., 2013), and network-in-network (Lin et al., 2013).

We observe that both maxout units and network-in-network can learn any nonlinear activation function that APL units can, but require many more parameters to do so. This difference allows APL units to be applied in very different ways from maxout and network-in-network nonlinearities: the small number of parameters needed to tune an APL unit makes it practical to train convolutional networks that apply different nonlinearities at each point in each feature map, which would be completely impractical in either maxout networks or network-in-network approaches.

Maxout units differ from traditional neural network nonlinearities in that they take as input the output of multiple linear functions, and return the largest:

Incorporating multiple linear functions increases the expressive power of maxout units, allowing them to approximate arbitrary convex functions, and allowing the difference of a pair of maxout units to approximate arbitrary functions.

Networks of maxout units with a particular weight-tying scheme can reproduce the output of an APL unit. The sum of terms in Equation 1 with positive coefficients (including the initial max(0,x)\max(0,x) term) is a convex function, and the sum of terms with negative coefficients is a concave function. One could approximate the convex part with one maxout unit, and the concave part with another maxout unit:

In a standard maxout network, however, the ww vectors are not tied. So implementing APL units (Equation 1) using a maxout network would require learning O(SK)O(SK) times as many parameters, where KK is the size of the maxout layer’s input vector. Whenever the expressive power of an APL unit is sufficient, using the more complex maxout units is therefore a waste of computational and modeling power.

Lin et al. (2013) proposed replacing the simple rectified linear activation in convolutional networks with a fully connected network whose parameters are learned from data. This “MLPConv” layer couples the outputs of all filters applied to a patch, and permits arbitrarily complex transformations of the inputs. A depth-MM MLPConv layer produces an output vector fijMf^{M}_{ij} from an input patch xijx_{ij} via the series of transformations

As with maxout networks, there is a weight-tying scheme that allows an MLPConv layer to reproduce the behavior of an APL unit:

where the function κ(k)\kappa(k) maps from hinge output indices kk to filter indices κ\kappa, and the coefficient ck{1,1}c_{k}\in\{-1,1\}.

This is a very aggressive weight-tying scheme that dramatically reduces the number of parameters used by the MLPConv layer. Again we see that it is a waste of computational and modeling power to use network-in-network wherever an APL unit would suffice.

However, network-in-network can do things that APL units cannot—in particular, it efficiently couples and summarizes the outputs of multiple filters. One can get the benefits of both architectures by replacing the rectified linear units in the MLPconv layer with APL units.

Experiments

Experiments were performed using the software package CAFFE (Jia et al., 2014). The hyperparameter, SS, that controls the complexity of the activation function was determined using a validation set for each dataset. The aisa^{s}_{i} and bisb^{s}_{i} parameters were regularized with an L2 penalty, scaled by 0.0010.001. Without this penalty, the optimizer is free to choose very large values of aisa^{s}_{i} balanced by very small weights, which would lead to numerical instability. We found that adding this penalty improved results. The model files and solver files are available at https://github.com/ForestAgostinelli/Learned-Activation-Functions-Source/tree/master.

The CIFAR-10 and CIFAR-100 datasets (Krizhevsky & Hinton, 2009) are 32x32 color images that have 10 and 100 classes, respectively. They both have 50,000 training images and 10,000 test images. The images were preprocessed by subtracting the mean values of each pixel of the training set from each image. Our network for CIFAR-10 was loosely based on the network used in (Srivastava et al., 2014). It had 3 convolutional layers with 96, 128, and 256 filters, respectively. Each kernel size was 5x5 and was padded by 2 pixels on each side. The convolutional layers were followed by a max-pooling, average-pooling, and average-pooling layer, respectively; all with a kernel size of 3 and a stride of 2. The two fully connected layers had 2048 units each. We applied dropout (Hinton et al., 2012) to the network as well. We found that applying dropout both before and after a pooling layer increased classification accuracy. The probability of a unit being dropped before a pooling layer was 0.25 for all pooling layers. The probability for them being dropped after each pooling layers was 0.25, 0.25, and 0.5, respectively. The probability of a unit being dropped for the fully connected layers was 0.5 for both layers. The final layer was a softmax classification layer. For CIFAR-100, the only difference was the second pooling layer was max-pooling instead of average-pooling. The baseline used rectified linear activation functions.

When using the APL units, for CIFAR-10, we set S=5S=5. For CIFAR-100 we set S=2S=2. Table 1 shows that adding the APL units improved the baseline by over 1% in the case of CIFAR-10 and by almost 3% in the case of CIFAR-100. In terms of relative difference, this is a 9.4% and a 7.5% decrease in error rate, respectively. We also try the network-in-network architecture for CIFAR-10 (Lin et al., 2013). We have S=2S=2 for CIFAR-10 and S=1S=1 for CIFAR-100. We see that it improves performance for both datasets.

We also try our method with the augmented version of CIFAR-10 and CIFAR-100. We pad the image all around with a four pixel border of zeros. For training, we take random 3232 x 3232 crops of the image and randomly do horizontal flips. For testing we just take the center 3232 x 3232 image. To the best of our knowledge, the results we report for data augmentation using the network-in-network architecture are the best results reported for CIFAR-10 and CIFAR-100 for any method.

In section 3.4, one can observe that the learned activations can look similar to leaky rectified linear units (Leaky ReLU) (Maas et al., 2013). This activation function is slightly different than the ReLU because it has a small slope kk when the input x<0x<0.

In (Maas et al., 2013), kk is equal to 0.010.01. To compare Leaky ReLUs to our method, we try different values for kk and pick the best value one. The possible values are positive and negative 0.010.01, 0.050.05, 0.10.1, and 0.20.2. For the standard convolutional neural network architecture k=0.05k=0.05 for CIFAR-10 and k=0.05k=-0.05 for CIFAR-100. For the network-in-network architecture k=0.05k=0.05 for CIFAR-10 and k=0.2k=0.2 for CIFAR-100. APL units consistently outperform leaky ReLU units, showing the value of tuning the nonlinearity (see also section 3.3).

2 Higgs Boson Decay

The Higgs-to-τ+τ\tau^{+}\tau^{-} decay dataset comes from the field of high-energy physics and the analysis of data generated by the Large Hadron Collider (Baldi et al., 2015). The dataset contains 80 million collision events, characterized by 25 real-valued features describing the 3D momenta and energies of the collision products. The supervised learning task is to distinguish between two types of physical processes: one in which a Higgs boson decays into τ+τ\tau^{+}\tau^{-} leptons and a background process that produces a similar measurement distribution. Performance is measured in terms of the area under the receiver operating characteristic curve (AUC) on a test set of 10 million examples, and in terms of discovery significance (Cowan et al., 2011) in units of Gaussian σ\sigma, using 100 signal events and 5000 background events with a 5% relative uncertainty.

Our baseline for this experiment is the 8 layer neural network architecture from (Baldi et al., 2015) whose architecture and training hyperparameters were optimized using the Spearmint algorithm (Snoek et al., 2012). We used the same architecture and training parameters except that dropout was used in the top two hidden layers to reduce overfitting. For the APL units we used S=2S=2. Table 2 shows that a single network with APL units achieves state-of-the-art performance, increasing performance over the dropout-trained baseline and the ensemble of 5 neural networks from (Baldi et al., 2015).

3 Effects of APL unit Hyperparameters

Table 3 shows the effect of varying SS on the CIFAR-10 benchmark. We also tested whether learning the activation function was important (as opposed to having complicated, fixed activation functions). For S=1S=1, we tried freezing the activation functions at their random initialized positions, and not allowing them to learn. The results show that learning activations, as opposed to keeping them fixed, results in better performance.

4 Visualization and Analysis of Adaptive Piecewise Linear Functions

The diversity of adaptive piecewise linear functions was visualized by plotting hi(x)h_{i}(x) for sample neurons. Figures 2 and 3 show adaptive piecewise linear functions for the CIFAR-100 and Higgsτ+τ\rightarrow\tau^{+}\tau^{-} experiments, along with the random initialization of that function.

In figure 4, for each layer, 1000 activation functions (or the maximum number of activation functions for that layer, whichever is smaller) are plotted. One can see that there is greater variance in the learned activations for CIFAR-100 than there is for CIFAR-10. There is greater variance in the learned activations for Higgsτ+τ\rightarrow\tau^{+}\tau^{-} than there is for CIFAR-100. For the case of Higgsτ+τ\rightarrow\tau^{+}\tau^{-}, a trend that can be seen is that the variance decreases in the higher layers.

Conclusion

We have introduced a novel neural network activation function in which each neuron computes an independent, piecewise linear function. The parameters of each neuron-specific activation function are learned via gradient descent along with the network’s weight parameters. Our experiments demonstrate that learning the activation functions in this way can lead to significant performance improvements in deep neural networks without significantly increasing the number of parameters. Furthermore, the networks learn a diverse set of activation functions, suggesting that the standard one-activation-function-fits-all approach may be suboptimal.

F. Agostinelli was supported by the GEM Fellowship. This work was done during an internship at Adobe. We also wish to acknowledge the support of NVIDIA Corporation with the donation of the Tesla K40 GPU used for this research, NSF grant IIS-0513376, and a Google Faculty Research award to P. Baldi, and thanks to Yuzo Kanomata for computing support.

References