Insertion-based Decoding with automatically Inferred Generation Order

Jiatao Gu, Qi Liu, Kyunghyun Cho

Abstract

Traditional autoregressive models generate sequences in a strict left-to-right fashion. This paper introduces InDIGO (Insertion-based Decoding with Inferred Generation Order), a framework that treats generation order as a latent variable. By utilizing a relative-position-based Transformer, InDIGO learns to generate sequences by inserting tokens at arbitrary positions. This approach allows the model to discover optimal generation paths, leading to significant improvements in structured tasks like code generation and word order recovery while maintaining competitive performance and speed in machine translation.

Introduction: Beyond Left-to-Right Dogma

Most modern sequence generation models, such as GPT, are constrained by a left-to-right (L2R) autoregressive bottleneck. While effective for natural language, this rigid order is often sub-optimal for structured data or languages with significantly different syntactic structures. Humans do not always write linearly; we often start with a core concept and expand outwards or fill in details later.

The InDIGO decoding process allows for non-linear sequence construction through flexible insertions.

The authors propose InDIGO to break this dogma. Instead of a fixed order, the model learns the most efficient way to "build" a sentence through a series of insertions. This flexibility is particularly beneficial for tasks like programming (code generation) where the logical structure may not align with a simple linear scan.

Methodology: The InDIGO Framework

The core of InDIGO is a modified Transformer architecture designed to handle dynamic insertions without the need for costly re-encoding of absolute positions.

Relative Position Representations

Standard Transformers rely on absolute position embeddings. If a word is inserted in the middle of a sequence, the absolute indices of all subsequent words shift, requiring a full re-computation. InDIGO solves this by using a ternary relative position matrix $R$, where $r_{i,j} \in \{-1, 0, 1\}$ indicates whether token $i$ is to the left of, at the same position as, or to the right of token $j$. This representation is "append-only"; adding a new token only requires calculating its relationship to existing tokens, preserving previous computations.

InDIGO architecture overview: (a) joint word and position prediction, (b) Transformer-Decoder with relative position updates, and (c) final sorting for output.

Joint Prediction and Adaptive Ordering

At each decoding step $t$, the model performs two simultaneous predictions:

  1. Word Prediction: Selecting the next token $y_t$ from the vocabulary.
  2. Position Prediction: Determining where to insert $y_t$ relative to the existing sequence using a pointer-network-style mechanism.

To train the model without a ground-truth generation order, the authors employ Searched Adaptive Order (SAO). During training, the model uses beam search to find the most probable generation path for a target sentence and then optimizes its parameters to follow that inferred order.

Experimental Evaluation

InDIGO was evaluated across diverse benchmarks:

  • Word Order Recovery: Reconstructing sentences from a "bag of words." InDIGO with SAO outperformed L2R baselines by up to 3 BLEU points.
  • Code Generation (Django): Mapping natural language to Python code. InDIGO achieved 16.3% accuracy, significantly higher than the 13.6% of the L2R baseline, highlighting its strength in structured tasks.
  • Machine Translation: Tested on WMT16 (Ro-En), WMT18 (En-Tr), and KFTT (En-Ja). InDIGO remained competitive with standard Transformers, showing particular gains in language pairs with divergent word orders.

Insights and Limitations

A key finding is that InDIGO tends to generate "chunks" of words in a local L2R order but shuffles the global order of these chunks. This suggests the model learns a hierarchical or structural approach to generation. Furthermore, despite the added complexity of position prediction, InDIGO's decoding speed (12.8 ms/sentence) is nearly identical to standard Transformers (12.3 ms/sentence) due to its efficient relative position mechanism.

However, the primary trade-off is training time. The SAO process, which requires beam search during training, makes InDIGO 3.8x to 7.2x slower to train than standard models. Future work may involve more efficient latent variable inference to mitigate this overhead.

Conclusion

InDIGO demonstrates that fixed generation orders are not a requirement for high-performing neural sequence models. By allowing the model to infer its own generation path, InDIGO achieves superior results in structured domains and provides a more flexible foundation for complex generation tasks.

Summary updated

BibTeX
@article{gu2019insertion,
  author = {Jiatao Gu and Qi Liu and Kyunghyun Cho},
  title = {{Insertion-based Decoding with automatically Inferred Generation Order}},
  journal = {Trans. Assoc. Comput. Linguistics},
  year = {2019},
  doi = {10.1162/tacl\_a\_00292},
}
Figure