TL;DR
This paper introduces FGDILP, a novel method for detoxifying Large Language Models (LLMs) without requiring additional training data or models. By leveraging self-generated instance-level prefixes, FGDILP effectively mitigates various forms of toxic content, outperforming existing prompt-based approaches.
What Problem Does This Paper Address?
Large Language Models (LLMs) like GPT and Llama have demonstrated remarkable capabilities across numerous NLP tasks. However, a significant drawback is their tendency to generate toxic content, including insults, threats, and profanity. This toxicity poses a serious risk to the practical application of LLMs. Existing solutions, such as finetuning or auxiliary decoding models, often incur substantial costs in terms of computational resources, data, or model complexity. Prompt-based methods, while promising, lack a deep understanding of their underlying mechanisms, limiting optimization potential. The paper aims to address this by proposing a cost-effective, instance-specific detoxification strategy.
Methods
The core of FGDILP lies in its "fine-grained detoxification via instance-level prefixes." The approach operates in three main stages:
- Instance-Level Prefix Generation:
- Self-Generation: The LLM generates multiple text samples from a given raw prompt.
- Self-Diagnosis: These generated texts are then "self-diagnosed" using specific templates to classify them as either toxic (negative prefixes) or non-toxic (positive prefixes) for various subtoxicity types (e.g., threat, insult, profanity). This classification is based on the LLM's own probability assignments for "Yes" or "No" answers to diagnostic queries.
- Subtoxicity Vector Construction and Fusion:
- Prefix-Prepend: The raw prompt is combined with a positive prefix and multiple negative prefixes (one for each identified subtoxicity).
- Contextualized Representation: These prefixed prompts are fed through the LLM's transformer layers. The contextualized representations of the last token are extracted.
- Subtoxicity Vector Creation: Differences between the representations of positive and negative prefix-prepended prompts are calculated to form "subtoxicity vectors." These vectors capture specific toxic behaviors.
- Fusion: A three-step process (Masking, Symbolization, Alignment) is used to fuse these subtoxicity vectors into a single "toxicity probe." This probe aims to capture a comprehensive range of toxic signals.
- Detoxification:
- The fused toxicity vector is used to steer the LLM's generation process, guiding it away from toxic directions and towards non-toxic outputs. This is achieved by modifying the raw vector in the attention layer.
Datasets
The paper evaluates its method on two established datasets:
- RealToxicityPrompts: This dataset consists of 100k sentence-level prompts derived from a large English web text corpus. Prompts are categorized as toxic or non-toxic based on toxicity scores.
- FFT (Forced Factuality and Toxicity): This dataset is used for evaluating context-level toxicity. It comprises question-response pairs designed to assess toxicity that emerges from contextual relationships.
Key Insights and Ideas
- LLMs "know" their toxicity: The approach is built on the observation that LLMs can, to a significant degree, recognize the toxic content they produce. This self-awareness is leveraged for detoxification.
- Instance-level prefixes are powerful: By generating prefixes specific to each instance and its potential subtoxicities, the method achieves fine-grained control over detoxification.
- Subtoxicity vectors capture nuanced toxicity: The creation of vectors for different subtoxicity types allows for a more targeted and comprehensive approach to mitigating diverse forms of harmful content.
- Fusion is key: The proposed fusion mechanism (Masking, Symbolization, Alignment) is crucial for effectively combining information from multiple subtoxicity vectors and creating a robust toxicity probe.
- Automatic evaluation has limitations: The authors highlight that automatic metrics can sometimes be misleading, particularly for context-level toxicity, underscoring the importance of human evaluation.
Key Results
- Utterance-level detoxification: FGDILP significantly outperforms prompt-based baselines on the RealToxicityPrompts dataset, achieving lower Expected Maximum Toxicity (Exp. Max. Tox.) and Toxicity Probability (Tox. Prob.). For instance, FGDILP achieved an Exp. Max. Tox. of 0.526 and Tox. Prob. of 51.9% on GPT-2-Large, outperforming SD (0.730, 81.6%) and SDVTR (0.607, 62.6%).
- Context-level detoxification: On the FFT dataset, FGDILP also demonstrates superior performance across various LLM backbones (Llama-2-7B, Llama-2-chat-7B, Vicuna-7B), showing reduced toxicity scores.
- Human evaluation: Human evaluations confirm FGDILP's effectiveness, showing it to be less toxic than baselines like DAPT and GeDi, and comparable or better in fluency and coherence than SDVTR.
- Trade-offs: The method incurs a slight cost in generation fluency and diversity compared to some baselines, though it remains within acceptable bounds.
- Model Size Consistency: FGDILP's effectiveness is observed across various model sizes, from LiteLlama (460M) to Llama-2-7B.
Limitations and Future Work
- Reliance on LLM's self-knowledge: The method's effectiveness is dependent on the LLM's pre-existing knowledge of toxicity types. If specific toxicity types are absent in the pre-training data, prefix identification might be uncertain.
- Template dependency: The use of predetermined template structures for self-diagnosis can influence attribute classification.
- Evaluation tool limitations: The reliance on tools like Perspective API and Llama-Guard means that inaccuracies in these tools can affect evaluation outcomes, especially for implicitly toxic content.
- Human evaluation constraints: While human evaluation is crucial, it's resource-intensive and can be influenced by individual biases.
- Incomplete mitigation: The authors acknowledge that their method cannot entirely eliminate toxic content but aims to reduce its probability and severity.
- Future Work: The paper suggests further research into refining the approach to mitigate toxicity while maintaining superior output quality, exploring more sophisticated fusion strategies, and addressing the limitations of self-diagnosis and evaluation tools.
Summary updated