Autoregressive Large Language Models (LLMs) like GPT-2 and GPT-3 have revolutionized text generation with their remarkable fluency. However, they consistently struggle with "hard" lexical constraints—for example, generating a sentence that must include a specific set of words like winter, snow, and skiing.
The root of this problem is mathematical intractability. To perfectly satisfy a constraint, a model must compute the probability of the entire future sentence given that constraint ($\Pr(\text{text} | \alpha)$). For standard transformer architectures, calculating this at inference time is computationally impossible. Existing workarounds typically rely on slow brute-force search algorithms or require training auxiliary neural "guide" models from scratch for every new type of constraint.
To solve this, researchers have introduced GeLaTo (Generating Language with Tractable Constraints), a novel framework that bridges the fluency of LLMs with the mathematical rigor of Tractable Probabilistic Models (TPMs).
The GeLaTo Framework
GeLaTo guarantees constraint satisfaction without sacrificing the natural flow of autoregressive generation. It achieves this through a clever combination of model distillation and dynamic programming:
- Distillation into HMMs: Instead of forcing the LLM to calculate intractable probabilities, the researchers distill the LLM into a massive Hidden Markov Model (HMM) featuring 4,096 latent states. This TPM is trained to mimic the probability distribution of a fine-tuned GPT-2 model.
- Tractable Inference and Look-Ahead: Unlike transformers, HMMs allow for efficient "look-ahead." GeLaTo utilizes a dynamic programming algorithm to calculate exactly how likely a constraint is to be satisfied given the current text prefix.
- Token-Level Guidance: During generation, GeLaTo merges the LLM’s next-token distribution with the TPM’s guidance. If selecting a specific next token makes it mathematically impossible to satisfy the user's constraints later in the sentence, the TPM effectively "zeros out" that token's probability.
- Logical Constraints via CNF: Constraints are formatted as Conjunctive Normal Forms (CNFs). This logical structuring allows the model to handle complex "either/or" scenarios and word inflections (e.g., satisfying the constraint "run" with "ran" or "running").
Experimental Setup and Key Findings
The researchers evaluated GeLaTo across three primary benchmarks for constrained text generation: CommonGen (requiring the use of 3–5 unordered concepts in a coherent sentence), Yelp!Review (ordered keyword insertion), and News (ordered keyword insertion in a journalistic context).
GeLaTo demonstrated significant improvements over strong baselines like NeuroLogic and NADO:
- Guaranteed Satisfaction: Because the TPM calculates the exact probability of future success, GeLaTo provides a mathematical guarantee—a 100% success rate on CommonGen. By contrast, baseline models typically hovered between 88% and 97%.
- State-of-the-Art Fluency: On the unsupervised split of CommonGen, GeLaTo achieved a 30.3 BLEU score, crushing the previous best baseline of 26.2. Furthermore, the authors noted a strong positive correlation: the better the TPM approximates the base LLM, the higher the fluency of the resulting text.
- Unconditional Training: Unlike previous methods (such as NADO or FUDGE) that require training a guide model on specific constraint types, GeLaTo’s TPM is trained unconditionally on the LLM's distribution. A single trained GeLaTo model can handle any number or type of keywords at test time without retraining.
- Efficiency: In unsupervised settings, GeLaTo proved to be orders of magnitude faster than search-based methods like NeuroLogic A*esque, which are bogged down by massive search spaces.
Limitations and Future Directions
While GeLaTo represents a major leap forward in controlled text generation, it does have limitations. HMMs are inherently Markovian (memoryless), meaning they only consider the immediate previous state. While sufficient for lexical constraints, this architecture may struggle with constraints requiring long-range semantic consistency beyond what the base LLM provides.
Additionally, the computational complexity of the guidance algorithm scales with the number of clauses in the constraint. While it handles standard lists of 3–5 keywords effortlessly, extremely long constraint lists could slow down generation.
Ultimately, GeLaTo proves that "old school" models like HMMs can effectively guide modern Transformers. Future work will likely explore moving beyond HMMs to more expressive TPMs, such as advanced Probabilistic Circuits, to further enhance the fluency and intelligence of constrained language generation.
Summary updated