DeepLog
The PyTorch for neurosymbolic AI
This post is based on the following publications:
- DeepLog: A Software Framework for Modular Neurosymbolic AI. Manhaeve, R., Colamonaco, S., Derkinderen, V., Adriaensen, R., Van Praet, L., De Raedt, L., Marra, G., IJCAI 2026 (Demo Track), pp. 8462–8465.
- The DeepLog Neurosymbolic Machine. Derkinderen, V., Manhaeve, R., Adriaensen, R., Van Praet, L., De Smet, L., Marra, G., De Raedt, L., arXiv, 2025.
Software is available on
GitHub and
PyPI (pip install pydeeplog), with
documentation.
In 2020, we wrote on this blog about DeepProbLog, which lets a neural network supply the probabilities of the facts in a probabilistic logic program. Building DeepProbLog meant building everything underneath it: a reasoner to prove the queries, a knowledge compiler to turn the proofs into circuits, and an evaluator to compute those circuits and their gradients. Every neurosymbolic system since has done the same, each on its own.
Deep learning stopped working that way a long time ago. With PyTorch, you describe a model by composing layers, and the framework takes care of the tensors, the gradients and the GPU. DeepLog does the same for neurosymbolic AI. You state the logic of a model, as a formula or as a program, and DeepLog turns it into a differentiable PyTorch module that you combine with your networks and train like any other.

Code · Documentation · PyPI · Paper
From logic to a PyTorch module
At the heart of DeepLog is the DeepLog language, which we introduced in The DeepLog Neurosymbolic Machine. It extends first-order logic with neural networks, and every formula in it names the algebra it is evaluated in: boolean, probabilistic, one of many fuzzy logics, or one you define yourself.

Whatever you start from, DeepLog takes the same three steps:
- A front end turns the model into a formula in the DeepLog language. For DeepProbLog, that is a Prolog engine that proves the queries; for semantic loss, a parser for the constraint. You can also write the formula yourself.
- The compiler lowers the formula: it chooses, for each part, a strategy that turns it into tensor operations. By default, DeepLog computes probabilities exactly by knowledge compilation into algebraic circuits, graphs of sums and products in the algebras the formula names, because that is the method we know best. But DeepLog is not tied to circuits: enumeration and sampling are strategies too, and other inference methods can be added as new ones.
- The result is one ordinary
torch.nn.Module, with the neural networks inside it. It runs as batched tensor operations on the GPU, next to the networks, instead of on the CPU between them; circuits, for example, are evaluated with KLay.
What to compute, and how
The most direct way to use DeepLog is to write a formula. The one below asks for the probability of burglary or earthquake, where a burglary happens with probability 0.8 and an earthquake with probability 0.3:
from deeplog import Compiler, enumeration, parse_formula, sampling
alarm = parse_formula("""
expectation(Burglary, Earthquake;
p(Burglary,0.8)_probability times p(Earthquake,0.3)_probability):
=(Burglary,true)_boolean or =(Earthquake,true)_boolean
""")
Compiler().compile(alarm)() # 0.86
Compiler(aggregation_builders={"expectation": enumeration}).compile(alarm)() # 0.86
Compiler(aggregation_builders={"expectation": sampling(10_000)}).compile(alarm)() # ≈ 0.86
The _boolean and _probability annotations are the algebras: the condition is a boolean formula, and its distribution is a product of probabilities.
As in PyTorch, where you write the forward pass and the framework derives the gradients, the formula says what to compute and the compiler decides how. By default, DeepLog computes an expectation exactly, by knowledge compilation. It can also enumerate every possible world, or estimate the value by sampling when a formula is too large to compile. Choosing between them is one argument to the compiler, and a new inference method plugs in the same way. Each result is a PyTorch module, so the gradients come for free.
DeepProbLog, revisited
A front end lets you write in a language you already know. Here is the MNIST-addition program from our 2020 post, in the form DeepLog reads it:
nn(mnist_classifier, [X], Y, [0..9]) :: digit(X, Y).
addition(X, Y, Z) :- digit(X, N1), digit(Y, N2), is(Z, +(N1, N2)).

