Architectural Complexity Measures of Recurrent Neural Networks

Saizheng Zhang, Yuhuai Wu, Tong Che, Zhouhan Lin, Roland Memisevic, Ruslan Salakhutdinov, Yoshua Bengio

Introduction

Recurrent neural networks (RNNs) have been shown to achieve promising results on many difficult sequential learning problems . There is also much work attempting to reveal the principles behind the challenges and successes of RNNs, including optimization issues , gradient vanishing/exploding related problems , analysing/designing new RNN transition functional units like LSTMs, GRUs and their variants .

This paper focuses on another important theoretical aspect of RNNs: the connecting architecture. Ever since introduced different forms of “stacked RNNs”, researchers have taken architecture design for granted and have paid less attention to the exploration of other connecting architectures. Some examples include who explored the use of skip connections; who pointed out the distinction of constructing a “deep” RNN from the view of the recurrent paths and the view of the input-to-hidden and hidden-to-output maps. However, they did not rigorously formalize the notion of “depth” and its implications in “deep” RNNs. Besides “deep” RNNs, there still remains a vastly unexplored field of connecting architectures. We argue that one barrier for better understanding the architectural complexity is the lack of a general definition of the connecting architecture. This forced previous researchers to mostly consider the simple cases while neglecting other possible connecting variations. Another barrier is the lack of quantitative measurements of the complexity of different RNN connecting architectures: even the concept of “depth” is not clear with current RNNs.

In this paper, we try to address these two barriers. We first introduce a general formulation of RNN connecting architectures, using a well-defined graph representation. Observing that the RNN undergoes multiple transformations not only feedforwardly (from input to output within a time step) but also recurrently (across multiple time steps), we carry out a quantitative analysis of the number of transformations in these two orthogonal directions, which results in the definitions of recurrent depth and feedforward depth. These two depths can be viewed as general extensions of the work of . We also explore a quantity called the recurrent skip coefficient which measures how quickly information propagates over time. This quantity is strongly related to vanishing/exploding gradient issues, and helps deal with long term dependency problems. Skip connections crossing different timescales have also been studied by . Instead of specific architecture design, we focus on analyzing the graph-theoretic properties of recurrent skip coefficients, revealing the fundamental difference between the regular skip connections and the ones which truly increase the recurrent skip coefficients. We rigorously prove each measure’s existence and computability under the general framework.

We empirically evaluate models with different recurrent/feedforward depths and recurrent skip coefficients on various sequential modelling tasks. We also show that our experimental results further validate the usefulness of the proposed definitions.

General Formulations of RNN Connecting Architectures

RNNs are learning machines that recursively compute new states by applying transition functions to previous states and inputs. Its connecting architecture describes how information flows between different nodes. In this section, we formalize the concept of the connecting architecture by extending the traditional graph-based illustration to a more general definition with a finite directed multigraph and its unfolded version. Let us first define the notion of the RNN cyclic graph Gc\mathcal{G}_{c} that can be viewed as a cyclic graphical representation of RNNs. We attach “weights” to the edges in the cyclic graph Gc\mathcal{G}_{c} that represent time delay differences between the source and destination node in the unfolded graph.

The unfolding Gun⁡\mathcal{G}_{\operatorname{un}} of any RNN cyclic graph Gc\mathcal{G}_{c} is a directed acyclic graph (DAG).

Figure 1(a) shows an example of two graph representations Gun⁡\mathcal{G}_{\operatorname{un}} and Gc\mathcal{G}_{c} of a given RNN. Consider the edge from node (1,7)(1,7) going to node (0,3)(0,3) in Gc\mathcal{G}_{c}. The fact that it has weight 1 indicates that the corresponding edge in Gun⁡\mathcal{G}_{\operatorname{un}} travels one time step, ((t+1,7),(t+2,3))((t+1,7),(t+2,3)). Note that node (0,3)(0,3) also has a loop with weight 2. This loop corresponds to the edge ((t,3),(t+2,3))((t,3),(t+2,3)). The two kinds of graph representations we presented above have a one-to-one correspondence. Also, any graph structure θ\theta on Gun⁡\mathcal{G}_{\operatorname{un}} is naturally mapped into a graph structure θˉ\bar{\theta} on Gc\mathcal{G}_{c}. Given an edge tuple eˉ=(u,v,σ)\bar{e}=(u,v,\sigma) in Gc\mathcal{G}_{c}, σ\sigma stands for the number of time steps crossed by eˉ\bar{e}’s covering edges in EunE_{un}, i.e., for every corresponding edge e∈Gun⁡e\in\mathcal{G}_{\operatorname{un}}, ee must start from some time index tt to t+σt+\sigma. Hence σ\sigma corresponds to the “time delay” associated with ee. In addition, the period number mm in Definition 2.1 can be interpreted as the time length of the entire non-repeated recurrent structure in its unfolded RNN graph Gun⁡\mathcal{G}_{\operatorname{un}}. In other words, shifting the Gun⁡\mathcal{G}_{\operatorname{un}} through time by kmkm time steps will result in a DAG which is identical to Gun⁡\mathcal{G}_{\operatorname{un}}, and mm is the smallest number that has such property for Gun⁡\mathcal{G}_{\operatorname{un}}. Most traditional RNNs have m=1m=1, while some special structures like hierarchical or clockwork RNN have m>1m>1. For example, Figure 1(a) shows that the period number of this specific RNN is 2.

