Sequence-Level Knowledge Distillation

Abstract: Neural machine translation (NMT) offers a novel alternative formulation of translation that is potentially simpler than statistical approaches. However to reach competitive performance, NMT models need to be exceedingly large. In this paper we consider applying knowledge distillation approaches (Bucila et al., 2006; Hinton et al., 2015) that have proven successful for reducing the size of neural models in other domains to the problem of NMT. We demonstrate that standard knowledge distillation applied to word-level prediction can be effective for NMT, and also introduce two novel sequence-level versions of knowledge distillation that further improve performance, and somewhat surprisingly, seem to eliminate the need for beam search (even when applied on the original teacher model). Our best student model runs 10 times faster than its state-of-the-art teacher with little loss in performance. It is also significantly better than a baseline model trained without knowledge distillation: by 4.2/1.7 BLEU with greedy decoding/beam search. Applying weight pruning on top of knowledge distillation results in a student model that has 13 times fewer parameters than the original teacher model, with a decrease of 0.4 BLEU.

Neural machine translation (NMT) BIBREF2 , BIBREF3 , BIBREF4 , BIBREF5 is a deep learning-based method for translation that has recently shown promising results as an alternative to statistical approaches. NMT systems directly model the probability of the next word in the target sentence simply by conditioning a recurrent neural network on the source sentence and previously generated target words.
While both simple and surprisingly accurate, NMT systems typically need to have very high capacity in order to perform well: Sutskever2014 used a 4-layer LSTM with 1000 hidden units per layer (herein INLINEFORM0 ) and Zhou2016 obtained state-of-the-art results on English INLINEFORM1 French with a 16-layer LSTM with 512 units per layer. The sheer size of the models requires cutting-edge hardware for training and makes using the models on standard setups very challenging.
This issue of excessively large networks has been observed in several other domains, with much focus on fully-connected and convolutional networks for multi-class classification. Researchers have particularly noted that large networks seem to be necessary for training, but learn redundant representations in the process BIBREF6 . Therefore compressing deep models into smaller networks has been an active area of research. As deep learning systems obtain better results on NLP tasks, compression also becomes an important practical issue with applications such as running deep learning models for speech and translation locally on cell phones.
Existing compression methods generally fall into two categories: (1) pruning and (2) knowledge distillation. Pruning methods BIBREF7 , BIBREF8 , BIBREF9 , zero-out weights or entire neurons based on an importance criterion: LeCun1990 use (a diagonal approximation to) the Hessian to identify weights whose removal minimally impacts the objective function, while Han2016 remove weights based on thresholding their absolute values. Knowledge distillation approaches BIBREF0 , BIBREF10 , BIBREF1 learn a smaller student network to mimic the original teacher network by minimizing the loss (typically INLINEFORM0 or cross-entropy) between the student and teacher output.
In this work, we investigate knowledge distillation in the context of neural machine translation. We note that NMT differs from previous work which has mainly explored non-recurrent models in the multi-class prediction setting. For NMT, while the model is trained on multi-class prediction at the word-level, it is tasked with predicting complete sequence outputs conditioned on previous decisions. With this difference in mind, we experiment with standard knowledge distillation for NMT and also propose two new versions of the approach that attempt to approximately match the sequence-level (as opposed to word-level) distribution of the teacher network. This sequence-level approximation leads to a simple training procedure wherein the student network is trained on a newly generated dataset that is the result of running beam search with the teacher network.
We run experiments to compress a large state-of-the-art INLINEFORM0 LSTM model, and find that with sequence-level knowledge distillation we are able to learn a INLINEFORM1 LSTM that roughly matches the performance of the full system. We see similar results compressing a INLINEFORM2 model down to INLINEFORM3 on a smaller data set. Furthermore, we observe that our proposed approach has other benefits, such as not requiring any beam search at test-time. As a result we are able to perform greedy decoding on the INLINEFORM4 model 10 times faster than beam search on the INLINEFORM5 model with comparable performance. Our student models can even be run efficiently on a standard smartphone. Finally, we apply weight pruning on top of the student network to obtain a model that has INLINEFORM6 fewer parameters than the original teacher model. We have released all the code for the models described in this paper.
Let INLINEFORM0 and INLINEFORM1 be (random variable sequences representing) the source/target sentence, with INLINEFORM2 and INLINEFORM3 respectively being the source/target lengths. Machine translation involves finding the most probable target sentence given the source: INLINEFORM4 
where INLINEFORM0 is the set of all possible sequences. NMT models parameterize INLINEFORM1 with an encoder neural network which reads the source sentence and a decoder neural network which produces a distribution over the target sentence (one word at a time) given the source. We employ the attentional architecture from Luong2015, which achieved state-of-the-art results on English INLINEFORM2 German translation.
Knowledge distillation describes a class of methods for training a smaller student network to perform better by learning from a larger teacher network (in addition to learning from the training data set). We generally assume that the teacher has previously been trained, and that we are estimating parameters for the student. Knowledge distillation suggests training by matching the student's predictions to the teacher's predictions. For classification this usually means matching the probabilities either via INLINEFORM0 on the INLINEFORM1 scale BIBREF10 or by cross-entropy BIBREF11 , BIBREF1 .
Concretely, assume we are learning a multi-class classifier over a data set of examples of the form INLINEFORM0 with possible classes INLINEFORM1 . The usual training criteria is to minimize NLL for each example from the training data, INLINEFORM2 
where INLINEFORM0 is the indicator function and INLINEFORM1 the distribution from our model (parameterized by INLINEFORM2 ). This objective can be seen as minimizing the cross-entropy between the degenerate data distribution (which has all of its probability mass on one class) and the model distribution INLINEFORM3 .
In knowledge distillation, we assume access to a learned teacher distribution INLINEFORM0 , possibly trained over the same data set. Instead of minimizing cross-entropy with the observed data, we instead minimize the cross-entropy with the teacher's probability distribution, INLINEFORM1 
 where INLINEFORM0 parameterizes the teacher distribution and remains fixed. Note the cross-entropy setup is identical, but the target distribution is no longer a sparse distribution. Training on INLINEFORM5 is attractive since it gives more information about other classes for a given data point (e.g. similarity between classes) and has less variance in gradients BIBREF1 .
