NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

UniDetox: Universal Detoxification of Large Language Models via Dataset Distillation

Huimin Lu, Masaru Isonuma, Junichiro Mori, Ichiro Sakata

Abstract

Large Language Models (LLMs) often inherit and amplify toxic biases present in their massive pre-training corpora. Existing detoxification methods, such as decoding-time interventions or model editing, are largely model-specific, requiring intensive hyperparameter tuning and the training of auxiliary models for every new architecture. We introduce UniDetox, a data-centric framework that shifts the focus from model-specific interventions to a universal "detoxifying" dataset. By using a novel dataset distillation technique based on contrastive decoding, UniDetox generates a small, synthetic corpus that acts as a universal antidote. Fine-tuning diverse models like LLaMA-2 and Falcon on this distilled text significantly reduces toxicity while maintaining fluency and general task performance, even when the data is distilled from a much smaller source model like GPT-2 XL.

Introduction

As Large Language Models (LLMs) scale, so does the risk of them generating harmful, biased, or toxic content. While the research community has developed several post-hoc detoxification strategies, they face a significant scalability hurdle: they are almost entirely model-specific. Methods like DExperts or Task Arithmetic typically require practitioners to train a "toxic" version of their specific target model and perform meticulous hyperparameter tuning to balance toxicity reduction against linguistic fluency.

If these hyperparameters are misaligned, models often suffer from "perplexity explosion," where they stop being toxic but also stop being coherent. Because the optimal balance varies wildly across different architectures and tokenizers, scaling these interventions across the rapidly expanding ecosystem of LLMs is computationally expensive and practically difficult. UniDetox addresses this by proposing a universal, data-driven approach that transfers across models without the need for architecture-specific tuning.

The UniDetox Methodology

UniDetox moves the intervention from the model's internal weights or decoding logic to the training data itself. The core of the method is a novel form of dataset distillation tailored for LLMs.

1. Creating the Toxic Source

The process begins by fine-tuning a base model (e.g., GPT-2 XL) on a dataset of known toxic text, such as Dynamically Generated Hate Speech (DGHS). This creates a "toxic expert" that understands the distribution of harmful language.

2. Distilling the Detoxifying Corpus

Instead of traditional dataset distillation—which relies on computationally expensive gradient matching—UniDetox uses contrastive decoding. The authors generate synthetic text by sampling tokens that have a high probability in the original base model but a low probability in the toxic version. To ensure the resulting text remains coherent and readable, an adaptive plausibility constraint is applied to filter out low-probability gibberish. This process results in a discrete, synthetic dataset that represents the "opposite" of the toxic distribution.

3. Universal Fine-Tuning

This distilled text serves as a universal detoxifying dataset. Any target LLM, regardless of its architecture or size, can be fine-tuned on this small corpus. This process effectively "unlearns" toxic behaviors by moving the model's parameters away from the toxicity vector.

Experimental Setup

The authors evaluated UniDetox across several prominent open-source models, including OPT-6.7B, Falcon-7B, and LLaMA2-7B. Notably, the detoxifying data was distilled using a much smaller GPT-2 XL model to test cross-model generalization.

  • Toxicity Evaluation: Mitigation was tested using the ToxiGen dataset, covering both in-distribution domains (e.g., race, religion) and out-of-distribution domains (e.g., physical disabilities) to measure generalization.
  • Capability Evaluation: The MMLU (Massive Multitask Language Understanding) benchmark was used to ensure that detoxification did not degrade the models' general reasoning and knowledge capabilities.

Key Results and Insights

Cross-Model Generalization

A primary finding of UniDetox is that "antidote" data is model-agnostic. Detoxifying text distilled from GPT-2 XL successfully reduced toxicity in much larger, modern models like LLaMA2-7B. For instance, on LLaMA2-7B, UniDetox reduced in-distribution Toxicity Probability (TP) from 0.58 to 0.29, and out-of-distribution TP from 0.49 to 0.26.

Maintaining Fluency and Performance

Unlike baseline methods like Task Arithmetic, which caused Falcon-7B's perplexity (PPL) to spike to an unusable 275.5 when not perfectly tuned, UniDetox maintained a healthy PPL of 7.85 (compared to the base model's 10.69). Furthermore, MMLU accuracy remained stable; LLaMA2-7B's 3-shot MMLU accuracy only saw a minor shift from 41.74% to approximately 37%, a significantly lower performance penalty than other aggressive detoxification methods.

Theoretical Foundations

The authors provide a mathematical link between UniDetox and Task Arithmetic. Using Taylor approximation, they demonstrate that fine-tuning on contrastively decoded text is functionally equivalent to moving a model's weights in the opposite direction of a "toxicity vector" in the parameter space. This explains why the method is so effective at neutralizing harmful outputs.

Political Neutrality

An interesting byproduct of the distillation process is political neutralization. Analysis of the distilled text showed it was significantly more balanced—less skewed toward either left-leaning or right-leaning extremes—than standard text sampled from GPT-2. This suggests that detoxification naturally encourages a more neutral, objective linguistic style.

Limitations and Future Work

While UniDetox is highly effective, it does involve a slight trade-off in lexical diversity; the most aggressive detoxification settings can lead to more repetitive vocabulary. Additionally, instruction-tuned models (like LLaMA2-7B-chat) may require specific handling, as their pre-existing conversational alignments interact differently with the detoxification process than base models.

Future research may explore scaling the distillation process to larger base models to generate even higher-quality synthetic data or expanding the range of toxic domains covered during the initial distillation phase to create a more robust, comprehensive universal antidote.

Conclusion

UniDetox represents a significant step toward scalable LLM safety. By treating detoxification as a data distillation problem rather than a model-specific engineering task, it allows for the rapid, efficient protection of diverse model architectures. The ability to use small models to "cure" much larger ones suggests that the underlying patterns of toxicity are sufficiently universal to be addressed through shared, synthetic datasets.

Summary updated

BibTeX
@inproceedings{lu2025unidetox,
  author = {Huimin LU and Masaru Isonuma and Junichiro Mori and Ichiro Sakata},
  title = {{UniDetox: Universal Detoxification of Large Language Models via Dataset Distillation}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=eLLBILFRsA},
}
Figure