Projects

DeepStochLog

Neural stochastic logic programming, published at AAAI 2022

Code Cite

DeepStochLog cover

DeepStochLog is a neural-symbolic framework for neural stochastic logic programming. This framework allows users to express background knowledge using logic and probabilities to train neural networks more effectively. It achieved state-of-the-art results on a wide variety of tasks while scaling much better than alternative neural-symbolic frameworks.

For more depth, see the paper and the code on GitHub.

Capabilities

Sum of handwritten numbers

For example, take adding up two handwritten numbers, when you have never seen a handwritten digit with its label: only pairs of handwritten numbers together with their sum.

Example of a sum of handwritten numbers
Example of a sum of handwritten numbers

DeepStochLog encodes this information as follows:

digit_dom(Y) :- member(Y,[0,1,2,3,4,5,6,7,8,9]).

nn(number, [X], Y, digit_dom) :: digit(Y) --> [X].
1 :: addition(N) --> digit(N1),
                     digit(N2),
                     {N is N1 + N2}.

General tasks

More generally, DeepStochLog can easily parse and classify sequences of subsymbolic information like images that follow a known grammar structure. It can even encode general problems like word algebra problems, labeling papers in a citation graph, or any other task that could be expressed using neural stochastic logic.

In the paper’s experiments, DeepStochLog reached state-of-the-art accuracy on all tasks, and it scaled better than similar neural-symbolic frameworks. On the sum of handwritten numbers, for example, it works out the probability of a query in a few milliseconds, where DeepProbLog and NeurASP need up to two hundred, and can’t finish once the numbers have four digits:

Time for one query, in milliseconds
Numbers of 1 digit
DeepStochLog 1.3 ms
DeepProbLog 13.5 ms
NeurASP 9.2 ms
Numbers of 2 digits
DeepStochLog 2.3 ms
DeepProbLog 36.0 ms
NeurASP 85.7 ms
Numbers of 3 digits
DeepStochLog 4.0 ms
DeepProbLog 199.7 ms
NeurASP 158.2 ms
Numbers of 4 digits
DeepStochLog 5.7 ms
DeepProbLog timeout
NeurASP timeout

The average time to compute the probability of a query, over 100 queries from the training data (the paper, Table 7). DeepStochLog stores the derivations it has worked out to reuse them (tabling), and its random-walk semantics is cheaper to compute than the possible worlds of DeepProbLog and NeurASP.

Understanding neural definite clause grammars

DeepStochLog extends definite clause grammars with neural probabilities to create “Neural Definite Clause Grammars”. To understand this, let’s look at the basic building blocks, namely context-free grammars and probabilistic context-free grammars, as well as its logic-based extensions, definite clause grammars, and stochastic definite clause grammars. The figure below parses the same sum with each of them, in the order of the sections after it.

CFG: Context-free grammar Rules that rewrite a non-terminal into non-terminals and terminals.

E --> NE --> E, P, NP --> ["+"]N --> ["0"]N --> ["1"]…N --> ["9"]
E E E N P N P N 2 + 3 + 8

PCFG: Probabilistic context-free grammar A probability for every rule; the rules of a non-terminal add up to 1.

0.5 :: E --> N0.5 :: E --> E, P, N1.0 :: P --> ["+"]0.1 :: N --> ["0"]0.1 :: N --> ["1"]…0.1 :: N --> ["9"]
E 0.5 E 0.5 E 0.5 N 0.1 P 1 N 0.1 P 1 N 0.1 2 + 3 + 8

Probability of this parse: 0.5 × 0.5 × 0.5 × 0.1 × 1 × 0.1 × 1 × 0.1 = 0.000125

DCG: Definite clause grammar Arguments and Prolog goals between braces: here, the value of the sum.

e(N) --> n(N).e(N) -->    e(N1), p, n(N2),    {N is N1 + N2}.p --> ["+"].n(0) --> ["0"].n(1) --> ["1"].…n(9) --> ["9"].
e(13) e(5) e(2) n(2) p n(3) p n(8) 2 + 3 + 8

SDCG: Stochastic definite clause grammar Probabilities on the rules again. A derivation that fails loses its probability.

0.5 :: e(N) --> n(N).0.5 :: e(N) -->    e(N1), p, n(N2),    {N is N1 + N2}.1.0 :: p --> ["+"].0.1 :: n(0) --> ["0"].0.1 :: n(1) --> ["1"].…0.1 :: n(9) --> ["9"].
e(13) 0.5 e(5) 0.5 e(2) 0.5 n(2) 0.1 p 1 n(3) 0.1 p 1 n(8) 0.1 2 + 3 + 8

Probability of this parse: 0.5 × 0.5 × 0.5 × 0.1 × 1 × 0.1 × 1 × 0.1 = 0.000125

NDCG: Neural definite clause grammar (DeepStochLog) A neural network gives a rule its probabilities, so the terminals can be images.

