DeepStochLog

DeepStochLog is a neuro-symbolic framework that combines grammars, logic, probabilities and neural networks. By writing a DeepStochLog program, one can train a neural network with the given background knowledge. One can express symbolic information about subsymbolic data in DeepStochLog and help train neural networks more efficiently this way. For example, if the training data is made up of handwritten digit images, and we know the sum of these digits but not the individual numbers, one can express this relation in DeepStochLog and train the neural networks much faster.


Capabilities

Sum of handwritten numbers

As an example consider having to calculate the sum of two handwritten numbers, but never having seen handwritten numbers with their numeric label, but only having seen having seen combinations of handwritten numbers together with their numerical sum.

_images/sum.png

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

This handwritten sum problem was originally created in the development of its sibling framework, DeepProbLog. 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 or labeling papers in a citation graph, or any other task that could be expressed using neural stochastic logic.

In our experiments in the paper, we found that for all tasks, DeepStochLog achieved state-of-the-art accuracy, but scaled better than other similar neural-symbolic frameworks.


Defining Neural Definite Clause Grammars

Rules in DeepStochLog are modelled 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)


Understanding Neural Definite Clause Grammars

DeepStochLog extends definite clause grammars with neural probabilities to create “Neural Definite Clause Grammars”. To understand this, let’s take a look at the basic building blocks, namely context-free grammars and probabilistic context-free grammars, as well as it’s logic-based extensions definite clause grammars and stochastic definite clause grammars.

Context-free grammars

Context-free grammars model rules as just mappings from non-terminals to sequences of other non-terminals and terminals. It is useful for a wide variety of 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 all elements of language

_images/cfg.png

Parsing using a context-free grammar

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 is useful for finding 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?

_images/pcfg.png

Parsing using a probabilistic context-free grammar

Definite clause grammars

Definite clause grammars extend context-free grammars with logic programming concepts. It allows for adding arguments to the non-terminals, and adding extra logic calculations between the curly brackets {}. Thanks to the addition of logic programming, this makes this type of grammar Turing-complete. Definite clause grammars are useful for:

  • Modelling 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)

_images/dcg.png

Parsing using a definite clause grammars

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. This thus gives rise to the same type of 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.

_images/sdcg.png

Parsing using a stochastic definite clause grammars

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 useful for:

  • Subsymbolic processing: e.g. tensors as terminals

  • Learning rule probabilities using neural networks

_images/ndcg.png

Parsing using a neural definite clause grammars

Text and illustrations for this section were provided by Thomas Winters.