Awesome Open Source
Awesome Open Source

Position-aware Attention RNN Model for Relation Extraction

This repo contains the PyTorch code for paper Position-aware Attention and Supervised Data Improve Slot Filling.

The TACRED dataset: Details on the TAC Relation Extraction Dataset can be found on this dataset website.


  • Python 3 (tested on 3.6.2)
  • PyTorch (tested on 1.0.0)
  • unzip, wget (for downloading only)


First, download and unzip GloVe vectors from the Stanford website, with:

chmod +x; ./

Then prepare vocabulary and initial word vectors with:

python dataset/tacred dataset/vocab --glove_dir dataset/glove

This will write vocabulary and word vectors as a numpy matrix into the dir dataset/vocab.


Train a position-aware attention RNN model with:

python --data_dir dataset/tacred --vocab_dir dataset/vocab --id 00 --info "Position-aware attention model"

Use --topn N to finetune the top N word vectors only. The script will do the preprocessing automatically (word dropout, entity masking, etc.).

Train an LSTM model with:

python --data_dir dataset/tacred --vocab_dir dataset/vocab --no-attn --id 01 --info "LSTM model"

Model checkpoints and logs will be saved to ./saved_models/00.


Run evaluation on the test set with:

python saved_models/00 --dataset test

This will use the by default. Use --model to specify a model checkpoint file. Add --out saved_models/out/test1.pkl to write model probability output to files (for ensemble, etc.).


Please see the example script


All work contained in this package is licensed under the Apache License, Version 2.0. See the included LICENSE file.

Alternative Project Comparisons
Related Awesome Lists
Top Programming Languages

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Python (864,795
Pytorch (22,212
Natural Language Processing (15,542
Position (8,465
Attention (3,883
Relation Extraction (446
Information Extraction (425
Word Vectors (373
Attention Model (262