Selective-Unlearning-in-NLP
- Stars
- 6
- Language
- Python
- Updated
Selective Machine Unlearning in NLP
Problem Statement
This project implements selective machine unlearning for NLP models, allowing models to forget specific data points, users, or topics without full retraining. This is crucial for GDPR compliance and privacy-preserving AI.
Methodology
Dataset
- AG News: 127,600 news articles categorized into 4 classes (World, Sports, Business, Sci/Tech).
- Simulated 1000 users for user-based forgetting.
- Split: 70% train, 15% val, 15% test.
Model
- Base Model: DistilBERT fine-tuned for text classification.
- Architecture: DistilBERT encoder + linear classifier.
- Training: AdamW optimizer, Cross-Entropy loss, 3 epochs.
Unlearning Strategies
1. Gradient Ascent on Forget Set
- Why it works: Maximizes loss on forget data, pushing parameters away from forget-set minima.
- Trade-offs: Fast but may cause catastrophic forgetting; requires regularization on retain set.
- Failure cases: Large forget sets degrade performance; sensitive to hyperparameters.
2. Negative Fine-Tuning with Retention Loss
- Why it works: Fine-tunes on retain data while penalizing forget-set performance.
- Trade-offs: More stable than gradient ascent but slower; balances forgetting and retention.
- Failure cases: Weak retention loss may not fully forget; over-regularization hurts generalization.
Evaluation Metrics
- Forgetting Score: (Random_Acc - Forget_Acc) / Random_Acc (higher better)
- Retained Accuracy: Unlearned_Retain_Acc / Baseline_Retain_Acc
- Membership Inference Attack: Accuracy of detecting forgotten samples
- Runtime Analysis: Time saved vs full retraining
Results
[To be filled after experiments]
Ethical Considerations
- Ensures privacy by allowing data removal post-training.
- Prevents misuse by requiring explicit forget requests.
- Trade-off between utility and privacy.
Limitations
- Simulated users; real-world needs actual user data.
- Assumes access to original training data.
- Computational cost for large models.
Setup
pip install -r requirements.txt
python scripts/prepare_data.py
python scripts/train.py
python scripts/main.py
API Usage
- Start API:
uvicorn api.forget_request_handler:app --host 0.0.0.0 --port 8000 - Inference:
uvicorn api.inference:app --host 0.0.0.0 --port 8001 - UI:
streamlit run ui/app.py
Deployment
- Use Docker for containerization.
- Scale with Kubernetes for production.
- Monitor with logging and metrics.