📢 News: this work has been accepted at the EMNLP 2025 main conference!
📢 News: Our another work "Decoupling Reasoning and Knowledge Injection for In-Context Knowledge Editing" (DecKER) has been accepted to Findings of ACL 2025! 🎉
DecKER disentangles knowledge injection from reasoning in in-context editing, further enhancing editing performance. We welcome your attention and support!
Like our project? ⭐ A star from you would be the best encouragement!
EditCoT accomplishes knowledge editing by modifying the chain of thought generated by the model. In this repository, we provide:
- Complete framework code for EditCoT.
- All code for training the CoT Editor, including data generation, post-processing, and model training.
- Code for evaluating EditCoT on MQuAKE-CF-3k.
conda create -n editcot python=3.10
conda activate editcot
pip install -r ./requirements.txtThe ./all_prompts directory contains all the prompts involved in generating datasets and editing chains of thought for EditCoT.
The ./dataset_construct directory includes the code for generating datasets with EditCoT.
The ./train_editor directory contains the code for training the CoT Editor.
The ./eval directory includes the code for evaluating EditCoT on MQuAKE-CF-3k.
Run the following command:
bash ./dataset_construct/data_construct.shNote that this command will generate intermediate data and the final dataset (dataset.json) in the ./dataset_construct/output directory.
For training convenience, we provide a dataset constructed from Meta-Llama-3-8B-Instruct, located at ./dataset_construct/output/llama3_dataset.json (note: as mentioned in the paper, this dataset samples 80% of the generated data).
Run the following command:
bash ./train_editor/train.shRun the following command:
cd ./eval
python eval.pyNote that you need to set the --editor_path parameter to the path of the trained CoT Editor from the previous step. If you need to modify the model path, maximum epochs, or other parameters, please refer to the parameter settings in eval.py.
The results on MQuAKE-CF-3k are as follows (using Multihop-Accuracy as the evaluation metric):
| Method | Meta-Llama-3-8B-Instruct | Qwen2.5-14B-Instruct |
|---|---|---|
| EditCoT | 35.4 | 34.2 |