https://github.com/zjunlp/unlearn
Knowledge Unlearning for Large Language Models
https://github.com/zjunlp/unlearn
artificial-intelligence copyright knowledge-editing knowledge-unlearning large-language-models machine-unlearning natural-language-processing privacy semeval-2025 unlearning
Last synced: 4 months ago
JSON representation
Knowledge Unlearning for Large Language Models
- Host: GitHub
- URL: https://github.com/zjunlp/unlearn
- Owner: zjunlp
- License: mit
- Created: 2023-04-28T09:01:25.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-05-05T06:05:16.000Z (5 months ago)
- Last Synced: 2025-05-05T07:22:55.532Z (5 months ago)
- Topics: artificial-intelligence, copyright, knowledge-editing, knowledge-unlearning, large-language-models, machine-unlearning, natural-language-processing, privacy, semeval-2025, unlearning
- Language: Python
- Homepage:
- Size: 506 KB
- Stars: 25
- Watchers: 4
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Knowledge Unlearning for Large Language Models
πarXiv β’
π€HFPaper β’
π€HF CollectionThis repository provides the official PyTorch implementation of our paper:
> **ReLearn: Unlearning via Learning for Large Language Models**
>
> Haoming Xu1, Ningyuan Zhao2, Liming Yang3, Sendong Zhao4, Shumin Deng5, Mengru Wang1, Bryan Hooi5, Nay Oo5, Huajun Chen1, Ningyu Zhang1
>
> 1Zhejiang University, 2Xiamen University, 3Tsinghua University, 4Harbin Institute of Technology, 5National University of Singapore## π News
π Our team won 2nd place in the [**SEMEval 2025 Challenge on Unlearning Sensitive Content from Large Language Models**!](https://llmunlearningsemeval2025.github.io/) Check out our implementation in the `Semeval25` directory.
## π Overview

## π¦ Installation
```bash
# Create and activate conda environment
conda create -n relearn python=3.10.15
conda activate relearn# Install PyTorch with CUDA support
conda install pytorch pytorch-cuda=11.8 -c pytorch -c nvidia
conda install -c "nvidia/label/cuda-11.8.0" cuda-toolkit# Install dependencies
pip install -r requirements.txt
pip install flash-attn --no-build-isolation
```## π Quick Start
### 1. Data Augmentation
```bash
cd dataAugument
bash augu.sh
```### 2. Model Training
Currently supports:
- Llama3-8b instruct
- Gemma2-2b-it
- Llama2-7b chat```bash
cd baselines/pretrain_scripts/
bash kud-pt.sh
```### 3. Unlearning Process
```bash
cd baselines/unlearn_scripts/
bash kud-relearn.sh
```### 4. Evaluation
```bash
cd evals
bash merge_all.sh
bash inf_all.sh
bash eval_all.sh
```
**Note:** If you plan to use KFR and KRR, please configure the API in [`dataAugment/utils.py`](https://github.com/zjunlp/unlearn/blob/main/dataAugument/utils.py).## π§ Supported Methods
| Method | Script |
| ----------- | ---------------------------------------------------- |
| GA / NPO | `unlearn/baselines/unlearn_scripts/kud-baselines.sh` |
| SURE | `unlearn/baselines/unlearn_scripts/kud-baselines.sh` |
| Memflex (Iterative version) | `unlearn/baselines/unlearn_scripts/kud-baselines.sh` |
| ReLearn | `unlearn/baselines/unlearn_scripts/kud-relearn.sh` |
| ReLearn_dpo | `unlearn/baselines/unlearn_scripts/kud-relearn.sh` |## π Open Resources
### Pretrained Models
- **Llama-2-7b-chat-KnowUnDo-Privacy (Vanilla)**
[π ModelScope](https://www.modelscope.cn/models/haomingx/Llama-2-7b-chat-KnowUnDo-Privacy/files)- **Llama-2-7b-chat-TOFU-Forget10-ReLearn**
[π Google Drive](https://drive.google.com/drive/folders/1wsPKpF2IZ4RC52_PI7ILhYsegtqZG25Y?usp=drive_link)- **Llama-2-7b-chat-KnowUnDo-Privacy-ReLearn**
[π Google Drive](https://drive.google.com/drive/folders/1R7wSu1kegr0Ui4x_R-5L5vg4vuoFhskM?usp=drive_link)### Datasets
- **Augmented KnowUnDo Privacy Dataset**
[π Google Drive](https://drive.google.com/file/d/1lct2s3Xs8JKv4CL-LlBZHXTP9H1AKeg5/view?usp=drive_link)
- **Augmented ToFU Forget01 Dataset**
[π Google Drive](https://drive.google.com/file/d/16NtfMeB_4ISApuVrJnQHo26EKjT9xzvz/view?usp=sharing)### Inference & Eval Results
- **Llama-2-7b-chat KnowUnDo Privacy**
[π Google Drive](https://drive.google.com/drive/folders/169E1HDgZGcDTKAJcKJX17SoQtpkkd1pV?usp=drive_link)
## π Acknowledgements
We would like to express our heartfelt gratitude for the contribution of [KnowUnDo](https://github.com/zjunlp/KnowUnDo), [TOFU](https://github.com/locuslab/tofu), [MUSE](https://github.com/jaechan-repo/muse_bench), [SURE](https://github.com/zzwjames/FailureLLMUnlearning) [Open-Unlearning](https://github.com/locuslab/open-unlearning) to our project, as we have utilized portions of their source code in our project.## π Citation
If you find this work useful for your research, please cite [our paper](https://arxiv.org/abs/2502.11190):
```bibtex
@article{xu2025relearnunlearninglearninglarge,
title={ReLearn: Unlearning via Learning for Large Language Models},
author={Haoming Xu and Ningyuan Zhao and Liming Yang and Sendong Zhao and
Shumin Deng and Mengru Wang and Bryan Hooi and Nay Oo and
Huajun Chen and Ningyu Zhang},
journal={arXiv preprint arXiv:2502.11190},
year={2025}
}```