Git Product home page Git Product logo

rsan's Introduction

Source code for IJCAI 2020 paper "A Relation-Specific Attention Network for Joint Entity and Relation Extraction"

Prerequisites

  • Pytorch (1.0.1)
  • nltk
  • numpy
  • six

Code

├── config.py
├── data
├── DataLoader.py
├── data_prepare.py
├── eval_utils.py
├── misc
│   ├── init.py
│   ├── LossWrapper.py
│   └── utils.py
├── model
│   ├── init.py
│   └── Rel_based_labeling.py
├── networks
│   ├── decoder.py
│   ├── embedding.py
│   ├── encoder.py
│   └── init.py
├── Test.py
└── train.py

Descriptions

data/multiNYT/util.py

Process raw data to obtain word dict (word.npy),relation dict(rel2id.json),label dict(label2id.json) and so on.

Labels:["S-H", "S-T", "B-H", "B-T", "I-H", "I-T", "E-H", "E-T", "O", "X"]

Tag H and T stand for head and tail respectively, tag O stands for irrelevant tokens in the sentence, and tag X is padding signal.

data_prepare.py

Convert the original input data into the form of model input and save as .pkl files.

  • Construct ground truth tag sequences

    We will construct different tag sequences for different relations, and align head and tail entities of the triplets in the original sentence.

  • Relational negative sampling

    We use relational negative sampling mechanism for efficiency. We treat the relations that are described in the current sentence as positive relations, and the rest are negative ones. We randomly select $n_{neg}$ relations from the negatives of each sentence (corresponding to parameter --neg_num in config.py), whose ground truth tag sequences contain only O and X labels.

See the example below.

DataLoader.py

Construct dataloader from .pkl files stored in the previous step. Note that our batch_size refers to the number of sentences, one sentence corresponds to $n_{pos}+n_{neg}$ training samples, so you may find that the number of training samples in different batches are different.

Run

  • python data_prepare.py

  • Train

    python train.py --checkpoint_path [ckpt_path] --gpu 3 --use_pos

  • Test

    python Test.py --load_from [ckpt_path] --gpu 0 --use_pos

Citation

@inproceedings{ijcai2020-561,
  title     = {A Relation-Specific Attention Network for Joint Entity and Relation Extraction},
  author    = {Yuan, Yue and Zhou, Xiaofei and Pan, Shirui and Zhu, Qiannan and Song, Zeliang and Guo, Li},
  booktitle = {Proceedings of the Twenty-Ninth International Joint Conference on
               Artificial Intelligence, {IJCAI-20}},
  publisher = {International Joint Conferences on Artificial Intelligence Organization},             
  editor    = {Christian Bessiere},	
  pages     = {4054--4060},
  year      = {2020},
  month     = {7},
  note      = {Main track},
  doi       = {10.24963/ijcai.2020/561},
  url       = {https://doi.org/10.24963/ijcai.2020/561},
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.