/OWE

Pytorch code for An Open-World Extension to Knowledge Graph Completion Models (AAAI 2019)

Primary LanguagePython

An Open-World Extension for Knowledge Graph Completion Models

This repository contains the official Pytorch code for An Open-World Extension for Knowledge Graph Completion Models.

Update: The code and paper for an extension to this work (with better results) is available at this link.

Setup

Resolve dependencies by executing the following command:

pip install -e .

Then download the FB15k-237-OWE, DBPedia50 and FB20k datasets as required. These contain the datasets in format required for both OpenKE and our code.

Usage

Training the KGC model

Before using OWE you need to train a KGC model. You can use any knowledge graph embedding framework for training. We used the PyTorch version of OpenKE.

To use a previously trained KGC model with OWE you need to export the entity and relation matrices as numpy arrays using pickle:

  • For TransE and DistMult the matrices are called entities.p and relations.p
  • For CompLEx entities_r.p, entities_i.p, relations_r.p and relations_i.p.

Furthermore you need to provide two more files: entity2id.txt and relation2id.txt, which contain a mapping of an entity/relation string to the corresponding index (id) in the embedding files.

The trained 300D ComplEx embeddings for FB15k-237-OWE can be obtained from here.

For closed-world evaluation:

python owe/run_closed_world.py -e -c <PATH_TO_DATASET> --<KGC_MODEL_NAME> <PATH_TO_KGC_EMBEDDINGS>

where KGC_MODEL_NAME can be complex, distmult or transe.

Instructions for OpenKE

Follow the instructions to install OpenKE. Under openke_scripts you can find exemplary training scripts (make sure you update the paths to the dataset in OpenKE format). As the API of OpenKE frequently changes, scripts work with the following version of OpenKE.

Training the Open-World Extension

Word embeddings are required for training the extension. You may obtain the wikipedia2vec word embeddings from here. An example config file to reproduce the results is provided as config.ini in the root folder.

For training:

python owe/run_open_world.py -t -c <PATH_TO_DATASET> -d  <PATH_TO_CONFIG_AND_OUTPUT_DIR> --<KGC_MODEL_NAME> <PATH_TO_KGC_EMBEDDINGS>

For evaluation:

python owe/run_open_world.py -e -lb -c <PATH_TO_DATASET> -d  <PATH_TO_CONFIG_AND_OUTPUT_DIR> --<KGC_MODEL_NAME> <PATH_TO_KGC_EMBEDDINGS>

Citation

If you found our work helpful in your research, consider citing the following:

@inproceedings{shah2019open,
  title={An Open-World Extension to Knowledge Graph Completion Models},
  author={Shah, Haseeb and Villmow, Johannes and Ulges, Adrian and Schwanecke, Ulrich and Shafait, Faisal},
  booktitle={Proceedings of the AAAI Conference on Artificial Intelligence},
  volume={33},
  pages={3044--3051},
  year={2019}
}