Controlled Text Generation for Large Language Model with Dynamic Attribute Graphs

Xun Liang, Hanyu Wang, Shichao Song, Mengting Hu, Xunzhi Wang, Zhiyu Li, Feiyu Xiong, Bo Tang

Introduction

Large Language Models (LLMs) have demonstrated remarkable generative capabilities, yet controlling specific attributes of their output—such as sentiment, toxicity, or style—remains a significant challenge. Traditional Controlled Text Generation (CTG) methods often rely on external "guide" models to influence token selection. However, this frequently results in the "puppet problem," where the guide model's influence overrides the LLM's inherent reasoning, leading to repetitive, unnatural, or incoherent text.

The DATG Framework

To address these limitations, researchers proposed Dynamic Attribute Graphs (DATG), a pluggable, training-free framework designed to steer LLMs while preserving their natural fluency. DATG operates through a four-stage pipeline that identifies and leverages high-impact "anchor words" to guide the generation process.

The four-stage DATG workflow: Contextual Corpus Construction, Attribute Classifier Scoring, Dynamic Attribute Graph Construction, and ReGeneration with Dynamic Boundary Controlling.

The process begins with Contextual Corpus Construction, where the base LLM generates a set of candidate sentences. These candidates are then evaluated by an Attribute Classifier to determine their alignment with the target trait (e.g., toxicity or sentiment). In the third stage, Dynamic Attribute Graph Construction, these sentences are transformed into directed graphs. By weighting edges based on classifier scores, the system identifies specific word sequences that strongly correlate with positive or negative attributes. Finally, the ReGeneration phase uses these graphs to identify "key nodes" or anchor words, which are then used to steer the final output via Logits-Boost and Prefix-Prompt strategies.

Sparse Decisiveness and Anchor Words

A core insight of the DATG approach is the concept of "sparse decisiveness." The researchers observed that the overall attribute of a sentence is often determined by a very small number of tokens. For instance, in a review of a novel, changing a single word from "masterpiece" to "disaster" can completely flip the sentiment of the entire passage.

Illustration of sparse decisiveness: a few key word changes can dramatically shift a sentence's position on the sentiment dimension.

By focusing control efforts on these critical anchor words rather than every token in the sequence, DATG avoids the heavy-handedness of previous methods. This targeted intervention allows the LLM to maintain its natural linguistic flow while still adhering to the desired attribute constraints. This approach also helps avoid the "pink elephant" trap, where explicitly telling a model not to generate toxic content can inadvertently cause the model to focus more on those negative concepts; instead, DATG identifies positive anchors to steer toward.

Experimental Results

The framework was evaluated across multiple LLMs (including LLaMA-2, Falcon, and Phi-2) on tasks involving toxicity mitigation and sentiment transformation. The results demonstrate significant improvements over existing baselines:

  • Control Accuracy: DATG achieved up to a 19.29% improvement in control accuracy compared to state-of-the-art methods like FUDGE.
  • Fluency and Naturalness: Unlike many CTG techniques that increase perplexity, DATG actually decreased perplexity, indicating that the generated text was more fluent and coherent than the baseline outputs.
  • Efficiency: The graph-based steering mechanism is computationally efficient, resulting in a 32% to 40% reduction in generation time per item compared to traditional guide-model approaches.

Conclusion

DATG represents a significant step forward in controlled text generation by treating attribute control as a sparse, graph-based steering problem rather than a continuous oversight task. By identifying and boosting specific anchor words, the framework achieves high control precision without sacrificing the generative quality or speed of the underlying Large Language Model. Future research will explore pre-generating attribute graphs for common topics to further reduce the initial setup latency.

Summary updated

BibTeX
@inproceedings{liang2024controlled,
  author = {Xun Liang and Hanyu Wang and Shichao Song and Mengting Hu and Xunzhi Wang and Zhiyu Li and Feiyu Xiong and Bo Tang},
  title = {{Controlled Text Generation for Large Language Model with Dynamic Attribute Graphs}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.findings-acl.345},
}
Figure