An RNN is a tuple (Gc,Gun⁡,{Fvˉ}vˉ∈Vc)(\mathcal{G}_{c},\mathcal{G}_{\operatorname{un}},\{F_{\bar{v}}\}_{\bar{v}\in V_{c}}), in which Gun⁡=(Vun,Eun)\mathcal{G}_{\operatorname{un}}=(V_{un},E_{un}) is the unfolding of RNN cyclic graph Gc\mathcal{G}_{c}, and {Fvˉ}vˉ∈Vc\{F_{\bar{v}}\}_{\bar{v}\in V_{c}} is the set of transition functions. In the forward pass, for each hidden and output node v∈Vunv\in V_{un}, the transition function FvˉF_{\bar{v}} takes all incoming nodes of vv as the input to compute the output.

An RNN is homogeneous if all the hidden nodes share the same form of the transition function.

Measures of Architectural Complexity

In this section, we develop different measures of RNNs’ architectural complexity, focusing mostly on the graph-theoretic properties of RNNs. To analyze an RNN solely from its architectural aspect, we make the mild assumption that the RNN is homogeneous. We further assume the RNN to be unidirectional. For a bidirectional RNN, it is more natural to measure the complexities of its unidirectional components.

Unlike feedforward models where computations are done within one time frame, RNNs map inputs to outputs over multiple time steps. In some sense, an RNN undergoes transformations along both feedforward and recurrent dimensions. This fact suggests that we should investigate its architectural complexity from these two different perspectives. We first consider the recurrent perspective.

Given an RNN and its two graph representation Gun⁡\mathcal{G}_{\operatorname{un}} and Gc\mathcal{G}_{c}, we denote C(Gc)C(\mathcal{G}_{c}) to be the set of directed cycles in Gc\mathcal{G}_{c}. For ϑ\vartheta ∈C(Gc)\in C(\mathcal{G}_{c}), let l(ϑ)l(\vartheta) denote the length of ϑ\vartheta and σs(ϑ)\sigma_{s}(\vartheta) denote the sum of edge weights σ\sigma along ϑ\vartheta. Under a mild assumption See a full treatment of the limit in general cases in Theorem A.1 and Proposition A.1.1 in Appendix.,

More intuitively, drd_{r} is a measure of the average maximum number of nonlinear transformations per time step as nn gets large. Thus, we call it recurrent depth:

Given an RNN and its two graph representations Gun⁡\mathcal{G}_{\operatorname{un}} and Gc\mathcal{G}_{c}, we call drd_{r}, defined in Eq.(1), the recurrent depth of the RNN.

In Figure 1(a), one can easily verify that Dt(1)=5\mathfrak{D}_{t}(1)=5, Dt(2)=6\mathfrak{D}_{t}(2)=6, Dt(3)=8\mathfrak{D}_{t}(3)=8, Dt(4)=9\mathfrak{D}_{t}(4)=9 …\dots Thus Dt(1)1=5\frac{\mathfrak{D}_{t}(1)}{1}=5, Dt(2)2=3\frac{\mathfrak{D}_{t}(2)}{2}=3, Dt(3)3=83\frac{\mathfrak{D}_{t}(3)}{3}=\frac{8}{3}, Dt(4)4=94\frac{\mathfrak{D}_{t}(4)}{4}=\frac{9}{4} …\dots., which eventually converges to 32\frac{3}{2} as n→∞n\to\infty. As nn increases, most parts of the longest path coincides with the path colored in red. As a result, drd_{r} coincides with the number of nodes the red path goes through per time step. Similarly in Gc\mathcal{G}_{c}, observe that the red cycle achieves the maximum (32\frac{3}{2}) in Eq.(1). Usually, one can directly calculate drd_{r} from Gun⁡\mathcal{G}_{\operatorname{un}}. It is easy to verify that simple RNNs and stacked RNNs share the same recurrent depth which is equal to 1. This reveals the fact that their nonlinearities increase at the same rate, which suggests that they will behave similarly in the long run. This fact is often neglected, since one would typically consider the number of layers as a measure of depth, and think of stacked RNNs as “deep” and simple RNNs as “shallow”, even though their discrepancies are not due to recurrent depth (which regards time) but due to feedforward depth, defined next.

3 Feedforward Depth

Recurrent depth does not fully characterize the nature of nonlinearity of an RNN. As previous work suggests , stacked RNNs do outperform shallow ones with the same hidden size on problems where a more immediate input and output process is modeled. This is not surprising, since the growth rate of Di(n)\mathfrak{D}_{i}(n) only captures the number of nonlinear transformations in the time direction, not in the feedforward direction. The perspective of feedforward computation puts more emphasis on the specific paths connecting inputs to outputs. Given an RNN unfolded graph GunG_{un}, let Di∗(n)\mathfrak{D}^{*}_{i}(n) be the length of the longest path from any input node at time step ii to any output node at time step i+ni+n. Clearly, when nn is small, the recurrent depth cannot serve as a good description for Di∗(n)\mathfrak{D}^{*}_{i}(n). In fact. it heavily depends on another quantity which we call feedforward depth. The following proposition guarantees the existence of such a quantity and demonstrates the role of both measures in quantifying the nonlinearity of an RNN.

The above upper bound explicitly shows the interplay between recurrent depth and feedforward depth: when nn is small, Di∗(n)\mathfrak{D}^{*}_{i}(n) is largely bounded by dfd_{f}; when nn is large, drd_{r} captures the nature of the bound (≈n⋅dr\approx{n\cdot d_{r}}). These two measures are equally important, as they separately capture the maximum number of nonlinear transformations of an RNN in the long run and in the short run.

