Language Model Detoxification in Dialogue with Contextualized Stance Control

Jing Qian, Xifeng Yan

Abstract

Large Language Models (LLMs) are prone to "toxic degeneration," which includes not only the generation of explicit slurs but also implicit offensiveness through agreement with toxic user statements. This paper introduces a hierarchical prefix-tuning framework that contextualizes a model's stance to prevent it from supporting harmful content. By utilizing meta-prefixes and novel contrastive training objectives—specifically stance and context contrastive losses—the model learns to implicitly adjust its response behavior based on dialogue history. Experimental results on the ToxiChat dataset demonstrate that this approach significantly reduces supportive stances toward offensive content while preserving conversational naturalness in safe contexts, outperforming traditional classify-then-generate baselines.

Introduction: The Challenge of Implicit Offensiveness

While standard detoxification methods effectively prevent LLMs from generating explicit hate speech, they often fail to address implicit offensiveness in dialogue. A model can be offensive simply by aligning itself with a toxic user. For instance, if a user makes a hateful remark and the model responds with "Yeah, he is," the output is technically "clean" of slurs but remains deeply harmful.

Figure 1: Examples of implicit toxicity where the model agrees with or supports offensive user statements.

As illustrated in Figure 1, the core challenge is that the appropriate stance is context-dependent: the model should be supportive in friendly conversations but non-supportive when the user is offensive. Traditional "Classify-then-Generate" pipelines—which use a separate model to flag toxicity—often suffer from high latency and error propagation, where a single missed classification leads to toxic agreement.

Methodology: Hierarchical Prefix-Tuning

The authors propose a novel control method using hierarchical prefixes. Building on prefix-tuning, where small trainable vectors are prepended to the LM's hidden states, they introduce two layers of control:

  1. Toxicity Control Prefixes ($H_\beta$): Standard prefixes trained to reduce the explicit self-toxicity of the output.
  2. Meta Prefixes ($H_\alpha$): The primary innovation, these prefixes are trained to dynamically generate a stance control prefix based on the specific dialogue context.

Instead of relying on an explicit binary classifier, the model learns the relationship between context and stance implicitly through two contrastive training objectives:

  • Stance Contrastive Loss ($L_s$): This forces the model to generate distinct prefixes for supportive versus non-supportive stances when user input is offensive.
  • Context Contrastive Loss ($L_c$): This ensures the model distinguishes between offensive and non-offensive utterances, preventing the stance control from interfering with normal, supportive behavior in safe contexts.

Experimental Results

The researchers evaluated their method using the ToxiChat dataset (2,000 annotated Reddit threads) with DialoGPT-medium as the backbone. They compared their approach against standard Prefix-Tuning and a Classify-then-Generate (Cls-Gen) flow.

Figure 4: Quantitative performance metrics comparing the proposed method against various baselines.

As shown in Figure 4, the proposed method ("Ours") achieved a Support Stance score of 0.225 in offensive contexts, significantly lower than baseline DialoGPT (0.253) and other prefix-based methods (~0.32). Crucially, in safe contexts, the model maintained high naturalness with the lowest Stance Shift (0.089), meaning it stayed much closer to the original model's helpful behavior than the Cls-Gen flow (0.286). While all detoxification methods impact linguistic quality, the proposed method maintained a competitive perplexity (PPL) of 156.85.

Conclusion and Future Work

This hierarchical prefix framework provides a robust solution for managing implicit toxicity in dialogue without the bottlenecks of explicit classification. By embedding the decision to be non-supportive within the prefix generation process, the model remains a pleasant conversationalist in safe settings while pivoting away from harmful alignment in toxic ones. Future research may extend this framework to handle more complex linguistic phenomena such as sarcasm or to control for other context-dependent attributes like factuality.

Summary updated

BibTeX
@inproceedings{qian2022language,
  author = {Jing Qian and Xifeng Yan},
  title = {{Language Model Detoxification in Dialogue with Contextualized Stance Control}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2022},
  doi = {10.18653/v1/2022.findings-emnlp.406},
}
Figure