Constraint Satisfaction Driven Natural Language Generation: A Tree Search Embedded MCMC Approach

Maosen Zhang, Nan Jiang, Lei Li, Yexiang Xue

Abstract

Generating text that follows strict logical or grammatical constraints usually requires massive, task-specific datasets and expensive fine-tuning. This paper introduces TSMH (Tree Search Enhanced Metropolis-Hastings), a framework that treats language generation as a constraint satisfaction problem. By embedding a tree search into the proposal process of a Markov chain Monte Carlo (MCMC) sampler, the authors enable the model to "jump" between high-quality sentences that satisfy complex requirements without any task-specific training.

What Problem Does This Paper Address?

Modern Natural Language Generation (NLG) is dominated by supervised learning, which relies on feeding models millions of paired examples. This approach suffers from high data requirements and a lack of explicit control over output constraints.

Previous attempts to solve this using unsupervised MCMC sampling, such as the CGMH algorithm, struggled with the "low acceptance barrier." These models typically modify only one word at a time. If a model attempts to transform a sentence like "Paris is in France" into a question, the intermediate ungrammatical steps (e.g., "Paris is in") are assigned near-zero probability by the underlying language model. This causes the MCMC chain to reject the move, leaving the sampler "stuck" in local optima.

Comparison of supervised NLG vs. constraint satisfaction and the probability landscape of sentence edits.

Methods

The authors propose TSMH, which combines the probabilistic rigor of MCMC with the look-ahead power of tree search to bypass these low-probability valleys.

  • Constraint Specification: Users define Hard Constraints (e.g., propositional logic for sentence structure) and Soft Constraints (e.g., sentiment or semantic similarity scores).
  • Tree Search Proposals: Instead of local word edits, TSMH selects multiple positions and performs a tree search to enumerate possible sentence "templates" (skeletons with word categories).
  • Template Ranking & Filling: Templates are ranked by constraint satisfaction. A high-ranking template is sampled, and a pre-trained language model (like BERT) fills in the blanks.
  • Metropolis-Hastings Step: The proposed sentence is accepted or rejected based on a probability that balances fluency (LM score) and constraint satisfaction.
Comparison between standard CGMH and the proposed Tree Search Enhanced MCMC.

This "look-ahead" mechanism allows the model to propose non-local moves, jumping directly to valid, high-probability states. Because it uses a general-purpose language model and logical rules, it requires zero task-specific training.

Key Insights and Results

The core innovation of TSMH is the realization that MCMC's failure in text generation is primarily a search problem. By breaking the locality of edits, the model can reason about rules rather than just learning from examples.

Performance Highlights

The authors evaluated TSMH on tasks like interrogative generation (SQuAD 2.0) and sentiment transformation (Yelp). Key results include:

  • Constraint Satisfaction: In interrogative tasks, TSMH achieved a 92.67% success rate, vastly outperforming the CGMH baseline's 18.33%.
  • Efficiency: The MCMC acceptance rate for TSMH was 24.5%, nearly five times higher than the baseline (5.45%), indicating a much more effective traversal of the search space.
  • Human Preference: In blind tests, human evaluators preferred TSMH-generated text by a 2-to-1 ratio over baselines in terms of fluency and grammar.

Limitations and Future Work

While TSMH offers significant flexibility and zero-shot capabilities, it introduces higher computational overhead due to the tree search and multiple BERT queries per step. Future work may involve moving to first-order logic for more complex relational constraints and optimizing the search process to reduce latency.

Summary updated

BibTeX
@inproceedings{zhang2020constraint,
  author = {Maosen Zhang and Nan Jiang and Lei Li and Yexiang Xue},
  title = {{Constraint Satisfaction Driven Natural Language Generation: A Tree Search Embedded MCMC Approach}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2020},
  doi = {10.18653/v1/2020.findings-emnlp.115},
}
Figure