Since this new objective has no direct term for the training data, it is common practice to interpolate between the two losses, INLINEFORM0 
where INLINEFORM0 is mixture parameter combining the one-hot distribution and the teacher distribution.
The large sizes of neural machine translation systems make them an ideal candidate for knowledge distillation approaches. In this section we explore three different ways this technique can be applied to NMT.
NMT systems are trained directly to minimize word NLL, INLINEFORM0 , at each position. Therefore if we have a teacher model, standard knowledge distillation for multi-class cross-entropy can be applied. We define this distillation for a sentence as, INLINEFORM1 
where INLINEFORM0 is the target vocabulary set. The student can further be trained to optimize the mixture of INLINEFORM1 and INLINEFORM2 . In the context of NMT, we refer to this approach as word-level knowledge distillation and illustrate this in Figure 1 (left).
Word-level knowledge distillation allows transfer of these local word distributions. Ideally however, we would like the student model to mimic the teacher's actions at the sequence-level. The sequence distribution is particularly important for NMT, because wrong predictions can propagate forward at test-time.
First, consider the sequence-level distribution specified by the model over all possible sequences INLINEFORM0 , INLINEFORM1 
for any length INLINEFORM0 . The sequence-level negative log-likelihood for NMT then involves matching the one-hot distribution over all complete sequences, INLINEFORM1 
where INLINEFORM0 is the observed sequence. Of course, this just shows that from a negative log likelihood perspective, minimizing word-level NLL and sequence-level NLL are equivalent in this model.
But now consider the case of sequence-level knowledge distillation. As before, we can simply replace the distribution from the data with a probability distribution derived from our teacher model. However, instead of using a single word prediction, we use INLINEFORM0 to represent the teacher's sequence distribution over the sample space of all possible sequences, INLINEFORM1 
Note that INLINEFORM0 is inherently different from INLINEFORM1 , as the sum is over an exponential number of terms. Despite its intractability, we posit that this sequence-level objective is worthwhile. It gives the teacher the chance to assign probabilities to complete sequences and therefore transfer a broader range of knowledge. We thus consider an approximation of this objective.
Our simplest approximation is to replace the teacher distribution INLINEFORM0 with its mode, INLINEFORM1 
Observing that finding the mode is itself intractable, we use beam search to find an approximation. The loss is then INLINEFORM0 
where INLINEFORM0 is now the output from running beam search with the teacher model.
Using the mode seems like a poor approximation for the teacher distribution INLINEFORM0 , as we are approximating an exponentially-sized distribution with a single sample. However, previous results showing the effectiveness of beam search decoding for NMT lead us to belief that a large portion of INLINEFORM1 's mass lies in a single output sequence. In fact, in experiments we find that with beam of size 1, INLINEFORM2 (on average) accounts for INLINEFORM3 of the distribution for German INLINEFORM4 English, and INLINEFORM5 for Thai INLINEFORM6 English (Table 1: INLINEFORM7 ).
To summarize, sequence-level knowledge distillation suggests to: (1) train a teacher model, (2) run beam search over the training set with this model, (3) train the student network with cross-entropy on this new dataset. Step (3) is identical to the word-level NLL process except now on the newly-generated data set. This is shown in Figure 1 (center).
Next we consider integrating the training data back into the process, such that we train the student model as a mixture of our sequence-level teacher-generated data ( INLINEFORM0 ) with the original training data ( INLINEFORM1 ), INLINEFORM2 
 where INLINEFORM0 is the gold target sequence.
