On the Compression of Recurrent Neural Networks with an Application to LVCSR acoustic modeling for Embedded Speech Recognition
Rohit Prabhavalkar, Ouais Alsharif, Antoine Bruguier, Ian McGraw
Introduction
Neural networks (NNs) with multiple feed-forward or recurrent hidden layers have emerged as state-of-the-art acoustic models (AMs) for automatic speech recognition (ASR) tasks. Advances in computational capabilities coupled with the availability of large annotated speech corpora have made it possible to train NN-based AMs with a large number of parameters with great success.
As speech recognition technologies continue to improve, they are becoming increasingly ubiquitous on mobile devices: voice assistants such as Apple’s Siri, Microsoft’s Cortana, Amazon’s Alexa and Google Now enable users to search for information using their voice. Although the traditional model for these applications has been to recognize speech remotely on large servers, there has been growing interest in developing ASR technologies that can recognize the input speech directly “on-device” . This has the promise to reduce latency while enabling user interaction even in cases where a mobile data connection is either unavailable, slow or unreliable. Some of the main challenges in this regard are the disk, memory and computational constraints imposed by these devices. Since the number of operations in neural networks is proportional to the number of model parameters, compressing the model is desirable from the point of view of reducing memory usage and power consumption.
In this paper, we study techniques for compressing recurrent neural networks (RNNs), specifically RNN acoustic models. We demonstrate how a generalization of conventional inter-layer matrix factorization techniques (e.g., ), where we jointly compress both recurrent and inter-layer weight matrices, allows us to compress acoustic models up to a third of their original size with negligible loss in accuracy. While we focus on acoustic modeling, the techniques presented can be applied to RNNs in other domains, e.g., handwriting recognition and machine translation inter alia. The technique presented in this paper encompasses both traditional recurrent neural networks (RNNs) as well as Long Short-Term Memory (LSTM) neural networks.
In Section 2, we review previous work that has focussed on techniques for compressing neural networks. Our proposed compression technique is presented in Section 3. We examine the effectiveness of proposed techniques in Sections 4 and 5. Finally, we conclude with a discussion of our findings in Section 6.
Related Work
There have been a number of previous proposals to compress neural networks, both in the context of ASR as well as in the broader field of machine learning. We summarize a number of proposed approaches in this section.
It has been noted in previous work that there is a large amount of redundancy in the parameters of a neural network. For example, Denil et al. show that the entire neural network can be reconstructed given the values of a small number of parameters. Caruana and colleagues show that the output distribution learned by a larger neural network can be approximated by a neural network with fewer parameters by training the smaller network to directly predict the outputs of the larger network . This approach, termed “model compression” is closely related to the recent “distillation” approach proposed by Hinton et al. . The redundancy in a neural network has also been exploited in the HashNet approach of Chen et al. , which imposes parameter tying in network based on a set of hash functions.
In the context of ASR, previous approaches to acoustic model compression have focused mainly on the case of feed-forward DNNs. One popular technique is based on sparsifying the weight matrices in the neural network, for example, by setting weights whose magnitude falls below a certain threshold to zero or based on the second-derivative of the loss function in the “optimal brain damage” procedure . In fact, Seide et al. demonstrate that up to two-thirds of the weights of the feed-forward network can be set to zero without incurring any loss in performance. Although techniques based on sparsification do decrease the number of effective weights, encoding the subset of weights which can be ‘zeroed out’ requires additional memory. Further, if the weight matrices are represented as dense matrices for efficient computation, then the parameter savings on disk will not translate in to savings of runtime memory. Other techniques to reduce the number of model parameters is based on changing the neural network architecture, e.g., by introducing bottleneck layers or through a low-rank matrix factorization layer . We also note recent work by Wang et al. which uses a combination of singular value decomposition (SVD) and vector quantization to compress acoustic models.
The methods investigated in our work are most similar to previous work that has examined using SVD to reduce the number of parameters in the network in the context of feed-forward DNNs . As we describe in Section 3, our methods can be thought of as an extension of the techniques proposed by Xue et al. , wherein we jointly factorize both recurrent and (non-recurrent) inter-layer weight matrices in the network.
Model Compression
In this section, we present a general technique for compressing individual recurrent layers in a recurrent neural network, thus generalizing the methods proposed by Xue et al. .
We note that sharing across the recurrent and inter-layer matrices allows for more efficient parameterization of the weight matrices; as shown in Section 5, this does not result in a significant loss of performance. Thus, the degree of compression in the model can be controlled by setting the ranks of the projection matrices in each of the layers of the network.
We determine the recurrent projection matrix , by first computing an SVD of the recurrent weight matrix, which we then truncate, retaining only the top singular values (denoted by ) and the corresponding singular vectors from and (denoted by and , respectively):
where and . Finally, we determine , as the solution to the following least-squares problem:
where, denotes the Frobenius norm of the matrix. In pilot experiments we found that the proposed SVD-based initialization performed better than training a model with recurrent projection matrices (i.e., same model architecture) but with random initialization of the network weights.
Generalizing the procedure described above in the context of standard RNNs to the case of LSTM RNNs is straightforward. Using the notation in , note that the recurrent-weight matrix in the case of the LSTM is the concatenation of the four gate weight matrices, obtained by stacking them vertically:
which represent respectively, recurrent connections to the input gate, the output gate, the forget gate and the cell state. Similarly, the inter-layer matrix is the concatenation of the matrices:
which correspond to the input gate, the forget gate, the output gate and the cell state (of the next layer). With these definitions, compression can be applied as described in Section 3. Note that we do not compress the “peep-hole” weights, since they are already narrow, single column matrices and do not contribute significantly to the total number of parameters in the network.
Experimental Setup
In order to determine the effectiveness of the proposed RNN compression technique, we conduct experiments on a open-ended large-vocabulary dictation task.
As we mentioned in Section 1, one of our primary motivations behind investigating acoustic model compression is to build compact acoustic models that can be deployed on mobile devices. In recent work, Sak et al. have demonstrated that deep LSTM-based AMs trained to predict either context-independent (CI) phoneme targets or context-dependent (CD) phoneme targets approach state-of-the-art performance on speech tasks. These systems have two important characteristics: in addition to the CI or CD phoneme labels, the system can also hypothesize a “blank” label if it is unsure of the identity of the current phoneme, and the systems are trained to optimize the connectionist temporal classification (CTC) criterion which maximizes the total probability of correct label sequence conditioned on the input sequence. More details can be found in .
Following , our baseline model is thus a CTC model: a five hidden layer RNN with 500 LSTM cells in each layer, which predicts 41 CI phonemes (plus “blank”). As a point of comparison, we also present results obtained using a much larger state-of-the-art ‘server-sized’ model which is too large to deploy on embedded devices but nonethless serves as an upper-bound performance for our models on this dataset. This model consists of five hidden layers with 600 LSTM cells per layer, and is trained to predict one of 9287 context-dependent phonemes (plus “blank”).
Our systems are trained using distributed asynchronous stochastic gradient descent with a parameter server . The systems are first trained to convergence to optimize the CTC criterion, following which these are discriminatively sequence trained to optimize the state-level minimum Bayes risk (sMBR) criterion . As discussed in Section 5, after applying the proposed compression scheme, we further fine-tune the network: first with the CTC criterion, followed by sequence discriminative training with the sMBR criterion. This additional fine-tuning step was found to be necessary to achieve good performance, particularly as the amount of compression was increased.
The language model used in this work is a 5-gram model trained on 100M sentences of in-domain data, with entropy-based pruning applied to reduce the size of the LM down to roughly 1.5M n-grams (mainly bigrams) with a 64K vocabulary. Since our goal is to build a recognizer to run efficiently on mobile devices, we minimize the size of the decoder graph used for recognition, following the approach outlined in : we perform an additional pruning step to generate a much smaller first-pass language model (69.5K n-grams; mainly unigrams), which is composed with the lexicon transducer to construct the decoder graph. We then perform on-the-fly rescoring with the larger LM. The resulting models, when compressed for use on-device, total about 20.3 MB, thus enabling them to be run many times faster than real-time on recent mobile devices .
We parameterize the input acoustics by computing 40-dimensional log mel-filterbank energies over the 8Khz range, which are computed every 10ms over 25ms windowed speech segments. The server-sized system uses 80-dimensional features computed over the same range since this resulted in slightly improved performance. Following , we stabilize CTC training by stacking together 8 consecutive speech frames (7 right context frames); only every third stacked frame is presented as an input to the network.
Our systems are trained on 3M hand-transcribed anonymized utterances extracted from Google voice search traffic (2000 hours). We create “multi-style” training data by synthetically distorting utterances to simulate background noise and reverberation using a room simulator with noise samples extracted from YouTube videos and environmental recordings of everyday events; 20 distorted examples are created for each utterance in the training set. Systems are additionally adapted using the sMBR criterion on a set of 1M anonymized hand-transcribed (in-domain) dictation utterances extracted from Google traffic, processed to generate “multi-style” training data as described above, which improves performance on our dictation task. All results are reported on a set of 13.3K hand-transcribed anonymized utterances extracted from Google traffic from an open-ended dictation domain.
Results
In our experiments, we seek to determine the impact of the proposed joint SVD-based compression technique on system performance. In particular, we are interested in determining how system performance varies as a function of the degree of compression, which is controlled by setting the ranks of the recurrent projection matrices as described in Section 3.
Notice that since the proposed compression scheme is applied to all hidden layers of the baseline system, there are numerous settings of the ranks for the projection matrices in each layer which result in the same number of total parameters in the compressed network. In order to avoid this ambiguity, we set the various projection ranks using the following criterion: Given a threshold , for each layer , we set the rank of the corresponding projection matrix such that it corresponds to retaining a fraction of at most of the explained variance after the truncated SVD of . More specifically, if the singular values in in (5) are sorted in non-increasing order as , we set each as:
Choosing the projection ranks using (7) allows us to control the degree of compression, and thus compressed model size by varying a single parameter, . In pilot experiments we found that this scheme performed better than setting ranks to be equal for all layers (given the same total parameter budget). Once the projection ranks have been determined for the various projection matrices we fine-tune the compressed models by first optimizing the CTC criterion, followed by sequence training with the sMBR criterion and adaptation on in-domain data as described in Section 4.1. The results of our experiments are presented in Table 1.
As can be seen in Table 1, the baseline system which predicts CI phoneme targets is only 10% relative worse than the larger server-sized system, although it has half as many parameters. Since the ranks are all chosen to retain a given fraction of the explained variance in the SVD operation, we also note that earlier hidden layers in the network appear to have lower ranks than later layers, since most of the variance is accounted for by a smaller number of singular values. It can be seen from Table 1 that word error rates increase as the amount of compression is increased, although performance of the compressed systems are close to the baseline for moderate compression (). Using a value of , enables the model to be compressed to a third of its original size, with only a small degradation in accuracy. However, performance begins to degrade significantly for . Future work will consider alternative techniques for setting the projection ranks in order to examine their impact on system performance.
Conclusions
We presented a technique to compress RNNs using a joint factorization of recurrent and inter-layer weight matrices, generalizing previous work . The proposed technique was applied to the task of compressing LSTM RNN acoustic models for embedded speech recognition, where we found that we could compress our baseline acoustic model to a third of its original size with negligible loss in accuracy. The proposed techniques, in combination with weight quantization, allow us to build a small and efficient speech recognizer that run many times faster than real-time on recent mobile devices .