L EARN TO E XPLAIN E FFICIENTLY VIA N EURAL L OGIC I NDUCTIVE L EARNING
A BSTRACT
The capability of making interpretable and self-explanatory decisions is essential for developing responsible machine learning systems.
In this work, we study the learning to explain problem in the scope of inductive logic programming (ILP).
We propose Neural Logic Inductive Learning (NLIL), an efﬁcient differentiable
ILP framework that learns ﬁrst-order logic rules that can explain the patterns in the data.
In experiments, compared with the state-of-the-art methods, we ﬁnd NLIL can search for rules that are x10 times longer while remaining x3 times faster.
We also show that NLIL can scale to large image datasets, i e. Visual Genome, with 1M entities
I NTRODUCTION
Car( ) ← Of( , ) ∧ Window( )
∧
Person( ) ← Car( ) ∧ Inside( , ) ∧
Of( , ) ∧ Wheel( )
On( , ) ∧ Clothing( ) “An object that has wheels and windows is a car” “An object that is inside the car with clothing is a person”
[Figure]
The recent years have witnessed the growing success of deep learning models in a wide range of applications.
However, these models are also criticized for the lack of interpretability in its behavior and decision making process (Lipton, 2016; Mittelstadt et al., 2019), and for being data-hungry.
The ability to explain its decision is essential for developing a responsible and robust decision system (Guidotti et al., 2019).
On the other hand, logic programming methods, in the form of ﬁrst-order logic (FOL), are capable of discovering and representing knowledge in explicit symbolic structure that can be understood and examined by human (Evans & Grefenstette, 2018).
In this paper, we investigate the learning to explain problem in the scope of inductive logic programming (ILP) which seeks to learn ﬁrst-order logic rules that explain the data.
Traditional ILP methods (Gal´arraga et al., 2015) rely on hard matching and discrete logic for rule search which is not tolerant for ambiguous and noisy data (Evans & Grefenstette, 2018).
A number of works are proposed for developing differentiable ILP models that combine the strength of neural and logicbased computation (Evans & Grefenstette, 2018; Campero et al., 2018; Rockt¨aschel & Riedel, 2017;
Payani & Fekri, 2019; Dong et al., 2019).
Methods such as ∂ ILP (Evans & Grefenstette, 2018) are referred to as forward-chaining methods.
It constructs rules using a set of pre-deﬁned templates and evaluates them by applying the rule on background data multiple times to deduce new facts that lie in the held-out set (related works available at Appendix A).
However, general ILP problem involves several steps that are NP-hard: (i) the rule search space grows exponentially in the length of the rule; (ii) assigning the logic variables to be shared by predicates grows exponentially in the number of arguments, which we refer as variable binding problem; (iii) the number of rule instantiations needed for formula evaluation grows exponentially in the size of data.
To alleviate these complexities, most works have limited the search length to within 3 and resort to template-based variable assignments, limiting the expressiveness of the learned rules (detailed discussion available at Appendix B).
Still, most of the works are limited in small scale problems with less than 10 relations and 1K entities.
On the other hand, multi-hop reasoning methods (Guu et al., 2015; Lao & Cohen, 2010; Lin et al., 2015; Gardner & Mitchell, 2015; Das et al., 2016) are proposed for the knowledge base (KB) completion task.
Methods such as NeuralLP (Yang et al., 2017) can answer the KB queries by searching for a relational path that leads from the subject to the object.
These methods can be interpreted in the
ILP domain where the learned relational path is equivalent to a chain-like ﬁrst-order rule.
Compared to the template-based counterparts, methods such as NeuralLP is highly efﬁcient in variable binding and rule evaluation.
However, they are limited in two aspects: (i) the chain-like rules represent a subset of the Horn clauses, and are limited in expressing complex rules such as those shown in Figure 1; (ii) the relational path is generated while conditioning on the speciﬁc query, meaning that the learned rule is only valid for the current query.
This makes it difﬁcult to learn rules that are globally consistent in the KB, which is an important aspect of a good explanation.
In this work, we propose Neural Logic Inductive Learning (NLIL), a differentiable ILP method that extends the multi-hop reasoning framework for general ILP problem.
NLIL is highly efﬁcient and expressive.
We propose a divide-and-conquer strategy and decompose the search space into 3 subspaces in a hierarchy, where each of them can be searched efﬁciently using attentions.
This enables us to search for x10 times longer rules while remaining x3 times faster than the state-of-theart methods.
We maintain the global consistency of rules by splitting the training into rule generation and rule evaluation phase, where the former is only conditioned on the predicate type that is shared globally.
And more importantly, we show that a scalable ILP method is widely applicable for model explanations in supervised learning scenario.
We apply NLIL on Visual Genome (Krishna et al., 2016) dataset for learning explanations for 150 object classes over 1M entities.
We demonstrate that the learned rules, while maintaining the interpretability, have comparable predictive power as densely supervised models, and generalize well with less than 1% of the data.
P RELIMINARIES
Supervised learning typically involves learning classiﬁers that map an object from its input space to a score between 0 and 1.
How can one explain the outcome of a classiﬁer?
Recent works on interpretability focus on generating heatmaps or attention that self-explains a classiﬁer (Ribeiro et al., 2016;
Chen et al., 2018; Olah et al., 2018).
We argue that a more effective and humanintelligent explanation is through the description of the connection with other classiﬁers.
For example, consider an object detector with classiﬁers Person ( X ) , Car ( X ) , Clothing ( X ) and Inside ( X, X (cid:48) ) that detects if certain region contains a person, a car, a clothing or is inside another region, respectively.
To explain why a person is present, one can leverage its connection with other attributes, such as “ X is a person if it’s inside a car and wearing clothing”, as shown in Figure 1.
This intuition draws a close connection to a longstanding problem of ﬁrst-order logic literature, i.e. Inductive Logic Programming (ILP).
2. I NDUCTIVE L OGIC P ROGRAMMING
A typical ﬁrst-order logic system consists of 3 components: entity , predicate and formula .
Entities are objects x ∈ X .
For example, for a given image, a certain region is an entity x , and the set of all possible regions is X .
Predicates are functions that map entities to 0 or 1, for example
Person : x (cid:55)→ { 0 , 1 } , x ∈ X .
Classiﬁers can be seen as soft predicates.
Predicates can take multiple arguments, e.g. Inside is a predicate with 2 inputs.
The number of arguments is referred to as the arity .
Atom is a predicate symbol applied to a logic variable, e.g. Person ( X ) and
Inside ( X, X (cid:48) ) .
A logic variable such as X can be instantiated into any object in X .
A ﬁrst-order logic (FOL) formula is a combination of atoms using logical operations {∧ , ∨ , ¬} which correspond to logic and , or and not respectively.
Given a set of predicates P = { P 1 , ..., P K } , we deﬁne the explanation of a predicate P k as a ﬁrst-order logic entailment
[Equation]
where P k ( X, X (cid:48) ) is the head of the entailment, and it will become P
k
( X ) if it is a unary predicate.
A is deﬁned as the rule body and is a general formula, e.g. conjunction normal form (CNF), that is made of atoms with predicate symbols from P and logic variables that are either head variables X ,
X (cid:48) or one of the body variables Y =
{ Y 1 , Y 2 , ... } .
By using the logic variables, the explanation becomes transferrable as it represents the “lifted” knowledge that does not depend on the speciﬁc data.
It can be easily interpreted.
For example,
[Equation]
represents the knowledge that “if an object is inside the car with clothing on it, then it’s a person”.
To evaluate a formula on the actual data, one grounds the formula by instantiating all the variables into objects.
For example, in Figure 1, Eq.(2) is applied to the speciﬁc regions of an image.
Given a relational knowledge base (KB) that consists of a set of facts {(cid:104) x
i , P i , x (cid:48) i (cid:105)} N i =1 where P i ∈ P and x i , x (cid:48) i ∈ X .
The task of learning FOL rules in the form of Eq.(1) that entail target predicate
P ∗ ∈ P is called inductive logic programming.
For simplicity, we consider unary and binary predicates for the following contents, but this deﬁnition can be extended to predicates with higher arity as well.
2. M UTLI -H OP R EASONING
The ILP problem is closely related to the multi-hop reasoning task on the knowledge graph (Guu et al., 2015; Lao & Cohen, 2010; Lin et al., 2015; Gardner & Mitchell, 2015; Das et al., 2016).
Similar to ILP, the task operates on a KB that consists of a set of predicates P .
Here the facts are stored with respect to the predicate P k which is represented as a binary matrix M k in { 0 , 1 } |X|×|X| .
This is an adjacency matrix, meaning that (cid:104) x i , P k , x j (cid:105) is in the KB if and only if the ( i, j ) entry of
M k is 1.
Given a query q = (cid:104) x , P ∗ , x (cid:48) (cid:105) .
The task is to ﬁnd a relational path x P (1) −−−→ ... P ( T ) −−−→ x (cid:48) , such that the two query entities are connected.
Formally, let v x be the one-hot encoding of object x with dimension of |X| .
Then, the ( t ) th hop of the reasoning along the path is represented as
[Equation]
where M ( t ) is the adjacency matrix of the predicate used in ( t ) th hop.
The v ( t ) is the path features vector , where the j th element v ( t ) j counts the number of unique paths from x to x j
(Guu et al., 2015).
After T steps of reasoning, the score of the query is computed as
[Equation]
For each q , the goal is to (i) ﬁnd an appropriate T and (ii) for each t ∈ [1 , 2 , ..., T ] , ﬁnd the appropriate M ( t ) to multiply, such that Eq.(3) is maximized.
These two discrete picks can be relaxed as learning the weighted sum of scores from all possible paths, and weighted sum of matrices at each step.
Let κ
[Equation]
be the soft path selection function parameterized by (i) the path attention vector s ψ =
[ s (1) ψ , ..., s ( T ) ψ ] (cid:62) that softly picks the best path with length between 1 to T that answers the query, and (ii) the operator attention vectors S ϕ
=
[ s (1) ϕ , ..., s ( T ) ϕ ] (cid:62) , where s ( t ) ϕ softly picks the M ( t ) at ( t ) th step.
Here we omit the dependence on M k for notation clarity.
These two attentions are generated with a model
[Equation]
with learnable parameters w .
For methods such as (Guu et al., 2015; Lao & Cohen, 2010), T ( x ; w ) is a random walk sampler which generates one-hot vectors that simulate the random walk on the graph starting from x .
And in NeuralLP (Yang et al., 2017), T ( x ; w ) is an RNN controller that generates a sequence of normalized attention vectors with v x as the initial input.
Therefore, the objective is deﬁned as
[Equation]
Learning the relational path in the multi-hop reasoning can be interpreted as solving an ILP problem with chain-like FOL rules (Yang et al., 2017)
[Equation]
Compared to the template-based ILP methods such as ∂ ILP, this class of methods is efﬁcient in rule exploration and evaluation.
However, (P1) generating explanations for supervised models puts a high demand on the rule expressiveness.
The chain-like rule space is limited in its expressive power because it represents a constrained subspace of the Horn clauses rule space.
For example, Eq.(2) is a Horn clause and is not chain-like.
And the ability to efﬁciently search beyond the chain-like rule space is still lacking in these methods.
On the other hand, (P2) the attention generator T ( x ; w ) is dependent on x , the subject of a speciﬁc query q , meaning that the explanation generated for target P ∗ can vary from query to query.
This makes it difﬁcult to learn FOL rules that are globally consistent in the KB.
N EURAL L OGIC I NDUCTIVE L EARNING
In this section, we show the connection between the multi-hop reasoning methods with the general logic entailment deﬁned in Eq.(1).
Then we propose a hierarchical rule space to solve (P1) , i.e. we extend the chain-like space for efﬁcient learning of more expressive rules.
3. T HE OPERATOR VIEW
In Eq.(1), variables that only appear in the body are under existential quantiﬁer.
We can turn Eq.(1) into Skolem normal form by replacing all variables under existential quantiﬁer with functions with respect to X and X (cid:48) ,
[Equation]
If the functions are known, Eq.(7) will be much easier to evaluate than Eq.(1).
Because grounding this formula only requires to instantiate the head variables, and the rest of the body variables are then determined by the deterministic functions.
Functions in Eq.(7) can be arbitrary.
But what are the functions that one can utilize?
We propose to adopt the notions in section 2.2 and treat each predicate as an operator , such that we have a subspace of the functions Φ = { ϕ 1 , ..., ϕ K } , where
[Equation]
where U and B are the sets of unary and binary predicates respectively.
The operator of the unary predicate takes no input and is parameterized with a diagonal matrix.
Intuitively, given a subject entity x , ϕ k returns the set embedding (Guu et al., 2015) that represents the object entities that, together with the subject, satisfy the predicate P k .
For example, let v x be the one-hot encoding of an object in the image, then ϕ
Inside ( v x ) returns the objects that spatially contain the input box.
For unary predicate such as Car ( X ) , its operator ϕ Car () =
M car 1 takes no input and returns the set of all objects labelled as car.
Since we only use Φ , a subspace of the functions, the existential variables that can be represented by the operator calls, denoted as ˆ Y , also form the subset ˆ Y ⊆ Y .
This is slightly constrained from Eq.(1).
For example, in Person ( X ) ← Car ( Y ) , Y can not be interpreted as the operator call from X .
However, we argue that such rules are generally trivial.
For example, it’s not likely to infer “an image contains a person” by simply checking if “there is any car in the image”.
Therefore, any FOL formula that complies with Eq.(7) can now be converted into the operator form and vice versa.
For example, Eq.(2) can be written as
[Equation]
where the variable Y 1 and Y 2 are eliminated.
Note that this conversion is not unique.
For example,
Car ( ϕ Inside ( X )) can be also written as Inside ( X, ϕ Car ()) .
The variable binding problem now becomes equivalent to the path-ﬁnding problem in section 2.2, where one searches for the appropriate chain of operator calls that can represent the variable in ˆ Y .
3. P RIMITIVE S TATEMENTS
[Figure]
type is
Succ stands for successor.
As discussed above, the Eq.(3) is equivalent to a chain-like rule.
We want to extend this notion and be able to represent more expressive rules.
To do this, we introduce the notion of primitive statement ψ .
Note that an atom is deﬁned as a predicate symbol applied to speciﬁc logic variables.
Similarly, we deﬁne a predicate symbol applied to the head variables or those in ˆ Y as a primitive statement.
For example, in Eq.(8), ψ 1 = Car ( ϕ Inside ( X )) and ψ 2 =
On ( ϕ Clothing () , X ) are two primitive statements.
Similar to an atom, each primitive statement is a mapping from the input space to a scalar conﬁdence score, i.e. ψ : R |X| ×
R |X| (cid:55)→ s ∈ [0 , 1] .
Formally, for a unary primitive statement
P k ( ϕ ( T (cid:48) ) · ... · ϕ (1) ( x (cid:48) )) and a binary one P k ( ϕ ( T ) · ... · ϕ (1) ( x ) , ϕ ( T (cid:48) ) · ... · ϕ (1) ( x (cid:48) )) , their mappings are deﬁned as
[Equation]
if k ∈ U ,
[Equation]
if k ∈ B , (9) where σ ( · ) is the sigmoid function.
Note that we give unary ψ a dummy input x for notation convenience.
For example, in
Ear ( X ) ← Eye ( Y 1 ) ∧ Of ( Y 1 , Y 2 ) ∧ Of ( X, Y 2 ) , the body is a single statement ψ =
Of ( ϕ Eye () , ϕ Of ( X )) .
Its value is computed as ψ Of ( ϕ Eye () , ϕ
Of ( v x (cid:48) ))
=
σ (( M Of M Eye 1 ) (cid:62) ( M Of v x (cid:48) )) .
Compared to Eq.(3), Eq.(9) replaces the target v x (cid:48) into another relational path.
This makes it possible to represent “correlations” between two variables, and the path that starts from the unary operator, e.g. ϕ Eye () .
To see this, one can view a FOL rule as a factor graph with logic variables as the nodes and predicates as the potentials (Cohen et al., 2017).
And running the operator call is essentially conducting the belief propagation over the graph in a ﬁxed direction.
As shown in Figure 2, primitive statement is capable of representing the tree-like factor graphs, which signiﬁcantly improves the expressive power of the learned rules.
Similarly, Eq.(9) can be relaxed into weighted sums.
In Eq.(6), all relational paths are summed with a single path attention vector s ψ .
We extend this notion by assigning separate vectors for each argument of the statement ψ .
Let S ψ , S (cid:48) ψ ∈ R K × T be the path attention matrices for the ﬁrst and second argument of all statements in Ψ , i.e. s ψ,k and s (cid:48)
ψ,k are the path attention vectors of the ﬁrst and second argument of the k th statement.
Then we have
[Equation]
3. L OGIC COMBINATION SPACE
By introducing the primitive statements, we are now one step away from representing the running example rule Eq.(8), which is the logic conjunction of two statements ψ 1 and ψ 2 .
Speciﬁcally,
XE n t 𝑴𝑴𝑴 𝑲
I t e r a t e
W / s u m 𝑴 (𝟏) 𝑴 (𝟐) 𝑴 (𝑻)
M a t m u l M a t m u l …
M a t m u l
I t e r a t e
W / s u m 𝝍𝝍𝝍 𝑲
Eq.(10) ෠ ℱ 𝟎 Neg
Concat
I t e r a t e
W / s u m * ℱℱ 𝑳−
W / s u
m ℱ 𝑳 𝒗 𝒙 𝒗 𝒙′ 𝒚 S a m p l e … …
I t e r a t e …
I t e r a t e 𝑺 𝝋 𝑺 𝝍 𝑺 𝝍′
𝑺 𝒇 𝑺 𝒇′ 𝒔 𝒐 𝒔 𝝋 (𝒕) 𝒔 𝝍,𝒌 𝒔 𝝍,𝒌′ 𝒔 𝒇,𝒍𝒄 𝒔 𝒇,𝒍𝒄′ … 𝒍= 𝒍=𝑳− we want to further extend the rule search space by exploring the logic combinations of primitive statements, via {∧ , ∨ , ¬} , as shown in Figure 2.
To do this, we utilize the soft logic not and soft logic and operations
¬ p = 1 − p, p ∧ q = p ∗ q, where p, q ∈ [0 , 1] .
Here we do not include the logic ∨ operation because it can be implicitly represented as p ∨ q = ¬ ( ¬ p ∧¬ q ) .
Let Ψ = { ψ k ( x , x (cid:48) )
} Kk =1 be the set of primitive statements with all possible predicate symbols.
We deﬁne the formula set at l th level as
[Equation]
where each element in the formula set { f : f ∈ F l } is called a formula such that f : R |X| ×
R |X| (cid:55)→ s ∈ [0 , 1] .
Intuitively, we deﬁne the logic combination space in a similar way as that in pathﬁnding: the initial formula set contains only primitive statements Ψ , because they are formulas by themselves.
For the l − 1 th formula set F l − 1 , we concatenate it with its logic negation, which yields ˆ
F l − 1 .
Then each formula in the next level is the logic and of two formulas from ˆ F l − 1 .
Enumerating all possible combinations at each level is expensive, so we set up a memory limitation C to indicate the maximum number of combinations each level can keep track of 1 .
In other words, each level F l is to search for C logic and combinations on formulas from the previous level ˆ F l − 1 , such that the c th formula at the l th level f
lc is
[Equation] [Equation]
As an example, for Ψ = { ψ 1 , ψ 2 } and C = 2 , one possible level sequence is F 0 = { ψ 1 , ψ 2 } ,
F 1 = { ψ 1 ∗ ψ 2 , (1 − ψ 2 ) ∗ ψ 1 } , F 2 = { ( ψ 1 ∗ ψ 2 ) ∗ ((1 − ψ 2 ) ∗ ψ 1 ) , ... } and etc.
To collect the rules from all levels, the ﬁnal level L is the union of previous sets, i.e. F L = F 0 ∪ ... ∪ F L − 1 .
Note that Eq.(11) does not explicitly forbid trivial rules such as ψ 1 ∗ (1 − ψ 1 ) that is always true regardless of the input.
This is alleviated by introducing nonexistent queries during the training (detailed discussion at section 5).
Again, the rule selection can be parameterized into the weighted-sum form with respect to the attentions.
We deﬁne the formula attention tensors as S f , S (cid:48) f ∈ R L − 1 × C × 2 C , such that f lc is the product of two summations over the previous outputs weighted by attention vectors s f,lc and s (cid:48)
f,lc respectively 2 .
Formally, we have
[Equation]
[Equation]
where f l − 1 ( x , x (cid:48) )
∈
R 2 C is the stacked outputs of all formulas f ∈ ˆ F l − 1 with arguments (cid:104) x , x (cid:48) (cid:105) .
Finally, we want to select the best explanation and compute the score for each query.
Let s o be the
Transformer
Concat& feedforward
X LTransformer +
X T
Transformer +
Concat&feedforward e x e x' … e φ ෡𝑸 𝝋 ෩𝑽 𝝍 ෡𝑽 𝒇,𝒍−
Transformer ෡𝑽 𝝋(𝒕) 𝒒 𝝋(𝒕)
𝒔 𝝋 (𝒕) 𝒗 𝝋(𝒕)
𝒆 𝝍 𝒆 𝝍′
X
Iterate
Concat 𝒆 + 𝒆 ¬
Iterate +
X𝑸 𝝍 𝑽 𝝋 𝑺 𝝍 … 𝑸 𝒇,𝒍
𝑺 𝒇,𝒍 ෩𝑽 𝒇.𝒍 ෡𝑯 ෡𝑯 𝒒 𝝋(𝒕)
෡𝑺 𝝋(𝒕)
෡𝑽 𝝋 (𝒕−𝟏)
෡𝑽 𝝋 (𝒕) 𝑸 𝒇,𝒍
Concat
Transformer 𝒒 𝒐 𝑽 𝒐 𝒗 𝒐 𝒔 𝒐 𝒒 𝒐
𝑺 𝝋 𝑺 𝝍
𝑺 𝝍′
𝑺 𝒇 𝑺 𝒇 ′ 𝒔 𝒐
Concat attention vector over F L , so the output score is deﬁned as
[Equation]
An overview of the relaxed hierarchical rule space is illustrated in Figure 3.
H IERARCHICAL T RANSFORMER N ETWORKS FOR R ULE G ENERATION
We have deﬁned a hierarchical rule space as shown in Figure 3, where the discrete selections on the operators, statements and logic combinations are all relaxed into the weight sums with respect to a series of attention parameters S ϕ , S ψ , S (cid:48) ψ , S f , S (cid:48)
f and s o .
In this section, we solve (P2) , i.e. we propose a differentiable model that generates these attentions without conditioning on the speciﬁc query.
The goal of NLIL is to generate data-independent FOL rules.
In other words, for each target predicate P ∗ , its rule set F L and the ﬁnal output rule should remain unchanged for all the queries q = (cid:104) x , P ∗ , x (cid:48) (cid:105) (which is different from that in Eq.(5)).
To do this, we deﬁne the learnable embeddings of all predicates as H =
[ h 1 , .., h K ] (cid:62) ∈ R K × d , and the embeddings for the “dummy” arguments X and X (cid:48) as e X , e X (cid:48)
∈ R d .
We deﬁne the attention generation model as
[Equation]
where h ∗ is the embedding of P ∗ , such that attentions only vary with respect to P ∗ .
As shown in Figure 4, we propose a stack of three Transformer (Vaswani et al., 2017) networks for attention generator T .
Each module is designed to mimic the actual evaluation that could happen during the operator call, primitive statement evaluation and formula computation respectively with neural networks and “dummy” embeddings.
And the attention matrices generated during this simulated evaluation process are kept for evaluating Eq.(14).
A MultiHeadAttn is a standard Transformer module such that MultiHeadAttn : Q q × d × V v × d (cid:55)→ O q × d × S q × v , where d is the latent dimension and q, v are the query and value dimensions respectively.
It takes the query Q and input value V (which will be internally transformed into keys and values ), and returns the output value O and attention matrix S .
Intuitively, S encodes the “compatibility” between query and the value, and
O represents the “outcome” of a query given its compatibility with the input.
Operator search : For target predicate P ∗ , we alter the embedding matrix H with ˆh
[Equation]
FeedForward(Concat( h
[Equation]
, h
[Equation]
[Equation]
such that the rule generation is predicate-speciﬁc.
Let q ( t ) ϕ be the learnable t th step operator query embedding.
The operator transformer module is parameterized as
[Equation]
Here, ˆV (0) ϕ is the dummy input embedding representing the starting points of the paths.
e ϕ is a learnable operator encoding such that ˆQ ϕ represents the embeddings of all operators Φ .
Therefore,
[Table] [Table]
we consider that ˆ V ( t ) ϕ encodes the outputs of the operator calls of K predicates.
And we aggregate the outputs with another MultiHeadAttn with respect to a single query q ( t ) ϕ , which in turn yields the operator path attention vector s ( t ) ϕ
and aggregated output v ( t ) ϕ .
Primitive statement search : Let V ϕ
= [ v (1) ϕ , ..., v ( T ) ϕ ] (cid:62) be the output embedding of T paths.
The path attention is generated as
[Equation]
Here, e ψ and e (cid:48) ψ are the ﬁrst and second argument encodings, such that Q ψ and Q (cid:48)
ψ encode the arguments of each statement in Ψ .
The compatibility between paths and the arguments are computed with two MultiHeadAttn s. Finally, a FeedForward is used to aggregate the selections.
Its output
V ψ ∈ R K × d represents the results of all statement evaluations in Ψ .
Formula search : Let Q f,l , Q (cid:48)
f,l ∈ R C ×
d be the learnable queries of the ﬁrst and second argument of formulas at l th level, and let V f, 0 = V ψ .
The formula attention is generated as
[Equation]
Here, e + , e ¬ are the learnable embeddings, such that ˆV f,l − 1 represents the positive and negative states of the formulas at l − 1 th level.
Similar to the statement search, the compatibility between the logic and arguments and the previous formulas are computed with two MultiHeadAttn s. And the embeddings of formulas at l th level V f,l are aggregated by a FeedForward .
Finally, let q o be the learnable ﬁnal output query and let V o =
[ V f, 0 , ..., V f,L − 1 ] .
The output attention is computed as v o , s o =
MultiHeadAttn( q o , V o ) .
S TOCHASTIC T RAINING A ND R ULE V ISUALIZATIONS
The training of NLIL consists of two phases: rule generation and rule evaluation.
During generation, we run Eq.(15) to obtain the attentions S ϕ , S ψ , S (cid:48) ψ , S f , S (cid:48)
f and s o for all P ∗ s. For the evaluation phase, we sample a mini-batch of queries {(cid:104) x , P ∗ , x (cid:48) , y (cid:105) i } bi =1 , and evaluate the formulas using Eq.(14).
Here, y is the query label indicating if the triplet exists in the KB or not.
We sample nonexistent queries to prevent the model from learning trivial rules that always output 1.
In the experiments, these negative queries are sampled uniformly from the target query matrix M ∗ where the entry is 0.
Then the objective becomes
[Equation]
Since the attentions are generated from Eq.(15) differentiably, the loss is back-propagated through the attentions into the Transformer networks for end-to-end training.
5. E XTRACTING EXPLICIT RULES
During training, the results from operator calls and logic combinations are averaged via attentions.
For validation and testing, we evaluate the model with the explicit FOL rules extracted from the
[Figure] [Figure]
- NeuralLP 0. NLIL <
[Figure]
< 0.
(a)
Length
T i m e
P e r E po
c h s /
M i n s     4 6
NeuralLP
NLIL (b)
Data Portion / %
R @0.07 0.
MLP+RCNN
Freq
NLIL (
[Figure]
attentions.
To do this, one can view an attention vector as a categorical distribution.
For example, s ( t ) ϕ is such a distribution over random variables k ∈ [1 , K ] .
And the weighted sum is the expectation over M k .
Therefore, one can extract the explicit rules by sampling from the distributions (Kool et al., 2018; Yang et al., 2017).
However, since we are interested in the best rules and the attentions usually become highly concentrated on one entity after convergence.
We replace the sampling with the arg max , where we get the one-hot encoding of the entity with the largest probability mass.
E XPERIMENTS
We ﬁrst evaluate NLIL on classical ILP benchmarks and compare it with 4 state-of-the-art KB completion methods in terms of their accuracy and efﬁciency.
Then we show NLIL is capable of learning FOL explanations for object classiﬁers on a large image dataset when scene-graphs are present.
Though each scene-graph corresponds to a small KB, the total amount of the graphs makes it infeasible for all classical ILP methods.
We show that NLIL can overcome it via efﬁcient stochastic training.
Our implementation is available at https://github.com/gblackout/NLIL.
6. C LASSICAL ILP BENCHMARKS
We evaluate NLIL together with two state-of-the-art differentiable ILP methods, i.e.
NeuralLP (Yang et al., 2017) and ∂ ILP (Evans & Grefenstette, 2018), and two structure embedding methods, TransE (Bordes et al., 2013) and RotatE (Sun et al., 2019).
Detailed experiments setup is available at Appendix C.
Benchmark datasets : (i) Even-and-Successor (ES) benchmark is introduced in (Evans & Grefenstette, 2018), which involves two unary predicates Even ( X ) , Zero ( X ) and one binary predicate
Succ ( X, Y ) .
The goal is to learn FOL rules over a set of integers.
The benchmark is evaluated with 10, 50 and 1K consecutive integers starting at 0; (ii) FB15K-237 is a subset of the Freebase knowledge base (Toutanova & Chen, 2015) containing general knowledge facts;
(iii) WN18 (Bordes et al., 2013) is the subset of WordNet containing relations between words.
Statistics of datasets are provided in Table 2.
Knowledge base completion : All models are evaluated on the KB completion task.
The benchmark datasets are split into train/valid/test sets.
The model is tasked to predict the probability of a fact triplet (query) being present in the KB.
We use Mean Reciprocal Ranks (MRR) and Hits@10 for evaluation metrics (see Appendix C for details).
Results on Even-and-Successor benchmark are shown in Table 5a.
Since the benchmark is noisefree, we only show the wall clock time for completely solving the task.
As we have previously mentioned, the forward-chaining method, i.e. ∂ ILP scales exponentially in the number of facts and quickly becomes infeasible for 1K entities.
Thus, we skip its evaluation for other benchmarks.
Results on FB15K-
and WN18 are shown in Table.
Compared to NeuralLP, NLIL yields slightly higher scores.
This is due to the benchmarks favor symmetric/asymmetric relations or compositions of a few relations (Sun et al., 2019), such that most valuable rules will already lie within the chain-like search space of NeuralLP.
Thus the improvements gained from a larger search space with NLIL are limited.
On the other hand, with the Transformer block and smaller model created for each target predicate, NLIL can achieve a similar score at least 3 times faster.
Compared to the structure embedding methods, NLIL is signiﬁcantly outperformed by the current state-of-the-art, i.e. RotatE, on FB15K.
This is expected because NLIL searches over the symbolic space that is highly constrained.
However, the learned rules are still reasonably predictive, as its performance is comparable to that of TransE.
Scalability for long rules : we demonstrate that NLIL can explore longer rules efﬁciently.
We compare the wall clock time of NeuralLP and NLIL for performing one epoch of training against different maximum rule lengths.
As shown in Figure 5b, NeuralLP searches over a chain-like rule space thus scales linearly with the length, while NLIL searches over a hierarchical space thus grows in log scale.
The search time for length 32 in NLIL is similar to that for length 3 in NerualLP.
6. ILP ON V ISUAL G ENOME DATASET
The ability to perform ILP efﬁciently extends the applications of NLIL to beyond canonical KB completion.
For example in visual object detection and relation learning, supervised models can learn to generate a scene-graph (As shown in Figure 1) for each image.
It consists of nodes each labeled as an object class.
And each pair of objects are connected with one type of relation.
The scene-graph can then be represented as a relational KB where one can perform ILP.
Learning the
FOL rules on such an output of a supervised model is beneﬁcial.
As it provides an alternative way of interpreting model behaviors in terms of its relations with other classiﬁers that are consistent across the dataset.
To show this, we conduct experiments on Visual Genome dataset (Krishna et al., 2016).
The original dataset is highly noisy (Zellers et al., 2018), so we use a pre-processed version available as the GQA dataset (Hudson & Manning, 2019).
The scene-graphs are converted to a collection KBs, and its statistics are shown in Table 2.
We ﬁlter out the predicates with less than 1500 occurrences.
The processed KBs contain 213 predicates.
Then we perform ILP on learning the explanations for the top 150 objects in the dataset.
[Table]
Quantitatively, we evaluate the learned rules on predicting the object class labels on a held-out set in terms of their R@1 and R@5.
As none of the ILP works scale to this benchmark, we compare
NLIL with two supervised baselines: (i) MLP-RCNN : a MLP classiﬁer with RCNN features of the object (available in GQA dataset) as input; and (ii) Freq : a frequency-based baseline that predicts object label by looking at the mostly occurred object class in the relation that contains the target.
This method is nontrivial.
As noted in (Zellers et al., 2018), a large number of triples in Visual Genome are highly predictive by knowing only the relation type and either one of the objects or subjects.
Explaining objects with rules : Results are shown in Table 3.
We see that the supervised method achieves the best scores, as it relies on highly informative visual features.
On the other hand, NLIL achieves a comparable score on R@1 solely relying on KBs with sparse binary labels.
We note that
NLIL outperforms Freq signiﬁcantly.
This means the FOL rules learned by NLIL are beyond the superﬁcial correlations exhibited by the dataset.
We verify this ﬁnding by showing the rules for top objects in Table 4.
Induction for few-shot learning : Logic inductive learning is data-efﬁcient and the learned rules are highly transferrable.
To see this, we vary the size of the training set and compare the R@1 scores for 3 methods.
As shown in Figure 5c, the NLIL maintains a similar R@1 score with less than 1% of the training set.
C ONCLUSION
In this work, we propose Neural Logic Inductive Learning, a differentiable
ILP framework that learns explanatory rules from data.
We demonstrate that NLIL can scale to very large datasets while being able to search over complex and expressive rules.
More importantly, we show that a scalable
ILP method is effective in explaining decisions of supervised models, which provides an alternative perspective for inspecting the decision process of machine learning systems
A CKNOWLEDGMENTS
This project is partially supported by DARPA ASED program under FA8650-18-2-7882.
We thank
Ramesh Arvind 3 and Hoon Na 4 for implementing the MLP baseline.
A R ELATED W ORK
Inductive Logic Programming (ILP) is the task that seeks to summarize the underlying patterns shared in the data and express it as a set of logic programs (or rule/formulae) (Lavrac & Dzeroski, 1994).
Traditional ILP methods such as AMIE+ (Gal´arraga et al., 2015) and RLvLR (Omran et al., 2018) relies on explicit search-based method for rule mining with various pruning techniques.
These works can scale up to very large knowledge bases.
However, the algorithm complexity grows exponentially in the size of the variables and predicates involved.
The acquired rules are often restricted to Horn clauses with a maximum length of less than 3, limiting the expressiveness of the rules.
On the other hand, compared to the differentiable approach, traditional methods make use of hard matching and discrete logic for rule search, which lacks the tolerance for ambiguous and noisy data.
The state-of-the-art differentiable forward-chaining methods focus on rule learning on predeﬁned templates (Evans & Grefenstette, 2018; Campero et al., 2018;
Ho et al., 2018), typically in the form of a Horn clause with one head predicate and two body predicates with chain-like variables,
i.e.
[Equation]
To evaluate the rules, one starts with a background set of facts and repeatedly apply rules for every possible triple until no new facts can be deduced.
Then the deduced facts are compared with a heldout ground-truth set.
Rules that are learned in this approach are in ﬁrst-order, i.e. data-independent and can be readily interpreted.
However, the deducing phase can quickly become infeasible with a larger background set.
Although ∂ ILP (Evans & Grefenstette, 2018) has proposed to alleviate by performing only a ﬁxed number of steps, works of this type could generally scale to KBs with less than 1K facts and 100 entities.
On the other hand, differentiable backward-chaining methods such as NTP (Rockt ¨ aschel & Riedel, 2017) are more efﬁcient in rule evaluation.
In (Minervini et al., 2018), NTP 2.0 can scale to larges KBs such as WordNet.
However, FOL rules are searched with templates, so the expressiveness is still limited.
Another differentiable ILP method, i.e. Neural Logic Machine (NLM), is proposed in (Dong et al., 2019), which learns to represent logic predicates with tensorized operations.
NLM is capable of both deductive and inductive learning on predicates with unknown arity.
However, as a forward-chaining method, it also suffers from the scalability issue as ∂ ILP.
It involves a permutation operation over the tensors when performing logic deductions, making it difﬁcult to scale to real-world KBs.
On the other hand, the inductive rules learned by NLM are encoded by the network parameters implicitly, so it does not support representing the rules with explicit predicate and logic variable symbols.
Multi-hop reasoning : Multi-hop reasoning methods (Guu et al., 2015; Lao & Cohen, 2010; Lin et al., 2015; Gardner & Mitchell, 2015; Das et al., 2016;
Yang et al., 2017) such as NeuralLP (Yang et al., 2017) construct rule on-the-ﬂy when given a speciﬁc query.
It adopts a ﬂexible ILP setting: instead of pre-deﬁning templates, it assumes a chain-like Horn clause can be constructed to answer the query
P ∗ ( X
[Equation]
X (cid:48) )
←
[Equation]
[Equation]
[Equation]
( T
[Equation]
Y n −
[Equation]
X (cid:48) ) .
And each step of the reasoning in the chain can be efﬁciently represented by matrix multiplication.
The resulting algorithm is highly scalable compared to the forward-chaining counter-parts and can learn rules on large datasets such as FreeBase.
However, this approach reasons over a single chainlike path, and the path is sampled by performing random walks that are independent on the task context (Das et al., 2017), limiting the rule expressiveness.
On the other hand, the FOL rule is generated while conditioning on the speciﬁc query, making it difﬁcult to extract rules that are globally consistent.
Link prediction with relational embeddings : Besides multi-hop reasoning methods, a number of works are proposed for KB completion using learnable embeddings for KB relations.
For example,
In (Bordes et al., 2013; Sun et al., 2019; Balaˇzevi´c et al., 2019) it learns to map KB relations into vector space and predict links with scoring functions.
NTN (Socher et al., 2013), on the other hand, parameterizes each relation into a neural network.
In this approach, embeddings are used for predicting links directly, thus its prediction cannot be interpreted as explicit FOL rules.
This is different from that in NLIL, where predicate embeddings are used for generating data-independent rules.
[Table]
[Equation]
X [Equation]
B C HALLENGES IN ILP
Standard ILP approaches are difﬁcult and involve several procedures that have been proved to be
NP-hard.
The complexity comes from 3 levels: ﬁrst, the search space for a formula is vast.
The body of the entailment can be arbitrarily long and the same predicate can appear multiple times with different variables, for example, the Inside predicate in Eq.(2) appears twice.
Most ILP works constrain the logic entailment to be Horn clause, i.e. the body of the entailment is a ﬂat conjunction over literals, and the length limited within 3 for large datasets.
Second, constructing formulas also involves assigning logic variables that are shared across different predicates, which we refer to as variable binding .
For example, in Eq.(2), to express that a person is inside the car, we use X and Y to represent the region of a person and that of a car, and the same two variables are used in Inside to express their relations.
Different bindings lead to different meanings.
For a formula with n arguments (Eq.(2) has 7), there are O ( n n ) possible assignments.
Existing
ILP works either resort to constructing formula from pre-deﬁned templates (Evans & Grefenstette, 2018;
Campero et al., 2018) or from chain-like variable reference (Yang et al., 2017), limiting the expressiveness of the learned rules.
Finally, evaluating a formula candidate is expensive.
A FOL rule is data-independent.
To evaluate it, one needs to replace the variables with actual entities and compute its value.
This is referred to as grounding or instantiation .
Each variable used in a formula can be grounded independently, meaning a formula with n variables can be instantiated into O ( C n ) grounded formulas, where C is the number of total entities.
For example, Eq.(2) contains 3 logic variables: X , Y and Z .
To evaluate this formula, one needs to instantiate these variables into C 3 possible combinations, and check if the rule holds or not in each case.
However in many domains, such as object detection, such grounding space is vast (e.g. all possible bounding boxes of an image) making the full evaluation infeasible.
Many forward-chaining methods such as ∂ ILP (Evans & Grefenstette, 2018) scales exponentially in the size of the grounding space, thus are limited to small scale datasets with less than 10 predicates and 1K entities.
C E XPERIMENTS
Baselines : For NeuralLP, we use the ofﬁcial implementation at here .
For ∂ ILP, we use the thirdparty implementation at here .
For TransE, we use the implementation at here .
For RotatE, we use the ofﬁcial implementation at here .
[Table]
Model setting : For NLIL, we create separate Transformer blocks for each target predicate.
All experiments are conducted on a machine with i7-8700K, 32G RAM and one GTX1080ti.
We use the embedding size d = 32 .
We use 3 layers of multi-head attentions for each Transformer network.
The number of attention heads are set to number of heads = 4 for encoder, and the ﬁrst two layers of the decoder.
The last layer of the decoder has one attention head to produce the ﬁnal attention required for rule evaluation.
For KB completion task, we set the number of operator calls T = 2 and formula combinations
L = 0 , as most of the relations in those benchmarks can be recovered by symmetric/asymmetric relations or compositions of a few relations (Sun et al., 2019).
Thus complex formulas are not preferred.
For FB15K-237, binary predicates are grouped hierarchically into domains.
To avoid unnecessary search overhead, we use the most frequent 20 predicates that share the same root domain (e.g. “award”, “location”) with the head predicate for rule body construction, which is a similar treatment as in (Yang et al., 2017).
For VG dataset, we set T = 3 , L = 2 and C = 4 .
Evaluation metrics :
Following the conventions in (Yang et al., 2017;
Bordes et al., 2013) we use
Mean Reciprocal Ranks (MRR) and Hits@10 for evaluation metrics.
For each query (cid:104) x , P k , x (cid:48) (cid:105) , the model generates a ranking list over all possible groundings of predicate P k , with other groundtruth triplets ﬁltered out.
Then MRR is the average of the reciprocal rank of the queries in their corresponding lists, and Hits@10 is the percentage of queries that are ranked within the top 10 in the list.