Getting started
INSTALLATION
Ship a NeSy baseline in under a minute
Install DeepLog from PyPI or from source to explore the tutorial notebooks and examples.
Install DeepLog with pip, optionally adding extras for notebooks, tests, or the Janus backend:
pip install pydeeplog
Add extras as needed, for example pip install "pydeeplog[examples,tests]".
The recommended approach in Conda environments is to install PyTorch via Conda Forge first, then install DeepLog from PyPI:
conda install pytorch -c conda-forge
pip install pydeeplog
This approach is handy when you need GPU-enabled PyTorch builds from Conda Forge.
Clone the repository to track the latest commits or to contribute to DeepLog itself.
git clone https://github.com/ML-KULeuven/deeplog.git
cd deeplog
pip install -e ".[tests,examples]"
Editable installs automatically refresh when you modify the source tree.
Feature extras
pydeeplog[mvsdd]— installs mv-sdd, the knowledge compiler for formulas that test several values of one variable, such as a digit classifier’s ten classes in MNIST addition. Without it, such an expectation is enumerated.pydeeplog[tests]— includes pytest, pytest-xdist and coverage, and what the example notebooks need, to executepytestacross the repo, notebooks included.pydeeplog[examples]— pulls the tutorial notebook requirements so every example in Tutorial runs without additional setup.pydeeplog[site]— installs the doc toolchain (Sphinx, myst-nb, design components) so you can run(cd site && make html)locally.pydeeplog[janus_engine]— activates the SWI-Prolog powered Janus backend for lower-latency logical inference (requires a local SWI-Prolog install).
Hello DeepLog (30 seconds)
import torch
from deeplog import SymTensor, parse_formula_to_module, reshape
# Compute the expected value of an implication (A → B ≡ ¬A ∨ B).
# E[A → B] where A and B are independent boolean random variables.
module = parse_formula_to_module(
"expectation(A, B): not =(A,true)_boolean or =(B,true)_boolean"
)
# A module names its inputs, so declare the layout of your data and
# reshape the module onto it instead of matching its input order.
# Without a distribution, A is distributed by a/1 and B by b/1.
layout = SymTensor(["a(true) _ probability", "b(true) _ probability"])
module = reshape(module, layout)
# Each row: [P(A=true), P(B=true)]
probs = torch.tensor(
[
[0.0, 0.0], # A is false, so implication holds: E = 1.0
[1.0, 1.0], # Both true, implication holds: E = 1.0
[1.0, 0.0], # A true, B false, implication fails: E = 0.0
[0.8, 0.3], # E[A → B] = P(¬A) + P(A)P(B) = 0.2 + 0.8*0.3 = 0.44
]
)
expectations = module(probs)
for (p_a, p_b), exp in zip(probs, expectations):
print(f"P(A)={p_a:.1f} P(B)={p_b:.1f} -> E[A → B]={float(exp):.2f}")
P(A)=0.0 P(B)=0.0 -> E[A → B]=1.00
P(A)=1.0 P(B)=1.0 -> E[A → B]=1.00
P(A)=1.0 P(B)=0.0 -> E[A → B]=0.00
P(A)=0.8 P(B)=0.3 -> E[A → B]=0.44
This computes the probability that an implication holds when A and B are true independently, with the given probabilities: a weighted model count. The expectation operator compiles the boolean formula into the probability semiring. Feed this into your loss to softly encourage logical constraints during training.
See also
Tutorial ‒ pick the example notebook that matches your workload.
Public API ‒ dive into the API reference when you start composing modules.