Home

Awesome

PFN (Partition Filter Network)

This repository contains codes of the official implementation for the paper A Partition Filter Network for Joint Entity and Relation Extraction EMNLP 2021

Quick links

Model Overview

Framework

In this work, we present a new framework equipped with a novel recurrent encoder named partition filter encoder designed for multi-task learning.

Equation Explanation

The explanation for equation 2 and 3 is displayed here.

Preparation

Environment Setup

The experiments were performed using one single NVIDIA-RTX3090 GPU. The dependency packages can be installed with the command:

pip install -r requirements.txt

Other configurations we use are:

Data Acquisition and Preprocessing

This is the first work that covers all the mainstream English datasets for evaluation, including NYT, WebNLG, ADE, ACE05, ACE04, SCIERC, CoNLL04.

Please follow the instructions of reademe.md in each dataset folder in ./data/ for data acquisition and preprocessing.

Custom Dataset

We suggest that you use PFN-nested for other datasets, especially Chinese datasets.
PFN-nested is an enhanced version of PFN. It is better in leveraging entity tail information and capable of handling nested triple prediction.

---Reasons for Not Using the Original Model

The orignal one will not be able to decode triples with head-overlap entities. For example, if New York and New York City are both entities, and there exists a RE prediction such as (New, cityof, USA), we cannot know what New corresponds to.

Luckily, the impact on evaluation of English dataset is limited, since such triple is either filtered out (for ADE) or rare (one in test set of SciERC, one in ACE04, zero in other datasets).

---Usage

Replace the files (except for readme.md) in the root directory with the files in the PFN-nested folder, then follow the directions in Quick Start.

---Performance comparison in SciERC

ModelNERRE
PFN66.838.4
PFN-nested67.938.7

Quick Start

Model Training

The training command-line is listed below (command for CONLL04 is in Evaluation on CoNLL04):

python main.py \
--data ${NYT/WEBNLG/ADE/ACE2005/ACE2004/SCIERC} \
--do_train \
--do_eval \
--embed_mode ${bert_cased/albert/scibert} \
--batch_size ${20 (for most datasets) /4 (for SCIERC)} \
--lr ${0.00002 (for most datasets) /0.00001 (for SCIERC)} \
--output_file ${the name of your output files, e.g. ace_test} \
--eval_metric ${micro/macro} 

After training, you will obtain three files in the ./save/${output_file}/ directory:

Evaluation on Pre-trained Model

The evaluation command-line is listed as follows:

python eval.py \
--data ${NYT/WEBNLG/ADE/ACE2005/ACE2004/SCIERC} \
--eval_metric ${micro/macro} \
--model_file ${the path of saved model you want to evaluate. e.g. save/ace_test.pt} \
--embed_mode ${bert_cased/albert/scibert}

Inference on Customized Input

If you want to evaluate the model with customized input, please run the following code:

python inference.py \
--model_file ${the path of your saved model} \
--sent ${sentence you want to evaluate, str type restricted}

model_file must contain two kinds of keywords:

For example, model_file could be set as "web_bert.pt"

---Example

input:
python inference.py \
--model_file save/sci_test_scibert.pt \
--sent "In this work , we present a new framework equipped with a novel recurrent encoder   
        named partition filter encoder designed for multi-task learning ."

result:
entity_name: framework, entity type: Generic
entity_name: recurrent encoder, entity type: Method
entity_name: partition filter encoder, entity type: Method
entity_name: multi-task learning, entity type: Task
triple: recurrent encoder, Used-for, framework
triple: recurrent encoder, Part-of, framework
triple: recurrent encoder, Used-for, multi-task learning
triple: partition filter encoder, Hyponym-of, recurrent encoder
triple: partition filter encoder, Used-for, multi-task learning



input:  
python inference.py \
--model_file save/ace_test_albert.pt \
--sent "As Williams was struggling to gain production and an audience for his work in the late 1930s ,  
        he worked at a string of menial jobs that included a stint as caretaker on a chicken ranch in   
        Laguna Beach , California . In 1939 , with the help of his agent Audrey Wood , Williams was 
        awarded a $1,000 grant from the Rockefeller Foundation in recognition of his play Battle of 
        Angels . It was produced in Boston in 1940 and was poorly received ."

