Code for the paper Relation Prediction as an Auxiliary Training Objective for Improving Multi-Relational Graph Representations (AKBC 2021).

Overview

Relation Prediction as an Auxiliary Training Objective for Knowledge Base Completion

PWC PWC PWC

This repo provides the code for the paper Relation Prediction as an Auxiliary Training Objective for Improving Multi-Relational Graph Representations. Incorporating relation prediction into the 1vsAll objective leads to a new self-supervised training objective for knowledge base completion (KBC), which brings significant performance improvement with 3-10 lines of code. Unleash the power of your KBC models with relation prediction objective!

Prepare Datasets

Download

Download datasets and put them under src_data. The folder should look like this TODO: tree command output

src_data/FB15K-237/train # Tab separated file
src_data/FB15K-237/valid # Tab separated file
src_data/FB15K-237/test # Tab separated file

As an option, you can download together UMLS, Nations, Kinship, FB15K-237, WN18RR from here and aristo-v4 from here. You can also download some datasets separately on WN18RR and FB15K-237.

Preprocessing

mkdir data/
python preprocess_datasets.py

Train the model

Use option score_rel to turn on the auxiliary objective of relation prediction. Use option w_rel to set the weight of the relation prediction objective.

For example, the following command trains a ComplEx model with relation prediction on FB15K-237

python main.py --dataset FB15K-237 --score_rel True --model ComplEx --rank 1000 --learning_rate 0.1 --batch_size 1000 --lmbda 0.05 --w_rel 4 --max_epochs 100

And the following command trains a ComplEx model without relation prediction on FB15K-237

python main.py --dataset FB15K-237 --score_rel False --model ComplEx --rank 1000 --learning_rate 0.1 --batch_size 1000 --lmbda 0.05 --w_rel 4 --max_epochs 100

Dependency

  • pytorch
  • wandb

Acknowledgement

This repo is based on the repo kbc, which provides efficient implementations of 1vsAll for ComplEx and CP. Our repo also includes implementations for other models: TransE, RESCAL, and TuckER.

BibTex

If you find this repo useful, please cite us

