Contrastive Perplexity for Controlled Generation: An Application in Detoxifying Large Language Models

Tassilo Klein, Moin Nabi
1/16/2024
cs.CLcs.LG

No official code found. Best implementation: SAP-samples/acl2025-contrastive-perplexity (2 stars, Apache-2.0, last commit 2025-12-18).

Abstract

The generation of toxic content by large language models (LLMs) remains a critical challenge for the safe deployment of language technology. We propose a novel framework for implicit knowledge editing and controlled text generation by fine-tuning LLMs with a prototype-based contrastive perplexity objective. Central to our method is the construction of hard negatives - toxic outputs that are generated through adversarial paraphrasing to be semantically similar and model probability to their non-toxic counterparts. By training on these challenging and realistic pairs, our approach ensures robust and stable contrastive optimization. Experimental results in the domain of detoxification demonstrate that our method significantly reduces toxic generation while maintaining strong performance on downstream tasks such as commonsense reasoning and reading comprehension. Our findings highlight the effectiveness of exploiting hard negatives for attribute-aware fine-tuning.

View on arXivView PDF

Code Implementations(1)

Apache-2.0

This reposity contains the source code of the ACL'25 paper "Contrastive Perplexity for Controlled Generation: An Application in Detoxifying Large Language Models". Paper abstract: "The generation of undesirable and factually incorrect content of large language models poses a significant challenge and remains largely an unsolved issue. This pap...

20Shell, PythonMay 20, 202510 months agoApache-2.0
controlleddetoxificationgenerationnlptransformers

Similar Papers

Cite this paper

@article{klein2024contrastive,
  title  = {Contrastive Perplexity for Controlled Generation: An Application in Detoxifying Large Language Models},
  author = {Tassilo Klein and Moin Nabi},
  year   = {2024},
  eprint = {2401.08491},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2401.08491v3}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2401.08491.svg)](https://codeofpaper.com/paper/2401.08491)

Discussion