result:
entity_name: Williams, entity type: PER
entity_name: audience, entity type: PER
entity_name: his, entity type: PER
entity_name: he, entity type: PER
entity_name: caretaker, entity type: PER
entity_name: ranch, entity type: FAC
entity_name: Laguna Beach, entity type: GPE
entity_name: California, entity type: GPE
entity_name: his, entity type: PER
entity_name: agent, entity type: PER
entity_name: Audrey Wood, entity type: PER
entity_name: Williams, entity type: PER
entity_name: Rockefeller Foundation, entity type: ORG
entity_name: his, entity type: PER
entity_name: Boston, entity type: GPE
triple: caretaker, PHYS, ranch
triple: ranch, PART-WHOLE, Laguna Beach
triple: Laguna Beach, PART-WHOLE, California

Evaluation on CoNLL04

We also run the test on the dataset CoNLL04, and our model surpasses previous SoTA table-sequence in micro/macro RE by 1.4%/0.9%.

but we did not report the results in our paper due to several reasons:

The command for running CoNLL04 is listed below:

python main.py \
--data CONLL04 \
--do_train \
--do_eval \
--embed_mode albert \
--batch_size 10 \
--lr 0.00002 \
--output_file ${the name of your output files} \
--eval_metric micro \
--clip 1.0 \
--epoch 200

Pre-trained Models and Training Logs

Download Links

Due to limited space in google drive, 10-fold model checkpoints of ADE are not available to you.

DatasetFile SizeEmbeddingDownload
NYT393MBBert-base-casedLink
WebNLG393MBBert-base-casedLink
ACE05815MBAlbert-xxlarge-v1Link
ACE043.98GBAlbert-xxlarge-v1Link
SciERC399MBScibert-uncasedLink
ADE214KBBert + AlbertLink
CoNLL04815MBAlbert-xxlarge-v1Link

Result Display

DatasetEmbeddingEvaluation MetricNERRE
NYTBert-base-casedMicro95.892.4
WebNLGBert-base-casedMicro98.093.6
ACE05Albert-xxlarge-v1Micro89.066.8
ACE04Albert-xxlarge-v1Micro89.362.5
SciERCScibert-uncasedMicro66.838.4
CoNLL04Albert-xxlarge-v1Micro/Macro89.6/86.475.0/76.3
ADEBert/AlbertMacro89.6/91.380.0/83.2

F1 results on ACE04:

5-fold01234Average
Albert-NER89.789.989.589.787.689.3
Albert-RE65.561.463.461.560.762.5

F1 results on ADE:

10-fold0123456789Average
Bert-NER89.692.390.388.988.890.290.188.588.088.989.6
Bert-RE80.585.879.979.479.380.580.078.176.279.880.0
Albert-NER91.492.991.991.590.791.691.989.990.690.791.3
Albert-RE83.986.882.883.282.282.484.582.381.982.283.2

Extension on Ablation Study

As requested, we release ablation NER/RE results of 5 runs in the category of encoding scheme and decoding strategy.

Model/seed01234MeanStandard Deviation
Original66.8/38.466.9/36.966.4/36.368.0/38.967.7/37.767.2/37.60.67/1.06
Sequential68.7/36.968.0/35.968.5/34.867.7/36.967.0/36.268.0/36.10.68/0.87
Parallel67.0/35.167.2/36.667.9/37.468.0/37.966.9/34.667.4/36.30.51/1.43
Selective68.1/37.467.0/35.967.5/38.566.8/35.167.7/36.767.4/36.70.53/1.32

Robustness Against Input Perturbation

We use robustness test to evaluate our model under adverse circumstances. In this case, we use the domain transformation methods of NER from Textflint.

The test files can be found in the folder of ./robustness_data/. Our reported results are evaluated with the linked ACE2005-albert model above.

For each test file, move it to ./data/ACE2005/ and rename it as test_triples.json, then run eval.py with the instructions above.

Citation

Please cite our paper if it's helpful to you in your research.

@inproceedings{yan-etal-2021-partition,
    title = "A Partition Filter Network for Joint Entity and Relation Extraction",
    author = "Yan, Zhiheng  and  Zhang, Chong  and  Fu, Jinlan  and  Zhang, Qi  and  Wei, Zhongyu",
    booktitle = "Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing",
    month = nov,
    year = "2021",
    address = "Online and Punta Cana, Dominican Republic",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2021.emnlp-main.17",
    pages = "185--197"
}