clockworkrnn
ClockworkRNN implementation using python and Theano
view repo
Sequence prediction and classification are ubiquitous and challenging problems in machine learning that can require identifying complex dependencies between temporally distant inputs. Recurrent Neural Networks (RNNs) have the ability, in theory, to cope with these temporal dependencies by virtue of the short-term memory implemented by their recurrent (feedback) connections. However, in practice they are difficult to train successfully when the long-term memory is required. This paper introduces a simple, yet powerful modification to the standard RNN architecture, the Clockwork RNN (CW-RNN), in which the hidden layer is partitioned into separate modules, each processing inputs at its own temporal granularity, making computations only at its prescribed clock rate. Rather than making the standard RNN models more complex, CW-RNN reduces the number of RNN parameters, improves the performance significantly in the tasks tested, and speeds up the network evaluation. The network is demonstrated in preliminary experiments involving two tasks: audio signal generation and TIMIT spoken word classification, where it outperforms both RNN and LSTM networks.
READ FULL TEXT VIEW PDF
Recurrent Neural Networks (RNNs), which are a powerful scheme for modeli...
read it
Learning with recurrent neural networks (RNNs) on long sequences is a
no...
read it
Recurrent neural networks (RNNs) have achieved state-of-the-art performa...
read it
Extracting temporal and representation features efficiently plays a pivo...
read it
Learning long-term dependencies still remains difficult for recurrent ne...
read it
The current paper is a study in Recurrent Neural Networks (RNN), motivat...
read it
The extension of deep learning towards temporal data processing is gaini...
read it
ClockworkRNN implementation using python and Theano
Recurrent Neural Networks (RNNs; Robinson & Fallside, 1987; Werbos, 1988; Williams, 1989) are a class of connectionist models that possess internal state or short term memory due to recurrent feed-back connections, that make them suitable for dealing with sequential problems, such as speech classification, prediction and generation.
Standard RNNs trained with stochastic gradient descent have difficulty learning long-term dependencies (i.e. spanning more that 10 time-steps) encoded in the input sequences due to the
vanishing gradient Hochreiter (1991); Hochreiter et al. (2001). The problem has been addressed for example by using a specialized neuron structure, or cell, in Long Short-Term Memory (LSTM) networks
Hochreiter & Schmidhuber (1997) that maintains constant backward flow in the error signal; second-order optimization methods Martens & Sutskever (2011)preserve the gradient by estimating its curvature; or using informed random initialization
Sutskever et al. (2013) which allows for training the networks with momentum and stochastic gradient descent only.This paper presents a novel modification to the simple RNN (SRN; Elman, 1988) architecture and, mutatis mutandis, an associated error back-propagation through time Rumelhart et al. (1986); Werbos (1988); Williams (1989) training algorithm, that show superior performance in the generation and classification of sequences that contain long-term dependencies. Here, the long-term dependency problem is solved by having different parts (modules) of the RNN hidden layer running at different clock speeds, timing their computation with different, discrete clock periods, hence the name Clockwork Recurrent Neural Network (CW-RNN). CW-RNN train and evaluate faster since not all modules are executed at every time step, and have a smaller number of weights compared to SRNs, because slower modules are not connected to faster ones.
CW-RNNs were tested on two supervised learning tasks: sequence generation where a target audio signal must be output by a network using no input; and spoken word classification using the TIMIT dataset. In these preliminary experiments, CW-RNN outperformed both SRN and LSTM with the same number of weights by a significant margin. The next section provides an overview of the related work,
section 3 describes the CW-RNN architecture in detail and section 5 discusses the results of experiments in section 4 and future potential of Clockwork Recurrent Neural Networks.Contributions to the sequence modeling and recognition that are relevant to CW-RNN are introduced in this section. The primary focus is on RNN extensions that deal with the problem of bridging long time lags.
One model that is similar in spirit to our approach is the NARX RNN^{1}^{1}1NARX stands for Non-linear Auto-Regressive model with eXogeneous inputs Lin et al. (1996). But instead of simplifying the network, it introduces an additional sets of recurrent connections with time lags of ,.. time steps. These additional connections help to bridge long time lags, but introduce many additional parameters that make NARX RNN training more difficult and run times slower.
Long Short-Term Memory (LSTM; Hochreiter & Schmidhuber, 1997) uses a specialized architecture that allows information to be stored in a linear unit called a constant error carousel (CEC) indefinitely. The cell containing the CEC has a set of multiplicative units (gates) connected to other cells that regulate when new information enters the CEC (input gate), when the activation of the CEC is output to the rest of the network (output gate), and when the activation decays or is ”forgotten” (forget gate). These networks have been very successful recently in speech and handwriting recognition Graves et al. (2005, 2009); Sak et al. (2014).
Stacking LSTMs into several layers (Fernandez et al., 2007; Graves & Schmidhuber, 2009) aims for hierarchical sequence processing. Such a hierarchy, equipped with Connectionist Temporal Classification (CTC; Graves et al., 2006), performs simultaneous segmentation and recognition of sequences. Its deep variant currently holds the state-of-the-art result in phoneme recognition on the TIMIT database Graves et al. (2013).
Temporal Transition Hierarchy (TTH; Ring, 1993) incrementally adds high-order neurons in order to build a memory that is used to disambiguate an input at the current time step. This approach can, in principle, bridge time intervals of any length, but with proportionally growing network size. The model was recently improved by adding recurrent connections Ring (2011) that prevent it from bloating by reusing the high-level nodes through the recurrent connections.
One of the earliest attempts to enable RNNs to handle long-term dependencies is the Reduced Description Network Mozer (1992, 1994). It uses leaky neurons whose activation changes only a bit in response to its inputs. This technique was recently picked up by Echo State Networks (ESN; Jaeger, 2002).
A similar technique has been used by Sutskever & Hinton (2010) to solve some serial recall tasks. These Temporal-Kernel RNNs add a connection from each neuron to itself that has a weight that decays exponentially in time. This is implemented in a way that can be computed efficiently, however, its performance is still inferior to LSTM.
Evolino Schmidhuber et al. (2007, 2005)
feeds the input to an RNN (which can be e.g. LSTM to cope with long time lags) and then transforms the RNN outputs to the target sequences via a optimal linear mapping, that is computed analytically by pseudo-inverse. The RNN is trained by an evolutionary algorithm, therefore it does not suffer from the vanishing gradient problem. Evolino outperformed LSTM on a set of synthetic problems and was used to perform complex robotic manipulation
Mayer et al. (2006).A modern theory of why RNNs fail to learn long-term dependencies is that simple gradient descent fails to optimize them correctly. One attempt to mitigate this problem is Hessian Free (HF) optimization Martens & Sutskever (2011), an adapted second-order training method that has been demonstrated to work well with RNNs. It allows RNNs to solve some long-term lag problems that were impossible with stochastic gradient descent. Their performance on rather synthetic, long-term memory benchmarks is approaching the performance of LSTM, though the number of optimization steps in HF-RNN is usually greater. Training networks by HF optimization is an orthogonal approach to the network architecture, so both LSTM and CW-RNN can still benefit from it.
HF optimization allowed for training of Multiplicative RNN (MRNN; Sutskever et al., 2011
) that port the concept of multiplicative gating units to SRNs. The gating units are represented by a factored 3-way tensor in order to reduce the number of parameters. Extensive training of an MRNN for a number of days on a graphics cards provided impressive results in text generation tasks.
Training RNNs with Kalman filters
Williams (1992) has shown advantages in bridging long time lags as well, although this approach is computationally unfeasible for larger networks.The methods mentioned above are strictly synchronous–elements of the network clock at the same speed. The Sequence Chunker, Neural History Compressor or Hierarchical Temporal Memory Schmidhuber (1991, 1992) consists of a hierarchy or stack of RNN that may run at different time scales, but, unlike the simpler CW-RNN, it requires unsupervised event predictors: a higher-level RNN receives an input only when the lower-level RNN below is unable to predict it. Hence the clock of the higher level may speed up or slow down, depending on the current predictability of the input stream. This contrasts the CW-RNN, in which the clocks always run at the same speed, some slower, some faster.
Clockwork Recurrent Neural Networks (CW-RNN) like SRNs, consist of input, hidden and output layers. There are forward connections from the input to hidden layer, and from the hidden to output layer, but, unlike the SRN, the neurons in the hidden layer are partitioned into modules of size . Each of the modules is assigned a clock period . Each module is internally fully-interconnected, but the recurrent connections from module to module exists only if the period is smaller than period . Sorting the modules by increasing period, the connections between modules propagate the hidden state right-to-left, from slower modules to faster modules, see Figure 1.
The standard RNN output, , at a time step is calculated using the following equations:
((1)) |
((2)) |
where , and are the hidden, input and output weight matrices,
is the input vector at time step
, vectors and represent the hidden neuron activations at time steps and . Functions andare the non-linear activation functions. For simplicity, neuron biases are omitted in the equations.
The main difference between CW-RNN and an RNN is that at each CW-RNN time step , only the output of modules that satisfy mod are executed. The choice of the set of periods is arbitrary. In this paper, we use the exponential series of periods: module has clock period of .
Matrices and are partitioned into blocks-rows:
((3)) |
and is a block-upper triangular matrix, where each block-row, , is partitioned into block-columns . At each forward pass time step, only the block-rows of and that correspond to the executed modules are used for evaluation in Equation (1):
((4)) |
and the corresponding parts of the output vector, , are updated. The other modules retain their output values from the previous time-step. Calculation of the hidden activation at time step is illustrated in Figure 2.
As a result, the low-clock-rate modules process, retain and output the long-term information obtained from the input sequences (not being distracted by the high speed modules), whereas the high-speed modules focus on the local, high-frequency information (having the context provided by the low speed modules available).
The backward pass of the error propagation is similar to RNN as well. The only difference is that the error propagates only from modules that were executed at time step . The error of non-activated modules gets copied back in time (similarly to copying the activations of nodes not activated at the time step during the corresponding forward pass), where it is added to the back-propagated error.
CW-RNN runs much faster than a simple RNN with the same number of hidden nodes since not all modules are evaluated at every time step. The lower bound for the CW-RNN speedup compared to an RNN with the same number of neurons is in the case of this exponential clock setup, see Appendix for a detailed derivation.
CW-RNNs were compared to the simple RNN (SRN) and LSTM networks. All networks have one hidden layer with the tanh activation function, and the number of nodes in the hidden layer was chosen to obtain (approximately) the same number of parameters for all three methods (in the case of CW-RNN, the clock periods were included in the parameter count).
Initial values for all the weights were drawn from a Gaussian distribution with zero mean and standard deviation of
. Initial values of all internal state variables were set to . Each setup was run times with different random initialization of parameters. All networks were trained using Stochastic Gradient Descent (SGD) with Nesterov-style momentum Sutskever et al. (2013).The goal of this task is to train a recurrent neural network, that receives no input, to generate a target sequence as accurately as possible. The weights of the network can be seen as a (lossy) encoding of the whole sequence, which could be used for compression.
Five different target sequences were created by sampling a piece of music^{2}^{2}2taken from the beginning of the first track Manýrista of album Musica Deposita by Cuprum at Hz for ms. The resulting sequences of data points each were scaled to the interval . In the following experiments we compare performance on these five sequences.
All networks used the same architecture: no inputs, one hidden layer and a single linear output neuron. Each network type was run with 4 different sizes: , , , and parameters, see Table 1 for the summary of number of hidden nodes. The networks were trained over epochs to minimize the mean squared error. After that time the error no longer decreased noticeably. Momentum was set to while the learning rate was optimized separately for every method, but kept the same for all network sizes.
A learning rate of was found to be optimal for RNN and CW-RNN while for LSTM gave better results. For LSTM it was also crucial to initialize the bias of the forget gates to a high value (5 in this case) to encourage the long-term memory. The hidden units of CW-RNN were divided into nine equally sized groups with exponential clock-timings {, , , …, }.
The results for the experiments are shown in Figure 3
. It is obvious that RNNs fail to generate the target sequence, and they do not seem to improve with network size. LSTM does much better, and shows an improvement as the networks get bigger. CW-RNNs give by far the best results, with the smallest one being roughly on par with the second-biggest LSTM network. Also, all but the smallest CW-RNN have significantly less variance than all the other methods. To get an intuitive understanding of what is happening,
Figure 5 shows the output of the best network of each type on each one of the five audio samples. The average error of the best networks is summarized in Table 3 (row 1).# of Parameters | RNN | LSTM | CW-RNN |
---|---|---|---|
100 | 9 | 4 | 11 |
250 | 15 | 7 | 19 |
500 | 22 | 10 | 27 |
1 000 | 31 | 15 | 40 |
The second task is sequence classification instead of generation. Each sequence contains an audio signal of one spoken word from the TIMIT Speech Recognition Benchmark Garofolo et al. (1993). The dataset contains different words (classes) arranged in clusters based on their suffix. Because of the suffix-similarity the network needs to learn long-term dependencies in order to disambiguate the words. The words are:
making, walking, cooking, looking, working
biblical, cyclical, technical, classical, critical
tradition, addition, audition, recognition, competition
musicians, discussions, regulations, accusations, conditions
subway, leeway, freeway, highway, hallway
For every word there are examples from different speakers, which were partitioned into for training and for testing, for a total of 175 sequences ( train, test). Each sequence element consists of -dimensional MFCC vector Mermelstein (1976) plus energy, sampled every ms over a ms window with a pre-emphasis coefficient of . Each of the channels was then normalized to have zero mean and unit variance over the whole training set.
All network types used the same architecture: inputs, a single hidden and a softmax output layer with units. Five hidden layer sizes were chosen such that the total number of parameters for the whole network is roughly k, k, k, k, and k.
All networks used a learning rate of , a momentum of 0.9, and were trained to minimize the Multinomial Cross Entropy Error. Every experiment was repeated times with different random initializations.
Because the dataset is so small, Gaussian noise with a standard deviation of was added to the inputs during training to guard against overfitting. Training was stopped once the error on the noise-free training set did not decrease for epochs. To obtain good results with LSTM, it was again important to initialize the forget gate bias to . For the CW-RNN the neurons were divided evenly into groups with exponentially increasing periods: {, , , , , , }.
Figure 4 shows the classification error of the different networks on the word classification task. Here again, RNNs perform the worst, followed by LSTMs, which give substantially better results, especially with more parameters. CW-RNNs beat both RNN and LSTM networks by a considerable margin of -% on average irrespective of the number of parameters. The error of the largest networks is summarized in Table 3 (row 2).
# of Parameters | RNN | LSTM | CW-RNN |
---|---|---|---|
500 | 10 | 5 | 10 |
1000 | 18 | 8 | 19 |
2500 | 34 | 17 | 40 |
5000 | 54 | 26 | 65 |
10000 | 84 | 41 | 102 |
Task | RNN | LSTM | CW-RNN | |||
---|---|---|---|---|---|---|
4.1 NMSE | 0.46 | 0.08 | 0.04 | 0.01 | 0.007 | 0.004 |
4.2 Error [%] | 66.8 | 4.7 | 34.2 | 5.6 | 16.8 | 3.5 |
The experimental results show that the simple mechanism of running subsets of neurons at different speeds allows an RNN to efficiently learn the different dynamic time-scales inherent in complex signals.
Other functions could be used to set the module periods: linear, Fibonacci, logarithmic series, or even fixed random periods. These were not considered in this paper because the intuitive setup of using an exponential series worked well in these preliminary experiments. Another option would be to learn the periods as well, which, to use error back-propagation would require a differentiable modulo function for triggering the clocks. Alternatively, one could train the clocks (together with the weights) using evolutionary algorithms which do not require a closed form for the gradient. Note that the lowest period in the network can be greater than . Such a network would not be able to change its output at every time step, which may be useful as a low-pass filter when the data contains noise.
Also, the modules do not have to be all of the same size. One could adjust them according to the expected information in the input sequences, by e.g. using frequency analysis of the data and setting up modules sizes and clocks proportional to the spectrum.
Grouping hidden neurons into modules is a partway to having each weight have its own clock. Initial experiments, not included in this paper, have shown that such networks are hard to train and do not provide good results.
CW-RNN showed superior performance on the speech data classification among all three models tested. Note that, unlike in the standard approach, in which the speech signal frequency coefficients are first translated to phonemes which are modeled with a standard approach like Hidden Markov Modes for complete words, CW-RNN attempts to model and recognize the complete words directly, where it benefits from the modules running at multiple speeds.
Future work will start by conducting a detailed analysis of the internal dynamics taking place in the CW-RNN to understand how the network is allocating resources for a given type of input sequence. Further testing on other classes of problems, such as reinforcement learning, and comparison to the larger set of connectionist models for sequential data processing are also planned.
CW-RNN has fewer total parameters and even fewer operations per time step than a standard RNN with the same number of neurons. Assume CW-RNN consists of modules of size for a total of neurons. Because a neuron is only connected to other neurons with the same or larger period, the number of parameters for the recurrent matrix is:
Compared to the parameters in the recurrent matrix of RNN this results in roughly half as many parameters:
Each module is evaluated only every -th time step, therefore the number of operations at a time step is:
For exponentially scaled periods, , the upper bound for number of operations, , needed for per time step is:
because this is less than or equal to . Recurrent operations in CW-RNN are faster than in an RNN with the same number of neurons by a factor of at least , which, for typical CW-RNN sizes ends up being between 2 and 5. Similarly, upper bound for the number of input weight evaluations, , is:
Therefore, the overall CW-RNN speed-up w.r.t RNN is:
Note that this is a conservative lower bound.
This research was supported by Swiss National Science Foundation grant #138219: “Theory and Practice of Reinforcement Learning 2”, and the EU FP7 project “NanoBioTouch”, grant #228844.
Proceedings of the 20th International Joint Conference on Artificial Intelligence (IJCAI)
, 2007.On the importance of initialization and momentum in deep learning.
In Dasgupta, Sanjoy and Mcallester, David (eds.), Proceedings of the 30th International Conference on Machine Learning (ICML-13), volume 28, pp. 1139–1147. JMLR Workshop and Conference Proceedings, May 2013. URL http://jmlr.org/proceedings/papers/v28/sutskever13.pdf.Generalization of backpropagation with application to a recurrent gas market model.
Neural Networks, 1, 1988.
Comments
There are no comments yet.