Approximating Real-Time Recurrent Learning with Random Kronecker Factors

# Approximating Real-Time Recurrent Learning with Random Kronecker Factors

Asier Mujika
Department of Computer Science
ETH Zürich, Switzerland
asierm@inf.ethz.ch
&Florian Meier
Department of Computer Science
ETH Zürich, Switzerland
meierflo@inf.ethz.ch
&Angelika Steger
Department of Computer Science
ETH Zürich, Switzerland
steger@inf.ethz.ch
Author was supported by grant no. CRSII5_173721 of the Swiss National Science Foundation.
###### Abstract

Despite all the impressive advances of recurrent neural networks, sequential data is still in need of better modelling. Truncated backpropagation through time (TBPTT), the learning algorithm most widely used in practice, suffers from the truncation bias, which drastically limits its ability to learn long-term dependencies.The Real-Time Recurrent Learning algorithm (RTRL) addresses this issue, but its high computational requirements make it infeasible in practice. The Unbiased Online Recurrent Optimization algorithm (UORO) approximates RTRL with a smaller runtime and memory cost, but with the disadvantage of obtaining noisy gradients that also limit its practical applicability. In this paper we propose the Kronecker Factored RTRL (KF-RTRL) algorithm that uses a Kronecker product decomposition to approximate the gradients for a large class of RNNs. We show that KF-RTRL is an unbiased and memory efficient online learning algorithm. Our theoretical analysis shows that, under reasonable assumptions, the noise introduced by our algorithm is not only stable over time but also asymptotically much smaller than the one of the UORO algorithm. We also confirm these theoretical results experimentally. Further, we show empirically that the KF-RTRL algorithm captures long-term dependencies and almost matches the performance of TBPTT on real world tasks by training Recurrent Highway Networks on a synthetic string memorization task and on the Penn TreeBank task, respectively. These results indicate that RTRL based approaches might be a promising future alternative to TBPTT.

Approximating Real-Time Recurrent Learning with Random Kronecker Factors

Asier Mujika thanks: Author was supported by grant no. CRSII5_173721 of the Swiss National Science Foundation. Department of Computer Science ETH Zürich, Switzerland asierm@inf.ethz.ch Florian Meier Department of Computer Science ETH Zürich, Switzerland meierflo@inf.ethz.ch Angelika Steger Department of Computer Science ETH Zürich, Switzerland steger@inf.ethz.ch

\@float

noticebox[b]Preprint. Work in progress.\end@float

## 1 Introduction

Processing sequential data is a central problem in the field of machine learning. In recent years, Recurrent Neural Networks (RNN) have achieved great success, outperforming all other approaches in many different sequential tasks like machine translation, language modeling, reinforcement learning and more.

Despite this success, it remains unclear how to train such models. The standard algorithm, Truncated Back Propagation Through Time (TBPTT) [19], considers the RNN as a feed-forward model over time with shared parameters. While this approach works extremely well in the range of a few hundred time-steps, it scales very poorly to longer time dependencies. As the time horizon is increased, the parameters are updated less frequently and more memory is required to store all past states. This makes TBPTT ill-suited for learning long-term dependencies in sequential tasks.

An appealing alternative to TBPTT is Real-Time Recurrent Learning (RTRL) [20]. This algorithm allows online updates of the parameters and learning arbitrarily long-term dependencies by exploiting the recurrent structure of the network for forward propagation of the gradient. Despite its impressive theoretical properties, RTRL is impractical for decently sized RNNs because run-time and memory costs scale poorly with network size.

As a remedy to this issue, Tallec and Ollivier [17] proposed the Unbiased Online Recurrent Learning algorithm (UORO). This algorithm unbiasedly approximates the gradients, which reduces the run-time and memory costs such that they are similar to the costs required to run the RNN forward. Unbiasedness is of central importance since it guarantees convergence to a local optimum. Still, the variance of the gradients slows down learning.

Here we propose the Kronecker Factored RTRL (KF-RTRL) algorithm. This algorithm builds up on the ideas of the UORO algorithm, but uses Kronecker factors for the RTRL approximation. We show both theoretically and empirically that this drastically reduces the noise in the approximation and greatly improves learning. However, this comes at the cost of requiring more computation and only being applicable to a class of RNNs. Still, this class of RNNs is very general and includes Tanh-RNN and Recurrent Highway Networks [21] among others.

