Pytorch code for our AAAI 2020 paper "Path Ranking with Attention to Type Hierarchies"
Go to file
dependabot[bot] 40023297ce
Bump protobuf from 3.7.1 to 3.18.3
Bumps [protobuf](https://github.com/protocolbuffers/protobuf) from 3.7.1 to 3.18.3.
- [Release notes](https://github.com/protocolbuffers/protobuf/releases)
- [Changelog](https://github.com/protocolbuffers/protobuf/blob/main/generate_changelog.py)
- [Commits](https://github.com/protocolbuffers/protobuf/compare/v3.7.1...v3.18.3)

---
updated-dependencies:
- dependency-name: protobuf
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-09-23 22:32:05 +00:00
docs added sphinx doc 2020-07-31 17:24:04 -04:00
figure updated readme 2020-07-31 23:29:03 -04:00
main added complete code 2020-07-31 17:32:38 -04:00
pra_templates added templates for running pra scala 2020-07-31 17:26:32 -04:00
.gitignore updated readme 2020-07-31 23:29:03 -04:00
demo_fb15k237.py added complete code 2020-07-31 17:32:38 -04:00
demo_wn18rr.py added complete code 2020-07-31 17:32:38 -04:00
LICENSE Create LICENSE 2020-07-31 17:52:15 -04:00
README.md added data link 2020-08-01 00:01:46 -04:00
requirements.txt Bump protobuf from 3.7.1 to 3.18.3 2022-09-23 22:32:05 +00:00
run_fb15k237.py added complete code 2020-07-31 17:32:38 -04:00
run_wn18rr.py added complete code 2020-07-31 17:32:38 -04:00
run.py first commit 2019-11-20 21:59:53 -05:00

Path Ranking with Attention to Type Hierarchies

This repo contains code for AAAI 2020 paper Path Ranking with Attention to Type Hierarchies, in which we introduce Attentive Path Ranking (APR), a novel path pattern representation that leverages type hierarchies of entities to both avoid ambiguity and maintain generalization.

drawing

Resources

  1. Code for baseline models in the paper can be found here (PRA and SFE) and here (Path-RNN).
  2. We provide tokenized data for WN18RR and FB15k-237. Our data format follows ChainsofReasoning. Vocabularies used for tokenizing data are also provided for reference.
  3. Raw data for WN18RR and FB15k-237 can be found here. Types for WN18RR entities can be obtained from Wordnet. Types for FB15k-237 entities can be found here.

Tested platform

  • Hardware: 64GB RAM, 12GB GPU memory
  • Software: ubuntu 16.04, python 3.5, cuda 8

Setup

  1. Install cuda
  2. (Optional) Set up python virtual environment by running virtualenv -p python3 .
  3. (Optional) Activate virtual environment by running source bin/activate
  4. Install pytorch with cuda
  5. Install requirements by running pip3 install -r requirements.txt

Quick Start for Attentive Path Ranking (APR) model

To help you quickly train and test the model, we have prepared data that are already vectorized.

Data

  1. Vectorized data file can be downloaded from dropbox.
  2. Unzip the file in the root directory of this repo.

Run the model

  1. Use run.py to train and test the model on WN18RR or FB15k-237.
  2. Use main/playground/model2/CompositionalVectorSpaceAlgorithm.py to modify the training settings and hyperparamters.
  3. Use main/playground/model2/CompositionalVectorSpaceModel.py to modify the network design. Different attention methods for types and paths can be selected here.
  4. Training progress can be monitored using tensorboardX by running tensorboard --logdir runs. Tutorials and Details can be found here.

Running the Complete Knowledge Graph Completion Pipeline

You can also use the code to build knowledge graphs from relation data, sample negative examples, create splits, extract paths, vectorize path data, run baselines, and run APR model.

Data

  1. Raw data, including relation data, type information, and word embeddings, for WN18RR, FB15k-237 can be downloaded from dropbox.
  2. Unzip the file in the root directory of this repo.

Install Dependencies

  1. Clone our PRA repo and install necessary dependencies. For more details, check out readme in that repo.
  2. (Optional) Clone our CVSM repo only if you want to run CVSM baselines.

Run

  1. Use demo_wn18rr.py or demo_fb15k237.py to go through the whole pipeline for the respective dataset.
  2. Use run_wn18rr.py or run_fb15k237.py if you want to run PRA, SFE, and CVSM baselines

Code Documentation

Code are documented with docstrings. We also use sphinx to automatically generate API documentation from docstrings.

Viewing the documentation

  1. Make sure you have the necessary pip dependencies of sphinx installed.
  2. Navigate to docs and build the documentation: make html
  3. Navigate to docs/_build/html (this folder will be generated by the previous command) and start a simple server: python -m SimpleHTTPServer.
  4. Navigate to http://localhost:8000 in your browser.

Citation

Please cite the following work if you find the data/code useful.

@inproceedings{liu2019path,
  title = {Path Ranking with Attention to Type Hierarchies},
  author = {Weiyu Liu and Daruna, Angel and Kira, Zsolt and Chernova, Sonia},
  booktitle = {Thirty-Fourth AAAI Conference on Artificial Intelligence (AAAI)},
  year = {2020}
}