Contrastive Representation Shaping for LLM Unlearning

Haoran Tang, Rajiv KhannaNeurIPS 2026

TL;DR

When we ask a Large Language Model (LLM) to "unlearn" copyrighted or dangerous data, most current methods simply train the model to suppress those outputs—meaning the forbidden knowledge still lurks inside its internal representations, tangled up with everything else. This paper introduces CLReg, a plug-and-play contrastive regularizer that physically separates "forget" concepts from "retain" concepts in the model’s latent space. By untangling these representations, existing unlearning algorithms can snip out unwanted memories much cleanly, preserving general model utility and resisting attacks that try to jog the model's memory.

What Problem Does This Paper Address?

Retraining a massive LLM from scratch every time you need to delete proprietary, private, or hazardous training data is prohibitively expensive. This has sparked a boom in approximate machine unlearning: cheap fine-tuning tricks designed to make a model behave as if it never saw the "forget set" while keeping its performance on the "retain set" intact.

Today’s leading LLM unlearning methods (like NPO and SimNPO) operate in the prediction space—adjusting final output probabilities so the model stops generating forgotten facts. The catch? Suppressing an output doesn't erase the underlying concept. Inside the model's hidden layers, representations of forgotten data remain tightly entangled with retained knowledge. Because the knowledge is merely muzzled rather than removed, trying to erase it aggressively causes collateral damage to general capabilities, and a tiny bit of adversarial fine-tuning (a "relearning attack"—here, just 32 steps!) can bring over half the "forgotten" knowledge right back.

Methods

Instead of inventing a brand-new unlearning algorithm from scratch, the authors propose Contrastive Representation Regularization (CLReg)—an add-on penalty term ($\mathcal{L}_{\text{CL}}$) that can be bolted onto any standard unlearning objective ($\mathcal{L} = \alpha\mathcal{L}_{\text{retain}} + \gamma\mathcal{L}_{\text{forget}} + \lambda\mathcal{L}_{\text{CL}}$).

While contrastive learning usually relies on neat class labels, generative LLMs don't have them. Here is how CLReg adapts standard contrastive mechanics to self-supervised LLMs:

  • Positive Pairs (What to cluster): Given a "forget" example, the authors create an augmented twin using pre-computed LLM paraphrases and randomized dropout masks on the hidden states. Mean-pooled, normalized embeddings of these pairs are pulled together to isolate a coherent "forget subspace."
  • Negative Pairs (What to repel): Embeddings from the "retain" set act as negatives. Using a DPO-style sigmoid loss (or standard InfoNCE), CLReg pushes the forget cluster away from retain features.
  • Targeted Layer Selection: Rather than perturbing the whole network, CLReg is applied only to the final transformer layer, where high-level semantic concepts live.

Datasets

No new benchmarks were introduced; the authors evaluate across three established unlearning suites spanning four models (Llama-3.1-8B, Llama-3.2-3B, Llama-2-7B, and Zephyr-7B-$\beta$):

  • TOFU: Synthetic author biographies designed to test precise factual forgetting.
  • MUSE (Books & News): Tests unlearning of verbatim and high-level knowledge from Harry Potter books and news articles, alongside sequential unlearning requests.
  • WMDP (WMDP-cyber): Evaluates the removal of real-world hazardous cybersecurity knowledge.

Key Insights and Ideas

  • Untangling causes easier unlearning: To prove CLReg isn't just adding extra gradient noise, the authors ran a two-stage experiment: first, they shaped the latent space with CLReg without any forgetting objective at all, then ran an unmodified unlearning method. Just pre-separating the representations boosted final unlearning scores (+0.037 for SimNPO, +0.050 for NPO) over compute-matched baselines.
  • Retain geometry stays put: A common fear in unlearning is that warping internal representations will break the model. UMAP projections reveal something remarkable: CLReg leaves the retain cluster sitting calmly in its original compact coordinate range (roughly $[-10, 10]$), while flinging forget features far out into the periphery (up to $[-30, 40]$).
UMAP projections showing how CLReg flings orange 'Forget' features far outside the central blue 'Retain' cluster while preserving the retain cluster's scale and shape.
  • Leave the early layers alone: Applying CLReg to earlier transformer layers consistently hurts model utility. Early layers handle shared syntax and foundational knowledge; high-level semantic forgetting belongs at the top of the network.
  • Structured separation beats random noise: Compared to RMU (a baseline that scrambles forget activations toward a random vector), CLReg's directional push away from retain features preserves utility much better.

Key Results

  • Universal Boost: Across 25 method–benchmark pairs (testing GradDiff, UNDIAL, NPO, SimNPO, and PDU), adding CLReg improved the aggregate UnlearningScore (the harmonic mean of forgetting quality and model utility) in all 25 cases.
  • Headline Gains: SimNPO+CL achieved the top score on every benchmark—e.g., lifting TOFU-8B from $0.774 \to 0.813$ (beating RMU's $0.704$) and MUSE-News from $0.461 \to 0.572$. GradDiff+CL saw the largest single jump, leaping from $0.411 \to 0.738$ on MUSE-Books.
  • Massive Disentanglement & Privacy Balance: CLReg slashed variance-based representation entanglement by up to 88% (from $92.2 \to 11.1$ on MUSE-News) and pulled privacy leakage (|PrivLeak|) much closer to the ideal zero mark (e.g., $62.0 \to 3.7$ on TOFU-3B).
  • Durability: Under sequential unlearning (4 consecutive requests on MUSE-News), plain SimNPO lost 37.1% of its retain knowledge, whereas SimNPO+CL eroded by only 3.0%. It also significantly slowed down knowledge recovery under 64-step fine-tuning attacks, all at the cost of one extra forward pass (34–49% wall-clock training overhead) and zero extra parameters.

Limitations and Future Work

  • Slows, doesn't stop, relearning: CLReg is a regularizer that assists a base algorithm, not a standalone memory wiper. While it makes adversarial relearning significantly harder, it slows recovery rather than preventing it completely.
  • Lightweight theory: The mathematical justification is strictly a one-step gradient analysis on an embedding proxy; it offers intuition rather than formal multi-step or retain-side guarantees.
  • Sequential trade-offs & layer rigidity: Over long chains of sequential unlearning requests, per-request forgetting strength gradually weakens even as utility holds steady. Furthermore, targeting the final layer works for semantic facts, but unlearning stylistic or syntactic patterns residing in earlier layers will likely require automated layer-wise probing—a prime avenue for future work, alongside surgically clipping out the isolated "outlier" forget features.

Summary updated

Abstract

Most LLM unlearning methods aim to approximate retrain-from-scratch behaviors with minimal distribution shift, often via alignment-style objectives defined in the prediction space. While effective at reducing forgotten content generation, such approaches may act as suppression: forgotten concepts can persist in representations and remain entangled with retained knowledge. We introduce CLReg, a contrastive representation regularizer that identifies forget features while pushing them away from retain features, reducing forget--retain interference while empirically preserving the scale and shape of retain features. As light motivation for the mechanism, we provide a one-step analysis showing that CLReg decreases a simple entanglement proxy in the embedding space. Across unlearning benchmarks and LLMs of different sizes, CLReg decreases forget-retain representation entanglement to enhance mainstream unlearning methods without extra privacy risks, inspiring future unlearning work to remove forget concepts via representation shaping.
BibTeX
@inproceedings{tang2026contrastive,
  author = {Haoran Tang and Rajiv Khanna},
  title = {{Contrastive Representation Shaping for LLM Unlearning}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=YRlb8TydTR},
}
Figure