
Research framework for detecting and removing backdoors in language models, combining feature-based anomaly detection with LoRA-based unlearning across BERT, BART, LLaMA, and Qwen.
This is the official repository for the paper:
DUP: Detection-guided Unlearning for Backdoor Purification in Language Models
DUP introduces a unified framework that combines feature-based anomaly detection with parameter-efficient unlearning to remove backdoors from pre-trained language models. It is effective across both traditional PLMs and modern LLMs, including BERT, BART, LLaMA 3B, and Qwen 3B.
The DUP framework is implemented and tested under the following environment:
Python: 3.10
OS: Ubuntu 22.04
CUDA: 11.8
PyTorch: 2.1.2
Accelerate: 1.0.1
PEFT: 0.12.0
language-tool-python: 2.8.1
Download the following models and place them under the /victim_models directory:
bert-base-uncasedbart-baseLLaMA-3.2-3B-InstructQwen2.5-3BThe poisoned datasets are already prepared and located in /poison_data
To launch backdoor attacks:
python demo_attack.py
Supported attacks:
This module identifies poisoned inputs using Mahalanobis Distance and Spectral Signature scores with adaptive layer selection.
python demo_detection.py
This module removes backdoors using LoRA-based distillation guided by detection:
python demo_unlearning.py
.
├── victim_models/ # Pretrained model weights
├── poison_data/ # poisoned datasets
├── openbackdoor/ # Core implementation of backdoor attacks and defenses
├── demo_attack.py # Backdoor attack scripts
├── demo_detection.py # Detection procedure
├── demo_unlearning.py # Unlearning procedure
└── README.md # Project documentation