(Feedforward Depth) Given an RNN with recurrent depth drd_{r} and its two graph representations Gun⁡\mathcal{G}_{\operatorname{un}} and Gc\mathcal{G}_{c}, we call dfd_{f}, defined in Proposition 3.3.1, the feedforward depth Conventionally, an architecture with depth 1 is a three-layer architecture containing one hidden layer. But in our definition, since it goes through two transformations, we count the depth as 2 instead of 1. This should be particularly noted with the concept of feedforward depth, which can be thought as the conventional depth plus 1. of the RNN.

The following theorem proves dfd_{f}’s computability:

Given an RNN and its two graph representations Gun⁡\mathcal{G}_{\operatorname{un}} and Gc\mathcal{G}_{c}, we denote ξ(Gc)\xi(\mathcal{G}_{c}) the set of directed paths that start at an input node and end at an output node in Gc\mathcal{G}_{c}. For γ∈ξ(Gc)\gamma\in\xi(\mathcal{G}_{c}), denote l(γ)l(\gamma) the length and σs(γ)\sigma_{s}(\gamma) the sum of σ\sigma along γ\gamma. Then we have:

where mm is the period number and drd_{r} is the recurrent depth of the RNN.

For example, in Figure 1(a), one can easily verify that df=Dt∗(0)=3d_{f}=\mathfrak{D}^{*}_{t}(0)=3. Most commonly, dfd_{f} is the same as Dt∗(0)\mathfrak{D}^{*}_{t}(0), i.e., the maximum length from an input to its current output.

5 Recurrent Skip Coefficient

Given an RNN and its two graph representations Gun⁡\mathcal{G}_{\operatorname{un}} and Gc\mathcal{G}_{c}, under mild assumptions See Proposition A.3.1 in Appendix.

Since it is often the case that jj is smaller or equal to 1, it is more intuitive to consider its reciprocal.

(Recurrent Skip Coefficient) One would find this definition very similar to the definition of the recurrent depth. Therefore, we refer readers to examples in Figure 1 for some illustrations.. Given an RNN and corresponding Gun⁡\mathcal{G}_{\operatorname{un}} and Gc\mathcal{G}_{c}, we define s=1js=\frac{1}{j}, whose reciprocal is defined in Eq.(2), as the recurrent skip coefficient of the RNN.

With a larger recurrent skip coefficient, the number of transformations per time step is smaller. As a result, the nodes in the RNN are more capable of “skipping” across the network, allowing unimpeded information flow across multiple time steps, thus alleviating the problem of learning long term dependencies. In particular, such effect is more prominent in the long run, due to the network’s recurrent structure. Also note that not all types of skip connections can increase the recurrent skip coefficient. We will consider specific examples in our experimental results section.

Experiments and Results

In this section we conduct a series of experiments to investigate the following questions: (1) Is recurrent depth a trivial measure? (2) Can increasing depth yield performance improvements? (3) Can increasing the recurrent skip coefficient improve the performance on long term dependency tasks? (4) Does the recurrent skip coefficient suggest something more compared to simply adding skip connections? We show our evaluations on both tanh⁡\tanh RNNs and LSTMs.

PennTreebank dataset: We evaluate our models on character level language modelling using the PennTreebank dataset [marcus1993building]. It contains 5059k characters for training, 396k for validation and 446k for test, and has a alphabet size of 50. We set each training sequence to have the length of 50. Quality of fit is evaluated by the bits-per-character (BPC) metric, which is log⁡2\log_{2} of perplexity.

text8 dataset: Another dataset used for character level language modelling is the text8 dataset http://mattmahoney.net/dc/textdata., which contains 100M100M characters from Wikipedia with an alphabet size of 27. We follow the setting from and each training sequence has length of 180.

adding problem: The adding problem (and the following copying memory problem) was introduced in . For the adding problem, each input has two sequences with length of TT where the first sequence are numbers sampled from uniform and the second sequence are all zeros except two elements which indicates the position of the two elements in the first sequence that should be summed together. The output is the sum. We follow the most recent results and experimental settings in (same for copying memory).

copying memory problem: Each input sequence has length of T+20T+20, where the first 1010 values are random integers between 11 to 88. The model should remember them after TT steps. The rest of the sequence are all zeros, except for the last 11 entries in the sequence, which starts with 99 as a marker indicating that the model should begin to output its memorized values. The model is expected to give zero outputs at every time step except the last 10 entries, where it should generate (copy) the 1010 values in the same order as it has seen at the beginning of the sequence. The goal is to minimize the average cross entropy of category predictions at each time step.

sequential MNIST dataset: Each MNIST image data is reshaped into a 784×1784\times 1 sequence, turning the digit classification task into a sequence classification one with long-term dependencies . A slight modification of the dataset is to permute the image sequences by a fixed random order beforehand (permuted MNIST). Results in have shown that both tanh RNNs and LSTMs did not achieve satisfying performance, which also highlights the difficulty of this task.

For all of our experiments we use Adam for optimization, and conduct a grid search on the learning rate in {10−2,10−3,10−4,10−5}\{10^{-2},10^{-3},10^{-4},10^{-5}\}. For tanh⁡\tanh RNNs, the parameters are initialized with samples from a uniform distribution. For LSTM networks we adopt a similar initialization scheme, while the forget gate biases are chosen by the grid search on {−5,−3,−1,0,1,3,5}\{-5,-3,-1,0,1,3,5\}. We employ early stopping and the batch size was set to 5050.

