An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# Knowledge Unlearning for Large Language Models


πŸ“„arXiv β€’
πŸ€—HFPaper β€’
πŸ€—HF Collection

This 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

![Introduction](images/intro.jpg)

## πŸ“¦ 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}
}

```