The main contributions of this paper are:

• We propose the KF-RTRL online learning algorithm.

• We theoretically prove that our algorithm is unbiased and under reasonable assumptions the noise is stable over time and asymptotically by a factor smaller that the noise of UORO.

• We test KF-RTRL on a binary string memorization task where our networks can learn dependencies of up to steps.

• We evaluate on character-level Penn TreeBank, where the performance of KF-RTRL almost matches the one of TBPTT for steps.

• We empirically confirm that the variance of KF-RTRL is stable over time and that increasing the number of units does not increase the noise significantly.

## 2 Related Work

Training Recurrent Neural Networks for finite length sequences is currently almost exclusively done using BackPropagation Through Time [16] (BPTT). The network is "unrolled" over time and is considered as a feed-forward model with shared parameters (the same parameters are used at each time step). Like this, it is easy to do backpropagation and exactly calculate the gradients in order to do gradient descent.

However, this approach does not scale well to very long sequences, as the whole sequence needs to be processed before calculating the gradients, which makes training extremely slow and very memory intensive. In fact, BPTT cannot be applied to an online stream of data. In order to circumvent this issue, Truncated BackPropagation Through Time [19] (TBPTT) is used generally. The RNN is only "unrolled" for a fixed number of steps (the truncation horizon) and gradients beyond these steps are ignored. Therefore, if the truncation horizon is smaller than the length of the dependencies needed to solve a task, the network cannot learn it.

Several approaches have been proposed to deal with the truncation horizon. Anticipated Reweighted Truncated Backpropagation [18] samples different truncation horizons and weights the calculated gradients such that the expected gradient is that of the whole sequence. Jaderberg et al. [6] proposed Decoupled Neural Interfaces, where the network learns to predict incoming gradients from the future. Then, it uses these predictions for learning. The main assumption of this model is that all future gradients can be computed as a function of the current hidden state.

A more extreme proposal is calculating the gradients forward and not doing any kind of BPTT. This is known as Real-Time Recurrent Learning [20] (RTRL). RTRL allows updating the model parameters online after observing each input/output pair; we explain it in detail in Section 3. However, its large running time of order and memory requirements of order , where is the number of units of a fully connected RNN, make it unpractical for large networks. To fix this, Tallec and Ollivier [17] presented the Unbiased Online Recurrent Optimization (UORO) algorithm. This algorithm approximates RTRL using a low rank matrix. This makes the run-time of the algorithm of the same order as a single forward pass in an RNN, . However, the low rank approximation introduces a lot of variance, which negatively affects learning as we show in Section 5.

Other alternatives are Reservoir computing approaches [9] like Echo State Networks [7] or Liquid State Machines [10]. In these approaches, the recurrent weights are fixed and only the output connections are learned. This allows online learning, as gradients do not need to be propagated back in time. However, it prevents any kind of learning in the recurrent connections, which makes the RNN computationally much less powerful.

## 3 Real-Time Recurrent Learning and UORO

RTRL [20] is an online learning algorithm for RNNs. Contrary to TBPPT, no previous inputs or network states need to be stored. At any time-step , RTRL only requires the hidden state , input and in order to compute . With at hand, is obtained by applying the chain rule. Thus, the parameters can be updated online, that is, for each observed input/output pair one parameter update can be performed.

In order to present the RTRL update precisely, let us first define an RNN formally. An RNN is a differentiable function , that maps an input , a hidden state and parameters to the next hidden state . At any time-step , RTRL computes by applying the chain rule:

 dhtdθ =∂ht∂ht−1dht−1dθ+∂ht∂xtdxtdθ+∂ht∂θ (1) =∂ht∂ht−1dht−1dθ+∂ht∂θ , (2)

where the middle term vanishes because we assume that the inputs do not depend on the parameters. For notational simplicity, define , and , which reduces the above equation to

 dhtdθ=Gt=HtGt−1+Ft . (3)

Both and are straight-forward to compute for RNNs. We assume to be fixed, which implies . With all this, RTRL obtains the exact gradient for each time-step and enables online updates of the parameters. However, updating the parameters means that is only exact in the limit were the learning rate is arbitrarily small. In practice learning rates are sufficiently small such that this is not an issue.