2 Recurrent Depth is Non-trivial

To investigate the first question, we compare 4 similar connecting architectures: 1-layer (shallow) “shsh”, 2-layers stacked “stst”, 2-layers stacked with an extra bottom-up connection “bubu”, and 2-layers stacked with an extra top-down connection “tdtd”, as shown in Figure 2(a), left panel. Although the four architectures look quite similar, they have different recurrent depths: sh, st and bu have dr=1d_{r}=1, while td has dr=2d_{r}=2. Note that the specific construction of the extra nonlinear transformations in td is not conventional. Instead of simply adding intermediate layers in hidden-to-hidden connection, as reported in , more nonlinearities are gained by a recurrent flow from the first layer to the second layer and then back to the first layer at each time step (see the red path in Figure 2a, left panel).

We first evaluate our architectures using tanh⁡\tanh RNN on PennTreebank, where sh has hidden-layer size of 16001600. Next, we evaluate four different models for text8 which are tanh⁡\tanh RNN-small, tanh⁡\tanh RNN-large, LSTM-small, LSTM large, where the model’s sh architecture has hidden-layer size of 512, 2048, 512, 1024 respectively. Given the architecture of the sh model, we set the remaining three architectures to have the same number of parameters. Table 1, left panel, shows that the td architecture outperforms all the other architectures for all the different models. Specifically, td in tanh⁡\tanh RNN achieves a test BPC of 1.49 on PennTreebank, which is comparable to the BPC of 1.48 reported in [krueger2015regularizing] using stabilization techniques. Similar improvements are shown for LSTMs, where td architecture in LSTM-large achieves BPC of 1.49 on text8, outperforming the BPC of 1.54 reported in with Multiplicative RNN (MRNN). It is also interesting to note the improvement we obtain when switching from bu to td. The only difference between these two architectures lies in changing the direction of one connection (see Figure 2(a)), which also increases the recurrent depth. Such a fundamental difference is by no means self-evident, but this result highlights the necessity of the concept of recurrent depth.

3 Comparing Depths

From the previous experiment, we found some evidence that with larger recurrent depth, the performance might improve. To further investigate various implications of depths, we carry out a systematic analysis for both recurrent depth drd_{r} and feedforward depth dfd_{f} on text8 and sequential MNIST datasets. We build 99 models in total with dr=1,2,3d_{r}=1,2,3 and df=2,3,4d_{f}=2,3,4, respectively (as shown in Figure 2(b)). We ensure that all the models have roughly the same number of parameters (e.g., the model with dr=1d_{r}=1 and df=2d_{f}=2 has a hidden-layer size of 360360).

Table 1, right panel, displays results on the text8 dataset. We observed that when fixing feedforward depth df=2,3d_{f}=2,3 (or fixing recurrent depth dr=1,2d_{r}=1,2), increasing recurrent depth drd_{r} from 11 to 22 (or increasing feedforward depth dfd_{f} from 22 to 33) does improve the model performance. The best test BPC is achieved by the architecture with df=3,dr=2d_{f}=3,d_{r}=2. This suggests that reasonably increasing drd_{r} and dfd_{f} can aid in better capturing the over-time nonlinearity of the input sequence. However, for too large drd_{r} (or dfd_{f}) like dr=3d_{r}=3 or df=4d_{f}=4, increasing dfd_{f} (or drd_{r}) only hurts models performance. This can potentially be attributed to the optimization issues when modelling large input-to-output dependencies (see Appendix B.4 for more details). With sequential MNIST dataset, we next examined the effects of dfd_{f} and drd_{r} when modelling long term dependencies (more in Appendix B.4). In particular, we observed that increasing dfd_{f} does not bring any improvement to the model performance, and increasing drd_{r} might even be detrimental for training. Indeed, it appears that dfd_{f} only captures the local nonlinearity and has less effect on the long term prediction. This result seems to contradict previous claims that stacked RNNs (df>1d_{f}>1, dr=1d_{r}=1) could capture information in different time scales and would thus be more capable of dealing with learning long-term dependencies. On the other hand, a large drd_{r} indicates multiple transformations per time step, resulting in greater gradient vanishing/exploding issues , which suggests that drd_{r} should be neither too small nor too large.

4 Recurrent Skip Coefficients

To investigate whether increasing a recurrent skip coefficient ss improves model performance on long term dependency tasks, we compare models with increasing ss on the adding problem, the copying memory problem and the sequential MNIST problem (without/with permutation, denoted as MNIST and ppMNIST). Our baseline model is the shallow architecture proposed in . To increase the recurrent skip coefficient ss, we add connections from time step tt to time step t+kt+k for some fixed integer kk, shown in Figure 2(a), right panel. By using this specific construction, the recurrent skip coefficient increases from 1 (i.e., baseline) to kk and the new model with extra connection has 22 hidden matrices (one from tt to t+1t+1 and the other from tt to t+kt+k).

For the adding problem, we follow the same setting as in . We evaluate the baseline LSTM with 128 hidden units and an LSTM with s=30s=30 and 90 hidden units (roughly the same number of parameters as the baseline). The results are quite encouraging: as suggested in baseline LSTM works well for input sequence lengths T=100,200,400T=100,200,400 but fails when T=750T=750. On the other hand, we observe that the LSTM with s=30s=30 learns perfectly when T=750T=750, and even if we increase TT to 1000, LSTM with s=30s=30 still works well and the loss reaches to zero.

