Towards Safer Large Language Models through Machine Unlearning

Zheyuan Liu, Guangyao Dou, Zhaoxuan Tan, Yijun Tian, Meng Jiang

Abstract

Large Language Models (LLMs) are trained on vast datasets that inevitably contain toxic, biased, or dangerous information. While alignment techniques like Reinforcement Learning from Human Feedback (RLHF) are standard, they are often computationally intensive and brittle. Machine Unlearning (MU) offers a more efficient alternative by teaching models to "forget" specific data, yet traditional MU methods frequently suffer from "catastrophic forgetting," where the model loses general utility. This paper introduces Selective Knowledge negation Unlearning (SKU), a surgical framework designed to remove harmful behaviors while preserving the model's core intelligence. By isolating a "harmful knowledge delta" and subtracting it from the original model, SKU achieves a superior balance between safety and performance across multiple architectures.

Introduction

The proliferation of LLMs has raised significant safety concerns regarding their ability to generate harmful content. Current mitigation strategies often face a trade-off: they either fail to fully suppress harmful outputs or they "lobotomize" the model, rendering it incoherent. For instance, Gradient Ascent (GA), a common unlearning technique, effectively reduces harmfulness but often causes the model's perplexity to skyrocket, resulting in gibberish outputs. The fundamental challenge lies in deleting specific "bad" knowledge without damaging the "good" knowledge that constitutes the model's utility.

Methodology: The SKU Framework

The authors propose a two-stage framework that first identifies and then negates harmful knowledge with high precision.

Stage 1: Harmful Knowledge Acquisition

Rather than attempting to forget immediately, the model is first trained to isolate harmful patterns. This stage utilizes three distinct modules:

  1. Guided Distortion Module: The model learns to respond accurately to harmful prompts to "locate" the toxic knowledge within its parameters.
  2. Random Disassociation Module: To prevent simple memorization of specific answers, the model is trained on mismatched harmful pairs (e.g., pairing a prompt about bank robbery with an answer about explosives). This forces the model to learn the underlying concept of harm rather than specific strings.
  3. Preservation Divergence Module: Using a negative KL-divergence loss, this module ensures that while the model learns harmful patterns, its performance on "normal" prompts remains as close to the original pretrained model as possible.

Stage 2: Knowledge Negation

Once a "bad" version of the model ($\theta_{bad}$) is created, the researchers calculate a Task Vector—the mathematical difference between the "bad" model and the original pretrained model ($\theta_{o}$). By subtracting this vector from the original model, they effectively erase the specific neural pathways associated with harmful outputs, resulting in a safer model ($\theta_{u}$).

The two-stage SKU framework: Stage 1 isolates harmful knowledge through three modules, and Stage 2 negates that knowledge using task vectors.

Experimental Setup

The SKU framework was evaluated using several benchmarks:

  • PKU-SafeRLHF: Served as the "forget set" containing harmful question-answer pairs.
  • TruthfulQA: Used to monitor the model's utility and truthfulness.
  • Wiki-103: Used as a reference for calculating perplexity, a metric for text coherence.

The experiments were conducted across three model architectures: OPT-2.7B, LLAMA2-7B, and LLAMA2-13B.

Key Results and Analysis

SKU consistently outperformed traditional baselines in maintaining a balance between safety and utility.

Safety and Utility Trade-off

As shown in the experimental results, SKU significantly reduced harmful response rates while maintaining low perplexity. For example, on the LLAMA2-7B model, SKU reduced the harmful rate from 57% to 3%. While Gradient Ascent (GA) achieved a slightly lower harmful rate (1-2%), it rendered the model unusable, with perplexity scores exceeding 1000. In contrast, SKU maintained a perplexity of ~24.86, which is remarkably close to the original model's performance.

Generalization to Unseen Prompts

A critical finding was SKU's ability to generalize. The model did not just "patch" the specific prompts it was trained on; it also showed a significant reduction in harmfulness when faced with unseen harmful prompts, dropping the rate from 55% to 3.5% on LLAMA2-7B.

Main results comparing SKU against baselines. SKU achieves a low harmful rate while maintaining utility (low perplexity and high BLEURT scores) comparable to the original model.

Conclusion and Future Work

Selective Knowledge negation Unlearning (SKU) demonstrates that it is possible to surgically remove harmful behaviors from LLMs without sacrificing general intelligence. By intentionally "knowing the enemy" through a controlled acquisition stage, researchers can create precise negation vectors that protect the model's utility.

Future research will focus on reaching a 0% harmful rate and testing the framework's robustness against sophisticated adversarial "jailbreak" attempts. Additionally, the authors suggest that SKU could be applied to other unlearning scenarios, such as the removal of copyrighted material or personally identifiable information (PII) to satisfy "Right to be Forgotten" requirements.

Summary updated

BibTeX
@inproceedings{liu2024towards,
  author = {Zheyuan Liu and Guangyao Dou and Zhaoxuan Tan and Yijun Tian and Meng Jiang},
  title = {{Towards Safer Large Language Models through Machine Unlearning}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.findings-acl.107},
}
Figure