DeepProbLog is an extension of ProbLog that integrates Probabilistic Logic Programming with deep learning by introducing the neural predicate.

Overview

DeepProbLog

Unit tests

DeepProbLog is an extension of ProbLog that integrates Probabilistic Logic Programming with deep learning by introducing the neural predicate. The neural predicate represents probabilistic facts whose probabilites are parameterized by neural networks. For more information, consult the papers listed below.

Requirements

DeepProbLog has the following requirements:

Experiments

The experiments are presented in the papers are available in the src/deepproblog/examples directory.

Papers

  1. Robin Manhaeve, Sebastijan Dumancic, Angelika Kimmig, Thomas Demeester, Luc De Raedt: DeepProbLog: Neural Probabilistic Logic Programming. NeurIPS 2018: 3753-3763 (paper)
  2. Robin Manhaeve, Sebastijan Dumancic, Angelika Kimmig, Thomas Demeester, Luc De Raedt: Neural Probabilistic Logic Programming in DeepProbLog. AIJ (paper)
  3. Robin Manhaeve, Giuseppe Marra, Luc De Raedt: Approximate Inference for Neural Probabilistic Logic Programming. KR 2021

License

Copyright 2021 KU Leuven, DTAI Research Group

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Comments
  • [BUG] Unhandled type <class 'str'>

    [BUG] Unhandled type

    To Reproduce Steps to reproduce the behavior:

    $ python addition.py
    addition_method_gm_N_1_pretrain_0_exploration_False_run_0_210826_015053743282
    Training  for 1 epoch(s)
    Epoch 1
    Traceback (most recent call last):
      File "/data/home/fchua/deepproblog/src/deepproblog/examples/MNIST/addition.py", line 66, in <module>
        train = train_model(model, loader, 1, log_iter=100, profile=0)
      File "/data/home/fchua/deepproblog/src/deepproblog/train.py", line 200, in train_model
        train_object.train(loader, stop_condition, **kwargs)
      File "/data/home/fchua/deepproblog/src/deepproblog/train.py", line 128, in train
        loss = self.get_loss(batch, loss_function)
      File "/data/home/fchua/deepproblog/src/deepproblog/train.py", line 39, in get_loss
        result = self.model.solve(batch)
      File "/data/home/fchua/deepproblog/src/deepproblog/model.py", line 106, in solve
        return self.solver.solve(batch)
      File "/data/home/fchua/deepproblog/src/deepproblog/solver.py", line 80, in solve
        acs: List[ArithmeticCircuit] = [self.cache.get(q) for q in batch]
      File "/data/home/fchua/deepproblog/src/deepproblog/solver.py", line 80, in <listcomp>
        acs: List[ArithmeticCircuit] = [self.cache.get(q) for q in batch]
      File "/data/home/fchua/deepproblog/src/deepproblog/utils/cache.py", line 52, in get
        return self.first(item)
      File "/data/home/fchua/deepproblog/src/deepproblog/solver.py", line 67, in build_ac
        ground = self.engine.ground(q, label=LogicFormula.LABEL_QUERY)
      File "/data/home/fchua/deepproblog/src/deepproblog/engines/approximate_engine.py", line 124, in ground
        return self.engine.ground(
      File "/data/home/fchua/deepproblog/src/deepproblog/engines/prolog_engine/engine.py", line 59, in ground
        proofs = self.get_proofs(term, sp)
      File "/data/home/fchua/deepproblog/src/deepproblog/engines/prolog_engine/engine.py", line 88, in get_proofs
        res = program.query(query_str, profile=profile)
      File "/data/home/fchua/deepproblog/src/deepproblog/engines/prolog_engine/swi_program.py", line 321, in query
        out_partial[k] = [p for p in term2list(parse(result[0][k]))]
      File "/data/home/fchua/deepproblog/src/deepproblog/engines/prolog_engine/swip.py", line 99, in parse
        return pyswip_to_term(to_parse)
      File "/data/home/fchua/deepproblog/src/deepproblog/engines/prolog_engine/swip.py", line 50, in pyswip_to_term
        e, vars2 = pyswip_to_term(o, True)
      File "/data/home/fchua/deepproblog/src/deepproblog/engines/prolog_engine/swip.py", line 62, in pyswip_to_term
        raise Exception(
    Exception: Unhandled type <class 'str'> from object -(10, -(addition(tensor(train(0)), tensor(train(1)), 5), and(["-(digit(tensor(train(0)), 2), ::(3, nn(mnist_net, ['tensor(train(0))'], 2), digit(tensor(train(0)), 2), ad(0, 2, ['tensor(train(0))'])))", "-(digit(tensor(train(1)), 3), ::(4, nn(mnist_net, ['tensor(train(1))'], 3), digit(tensor(train(1)), 3), ad(0, 3, ['tensor(train(1))'])))", '-(is(5, +(2, 3)), builtin)'])))
    

    Desktop (please complete the following information):

    • OS: Linux Ubuntu 18.04
    • Python Version: 3.9

    Additional context pyswip is installed from master branch, otherwise pyswip has a bug in the last release.

    bug 
    opened by freddycct 10
  • [BUG] Running addition.py gives a Python error

    [BUG] Running addition.py gives a Python error

    Describe the bug Running deepproblog/src/deepproblog/examples/MNIST/addition.py gives a Python error

    To Reproduce Steps to reproduce the behavior:

    pip3 install git+https://github.com/wannesm/PySDD.git#egg=PySDD
    pip3 install git+https://github.com/yuce/pyswip.git
    git clone https://github.com/ML-KULeuven/deepproblog.git
    cd deepproblog
    pip3 install -e .
    cd src/deepproblog/examples/MNIST
    python 3addition.py
    

    Note that I need to install PySDD and pyswip from sources (as above) in order to avoid other errors. Also, the swi-prolog version needs to come from a PPA (see below).

    Expected behavior There should be no error.

    Desktop (please complete the following information):

    • OS: Ubuntu 20.04
    • Python Version: 3.8.10
    apt-cache policy swi-prolog
    swi-prolog:
      Installed:              8.4.2-1-g94306448a-focalppa2
      Installation candidate: 8.4.2-1-g94306448a-focalppa2
      Version table:
     *** 8.4.2-1-g94306448a-focalppa2 500
            500 http://ppa.launchpad.net/swi-prolog/stable/ubuntu focal/main amd64 Packages
    [...]
    

    Additional context Here is the error:

    ~/programs/deepproblog/src/deepproblog/examples/MNIST$ python3 addition.py 
    addition_method_gm_N_1_pretrain_0_exploration_False_run_0_220518_111251556629
    Training  for 1 epoch(s)
    Epoch 1
    Traceback (most recent call last):
      File "addition.py", line 66, in <module>
        train = train_model(model, loader, 1, log_iter=100, profile=0)
      File "/home/till/programs/deepproblog/src/deepproblog/train.py", line 200, in train_model
        train_object.train(loader, stop_condition, **kwargs)
      File "/home/till/programs/deepproblog/src/deepproblog/train.py", line 128, in train
        loss = self.get_loss(batch, loss_function)
      File "/home/till/programs/deepproblog/src/deepproblog/train.py", line 39, in get_loss
        result = self.model.solve(batch)
      File "/home/till/programs/deepproblog/src/deepproblog/model.py", line 106, in solve
        return self.solver.solve(batch)
      File "/home/till/programs/deepproblog/src/deepproblog/solver.py", line 80, in solve
        acs: List[ArithmeticCircuit] = [self.cache.get(q) for q in batch]
      File "/home/till/programs/deepproblog/src/deepproblog/solver.py", line 80, in <listcomp>
        acs: List[ArithmeticCircuit] = [self.cache.get(q) for q in batch]
      File "/home/till/programs/deepproblog/src/deepproblog/utils/cache.py", line 52, in get
        return self.first(item)
      File "/home/till/programs/deepproblog/src/deepproblog/solver.py", line 67, in build_ac
        ground = self.engine.ground(q, label=LogicFormula.LABEL_QUERY)
      File "/home/till/programs/deepproblog/src/deepproblog/engines/approximate_engine.py", line 124, in ground
        return self.engine.ground(
      File "/home/till/programs/deepproblog/src/deepproblog/engines/prolog_engine/engine.py", line 59, in ground
        proofs = self.get_proofs(term, sp)
      File "/home/till/programs/deepproblog/src/deepproblog/engines/prolog_engine/engine.py", line 86, in get_proofs
        res = program.query(query_str, profile=profile)
      File "/home/till/programs/deepproblog/src/deepproblog/engines/prolog_engine/swi_program.py", line 321, in query
        out_partial[k] = [p for p in term2list(parse(result[0][k]))]
      File "/home/till/programs/deepproblog/src/deepproblog/engines/prolog_engine/swip.py", line 99, in parse
        return pyswip_to_term(to_parse)
      File "/home/till/programs/deepproblog/src/deepproblog/engines/prolog_engine/swip.py", line 50, in pyswip_to_term
        e, vars2 = pyswip_to_term(o, True)
      File "/home/till/programs/deepproblog/src/deepproblog/engines/prolog_engine/swip.py", line 62, in pyswip_to_term
        raise Exception(
    Exception: Unhandled type <class 'str'> from object -(10, -(addition(tensor(train(0)), tensor(train(1)), 5), and(["-(digit(tensor(train(0)), 2), ::(3, nn(mnist_net, ['tensor(train(0))'], 2), digit(tensor(train(0)), 2), ad(0, 2, ['tensor(train(0))'])))", "-(digit(tensor(train(1)), 3), ::(4, nn(mnist_net, ['tensor(train(1))'], 3), digit(tensor(train(1)), 3), ad(0, 3, ['tensor(train(1))'])))", '-(is(5, +(2, 3)), builtin)'])))
    
    bug 
    opened by tillmo 6
  • [BUG] Errors in Pyswip.core file when running tests

    [BUG] Errors in Pyswip.core file when running tests

    Problem When I'm trying to run tests using pytest library I'm encountering bug which you can see below:

    test_engine.py:2: in <module>
        from deepproblog.engines import ApproximateEngine
    ../src/deepproblog/engines/__init__.py:1: in <module>
        from deepproblog.engines.approximate_engine import ApproximateEngine
    ../src/deepproblog/engines/approximate_engine.py:2: in <module>
        from deepproblog.engines.prolog_engine import (
    ../src/deepproblog/engines/prolog_engine/__init__.py:1: in <module>
        from .engine import PrologEngine
    ../src/deepproblog/engines/prolog_engine/engine.py:4: in <module>
        from pyswip import Prolog
    ../venv/src/pyswip/pyswip/__init__.py:29: in <module>
        from pyswip.prolog import Prolog
    ../venv/src/pyswip/pyswip/prolog.py:28: in <module>
        from pyswip.core import *
    ../venv/src/pyswip/pyswip/core.py:849: in <module>
        PL_mark_string_buffers = _lib.PL_mark_string_buffers
    /usr/lib/python3.6/ctypes/__init__.py:361: in __getattr__
        func = self.__getitem__(name)
    /usr/lib/python3.6/ctypes/__init__.py:366: in __getitem__
        func = self._FuncPtr((name_or_ordinal, self))
    E   AttributeError: /usr/lib/libswipl.so.7.6: undefined symbol: PL_mark_string_buffers
    

    This exact error is happening for all of the test cases.

    This error appears in core.py from pyswip library in 849 line of code

     PL_mark_string_buffers = _lib.PL_mark_string_buffers
    

    Regarding Python IDE I'm using Pycharm.

    I'am using forked version of PySwip alongside with all other necessary libraries:

    packages like ProbLog, PyTorch and TorchVision were downloaded using Pycharm package manager. PySDD and PySwip were downloaded from source.

    Also what is worth to mention is that I'm trying to run it on venv so all the packages are located inside venv/lib/python3.6/site-packages and PySwip is located inside venv/src

    I'm wondering what is the problem here and If you know the cause for this problems and how to fix them i would be grateful for giving me solution.

    • OS: Ubuntu 18.04 LTS
    • Python Version: Python 3.6
    bug 
    opened by Dcisowski 6
  • `ValueError: not enough values to unpack reported` when running MNIST example

    `ValueError: not enough values to unpack reported` when running MNIST example

    Describe the bug

    Hi,

    I encountered a ValueError: not enough values to unpack when running the provided examples as instruction told, error details shown as following:

    stack trace:

    Traceback (most recent call last):
      File "Add/add.py", line 4, in <module>
        from deepproblog.engines import ExactEngine
      File "/Users/mac/Documents/Academic/projects/dissertation/deepproblog/src/deepproblog/engines/__init__.py", line 1, in <module>
        from deepproblog.engines.approximate_engine import ApproximateEngine
      File "/Users/mac/Documents/Academic/projects/dissertation/deepproblog/src/deepproblog/engines/approximate_engine.py", line 2, in <module>
        from deepproblog.engines.prolog_engine import (
      File "/Users/mac/Documents/Academic/projects/dissertation/deepproblog/src/deepproblog/engines/prolog_engine/__init__.py", line 1, in <module>
        from .engine import PrologEngine
      File "/Users/mac/Documents/Academic/projects/dissertation/deepproblog/src/deepproblog/engines/prolog_engine/engine.py", line 4, in <module>
        from pyswip import Prolog
      File "/usr/local/anaconda3/lib/python3.8/site-packages/pyswip/__init__.py", line 29, in <module>
        from pyswip.prolog import Prolog
      File "/usr/local/anaconda3/lib/python3.8/site-packages/pyswip/prolog.py", line 28, in <module>
        from pyswip.core import *
      File "/usr/local/anaconda3/lib/python3.8/site-packages/pyswip/core.py", line 567, in <module>
        (_path, SWI_HOME_DIR) = _findSwipl()
      File "/usr/local/anaconda3/lib/python3.8/site-packages/pyswip/core.py", line 416, in _findSwipl
        (path, swiHome) = _findSwiplDar()
      File "/usr/local/anaconda3/lib/python3.8/site-packages/pyswip/core.py", line 370, in _findSwiplDar
        (path, swiHome) = _findSwiplFromExec()
      File "/usr/local/anaconda3/lib/python3.8/site-packages/pyswip/core.py", line 93, in _findSwiplFromExec
        rtvars = dict((name, value[1:-1]) for name, value in ret) # [1:-1] gets
      File "/usr/local/anaconda3/lib/python3.8/site-packages/pyswip/core.py", line 93, in <genexpr>
        rtvars = dict((name, value[1:-1]) for name, value in ret) # [1:-1] gets
    ValueError: not enough values to unpack (expected 2, got 1)
    

    To Reproduce Steps to reproduce the behavior:

    1. cd ~/deepproblog/src/
    2. export PYTHONPATH=`pwd`
    3. python3 deepproblog/examples/MNIST/addition.py

    Desktop (please complete the following information):

    • OS: macOS 11.4
    • Python Version: 3.8
    • problog 2.1.0.42
    • PySDD 0.2.10
    • pyswip 0.2.10
    • torch 1.8.0
    • torchvision 0.9.0

    Please help, thank you !

    bug 
    opened by zl-xiang 2
  • Throw TypeError when wrong PySwip version is being used

    Throw TypeError when wrong PySwip version is being used

    Altered swi_program.py to throw a TypeError when the result of the query seems to have been normalized by PySwip, i.e., the user is using the wrong PySwip version. The error message includes directions for how to resolve the issue.

    opened by LaurentMertens 0
Owner
KU Leuven Machine Learning Research Group
KU Leuven Machine Learning Research Group
Introducing neural networks to predict stock prices

IntroNeuralNetworks in Python: A Template Project IntroNeuralNetworks is a project that introduces neural networks and illustrates an example of how o

Vivek Palaniappan 637 Jan 4, 2023
Deep universal probabilistic programming with Python and PyTorch

Getting Started | Documentation | Community | Contributing Pyro is a flexible, scalable deep probabilistic programming library built on PyTorch. Notab

null 7.7k Dec 30, 2022
Deep Probabilistic Programming Course @ DIKU

Deep Probabilistic Programming Course @ DIKU

null 52 May 14, 2022
PyTorch Implementation of CvT: Introducing Convolutions to Vision Transformers

CvT: Introducing Convolutions to Vision Transformers Pytorch implementation of CvT: Introducing Convolutions to Vision Transformers Usage: img = torch

Rishikesh (ऋषिकेश) 193 Jan 3, 2023
This is an official implementation of CvT: Introducing Convolutions to Vision Transformers.

Introduction This is an official implementation of CvT: Introducing Convolutions to Vision Transformers. We present a new architecture, named Convolut

Microsoft 408 Dec 30, 2022
This is an official implementation of CvT: Introducing Convolutions to Vision Transformers.

Introduction This is an official implementation of CvT: Introducing Convolutions to Vision Transformers. We present a new architecture, named Convolut

Bin Xiao 175 Jan 8, 2023
Code and data form the paper BERT Got a Date: Introducing Transformers to Temporal Tagging

BERT Got a Date: Introducing Transformers to Temporal Tagging Satya Almasian*, Dennis Aumiller*, and Michael Gertz Heidelberg University Contact us vi

null 54 Dec 4, 2022
An attempt at the implementation of Glom, Geoffrey Hinton's new idea that integrates neural fields, predictive coding, top-down-bottom-up, and attention (consensus between columns)

GLOM - Pytorch (wip) An attempt at the implementation of Glom, Geoffrey Hinton's new idea that integrates neural fields, predictive coding,

Phil Wang 173 Dec 14, 2022
Neural Logic Inductive Learning

Neural Logic Inductive Learning This is the implementation of the Neural Logic Inductive Learning model (NLIL) proposed in the ICLR 2020 paper: Learn

null 36 Nov 28, 2022
A PyTorch Implementation of "Neural Arithmetic Logic Units"

Neural Arithmetic Logic Units [WIP] This is a PyTorch implementation of Neural Arithmetic Logic Units by Andrew Trask, Felix Hill, Scott Reed, Jack Ra

Kevin Zakka 181 Nov 18, 2022
PyTorch implementation for the Neuro-Symbolic Sudoku Solver leveraging the power of Neural Logic Machines (NLM)

Neuro-Symbolic Sudoku Solver PyTorch implementation for the Neuro-Symbolic Sudoku Solver leveraging the power of Neural Logic Machines (NLM). Please n

Ashutosh Hathidara 60 Dec 10, 2022
aka "Bayesian Methods for Hackers": An introduction to Bayesian methods + probabilistic programming with a computation/understanding-first, mathematics-second point of view. All in pure Python ;)

Bayesian Methods for Hackers Using Python and PyMC The Bayesian method is the natural approach to inference, yet it is hidden from readers behind chap

Cameron Davidson-Pilon 25.1k Jan 2, 2023
Probabilistic Programming and Statistical Inference in PyTorch

PtStat Probabilistic Programming and Statistical Inference in PyTorch. Introduction This project is being developed during my time at Cogent Labs. The

Stefano Peluchetti 109 Nov 26, 2022
Modular Probabilistic Programming on MXNet

MXFusion | | | | Tutorials | Documentation | Contribution Guide MXFusion is a modular deep probabilistic programming library. With MXFusion Modules yo

Amazon 100 Dec 10, 2022
PClean: A Domain-Specific Probabilistic Programming Language for Bayesian Data Cleaning

PClean: A Domain-Specific Probabilistic Programming Language for Bayesian Data Cleaning Warning: This is a rapidly evolving research prototype.

MIT Probabilistic Computing Project 190 Dec 27, 2022
Crab is a flexible, fast recommender engine for Python that integrates classic information filtering recommendation algorithms in the world of scientific Python packages (numpy, scipy, matplotlib).

Crab - A Recommendation Engine library for Python Crab is a flexible, fast recommender engine for Python that integrates classic information filtering r

python-recsys 1.2k Dec 21, 2022
GAN encoders in PyTorch that could match PGGAN, StyleGAN v1/v2, and BigGAN. Code also integrates the implementation of these GANs.

MTV-TSA: Adaptable GAN Encoders for Image Reconstruction via Multi-type Latent Vectors with Two-scale Attentions. This is the official code release fo

owl 37 Dec 24, 2022
pcnaDeep integrates cutting-edge detection techniques with tracking and cell cycle resolving models.

pcnaDeep: a deep-learning based single-cell cycle profiler with PCNA signal Welcome! pcnaDeep integrates cutting-edge detection techniques with tracki

ChanLab 8 Oct 18, 2022
Registration Loss Learning for Deep Probabilistic Point Set Registration

RLLReg This repository contains a Pytorch implementation of the point set registration method RLLReg. Details about the method can be found in the 3DV

Felix Järemo Lawin 35 Nov 2, 2022