For the copying memory problem, we use a single layer RNN with 724 hidden units as our basic model, and 512 hidden units with skip connections. So they have roughly the same number of parameters. Models with a higher recurrent skip coefficient outperform those without skip connections by a large margin. When T=200T=200, test set cross entropy (CE) of a basic model only yields 0.2409, but with s=40s=40 it is able to reach a test set cross entropy of 0.0975. When T=300T=300, a model with s=30s=30 yields a test set CE of 0.1328, while its baseline could only reach 0.2025. We varied the sequence length (TT) and recurrent skip coefficient (ss) in a wide range (where TT varies from 100 up to 300, and ss from 10 up to 50), and found that this kind of improvement persists.

For the sequential MNIST problem, the hidden-layer size of the baseline model is set to 9090 and models with s>1s>1 have hidden-layer sizes of 6464.

The results in Table 2, top-left panel, show that tanh⁡\tanh RNNs with recurrent skip coefficient ss larger than 11 could improve the model performance dramatically. Within a reasonable range of ss, test accuracy increases quickly as ss becomes larger. We note that our model is the first tanh⁡\tanh RNN model that achieves good performance on this task, even improving upon the method proposed in . In addition, we also formally compare with the previous results reported in , where our model (referred to as stanh⁡\tanh) has a hidden-layer size of 9595, which is about the same number of parameters as in the tanh⁡\tanh model of . Table 2, bottom-left panel, shows that our simple architecture improves upon the uuRNN by 2.6%2.6\% on ppMNIST, and achieves almost the same performance as LSTM on the MNIST dataset with only 25%25\% number of parameters . Note that obtaining good performance on sequential MNIST requires a larger ss than that for ppMNIST (see Appendix B.4 for more details). LSTMs also showed performance boost and much faster convergence speed when using larger ss, as displayed in Table 2, top-right panel. LSTM with s=3s=3 already performs quite well and increasing ss did not result in any significant improvement, while in ppMNIST, the performance gradually improves as ss increases from 44 to 66. We also observed that the LSTM network performed worse on permuted MNIST compared to a tanh⁡\tanh RNN. Similar result was also reported in .

5 Recurrent Skip Coefficients vs. Skip Connections

We also investigated whether the recurrent skip coefficient can suggest something more than simply adding skip connections. We design 4 specific architectures shown in Figure 2(b), right panel. (1) is the baseline model with a 2-layer stacked architecture, while the other three models add extra skip connections in different ways. Note that these extra skip connections all cross the same time length kk. In particular, (2) and (3) share quite similar architectures. However, ways in which the skip connections are allocated makes big differences on their recurrent skip coefficients: (2) has s=1s=1, (3) has s=k2s=\frac{k}{2} and (4) has s=ks=k. Therefore, even though (2), (3) and (4) all add extra skip connections, the fact that their recurrent skip coefficients are different might result in different performance.

We evaluated these architectures on the sequential MNIST and ppMNIST datasets. The results show that differences in ss indeed cause big performance gaps regardless of the fact that they all have skip connections (see Table 2, bottom-right panel). Given the same kk, the model with a larger ss performs better. In particular, model (3) is better than model (2) even though they only differ in the direction of the skip connections. It is interesting to see that for MNIST (unpermuted), the extra skip connection in model (2) (which does not really increase the recurrent skip coefficient) brings almost no benefits, as model (2) and model (1) have almost the same results. This observation highlights the following point: when addressing the long term dependency problems using skip connections, instead of only considering the time intervals crossed by the skip connection, one should also consider the model’s recurrent skip coefficient, which can serve as a guide for introducing more powerful skip connections.

Conclusion

In this paper, we first introduced a general formulation of RNN architectures, which provides a solid framework for the architectural complexity analysis. We then proposed three architectural complexity measures: recurrent depth, feedforward depth, and recurrent skip coefficients capturing both short term and long term properties of RNNs. We also found empirical evidences that increasing recurrent depth and feedforward depth might yield performance improvements, increasing feedforward depth might not help on long term dependency tasks, while increasing the recurrent skip coefficient can largely improve performance on long term dependency tasks. These measures and results can provide guidance for the design of new recurrent architectures for particular learning tasks.

Acknowledgments

The authors acknowledge the following agencies for funding and support: NSERC, Canada Research Chairs, CIFAR, Calcul Quebec, Compute Canada, Samsung, ONR Grant N000141310721, ONR Grant N000141512791 and IARPA Raytheon BBN Contract No. D11PC20071. The authors thank the developers of Theano [team2016theano] and Keras [chollet2015], and also thank Nicolas Ballas, Tim Cooijmans, Ryan Lowe, Mohammad Pezeshki, Roger Grosse and Alex Schwing for their insightful comments.

References

Appendix A Proofs

To show theorem 3.2, we first consider the most general case in which drd_{r} is defined (Theorem A.1). Then we discuss the mild assumptions under which we can reduce to the original limit (Proposition A.1.1). Additionally, we introduce some notations that will be used throughout the proof. If v=(t,p)∈Gun⁡v=(t,p)\in\mathcal{G}_{\operatorname{un}} is a node in the unfolded graph, it has a corresponding node in the folded graph, which is denoted by vˉ=(tˉ,p)\bar{v}=(\bar{t},p).