The downside of RTRL is that for a fully connected RNN with units the matrices and have size and , respectively. Therefore, computing Equation 3 takes operations and requires storage, which makes RTRL impractical for large networks.

The UORO algorithm [17] addresses this issue and reduces run-time and memory requirements to at the cost of obtaining an unbiased but noisy estimate of . More precisely, the UORO algorithm keeps an unbiased rank-one estimate of by approximating as the outer product of two vectors of size and size , respectively. At any time , the UORO update consists of two approximation steps. Assume that the unbiased approximation of is given. First, is approximated by a rank-one matrix. Second, the sum of two rank-one matrices is approximated by a rank-one matrix yielding the estimate of . The estimate is provably unbiased and the UORO update requires the same run-time and memory as updating the RNN [17].

## 4 Kronecker Factored RTRL

Our proposed Kronecker Factored RTRL algorithm (KF-RTRL) is an online learning algorithm for RNNs, which does not require storing any previous inputs or network states. KF-RTRL approximates , which is the derivative of the internal state with respect to the parameters, see Section 3, by a Kronecker product. The following theorem shows that the KF-RTRL algorithm satisfies various desireable properties.

###### Theorem 1.

For the class of RNNs defined in Lemma 1, the estimate obtained by the KF-RTRL algorithm satisfies

1. is an unbiased estimate of , that is , and

2. assuming that the spectral norm of is at most for some arbitrary small , then at any time , the mean of the variances of the entries of is of order .

Moreover, one time-step of the KF-RTRL algorithm requires operations and memory.

We remark that the class of RNNs defined in Lemma 1 contains many widely used RNN architectures like Recurrent Highway Networks and Tanh-RNNs, but does not include GRUs [4] or LSTMs [5]. Further, the assumption that the spectral norm of is at most is reasonable, as otherwise gradients might grow exponentially as noted by Bengio et al. [2]. Lastly, the bottleneck of the algorithm is a matrix multiplication and thus for sufficiently large matrices an algorithm with a better run time than may be be practical.

In the remainder of this section, we explain the main ideas behind the KF-RTRL algorithm (formal proofs are given in the appendix). In the subsequent Section 5 we show that these theoretical properties carry over into practical application. KF-RTRL is well suited for learning long-term dependencies (see Section 5.1) and almost matches the performance of TBPTT on a complex real world task, that is, character level language modeling (see Section 5.2). Moreover, we confirm empirically that the variance of the KF-RTRL estimate is stable over time and scales well as the network size increases (see Section 5.3).

Before giving the theoretical background and motivating the key ideas of KF-RTRL, we give a brief overview of the KF-RTRL algorithm. At any time-step , KF-RTRL maintains a vector and a matrix , such that satisfies . Both and are factored as a Kronecker product, and then the sum of these two Kronecker products is approximated by one Kronecker product. This approximation step (see Lemma 2) works analogously to the second approximation step of the UORO algorithm (see rank-one trick, Proposition in [17]). The detailed algorithmic steps of KF-RTRL are presented in Algorithm 1 and motivated below.

#### Theoretical motivation of the KF-RTRL algorithm

The key observation that motivates our algorithm is that for many popular RNN architectures can be exactly decomposed as the Kronecker product of a vector and a diagonal matrix, see Lemma 1. Such a decomposition exists if every parameter affects exactly one element of assuming is fixed. This condition is satisfied by many popular RNN networks like Tanh-RNN and Recurrent Highway Networks. The class of RNNs considered in the following lemma contains all these RNN architectures.

###### Lemma 1.

Assume the learnable parameters are a set of matrices , let be the hidden state concatenated with the input and let for . Assume that is obtained by point-wise operations over the ’s, that is, , where is such that is bounded by a constant. Let be the diagonal matrix defined by , and let . Then, it holds .

Further, we observe that the sum of two Kronecker products can be approximated by a single Kronecker product. The following lemma, which is the analogue of Proposition in [15] for Kronecker products, states how this is achieved.

###### Lemma 2.

Let , where the matrix has the same size as the matrix and has the same size as . Let and be chosen independently and uniformly at random from and let be positive reals. Define and . Then, is an unbiased approximation of , that is . Moreover, the variance of this approximation is minimized by setting the free parameters .

