Table of Contents
Fetching ...

UniDetox: Universal Detoxification of Large Language Models via Dataset Distillation

Huimin Lu, Masaru Isonuma, Junichiro Mori, Ichiro Sakata

TL;DR

UniDetox tackles the problem of detoxifying large language models in a model-agnostic way by extending dataset distillation to produce detoxifying text via contrastive decoding. The method distills detoxifying representations into discrete synthetic text and then fine-tunes any target model on that distilled data, achieving universal detoxification without per-model hyperparameter tuning. Theoretical justification via a first-order Taylor approximation shows the detoxifying gradient aligns with moving away from the toxic direction, and empirical results demonstrate strong toxicity mitigation across GPT-2, OPT, Falcon, and LLaMA2 with minimal degradation to fluency; the distilled text also reduces political bias. This approach offers a scalable, practical pathway toward consistent toxicity control across diverse LLMs, with important implications for real-world deployment and regulatory compliance.

Abstract

We present UniDetox, a universally applicable method designed to mitigate toxicity across various large language models (LLMs). Previous detoxification methods are typically model-specific, addressing only individual models or model families, and require careful hyperparameter tuning due to the trade-off between detoxification efficacy and language modeling performance. In contrast, UniDetox provides a detoxification technique that can be universally applied to a wide range of LLMs without the need for separate model-specific tuning. Specifically, we propose a novel and efficient dataset distillation technique for detoxification using contrastive decoding. This approach distills detoxifying representations in the form of synthetic text data, enabling universal detoxification of any LLM through fine-tuning with the distilled text. Our experiments demonstrate that the detoxifying text distilled from GPT-2 can effectively detoxify larger models, including OPT, Falcon, and LLaMA-2. Furthermore, UniDetox eliminates the need for separate hyperparameter tuning for each model, as a single hyperparameter configuration can be seamlessly applied across different models. Additionally, analysis of the detoxifying text reveals a reduction in politically biased content, providing insights into the attributes necessary for effective detoxification of LLMs.

UniDetox: Universal Detoxification of Large Language Models via Dataset Distillation

TL;DR

UniDetox tackles the problem of detoxifying large language models in a model-agnostic way by extending dataset distillation to produce detoxifying text via contrastive decoding. The method distills detoxifying representations into discrete synthetic text and then fine-tunes any target model on that distilled data, achieving universal detoxification without per-model hyperparameter tuning. Theoretical justification via a first-order Taylor approximation shows the detoxifying gradient aligns with moving away from the toxic direction, and empirical results demonstrate strong toxicity mitigation across GPT-2, OPT, Falcon, and LLaMA2 with minimal degradation to fluency; the distilled text also reduces political bias. This approach offers a scalable, practical pathway toward consistent toxicity control across diverse LLMs, with important implications for real-world deployment and regulatory compliance.

Abstract

We present UniDetox, a universally applicable method designed to mitigate toxicity across various large language models (LLMs). Previous detoxification methods are typically model-specific, addressing only individual models or model families, and require careful hyperparameter tuning due to the trade-off between detoxification efficacy and language modeling performance. In contrast, UniDetox provides a detoxification technique that can be universally applied to a wide range of LLMs without the need for separate model-specific tuning. Specifically, we propose a novel and efficient dataset distillation technique for detoxification using contrastive decoding. This approach distills detoxifying representations in the form of synthetic text data, enabling universal detoxification of any LLM through fine-tuning with the distilled text. Our experiments demonstrate that the detoxifying text distilled from GPT-2 can effectively detoxify larger models, including OPT, Falcon, and LLaMA-2. Furthermore, UniDetox eliminates the need for separate hyperparameter tuning for each model, as a single hyperparameter configuration can be seamlessly applied across different models. Additionally, analysis of the detoxifying text reveals a reduction in politically biased content, providing insights into the attributes necessary for effective detoxification of LLMs.
Paper Structure (56 sections, 8 equations, 3 figures, 11 tables)

This paper contains 56 sections, 8 equations, 3 figures, 11 tables.

Figures (3)

  • Figure 1: Overview of UniDetox. (1) We create the toxic model $\bm{\theta}_\text{toxic}$ by fine-tuning the base model $\bm{\theta}_\text{base}$ on toxic text. (2) Detoxifying text is then distilled through contrastive decoding between the base and toxic models. (3) The base model is detoxified by fine-tuning with the detoxifying text. As detailed in Section \ref{['sec: rationale']}, the gradient of the loss function for the detoxifying text aligns with $-\bm{\tau}_\text{toxic}$, the opposite direction of the toxicity vector, leading to effective detoxification. This detoxifying text can also be used to detoxify other models.
  • Figure 2: Hyperparameter sensitivity. This figure illustrates the changes in perplexity and Toxicity Probability (TP) averaged on all domains across different hyperparameters.
  • Figure 3: Few-shot prompt formatting.