Given an RNN cyclic graph and its unfolded representation (Gc,Gun⁡)(\mathcal{G}_{c},\mathcal{G}_{\operatorname{un}}), we denote C(Gc)C(\mathcal{G}_{c}) the set of directed cycles in Gc\mathcal{G}_{c}. For ϑ∈C(Gc)\vartheta\in C(\mathcal{G}_{c}), denote l(ϑ)l(\vartheta) the length of ϑ\vartheta and σs(ϑ)\sigma_{s}(\vartheta) the sum of σ\sigma along ϑ\vartheta. Write di=lim sup⁡k→∞Di(n)nd_{i}=\limsup_{k\rightarrow\infty}\frac{\mathfrak{D}_{i}(n)}{n}. Di(n)\mathfrak{D}_{i}(n) is not defined when there does not exist a path from time ii to time i+ni+n. We simply omit undefined cases when we consider the limsup. In a more rigorous sense, it is the limsup of a subsequence of {Di(n)}n=1∞\{\mathfrak{D}_{i}(n)\}_{n=1}^{\infty}, where Di(n)\mathfrak{D}_{i}(n) is defined. we have :

The first statement is easy to prove. Because of the periodicity of the graph, any path from time step ii to i+ni+n corresponds to an isomorphic path from time step i+mi+m to i+m+ni+m+n. Passing to limit, and we can deduce the first statement.

Now we prove the second statement. Write ϑ0=argmax⁡ϑl(ϑ)σs(ϑ)\vartheta_{0}=\operatorname{argmax}_{\vartheta}\frac{l(\vartheta)}{\sigma_{s}(\vartheta)}. First we prove that d≥l(ϑ0)σs(ϑ0)d\geq\frac{l(\vartheta_{0})}{\sigma_{s}(\vartheta_{0})}. Let c1=(t1,p1)∈Gun⁡c_{1}=(t_{1},p_{1})\in\mathcal{G}_{\operatorname{un}} be a node such that if we denote c1‾=(t1‾,p1)\overline{c_{1}}=(\overline{t_{1}},p_{1}) the image of c1c_{1} on the cyclic graph, we have c1‾∈ϑ0\overline{c_{1}}\in\vartheta_{0}. Consider the subsequence S0={Dt1‾(kσs(ϑ0))kσs(ϑ0)}k=1∞S_{0}=\left\{\frac{\mathfrak{D}_{\overline{t_{1}}}(k\sigma_{s}(\vartheta_{0}))}{k\sigma_{s}(\vartheta_{0})}\right\}_{k=1}^{\infty} of {Dt1‾(n)n}n=1∞\left\{\frac{\mathfrak{D}_{\overline{t_{1}}}(n)}{n}\right\}_{n=1}^{\infty}. From the definition of D\mathfrak{D} and the fact that ϑ0\vartheta_{0} is a directed circle, we have Dt1‾(kσs(ϑ0))≥kl(ϑ0)\mathfrak{D}_{\overline{t_{1}}}(k\sigma_{s}(\vartheta_{0}))\geq kl(\vartheta_{0}), by considering the path on Gun⁡\mathcal{G}_{\operatorname{un}} corresponding to following ϑ0\vartheta_{0} kk -times. So we have

Next we prove dr≤l(ϑ0)σs(ϑ0)d_{r}\leq\frac{l(\vartheta_{0})}{\sigma_{s}(\vartheta_{0})}. It suffices to prove that, for any ϵ≥0\epsilon\geq 0, there exists N>0N>0, such that for any path γ:{(t0,p0),(t1,p1),⋯ ,(tnγ,pnγ)}\gamma:\{(t_{0},p_{0}),(t_{1},p_{1}),\cdots,(t_{n_{\gamma}},p_{n_{\gamma}})\} with tnγ−t1>Nt_{n_{\gamma}}-t_{1}>N, we have nγtnγ−t1≤l(ϑ0)σs(ϑ0)+ϵ\frac{n_{\gamma}}{t_{n_{\gamma}}-t_{1}}\leq\frac{l(\vartheta_{0})}{\sigma_{s}(\vartheta_{0})}+\epsilon. We denote γˉ\bar{\gamma} as the image of γ\gamma on the cyclic graph. γˉ\bar{\gamma} is a walk with repeated nodes and edges. Also, we assume there are in total Γ\Gamma nodes in cyclic graph Gc\mathcal{G}_{c}.

We first decompose γˉ\bar{\gamma} into a path and a set of directed cycles. More precisely, there is a path γ0\gamma_{0} and a sequence of directed cycles C=C1(γ),C2(γ),⋯ ,Cw(γ)C=C_{1}(\gamma),C_{2}(\gamma),\cdots,C_{w}(\gamma) on Gc\mathcal{G}_{c} such that:

The starting and end nodes of γ0\gamma_{0} is the same as γ\gamma. (If γ\gamma starts and ends at the same node, take γ0\gamma_{0} as empty.)

The catenation of the sequences of directed edges E(γ0),E(C1(γ)),E(C2(γ)),⋯ ,E(Cw(γ))E(\gamma_{0}),E(C_{1}(\gamma)),E(C_{2}(\gamma)),\cdots,E(C_{w}(\gamma)) is a permutation of the sequence of edges of E(γ)E(\gamma).

The existence of such a decomposition can be proved iteratively by removing directed cycles from γ\gamma. Namely, if γ\gamma is not a paths, there must be some directed cycles C′C^{\prime} on γ\gamma. Removing C′C^{\prime} from γ\gamma, we can get a new walk γ′\gamma^{\prime}. Inductively apply this removal, we will finally get a (possibly empty) path and a sequence of directed cycles. For a directed path or loop γ\gamma, we write D(γ)D(\gamma) the distance between the ending node and starting node when travel through γ\gamma once. We have

