Controlled Text Generation with Hidden Representation Transformations

Vaibhav Kumar, Hana Koorehdavoudi, Masud Moshtaghi, Amita Misra, Ankit Chadha, Emilio FerraraACL 2023

Large Language Models (LLMs) are powerful tools, yet they are susceptible to generating toxic, biased, or nonsensical content. While various "steering" methods exist to mitigate these issues, they often impose a significant trade-off: either they slow down text generation considerably or they compromise the linguistic fluency of the model.

Presented at ACL 2023, researchers from UCLA, Amazon Alexa AI, and USC introduced CHRT (Control Hidden Representation Transformation). This framework enables high-speed controlled generation while maintaining the natural linguistic quality of the base model.

The Challenge of Controlled Text Generation (CTG)

Effective CTG requires balancing three critical objectives:

  1. Attribute Control: Ensuring the model strictly adheres to specific constraints (e.g., avoiding toxicity).
  2. Fluency: Maintaining the natural, human-like quality of the generated text.
  3. Efficiency: Achieving generation speeds suitable for real-time applications.

Existing approaches generally fall into two categories. Learning-based methods, such as fine-tuning, often lack precise control. Conversely, decoding-time methods (e.g., PPLM or DExperts) provide superior control but are computationally intensive, requiring multiple model passes or complex calculations for every token generated. CHRT bridges this gap, offering the precision of decoding-time methods with the efficiency of standard inference.

Methodology: The Transformation Block

The core of CHRT is the Transformation Block ($\tau$). Rather than modifying model weights or final token probabilities, CHRT intervenes at the level of "hidden representations"—the internal vectors the model computes before selecting a word.

Overview of CHRT training, inference, and the internal architecture of the Transformation Block.

The implementation involves three primary stages:

  1. Guider Models: Two small versions of the base model are fine-tuned: one on "positive" examples (e.g., non-toxic text) and one on "negative" examples (e.g., toxic text). These serve as anchors for the desired and undesired attributes.
  2. Contrastive Learning: The transformation block is trained using a Triplet Loss. This objective encourages the block to shift the base model's hidden state closer to the positive guider's representation and further from the negative guider's.
  3. Preservation Loss: To maintain linguistic integrity, an L2 loss is applied, preventing the transformed representation from deviating excessively from the original base representation.

This results in a lightweight "plug-in" layer that can be integrated into existing LLMs, such as GPT-2, to steer their output dynamically.

Evaluation Datasets

The researchers evaluated CHRT across three key attributes: toxicity, sentiment, and text simplicity.

  • RealToxicityPrompts: A standard benchmark for measuring a model's propensity for toxic generation.
  • RealAttributePrompts: A new framework introduced by the authors to create RealSentimentPrompts and RealSimplicityPrompts, providing 100k prompt-continuation pairs for benchmarking.
  • Jigsaw Toxic Comment Classification: Utilized to assess the effectiveness of detoxification.

Key Results and Performance

CHRT was benchmarked against prominent methods including PPLM, GeDi, and DExperts.

Quantitative comparison of CHRT against baselines on toxicity, fluency, and diversity metrics.
  • Detoxification: CHRT achieved a remarkably low maximum toxicity score of 0.085, significantly outperforming the base GPT-2 (0.827) and the strongest baseline, DExperts (0.154).
  • Sentiment Steering: The model reduced the probability of negative sentiment generation to 0.5%, representing a 62% improvement over the next best baseline.
  • Simplicity and Fluency: In text simplification tasks, CHRT improved fluency (measured by perplexity) compared to vanilla GPT-2 while achieving a 99.6% success rate in generating simple text.
  • Efficiency: While most high-performing control methods add seconds of latency, CHRT adds a negligible 10 milliseconds, making it viable for production environments.

Discussion and Future Directions

CHRT offers tunable control via a single hyperparameter ($\lambda$), allowing developers to balance attribute strength against fluency. Furthermore, because transformations occur in the hidden space, multiple attributes can be combined (e.g., simultaneous detoxification and simplification) through linear combinations of outputs.

Despite its success, the authors note limitations. Maximizing one attribute may inadvertently trigger correlated biases present in the training data. Additionally, the framework currently requires training specific guider models for each new attribute. Future research will focus on developing more "universal" transformations to further simplify the deployment of controlled generation.

Reference: Kumar, V., et al. (2023). Controlled Text Generation with Hidden Representation Transformations. Findings of ACL 2023.

Summary updated

BibTeX
@inproceedings{kumar2023controlled,
  author = {Vaibhav Kumar and Hana Koorehdavoudi and Masud Moshtaghi and Amita Misra and Ankit Chadha and Emilio Ferrara},
  title = {{Controlled Text Generation with Hidden Representation Transformations}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  doi = {10.18653/v1/2023.findings-acl.602},
}
Figure