Since the second term is intractable, we could again apply the mode approximation from the previous section, INLINEFORM0 
and train on both observed ( INLINEFORM0 ) and teacher-generated ( INLINEFORM1 ) data. However, this process is non-ideal for two reasons: (1) unlike for standard knowledge distribution, it doubles the size of the training data, and (2) it requires training on both the teacher-generated sequence and the true sequence, conditioned on the same source input. The latter concern is particularly problematic since we observe that INLINEFORM2 and INLINEFORM3 are often quite different.
As an alternative, we propose a single-sequence approximation that is more attractive in this setting. This approach is inspired by local updating BIBREF12 , a method for discriminative training in statistical machine translation (although to our knowledge not for knowledge distillation). Local updating suggests selecting a training sequence which is close to INLINEFORM0 and has high probability under the teacher model, INLINEFORM1 
where INLINEFORM0 is a function measuring closeness (e.g. Jaccard similarity or BLEU BIBREF13 ). Following local updating, we can approximate this sequence by running beam search and choosing INLINEFORM1 
where INLINEFORM0 is the INLINEFORM1 -best list from beam search. We take INLINEFORM2 to be smoothed sentence-level BLEU BIBREF14 .
We justify training on INLINEFORM0 from a knowledge distillation perspective with the following generative process: suppose that there is a true target sequence (which we do not observe) that is first generated from the underlying data distribution INLINEFORM1 . And further suppose that the target sequence that we observe ( INLINEFORM2 ) is a noisy version of the unobserved true sequence: i.e. (i) INLINEFORM3 , (ii) INLINEFORM4 , where INLINEFORM5 is, for example, a noise function that independently replaces each element in INLINEFORM6 with a random element in INLINEFORM7 with some small probability. In such a case, ideally the student's distribution should match the mixture distribution, INLINEFORM10 
In this setting, due to the noise assumption, INLINEFORM0 now has significant probability mass around a neighborhood of INLINEFORM1 (not just at INLINEFORM2 ), and therefore the INLINEFORM3 of the mixture distribution is likely something other than INLINEFORM4 (the observed sequence) or INLINEFORM5 (the output from beam search). We can see that INLINEFORM6 is a natural approximation to the INLINEFORM7 of this mixture distribution between INLINEFORM8 and INLINEFORM9 for some INLINEFORM10 . We illustrate this framework in Figure 1 (right) and visualize the distribution over a real example in Figure 2.
To test out these approaches, we conduct two sets of NMT experiments: high resource (English INLINEFORM0 German) and low resource (Thai INLINEFORM1 English).
The English-German data comes from WMT 2014. The training set has 4m sentences and we take newstest2012/newstest2013 as the dev set and newstest2014 as the test set. We keep the top 50k most frequent words, and replace the rest with UNK. The teacher model is a INLINEFORM0 LSTM (as in Luong2015) and we train two student models: INLINEFORM1 and INLINEFORM2 . The Thai-English data comes from IWSLT 2015. There are 90k sentences in the training set and we take 2010/2011/2012 data as the dev set and 2012/2013 as the test set, with a vocabulary size is 25k. Size of the teacher model is INLINEFORM3 (which performed better than INLINEFORM4 , INLINEFORM5 models), and the student model is INLINEFORM6 . Other training details mirror Luong2015.
We evaluate on tokenized BLEU with INLINEFORM0 , and experiment with the following variations:
Results of our experiments are shown in Table 1. We find that while word-level knowledge distillation (Word-KD) does improve upon the baseline, sequence-level knowledge distillation (Seq-KD) does better on English INLINEFORM0 German and performs similarly on Thai INLINEFORM1 English. Combining them (Seq-KD INLINEFORM2 Word-KD) results in further gains for the INLINEFORM3 and INLINEFORM4 models (although not for the INLINEFORM5 model), indicating that these methods provide orthogonal means of transferring knowledge from the teacher to the student: Word-KD is transferring knowledge at the the local (i.e. word) level while Seq-KD is transferring knowledge at the global (i.e. sequence) level.
Sequence-level interpolation (Seq-Inter), in addition to improving models trained via Word-KD and Seq-KD, also improves upon the original teacher model that was trained on the actual data but fine-tuned towards Seq-Inter data (Baseline INLINEFORM0 Seq-Inter). In fact, greedy decoding with this fine-tuned model has similar performance ( INLINEFORM1 ) as beam search with the original model ( INLINEFORM2 ), allowing for faster decoding even with an identically-sized model.
We hypothesize that sequence-level knowledge distillation is effective because it allows the student network to only model relevant parts of the teacher distribution (i.e. around the teacher's mode) instead of `wasting' parameters on trying to model the entire space of translations. Our results suggest that this is indeed the case: the probability mass that Seq-KD models assign to the approximate mode is much higher than is the case for baseline models trained on original data (Table 1: INLINEFORM0 ). For example, on English INLINEFORM1 German the (approximate) INLINEFORM2 for the INLINEFORM3 Seq-KD model (on average) accounts for INLINEFORM4 of the total probability mass, while the corresponding number is INLINEFORM5 for the baseline. This also explains the success of greedy decoding for Seq-KD models—since we are only modeling around the teacher's mode, the student's distribution is more peaked and therefore the INLINEFORM6 is much easier to find. Seq-Inter offers a compromise between the two, with the greedily-decoded sequence accounting for INLINEFORM7 of the distribution.
Finally, although past work has shown that models with lower perplexity generally tend to have higher BLEU, our results indicate that this is not necessarily the case. The perplexity of the baseline INLINEFORM0 English INLINEFORM1 German model is INLINEFORM2 while the perplexity of the corresponding Seq-KD model is INLINEFORM3 , despite the fact that Seq-KD model does significantly better for both greedy ( INLINEFORM4 BLEU) and beam search ( INLINEFORM5 BLEU) decoding.
Run-time complexity for beam search grows linearly with beam size. Therefore, the fact that sequence-level knowledge distillation allows for greedy decoding is significant, with practical implications for running NMT systems across various devices. To test the speed gains, we run the teacher/student models on GPU, CPU, and smartphone, and check the average number of source words translated per second (Table 2). We use a GeForce GTX Titan X for GPU and a Samsung Galaxy 6 smartphone. We find that we can run the student model 10 times faster with greedy decoding than the teacher model with beam search on GPU ( INLINEFORM0 vs INLINEFORM1 words/sec), with similar performance.
Although knowledge distillation enables training faster models, the number of parameters for the student models is still somewhat large (Table 1: Params), due to the word embeddings which dominate most of the parameters. For example, on the INLINEFORM0 English INLINEFORM1 German model the word embeddings account for approximately INLINEFORM2 (50m out of 84m) of the parameters. The size of word embeddings have little impact on run-time as the word embedding layer is a simple lookup table that only affects the first layer of the model.
We therefore focus next on reducing the memory footprint of the student models further through weight pruning. Weight pruning for NMT was recently investigated by See2016, who found that up to INLINEFORM0 of the parameters in a large NMT model can be pruned with little loss in performance. We take our best English INLINEFORM1 German student model ( INLINEFORM2 Seq-KD INLINEFORM3 Seq-Inter) and prune INLINEFORM4 of the parameters by removing the weights with the lowest absolute values. We then retrain the pruned model on Seq-KD data with a learning rate of INLINEFORM5 and fine-tune towards Seq-Inter data with a learning rate of INLINEFORM6 . As observed by See2016, retraining proved to be crucial. The results are shown in Table 3.
Our findings suggest that compression benefits achieved through weight pruning and knowledge distillation are orthogonal. Pruning INLINEFORM0 of the weight in the INLINEFORM1 student model results in a model with INLINEFORM2 fewer parameters than the original teacher model with only a decrease of INLINEFORM3 BLEU. While pruning INLINEFORM4 of the weights results in a more appreciable decrease of INLINEFORM5 BLEU, the model is drastically smaller with 8m parameters, which is INLINEFORM6 fewer than the original teacher model.
For models trained with word-level knowledge distillation, we also tried regressing the student network's top-most hidden layer at each time step to the teacher network's top-most hidden layer as a pretraining step, noting that Romero2015 obtained improvements with a similar technique on feed-forward models. We found this to give comparable results to standard knowledge distillation and hence did not pursue this further.
There have been promising recent results on eliminating word embeddings completely and obtaining word representations directly from characters with character composition models, which have many fewer parameters than word embedding lookup tables BIBREF15 , BIBREF16 , BIBREF17 , BIBREF18 , BIBREF19 . Combining such methods with knowledge distillation/pruning to further reduce the memory footprint of NMT systems remains an avenue for future work.
Compressing deep learning models is an active area of current research. Pruning methods involve pruning weights or entire neurons/nodes based on some criterion. LeCun1990 prune weights based on an approximation of the Hessian, while Han2016 show that a simple magnitude-based pruning works well. Prior work on removing neurons/nodes include Srinivas2015 and Mariet2016. See2016 were the first to apply pruning to Neural Machine Translation, observing that that different parts of the architecture (input word embeddings, LSTM matrices, etc.) admit different levels of pruning. Knowledge distillation approaches train a smaller student model to mimic a larger teacher model, by minimizing the loss between the teacher/student predictions BIBREF0 , BIBREF10 , BIBREF11 , BIBREF1 . Romero2015 additionally regress on the intermediate hidden layers of the student/teacher network as a pretraining step, while Mou2015 obtain smaller word embeddings from a teacher model via regression. There has also been work on transferring knowledge across different network architectures: Chan2015b show that a deep non-recurrent neural network can learn from an RNN; Geras2016 train a CNN to mimic an LSTM for speech recognition. Kuncoro2016 recently investigated knowledge distillation for structured prediction by having a single parser learn from an ensemble of parsers.
Other approaches for compression involve low rank factorizations of weight matrices BIBREF20 , BIBREF21 , BIBREF22 , BIBREF23 , sparsity-inducing regularizers BIBREF24 , binarization of weights BIBREF25 , BIBREF26 , and weight sharing BIBREF27 , BIBREF9 . Finally, although we have motivated sequence-level knowledge distillation in the context of training a smaller model, there are other techniques that train on a mixture of the model's predictions and the data, such as local updating BIBREF12 , hope/fear training BIBREF28 , SEARN BIBREF29 , DAgger BIBREF30 , and minimum risk training BIBREF31 , BIBREF32 .
In this work we have investigated existing knowledge distillation methods for NMT (which work at the word-level) and introduced two sequence-level variants of knowledge distillation, which provide improvements over standard word-level knowledge distillation.
We have chosen to focus on translation as this domain has generally required the largest capacity deep learning models, but the sequence-to-sequence framework has been successfully applied to a wide range of tasks including parsing BIBREF33 , summarization BIBREF34 , dialogue BIBREF35 , BIBREF36 , BIBREF37 , NER/POS-tagging BIBREF38 , image captioning BIBREF39 , BIBREF40 , video generation BIBREF41 , and speech recognition BIBREF42 . We anticipate that methods described in this paper can be used to similarly train smaller models in other domains.

Figure and table captions:
Figure 1: Overview of the different knowledge distillation approaches. In word-level knowledge distillation (left) cross entropy is minimized between the student/teacher distributions (yellow) for each word in the actual target sequence (ECD), as well as between the student distribution and the degenerate data distribution, which has all of its probabilitiy mass on one word (black). In sequence-level knowledge distillation (center) the student network is trained on the output from beam search of the teacher network that had the highest score (ACF). In sequence-level interpolation (right) the student is trained on the output from beam search of the teacher network that had the highest sim with the target sequence (ECE).
Figure 2: Visualization of sequence-level interpolation on an example training sentence with a German → English model: Bis 15 Tage vor Anreise sind Zimmer-Annullationen kostenlos. We run beam search and plot the final hidden state of the hypotheses using t-SNE and show the corresponding (smoothed) probabilities with contours. In the above example, the sentence that is at the top of the beam after beam search (green) is quite far away from gold (red), so we train the model on a sentence that is on the beam but had the highest sim to gold (purple).
Table 1: Results on English-German (newstest2014) and English-Thai (2012/2013) test sets. Params: number of parameters in the model; PPL: perplexity on the test set; BLEUK=1: BLEU score with beam size K = 1 (i.e. greedy decoding); ∆K=1: BLEU gain over the baseline model without any knowledge distillation with greedy decoding; BLEUK=5: BLEU score with beam sizeK = 5; ∆K=5: BLEU gain over the baseline model without any knowledge distillation with beam size K = 5; p(t = ŷ): Probability of output sequence from greedy decoding (averaged over the test set).
Table 2: Number of source words translated per second across the GPU (GeForce GTX Titan X), CPU, and cell phone (Samsung Galaxy 6). We were unable to run the 4× 1000 models on the cell phone.

Questions about this paper:
What type of weight pruning do they use?

Answers:
Prune %x of the parameters by removing the weights with the lowest absolute values.