@inproceedings{
chen2021relation,
title={Relation Prediction as an Auxiliary Training Objective for Improving Multi-Relational Graph Representations},
author={Yihong Chen and Pasquale Minervini and Sebastian Riedel and Pontus Stenetorp},
booktitle={3rd Conference on Automated Knowledge Base Construction},
year={2021},
url={https://openreview.net/forum?id=Qa3uS3H7-Le}
}

License

This repo is CC-BY-NC licensed, as found in the LICENSE file.

Comments
  • The code fails when running a custom graph

    The code fails when running a custom graph

    Hello, I am trying to run the code on a graph I have built that is not included among the choices provided in the repo. The graph I am working with is bipartite with typed edges.

    To run the code, I prepared the list of triplets to be split in train, valid and test sets.

    Triplets are saved in .tsv files:

    ...
    idx__518	id	2449.0
    idx__519	id	2452.0
    idx__523	id	2469.0
    idx__531	id	2484.0
    idx__532	id	2487.0
    idx__533	id	2494.0
    idx__549	id	2545.0
    ...
    

    To run my dataset, I slightly modified the python scripts in the repo.

    In preprocess_dataset.py I added the line datasets = ['mydata'] to read from the folder src/src_data/mydata. I was then able to run the script, which created and filled the folder data/mydata.

    DATA_PATH: /content/ssl-relation-prediction/data
    Preparing dataset mydata
    2681 entities and 9 relations
    creating filtering lists
    Done processing!
    1
    

    In main.py, I modified the list of datasets by adding mydata so that the code wouldn't raise an exception.

    Finally, I tried to run the code with the arguments specified in the readme:

    ! python src/main.py --dataset mydata --score_rel True --model ComplEx --rank 1000 --learning_rate 0.1 --batch_size 1000 --lmbda 0.05 --w_rel 4 --max_epochs 100
    

    Unfortunately, at this point the code fails because there is no train.npy file in the data folder. I assume that the train.npy file should have been created by the preprocessing script, but for some reason that did not happen. The content of the data folder is the following:

    total 1320
    -rw-r--r-- 1 root root   40662 Dec  3 12:59 ent_id
    -rw-r--r-- 1 root root      97 Dec  3 12:59 rel_id
    -rw-r--r-- 1 root root   43023 Dec  3 12:59 test.tsv.pickle
    -rw-r--r-- 1 root root 1083297 Dec  3 12:59 to_skip.pickle
    -rw-r--r-- 1 root root  140727 Dec  3 12:59 train.tsv.pickle
    -rw-r--r-- 1 root root   32391 Dec  3 12:59 valid.tsv.pickle
    

    It's not clear to me how to run custom-made datasets from the readme. Could you help me with that?

    opened by rcap107 6
  • Evaluating CP model crashes

    Evaluating CP model crashes

    Hi Yihong, thank you so much for sharing this awesome repo!!

    I tried to run the CP model; training seems to work, but when the validation starts, it crashes:

    Evaluate the split train
    Evaluating the rhs
    Traceback (most recent call last):
      File "/home/jean/kg/src/main.py", line 25, in <module>
        main()
      File "/home/jean/kg/src/main.py", line 20, in main
        engine.episode()
      File "/home/jean/kg/src/engines.py", line 329, in episode
        self.validation_step(epoch=epoch, model=self.model)
      File "/home/jean/kg/src/engines.py", line 260, in validation_step
        res_s = self.dataset.eval(
      File "/home/jean/kg/src/datasets.py", line 243, in eval
        metrics = model.get_metric_ogb(
      File "/home/jean/kg/src/models/__init__.py", line 164, in get_metric_ogb
        cands = self.get_candidates(
    TypeError: get_candidates() got an unexpected keyword argument 'indices'
    
    

    Maybe the get_candidates(...) method of the CP class needs to be re-written?

    opened by JeanKaddour 4
  • Trained entity + relation embeddings

    Trained entity + relation embeddings

    Hi, thanks for your great contribution with this work :-) Do you plan to make the trained entity + relation embeddings for your SOTA models available for download?

    Tara

    opened by tsafavi 4
  • About models validation based on MRR

    About models validation based on MRR

    Hi, I am trying your code an I think there is something wrong about the validation step in the training loop.

    That is, consider the line at https://github.com/facebookresearch/ssl-relation-prediction/blob/main/src/engines.py#L197. At this line, the value assigned to the variable split is actually the last value that was assigned in the previous loop for computing step-wise metrics over all the splits (L.192-195). The last value is in fact "test".

    So I think that at the end the model is wrongly validated against the test set instead of the validation set.

    opened by loreloc 3
  • Quick check with the new evaluation code

    Quick check with the new evaluation code

    Hi! This is OGB Team.

    We recently released https://github.com/snap-stanford/ogb/releases/tag/1.3.4 which improves the MRR calculation. This should not change your result if your model makes different predictive scores for different triplets, but would penalize those models that give the same predictive scores for different triplets (which is not ideal for link prediction).

    Could you update your ogb package to 1.3.4 and run your model again just to confirm everything stays the same (the dataset stays the same. only evaluator changed)? Just one seed should be enough. Thanks!

    opened by weihua916 2
  • OGB model documentation

    OGB model documentation

    Good evening. I have a question , regarding your code for the ogb wikidata. I've been working on graph neural networks lately, but because it's something new to me I'm having difficulties. Could I find somewhere documentation for the code and more specifically for the methods.Thanks in advance.

    opened by Percefoni 1
  • Adding Code of Conduct file

    Adding Code of Conduct file

    This is pull request was created automatically because we noticed your project was missing a Code of Conduct file.

    Code of Conduct files facilitate respectful and constructive communities by establishing expected behaviors for project contributors.

    This PR was crafted with love by Facebook's Open Source Team.

    CLA Signed 
    opened by facebook-github-bot 1
  • Adding Contributing file

    Adding Contributing file

    This is pull request was created automatically because we noticed your project was missing a Contributing file.

    CONTRIBUTING files explain how a developer can contribute to the project - which you should actively encourage.

    This PR was crafted with love by Facebook's Open Source Team.

    CLA Signed 
    opened by facebook-github-bot 0
Owner
Facebook Research
Facebook Research
Code for the paper "Relation of the Relations: A New Formalization of the Relation Extraction Problem"

This repo contains the code for the EMNLP 2020 paper "Relation of the Relations: A New Paradigm of the Relation Extraction Problem" (Jin et al., 2020)

YYY 27 Oct 26, 2022
Pytorch implementation of "A simple neural network module for relational reasoning" (Relational Networks)

Pytorch implementation of Relational Networks - A simple neural network module for relational reasoning Implemented & tested on Sort-of-CLEVR task. So

Kim Heecheol 800 Dec 5, 2022
Exploring Relational Context for Multi-Task Dense Prediction [ICCV 2021]

Adaptive Task-Relational Context (ATRC) This repository provides source code for the ICCV 2021 paper Exploring Relational Context for Multi-Task Dense

David Brüggemann 35 Dec 5, 2022
Source code and dataset for ACL2021 paper: "ERICA: Improving Entity and Relation Understanding for Pre-trained Language Models via Contrastive Learning".

ERICA Source code and dataset for ACL2021 paper: "ERICA: Improving Entity and Relation Understanding for Pre-trained Language Models via Contrastive L

THUNLP 75 Nov 2, 2022
Few-shot Relation Extraction via Bayesian Meta-learning on Relation Graphs

Few-shot Relation Extraction via Bayesian Meta-learning on Relation Graphs This is an implemetation of the paper Few-shot Relation Extraction via Baye

MilaGraph 36 Nov 22, 2022
[ICML 2020] Prediction-Guided Multi-Objective Reinforcement Learning for Continuous Robot Control

PG-MORL This repository contains the implementation for the paper Prediction-Guided Multi-Objective Reinforcement Learning for Continuous Robot Contro

MIT Graphics Group 65 Jan 7, 2023
Wanli Li and Tieyun Qian: Exploit a Multi-head Reference Graph for Semi-supervised Relation Extraction, IJCNN 2021

MRefG Wanli Li and Tieyun Qian: "Exploit a Multi-head Reference Graph for Semi-supervised Relation Extraction", IJCNN 2021 1. Requirements To reproduc

万理 5 Jul 26, 2022
[EMNLP 2021] MuVER: Improving First-Stage Entity Retrieval with Multi-View Entity Representations

MuVER This repo contains the code and pre-trained model for our EMNLP 2021 paper: MuVER: Improving First-Stage Entity Retrieval with Multi-View Entity

null 24 May 30, 2022
Source code for CIKM 2021 paper for Relation-aware Heterogeneous Graph for User Profiling

RHGN Source code for CIKM 2021 paper for Relation-aware Heterogeneous Graph for User Profiling Dependencies torch==1.6.0 torchvision==0.7.0 dgl==0.7.1

Big Data and Multi-modal Computing Group, CRIPAC 6 Nov 29, 2022
Official PyTorch code of DeepPanoContext: Panoramic 3D Scene Understanding with Holistic Scene Context Graph and Relation-based Optimization (ICCV 2021 Oral).

DeepPanoContext (DPC) [Project Page (with interactive results)][Paper] DeepPanoContext: Panoramic 3D Scene Understanding with Holistic Scene Context G

Cheng Zhang 66 Nov 16, 2022
Code for paper PairRE: Knowledge Graph Embeddings via Paired Relation Vectors.

PairRE Code for paper PairRE: Knowledge Graph Embeddings via Paired Relation Vectors. This implementation of PairRE for Open Graph Benchmak datasets (

Alipay 65 Dec 19, 2022
[ACL 20] Probing Linguistic Features of Sentence-level Representations in Neural Relation Extraction

REval Table of Contents Introduction Overview Requirements Installation Probing Usage Citation License ?? Introduction REval is a simple framework for

null 13 Jan 6, 2023
This repository is an implementation of paper : Improving the Training of Graph Neural Networks with Consistency Regularization

CRGNN Paper : Improving the Training of Graph Neural Networks with Consistency Regularization Environments Implementing environment: GeForce RTX™ 3090

THUDM 1 Dec 9, 2021
Source code for paper "Document-Level Relation Extraction with Adaptive Thresholding and Localized Context Pooling", AAAI 2021

ATLOP Code for AAAI 2021 paper Document-Level Relation Extraction with Adaptive Thresholding and Localized Context Pooling. If you make use of this co

Wenxuan Zhou 146 Nov 29, 2022
It's a implement of this paper:Relation extraction via Multi-Level attention CNNs

Relation Classification via Multi-Level Attention CNNs It's a implement of this paper:Relation Classification via Multi-Level Attention CNNs. Training

Aybss 2 Nov 4, 2022
git《Joint Entity and Relation Extraction with Set Prediction Networks》(2020) GitHub:

Joint Entity and Relation Extraction with Set Prediction Networks Source code for Joint Entity and Relation Extraction with Set Prediction Networks. W

null 130 Dec 13, 2022
Official implementation of NeurIPS 2021 paper "One Loss for All: Deep Hashing with a Single Cosine Similarity based Learning Objective"

Official implementation of NeurIPS 2021 paper "One Loss for All: Deep Hashing with a Single Cosine Similarity based Learning Objective"

Ng Kam Woh 71 Dec 22, 2022
A PyTorch implementation of the Relational Graph Convolutional Network (RGCN).

Torch-RGCN Torch-RGCN is a PyTorch implementation of the RGCN, originally proposed by Schlichtkrull et al. in Modeling Relational Data with Graph Conv

Thiviyan Singam 66 Nov 30, 2022
Beyond Image to Depth: Improving Depth Prediction using Echoes (CVPR 2021)

Beyond Image to Depth: Improving Depth Prediction using Echoes (CVPR 2021) Kranti Kumar Parida, Siddharth Srivastava, Gaurav Sharma. We address the pr

Kranti Kumar Parida 33 Jun 27, 2022