Reverse-Order Decoding for Constrained Text Generation

28 concepts18 papers2 proposals

Standard autoregressive language models generate text from left to right, predicting each token conditioned on the preceding context. This approach aligns naturally with human speech and writing, and it works exceptionally well when the future of the sequence is open-ended.

However, left-to-right generation struggles when a sequence must satisfy a strict terminal constraint—a specific word, rhyme, or structural pattern that must occur at the very end of a line or sentence. To hit a terminal constraint using standard decoding, a model must perfectly anticipate the ending from the very first token. If it makes a sub-optimal choice early on, it can easily drift into a dead end where no grammatically or structurally valid completion can satisfy the required ending.

To solve this planning problem, researchers developed reverse-order decoding. By flipping the generation process to run from right to left, a global terminal constraint is transformed into a local starting condition. The model anchors the sequence on the highly constrained target token first, and then smoothly backfills the preceding context.

Flipping the Search Space

To understand why reverse decoding works, consider the task of writing a rhyming poem. If a model must end a line with the word "sky" to match a previous line, a left-to-right decoder must search through millions of possible sentence paths, hoping that one happens to land precisely on "sky" while maintaining proper meter and grammar.

As Van de Cruys notes, right-to-left text generation completely avoids the computational difficulty of forcing valid endings onto pre-existing sentence fragments. Instead, the model selects the constrained word first and constructs a grammatically valid preceding sequence.

Standard Left-to-Right (High Risk of Dead Ends):
[The] -> [birds] -> [fly] -> [in] -> [the] -> [???] (Must rhyme with "high")

Reverse-Order Right-to-Left (Deterministic Constraint Satisfaction):
[sky] <- [the] <- [in] <- [fly] <- [birds] <- [The]

Early work on poetry generation by Ghazvininejad et al. demonstrated that starting from a fixed terminal word prevents the generation process from reaching states where no valid completion exists. By establishing the core structural or semantic anchor first, the search space and uncertainty for all remaining tokens in the sequence are drastically reduced (Yi et al.; Xie et al.). As Li et al. frame it, reverse language modeling effectively addresses end-rhyme constraints by transforming a global structural requirement into a local starting condition.

Applications in Creative and Form-Constrained Text

The primary proving ground for reverse-order generation has been creative text synthesis, where rigid formal constraints like rhyme schemes and meter are paramount.

  • Poetry and Sonnets: Models like Deep-speare (Lau et al.) utilize reverse sequence generation to ensure that linguistic context and structural poetic requirements are met simultaneously. In the hierarchical framework Zest, Peng et al. show that working backward from a rhyme word avoids the awkward phrasing typically caused by trying to force a rhyme at the end of a pre-written sentence. This technique has also been successfully applied to historical styles, such as generating 17th-century French theatrical dialogue that respects strict classical verse (Grosjean et al.).
  • Rap and Song Lyrics: Writing lyrics requires modeling complex phonetic patterns alongside semantic meaning. DeepRapper (Xue et al.) generates lyrics in reverse order to prioritize highly constrained $N$-gram rhymes at the end of lines, ensuring the preceding text remains semantically consistent with the pre-determined rhyme anchor. For translation tasks, Ou demonstrated that decoding a sequence from end to beginning allows a model to satisfy suffix-based musical constraints without compromising the semantic integrity of the source text.

While fully reverse models are common, hybrid approaches also exist. For example, the Youling system (Zhang et al.) modifies the decoding process to generate the terminal rhyme character first, but then completes the rest of the sequence from left to right, blending the anchoring benefits of reverse generation with standard forward context.

Beyond Poetry: Arithmetic and Central Constraints

The intuition that sequence generation should match the direction of the underlying constraint extends beyond creative writing into mathematics and lexical control.

Multi-Digit Arithmetic

Standard language models frequently struggle with multi-digit calculation because standard left-to-right generation forces them to output the most significant digits first (e.g., writing the thousands place before the ones place). However, standard mathematical algorithms operate in reverse—processing from the least significant digit to the most significant digit to handle arithmetic carries.

To bridge this gap, Kim et al. showed that generating numerical outputs in reverse order aligns the sequence-to-sequence generation process with standard mathematical operations, leading to significantly more accurate multi-digit calculations.

Central and Inward Constraints

Sometimes a constraint does not appear at the very end of a sequence, but rather in the middle. In these cases, the intuition of reverse generation is expanded into bidirectional or "inside-out" generation.

For instance, to guarantee that specific brand names or keywords appear in headlines, Yamada et al. initialized text generation from a fixed central phrase and expanded the sequence both backward and forward. Similarly, for unsupervised metaphor generation, Wan et al. used an asynchronous bidirectional generation process to construct sentences outward from a central anchor word. This allowed the model to tightly constrain the part-of-speech and grammatical role of the metaphor while maintaining global sentence fluency.

Trade-offs of Backward Generation

Despite its mathematical and structural advantages for constrained tasks, reverse decoding introduces unique linguistic challenges.

The most notable drawback is the emergence of local grammatical errors. As Ghazvininejad et al. observed, right-to-left decoding can cause mistakes in forward-looking linguistic dependencies, such as article selection (e.g., accidentally generating "a" instead of "an"). Because the model is moving backward, it must choose the article before the phonetic properties of the preceding word are determined.

Additionally, when applying reverse generation to continuous domains like speech synthesis, researchers must account for how context accumulates. In synthesizing pitch contours for prosody, Bryan et al. found that reversing the generation order can stabilize recurrent networks dealing with user-defined constraints, but requires careful handling to ensure the model accumulates enough context to produce smooth transitions between fixed anchors and generated segments.

Key Foundational Work

Generating Topical Poetry (2016) — contributed 3 concept elements to this direction.
Generating Chinese Classical Poems with RNN Encoder-Decoder (2016) — contributed 2 concept elements to this direction.
Deep-speare: A joint neural model of poetic language, meter and rhyme (2018) — contributed 1 concept elements to this direction.
History & citationVersion 1 · 2026-10-04

Current · Permanent link

View frozen version 1

Cite this direction

Latest version (a living page):

@misc{lacuna_reverse_sequence_generation_e6b56f8b,
  title = {reverse sequence generation},
  author = {{Lacuna}},
  howpublished = {Lacuna research direction},
  year = {2026},
  url = {https://lacuna.tiptreesystems.com/direction/reverse-sequence-generation/rdr_e6b56f8b17684a008c185ac6c244c0fa},
  note = {Latest version of a living research direction; cite a version for a fixed text. Accessed 2026-11-21},
}

This exact version (version 1, frozen text):

@misc{lacuna_reverse_sequence_generation_e6b56f8b_v1,
  title = {reverse sequence generation},
  author = {{Lacuna}},
  howpublished = {Lacuna research direction},
  year = {2026},
  url = {https://lacuna.tiptreesystems.com/direction/reverse-sequence-generation/rdr_e6b56f8b17684a008c185ac6c244c0fa/v/1},
  note = {Version 1, frozen 2026-10-04. Accessed 2026-11-21},
}
About

These directions overlap with this one through shared papers.

See something wrong? Report a mistake