Path-Normalized Optimization of Recurrent Neural Networks with ReLU Activations
Behnam Neyshabur, Yuhuai Wu, Ruslan Salakhutdinov, Nathan Srebro
Introduction
Recurrent Neural Networks (RNNs) have been found to be successful in a variety of sequence learning problems , including those involving long term dependencies (e.g., ). However, most of the empirical success has not been with “plain” RNNs but rather with alternate, more complex structures, such as Long Short-Term Memory (LSTM) networks or Gated Recurrent Units (GRUs) . Much of the motivation for these more complex models is not so much because of their modeling richness, but perhaps more because they seem to be easier to optimize. As we discuss in Section 3, training plain RNNs using gradient-descent variants seems problematic, and the choice of the activation function could cause a problem of vanishing gradients or of exploding gradients.
In this paper our goal is to better understand the geometry of plain RNNs, and develop better optimization methods, adapted to this geometry, that directly learn plain RNNs with ReLU activations. One motivation for insisting on plain RNNs, as opposed to LSTMs or GRUs, is because they are simpler and might be more appropriate for applications that require low-complexity design such as in mobile computing platforms . In other applications, it might be better to solve optimization issues by better optimization methods rather than reverting to more complex models. Better understanding optimization of plain RNNs can also assist us in designing, optimizing and intelligently using more complex RNN extensions.
Improving training RNNs with ReLU activations has been the subject of some recent attention, with most research focusing on different initialization strategies . While initialization can certainly have a strong effect on the success of the method, it generally can at most delay the problem of gradient explosion during optimization. In this paper we take a different approach that can be combined with any initialization choice, and focus on the dynamics of the optimization itself.
Any local search method is inherently tied to some notion of geometry over the search space (e.g. the space of RNNs). For example, gradient descent (including stochastic gradient descent) is tied to the Euclidean geometry and can be viewed as steepest descent with respect to the Euclidean norm. Changing the norm (even to a different quadratic norm, e.g. by representing the weights with respect to a different basis in parameter space) results in different optimization dynamics. We build on prior work on the geometry and optimization in feed-forward networks, which uses the path-norm (defined in Section 4) to determine a geometry leading to the path-SGD optimization method. To do so, we investigate the geometry of RNNs as feedforward networks with shared weights (Section 2) and extend a line of work on Path-Normalized optimization to include networks with shared weights. We show that the resulting algorithm (Section 4) has similar invariance properties on RNNs as those of standard path-SGD on feedforward networks, and can result in better optimization with less sensitivity to the scale of the weights.
Recurrent Neural Nets as Feedforward Nets with Shared Weights
We view Recurrent Neural Networks (RNNs) as feedforward networks with shared weights.
If the mapping is a one-to-one mapping, then there is no weight sharing and it corresponds to standard feedforward networks. On the other hand, weight sharing exists if is a many-to-one mapping. Two well-known examples of feedforward networks with shared weights are convolutional and recurrent networks. We mostly use the general notation of feedforward networks with shared weights throughout the paper as this will be more general and simplifies the development and notation. However, when focusing on RNNs, it is helpful to discuss them using a more familiar notation which we briefly introduce next.
Time-unfolded RNNs are feedforward networks with shared weights that map an input sequence to an output sequence. Each input node corresponds to either a coordinate of the input vector at a particular time step or a hidden unit at time . Each output node also corresponds to a coordinate of the output at a specific time step. Finally, each internal node refers to some hidden unit at time . When discussing RNNs, it is useful to refer to different layers and the values calculated at different time-steps. We use a notation for RNN structures in which the nodes are partitioned into layers and denotes the output of nodes in layer at time step . Let be the input at different time steps where is the maximum number of propagations through time and we refer to it as the length of the RNN. For , let and be the input and recurrent parameter matrices of layer and be the output parameter matrix. Table 1 shows forward computations for RNNs.The output of the function implemented by RNN can then be calculated as . Note that in this notations, weight matrices , and correspond to “free” parameters of the model that are shared in different time steps.
Non-Saturating Activation Functions
The choice of activation function for neural networks can have a large impact on optimization. We are particularly concerned with the distinction between “saturating” and “non-starting” activation functions. We consider only monotone activation functions and say that a function is “saturating” if it is bounded—this includes, e.g. sigmoid, hyperbolic tangent and the piecewise-linear ramp activation functions. Boundedness necessarily implies that the function values converge to finite values at negative and positive infinity, and hence asymptote to horizontal lines on both sides. That is, the derivative of the activation converges to zero as the input goes to both and . Networks with saturating activations therefore have a major shortcoming: the vanishing gradient problem . The problem here is that the gradient disappears when the magnitude of the input to an activation is large (whether the unit is very “active” or very “inactive”) which makes the optimization very challenging.
While sigmoid and hyperbolic tangent have historically been popular choices for fully connected feedforward and convolutional neural networks, more recent works have shown undeniable advantages of non-saturating activations such as ReLU, which is now the standard choice for fully connected and Convolutional networks . Non-saturating activations, including the ReLU, are typically still bounded from below and asymptote to a horizontal line, with a vanishing derivative, at . But they are unbounded from above, enabling their derivative to remain bounded away from zero as the input goes to . Using ReLUs enables gradients to not vanish along activated paths and thus can provide a stronger signal for training.
However, for recurrent neural networks, using ReLU activations is challenging in a different way, as even a small change in the direction of the leading eigenvector of the recurrent weights could get amplified and potentially lead to the explosion in forward or backward propagation .
To understand this, consider a long path from an input in the first element of the sequence to an output of the last element, which passes through the same RNN edge at each step (i.e. through many edges in some in the shared-parameter representation). The length of this path, and the number of times it passes through edges associated with a single parameter, is proportional to the sequence length, which could easily be a few hundred or more. The effect of this parameter on the path is therefore exponentiated by the sequence length, as are gradient updates for this parameter, which could lead to parameter explosion unless an extremely small step size is used.
Understanding the geometry of RNNs with ReLUs could helps us deal with the above issues more effectively. We next investigate some properties of geometry of RNNs with ReLU activations.
Feedforward networks (with or without shared weights) are highly over-parameterized, i.e. there are many parameter settings that represent the same function . Since our true object of interest is the function , and not the identity of the parameters, it would be beneficial if optimization would depend only on and not get “distracted” by difference in that does not affect . It is therefore helpful to study the transformations on the parameters that will not change the function presented by the network and come up with methods that their performance is not affected by such transformations.
We say a network is invariant to a transformation if for any parameter setting , . Similarly, we say an update rule is invariant to if for any , .
Invariances have also been studied as different mappings from the parameter space to the same function space while we define the transformation as a mapping inside a fixed parameter space. A very important invariance in feedforward networks is node-wise rescaling . For any internal node and any scalar , we can multiply all incoming weights into (i.e. for any ) by and all the outgoing weights (i.e. for any ) by without changing the function computed by the network. Not all node-wise rescaling transformations can be applied in feedforward nets with shared weights. This is due to the fact that some weights are forced to be equal and therefore, we are only allowed to change them by the same scaling factor.
Given a network , we say an invariant transformation that is defined over edge weights (rather than parameters) is feasible for parameter mapping if the shared weights remain equal after the transformation, i.e. for any and for any , .
Therefore, it is helpful to understand what are the feasible node-wise rescalings for RNNs. In the following theorem, we characterize all feasible node-wise invariances in RNNs.
For any such that , any Recurrent Neural Network with ReLU activation is invariant to the transformation where for any :
Furthermore, any feasible node-wise rescaling transformation can be presented in the above form.
The proofs of all theorems and lemmas are given in Appendix A. The above theorem shows that there are many transformations under which RNNs represent the same function. An example of such invariances is shown in Fig. 1. Therefore, we would like to have optimization algorithms that are invariant to these transformations and in order to do so, we need to look at measures that are invariant to such mappings.
Path-SGD for Networks with Shared Weights
As we discussed, optimization is inherently tied to a choice of geometry, here represented by a choice of complexity measure or “norm”The path-norm which we define is a norm on functions, not on weights, but as we prefer not getting into this technical discussion here, we use the term “norm” very loosely to indicate some measure of magnitude .. Furthermore, we prefer using an invariant measure which could then lead to an invariant optimization method. In Section 4.1 we introduce the path-regularizer and in Section 4.2, the derived Path-SGD optimization algorithm for standard feed-forward networks. Then in Section 4.3 we extend these notions also to networks with shared weights, including RNNs, and present two invariant optimization algorithms based on it. In Section 4.4 we show how these can be implemented efficiently using forward and backward propagations.
The path-regularizer is the sum over all paths from input nodes to output nodes of the product of squared weights along the path. To define it formally, let be the set of directed paths from input to output units so that for any path of length , we have that , and for any , . We also abuse the notation and denote if for some , . Then the path regularizer can be written as:
Equivalently, the path-regularizer can be defined recursively on the nodes of the network as:
2 Path-SGD for Feedforward Networks
Path-SGD is an approximate steepest descent step with respect to the path-norm. More formally, for a network without shared weights, where the parameters are the weights themselves, consider the diagonal quadratic approximation of the path-regularizer about the current iterate :
Using the corresponding quadratic norm , we can define an approximate steepest descent step as:
The stochastic version that uses a subset of training examples to estimate is called Path-SGD . We now show how Path-SGD can be extended to networks with shared weights.
3 Extending to Networks with Shared Weights
When the networks has shared weights, the path-regularizer is a function of parameters and therefore the quadratic approximation should also be with respect to the iterate instead of which results in the following update rule:
where . Solving (7) gives the following update:
The second derivative terms are specified in terms of their path structure as follows:
where
and is defined in (6).
The second term measures the effect of interactions between edges corresponding to the same parameter (edges from the same ) on the same path from input to output. In particular, if for any path from an input unit to an output unit, no two edges along the path share the same parameter, then . For example, for any feedforward or Convolutional neural network, . But for RNNs, there certainly are multiple edges sharing a single parameter on the same path, and so we could have .
The above lemma gives us a precise update rule for the approximate steepest descent with respect to the path-regularizer. The following theorem confirms that the steepest descent with respect to this regularizer is also invariant to all feasible node-wise rescaling for networks with shared weights.
For any feedforward networks with shared weights, the update (8) is invariant to all feasible node-wise rescalings. Moreover, a simpler update rule that only uses in place of is also invariant to all feasible node-wise rescalings.
Equations (9) and (10) involve a sum over all paths in the network which is exponential in depth of the network. However, we next show that both of these equations can be calculated efficiently.
4 Simple and Efficient Computations for RNNs
We show how to calculate and by considering a network with the same architecture but with squared weights:
Experiments
As we discussed in section 4.4, the second term in the update rule can be computationally expensive for large networks. In this section we investigate the significance of the second term and show that at least in our experiments, the contribution of the second term is negligible. To compare the two terms and , we train a single layer RNN with hidden units for the task of word-level language modeling on Penn Treebank (PTB) Corpus . Fig. 2 compares the performance of SGD vs. Path-SGD with/without . We clearly see that both version of Path-SGD are performing very similarly and both of them outperform SGD significantly. This results in Fig. 2 suggest that the first term is more significant and therefore we can ignore the second term.
To better understand the importance of the two terms, we compared the ratio of the norms for different RNN lengths and number of hidden units . The table in Fig. 2 shows that the contribution of the second term is bigger when the network has fewer number of hidden units and the length of the RNN is larger ( is small and is large). However, in many cases, it appears that the first term has a much bigger contribution in the update step and hence the second term can be safely ignored. Therefore, in the rest of our experiments, we calculate the Path-SGD updates only using the first term .
2 Synthetic Problems with Long-term Dependencies
Training Recurrent Neural Networks is known to be hard for modeling long-term dependencies due to the gradient vanishing/exploding problem . In this section, we consider synthetic problems that are specifically designed to test the ability of a model to capture the long-term dependency structure. Specifically, we consider the addition problem and the sequential MNIST problem.
Addition problem: The addition problem was introduced in . Here, each input consists of two sequences of length , one of which includes numbers sampled from the uniform distribution with range $784$, turning the digit classification task into sequence classification with long-term dependencies .
For both tasks, we closely follow the experimental protocol in . We train a single-layer RNN consisting of 100 hidden units with path-SGD, referred to as RNN-Path. We also train an RNN of the same size with identity initialization, as was proposed in , using SGD as our baseline model, referred to as IRNN. We performed grid search for the learning rates over for both our model and the baseline. Non-recurrent weights were initialized from the uniform distribution with range . Similar to , we found the IRNN to be fairly unstable (with SGD optimization typically diverging). Therefore for IRNN, we ran 10 different initializations and picked the one that did not explode to show its performance.
In our first experiment, we evaluate Path-SGD on the addition problem. The results are shown in Fig. 3 with increasing the length of the sequence: . We note that this problem becomes much harder as increases because the dependency between the output (the sum of two numbers) and the corresponding inputs becomes more distant. We also compare RNN-Path with the previously published results, including identity initialized RNN (IRNN), unitary RNN (uRNN), and np-RNNThe original paper does not include any result for 750, so we implemented np-RNN for comparison. However, in our implementation the np-RNN is not able to even learn sequences of length of 200. Thus we put “¿2” for length of 750. introduced by . Table 3 shows the effectiveness of using Path-SGD. Perhaps more surprisingly, with the help of path-normalization, a simple RNN with the identity initialization is able to achieve a 0% error on the sequences of length 750, whereas all the other methods, including LSTMs, fail. This shows that Path-SGD may help stabilize the training and alleviate the gradient problem, so as to perform well on longer sequence. We next tried to model the sequences length of 1000, but we found that for such very long sequences RNNs, even with Path-SGD, fail to learn.
Next, we evaluate Path-SGD on the Sequential MNIST problem. Table 3, right column, reports test error rates achieved by RNN-Path compared to the previously published results. Clearly, using Path-SGD helps RNNs achieve better generalization. In many cases, RNN-Path outperforms other RNN methods (except for LSTMs), even for such a long-term dependency problem.
3 Language Modeling Tasks
In this section we evaluate Path-SGD on a language modeling task. We consider two datasets, Penn Treebank (PTB-c) and text8 http://mattmahoney.net/dc/textdata. PTB-c: We performed experiments on a tokenized Penn Treebank Corpus, following the experimental protocol of . The training, validations and test data contain 5017k, 393k and 442k characters respectively. The alphabet size is 50, and each training sequence is of length 50. text8: The text8 dataset contains 100M characters from Wikipedia with an alphabet size of 27. We follow the data partition of , where each training sequence has a length of 180. Performance is evaluated using bits-per-character (BPC) metric, which is of perplexity.
Similar to the experiments on the synthetic datasets, for both tasks, we train a single-layer RNN consisting of 2048 hidden units with path-SGD (RNN-Path). Due to the large dimension of hidden space, SGD can take a fairly long time to converge. Instead, we use Adam optimizer to help speed up the training, where we simply use the path-SGD gradient as input to the Adam optimizer.
We also train three additional baseline models: a ReLU RNN with 2048 hidden units, a tanh RNN with 2048 hidden units, and an LSTM with 1024 hidden units, all trained using Adam. We performed grid search for learning rate over for all of our models. For ReLU RNNs, we initialize the recurrent matrices from uniform, and uniform for non-recurrent weights. For LSTMs, we use orthogonal initialization for the recurrent matrices and uniform for non-recurrent weights. The results are summarized in Table 3.
We also compare our results to an RNN that uses hidden activation regularizer (TRec,), Multiplicative RNNs trained by Hessian Free methods (HF-MRNN), and an RNN with smooth version of ReLU . Table 3 shows that path-normalization is able to outperform RNN-ReLU and RNN-tanh, while at the same time shortening the performance gap between plain RNN and other more complicated models (e.g. LSTM by 57% on PTB and 54% on text8 datasets). This demonstrates the efficacy of path-normalized optimization for training RNNs with ReLU activation.
Conclusion
We investigated the geometry of RNNs in a broader class of feedforward networks with shared weights and showed how understanding the geometry can lead to significant improvements on different learning tasks. Designing an optimization algorithm with a geometry that is well-suited for RNNs, we closed over half of the performance gap between vanilla RNNs and LSTMs. This is particularly useful for applications in which we seek compressed models with fast prediction time that requires minimum storage; and also a step toward bridging the gap between LSTMs and RNNs.
This research was supported in part by an NSF RI-AF award and by Intel ICRI-CI. We thank Saizheng Zhang for sharing a base code for RNNs.
References
Appendix A Proofs
We first show that any RNN is invariant to by induction on layers and time-steps. More specifically, we prove that for any and , . The statement is clearly true for ; because for any , .
Next, we show that for , if we assume that the statement is true for , then it is also true for :
We now need to prove the statement for . Assuming that the statement is true for and the layers before , we have:
Finally, we can show that the output is invariant for any at any time step :
We now show that any feasible node-wise rescaling can be presented as . Recall that node-wise rescaling invariances for a general feedforward network can be written as for some where for internal nodes and for any input/output nodes. An RNN with has no weight sharing and for each node with index in layer , we have . For any however, we there is no invariance that is not already counted. The reason is that by fixing the values of for the nodes in time step 0, due to the feasibility, the values of for nodes in other time-steps should be tied to the corresponding value in time step . Therefore, all invariances are included and can be presented in form of .
A.2 Proof of Lemma 1
We prove the statement simply by calculating the second derivative of the path-regularizer with respect to each parameter:
Taking the second derivative then gives us both terms after a few calculations:
A.3 Proof of Theorem 2
Node-wise rescaling invariances for a feedforward network can be written as for some where for internal nodes and for any input/output nodes. Any feasible invariance for a network with shared weights can also be written in the same form. The only difference is that some of s are now tied to each other in a way that shared weights have the same value after transformation. First, note that since the network is invariant to the transformation, the following statement holds by an induction similar to Theorem 1 but in the backward direction:
for any . Furthermore, by the proof of the Theorem 1 we have that for any , . Therefore,
where . In order to prove the theorem statement, it is enough to show that for any edge , because this property gives us the following update:
Therefore, it is remained to show that for any edge , . We show that this is indeed true for both terms and separately.
We first prove the statement for . Consider each path . By an inductive argument along the path, it is easy to see that multiplying squared weights along this path is invariant to the transformation:
Therefore, we have that for any edge and any ,
Taking sum over all paths and all edges completes the proof for . Similarly for , considering any two edges and any path , we have that:
where . Again, taking sum over all paths and all edges proves the statement for and consequently for .
A.4 Proof of Theorem 3
This path can therefore be decomposed into a path from input to edge and a path from edge to the output. Therefore, for any edge , we can factor out the number corresponding to the paths that go through and rewrite as follows:
where is the set of paths from input nodes to node and is defined similarly for the output nodes.
Therefore, can be written as:
Next, we show how to calculate the second term, i.e. . Each term in corresponds to a path that goes through two edges. We can decompose such paths and rewrite similar to the first term:
where is the set of all directed paths from node to node .