0.5 :: e(N) --> n(N).0.5 :: e(N) -->    e(N1), p, n(N2),    {N is N1 + N2}.1.0 :: p --> ["+"].nn(number_nn, [X], [Y],   [digit])    :: n(Y) --> [X].digit(Y) :- member(Y,    [0,1,…,9]).
e(13) 0.5 e(5) 0.5 e(2) 0.5 n(2) P(2) p 1 n(3) P(3) p 1 n(8) P(8) a handwritten 2 + a handwritten 3 + a handwritten 8

Probability of this parse: 0.5 × 0.5 × 0.5 × P(2) × 1 × P(3) × 1 × P(8), where P(2) is how sure number_nn is that its image shows a 2

Each grammar parses 2 + 3 + 8 (from our talk at AAAI 2022). What a grammar adds to the one before is on the sun, in its rules and in its tree. The number under a node is the probability of the rule that expands it.

Context-free grammars

Context-free grammars model rules as just mappings from non-terminals to sequences of other non-terminals and terminals. They are useful for many language tasks, such as:

  • Finding out if a sequence is an element of the specified language
  • Labeling the “part of speech”-tag of a terminal
  • Generating every sentence of the language

Probabilistic context-free grammars

Probabilistic context-free grammars extend context-free grammars by adding probabilities to every rule. The probabilities of all used rules in the expansion are then used to calculate the probability of a particular parse. This framework helps find answers to the following questions:

  • What is the most likely parse for this sequence of terminals? (useful for ambiguous grammars)
  • What is the probability of generating this string?

Definite clause grammars

Definite clause grammars extend context-free grammars with logic programming concepts. They allow adding arguments to the non-terminals, and extra logic between curly brackets {}. The addition of logic programming makes this type of grammar Turing-complete.

Definite clause grammars are helpful for:

  • Modeling more complex languages (e.g. context-sensitive)
  • Adding constraints between non-terminals thanks to Prolog power (e.g., through unification)
  • Extra inputs & outputs aside from terminal sequence (through unification of input variables)

Stochastic definite clause grammars

Stochastic definite clause grammars add the same benefit to definite clause grammars as probabilistic context-free grammars add to context-free grammars, namely adding probabilities to rules. These grammars thus give rise to the same benefits, like finding the most likely parse. However, since expansions can fail in a definite clause grammar, probability mass can get lost in such a failing derivation, meaning that the sum of the probabilities of all possible elements is not necessarily 1.

Neural definite clause grammars

Neural definite clause grammars add neural probabilities to stochastic definite clause grammars, which swap rule probabilities with neural networks that output a probability. This is the same trick as DeepProbLog does to probabilistic logic programming, but then to stochastic definite clause grammars.

This framework is helpful for:

  • Subsymbolic processing: e.g. tensors as terminals
  • Learning rule probabilities using neural networks

Defining neural definite clause grammars

Rules in DeepStochLog are modeled as grammar rules that are allowed to contain arguments, logic, and (neural) probabilities.

nn(m,[I1,…,Im],[O1,…,OL],[D1,…,DL]) :: nt --> g1, …, gn.

Where:

  • nt is an atom
  • g1,…,gn are goals (goal = atom or list of terminals & variables)
  • I1,…,Im and O1,…,OL are variables occurring in g1,…,gn and are the inputs and outputs of m
  • D1,…,DL are the predicates specifying the domains of O1,…,OL
  • m is a neural network mapping I1,…,Im to probability distribution over O1,…,OL (= over cross product of D1,…,DL)

Talks about DeepStochLog

Papers

Citation

 

How to cite

DeepStochLog: Neural Stochastic Logic Programming

@article{Winters_Marra_Manhaeve_Raedt_2022,
	title        = {DeepStochLog: Neural Stochastic Logic Programming},
	author       = {Winters, Thomas and Marra, Giuseppe and Manhaeve, Robin and De Raedt, Luc},
	year         = 2022,
	month        = {Jun.},
	journal      = {Proceedings of the AAAI Conference on Artificial Intelligence},
	volume       = 36,
	number       = 9,
	pages        = {10090--10100},
	doi          = {10.1609/aaai.v36i9.21248},
	url          = {https://ojs.aaai.org/index.php/AAAI/article/view/21248},
	abstractnote = {Recent advances in neural-symbolic learning, such as DeepProbLog, extend probabilistic logic programs with neural predicates. Like graphical models, these probabilistic logic programs define a probability distribution over possible worlds, for which inference is computationally hard. We propose DeepStochLog, an alternative neural-symbolic framework based on stochastic definite clause grammars, a kind of stochastic logic program. More specifically, we introduce neural grammar rules into stochastic definite clause grammars to create a framework that can be trained end-to-end. We show that inference and learning in neural stochastic logic programming scale much better than for neural probabilistic logic programs. Furthermore, the experimental evaluation shows that DeepStochLog achieves state-of-the-art results on challenging neural-symbolic learning tasks.}
}

All projects