where ei,i∈{1,2,⋯ ,∣γ0∣}e_{i},i\in\{1,2,\cdots,|\gamma_{0}|\} is all the edges of γ0\gamma_{0}. tˉ\bar{t} denotes the module of tt: t≡tˉ(mod⁡m)t\equiv\bar{t}(\operatorname{mod}m).

For convenience, we denote l0,l1,⋯ ,lwl_{0},l_{1},\cdots,l_{w} to be the length of path γ0\gamma_{0} and directed cycles C1(γ),C2(γ),⋯ ,Cw(γ)C_{1}(\gamma),C_{2}(\gamma),\cdots,C_{w}(\gamma). Obviously we have:

In which we have for all i∈{1,2,⋯ ,w}i\in\{1,2,\cdots,w\} :

in which M′M^{\prime} and Γ\Gamma are constants depending only on the RNN Gc\mathcal{G}_{c}.

take N>M′+ΓϵN>\frac{M^{\prime}+\Gamma}{\epsilon}, we can prove the fact that dr≤l(ϑ0)σs(ϑ0)d_{r}\leq\frac{l(\vartheta_{0})}{\sigma_{s}(\vartheta_{0})}.

Given an RNN and its two graph representations Gun⁡\mathcal{G}_{\operatorname{un}} and Gc\mathcal{G}_{c}, if ∃ϑ∈C(Gc)\exists\vartheta\in C(\mathcal{G}_{c}) such that (1)(1) ϑ\vartheta achieves the maximum in Eq.(3) and (2)(2) the corresponding path of ϑ\vartheta in Gun⁡\mathcal{G}_{\operatorname{un}} visits nodes at every time step, then we have

We can see that if we set k>σs(ϑ)l(ϑ)ϵk>\frac{\sigma_{s}(\vartheta)}{l(\vartheta)\epsilon}, the inequality we wanted to prove.

We now prove Proposition 3.3.1 and Theorem 3.4 as follows.

Given an RNN with recurrent depth drd_{r}, we denote

The supremum dfd_{f} exists and we have the following least upper bound:

From the definition, we have Di(n)≥Di∗(n).\mathfrak{D}_{i}(n)\geq\mathfrak{D}_{i}^{\ast}(n). So we have

From the proof of Theorem A.1, there exists two constants M′M^{\prime} and Γ\Gamma depending only on the RNN Gc\mathcal{G}_{c}, such that

Given an RNN and its two graph representations Gun⁡\mathcal{G}_{\operatorname{un}} and Gc\mathcal{G}_{c}, we denote ξ(Gc)\xi(\mathcal{G}_{c}) the set of directed path that starts at an input node and ends at an output node in Gc\mathcal{G}_{c}. For γ∈ξ(Gc)\gamma\in\xi(\mathcal{G}_{c}), denote l(γ)l(\gamma) the length and σs(γ)\sigma_{s}(\gamma) the sum of σ\sigma along γ\gamma. Then we have:

Let γ:{(t0,0),(t1,p1),⋯ ,(tnγ,p)}\gamma:\{(t_{0},0),(t_{1},p_{1}),\cdots,(t_{n_{\gamma}},p)\} be a path in Gun⁡\mathcal{G}_{\operatorname{un}} from an input node (t0,0)(t_{0},0) to an output node (tnγ,p)(t_{n_{\gamma}},p), where t0=it_{0}=i and tnγ=i+nt_{n_{\gamma}}=i+n. We denote γˉ\bar{\gamma} as the image of γ\gamma on the cyclic graph. From the proof of Theorem A.1, for each γˉ\bar{\gamma} in Gc\mathcal{G}_{c}, we can decompose it into a path γ0\gamma_{0} and a sequence of directed cycles C=C1(γ),C2(γ),⋯ ,Cw(γ)C=C_{1}(\gamma),C_{2}(\gamma),\cdots,C_{w}(\gamma) on Gc\mathcal{G}_{c} satisfying those properties listed in Theorem A.1. We denote l0,l1,⋯ ,lwl_{0},l_{1},\cdots,l_{w} to be the length of path γ0\gamma_{0} and directed cycles C1(γ),C2(γ),⋯ ,Cw(γ)C_{1}(\gamma),C_{2}(\gamma),\cdots,C_{w}(\gamma). We know lkσs(Ck)≤dr\frac{l_{k}}{\sigma_{s}(C_{k})}\leq d_{r} for all k=1,2,…,wk=1,2,\dots,w by definition. Thus,

Note that n=σs(γ0)+∑k=1wσs(Ck)n=\sigma_{s}(\gamma_{0})+\sum_{k=1}^{w}\sigma_{s}(C_{k}). Therefore,

for all time step ii and all integer nn. The above inequality suggests that in order to take the supremum over all paths in Gun⁡\mathcal{G}_{\operatorname{un}}, it suffices to take the maximum over a directed path in Gc\mathcal{G}_{c}. On the other hand, the equality can be achieved simply by choosing the corresponding path of γ0\gamma_{0} in Gun⁡\mathcal{G}_{\operatorname{un}}. The desired conclusion then follows immediately.

