Detecting and Filtering Unsafe Training Data via Data Attribution with Denoised Representation

Yijun Pan, Taiwei Shi, Jieyu Zhao, Jiaqi W. Ma

Introduction

Large language models (LLMs) are incredibly sensitive to even minuscule amounts of unsafe training data. Finding these harmful "needles in the haystack" is notoriously difficult because the vast majority of tokens in a toxic sentence are actually benign. This paper introduces Denoised Representation Attribution (DRA), a novel method designed to filter out the "noise" of neutral language, allowing developers to precisely identify and remove the training samples that most strongly influence unsafe model behaviors.

The Challenge of Unsafe Data Detection

Training a safe LLM is a constant battle against poisoned or naturally biased data. Even a handful of bad examples can lead to jailbreaks, toxicity, or harmful biases. Current solutions generally fall into two camps, both of which have significant limitations:

  1. Moderation Classifiers: Tools like Llama-Guard or OpenAI's moderation API flag content based on fixed categories. However, they are computationally expensive to train and often fail to catch subtle, model-specific influences or emerging threats outside their predefined taxonomies.
  2. Data Attribution: This approach measures how similar a training sample is to a known "unsafe" output (the target). The core problem with existing data attribution is the "averaging trap." Most of an unsafe sentence consists of neutral noise—stop words like "the" or "is," along with benign factual information. When the mathematical representations (embeddings or gradients) of a whole sentence are averaged, this noise drowns out the signal of the few critical tokens that actually make the text unsafe.

Denoised Representation Attribution (DRA)

To sharpen the signal-to-noise ratio in data attribution, the authors propose DRA. This plug-and-play approach can be applied to both hidden states (RepSim-DRA) and gradients (GradSim-DRA). It operates in two main stages:

  • Centering and Whitening: Motivated by signal detection theory, DRA first centers the data and applies "whitening" via Principal Component Analysis (PCA). This step downweights high-variance dimensions that typically represent general topics or linguistic styles rather than actual "unsafeness."
  • Dimension Selection via Leave-Target-Out (LTO): Because developers rarely know exactly which training samples are unsafe, DRA uses a small set of "target" unsafe model responses as a surrogate. It identifies the specific mathematical dimensions that best separate these target examples from the general training distribution.
  • The DRA Score: By projecting training data onto these denoised dimensions, the system calculates a similarity score. Samples with the highest scores are flagged as the most likely culprits for the model's unsafe behavior.

Experimental Setup

The researchers evaluated DRA across several primary scenarios to test its robustness and utility:

  • Jailbreaking Injection: Using UltraChat-200k as a benign base, researchers injected unsafe samples from ToxicChat and XSTest-Response.
  • Gender Bias Mitigation: The Bias in Bios dataset was used to create a poisoned dataset where female physicians were intentionally mislabeled as nurses to induce occupational bias.
  • General Utility: The MMLU benchmark was utilized to ensure that filtering out unsafe data did not accidentally degrade the model's general knowledge and reasoning capabilities.

Key Findings and Results

DRA demonstrated substantial improvements over state-of-the-art methods, proving that you do not need a massive labeled dataset of bad training data to find culprits—as few as three examples of the targeted bad behavior can suffice.

  • Detection Accuracy: DRA significantly boosted the Area Under the Precision-Recall Curve (AUPRC). For Llama-3-8B, GradSim-DRA improved detection by 63.3% over the standard baseline.
  • Retraining Safety: After identifying and removing the top 500 unsafe samples and retraining the model, the Attack Success Rate (ASR) dropped by up to 39.9%.
  • Bias Reduction: In gender bias tests, DRA-based filtering reduced the "TPR Gender Gap" far more effectively than standard moderation classifiers, which often struggle to detect implicit biases.
  • Safety Without Sacrifice: Crucially, filtering with DRA significantly improved safety metrics without causing a meaningful drop in general performance on benchmarks like MMLU.

Limitations and Future Directions

While DRA represents a significant step forward, the authors note a few limitations. Currently, the work treats "unsafeness" as a broad, binary category and does not yet provide a fine-grained taxonomy (e.g., separating hate speech from privacy leaks). Furthermore, the method's effectiveness relies heavily on having a representative set of target unsafe behaviors; future work could explore how to automatically generate or discover these targets. Finally, there is a risk of adversarial vulnerability: if an attacker knows the specific attribution method being used, they might be able to strategically craft unsafe data designed to hide within the noise.

Summary updated

BibTeX
@inproceedings{pan2026detecting,
  author = {Yijun Pan and Taiwei Shi and Jieyu Zhao and Jiaqi W. Ma},
  title = {{Detecting and Filtering Unsafe Training Data via Data Attribution with Denoised Representation}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=M9DDNGIM7Z},
}
Figure