Text Detoxification using Large Pre-trained Neural Models

David Dale, Anton Voronov, Daryna Dementieva, Varvara Logacheva, Olga Kozlova, Nikita Semenov, Alexander Panchenko

Abstract

David Dale, Anton Voronov, Daryna Dementieva, Varvara Logacheva, Olga Kozlova, Nikita Semenov, Alexander Panchenko. Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing.

2021.

Introduction

While identifying toxic content online has become a standard task in natural language processing, the automatic detoxification of such text—rewriting it to be neutral while preserving its original meaning—remains a significant challenge. This task is often framed as a subset of unsupervised text style transfer. However, unlike sentiment transfer (e.g., changing a negative movie review to a positive one), detoxification requires strict adherence to the original intent. If a user expresses a substantive but offensive opinion, a detoxification tool should neutralize the aggression without altering the core message.

Researchers have identified three primary goals for successful detoxification: style accuracy (effective removal of toxicity), content preservation (maintaining the original meaning), and fluency (ensuring the output sounds natural). Balancing these often-conflicting objectives is the central hurdle in the field.

Proposed Architectures

The authors introduce two novel unsupervised models that leverage large pre-trained language models to achieve state-of-the-art results: ParaGeDi and CondBERT.

ParaGeDi: Paraphrasing with GeDi Guidance

ParaGeDi (Paraphrasing GeDi) treats detoxification as a "guided rewrite" process. It utilizes a T5-based paraphraser to generate candidate sentences. To ensure these candidates are non-toxic, it employs GeDi (Generative Discriminator), a small, style-conditioned language model.

ParaGeDi architecture using a T5-based paraphraser guided by a style-conditioned language model (GeDi).

By applying Bayes' rule, GeDi shifts the probability distribution of the next word during generation, "nudging" the paraphraser toward safe, polite synonyms and away from toxic ones. This allows the model to restructure entire sentences for better fluency while maintaining control over the output style.

CondBERT: Conditional Pointwise Editing

CondBERT (Conditional BERT) takes a "pointwise editing" approach, focusing on surgical replacements rather than full sentence restructuring. The process involves three main steps:

  1. Detection: Identifying toxic words using a logistic regression classifier.
  2. Substitution: Masking the toxic words and using BERT to suggest neutral alternatives.
  3. Reranking: Filtering BERT’s suggestions based on their semantic similarity to the original word and their predicted toxicity.
CondBERT workflow: detecting toxic words, generating substitutes with BERT, and reranking based on similarity and toxicity.

A key feature of CondBERT is its ability to replace a single toxic word with multiple neutral ones (e.g., "idiot" $\rightarrow$ "not very smart"), which helps maintain the original nuance.

Data and Evaluation

The models were trained and evaluated using several key datasets:

  • Jigsaw Competition Data: Used for training toxicity classifiers.
  • ParaNMT: A massive dataset of 50 million English paraphrases.
  • Mined Parallel Corpus: The authors created a novel benchmark by mining ParaNMT for "natural" detoxification pairs—instances where one paraphrase was significantly more toxic than its counterpart. They released 500,000 such pairs to support future research.

To evaluate performance holistically, the authors use the J-metric, which is the product of Accuracy, Similarity, and Fluency. This prevents models from "cheating" by optimizing for one metric (like toxicity removal) at the expense of others (like readability).

Results and Discussion

Both ParaGeDi and CondBERT established new state-of-the-art benchmarks, significantly outperforming previous models like Mask&Infill and STRAP on the J-metric.

Human validation confirmed these findings. ParaGeDi achieved a 93.4% style accuracy and a 91.3% fluency score. However, content preservation remains the most difficult challenge, with scores around 64.8%. The models occasionally struggle with semantic "opposites," sometimes replacing a toxic word with its antonym (e.g., "you are stupid" $\rightarrow$ "you are smart") instead of a neutral equivalent.

A major insight from the study is that BERT can act as a "zero-shot" stylist. CondBERT does not require style-specific fine-tuning; it effectively changes style simply by reranking standard masked-language-model outputs. Furthermore, the success of the "mined" parallel corpus suggests that high-quality, task-specific data may be as important as architectural complexity.

Conclusion

While ParaGeDi and CondBERT represent a significant leap forward, the authors note they are not yet ready for fully autonomous deployment in sensitive environments due to the subjective nature of toxicity and occasional failures in content preservation. Instead, these models are envisioned as powerful "writing assistants" that can suggest constructive edits to users, helping to foster a more civil online discourse.

Summary updated

BibTeX
@inproceedings{dale2021text,
  author = {David Dale and Anton Voronov and Daryna Dementieva and Varvara Logacheva and Olga Kozlova and Nikita Semenov and Alexander Panchenko},
  title = {{Text Detoxification using Large Pre-trained Neural Models}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2021},
  url = {https://openreview.net/forum?id=8AdUEjRhQ3k},
}
Figure