Git Product home page Git Product logo

glore's Introduction

Global Relation Embedding for Relation Extraction (GloRE)

GloRE is a relation embedding model that can be used to augment existing relation extraction models and improve their performance. Most remarkably, for the top 1,000 relational facts discovered by the best existing model (PCNN+ATT), the precision can be improved from 83.9% to 89.3%.

Prerequisite

  • Python 2.7
  • Tensorflow 0.11

Install Tensorflow 0.11

(GPU support)

export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11.0-cp27-none-linux_x86_64.whl
pip install --ignore-installed --upgrade $TF_BINARY_URL

(CPU only)

export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0-cp27-none-linux_x86_64.whl
pip install --ignore-installed --upgrade $TF_BINARY_URL

Results

The result files from held-out and manual evaluations are included in results. To reproduce the figures and tables in the paper, simply follow the IPython notebook:

plot.ipynb

We've also provided a pretrained model in runs/pretrained_model. You can use it to re-generate the Precision-Recall files with the following command:

python steps.py --steps 2,4 --model_dir runs/pretrained_model/

Data

We use the NYT dataset as an example to show how to use our model to improve existing relation extraction models. The original NYT dataset can be downloaded from http://iesl.cs.umass.edu/riedel/ecml/ or https://github.com/thunlp/NRE.

We provide the following pre-processed files in data:

  • data.train.gz / data.valid.gz : training and validation files that are in the format of
    textual relation [tab] KB relation [tab] weight
    
    As an example,
    <-nmod:for>##center##<-dobj>##created##<nsubj>##seminary##<compound>    /people/person/religion 0.666666666667
    
  • kb_relation2id.txt : the set of target KB relations and their ids.
  • left.20000.vocab / right.-1.vocab : vocabulary files. For the encoder input, we keep the most frequent 20,000 tokens in the vocabulary.
  • left.20000.word2vec.vocab.npy : 300-dimensional word2vec vectors pre-trained on the Google News corpus.
  • train_textual_relation.gz / test_textual_relation.gz : textual relations extracted from the training / testing corpus.
  • train_pcnn_att_scores.gz / test_pcnn_att_scores.gz : relation extraction scores from PCNN+ATT (previously best performing model). The format is as follows:
    #
    entity1 [tab] entity2
    textual relaiton id (line number)
    binary encoding for the KB relation labels
    scores of each KB relation generated from the existing relation extraction model
    
    As an example,
    #
    m.010016        m.0492jkz
    542694
    1      0       0       0       0       0       0       0       0       0       0       0       0       0       0
           0       0       0       0       0       0       0       0       0       0       0       0       0       0
           0       0       0       0       0       0       0       0       0       0       0       0       0       0
           0       0       0       0       0       0       0       0       0       0
    0.999106        0.000001        0.000000        0.000000        0.000000        0.000000        0.000054        0.000000                        0.000001        0.000002        0.000000        0.000000        0.000001        0.000003        0.000000        0.000000                  0.000000        0.000007        0.000002        0.000000        0.000000        0.000000
           0.000000        0.000004        0.000001        0.000000        0.000000        0.000000        0.000000
           0.000003        0.000000        0.000000        0.000000        0.000003        0.000000        0.000001
           0.000001        0.000003        0.000000        0.000000        0.000000        0.000000        0.000000
           0.000001        0.000000        0.000001        0.000000        0.000001        0.000443        0.000002
           0.000351        0.000000        0.000000
    #
    

Step-by-Step

To run the training and testing all together, it can be as simple as

python steps.py

By default, this command will run through the following 4 steps:

  1. Train a GloRE model

    You can run this step alone with

    python steps.py --steps 1
    

    OR

    python scripts/train_rel2vec.py your_model_directory
  2. Extract GloRE scores

    You can run this step alone with

    python steps.py --steps 2 --model_dir your_model_directory
    

    OR

    python scripts/test_rel2vec.py your_model_directory
  3. Train a merging model to combine GloRE scores with external scores

    You can run this step alone with

    python steps.py --steps 3 --model_dir your_model_directory
    

    OR

    python scripts/train_mlp.py your_model_directory
  4. Generate final scores and Precision-Recall files

    You can run this step alone with

    python steps.py --steps 4 --model_dir your_model_directory
    

    OR

    python scripts/test_mlp.py your_model_directory

    The Precision-Recall files will be located in your_model_directory/output

We also provide some scripts for interactively exploring the trained GloRE model. Given a textual relation, you can check GloRE's predictions of KB relations with

python scripts/interactive_rel2vec.py your_model_directory

Configuration

All the hyperparameters can be changed by modifying files in scripts.

Cite

If you use the code in your research, please cite the following paper:

Global Relation Embedding for Relation Extraction
Yu Su, Honglei Liu, Semih Yavuz, Izzeddin Gur, Huan Sun, and Xifeng Yan
arXiv preprint arXiv:1704.05958 (2017)

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.