Git Product home page Git Product logo

kg-ruleguider's Introduction

Neural Symbolic Reasoning on Knowledge Graph: RuleGuider

Pytorch implementation of our EMNLP 2020 paper: Learning Collaborative Agents with Rule Guidance for Knowledge Graph Reasoning.

We propose a neural symbolic method for knolwege graph reasoning that leverages symbolic rules.

Walk-based models have shown their advantages in knowledge graph (KG) reasoning by achieving decent performance while providing interpretable decisions. However, the sparse reward signals offered by the KG during traversal are often insufficient to guide a sophisticated walk-based reinforcement learning (RL) model. An alternate approach is to use traditional symbolic methods (e.g., rule induction), which achieve good performance but can be hard to generalize due to the limitation of symbolic representation. In this paper, we propose RuleGuider, which leverages high-quality rules generated by symbolicbased methods to provide reward supervision for walk-based agents. Experiments on benchmark datasets show that RuleGuider improves the performance of walk-based models without losing interpretability.

If you find the repository or ruleGuider helpful, please cite the following paper

@inproceedings{lei2020ruleguider,
  title={Learning Collaborative Agents with Rule Guidance for Knowledge Graph Reasoning},
  author={Lei, Deren and Jiang, Gangrong and Gu, Xiaotao and Sun, Kexuan and Mao, Yuning and Ren, Xiang},
  journal={EMNLP},
  year={2020}
}

Installation

Install PyTorch (>= 1.4.0) following the instructions on the PyTorch. Our code is written in Python3.

Run the following commands to install the required packages:

pip3 install -r requirements.txt

Data Preparation

Unpack the data files:

unzip data.zip

It will generate three dataset folders in the ./data directory. In our experiments, the datasets used are: fb15k-237, wn18rr and nell-995.

Rule Mining

Training

  1. Train embedding-based models:
./experiment-emb.sh configs/<dataset>-<model>.sh --train <gpu-ID>
  1. Pretrain relation agent using top rules:
./experiment-pretrain.sh configs/<dataset>-rs.sh --train <gpu-ID> <rule-path> --model point.rs.<embedding-model>
  1. Jointly train relation agent and entity agent with reward shaping
./experiment-rs.sh configs/<dataset>-rs.sh --train <gpu-ID> <rule-path> --model point.rs.<embedding-model> --checkpoint_path <pretrain-checkpoint-path>

Note:

  • you can choose embedding models among conve, complex, and distmult.
  • you have to pre-train the embedding-based models before pretraining relation agent or jointly training two agents.
  • you can skip pretraining relation agent.
  • make sure you set the file path pointers to the pre-trained embedding-based models correctly (example configuration file),
  • use --board <board-path> to logs the training details, --model <model-path> to assign the directory in which checkpoints are saved, and --checkpoint_path <checkpoint-path> to load checkpoints.
  • in joint training, you can use --rule_ratio <ratio> to specify the ratio between rule reward and hit reward.

Evaluation

  1. Evaluate embedding-based models:
./experiment-emb.sh configs/<dataset>-<model>.sh --inference <gpu-ID>
  1. Evaluate the pretraining of relation agent :
./experiment-pretrain.sh configs/<dataset>-rs.sh --inference <gpu-ID> <rule-path> --model point.rs.<embedding-model> --checkpoint_path <pretrain-checkpoint-path>
  1. Evaluate the final result:
./experiment-rs.sh configs/<dataset>-rs.sh --inference <gpu-ID> <rule-path> --model point.rs.<embedding-model> --checkpoint_path <checkpoint-path>

kg-ruleguider's People

Contributors

ttobbaccoo avatar derenlei avatar

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.