This repository contains code for machine unlearning experiments, including:
- Data poisoning and visualization
- Hessian-based analysis of model landscapes
- Various unlearning methods comparison (Retrain, Finetune, Scrub, Grad-Asc)
- Evaluation of unlearning effectiveness on both classical MLP and quantum neural networks
datar.py: Data preprocessing and loading functionsmodels.py: Model definitions for both MLP and QNNpoison_unlearn.py: Implementation of various unlearning methodsrun_unlearn_mnist.py: Main script for MNIST unlearning experimentsrun_unlearn_xxz.py: Main script for XXZ model unlearning experimentstest_mnist.ipynb: Jupyter notebook for MNIST experiments visualizationtest_xxz.ipynb: Jupyter notebook for XXZ model experiments visualizationheissian.ipynb: Hessian-based analysis of model landscapesrun_example.py: Example script demonstrating how to run the code
- Python 3.x
- TensorFlow
- JAX
- TensorCircuit
- Optax
- Scikit-learn
- NumPy
- Matplotlib
- Seaborn
Install all requirements with:
pip install -r requirements.txtRun the example script to test the code:
python run_example.pyTo run the MNIST unlearning experiments:
python run_unlearn_mnist.pyTo run the XXZ model unlearning experiments:
python run_unlearn_xxz.pyNote: The XXZ experiments require specific dataset files that are not included in this repository.
The results can be visualized using the provided Jupyter notebooks:
test_mnist.ipynb: For MNIST experiment resultstest_xxz.ipynb: For XXZ model experiment resultsheissian.ipynb: For Hessian-based analysis
The repository implements several machine unlearning methods:
- Retrain: Retrain the model from scratch on the retained data
- Fine-tune (cf): Continue training on the retained data
- Scrub: Use KL divergence regularization to "scrub" the influence of forgotten data
- Gradient Ascent (ga): Use gradient ascent to actively unlearn the forgotten data
Two types of models are implemented:
- Classical MLP: Multi-layer perceptron with configurable hidden layers
- Quantum Neural Network (QNN): Quantum circuit-based model using TensorCircuit
The code supports experiments on:
- MNIST: Binary classification of digits 1 and 9
- XXZ Model: Quantum many-body system data (requires external dataset files)
The experiments evaluate:
- Validation Accuracy: Performance on clean validation data
- Forgetting Accuracy: Ability to forget the "unlearned" data
- Model Stability: Robustness of the unlearning process
This project is licensed under the MIT License - see the LICENSE file for details.