Constant-Time Machine Translation with Conditional Masked Language Models

Marjan Ghazvininejad, Omer Levy, Yinhan Liu, Luke ZettlemoyerarXiv 2019

Introduction

The current state-of-the-art in machine translation is dominated by autoregressive models, most notably the Transformer. These models generate output sequences token-by-token from left to right. While effective, this sequential nature imposes an $O(N)$ time complexity, where $N$ is the sequence length. This creates a significant computational bottleneck, especially as hardware becomes increasingly parallel.

Non-autoregressive translation (NAT) models have been proposed to generate all tokens simultaneously. However, they frequently struggle with the multi-modality problem. Because tokens are predicted independently, the model may fail to coordinate between different valid translation paths, leading to ungrammatical repetitions (e.g., "The cat cat is on the mat"). This paper presents Mask-Predict, a novel decoding algorithm that leverages Conditional Masked Language Models (CMLMs) to bridge the gap between the speed of parallel generation and the coherence of sequential models.

Methodology

The Mask-Predict framework introduces a bidirectional approach to decoding through two primary components.

Conditional Masked Language Models (CMLMs)

Standard Transformer decoders are causal, meaning they can only attend to previously generated tokens. In contrast, a CMLM decoder is bidirectional. During training, it is tasked with predicting a random subset of masked target tokens by attending to both the source sentence and the surrounding unmasked target tokens. This architecture is reminiscent of BERT but is conditioned on a source sequence, allowing it to learn complex dependencies across the entire target sequence.

The Mask-Predict Algorithm

At inference time, the target sequence is unknown. The Mask-Predict algorithm operates over a constant number of iterations $T$, independent of the sequence length $N$.

  1. Initialization: The model first predicts the target sequence length $N$ using a dedicated LENGTH token at the encoder. It then initializes a sequence of $N$ MASK tokens.
  2. Parallel Prediction: In each iteration, the model predicts all currently masked tokens in parallel, conditioned on the source and the unmasked tokens from the previous step.
  3. Iterative Re-masking: The algorithm identifies the $n$ tokens with the lowest probability scores (confidence) and replaces them with MASK for the next round. The number of masked tokens $n$ decreases linearly over the $T$ iterations.
Iterative refinement example: The model refines its translation over multiple steps, correcting errors and resolving ambiguities.

By conditioning on high-confidence "anchor" words from previous iterations, the model effectively "collapses" the multi-modal distribution, allowing it to fix its own mistakes using bidirectional context.

Evaluation and Results

The authors evaluated Mask-Predict on three major benchmarks: WMT’14 English-German (EN-DE), WMT’16 English-Romanian (EN-RO), and WMT’17 English-Chinese (EN-ZH). To optimize performance, the CMLMs were trained using sequence-level knowledge distillation from a standard Transformer teacher model.

Performance vs. Speed

Mask-Predict achieves a remarkable balance between translation quality and decoding efficiency. With $T=10$ iterations, the model reaches within 0.5–1.2 BLEU points of a well-tuned autoregressive Transformer base model.

Relative decoding speed-up versus translation performance (BLEU). Mask-Predict (blue circles) offers a superior trade-off compared to traditional L2R models.

As illustrated in Figure 1, Mask-Predict provides up to a 3x speedup in wall-clock time compared to a standard Transformer using beam search ($b=5$). Even with fewer iterations (e.g., $T=4$), the model maintains high quality while significantly outperforming previous non-autoregressive approaches by approximately 4 BLEU points on average.

Reducing Repetitions

A key success of the iterative approach is the drastic reduction in token repetitions. Qualitative analysis reveals that repetitions drop from roughly 16% in a single-pass ($T=1$) model to less than 1% after just five iterations. This confirms that bidirectional context is highly effective at resolving the independence issues inherent in parallel decoding.

Discussion and Limitations

While Mask-Predict represents a significant leap forward, several challenges remain. The model's performance is sensitive to the initial length prediction; if the predicted $N$ is incorrect, the final translation quality suffers. The authors mitigated this by decoding multiple length candidates in parallel, though this increases computational cost.

Furthermore, like most NAT models, CMLMs rely heavily on knowledge distillation. When trained on raw, noisy data without a teacher model, performance degrades significantly. There also remains a small "independence penalty"—a slight gap in quality compared to the absolute best autoregressive systems—suggesting that while bidirectional context helps, it does not perfectly replicate the global coordination of sequential generation.

Conclusion

Mask-Predict demonstrates that constant-time machine translation is not only possible but can compete with state-of-the-art sequential models. By treating decoding as an iterative refinement process within a bidirectional framework, the authors have provided a scalable solution to the sequential bottleneck in modern NLP pipelines.

Summary updated

BibTeX
@misc{ghazvininejad2019constant,
  author = {Marjan Ghazvininejad and Omer Levy and Yinhan Liu and Luke Zettlemoyer},
  title = {{Constant-Time Machine Translation with Conditional Masked Language Models}},
  year = {2019},
  eprint = {1904.09324},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1904.09324},
}
Figure