Neural Logic Machines

1 INTRODUCTION . Deep learning has achieved great success in various applications such as speech recognition ( Hinton et al. , 2012 ) , image classification ( Krizhevsky et al. , 2012 ; He et al. , 2016 ) , machine translation ( Sutskever et al. , 2014 ; Bahdanau et al. , 2015 ; Wu et al. , 2016 ; Vaswani et al. , 2017 ) , and game playing ( Mnih et al. , 2015 ; Silver et al. , 2017 ) . Starting from Fodor & Pylyshyn ( 1988 ) , however , there has been a debate over the problem of systematicity ( such as understanding recursive systems ) in connectionist models ( Fodor & McLaughlin , 1990 ; Hadley , 1994 ; Jansen & Watter , 2012 ) . Logic systems can naturally process symbolic rules in language understanding and reasoning . Inductive logic programming ( ILP ) ( Muggleton , 1991 ; 1996 ; Friedman et al. , 1999 ) has been developed for learning logic rules from examples . Roughly speaking , given a collection of positive and negative examples , ILP systems learn a set of rules ( with uncertainty ) that entails all of the positive examples but none of the negative examples . Combining both symbols and probabilities , many problems arose from high-level cognitive abilities , such as systematicity , can be naturally resolved . However , due to an exponentially large searching space of the compositional rules , it is difficult for ILP to scale beyond small-sized rule sets ( Dantsin et al. , 2001 ; Lin et al. , 2014 ; Evans & Grefenstette , 2018 ) . To make the discussion concrete , let us consider the classic blocks world problem ( Nilsson , 1982 ; Gupta & Nau , 1992 ) . As shown in Figure 1 , we are given a set of blocks on the ground . We can move a block x and place it on the top of another block y or the ground , as long as x is moveable and y is placeable . We call this operation Move ( x , y ) . A block is said to be moveable or placeable if there are no other blocks on it . The ground is always placeable , implying that we can place all blocks on the ground . Given an initial configuration of blocks world , our goal is to transform it into a target configuration by taking a sequence of Move operations . Although the blocks world problem may appear simple at first glance , four major challenges exist in building a learning system to automatically accomplish this task : 1 . The learning system should recover a set of lifted rules ( i.e. , rules that apply to objects uniformly instead of being tied with specific ones ) and generalize to blocks worlds which contain more blocks than those encountered during training . To get an intuition on this , we refer the readers who are not familiar with the blocks world domain to the task of learning to sort arrays ( e.g. , ∗indicates equal contribution . This work was done when the first two authors were interns at Google . 1Project page : https : //sites.google.com/view/neural-logic-machines . Vinyals et al. , 2015 ) , where recurrent neural networks fail to generalize to arrays which are even just slightly longer than those for training . 2 . The learning system should deal with high-order relational data and quantifiers , which goes beyond the scope of typical graph-structured neural networks ( Kipf & Welling , 2017 ) . For example , to apply the transitivity rule of a relation r , i.e . r ( a , c ) ← ∃b r ( a , b ) ∧ r ( b , c ) , we need to jointly inspect three objects ( a , b , c ) . 3 . The learning system should scale up w.r.t . the complexity of the rules.2 Existing logic-driven approaches such as traditional ILP methods suffer an exponential computational complexity w.r.t . the number of logic rules to be learned ( Dantsin et al. , 2001 ; Lin et al. , 2014 ; Evans & Grefenstette , 2018 ) . 4 . The learning system should recover rules based on a minimal set of learning priors . In contrast , traditional ILP methods usually require hand-coded and task-specific rule templates to restrict the size of searching spaces ( Evans & Grefenstette , 2018 ) . In this paper , we propose Neural Logic Machines ( NLMs ) to address the aforementioned challenges . In a nutshell , NLMs offer a neural-symbolic architecture which realizes Horn clauses ( Horn , 1951 ) in first-order logic ( FOL ) . The key intuition behind NLMs is that logic operations such as logical ANDs and ORs can be efficiently approximated by neural networks , and the wiring among neural modules can realize the logic quantifiers . The rest of the paper is organized as follows . We first revisit some useful definitions in symbolic logic systems and define our neural implementation of a rule induction system in Section 2 . As a supplementary , we refer interested readers to Appendix A for implementation details . In Section 3 we evaluate the effectiveness of NLM on a broad set of tasks ranging from relational reasoning to decision making . We discuss related works in Section 4 , and conclude the paper in Section 5 . 2 NEURAL LOGIC MACHINES ( NLM ) . The NLM is a neural realization of logic machines ( under the Closed-World Assumption3 ) . Given a set of base predicates , grounded on a set of objects ( the premises ) , NLMs sequentially apply first-order rules to draw conclusions , such as a property about an object . For example , in the blocks world , based on premises IsGround ( u ) and Clear ( u ) of object u , NLMs can infer whether u is moveable . Internally , NLMs use tensors to represent logic predicates . This is done by grounding the predicate as True or False over a fixed set of objects . Based on the tensor representation , rules are implemented as neural operators that can be applied over the premise tensors and generate conclusion tensors . Such neural operators are probabilistic , lifted , and able to handle relational data with various orders ( i.e. , operating on predicates with different arities ) . 2.1 LOGIC PREDICATES AS TENSORS . We adopt a probabilistic tensor representation for logic predicates . Suppose we have a set of objects U = { u1 , u2 , . . . , um } . A predicate p ( x1 , x2 , . . . , xr ) , of arity r , can be grounded on the object set U ( informally , we call it U-grounding ) , resulting in a tensor pU of shape [ mr ] , [ m , m− 1 , m− 2 , . . . , m− r+ 1 ] , where the value of each entry pU ( ui1 , ui2 , . . . , uir ) of the tensor represents whether p is True under the grounding that x1 = ui1 , x2 = ui2 , · · · , xr = uir . Here , we restrict that the grounded objects of all xi ’ s are mutually exclusive , i.e. , ij 6= ik for all pairs of 2For a concrete example in the blocks world domain , please refer to Appendix E. 3https : //en.wikipedia.org/wiki/Closed-world_assumption indices j and k. This restriction does not limit the generality of the representation , as the “ missing ” entries can be represented by the U-grounding of other predicates with a smaller arity . For example , for a binary predicate p , the grounded values of the pU ( x , x ) can be represented by the U -grounding of a unary predicate p′ ( x ) , p ( x , x ) . We extend this representation to a collection of predicates of the same arity . Let C ( r ) be the number of predicates of arity r. We stack the U-grounding tensors of all predicates as a tensor of shape [ mr , C ( r ) ] , [ m , m− 1 , m− 2 , . . . , m− r + 1 , C ( r ) ] , where the last dimension corresponds to the predicates . Intuitively , a group of C ( 1 ) unary predicates grounded on m objects can be represented by a tensor of shape [ m , C ( 1 ) ] , describing a group of “ properties of objects ” , while a [ m , m− 1 , C ( 2 ) ] - shaped tensor for C ( 2 ) binary predicates describes a group of “ pairwise relations between objects ” . In practice , we set a maximum arity B for the predicates of interest , called the breadth of the NLM . In addition , NLMs take a probabilistic view of predicates . Each entry in U-grounding tensors takes value from [ 0 , 1 ] , which can be interpreted as the probability being True . All premises , conclusions , and intermediate results in NLMs are represented by such probabilistic tensors . As a side note , we impose the restriction that all arguments in the predicates can only be variables or objects ( i.e. , constants ) but not function symbols , which follows the setting of Datalog ( Maier & Warren , 1988 ) . 2.2 LOGIC RULES AS NEURAL OPERATORS . Our goal is to build a neural architecture to learn rules that are both lifted and able to handle relational data with multiple arities . We present different modules of our neural operators by making analogies to a set of essential meta-rules in symbolic logic systems . Specifically , we discuss our neural implementation of ( 1 ) boolean logic rules , as lifted rules containing boolean operations ( AND , OR , NOT ) over a set of predicates ; and ( 2 ) quantifications , which bridge predicates with different arities by logic quantifiers ( ∀ and ∃ ) . Next , we combine these neural units to compose NLMs . Figure 2 illustrates the overall multi-layer , multi-group architecture of an NLM . An NLM has layers of depthD ( horizontally ) , and each layer has B + 1 computation units ( vertically ) . These units operate on the tensor representations of predicates whose arities range from [ 0 , B ] , respectively . NLMs take input tensors of predicates ( premises ) , perform layer-by-layer computations , and output tensors as conclusions . As the number of layers increases , higher levels of abstraction can be formed . For example , the output of the first layer may represent Clear ( x ) , while a deeper layer may output more complicated predicate like Moveable ( x ) . Thus , forward propagation in NLMs can be interpreted as a sequence of rule applications . We further show that NLMs can efficiently realize a partial set of Horn clauses . We start from the neural boolean logic rules and the neural quantifiers . Boolean logic . We use the following symbolic meta-rule for boolean logic : p̂ ( x1 , x2 , · · · , xr ) ← expression ( x1 , x2 , · · · , xr ) , ( 1 ) where expression can be any boolean expressions consisting of predicates over all variables ( x1 , . . . , xr ) and p̂ ( · ) is the conclusive predicate . For example , the rule Moveable ( x ) ← ¬IsGround ( x ) ∧ Clear ( x ) can be instantiated from this meta-rule . Denote P = { p1 , . . . , pk } as the set of |P| predicates appeared in expression . By definition , all pi ’ s have the same arity r and can be stacked as a tensor of shape [ mr , |P| ] . In Eq . 1 , for a specific grounding of the conclusive predicate p̂ ( x1 · · ·xr ) , it is conditioned r ! × |R| grounding values with the same subset of objects , of arbitrary permutation as the arguments to all input predicates P . For example , consider a specific ternary predicate p̂ ( x1 , x2 , x3 ) . For three different objects a , b , c ∈ U , the grounding p̂ ( a , b , c ) is conditioned on pj ( a , b , c ) , pj ( a , c , b ) , pj ( b , a , c ) , pj ( b , c , a ) , pj ( c , a , b ) , pj ( c , b , a ) ( all permutations of the parameters ) for all j ( all input predicates ) . Our neural implementation of boolean logic rules is a lifted neural module that uniformly applies to any grounding entries ( x1 · · ·xr ) in the output tensor p̂U . It has a Permute ( · ) operation transforming the tensor representation of P , followed by a multi-layer perceptron ( MLP ) . Given the tensor representation of P , for each pUi ( x1 , x2 , . . . , xr ) , the Permute ( · ) operation creates r ! new tensors as pUi,1 , . . . , p U i , r ! by permuting all axes that index objects , with all possible permutations . We stack all to form a [ mr , r ! × |P| ] -shaped tensor . An MLP uniformly applies to all mr object indices : p̂ ( ui1 , · · · , uir ) = σ ( MLP ( p1,1 ( ui1 , . . . , uir ) , · · · , pk , r ! ( ui1 , . . . , uir ) ) ; θ ) , ( 2 ) where σ is the sigmoid nonlinearity , θ is the trainable network parameters . For all sets of mutually exclusive indexes i1 , . . . , ir ∈ { 1 , 2 , . . . , m } , the same MLP is applied . Thus , the size of θ is independent of the number of objects m. This property is analogous to the implicit unification property of Horn clauses : the rule p̂ ( x ) ← p1 ( x ) ∧p2 ( x ) implicitly means , ∀x p̂ ( x ) ← p1 ( x ) ∧p2 ( x ) . Quantification . We introduce two types of meta-rules for quantification , namely expansion and reduction . Let p be a predicate , and we have ( Expansion ) ∀xr+1 q ( x1 , x2 , · · · , xr , xr+1 ) ← p ( x1 , x2 , · · · , xr ) , ( 3 ) where xr+1 /∈ { xi } ri=1 . The expansion operation constructs a new predicate q from p , by introducing a new variable xr+1 . For example , consider the following rule ValidMove ( x , y ) ← Moveable ( x ) ∧ Placeable ( y ) . This rule does not fit the meta-rule in Eq . 1 as some predicates on the RHS only take a subset of variables as inputs . However , it can be described by using the expansion and the boolean logic meta-rules jointly . 1 . ∀z MoveableX ( x , z ) ← Moveable ( x ) ; ( from Eq . 3 ) 2 . ∀z PlaceableY ( y , z ) ← Placeable ( y ) ; ( from Eq . 3 ) 3 . ValidMove ( x , y ) ← MoveableX ( x , y ) ∧ PlaceableY ( y , x ) . ( from Eq . 1 ) The expansion meta-rule ( Eq . 3 ) for a set of C r-ary predicates , represented by a [ mr , C ] -shaped tensor , introduces a new and distinct variable xr+1 . Our neural implementation Expand ( · ) repeats each predicate ( their tensor representation ) for ( m− r ) times , and stacks in a new dimension . Thus the output shape is [ mr+1 , C ] . The other meta-rule is for reduction : ( Reduction ) q ( x1 , x2 , · · · , xr ) ← ∀xr+1 p ( x1 , x2 , · · · , xr , xr+1 ) , ( 4 ) where the ∀ quantifier can also be replaced by ∃ . The reduction operation reduces a variable in a predicate via the quantifier . As an example , the rule to deduce the moveability of objects , Moveable ( x ) ← ¬IsGround ( x ) ∧ ¬ ( ∃y On ( y , x ) ) , can be expressed using meta-rules as follows : 1 . Clear ( x ) ← ∀y ¬On ( y , x ) ; ( from Eq . 4 ) 2 . Moveable ( x ) ← ¬IsGround ( x ) ∧ Clear ( x ) . ( from Eq . 1 ) The reduction meta-rule ( Eq . 4 ) for a set of C ( r + 1 ) -ary predicates , represented by a [ mr+1 , C ] shaped tensor , eliminates the variable xr+1 via quantifiers . For ∃ ( or ∀ ) , our neural implementation Reduce ( · ) takes the maximum ( or minimum ) element along the dimension of xr+1 , and stacks the two resulting tensors . Therefore , the output shape becomes [ mr , 2C ] .

Summary: This paper presents a model to combine neural network and logic programming. It proposes to use 3 primitive logic rules to model first-order predicate calculus in the neural networks. Specifically, relations with different numbers of arguments over all permutations of the groups of objects are represented as tensors with corresponding dimensions. In each layer, a MLP (shared among different permutations) is applied to transform the tensor. Multiple layers captures multiple steps of deduction. On several synthetic tasks, the proposed method is shown to outperform the memory network baseline and shows strong generalization.