Machine Unlearning in Large Language Models

Kongyang Chen, Zixin Wang, Bing Mi, Waixi Liu, Shaowei Wang, Xiaojun Ren, Jiaxing ShenarXiv 2024

Abstract

Recently, large language models (LLMs) have emerged as a notable field, attracting significant attention for its ability to automatically generate intelligent contents for various application domains. However, LLMs still suffer from significant security and privacy issues. For example, LLMs might expose user privacy from hacking attacks or targeted prompts. To address this problem, this paper introduces a novel machine unlearning framework into LLMs. Our objectives are to make LLMs not produce harmful, hallucinatory, or privacy-compromising responses, while retaining their standard output capabilities. To accomplish this, we use an evaluative model to pinpoint dialogues needing unlearning. We also establish a distance loss to function as the model's negative loss, diverting it from previous undesirable outputs. Furthermore, we determine the expected output's cluster mean to formulate a positive loss, directing the model's outputs toward preferable outcomes without compromising its reasoning abilities and performance. Experimental results show that our approach effectively meets unlearning objectives without substantially compromising model performance.

Introduction

Large Language Models (LLMs) are trained on massive swaths of the internet, which inevitably includes toxic content, copyrighted material, and private data. Once a model is trained, "deleting" this information is notoriously difficult. Standard alignment techniques like Reinforcement Learning from Human Feedback (RLHF) are resource-heavy and slow, and simple fine-tuning on "safe" data often fails to fully erase underlying problematic patterns.

This paper presents a surgical approach to "forgetting" undesirable behaviors—such as hallucinations, privacy leaks, and harmful biases—without the prohibitive cost of retraining from scratch. The proposed framework uses a dual-loss strategy to redirect the model away from harmful outputs toward a high-dimensional "cluster center" of safe responses.

Methodology

The researchers introduce a three-pronged fine-tuning objective to achieve effective unlearning:

  1. Negative Samples (The "Push"): To stop the model from generating specific harmful outputs, a negative loss is used. By maximizing cross-entropy loss for these samples, the system effectively teaches the model what not to say.
  2. Positive Samples (The "Pull"): To maintain coherence, the model is trained to gravitate toward a clustering center in a high-dimensional feature space. This center is derived from a corpus of safe, normal data, ensuring the model adopts a safer tone without needing manually curated labels for every prompt.
  3. Normal Samples (The "Anchor"): To prevent "catastrophic forgetting" of general intelligence, Kullback-Leibler (KL) divergence acts as an anchor, keeping the model’s probability distribution on standard tasks close to the original pre-trained state.
The proposed machine unlearning framework utilizes an evaluative model to identify problematic outputs and directs the LLM toward harmless responses through an unlearning process.

An optimization trick involving a "conditional judgment" mechanism further enhances performance. If a training sample already meets unlearning criteria, it is assigned minimal weight, preventing overtraining and speeding up convergence.

Experimental Results

The framework was evaluated on ChatGLM2 and OPT-1.3B using benchmarks such as PKU-SafeRLHF, HaluEval, and TruthfulQA.

Efficiency and Speed

A primary advantage of this method is its speed. The framework required only 1% of the time taken by standard RLHF and approximately 50% of the time required by other state-of-the-art unlearning methods.

Run time comparison demonstrating that the proposed method achieves unlearning in a fraction of the time required by Full RLHF and standard fine-tuning.

Safety and Performance

  • Safety Improvements: Harmful scores improved significantly; for instance, ChatGLM2's score moved from -5.82 to 0.15 (where higher is safer).
  • Knowledge Erasure: In targeted tests, the "leak rate" of specific information was reduced to 0%.
  • Performance Retention: Crucially, metrics like BLEURT and Fluency on normal questions remained stable, indicating that the model retained its general reasoning and language capabilities.

Discussion and Conclusion

The study highlights that unlearning is most effective when treated as redirection rather than simple deletion. For hallucinations, teaching the model to gravitate toward neutral responses (e.g., "I am not familiar with that term") proved more effective than forcing correct answers during the unlearning phase.

While the method is highly efficient, future work is needed to establish standardized metrics for "forgetting" and to test the scalability of these dynamics on models exceeding 70B parameters. Despite these challenges, this framework provides a robust and lightweight solution for improving LLM safety and privacy.

Summary updated

BibTeX
@misc{chen2024machine,
  author = {Kongyang Chen and Zixin Wang and Bing Mi and Waixi Liu and Shaowei Wang and Xiaojun Ren and Jiaxing Shen},
  title = {{Machine Unlearning in Large Language Models}},
  year = {2024},
  eprint = {2404.16841},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2404.16841},
}
Figure