Controlled Text Generation (CTG) aims to produce texts that exhibit specific desired attributes. In this study, we introduce a pluggable CTG framework for Large Language Models (LLMs) named Dynamic Attribute Graphs-based controlled text generation (DATG). This framework utilizes an attribute scorer to evaluate the attributes of sentences generated by LLMs and constructs dynamic attribute graphs. DATG modulates the occurrence of key attribute words and key anti-attribute words, achieving effective attribute control without compromising the original capabilities of the model. We conduct experiments across four datasets in two tasks: toxicity mitigation and sentiment transformation, employing five LLMs as foundational models. Our findings highlight a remarkable enhancement in control accuracy, achieving a peak improvement of 19.29% over baseline methods in the most favorable task across four datasets. Additionally, we observe a significant decrease in perplexity, markedly improving text fluency.
Controlled Text Generation (CTG) focuses on generating text that adheres to specific attributes like sentiment and non-toxicity, maintaining both the quality and generative power of Large Language Models (LLMs). Traditionally, smaller language models have been used to guide the decoding of larger models, offering control but often at the cost of reducing output quality and variability.
Recent research highlights a key dilemma: excessive control can undermine text fluency, turning advanced LLMs into mere "puppets" of smaller models. This excessive reliance compromises LLMs' inherent decoding capabilities, relegating these powerful models to subordinate roles.
This introduction underscores the need for a balanced approach to integrating control within LLMs, ensuring that enhancements in text generation do not sacrifice the models' intrinsic strengths.
In light of our exploration, we believe that the specific attributes of a text are predominantly determined by a limited number of words that bear a close relation to those attributes. Although these key words are sparse within the text, their impact on the overall attributes is decisive (See Figure 1).
For instance in Figure 2, changing the word "masterpiece" to "failure" in the sentence "The novel is a masterpiece of storytelling, with a complex narrative." shifts the sentiment from positive to negative. This change not only alters the entire sentence's sentiment but also its meaning. In the conceptual framework of semantic space, these attributes can be seen as dimensions within this space. By strategically adjusting these key words, we can guide the text generated by Large Language Models (LLMs) to move in the desired direction within the semantic space, controlling its attributes without significant alterations to the overall content.
Building on our insights into controlled text generation, we introduce the Dynamic Attribute Graphs-based Controlled Text Generation (DATG) method. This refined approach leverages dynamic attribute graphs to identify and modulate a subset of key attribute words, allowing for targeted adjustments that enhance the precision of attribute control in generated text.
DATG begins with Contextual Corpus Construction, where large language models (LLMs) generate text sequences from specifically designed prompts to capture the desired attributes. The texts are then assessed through Attribute Classifier Scoring, employing classifiers like toxicity or sentiment models to evaluate their alignment with the target attributes.
At the heart of DATG is the Dynamic Attribute Graphs Construction step, which transforms these text sequences into directed weighted graphs based on classifier scores. This involves creating positive and negative attribute graphs, which represent the adherence to and deviation from the desired attributes. These graphs guide the subsequent text generation to ensure that it remains within the desired semantic dimensions.
The process concludes with ReGeneration with Dynamic Boundary Controlling. Here, a graph ranking algorithm selects key nodes, which are critical for pushing the generated text towards the control attributes' upper boundaries in the semantic space. Adjustments to these key nodes, facilitated by logits-boost and prefix-prompt strategies, refine the text generation process, ensuring that it adheres closely to the desired attributes while maintaining semantic integrity and coherence.
Figure 4: Detailed computation times for each stage of the DATG process.
@article{DATG,
title={Controlled Text Generation for Large Language Model with Dynamic Attribute Graphs},
author={Xun Liang and Hanyu Wang and Shichao Song and Mengting Hu and Xunzhi Wang and Zhiyu Li and Feiyu Xiong and Bo Tang},
journal={arXiv preprint arXiv:2402.11218},
year={2024},
}