We propose a conditional non-autoregressive neural sequence model based on iterative refinement. The proposed model is designed based on the principles of latent variable models and denoising autoencoders, and is generally applicable to any sequence generation task. We extensively evaluate the proposed model on machine translation (En-De and En-Ro) and image caption generation, and observe that it significantly speeds up decoding while maintaining the generation quality comparable to the autoregressive counterpart.READ FULL TEXT VIEW PDF
Although neural machine translation models reached high translation qual...
Most sequence-to-sequence (seq2seq) models are autoregressive; they gene...
Non-autoregressive neural machine translation (NAT) generates each targe...
We propose an efficient inference procedure for non-autoregressive machi...
We propose a model for hierarchical structured data as an extension to t...
Undirected neural sequence models such as BERT have received renewed int...
Recently, simultaneous translation has gathered a lot of attention since...
Conditional neural sequence modeling has become a de facto standard in a variety of tasks (see, e.g., Cho et al., 2015, and references therein)
. Much of this recent success is built on top of successful autoregressive sequence modeling in which the probability of a target sequence is factorized as a product of conditional probabilities of next symbols given all the preceding ones. Despite its success, neural autoregressive modeling, which is often non-Markovian and nonlinear, has its weakness in decoding, i.e., finding the most likely sequence. Because of intractability, we must resort to suboptimal approximate decoding, and due to its sequential nature, decoding cannot be easily parallelized and results in a large latency(see, e.g., Cho, 2016). This has motivated the recent investigation into non-autoregressive neural sequence modeling by Gu et al. (2017) in the context of machine translation and Oord et al. (2017) in the context of speech synthesis.
In this paper, we propose a non-autoregressive neural sequence model based on iterative refinement, which is generally applicable to any sequence generation task beyond machine translation. The proposed model can be viewed as both a latent variable model and a conditional denoising autoencoder. We thus propose a learning algorithm that is hybrid of (deterministic) lower-bound maximization and reconstruction error minimization. We further design an iterative inference strategy with an adaptive number of steps to minimize the generation latency without sacrificing the generation quality.
We extensively evaluate the proposed conditional non-autoregressive sequence model and compare it against the autoregressive counterpart, using the state-of-the-art Transformer (Vaswani et al., 2017), on machine translation and image caption generation. In the case of machine translation, the proposed deterministic non-autoregressive models are able to decode approximately faster than beam search from the autoregressive counterparts on both GPU and CPU, while maintaining 90% (IWSLT’16 EnDe and WMT’16 EnRo) and 80% (WMT’15 EnDe) of translation quality. On image caption generation, we observe approximately and faster decoding on GPU and CPU, respectively, while maintaining 85% of caption quality.
We release our implementation, preprocessed datasets and pretrained models online at https://github.com/nyu-dl/dl4mt-nonauto.
Sequence modeling in deep learning has largely focused on autoregressive modeling of a sequence. That is, given a sequence
, we use some form of a neural network to parametrize the conditional distribution over each variablegiven all the preceding variables, i.e.,
is for instance a recurrent neural network. This approach has become ade facto standard in language modeling (Mikolov et al., 2010). When this is augmented with an extra conditioning variable , it becomes conditional sequence modeling which serves as a basis on which many recent advances in, for instance, machine translation (Bahdanau et al., 2014; Sutskever et al., 2014; Kalchbrenner & Blunsom, 2013) and speech recognition (Chorowski et al., 2015; Chiu et al., 2017) have been made.
Despite the recent success, autoregressive sequence modeling has a weakness due to its nature of sequential processing. This weakness shows itself especially when we try to decode the most likely sequence from a trained model, i.e., . There is no known polynomial algorithm for solving it exactly, and practitioners have relied on approximate decoding algorithms, such as greedy decoding, beam search, noisy parallel approximate decoding and continuous relaxation (see, e.g., Cho, 2016; Hoang et al., 2017). Among these, beam search has become the method of choice, due to its superior performance over greedy decoding, which however comes with a substantial computational overhead (Cho, 2016).
As a solution to this issue of slow decoding, two recent works have attempted non-autoregressive sequence modeling. Gu et al. (2017) have modified the recently proposed Transformer (Vaswani et al., 2017) for non-autoregressive machine translation, and Oord et al. (2017) a convolutional network (Oord et al., 2016) for non-autoregressive modeling of waveform. Non-autoregressive modeling aims at factorizing the distribution over a target sequence given a source into a product of conditionally independent per-step distributions:
breaking the dependency among the target variables across time. This break of dependency allows us to trivially find the most likely target sequence by We effectively bypass the computational overhead and sub-optimality of decoding from an autoregressive sequence model.
This desirable property of non-autoregressive neural sequence modeling however comes also with a potential performance degradation (Kaiser & Bengio, 2016). It is due to the fact that any potential dependency among target variables must be captured by a neural network that models the factorized conditionals in Eq. (1). That is, the potential modeling gap, which is the gap between the underlying, true model and the neural sequence model, could be larger with the non-autogressive model than the autoregressive one. On the other hand, this issue may be canceled out, because the decoding gap, which may be arbitrarily large with the autoregressive model and an approximate decoding algorithm, does not exist with the non-autoregressive model (that is, decoding is exact given a model.) This has indeed been shown to be the case recently by Oord et al. (2017) and Gu et al. (2017). See Fig. 1 for graphical illustration of this view.
We propose a non-autoregressive neural sequence model. Similarly to two recent works (Oord et al., 2017; Gu et al., 2017), we introduce latent variables to implicitly capture the dependencies among target variables. We however remove any stochastic behavior by interpreting this latent variable model, introduced immediately below, as a process of iterative refinement.
Our goal is to capture the dependencies among target symbols given a source sentence without auto-regression. We address this by introducing
-many intermediate random variables and marginalizing them out:
Each product term inside the summation is modelled by a shared deep neural network that takes as input a source sentence and outputs the conditional distribution over the target vocabulary for each .
The marginalization in Eq. (2) is intractable. In order to avoid this issue, we consider its deterministic lower bound. To make it clearer, let us consider . Then,
Then, the entire lower bound can be written as:
In this formulation, the intermediate random variables could be anonymous. We however constrain them to be of the same type as the output in order to share the underlying parametrized neural network. This constraint allows us to view each conditional as a single-step of refining a rough target sequence . The entire chain of conditionals is then the -step iterative refinement. Furthermore, sharing the parameters across these refinement steps enables us to dynamically adapt the number of iterations per input . This is important as it substantially reduces the amount of time required for decoding, as we see later in the experiments.
For each training pair , we first compute the lower bound in Eq. (3) from the first conditional to the final one . The computation of each conditional is followed by
We then maximize
where is a set of parameters. is an empty sequence.
The proposed approach could instead be viewed as learning a conditional denoising autoencoder which is known to capture the gradient of the log-density (under certain assumptions.) That is, we implicitly learn to find a direction in the output space that maximizes the underlying true, data-generating distribution . Because the output space is discrete, much of the theoretical analysis by Alain & Bengio (2014) are not strictly applicable. We however find this view attractive as it serves as an alternative foundation for designing a learning algorithm.
We start with a corruption process , which introduces noise to the correct output . Given the source and the reference translation , we sample . This corrupted target then acts as an input to each conditional in Eq. (2). Then, the goal of learning is to maximize the log-probability of the original reference given the corrupted version. That is, to maximize
Once this cost is minimized, we can recursively perform the maximum-a-posterior inference, i.e.,
to find that (approximately) maximizes .
There is little consensus on the best corruption process for a sequence, especially of discrete tokens. In this work, we use a corruption process proposed by Hill et al. , which has recently become more widely adopted (see, e.g., Artetxe et al., 2017; Lample et al., 2017). Each in a reference target is corrupted with a probability . If decided to corrupt, we either (1) replace with this token , (2) replace with a token uniformly selected from a vocabulary of all unique tokens at random, or (3) swap and . This is done sequentially from until .
Although it is possible to train the proposed non-autoregressive sequence model using either of the cost functions above ( or ,) we propose to stochastically mix these two cost functions. We do so by randomly replacing each term in Eq. (4) with in Eq. (5). In other words,
where , and
is a sample from a Bernoulli distribution with the probability.
is a hyperparameter. As the first conditionalin Eq. (2) does not take as input any target , we set always.
Gu et al. (2017), in the context of machine translation, and Oord et al. (2017), in the context of speech generation, have recently discovered that it is important to use knowledge distillation (Hinton et al., 2015; Kim & Rush, 2016) to successfully train a non-autoregressive sequence model. Following Gu et al. (2017), we also use knowledge distillation by replacing the reference target of each training example with a target generated from a well-trained autoregressive counterpart. Other than this replacement, the cost function in Eq (3.3) and the model architecture remain unchanged.
One minor difference between the autoregressive and non-autoregressive models is that the former naturally models the length of a target sequence without any arbitrary upper-bound, while the latter does not. It is hence necessary to separately model , where is the length of a target sequence. During training, we simply use the length of each reference target sequence.
Inference in the proposed approach is entirely deterministic. We start from the input and use the first conditional to generate the initial target sequence, i.e.,
From here on, we iteratively generate target sequences by
Because these conditionals, except for the initial one, are modeled by a single, shared neural network, this refinement can be performed as many iterations as necessary, potentially more than the number of iterations used for training, until a predefined stopping criterion is met. A criterion can for instance be based either on the amount of change in a target sequence after each iteration (i.e., ), on the amount of change in the conditional log-probabilities (i.e., ) or on the computational budget. In the experiments later, we observe that the first criterion is a reasonable choice for both machine translation and image caption generation.
proposed a continuous-space translation model (CSTM) to estimate the conditional distribution over a target phrase given a source phrase, while dropping the conditional dependencies among target tokens, as in Eq. (1). The CSTM was found to improve the output of a machine translation system by reranking the -best list. The evaluation was however limited to reranking and to short phrase pairs (up to 7 words on each side) only.
More recently, Kaiser & Bengio (2016)
investigated a recurrent stack of convolutional gated recurrent units, called neural GPU(Kaiser & Sutskever, 2015), for machine translation. They evaluated both non-autoregressive and autoregressive approaches, and found that the non-autoregressive approach significantly lags behind the autoregressive variants. Their approach is similar in that a shared stack of a neural GPU is applied multiple times given an input sequence. It however differs from our approach that each iteration does not output a refined version from the previous iteration.
The recent paper by Gu et al. (2017)
is most relevant to the proposed work. In order to capture dependencies among target variables, they introduced a sequence of discrete latent variables. Instead of (approximately) marginalizing them out, they use supervised learning to train an inference network for those latent variables, using the off-the-shelf word alignment tool(Dyer et al., 2013), which is unlike our approach which does not require any extra supervision. To achieve the best result, Gu et al. (2017) stochastically sample the latent variables and rerank the corresponding target sequences with an external, autoregressive model. This is in stark contrast to the proposed approach which is fully deterministic and does not rely on any extra reranking mechanism. Furthermore, our approach does not require additional finetuning with reverse KL-divergence.
Simultaneously with Gu et al. (2017), Oord et al. (2017) presented a successful, non-autoregressive sequence model for speech waveform. They use inverse autoregressive flow (IAF, Kingma et al., 2016) to map a sequence of independent random variables to a target sequence. In order to maximize the performance, they found it helpful to apply the IAF multiple times, similarly to our iterative refinement strategy. Their approach is however restricted to continuous target variables, while the proposed approach in principle could be applied to both discrete and continuous variables.111 Despite this, we evaluate our approach only on discrete target variables, focusing on natural language sentence.
The deliberation network, proposed recently by Xia et al. (2017)
, incorporates the idea of refinement into neural machine translation. This deliberation network consists of two autoregressive decoders. The second decoder takes into account the translation generated by the first decoder. Our approach significantly expands this by allowing many steps of refinement.
We use three transformer-based network blocks to implement our model on the right side of Eq. (2). The first block (“Encoder”) encodes the input , the second block (“Decoder 1”) models the first conditional , and the final block (“Decoder 2”) is shared across iterative refinement steps, modeling . These blocks are depicted side-by-side in Fig. 2. The encoder is identical to that from the original Transformer (Vaswani et al., 2017). We however use the decoders from (Gu et al., 2017) with additional positional attention.222 Instead of the residual layer (He et al., 2016), we use the highway layer (Srivastava et al., 2015) to stabilize learning.
Decoder 1 takes as input the original input padded/shortened according to the length of the corresponding reference target sequence. At each refinement step , decoder 2 takes as input the predicted target sequence
and the sequence of final activation vectors from the previous step. For each position, the embedding vector of the target token and the activation vector are simply summed. In our preliminary experiments, we have experimented excluding the activation vector from the previous step, which underperformed the current setup.
We evaluate the proposed approach on two distinct sequence modeling tasks: (1) machine translation and (2) image caption generation. We compare the proposed non-autoregressive model against the autoregressive counterpart both in terms of generation quality, measured in terms of BLEU (Papineni et al., 2002), and generation efficiency, measured in terms of (source) tokens and images per second for translation and image captioning respectively.
We choose three translation datasets of different sizes: IWSLT’16 EnDe, WMT’16 EnRo and WMT’15 EnDe, whose training sets consist of 196K, 610k and 4.5M sentence pairs, respectively. We tokenize all corpora using a script from Moses (Koehn et al., 2007) and segment each word into subword units using Byte Pair Encoding (BPE, Sennrich et al., 2016). We use 40k, 40k and 60k shared BPE tokens for IWSLT’16 En-De, WMT’16 En-Ro and WMT’15 En-De, respectively. For WMT’15 En-De, we use newstest-2013 and newstest-2014 as development and test sets. For WMT’16 En-Ro, we use newsdev-2016 and newstest-2016 as development and test sets. For IWSLT’16 En-De, we use test2013 for validation.
We closely follow the setting from (Gu et al., 2017). In the case of IWSLT’16 En-De, we use the small model ( and ).333 Due to the space constraint, we refer readers to (Vaswani et al., 2017; Gu et al., 2017) for more details on how these hyperparameters define one transformer block. For WMT’15 En-De and WMT’16 En-Ro, we use the base transformer from (Vaswani et al., 2017) ( and ). In addition to the warm-up learning rate scheduling from (Vaswani et al., 2017), we also experimented with annealing the learning rate linearly from to . We do not use label smoothing nor average multiple check-pointed models. These decisions were made based on the preliminary experiments. We train each model either on a single NVIDIA P40 (WMT’15 En-De and WMT’16 En-Ro) or on a single NVIDIA P100 (IWSLT’16 En-De) with each minibatch consisting of approximately 2,048 tokens.
We use MS COCO (Lin et al., 2014) for image caption generation. We used the publicly available splits used in the previous image caption generation work (Karpathy & Li, 2015) consisting of 113,287 training images, 5k validation images and 5k test images. Each image is pre-transformed into a set of 49 512-dimensional feature vectors, using a ResNet-18 (He et al., 2016)
pretrained on ImageNet(Deng et al., 2009). The average of these 49 vectors is copied as many times to match the length of the target sentence (reference during training and predicted during evaluation) to form the initial input to decoder 1. We use the base transformer from (Vaswani et al., 2017) except for set to 4 instead of 6. We train each model on a single NVIDIA 1080ti with each minibatch consisting of approximately 1,024 tokens.
We formulate the target length prediction as a classification problem of predicting the difference between the target and source lengths for translation and target length for image captioning. All the hidden vectors from the
layers of the encoder are summed and fed to a softmax classifier after affine transformation. This length predictor is trained separately once the main non-autoregressive model has been trained and is used only during decoding.
We use Adam (Kingma & Ba, 2014) as an optimizer and use in Eq. (2), meaning we run four steps of iterative refinement ( from hereon.) We use based on the validation set performance. After both the main non-autogressive sequence model and target length predictor are trained, we decode by first predicting the target length and running iterative refinement steps until the outputs of consecutive iterations are the same (or Jaccard distance between consecutive decoded sequences is ). To assess the effectiveness of this adaptive scheme, we also test a fixed number of steps (). Only in the case of machine translation, we remove any repetition by mapping multiple consecutive occurrences in a token into one.
|distill||rep||no rep||rep||no rep|
We make some important observations from the results in Table 1. First, the generation quality improves across all the tasks as we run more refinement steps even beyond the number of iterations used during training (). This supports our interpretation of the proposed approach as a conditional denoising autoencoder in Sec. 3.2. To further verify this, we run decoding on WMT’15 (both directions) up to 100 iterations. As shown in Fig. 3, the quality improves up to a certain number of iterations, but from thereon, stagnates and eventually drops. A similar behavior was observed earlier with another generative model using iterative refinement (Raiko et al., 2014), which we leave as a future work to investigate.
Second, the generation efficiency decreases as more refinements are made. Together with the first observation, it suggests that the proposed approach allows us to make a smooth trade-off between the quality and speed. We further observe that the adaptive iteration scheme works well by achieving near-best generation quality with significantly lower computational overhead.
We also observe that the speedup in decoding from the proposed approach is much clearer on GPU than on CPU. This is a consequence of highly parallel computation of the proposed non-autoregressive model, which is better suited to GPUs, showcasing the potential of using the non-autoregressive model with a specialized hardware for parallel computation, such as Google’s TPUs (Jouppi et al., 2017).
The proposed approach however suffers from the generation quality degradation compared to the autoregressive counterpart, as also observed by Gu et al. (2017). The quality degradation is most evident on WMT’15 En-De. WMT’15 En-De is clearly distinguished from other datasets in two aspects. First, the average target length of training set in WMT’15 En-De is which is longer compared to IWSLT’16 En-De (20), WMT’16 En-Ro (26) and COCO (10). This may require unreasonably many refinement steps, or transformer blocks in each decoder in order to capture long-term dependencies in a target sequence. Second, WMT’15 has much more training examples compared to other datasets. It is not clear how these aspects negatively affect non-autoregressive model, and we leave this analysis for future investigation.
Lastly, it is encouraging to observe that the proposed non-autoregressive model works well on image caption generation. This result confirms the generality of our approach beyond machine translation, unlike that by Gu et al. (2017) which was explicitly designed and tested for machine translation or by Oord et al. (2017) which was for speech synthesis.
To better understand the observed decoding speedup, we plot the average seconds per sentence in Fig. 4, measured on GPU while sequentially decoding one sentence at a time. As expected, decoding from the autoregressive model linearly slows down as the length of a sentence grows, while decoding from the proposed non-autoregressive model with a fixed number of iterations has the constant complexity. The adaptive scheme, described in Sec. 3.4, automatically increases the number of refinement steps as the length of a source sentence increases, suggesting that this scheme captures the amount of information in the input well. This increase in latency is however less severe, compared to decoding from the autoregressive model.
We run ablative experiments on IWSLT’16 En-De to investigate the impact of different components in the proposed non-autoregressive sequence model. The results are presented in Table 2.
First, we observe that it is beneficial to use multiple iterations of refinement during training. By using four iterations (one step of decoder 1, followed by three steps of decoder 2), the BLEU score improved by approximately 1.5 points in both directions. We also notice that it is necessary to use the proposed hybrid learning strategy in Eq. (3.3) to maximize the improvement from more iterations during training ( vs. vs. .) Lastly, knowledge distillation was found crucial to close the gap between the proposed deterministic non-autoregressive sequence model and its autoregressive counterpart, echoing the observations by Gu et al. (2017) and Oord et al. (2017).
As we noticed many instances of repetition in the model output with our preliminary experiments, we have decided to remove any repeating, consecutive symbols as a simple post—processing routine. From Table 2, we see that removing such repeating, consecutive symbols improves the quality (approximately +1 BLEU).444 We did not observe this behavior with image caption generation. This suggests that the proposed iterative refinement is not enough to remove repetitions on its own. Further investigation and development is necessary to properly tackle this issue, which we leave as a future work.
In Table 3, we present three sample translations and their iterative refinement steps from the development set of IWSLT’16 (DeEn). As expected, the sequence generated from the first iteration is mostly rough and it is iteratively refined over multiple steps. Inspecting the underlined sequences, we see that each iteration does not monotonically improve the translation, but overall modifies the translation towards the reference sentence. Missing words are added, while unnecessary words are dropped. For instance, see the second example. The second iteration removes the unnecessary “were”, and the fourth iteration inserts a new word “mostly”. The phrase “at the time” is gradually added one word at a time.
Table 4 shows two examples of image caption generation from the proposed non-autoregressive sequence model. In this case, we observe that each iteration captures more and more details of the input image. In the first example (left), the bus was described only as a “yellow bus” in the first iteration, but the subsequent iterations refine it into “yellow and black bus”. Similarly, “road” is refined into “lot” by noticing the details such as parking lanes. We notice this behavior in the second example (right) as well. The first iteration does not specify the place in which “a woman” is “standing on”, which is fixed immediately in the second iteration: “standing on a tennis court”. In the final and fourth iteration, the proposed model captures the fact that the “woman” is “holding” a racquet.
Following on the exciting, recent success of non-autoregressive neural sequence modeling by Gu et al. (2017) and Oord et al. (2017), we proposed a deterministic non-autoregressive neural sequence model based on the idea of iterative refinement. We designed a learning algorithm specialized to the proposed approach by interpreting the entire model as a latent variable model and each refinement step as a denoising autoencoder.
We implemented our approach using the recently proposed Transformer, the state-of-the-art sequence-to-sequence model and evaluated it on two tasks: machine translation and image caption generation. On both tasks, we were able to show that the proposed non-autoregressive model performs closely to the autoregressive counterpart with significant speedup in decoding. Qualitative analysis revealed that the proposed iterative refinement indeed refines a target sequence gradually over multiple steps.
Despite these promising results, we observed that proposed non-autoregressive neural sequence model is outperformed by its autoregressive counterpart in terms of the quality of generated sequences. We believe the following directions should be pursued in the future to narrow this gap. First, the deterministic lower-bound in Eq. (3) should be replaced with a tighter bound. Second, we should investigate other corruption processes to understand better the impact of its choice on the generation quality. Lastly, further work on sequence-to-sequence model architectures could yield better results in non-autoregressive sequence modeling.
We thank support by AdeptMind, eBay, TenCent and NVIDIA. This work was partly supported by Samsung Advanced Institute of Technology (Next Generation Deep Learning: from pattern recognition to AI) and Samsung Electronics (Improving Deep Learning using Latent Structure). We also thank Jiatao Gu for valuable feedback.
The Journal of Machine Learning Research, 15(1):3563–3593, 2014.
Learning distributed representations of sentences from unlabelled data.In NAACL HLT 2016, The 2016 Conference of the North American Chapter of the Association for Computational Linguistics, pages = 1367–1377, year = 2016,.
In-datacenter performance analysis of a tensor processing unit.In Proceedings of the 44th Annual International Symposium on Computer Architecture, pp. 1–12. ACM, 2017.
Proceedings of the 2013 Conference on Empirical Methods in Natural Language Processing, pp. 1700–1709, 2013.