Git Product home page Git Product logo

neural-logic-machines's Introduction

Neural Logic Machines

PyTorch implementation for the Neural Logic Machines (NLM). Please note that this is not an officially supported Google product.

Neural Logic Machine (NLM) is a neural-symbolic architecture for both inductive learning and logic reasoning. NLMs use tensors to represent logic predicates. This is done by grounding the predicate as True or False over a fixed set of objects. Based on the tensor representation, rules are implemented as neural operators that can be applied over the premise tensors and generate conclusion tensors.

Neural Logic Machines
Honghua Dong*, Jiayuan Mao*, Tian Lin, Chong Wang, Lihong Li, and Denny Zhou
(*: indicates equal contribution.)
In International Conference on Learning Representations (ICLR) 2019
[Paper] [Project Page]

@inproceedings{
      dong2018neural,
      title     = {Neural Logic Machines},
      author    = {Honghua Dong and Jiayuan Mao and Tian Lin and Chong Wang and Lihong Li and Denny Zhou},
      booktitle = {International Conference on Learning Representations},
      year      = {2019},
      url       = {https://openreview.net/forum?id=B1xY-hRctX},
    }

Prerequisites

  • Python 3
  • PyTorch 0.4.0
  • Jacinle. We use the version ed90c3a for this repo.
  • Other required python packages specified by requirements.txt. See the Installation.

Installation

Clone this repository:

git clone https://github.com/google/neural-logic-machines --recursive

Install Jacinle included as a submodule. You need to add the bin path to your global PATH environment variable:

export PATH=<path_to_neural_logic_machines>/third_party/Jacinle/bin:$PATH

Create a conda environment for NLM, and install the requirements. This includes the required python packages from both Jacinle and NLM. Most of the required packages have been included in the built-in anaconda package:

conda create -n nlm anaconda
conda install pytorch torchvision -c pytorch

Usage

This repo contains 10 graph-related reasoning tasks (using supervised learning) and 3 decision-making tasks (using reinforcement learning).

We also provide pre-trained models for 3 decision-making tasks in models directory,

Taking the Blocks World task as an example.

# To train the model:
$ jac-run scripts/blocksworld/learn_policy.py --task final
# To test the model:
$ jac-run scripts/blocksworld/learn_policy.py --task final --test-only --load models/blocksworld.pth
# add [--test-epoch-size T] to control the number of testing cases.
# E.g. use T=20 for a quick testing, usually take ~2min on CPUs.
# Sample output of testing for number=10 and number=50:
> Evaluation:
    length = 12.500000
    number = 10.000000
    score = 0.885000
    succ = 1.000000
> Evaluation:
    length = 85.800000
    number = 50.000000
    score = 0.152000
    succ = 1.000000

Please refer to the graph directory for training/inference details of other tasks.

Useful Command-line options

  • jac-crun GPU_ID FILE --use-gpu GPU_ID instead of jac-run FILE to enable using gpu with id GPU_ID.
  • --model {nlm, memnet}[default: nlm]: choose memnet to use (Memory Networks)[https://arxiv.org/abs/1503.08895] as baseline.
  • --runs N: take N runs.
  • --dump-dir DUMP_DIR: place to dump logs/summaries/checkpoints/plays.
  • --dump-play: dump plays for visualization in json format, can be visualized by our html visualizer. (not applied to graph tasks)
  • --test-number-begin B --test-number-step S --step-number-end E:
    defines the range of the sizes of the test instances.
  • --test-epoch-size SIZE: number of test instances.

For a complete command-line options see jac-run FILE -h (e.g. jac-run scripts/blocksworld/learn_policy.py -h).

neural-logic-machines's People

Contributors

dhh1995 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

neural-logic-machines's Issues

DILP baseline model implementation

Hi,

I noticed your paper showed the results by DILP, but I couldn't find the corresponding code about the DILP implementation. Could you please share the code with me? Many thanks!

About the 1-outdegree rules testd in dILP

Hi, I'm trying to reproduce your evaluation for dILP in supervised tasks. But I'm stucking in designing the rules for task 1-outdegree for dILP.

  • For 1-outdegree, the rules can be:

Screen Shot 2021-01-31 at 2 44 13 PM

But how should we express it in dILP? which auxiliary predicates should we use to express the meaning: for all nodes `c`, which is unequal to `b`, and has no edge with node `a`?

I'll appreciate it if you can give me some suggestions!

How to extend to other dataset benchmarks?

Hi, I am trying to apply the NLM to other graph datasets, but I am a little confused on how to do it given the structure of the training script.

For instance, could you please shed some light on how to adapt the running scripts for other datasets like the Countries dataset*, that are bigger than the cases you presented in the paper and are also fixed (not randomly generated during each epoch)?

Thank you in advance for your time :)

  • Guillaume Bouchard, Sameer Singh, and Theo Trouillon. On approximate reasoning capabilities of low-rank vector spaces.AAAI Spring Symposium, 2015

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.