Home

Awesome

Distilling Causal Effect from Miscellaneous Other-Class for Continual Named Entity Recognition (EMNLP2022)

This repo provides the source code for our method

Besides, we also provide re-implementation of the following methods for a fair comparison:

<img src="imgs/other-class.png" width = "400" alt="Other-Class in Continual NER" align=center /> <img src="imgs/model_architecture.png" width = "600" alt="The architecture of the proposed method (CFNER)" align=center />

Overview of the directory

.
├── config
│   ├── conll2003
│   ├── ontonotes5
│   ├── i2b2
│   └── default.yaml
├── datasets
│   └── NER_data
│       ├── conll2003
│       ├── i2b2
│       └── ontonotes5
├── main_CL.py
└── src
    ├── config.py
    ├── dataloader.py
    ├── model.py
    ├── trainer.py
    ├── utils_log.py
    ├── utils_plot.py
    └── utils.py

Step 0: Prepare your environments

Reference environment settings:

python             3.7.13
torch              1.12.1+cu116
transformers       4.14.1

If you want to repreduce the results or use the same data splits of our paper, please download the ./datasets/ foloder in this link and skip Step 1 and 2.

Step 1: Prepare your data

Download data and preprocess them as the following format (word + \t + NER_tag):

SOCCER	O
-	O
JAPAN	B-location
GET	O
LUCKY	O
WIN	O
,	O
CHINA	B-person
IN	O
SURPRISE	O
DEFEAT	O
.	O

Then, save the training/testing/developing set to a txt file named train.txt/test.txt/dev.txt and move them to the corresponding directory in ./datasets/NER_data/{dataset_name}/

Step 2: Split the dataset for continual learning

Take CoNLL2003 as an example:

if __name__ == "__main__":
   spilt_dataset(['datasets/NER_data/conll2003'], 'train', domain2entity['conll2003'], 1, 1, 'BIO')
   # the parameters nb_class_fg=1 and nb_class_pg=1 represent that the model learns 1 entity in the first CL step and learns 1 entity in the following CL steps.
python ./src/dataloader.py

Then, the program will split the dataset with the Greedy Sampling Algorithm for continual learning and store the split dataset in train_fg_1_pg_1.pth. Note that only training set needs to be split!

Step 3: Run main_CL.py

Specify your configurations (e.g., ./config/i2b2/fg_8_pg_2/i2b2_ours.yaml) and run the following command

python3 main_CL.py --exp_name {your_experiment_name} --exp_id {your_experiment_id} --cfg {your_configuration}

Then, the results as well as the model checkpoint will be saved automatically in the directory ./experiments/{your_experiment_name}/{your_experiment_id}/

Experimental results

DatasetMethodFG-1-PG-1****FG-2-PG-2****FG-8-PG-1****FG-8-PG-2****
****Mi-F1Ma-F1Mi-F1Ma-F1Mi-F1Ma-F1Mi-F1Ma-F1
I2B2Finetune Only17.4313.8128.5721.4320.8318.1123.6023.54
****PODNet12.3117.1434.6724.6239.2627.2336.2226.08
****LUCIR43.8631.3164.3243.5357.8633.0468.5446.94
****ST31.9814.7655.4433.3849.5123.7748.9429.00
****ExtendNER42.8524.0557.0135.2943.9523.1252.2530.93
****CFNER(Ours)62.7336.2671.9849.0959.7937.3069.0751.09
OntoNotes5Finetune Only15.2710.8525.8520.5517.6312.2329.8120.05
****PODNet9.068.3634.6724.6229.0020.5437.3825.85
****LUCIR28.1821.1164.3243.5366.4646.2976.1755.58
****ST50.7133.2468.9350.6373.5949.4177.0753.32
****ExtendNER50.5332.8467.6149.2673.1249.5576.8554.37
****CFNER(Ours)58.9442.2272.5955.9678.9257.5180.6860.52
MethodFG-1-PG-1****FG-2-PG-1****
****Mi-F1Ma-F1Mi-F1Ma-F1
Finetune Only50.8440.6457.4543.58
PODNet36.7429.4359.1258.39
LUCIR74.1570.4880.5377.33
ST76.1772.8876.6566.72
ExtendNER76.3673.0476.6666.36
Ours80.9179.1180.8375.20

If you find the code useful, please consider citing this work

Junhao Zheng, Zhanxian Liang, Haibin Chen, and Qianli Ma. 2022. Distilling Causal Effect from Miscellaneous Other-Class for Continual Named Entity Recognition. In Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing, pages 3602–3615, Abu Dhabi, United Arab Emirates. Association for Computational Linguistics.