Algorithm Search⌘K

Modelresearch

Non-autoregressive translation

Also called NAT, mask-predict.

Generate all target tokens in parallel, or refine them over a few rounds, given a predicted length, trading quality for speed.

A non-autoregressive translation model generates all the target tokens at once instead of one after another. An autoregressive encoder-decoder model conditions each token on all the earlier ones, so it needs as many sequential decoder steps as there are output tokens. A non-autoregressive model first fixes the output length, then predicts every position in parallel, with the tokens independent of each other given the source and the length. Gu et al. (2018) introduced the idea with a transformer and a latent fertility for each source token. Mask-predict (Ghazvininejad et al. 2019) runs a few rounds of parallel prediction, each time masking and predicting again the tokens the model is least sure of. These models trade some translation quality for a large cut in latency, and nearly all of them train on the output of an autoregressive teacher by sequence-level knowledge distillation.

The machine

The input is a source sentence x=x1,…,xIx = x_1, \ldots, x_I, and the output is a target sentence y=y1,…,yJy = y_1, \ldots, y_J over a vocabulary of size VV. Both models below have a transformer encoder with model size dd and a decoder with no causal mask, so every decoder position attends to every other.

Fertility model (Gu et al. 2018). For each source position ii, a softmax on the top encoder state predicts a fertility fi∈{0,1,…,L}f_i \in \{0, 1, \ldots, L\}, the number of target tokens that source token accounts for. The length is J=∑ifiJ = \sum_i f_i. The decoder input is the source embeddings copied by fertility: xix_i is repeated fif_i times. The decoder outputs a distribution over VV at each of the JJ positions. The model is

P(y∣x)=∑f∏i=1IpF(fi∣x)∏j=1Jp(yj∣x,f),J=∑ifi,P(y \mid x) = \sum_{f} \prod_{i=1}^{I} p_F(f_i \mid x) \prod_{j=1}^{J} p(y_j \mid x, f), \qquad J = \sum_i f_i,

with the sum over the fertility sequences ff consistent with the length of yy. In training, the fertilities come from an external word aligner such as fast_align, and the model is trained on the target sentences of an autoregressive teacher.

Conditional masked language model (mask-predict). A special length token in the encoder predicts the length JJ. The decoder gets the target with some positions replaced by a mask symbol, and predicts the masked tokens YmaskY_{\mathrm{mask}} from xx and the observed tokens YobsY_{\mathrm{obs}}:

p(Ymask∣x,Yobs)=∏j∈maskp(yj∣x,Yobs).p(Y_{\mathrm{mask}} \mid x, Y_{\mathrm{obs}}) = \prod_{j \in \mathrm{mask}} p(y_j \mid x, Y_{\mathrm{obs}}).

Training masks a random number of random positions, as in masked language modeling. Decoding with TT iterations:

  1. Predict the length; start with every position masked, and predict all tokens in parallel.
  2. For t=1,…,T−1t = 1, \ldots, T - 1: mask again the n=J(T−t)/Tn = J (T - t) / T tokens with the lowest probability, rounded down, and predict them again from the rest.
  3. Return the result. In practice several length candidates are decoded in parallel, and the output with the best average log probability is kept.

Standing assumptions: a fixed vocabulary, a length chosen before the tokens, and conditional independence of the tokens predicted in the same pass.

What it counts

The fully parallel model assigns ∏jp(yj∣x,J)\prod_j p(y_j \mid x, J) to a target of length JJ, and decoding takes the most probable token at each position independently, which is exact for this product: the argmax of a product of independent factors is the product of the argmaxes (a theorem). The cost of one pass is that of a transformer encoder and decoder: Θ(I2d+Id2)\Theta(I^2 d + I d^2) and Θ(J2d+JId+Jd2)\Theta(J^2 d + J I d + J d^2) per layer, plus Θ(JdV)\Theta(J d V) for the output layer. All of the decoder work is one parallel pass, so the number of sequential decoder steps is 1, or TT for mask-predict, instead of JJ. Gu et al. report an order of magnitude lower latency than their autoregressive teacher (a measurement on their hardware). With noisy parallel decoding, which samples mm fertility sequences, decodes them in parallel and lets the teacher rescore them, the work grows by a factor mm but the latency stays nearly the same.

Relation to other models

  • Autoregressive models. The encoder-decoder model factors P(y∣x)P(y \mid x) by the chain rule, with no independence assumption, and decodes with beam search in JJ sequential steps. The non-autoregressive model drops the dependence on earlier tokens to gain parallel decoding.
  • Masked language models. The conditional masked language model is the training objective of BERT applied to the decoder, conditioned on a source sentence.
  • CTC. Connectionist temporal classification also predicts all output labels in parallel with independent frames, and handles the length with blanks and merging instead of a length predictor. Some later non-autoregressive translation models use a CTC loss.
  • Knowledge distillation. Sequence-level knowledge distillation from an autoregressive teacher is part of the training of nearly every model in this family.
  • Iterative refinement. Mask-predict sits between the two extremes: with T=1T = 1 it is fully parallel, and with T=JT = J and one token per round it predicts one token at a time, though not left to right.

Known results in the model

  • Independence cannot represent correlated outputs. A product distribution over two positions that gives positive probability to "ab" and to "ba" also gives positive probability to "aa" and to "bb" (a theorem: p1(a)p2(a)>0p_1(a) p_2(a) > 0 follows from p1(a)p2(b)>0p_1(a) p_2(b) > 0 and p1(b)p2(a)>0p_1(b) p_2(a) > 0). This is the multimodality problem of Gu et al.: when a source has two good translations, the parallel model mixes them and can output a word from each, or repeat a word.
  • Distillation reduces the problem. The outputs of an autoregressive teacher are more consistent than human references, so the target distribution has fewer modes. Gu et al. measured a substantial gain from distillation as one of the three parts of their training, and later non-autoregressive models keep it (measurements).
  • Quality and speed. Gu et al. report a cost of as little as 2.0 BLEU against their autoregressive teacher and 29.8 BLEU on WMT 2016 English to Romanian with noisy parallel decoding (measurements, from the abstract).
  • Iterative refinement. Mask-predict with a constant number of iterations improved on earlier non-autoregressive and parallel decoders by over 4 BLEU on average, and reached within about 1 BLEU of a typical left-to-right transformer while decoding faster (measurements, from the abstract).
  • Typical errors. Repeated tokens and dropped tokens are the common errors of fully parallel models; they follow from the independence assumption and are measured to fall with more refinement iterations and with distillation.
  • Speed depends on the setting. The gain in latency is largest for one sentence at a time on a parallel device. With large batches an autoregressive model also keeps the device busy, and the advantage is smaller (a measurement that depends on the hardware and the batch size).

References

  1. Jiatao Gu, James Bradbury, Caiming Xiong, Victor O. K. Li and Richard Socher, Non-Autoregressive Neural Machine Translation, ICLR 2018, the fertility model, the multimodality problem, knowledge distillation from an autoregressive teacher, and noisy parallel decoding; the abstract gives the cost of as little as 2.0 BLEU, the order of magnitude lower latency, and 29.8 BLEU on WMT 2016 English to Romanian
  2. Marjan Ghazvininejad, Omer Levy, Yinhan Liu and Luke Zettlemoyer, Mask-Predict - Parallel Decoding of Conditional Masked Language Models, EMNLP-IJCNLP 2019, the conditional masked language model, the length prediction, and mask-predict decoding with a constant number of iterations; the abstract gives over 4 BLEU on average over earlier parallel decoders and about 1 BLEU below a left-to-right transformer

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/T9EF3B/text.yaml