Lastly, we show by induction that random vectors and random matrices exist, such that satisfies . Assume that satisfies . Equation 3 and Lemma 1 imply that

 Gt =HtE[G′t−1]+Ft=HtE[ut−1⊗At−1]+^ht⊗Dt . (4)

Next, by linearity of expectation and since the first dimension of is , it follows

 Gt =E[Ht(ut−1⊗At−1)+^ht⊗Dt]=E[ut−1⊗(HtAt−1)+^ht⊗Dt] . (5)

Finally, we obtain by Lemma 2 for any

 Gt =E[(c1p1ut−1+c2p1^ht)⊗(c11p1(HtAt−1)+c21p2Dt)] , (6)

where the expectation is taken over the probability distribution of , , and .

With these observations at hand, we are ready to present the KF-RTRL algorithm. At any time-step we receive the estimates and from the previous time-step. First, compute , and . Then, choose and uniformly at random from and compute

 ut =c1p1ut−1+c2p2^ht (7) At =c11p1(HtAt−1)+c21p2Dt , (8)

where and . Lastly, our algorithm computes , which is used for optimizing the parameters. For a detailed pseudo-code of the KF-RTRL algorithm see Algorithm 1. In order to see that is an unbiased estimate of , we apply once more linearity of expectation: .

One KF-RTRL update has run-time and requires memory. In order to see the statement for the memory requirement, note that all involved matrices and vectors have elements, except . However, we do not need to explicitly compute in order to obtain , because can be evaluated in this order. In order to see the statement for the run-time, note that and have both size . Therefore, computing requires operations. All other arithmetic operations trivially require run-time .

The proofs of Lemmas 1 and 2 and of the second statement of Theorem 1 are given in the appendix.

#### Comparison of the KF-RTRL with the UORO algorithm

Since the variance of the gradient estimate is directly linked to convergence speed and performance, let us first compare the variance of the two algorithms. Theorem 1 states that the mean of the variances of the entries of are of order . In the appendix, we show a slightly stronger statement, that is, if for all , then the mean of the variances of the entries is of order , where is the number of elements of . The bound is obtained by a trivial bound on the size of the entries of and and using . In the appendix, we show further that already the first step of the UORO approximation, in which is approximated by a rank-one matrix, introduces noise of order . Assuming that all further approximations would not add any noise, then the same trivial bounds on yield a mean variance of . We conclude that the variance of KF-RTRL is asymptotically by (at least) a factor smaller than the variance of .

Next, let us compare the generality of the algorithm when applying it to different network architectures. The KF-RTRL algorithms requires that in one time-step each parameter only affects one element of the next hidden state (see Lemma 1). Although many widely used RNN architectures satisfy this requirement, seen from this angle, the UORO algorithm is favorable as it is applicable to arbitrary RNN architectures.

Finally, let us compare memory requirements and runtime of KF-RTRL and UORO. In terms of memory requirements, both algorithms require storage and perform equally good. In terms of run-time, KF-RTRL requires , while UORO requires operations. However, the faster run-time of UORO comes at the cost of worse variance and therefore worse performance. In order to reduce the variance of UORO by a factor , one would need independent samples of . This could be achieved by reducing the learning rate by a factor of , which would then require times more data, or by sampling times in parallel, which would require times more memory. Still, our empirical investigation shows, that KF-RTRL outperforms UORO, even when taking UORO samples of to reduce the variance (see Figure 3). Moreover, for sufficiently large networks the scaling of the KF-RTRL run-time improves by using fast matrix multiplication algorithms.

## 5 Experiments

In this section, we quantify the effect on learning that the reduced variance of KF-RTRL compared to the one of UORO has. First, we evaluate the ability of learning long-term dependencies on a deterministic binary string memorization task. Since most real world problems are more complex and of stochastic nature, we secondly evaluate the performance of the learning algorithms on a character level language modeling task, which is a more realistic benchmark. For these two tasks, we also compare to learning with Truncated BPTT. Finally, we investigate the variance of KF-RTRL and UORO by comparing to their exact counterpart, RTRL. For all experiments, we use a single-layer Recurrent Highway Network [21]. 111For implementation simplicity, we use instead of as non-linearity function. Both functions have very similar properties, and therefore, we do not believe this has any significant effect.