Controlled Text Generation with Natural Language Instructions

Wangchunshu Zhou, Yuchen Eleanor Jiang, Ethan Wilcox, Ryan Cotterell, Mrinmaya Sachan

Based on the paper "Controlled Text Generation with Natural Language Instructions" by Zhou et al. (ICML 2023).

TL;DR

InstructCTG is a framework that treats controlled text generation (CTG) as an instruction-following task rather than a decoding-time optimization problem. By fine-tuning models on a massive corpus of "reverse-engineered" instructions, the authors achieve high constraint satisfaction and superior text quality while operating significantly faster than traditional constrained decoding methods.

The Challenge of Controlled Text Generation

While Large Language Models (LLMs) are incredibly fluent, getting them to obey specific, rigid constraints—like "don't use the word 'message'," "write in a polite tone," or "ensure the output is exactly 12 words"—is notoriously difficult.

The traditional dominant paradigm involves modifying the decoding algorithm (e.g., constrained beam search). However, this approach has three major flaws:

  1. Quality Loss: Forcing a model to pick specific tokens often breaks its natural probability distribution, leading to "robotic" or lower-quality text.
  2. Speed: These methods are computationally expensive and slow down generation significantly.
  3. Inflexibility: Adding a new type of constraint often requires designing a new classifier or a bespoke feature from scratch.

The InstructCTG Method

The authors propose InstructCTG, which shifts the burden of control from the decoding phase to the training phase.

InstructCTG Framework

The process follows three main steps:

  1. Weakly Supervised Data Synthesis: Instead of hiring humans to write constrained text, the authors take a massive unlabeled corpus (C4) and use off-the-shelf NLP tools (like POS taggers and sentiment classifiers) to identify which constraints existing sentences already satisfy.
  2. Constraint Verbalization: These identified constraints are turned into natural language instructions using diverse templates (e.g., "Write something with positive sentiment").
  3. Instruction Tuning: They fine-tune a T0-11B model on these pairs. Crucially, they use Meta In-context Learning, where 50% of the training examples include a few demonstrations of the constraint being followed. This teaches the model to generalize to entirely new constraints at test time simply by reading a description and a few examples.

To handle complex requirements, they use Composition of Constraints, conjoining multiple instructions with "and" (e.g., "Write a sentence with keywords [A, B] AND a polite tone AND exactly 10 words").

Key Insights

  • The "Latent Prompt" Hypothesis: The core insight is the realization that any natural sentence can be viewed as if it were generated under the influence of latent constraints. By uncovering these constraints post-hoc, we can create a virtually infinite supply of training data for instruction following.
  • Training-time vs. Decoding-time: By teaching the model the relationship between instructions and output during training, the model maintains its internal fluency. It doesn't need to be "steered" at every step of decoding, preserving the natural flow of language.
  • Zero-Shot Generalization: Because the model learns to follow natural language descriptions, it can handle constraints it never saw during training just by describing them in the prompt.

Key Results

  • Efficiency: InstructCTG is 4x faster than NeuroLogic decoding and over 40x faster than Diffusion-LM. Because it uses standard beam search, there is virtually no overhead.
  • Fluency: Across all tests, InstructCTG produced text with significantly better fluency (lower perplexity) than decoding-time baselines.
  • Constraint Satisfaction: It achieved comparable or superior success rates to state-of-the-art methods. For example, on length constraints, it achieved nearly 100% accuracy.
  • Compositionality: The model proved highly robust when asked to satisfy multiple constraints simultaneously.
Performance vs. Number of Constraints

As shown above, when scaling from 2 to 5 simultaneous constraints, InstructCTG's performance degrades much more gracefully compared to baselines like COLD and Diffusion-LM.

Limitations and Future Work

  • Backbone Dependency: The study primarily used T0-11B. Testing on even larger or more diverse backbone architectures would provide a better picture of the framework's scaling laws.
  • Constraint Variety: The experiments focused on five main categories (lexical, syntax, semantic, style, length). Future work could explore more abstract constraints, such as logical consistency or specific rhetorical structures.
  • Safety Concerns: Like all controlled generation, there is a risk that malicious users could provide instructions to generate toxic or biased content, requiring ongoing safety research.

Summary updated

BibTeX
@inproceedings{zhou2023controlled,
  author = {Wangchunshu Zhou and Yuchen Eleanor Jiang and Ethan Wilcox and Ryan Cotterell and Mrinmaya Sachan},
  title = {{Controlled Text Generation with Natural Language Instructions}},
  booktitle = {International Conference on Machine Learning},
  year = {2023},
  url = {https://openreview.net/forum?id=DBlKltQIO0},
}
Figure