Most of us are taught to write from left to right (or right to left, depending on the language). For years, Natural Language Processing (NLP) followed this same "dogma": models generated text one token at a time, strictly in a predefined order. But is the first word of a sentence always the best place to start?
In the NeurIPS 2019 paper, "Sequence Modeling with Unconstrained Generation Order," researchers introduce INTRUS (INsertion TRansformer for Unconstrained order Sequence modeling), a model that learns to generate sequences by inserting tokens in whatever order it finds most convenient.
The Problem with Fixed-Order Decoding
The dominant paradigm in sequence generation tasks—such as Machine Translation or Image Captioning—is autoregressive left-to-right decoding. While simple and effective, this approach has two major flaws:
- Reduced Diversity: It forces the model to commit to a specific prefix early on, which can severely limit the variety of valid outputs.
- Structural Mismatch: Different languages have different "branching" structures. Forcing a left-to-right order on a language that naturally builds meaning differently (like Japanese compared to English) can be suboptimal.
Previous attempts to fix this relied on "prior knowledge"—manually instructing the model to start with certain semantic roles. The authors of this paper instead sought a model that could discover the optimal generation order on its own directly from the data.
The INTRUS Architecture
INTRUS moves away from fixed left-to-right generation by allowing the model to insert tokens at any position in a growing sequence. It is built on the standard Transformer architecture but introduces two critical modifications:
- Unmasked Attention: Unlike standard decoders that use a "causal mask" to prevent looking at future tokens, INTRUS allows tokens to attend to all other tokens currently in the partial sequence. This full attention is necessary because new tokens can be inserted anywhere, not just at the end.
- Joint Probability of Token and Position: At each step $t$, the model doesn't just predict what the next word is; it predicts a pair $\tau_t = (pos_t, token_t)$. It calculates the probability of a position first, and then the probability of a token given that position.
Training via Trajectory Sampling
Because there are $|Y|!$ possible ways to build a sequence of length $|Y|$, the authors use a training objective that maximizes a lower bound of the log-likelihood. They sample "correct" trajectories (paths that eventually lead to the target sequence) and encourage the model to concentrate its probability mass on the most "convenient" ones.
Key Insights: The "Easy-First" Hypothesis
One of the most fascinating findings of the paper is that INTRUS naturally learns to generate "easy" words first. It tends to start with punctuation and conjunctions, then moves to nouns and adjectives, and leaves the most difficult elements—verbs and particles—for the end when it has more context.
Crucially, the model isn't told which order is best; the decoding order emerges entirely as a by-product of the training procedure. This flexibility proved particularly effective for English-to-Japanese translation, where right-to-left or arbitrary orders are known to be more effective than standard left-to-right.
Key Results
The model was evaluated on three distinct types of tasks: Machine Translation (WMT14, ASPEC, IWSLT14), Image-to-LaTeX (ImageToLatex-140K), and Image Captioning (MSCOCO).
- Image Captioning: This was the standout result. INTRUS achieved a massive jump of +7.6 BLEU and +25.1 CIDEr points over the left-to-right baseline on the MSCOCO dataset.
- Machine Translation: INTRUS outperformed or matched baselines in almost every language pair. For example, it saw a +2.4 BLEU improvement in English-to-Japanese.
- Image-to-LaTeX: The model improved performance by 0.8 BLEU, showing that flexible ordering helps even in highly structured technical formats.
Limitations and Trade-offs
While INTRUS offers significant quality gains, it comes with computational trade-offs:
- Training Complexity: The training process is significantly slower (3-4 times longer) than standard models because generating insertions for the training objective is inherently sequential and difficult to parallelize on GPUs.
- Local Optima: The model can get stuck in poor local optima during training. The authors mitigated this by using a "pretraining" phase with uniform samples of trajectories before letting the model learn its own preferred order.
- Inference Speed: The theoretical complexity of inference is $O(|Y|^3 k)$, which is higher than the $O(|Y|^2 k)$ of conventional models. While inference is only about 50% slower than a standard Transformer on average-length sentences, the model may struggle with extremely long sequences.
Ultimately, INTRUS demonstrates that freeing sequence models from the strict left-to-right dogma can unlock substantial performance improvements, allowing neural networks to build sentences in the order that makes the most sense to them.
Summary updated