Given an RNN cyclic graph and its unfolded representation (Gc,Gun⁡)(\mathcal{G}_{c},\mathcal{G}_{\operatorname{un}}), we denote C(Gc)C(\mathcal{G}_{c}) the set of directed cycles in Gc\mathcal{G}_{c}. For ϑ∈C(Gc)\vartheta\in C(\mathcal{G}_{c}), denote l(ϑ)l(\vartheta) the length of ϑ\vartheta and σs(ϑ)\sigma_{s}(\vartheta) the sum of σ\sigma along ϑ\vartheta. Write si=lim⁡inf⁡k→∞di(n)ns_{i}=\lim\inf_{k\rightarrow\infty}\frac{\mathfrak{d}_{i}(n)}{n}. We have :

The proof is essentially the same as the proof of the first theorem. So we omit it here. ∎

Given an RNN and its two graph representations Gun⁡\mathcal{G}_{\operatorname{un}} and Gc\mathcal{G}_{c}, if ∃ϑ∈C(Gc)\exists\vartheta\in C(\mathcal{G}_{c}) such that (1)(1) ϑ\vartheta achieves the minimum in Eq.(4) and (2)(2) the corresponding path of ϑ\vartheta in Gun⁡\mathcal{G}_{\operatorname{un}} visits nodes at every time step, then we have

The proof is essentially the same as the proof of the Proposition A.1.1. So we omit it here. ∎

Appendix B Experiment Details

In this section we explain the functional dependency among nodes in RNNs with tanh⁡\tanh in detail.

The transition function for each node is the tanh⁡\tanh function. The output of a node vv is a vector hvh_{v}. To compute the output for a node, we simply take all incoming nodes as input, and sum over their affine transformations and then apply the tanh⁡\tanh function (we omit the bias term for simplicity).

where W(⋅)\textbf{W}(\cdot) represents a real matrix.

As a more concrete example, consider the “bottom-up” architecture in Figure 3, with which we did the experiment described in Section 4.2. To compute the output of node vv,

B.2 LSTMs

In this section we explain the Multidimensional LSTM (introduced by ) which we use for experiments with LSTMs.

The output of a node vv of the LSTM is a 2-tuple (cvc_{v},hvh_{v}), consisting of a cell memory state cvc_{v} and a hidden state hvh_{v}. The transition function FF is applied to each node indistinguishably. We describe the computation of FF below in a sequential manner (we omit the bias term for simplicity).

Note that the Multidimensional LSTM includes the usual definition of LSTM as a special case, where the extra forget gates are 0 (i.e., bias term set to -∞\infty) and extra weight matrices are 0. We again consider the architecture bubu in Fig. 3. We first compute the block input, the input gate and the output gate by summing over all affine transformed outputs of u,p,qu,p,q, and then apply the activation function. For example, to compute the input gate, we have

Next, we compute one forget gate for each pair of (v,u),(v,p),(v,q)(v,u),(v,p),(v,q). The way of computing a forget gate is the same as computing the other gates. For example, the forget gate in charge of the connection of u→vu\to v is computed as,

Then, the cell state is simply the sum of all element-wise products of the input gate with the block output and forget gates with the incoming nodes’ cell memory states,

Lastly, the hidden state is computed as usual,

B.3 Recurrent Depth is Non-trivial

The validation curves of the 4 different connecting architectures shsh, stst, bubu and tdtd on text8 dataset for both tanh⁡\tanhRNN-small and LSTM-small are shown below:

B.4 Full Comparisons on Depths

Figure 5 shows all the validation curves for the 9 architectures on text8 dataset, with their dr=1,2,3d_{r}=1,2,3 and df=2,3,4d_{f}=2,3,4 respectively. We initialize hidden-to-hidden matrices from uniform distribution.

Also, to see if increasing feedforward depth/ recurrent depth helps for long term dependency problems, we evaluate these 9 architectures on sequential MNIST task, with roughly the same number of parameters( 8K, where the first architecture with dr=1d_{r}=1 and df=2d_{f}=2 has hidden size of 90.). Hidden-to-hidden matrices are initialized from uniform distribution.

Figure 6 clearly show that, as the feedforward depth increases, the model performance stays roughly the same. In addition, note that increasing recurrent depth might even result in performance decrease. This is possibly because that larger recurrent depth amplifies the gradient vanishing/exploding problems, which is detrimental on long term dependency tasks.

B.5 Recurrent Skip Coefficients

The test curves for all the experiments are shown in Figure 7. In Figure 7, we observed that obtaining good performance on MNIST requires larger ss than for pMNIST. We hypothesize that this is because, for the sequential MNIST dataset, each training example contains many consecutive zero-valued subsequences, each of length 1010 to 2020. Thus within those subsequences, the input-output gradient flow could tend to vanish. However, when the recurrent skip coefficient is large enough to cover those zero-valued subsequences, the model starts to perform better. With ppMNIST, even though the random permuted order seems harder to learn, the permutation on the other hand blends zeros and ones to form more uniform sequences, and this may explain why training is easier, less hampered by by the long sequences of zeros.

B.6 Recurrent Skip Coefficients vs. Skip Connections

Test curves for all the experiments are shown in Figure 8. Observe that in most cases, the test accuracy of (3) is worse than (2) in the beginning while beating (2) in the middle of the training. This is possibly because in the first several time steps, it is easier for (2) to pass information to the output thanks to the skip connections, while only after multiples of kk time steps, (3) starts to show its advantage with recurrent skip connections It will be more clear if one checks the length of the shortest path from an node at time tt to to a node at time t+kt+k in both architectures.. The shorter paths in (2) make its gradient flow more easily in the beginning, but in the long run, (3) seems to be more superior, because of its more prominent skipping effect over time.

References