Lexically Constrained Decoding for Sequence Generation Using Grid Beam Search

Chris Hokamp, Qun Liu

Introduction

Neural Machine Translation (NMT) and other sequence generation models are often treated as "black boxes" once trained. At inference time, if a human translator knows a specific technical term must be used, or if a user wants to correct a mistake in a generated caption, there is traditionally no easy way to "steer" the model. Standard beam search—the algorithm used to find the most likely sentence—simply follows the model's probability distribution. If the model didn't see a specific term often during training, it likely won't generate it, even if a human explicitly asks for it. Previous attempts to fix this often required retraining the model or relied on complex alignment models. This paper introduces Grid Beam Search (GBS), a general, model-agnostic way to enforce lexical constraints on the fly.

Grid Beam Search Methodology

The core innovation of GBS is the expansion of the search space into a two-dimensional grid. In standard beam search, the algorithm tracks the $k$-best hypotheses at each timestep $t$. GBS adds a second dimension: the number of constraint tokens covered ($c$).

The 2D search space of GBS, mapping time against constraint coverage.

As illustrated in the grid above, beams are indexed by $(t, c)$. A hypothesis in beam $(5, 2)$ has generated 5 total tokens, 2 of which satisfy parts of the required constraints. The algorithm manages different hypothesis types:

  • Open: These can either generate a "normal" word from the model's distribution or "start" a new constraint.
  • Closed: These are currently in the middle of a multi-word constraint and must generate the next specific token in that phrase to remain valid.
Illustration of Grid Beam Search (GBS) enforcing lexical constraints during decoding.

Crucially, GBS utilizes subword units (like Byte Pair Encoding). This allows the system to handle constraints that contain words the model never saw during training by breaking them down into known characters or fragments. The algorithm ultimately seeks the highest-scoring finished sequence in the "top row" of the grid—the row where all required constraints have been satisfied.

Experimental Evaluation

The authors evaluated GBS on three language pairs: English-German (EN-DE), English-French (EN-FR), and English-Portuguese (EN-PT). Training was conducted on standard large-scale corpora like Europarl and CommonCrawl. Evaluation focused on two scenarios:

  1. Interactive Translation: Using WMT test sets to simulate a "Pick-Revise" scenario where a user provides a 1-3 word correction.
  2. Domain Adaptation: Using the Autodesk Post-Editing Corpus (IT/Software) to test the inclusion of domain-specific terminology without fine-tuning.

Key Results and Insights

GBS demonstrated significant improvements in translation quality. In the simulated interactive scenario, translation quality improved by over 20 BLEU points across four interaction cycles. For domain adaptation on the Autodesk dataset, GBS provided substantial gains over the baseline:

  • EN-DE: +1.82 BLEU
  • EN-FR: +2.59 BLEU
  • EN-PT: A massive +13.73 BLEU improvement.

A striking finding is the global influence of constraints. Adding a constraint doesn't just fix one word; it often "corrects" the surrounding context as the model seeks the overall most probable sequence containing that term. Furthermore, GBS is highly flexible, supporting single words, multi-word phrases, or even discontinuous phrases (e.g., "pick ... up") without requiring explicit alignment to the source text.

Limitations and Future Work

The primary limitation of GBS is its computational complexity, which is $O(ktc)$, where $c$ is the number of constraint tokens. While parallelizable, it is inherently slower than unconstrained decoding. Additionally, GBS still relies on the underlying model's scores; if a constraint is extremely unlikely, the model might produce awkward phrasing elsewhere to compensate. Future directions include applying GBS to tasks like image captioning or abstractive summarization, and exploring secondary attention mechanisms to integrate constraints more naturally.

Conclusion

Grid Beam Search provides a robust framework for lexically constrained decoding. By organizing the search space into a 2D grid, it ensures that pre-specified constraints are met without requiring changes to the underlying neural network's parameters or training data, enabling effective human-in-the-loop translation and zero-shot domain adaptation.

Summary updated

BibTeX
@inproceedings{hokamp2017lexically,
  author = {Chris Hokamp and Qun Liu},
  title = {{Lexically Constrained Decoding for Sequence Generation Using Grid Beam Search}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2017},
  doi = {10.18653/v1/p17-1141},
}
Figure