T OP -D OWN N EURAL M ODEL F OR F ORMULAE
Anonymous authors
Paper under double-blind review
A BSTRACT
We present a simple neural model that given a formula and a property tries to answer the question whether the formula has the given property, for example whether a propositional formula is always true.
A structure of formula is captured by a feedforward neural network build recursively for the given formula in a top-down manner.
The results of this network are then processed by two recurrent neural networks.
One of the interesting aspects of our model is how propositional atoms are treated.
The model is insensitive to the renaming of atoms and to the number of distinct atoms occurring in the formula.
I NTRODUCTION
In real-world situations a very successful approach, popularized in Kahneman (2011), to problem solving is based on a clever combination of fast instinctive (heuristic) reasoning and slow logical reasoning.
The latter is exempliﬁed by abstract logical formulae where only structural properties matter.
If computers are involved, a logical formula is traditionally a syntactic object which is a subject to simple but very fast syntactic manipulations Robinson & Voronkov (2001).
Hence all but very basic decisions are postponed if possible.
However, this viewpoint is rapidly changing as various AI methods are tested in the ﬁeld of automated reasoning, in particular machine learning methods.
A fundamental problem in using machine learning in automated reasoning is a suitable representation of logical formulae.
A formula as a solely syntactic object is no longer sufﬁcient and we have to exploit its semantic properties.
Various approaches have been proposed for different logical systems.
In this paper we will concentrate on the simplest yet very powerful standard logical system—classical (Boolean) propositional logic.
This paper presents, as far as we know, a novel neural representation of propositional formulae that makes it possible to test whether a given formula has a given property, e.g., whether the formula is always true or not.
Clearly, we try to solve a well-known CO NP-complete problem.
However, the fact that the problem is generally hard and requires a non-trivial search does not rule out the possibility that a decent heuristic can be learned, moreover, if only a speciﬁc subset of formulae is involved.
In particular, our general goal is to obtain a useful heuristic that can help us in guiding a proof search, where we typically face numerous choice points.
Unlike in natural language processing, a parse tree for a formula is available for free.
Although some approaches do not exploit this feature and try to learn the structure of a formula on their own, using usually various recurrent neural networks (RNN), it is more common to take advantage of this knowledge.
Moreover, it seems that the later approach has a signiﬁcant edge, see Evans et al.
Usually propositional atoms, basic building blocks of propositional formulae, are learned as embeddings and each logical connective is treated as a unique neural network that given the vector representation of its arguments produces a vector that represents an application of the connective on these arguments, e.g., a binary connective takes two vectors of length d , and produces a new one of length d , see Allamanis et al.
This clearly leads to tree recursive neural networks Socher et al.
(2012) where the structure of the network follows the parse tree.
Such models are built bottomup and the meaning of the formula is usually the vector produced in the root of the tree.
Our model also uses the parse tree of formula, but the knowledge is propagated in the opposite direction.
We start with a vector (random or learned), representing a property we want to test, and we propagate it from the root to leaves (propositional atoms).
The knowledge propagated to atoms is then processed by recurrent neural networks and a decision is produced.
This makes it possible to ignore completely the names of propositional atoms and concentrate more on structural properties of formulae.
The experimental results suggest that the model is more than competitive and beats other known approaches on some benchmarks.
More importantly, our model seems to suffer less if bigger formulae are involved and could be more useful in real world scenarios.
The structure of this paper is as follows.
In Section 2 we discuss the architecture of our model in full details and also a dataset on which we will experiment is introduced there.
In Section 3 we discuss an implementation of building blocks of our network and present experimental data.
Some possible future modiﬁcations are brieﬂy mentioned in Section 4.
Few relevant models are mentioned in Section 5 and the paper concludes with Section 6.
M ODEL
Our model tries to mimic the following approach sometimes used by humans to decide whether a propositional formula is always true (tautology).
If we want to know whether, e.g., ( p → q ) ∨ ( q → p ) is a tautology 1 we can suppose the contrary and try to produce a truth-value assignment such that the whole formula is false.
It means both p → q and q → p are false under such an assignment 2 .
It follows from the former that p is true and q is false, but from the latter we obtain that q is true and p is false.
Because such an assignment is impossible, we showed that the formula cannot be false and hence it is always true.
In a nutshell, we try to propagate a truth value assigned to the whole formula, in our case the formula being false, to its subformulae and we repeat this process until we reach propositional atoms.
This gives us a set of constraints on possible truth-value assignments to atoms.
At this point we check whether a truth-value assignment satisfying these constraints exists and thus we answer the original question.
However, it is pretty clear that usually this approach is not so straightforward.
For example, if we want a formula of the form A → B to be true, it means that the subformula A is false or the subformula B is true.
Moreover, such choices easily accumulate with the increasing depth 3 of formula.
Still we will show that a neural model based on the above mentioned idea is competitive.
Similarly to a standard recursive approach we also represent a formula by a recursively built model based on the parse tree of formula.
However, unlike there we use a top-down approach.
In our case, we start with a vector w ∈ R d (random or learned), where d is a parameter of the model, that roughly represents a property of formulae we want to check.
4 We continue by propagating this knowledge to subformulae in a top-down manner, e.g., a binary connective ◦ takes a vector v ∈ R d (input) and produces two new vectors v 1 ∈ R d and v 2 ∈ R d (outputs), hence ◦ : R n → R n × R n .
Since all the vector have the same length d , it is possible to connect individual building blocks together and produce a recursive neural network.
The basic building blocks of the tree part of our model are w ∈ R d an initial vector,
[Equation]
a neural network that represents a k -ary logical connective i , for all logical connectives i in our language 5 . From these components, which are shared among all formulae in a given language, we dynamically build a recursive network for a particular formula that corresponds to the parse tree of formula—the w
[Equation]
c → p [Equation]
q
[Equation]
qp
RNN-Var
RNN-Var ppqqp q
RNN-All
Final out parse tree tells us how to connect individual components together.
For example in the left part of
Figure 1 we see a model for F = ( p → q ) ∨ ( q → p ) , which is directly obtained from the parse tree.
The vector w is an input to the root of the tree and all the connectives in it are replaced by neural nets
c i that represent them.
Atoms contain propagated outputs (vectors) of this tree recursive model, here we obtain vectors p 1 , q 1 , q 2 , p 2 ∈ R d , where p 1 is at the position of the ﬁrst occurrence of p in
F .
Note that each occurrence of the same atom in our tree model produces a unique vector.
The fact that they correspond to the same atom is exploited by another level of our model.
We take a recurrent neural network RNN-Var that has a sequence of all vectors corresponding to the same atom in the formula as an input and outputs a vector in R d .
In Figure 1 RNN-Var takes p 1 and p 2 and outputs p ∈ R d and also the same RNN-Var takes q 1 and q 2 and outputs q ∈ R d .
One more recurrent neural network RNN-All takes the sequence of all output vectors produced by
RNN-Var and outputs a vector in R d that is input to a component Final : R d → R 2 which ends with a softmax layer and produces out ∈ R 2 that makes it easy to decide whether the output of whole network is true or false.
It should be emphasized that our model completely ignores the names of atoms, we only check whether they are the same or distinct.
The basic building blocks of the recurrent part of our model are
RNNVar
[Equation]
a RNN aggregating vectors corresponding to the same atom,
RNNAll : R d
[Equation]
a RNN aggregating the outputs of RNN-Var components,
Final : R d → Ra ﬁnal decision layer.
It should be emphasized again how the model is built.
Given a property we want to test, e.g., whether a formula is always true, we train representations of w , c
i , RNN-Var, RNN-All, and Final.
These components are shared among all the formulae.
For a single formula we produce a model (neural network) recursively from them as described above.
For implementation details see Section 3.
2. D ATASET
To provide comparable results in Section 3 we use the dataset 6 presented in Evans et al.
(2018) and thoroughly described therein.
For our purposes here it is essential that it contains triples of the form ( A, B, A | = B ) where A and B are propositinal formulae and A | =
B indicates whether B follows from A .
The dataset contains train (99876 triples), validation (5000), and various test sets with a different level of difﬁculty given by a number of atoms and connectives 7 occurring in them.
From the deduction theorem we know that A | =
B is equivalent to A → B being a tautology.
We prefer the later form, because it ﬁts nicely into our model and instead of learning the meaning of entailment ( | = ), we can use the connective → directly.
Note that although our model ignores the names of atoms this cannot be exploited directly, because validation and test sets do not contain pairs of formulae that would result from pairs in the training set after renaming atoms.
E XPERIMENTS
Although our model is conceptually simple, each building block can be implemented in various ways.
In this section we brieﬂy discuss some possible variants and parameters.
However, we have not tried to optimize over all the possible parameters discussed later and it is very likely that our results can be improved.
The following implementation of the model introduced in Section 2 is our standard experimental model, called TopDownNet:
• d = 128 , • w ∈ R d is a learned vector, • every c
i is a sequence of linear, ReLU, linear, and ReLU layers, where the input size and output size is always the same with the exception of binary connectives, where the last linear layer is R d → R 2 d , • RNN-Var is a gated recurrent unit (GRU) with 2 recurrent layers and the size of input and hidden state is d , • RNN-All is a GRU with 1 recurrent layer and the size of input and hidden state is d , • Final is a sequence of linear ( R d → R d/ 2 ), ReLU, linear ( R d/ 2 → R 2 ), and a log softmax, and we use the mean square error as a loss function and Adam algorithm as an optimizer with the learning rate 10 − 4 .
A key parameter of our model is the dimension d , which is the length of the initial vector w and also the length of most other vectors occurring in our model.
Even d = 8 produces reasonable results, as
Figure 2 shows, but with increasing d the quality of the model grows, see Table 1.
Our various experiments suggest that whether w is chosen randomly or learned makes little to no difference.
8 Similarly and more importantly, connectives c i composed of a single linear layer seem to perform almost equally, and sometimes even better, to more complicated versions containing non-linearities as in our standard TopDownNet.
In RNN-Var and RNN-All we use gated recurrent units (GRUs) which in our experiments perform similarly to long short-term memory (LSTM) RNNs, Similarly to results obtained in Evans et al.
(2018), we have seen no real advantage of using their bidirectional variants for our model and in many cases they produce worse results.
The order in which RNN-Var and RNN-All consume their inputs is random.
Although it is conceptually nicer and ﬁts to our original intuition, our combination of two RNNs and their functions clearly suggest a question whether they are in fact necessary.
Either we can use the same RNN for RNN-Var and RNN-All, or we can use padding to separate the sequences of different atoms.
Our preliminary experiments suggest that both new variants and our original approach perform quite similarly, see Figure 3.
[Figure]
d= d= d= d= d= d= d= d=
Epochs
V a li d a t i o n s u cc e ss r a t e
[Figure]
Epochs
V a li d a t i o n s u cc e ss r a t e
It seems that if the ﬁnal layer is just a combination of linear and log softmax the performance is slighly better than the one used in TopDownNet with an added non-linearity.
However, the best
[Table]
performing models that we present in Table 1 use our standard parameters with different values of dimension d .
In Table 1 is a comparison of our models and other approaches mentioned in the benchmark in Evans et al.
The values for the ﬁrst three models are taken from that paper.
TreeNN follows Allamanis et al.
and TreeLSTM follows Tai et al.
PossibleWorldNet is developed in Evans et al.
TopDownNets are our standard models from the beginning of Section 3 with the lowest losses on the validation set for different values of d .
The results in Table 1 show that our model is competitive with other approaches.
It beats standard tree recursive models (TreeNet Encoders and TreeLSTM Encoders) and PossibleWorldNet, which performs similar to testing random truth-values, on the massive set and keeps pace on examples from textbooks.
The good results on the massive set suggest that our model can do better than just random testing of truth-values.
Moreover, it is interesting that the increase of d does not have such a signiﬁcant role, as already mentioned before. 3. I NTERPRETATION OF MODEL
We present our model as an alternative to bottom-up approaches, where a possible interpretation of such models is that they combine (samples of) random assignments and produce the value of the whole formula.
Similarly, we could argue that our model propagates a truth value top-down and makes (sampled) random choices when multiple options are available, e.g., when we want to make A → B true.
However, this clearly does not explain better results of our model, because for example on the massive set from Table 1 random assignments are much more successful than random top-down propagations.
Our model therefore has to take advantage of something else. Clearly, it uses training data more efﬁciently, because it is insensitive to the names of atoms, but this is not enough to explain our results. However, it is possible that the top-down propagation captures the overall structure of the formula better and enables a more efﬁcient transfer of knowledge through formulae. All formulae in the dataset are of the form A → B , see Section 2.1, hence propagating w , which is supposed to mean false, through → , denoted c → ( w ) , produces two vectors v → 1 and v → 2 that correspond to A and B , respectively.
These two vectors are commonly very distinct and applying negation ( c ¬ ) on one of them almost exactly produces the other one.
Moreover, this remains true even if we apply c ¬ repeatedly, see Figure 4.
If we now apply c ∧ on v → 1 , then we not so surprisingly obtain two vectors very similar to each other and also similar to v → 1 .
More interesting is to apply c ∧ on v → 2 , because we obtain two vectors that are similar, but not as similar as in the previous case and commonly even less similar to v → 2 .
This suggests that something more involved than simple splitting of truth values according to possible choices takes place in the model.
Unfortunately, it is very unclear what happens deeper in the model and how recursive neural networks combine the vectors in leaves; moreover, RNN-Var and RNN-All consume their inputs in random order and this slightly inﬂuences the results.
However, it seems that our model is quite ro-
−
Iterations    −
Iterations bust to changes in the order of arguments in commutative connectives ( ∧ and ∨ ) and to other simple transformations of subformulae—replacing A → B by ¬ B → ¬ A , A ∧ B by ¬ ( ¬ A ∨ ¬ B ) etc.
An explanation of very good performance could be that our model just exploits the given dataset in some unforeseen way. In fact, we want to learn regularities in the dataset. Although this is possible, we believe that this does not explain the performance of our model completely. We trained our model on B OOL 8 and B OOL 10 datasets from Allamanis et al.
(2017) adapted 9 to our problem and tested it on unseen equivalence classes with the success rate 98.3% and 80.5%, respectively. These numbers are not directly comparable to the results presented in the paper, however, they suggest that our model is able to perform reasonably even on other datasets. Similarly, if we use the dataset from Evans et al. (2018) to test satisﬁability 10 , then we obtain results similar to the original dataset.
P OSSIBLE VARIANTS
We aimed for a simple model and hence a plethora of modiﬁcations is possible; they can both improve the quality of produced models and their generality.
Here we will discuss at least some of them.
Our model uses a feedforward neural network for representing a formula and only then two recurrent networks are used to process the results of the feedforward part.
Clearly, more complicated versions can be produced that provide a better interplay between these two layers and/or the feedforward part can become more complicated, e.g., to allow a communication between different subformulae.
For example, it is possible to propagate information also back in the bottom-up direction through the tree part of our model, or use an attention mechanism.
It should be also noted that although we use our model for deciding whether a formula is a tautology, we can try to enforce other properties by a similar process, e.g., we can test whether a formula is satisﬁable, i.e., is true under some assignment of truth-values.
Also learning more related properties, more vectors like w , with all the other components shared could be an interesting problem, and their interplay could even improve the performance on individual tasks.
Clearly, our presentation of the model suggests that it heavily relies on properties of classical (Boolean) propositional logic.
Nevertheless, it can be used directly also in a non-classical (propositional) setting.
Note that the semantics of a given logic is completely learned from examples and no a priory knowledge is provided, however, it is of course possible that our model is unable to reasonably capture the semantics of a given logic and some modiﬁcations, e.g., those mentioned above, are necessary.
The question whether a more involved model based on our model can be successfully used also for more complex formulae (ﬁrst-order or even higher-order) is a bit unclear, a clear goal for a future research.
R ELATED WORK
A thorough recent comparison of related methods is in Evans et al.
and therefore this section is only very brief.
In Wang et al.
(2017) authors also develop a model which is invariant to atoms (variables) renaming.
However, a formula graph obtained from a parse tree is there translated into a vector using the embeddings of nodes given by their neighborhoods.
Moreover, the problem they study is different (ﬁrst-order and higher-order logics).
In Zaremba et al.
(2014), a pioneering paper on using recursive neural networks Socher et al.
(2012) for mathematical expressions, they also do not deal with variables, because they allow at most one to occur in them.
In Allamanis et al.
(2017) a bottom-up approach is presented, however, it also contains a restricted form of backward communication that proved to be useful.
The problem studied there is learning vector representations of formulae and based on their similarity test their properties.
In our case, we test the properties directly.
An approach based solely on recurrent neural networks has been used in natural language processing where textual entailment is an important topic.
For LSTM models with an attention mechanism see Wang & Jiang (2016); Rockt ¨ aschel et al.
PossibleWorldNet developed in Evans et al.
(2018) addresses the same problem as our model.
It exploits a novel idea of learning various useful assignments and test them latter on.
However, the results suggest that the method performs similarly to random assignments (a very powerful technique on its own).
It could be because the standard bottom-up approach is used.
C ONCLUSION
We have presented a novel top-down approach to represent formulae by neural networks and showed some preliminary experiments.
They suggest that our approach is competitive with other known approaches and beats them on some benchmarks.
More importantly, it seems that the presented model can deal better with the increasing size of formulae than other approaches.
The model deals only with the structure of formulae and ignores completely for example names of individual atoms, only whether they are the same or distinct matters.
A CKNOWLEDGMENTS
This work was supported by the European Regional Development Fund under the project
AI&Reasoning (reg.
no.
CZ.02.1.01/0.0/0.0/15 003/0000466)