TRACE Back from the Future: A Probabilistic Reasoning Approach to Controllable Language Generation

Gwen Yidou Weng, Benjie Wang, Guy Van den Broeck

Introduction

Large Language Models (LLMs) are fundamentally autoregressive, predicting the next token based solely on the preceding context. This "greedy" generation process makes it difficult to enforce global attributes—such as toxicity, sentiment, or a specific persona—because the model cannot easily foresee if a currently "safe" token will lead to an "unsafe" or undesirable conclusion.

Existing solutions typically fall into two categories:

  1. Fine-tuning/Alignment (e.g., RLHF, DPO): These methods are computationally expensive, require massive datasets, and risk "mode collapse," where the model loses its original fluency or diversity.
  2. Decoding-time Interventions: Methods like FUDGE or sampling-based lookahead attempt to steer the model during generation. However, these are often either prohibitively slow (requiring thousands of samples) or unreliable (relying on heuristic discriminators).

The core challenge lies in efficiently computing the Expected Attribute Probability (EAP): the probability that a partial sentence will eventually satisfy a desired attribute.

The TRACE Framework

The authors introduce TRACE (Tractable Probabilistic Reasoning for Adaptable Controllable gEneration), a framework that treats controllable generation as a probabilistic reasoning task.

HMM Distillation and Exact Inference

Instead of performing lookahead on the massive, intractable LLM, TRACE distills the LLM’s distribution into a Hidden Markov Model (HMM). While simpler than a Transformer, HMMs are "tractable," allowing classical algorithms like the Forward-Backward algorithm to compute sums over all possible future sequences in linear time.

Overview of the TRACE decoding process, illustrating how the Expected Attribute Probability (EAP) from a distilled HMM guides the language model toward non-toxic continuations.

By pairing the HMM with a lightweight log-linear classifier that assigns weights to individual tokens, the EAP can be computed exactly and efficiently over the HMM’s state space. During decoding, the LLM’s next-token probabilities are reweighted by the EAP. If a token makes it highly unlikely to satisfy the attribute in the future, its probability is significantly reduced.

Probability Transformations

TRACE employs affine transformations in logit space during both training and decoding. This "sharpens" the control, allowing users to tune a "control knob" to trade off between strict attribute adherence and text fluency.

Experimental Evaluation

The researchers evaluated TRACE across several challenging domains:

  • RealToxicityPrompts: A standard benchmark for measuring toxicity in model outputs.
  • RoleBench: A dataset containing ~300 question-answer pairs for 76 distinct characters, used to test low-resource personalization.
  • News Category Dataset: Used for training "political relevance" classifiers for compositional tasks.

Key Results and Insights

TRACE achieves state-of-the-art results while maintaining extreme efficiency.

  • State-of-the-Art Detoxification: TRACE outperformed PPO and DPO on GPT-2 and Gemma-2B, achieving lower toxicity while maintaining higher text diversity.
  • Efficiency: TRACE adds only ~1.2x overhead to standard decoding, compared to sampling-based lookahead methods which can be 15x to 40x slower.
  • Rapid Adaptation: TRACE can personalize models for new characters in approximately 10 seconds, outperforming prompt-engineering baselines even with limited training data.
The tradeoff between maximum toxicity and mean fluency in TRACE, demonstrating controllable generation across different parameter settings.

The "aha moment" of TRACE is the realization that the LLM itself doesn't need to predict the future. A "good enough" distilled HMM provides a sufficiently accurate map of potential continuations to guide the more powerful LLM. Furthermore, because the system is probabilistic, multiple attributes can be combined simply by multiplying their respective EAPs during decoding.

Limitations and Future Work

The effectiveness of TRACE is bounded by the quality of the HMM distillation. If the HMM is too small to capture the nuances of the base LLM, the guidance will be poor. Additionally, the current classifier assumes attributes can be decomposed into token-level weights, which might struggle with complex structural constraints like rhyming patterns. Future work may explore more expressive tractable models, such as Probabilistic Circuits, to handle more sophisticated long-range dependencies.

Summary updated

BibTeX
@inproceedings{weng2025trace,
  author = {Gwen Yidou Weng and Benjie Wang and Guy Van den Broeck},
  title = {{TRACE Back from the Future: A Probabilistic Reasoning Approach to Controllable Language Generation}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=LhkSfpfRXW},
}
Figure