Introduction
In the field of natural language generation, ensuring that models adhere to specific lexical constraints—such as including a set of required keywords—remains a significant challenge. While large-scale Transformer models like T5 excel at producing fluent text, they often fail to incorporate all requested terms, particularly in zero-shot or low-resource settings. This paper, presented at ACL 2021, introduces Mention Flags (MF), an architectural enhancement designed to track and enforce these constraints in real-time during the decoding process.
The Problem: Fluency vs. Constraint Satisfaction
Current approaches to constrained text generation generally fall into two categories:
- Standard Sequence-to-Sequence (S2S) Models: These models are highly fluent but lack internal mechanisms to track which constraints have been satisfied. Consequently, they frequently "forget" to include required words.
- Constrained Decoding Algorithms: Techniques like Constrained Beam Search (CBS) force the inclusion of keywords by manipulating the search space. However, these methods are computationally expensive (often 10–50x slower) and can degrade text quality by overriding the model's natural probability distributions.
The authors propose a "third way": a model that is natively aware of its constraints, maintaining the speed of standard decoding while achieving near-perfect satisfaction.
The Mention Flag Mechanism
The core of the proposed solution is the Mention Flag (MF) mechanism, which maintains a state for every input constraint at each step of generation.
The Flag Matrix and Integration
For every input token and generation step, the model maintains a flag state: 0 for non-constraints, 1 for unsatisfied constraints, and 2 for satisfied constraints. Rather than appending these flags as text, the MF mechanism injects this state directly into the Cross-Attention layers of the Transformer decoder. The flags are treated as relative positions, providing the decoder with specific "key" and "value" embeddings that represent the satisfaction status of each input word. This allows the model to dynamically adjust its attention based on which keywords still need to be generated.
Training Signal
During training, the model is penalized if it generates the "End-of-Sequence" (EOS) token before all flags have transitioned from state 1 to state 2. This effectively teaches the model to continue generating text until all lexical constraints are met.
Evaluation and Key Results
The authors evaluated the MF mechanism across three benchmarks: CommonGen (common-sense reasoning), E2ENLG (data-to-text), and nocaps (novel object captioning).
Near-Perfect Satisfaction and Efficiency
As shown in the results for CommonGen (Figure 4), the addition of Mention Flags (MF) significantly boosts both quality metrics (CIDEr, SPICE) and constraint satisfaction. On the E2ENLG task, the MF-equipped model achieved 100% constraint satisfaction.
Crucially, this performance does not come at the cost of speed. Compared to Grid Beam Search (GBS), the MF approach is 20x to 60x faster. For instance, on the CommonGen test set, GBS required 645 minutes, whereas T5 + MF completed the task in just 10 minutes.
Robustness and Generalization
The MF mechanism decouples the logic of constraint satisfaction from specific word embeddings. This allows the model to handle "novel" constraints—words not seen during training—far more effectively than baseline models. In the nocaps task, MF improved the satisfaction of novel constraints from 16.3% to 49.3% in non-pretrained settings.
Conclusion
Mention Flags represent a significant step forward in controllable text generation. By integrating constraint tracking directly into the Transformer's attention mechanism, the authors provide a solution that is both highly effective and computationally efficient. Future work may extend this logic to handle larger textual units, such as specific sentences or paragraphs in long-form summarization.
Summary updated