The network mnist_classifier gives, for each image, a distribution over the digit it shows, and the rule says how digits add up.
DeepLog proves the query addition(i1, i2, Z) and turns the proofs into a formula like the one above: the expected value, under the network’s distributions, of “the two digits add up to Z”.
It compiles that formula into a PyTorch module that takes two images and returns a probability for each of the 19 possible sums, with the classifier inside it.
You train it with an ordinary PyTorch training loop, on the sums alone, and the classifier learns to recognise digits without ever seeing a digit label.
The
DeepProbLog notebook does this end to end.
Because the compiled module is batched tensor code, it is much faster than the original DeepProbLog. Here is the average time to evaluate the network and the circuit for one query on MNIST addition, where the numbers to add have 1 to 4 digits:
| Digits | DeepProbLog (CPU) | DeepLog (CPU) | DeepLog (GPU) |
|---|---|---|---|
| 1 | 6.1 ms | 11 µs | 0.56 µs |
| 2 | 35 ms | 41 µs | 1.5 µs |
| 3 | 132 ms | 2.4 ms | 0.15 ms |
| 4 | – | 196 ms | 54 ms |
For single-digit addition, DeepLog is over 500 times faster on a CPU, and over 10,000 times faster on a GPU (an NVIDIA L40S). The original DeepProbLog handles one query at a time; DeepLog evaluates a whole batch at once.
One framework for the alphabet soup
Because DeepLog is a framework and not one more system, it can also bring the existing systems together. Neurosymbolic AI has grown into an alphabet soup: DeepProbLog, DeepStochLog, DeepSoftLog, NeurASP, Scallop, Logic Tensor Networks, semantic loss, and many more. Each comes with its own language, its own semantics and its own engine, so comparing two of them means comparing two code bases, and an idea that works in one has to be reimplemented before it can be tried in another.
Look closely, and most of these systems differ along a handful of axes:
- How you write the knowledge. A Prolog program in DeepProbLog, first-order formulas in Logic Tensor Networks, a constraint in conjunctive normal form for semantic loss.
- What the connectives mean. In a probabilistic logic, A or B is the probability that at least one of them holds. In a fuzzy logic, it is a function of the two truth values, such as their maximum.
- Where the neural network sits. Inside the model, where its outputs become the probabilities of facts, or outside it, where the logic becomes a term in the loss.
In DeepLog, each of these is a choice within one framework: a front end, an algebra, and where the networks go. ProbLog, DeepProbLog, semantic loss and Logic Tensor Networks are already implemented on DeepLog. Reading the connectives in a fuzzy logic instead of in probability, for example, gives you Logic Tensor Networks: our LTN notebook reproduces part of the LTN tutorial this way. Comparing two systems becomes comparing two formulas, compiled by the same compiler and run on the same hardware.
Who is it for?
We built DeepLog for two kinds of users.
Machine learning practitioners. A DeepLog module is a PyTorch module, so you can add logic to an existing model without rewriting your training code. The semantic loss notebook, for example, adds a logical constraint to an MNIST classifier as a term in its loss. Every module declares symbolic shapes for its inputs and outputs, so connecting two modules that don’t fit raises an error instead of producing a silent shape bug.
Neurosymbolic researchers. You no longer have to write a reasoner, a knowledge compiler and a GPU evaluator before you can try an idea. A new system is built from DeepLog’s parts, the way a new architecture is built from PyTorch’s layers, and it runs on the same compiler as the systems it is compared with. A new inference method becomes a lowering strategy, and every front end can use it at once.
Try it
pip install pydeeplogThe documentation teaches DeepLog through notebooks, from symbolic shapes to MNIST addition, in two reading paths: one for ML practitioners and one for neurosymbolic developers. Every notebook opens in Colab. At IJCAI 2026 in Bremen, we presented DeepLog in the demo track and in a half-day tutorial, whose materials are online. Questions, bug reports and ideas are welcome as GitHub issues.
DeepLog is developed at DTAI as part of the ERC Advanced Grant project DeepLog (grant agreement No. 101142702).