Controlled Text Generation with Hidden Representation Transformations (2023)

Abstract: We propose CHRT (Control HiddenRepresentation Transformation) – a con-trolled language generation framework thatsteers large language models to generatetext pertaining to certain attributes (such astoxicity). CHRT gains attribute control bymodifying the hidden representation of thebase model through learned transformations. We employ a contrastive-learning frameworkto learn these transformations that can becombined to gain multi-attribute control. Theeffectiveness of CHRT is experimentallyshown by comparing it with seven baselinesover three attributes. CHRT outperforms all thebaselines in the task of detoxification, positivesentiment steering, and text simplificationwhile minimizing the loss in linguistic qualities. Further, our approach has the lowest inferencelatency of only 0.01 seconds more than thebase model, making it the most suitable forhigh-performance production environments. We open-source our code and release two noveldatasets to further propel controlled languagegeneration research

## introduction with the latest developments in transformers, @xcite , large language models @xcite @xcite have gained remarkable success in generating coherent and fluent text. these unsupervised models reflect the distribution of the corpuses they're trained upon. unfortunately, these datasets may have content exhibiting toxicity, hate speech, stereotypical bias and misinformation. language models serve millions of users in latency-constrained environments @xcite because of which it has become increasingly more important to gain control over certain attributes such as toxicity. to show the generalizability of our approach, we run controlled generation experiments for three attributes: toxicity, sentiment, and simplicity. for toxicity, we fine-tune our guider models on the real toxicity prompts @xcite dataset. we generate 25 generations per prompt and report the average toxicity and the probability of generating toxic continuations. we also report the fluency of generations using the perplexity metric. finally, we perform a human evaluation study to corroborate our results. closely following the approach of real toxicity prompts @xcite , we devise realat-tributeprompts -a framework to automatically generate datasets for controlled language generation benchmarking using an attribute classifier. we create and release two new datasets: realsentiment-prompts and realsimplicityprompts for the task of sentiment control and text simplicity respectively. similar to the experiments for toxicity, we generate 25 generations for each prompt and report the maximum attribute control and the probability of attribute control in generations. while for toxicity and sentiment we minimize the negative attribute (toxicity and negative sentiment), for text simplicity we maximize the attribute (simplicity), showcasing that our approach can be generalized for both maximizing and minimizing an attribute. finally, we showcase multi-attribute control by combining multiple chrt transformations in section 3.5. for all our results we perform a comprehensive comparison with five existing baselines: dapt (domain adaptive pre-training) @xcite , nlc @xcite (negative lexically constrained) decoding, pplm (plug and play language models) @xcite , gedi (generative discriminators) @xcite and dexperts @xcite , for controlling the base gpt-2 model. our approach outperforms all five baselines in controlling the attributes of toxicity, sentiment, and text simplicity respectively with minimal loss in liguistic qualities. it also achieves the lowest latency of +0.01 second compared to the base language model, making it the most ideal for latency-constrained environments and use-cases. our contributions can be summarized as follows: ## related work related work is broadly divided into two parts -controlled language generation and the application of contrastive learning in nlp. ## chrt: control hidden representation transformations we start with formally defining the problem of controlled language generation, followed by explaining how chrt transforms the hidden representations. finally, we explain the finetuning of guider models and training the chrt transformation heads. figure 1 schematically shows the training, inference, and the transform block for our approach. ## experimental results we experimentally show the efficacy of our approach by applying it to the gpt-2-medium language model and comparing it with five other controlled generation baselines. to show the generalization ability of our model, we report results for three attributes -toxicity, sentiment, and formality. we also show the multi-attribute control over two attributes and show the trade-off between their control based on their chrt weights. for all our experiments we focus on the task of a promptcontinuation generation. ## limitations our work is limited in capturing the unintended dependencies of attributes. it is possible that maximizing certain attributes like positive sentiment may maximize attributes like gender bias. a formal study to capture the dependency of the bias with varied attribute control is an important future direction. the efficacy automated metrics used to measure the linguistic qualities and attribute alignment of the generations is limited @xcite . devising more exhaustive and explainable metrics is also an important future-work. ## conclusion we present chrt, a learning-based controlled language generation framework that achieves stateof-the-art attribute control while minimizing the loss in linguistic quality as compared to five recent baselines. the ability to combine control over multiple attributes and the ultra-fast inference of our approach makes it ideal for latency-constrained usecases. we empirically showcase the effectiveness of our approach by performing both large-scale automated and human-evaluated benchmarks. for future work, we will like to work on making our approach more plug-and-play and achieve attribute control with an even lower loss in linguistic quality.