Giter VIP home page Giter VIP logo

lukaszahradnik / pyneuralogic Goto Github PK

View Code? Open in Web Editor NEW
271.0 6.0 18.0 32.42 MB

PyNeuraLogic lets you use Python to create Differentiable Logic Programs

Home Page: https://pyneuralogic.readthedocs.io/

License: MIT License

Python 100.00%
machine-learning deep-learning graph-neural-networks relational-learning python geometric-deep-learning pytorch logic-programming differentiable-programming

pyneuralogic's Introduction

PyNeuraLogic

PyPI version License Tests Status Code Quality Status Documentation Status Tweet

Documentation | Examples | Papers

PyNeuraLogic lets you use Python to write Differentiable Logic Programs


About

Logic programming is a declarative coding paradigm in which you declare your logical variables and relations between them. These can be further composed into so-called rules that drive the computation. Such a rule set then forms a logic program, and its execution is equivalent to performing logic inference with the rules.

PyNeuralogic, through its NeuraLogic backend, then makes this inference process differentiable which, in turn, makes it equivalent to forward propagation in deep learning. This lets you learn numeric parameters that can be associated with the rules, just like you learn weights in neural networks.

SQL tutorial

What is this good for?

Many things! For instance - ever heard of Graph Neural Networks (GNNs)? Well, a graph happens to be a special case of a logical relation - a binary one to be more exact. Now, at the heart of any GNN model there is a so-called propagation rule for passing 'messages' between the neighboring nodes. Particularly, the representation ('message') of a node X is calculated by aggregating the previous representations of adjacent nodes Y, i.e. those with an edge between X and Y.

Or, a bit more 'formally':

Relation.message2(Var.X) <= (Relation.message1(Var.Y), Relation.edge(Var.Y, Var.X))

...and that's the actual code! Now for a classic learnable GNN layer, you'll want to add some weights, such as

Relation.message2(Var.X)[5,10] <= (Relation.message1(Var.Y)[10,20], Relation.edge(Var.Y, Var.X))

to project your [20,1] input node embeddings ('message1') through a learnable [10,20] layer before the aggregation, and subsequently a [5,10] layer after the aggregation.

If you don't like the default settings, you can of course specify various additional details, such as the particular aggregation and activation functions

(R.message2(V.X)[5,10] <= (R.message1(V.Y)[10,20], R.edge(V.Y, V.X))) | [Transformation.RELU, Aggregation.AVG]

to instantiate the classic GCN layer specification, which you can directly train now!

How is it different from other GNN frameworks?

Naturally, PyNeuralogic is by no means limited to GNN models, as the expressiveness of relational logic goes much further beyond graphs. Hence, nothing stops you from playing directly with:

  • multiple relations and object types
  • hypergraphs, nested graphs, relational databases
  • relational pattern matching, various subgraph GNNs
  • alternative propagation schemes
  • inclusion of logical background knowledge
  • and more...

In PyNeuraLogic, all these ideas take the same form of simple small logic programs. These are commonly highly transparent and easy to understand, thanks to their declarative nature. Consequently, there is no need to design a zoo of blackbox class names for each small modification of the GNN rule - you code directly at the level of the logical principles here!

The backend engine then creates the underlying differentiable computation (inference) graphs in a fully automated and dynamic fashion, hence you don't have to care about aligning everything into some static (tensor) operations.

How does it perform?

While PyNeuraLogic allows you to easily declare highly expressive models with capabilities far beyond the common GNNs, it does not come at the cost of performance for the basic GNNs either. On the contrary, for a range of common GNN models and applications, such as learning with molecules, PyNeuraLogic is actually considerably faster than the popular GNN frameworks, as demonstrated in our benchmarks.

Benchmark of PyNeuraLogic


We hope you'll find the framework useful in designing your own deep relational learning ideas beyond the GNNs! Please let us know if you need some guidance or would like to cooperate!

๐Ÿ’ก Getting started

Installation

To install PyNeuraLogic's latest release from the PyPI repository, use the following command:

$ pip install neuralogic

Prerequisites

To use PyNeuraLogic, you need to install the following prerequisites:

Python >= 3.8
Java >= 1.8

In case you want to use visualization provided in the library, it is required to have Graphviz installed.

๐Ÿ”ฌ Examples

Open In Colab Simple XOR example
Open In Colab Molecular GNNs
Open In Colab Recursive XOR generalization
Open In Colab Visualization

Open In Colab Subgraph Patterns
Open In Colab Distinguishing k-regular graphs
Open In Colab Distinguishing non-regular graphs


๐Ÿ“ฆ Predefined Modules

PyNeuraLogic has a set of predefined modules to get you quickly started with your experimenting! It contains, for example, predefined modules for:

  • Graph Neural Networks (GNNConv, SAGEConv, GINConv, RGCNConv, ...)
  • Meta graphs and meta paths (MetaConv, MAGNN, ...)
  • Transformer, LSTM, GRU, RNN, ...and more!

๐Ÿ“ Papers

๐Ÿ“˜ Articles

๐ŸŽฅ Videos

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.