https://github.com/LukasZahradnik/PyNeuraLogic Skip to content Sign up * Product + Features + Mobile + Actions + Codespaces + Packages + Security + Code review + Issues + Integrations + GitHub Sponsors + Customer stories * Team * Enterprise * Explore + Explore GitHub + Learn and contribute + Topics + Collections + Trending + Learning Lab + Open source guides + Connect with others + The ReadME Project + Events + Community forum + GitHub Education + GitHub Stars program * Marketplace * Pricing + Plans + Compare plans + Contact Sales + Education [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} LukasZahradnik / PyNeuraLogic Public * Notifications * Fork 7 * Star 63 PyNeuraLogic lets you use Python to create Differentiable Logic Programs pyneuralogic.readthedocs.io/ MIT License 63 stars 7 forks Star Notifications * Code * Issues 0 * Pull requests 1 * Discussions * Actions * Projects 2 * Security * Insights More * Code * Issues * Pull requests * Discussions * Actions * Projects * Security * Insights This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags 9 branches 27 tags Code Latest commit @LukasZahradnik LukasZahradnik Merge pull request #34 from LukasZahradnik/dev ... a2c63ee Apr 25, 2022 Merge pull request #34 from LukasZahradnik/dev PyNeuraLogic restructure a2c63ee Git stats * 669 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github benchmarks docs examples neuralogic tests .coveragerc .env.example .gitignore .pre-commit-config.yaml LICENSE README.md mypy.ini pyproject.toml requirements.txt setup.py View code [ ] About What is this good for? How is it different from other GNN frameworks? How does it perform? Getting started Prerequisites Installation Examples Predefined Modules Papers README.md PyNeuraLogic PyPI version License Tests Status Documentation Status 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. 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 [1,20] 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)) | [Activation.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 Prerequisites To use PyNeuraLogic, you need to install the following prerequisites: Python >= 3.7 Java >= 1.8 Installation To install PyNeuraLogic's latest release from the PyPI repository, use the following command: $ pip install neuralogic 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: * GCNConv * SAGEConv * GINConv * RGCNConv * TAGConv * GATv2Conv * SGConv * ...and more! Papers Beyond Graph Neural Networks with Lifted Relational Neural Networks Machine Learning Journal, 2021 Lifted Relational Neural Networks Journal of Artificial Intelligence Research, 2018 Lossless compression of structured convolutional models via lifting ICLR, 2021 About PyNeuraLogic lets you use Python to create Differentiable Logic Programs pyneuralogic.readthedocs.io/ Topics python machine-learning deep-learning pytorch logic-programming relational-learning geometric-deep-learning differentiable-programming graph-neural-networks Resources Readme License MIT License Stars 63 stars Watchers 3 watching Forks 7 forks Releases 9 Restructuralization and predefined modules Latest Apr 25, 2022 + 8 releases Contributors 2 * @LukasZahradnik LukasZahradnik Lukas Zahradnik * @GustikS GustikS Gustav Sir Languages * Python 100.0% * (c) 2022 GitHub, Inc. * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.