Giter Site home page Giter Site logo

ml-kuleuven / deepproblog Goto Github PK

View Code? Open in Web Editor NEW
181.0 181.0 47.0 17.46 MB

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

License: Apache License 2.0

Python 63.33% Prolog 36.25% Shell 0.04% Makefile 0.17% Batchfile 0.21%

deepproblog's People

Contributors

laumerte avatar quinten-d avatar rmanhaeve avatar shuv6779 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

deepproblog's Issues

`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] Unhandled type <class 'str'>

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] 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

Query regarding the Multi-Digit Addition

Hi

I am reading about the DeepProbLog programs. In the paper, an experiment regarding multi-digit MNIST addition is mentioned as shown below:
multi_digit_addition
But I am getting slightly confused with the syntax here like what H and T mean here. Here, I am assuming that Acc and Acc2 are accumulator variables that store the intermediate results.
Let's say I supply the following input to this program as shown:
input
Do H and T mean the first and last elements of the list respectively?
If I have to represent a list with K elements, then how to represent all the elements except the first and the last?
What is the stopping condition in this recursive program? Is it [H|T] that says that only two elements can be present in the list?
Do you have any kind of tutorial apart from the examples provided in the research paper?

[BUG] 'The SDD library is not available' on mac os Ventura

Describe the bug
9 given tests fail, displaying an error 'The SDD library is not available'

To Reproduce
run pip install deepproblog, run pip install pytest and then python -m deepproblog test

Expected behavior
9 tests should pass

Desktop

  • OS: macOS Ventura 13.2.1
  • Python Version: 3.11

[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)'])))

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.