Learning Attention-based Embeddings for Relation Prediction in Knowledge Graphs

The recent proliferation of knowledge graphs (KGs) coupled with incomplete or partial information, in the form of missing relations (links) between entities, has fueled a lot of research on knowledge base completion (also known as relation prediction). Several recent works suggest that convolutional neural network (CNN) based models generate richer and more expressive feature embeddings and hence also perform well on relation prediction. However, we observe that these KG embeddings treat triples independently and thus fail to cover the complex and hidden information that is inherently implicit in the local neighborhood surrounding a triple. To this effect, our paper proposes a novel attention-based feature embedding that captures both entity and relation features in any given entity’s neighborhood. Additionally, we also encapsulate relation clusters and multi-hop relations in our model. Our empirical study offers insights into the efficacy of our attention-based model and we show marked performance gains in comparison to state-of-the-art methods on all datasets.


Introduction
Knowledge graphs (KGs) represent knowledge bases (KBs) as a directed graph whose nodes and edges represent entities and relations between entities, respectively. For example, in Figure 1, a triple (London, capital of, United Kingdom) is represented as two entities: London and United Kingdom along with a relation (capital of) linking them. KGs find uses in a wide variety of applications such as semantic search (Berant et al., 2013;Berant and Liang, 2014), dialogue generation (He et al., 2017;Keizer et al., 2017), and question answering (Zhang et al., 2016;Diefenbach et al., 2018), to name a few. However, KGs typically * Equal Contribution suffer from missing relations (Socher et al., 2013a;West et al., 2014). This problem gives rise to the task of knowledge base completion (also referred to as relation prediction), which entails predicting whether a given triple is valid or not.
State-of-the-art relation prediction methods are known to be primarily knowledge embedding based models. They are broadly classified as translational models Yang et al., 2015; and convolutional neural network (CNN)  based models. While translational models learn embeddings using simple operations and limited parameters, they produce low quality embeddings. In contrast, CNN based models learn more expressive embeddings due to their parameter efficiency and consideration of complex relations. However, both translational and CNN based models process each triple independently and hence fail to encapsulate the semantically rich and latent relations that are inherently present in the vicinity of a given entity in a KG.
Motivated by the aforementioned observations, we propose a generalized attention-based graph embedding for relation prediction. For node classification, graph attention networks (GATs) (Veličković et al., 2018) have been shown to focus on the most relevant portions of the graph, namely the node features in a 1-hop neighborhood. Given a KG and the task of relation prediction, our model generalizes and extends the attention mechanism by guiding attention to both entity (node) and relation (edge) features in a multi-hop neighborhood of a given entity / node. Our idea is: 1) to capture multi-hop relations (Lin et al., 2015) surrounding a given node, 2) to encapsulate the diversity of roles played by an entity in various relations, and 3) to consolidate the existing knowledge present in semantically similar relation clusters (Valverde-Rebaza and de Andrade Lopes, 2012). Our model achieves these objectives by assigning different weight mass (attention) to nodes in a neighborhood and by propagating attention via layers in an iterative fashion. However, as the model depth increases, the contribution of distant entities decreases exponentially. To resolve this issue, we use relation composition as proposed by (Lin et al., 2015) to introduce an auxiliary edge between nhop neighbors, which then readily allows the flow of knowledge between entities. Our architecture is an encoder-decoder model where our generalized graph attention model and ConvKB  play the roles of an encoder and decoder, respectively. Moreover, this method can be extended for learning effective embeddings for Textual Entailment Graphs (Kotlerman et al., 2015), where global learning has proven effective in the past as shown by (Berant et al., 2015) and (Berant et al., 2010).
Our contributions are as follows. To the best of our knowledge, we are the first to learn new graph attention based embeddings that specifically target relation prediction on KGs. Secondly, we generalize and extend graph attention mechanisms to capture both entity and relation features in a multi-hop neighborhood of a given entity. Finally, we evaluate our model on challenging relation prediction tasks for a wide variety of realworld datasets. Our experimental results indicate a clear and substantial improvement over stateof-the-art relation prediction methods. For instance, our attention-based embedding achieves an improvement of 104% over the state-of-the-art method for the Hits@1 metric on the popular Freebase (FB15K-237) dataset.
The rest of the paper is structured as follows. We first provide a review of related work in Section 2 and then our detailed approach in Section 3. Experimental results and dataset descriptions are reported in Section 4 followed by our conclusion and future research directions in Section 5.

Related Work
Recently, several variants of KG embeddings have been proposed for relation prediction. These methods can be broadly classified as: (i) compositional, (ii) translational, (iii) CNN based, and (iv) graph based models.
RESCAL (Nickel et al., 2011), NTN (Socher et al., 2013b), and the Holographic embedding  (Nickel et al., 2016) are examples of compositional based models. Both RESCAL and NTN use tensor products which capture rich interactions, but require a large number of parameters to model relations and are thus cumbersome to compute. To combat these drawbacks, HOLE creates more efficient and scalable compositional representations using the circular correlation of entity embeddings.
In comparison, translational models like TransE , DISTMULT (Yang et al., 2015) and ComplEx  propose arguably simpler models. TransE considers the translation operation between head and tail entities for relations. DISTMULT (Yang et al., 2015) learns embeddings using a bilinear diagonal model which is a special case of the bilinear objective used in NTN and TransE. DISTMULT uses weighted element-wise dot products to model entity relations. ComplEx  generalizes DISTMULT (Yang et al., 2015) by using complex embeddings and Hermitian dot products instead. These translational models are faster, require fewer parameters and are relatively easier to train, but result in less expressive KG embeddings.
Recently, two CNN based models have been proposed for relation prediction, namely ConvE  and Con-vKB (Nguyen et al., 2018). ConvE uses 2-D convolution over embeddings to predict links. It comprises of a convolutional layer, a fully connected projection layer and an inner product layer for the final predictions. Different feature maps are generated using multiple filters to extract global relationships. Concatenation of these feature maps represents an input triple. These models are parameter efficient but consider each triple independently without taking into account the relationships between the triples.
A graph based neural network model called R-GCN  is an extension of applying graph convolutional networks (GCNs) (Kipf and Welling, 2017) to relational data. It applies a convolution operation to the neighborhood of each entity and assigns them equal weights. This graph based model does not outperform the CNN based models.
Existing methods either learn KG embeddings by solely focusing on entity features or by taking into account the features of entities and relations in a disjoint manner. Instead, our proposed graph attention model holistically captures multi-hop and semantically similar relations in the n-hop neighborhood of any given entity in the KG.

Our Approach
We begin this section by introducing the notations and definitions used in the rest of the paper, followed by a brief background on graph attention networks (GATs) (Veličković et al., 2018). Finally, we describe our proposed attention architecture for knowledge graphs followed by our decoder network.

Background
A knowledge graph is denoted by G = (E, R), where E and R represent the set of entities (nodes) and relations (edges), respectively. A triple (e s , r, e o ) is represented as an edge r between nodes e s and e r in G 1 . Embedding models try to learn an effective representation of entities, relations, and a scoring function f , such that for a given input triple t = (e s , r, e o ), f (t) gives the likelihood of t being a valid triple. For example, Figure 1 shows the subgraph from a KG which infers missing links represented by dashed lines using existing triples such as (London, captial of, United Kingdom).

Graph Attention Networks (GATs)
Graph convolutional networks (GCNs) (Kipf and Welling, 2017) gather information from the entity's neighborhood and all neighbors contribute equally in the information passing.
To address the shortcomings of GCNs, (Veličković et al., 2018) introduced graph attention networks (GATs). GATs learn to assign varying levels of importance to nodes in every node's neighbor-hood, rather than treating all neighboring nodes with equal importance, as is done in GCN.
The input feature set of nodes to a layer is x = { x 1 , x 2 , ..., x N }. A layer produces a transformed set of node feature vectors x = { x 1 , x 2 , ..., x N }, where x i and x i are input and output embeddings of the entity e i , and N is number of entities (nodes). A single GAT layer can be described as where e ij is the attention value of the edge (e i , e j ) in G, W is a parametrized linear transformation matrix mapping the input features to a higher dimensional output feature space, and a is any attention function of our choosing. Attention values for each edge are the importance of the edge (e i , e j ) s features for a source node e i . Here, the relative attention α ij is computed using a softmax function over all the values in the neighborhood. Equation 2 shows the output of a layer. GAT employs multi-head attention to stabilize the learning process as credited to (Vaswani et al., 2017).
The multihead attention process of concatenating K attention heads is shown as follows in Equation 3.
where represents concatenation, σ represents any non-linear function, α k ij are normalized attention coefficients of edge (e i , e j ) calculated by the k-th attention mechanism, and W k represents the corresponding linear transformation matrix of the k-th attention mechanism. The output embedding in the final layer is calculated using averaging, instead of the concatenation operation, to achieve multi-head attention, as is shown in the following Equation 4.

Relations are Important
Despite the success of GATs, they are unsuitable for KGs as they ignore relation (edge) features, which are an integral part of KGs. In KGs, entities play different roles depending on the relation they are associated with. For example, in Figure  1, entity Christopher Nolan appears in two different triples assuming the roles of a brother and a director. To this end, we propose a novel embedding approach to incorporate relation and neighboring node features in the attention mechanism.

Chevrolet
We define a single attentional layer, which is the building block of our model. Similar to GAT, our framework is agnostic to the particular choice of attention mechanism.
Each layer in our model takes two embedding matrices as input. Entity embeddings are represented by a matrix H ∈ R Ne×T , where the i-th row is the embedding of entity e i , N e is the total number of entities, and T is the feature dimension of each entity embedding. With a similar construction, the relation embeddings are represented by a matrix G ∈ R Nr×P . The layer then outputs the corresponding embedding matrices, H ∈ R Ne×T and G ∈ R Nr×P .
In order to obtain the new embedding for an entity e i , a representation of each triple associated with e i is learned. We learn these embeddings by performing a linear transformation over the concatenation of entity and relation feature vectors corresponding to a particular triple t k ij = (e i , r k , e j ), as is shown in Equation 5. This operation is also illustrated in the initial block of Figure 4.
where c ijk is the vector representation of a triple t k ij . Vectors h i , h j , and g k denote embeddings of entities e i , e j and relation r k , respectively. Additionally, W 1 denotes the linear transformation matrix. Similar to (Veličković et al., 2018), we learn Figure 3: Attention Mechanism the importance of each triple t k ij denoted by b ijk . We perform a linear transformation parameterized by a weight matrix W 2 followed by application of the LeakyRelu non-linearity to get the absolute attention value of the triple (Equation 6).
To get the relative attention values softmax is applied over b ijk as shown in Equation 7. Figure 3 shows the computation of relative attention values α ijk for a single triple.
As suggested by (Veličković et al., 2018), multihead attention which was first introduced by (Vaswani et al., 2017), is used to stabilize the learning process and encapsulate more information about the neighborhood. Essentially, M independent attention mechanisms calculate the embeddings, which are then concatenated, resulting in the following representation: In the final layer of our model, instead of concatenating the embeddings from multiple heads we employ averaging to get final embedding vectors for entities as shown in Equation 11.
However, while learning new embeddings, entities lose their initial embedding information. To resolve this issue, we linearly transform H i to obtain H t using a weight matrix W E ∈ R T i ×T f , where H i represents the input entity embeddings to our model, H t represents the transformed entity embeddings, T i denotes the dimension of an initial entity embedding, and T f denotes the dimension of the final entity embedding. We add this initial entity embedding information to the entity embeddings obtained from the final attentional layer, H f ∈ R Ne×T f as shown in Equation 12.
In our architecture, we extend the notion of an edge to a directed path by introducing an auxiliary relation for n-hop neighbors between two entities. The embedding of this auxiliary relation is the summation of embeddings of all the relations in the path. Our model iteratively accumulates knowledge from distant neighbors of an entity. As illustrated in figure 2, in the first layer of our model, all entities capture information from their direct in-flowing neighbors. In the second layer, U.S gathers information from entities Barack Obama, Ethan Horvath, Chevrolet, and Washington D.C, which already possess information about their neighbors Michelle Obama and Samuel L. Jackson, from a previous layer. In general, for a n layer model the incoming information is accumulated over a n-hop neighborhood.
The aggregation process to learn new entity embeddings and the introduction of an auxiliary edge between n-hop neighbors is also shown in Figure  2. We normalize the entity embeddings after every generalized GAT layer and prior to the first layer, for every main iteration.

Training Objective
Our model borrows the idea of a translational scoring function from , which learns embeddings such that for a given valid triple t k ij = (e i , r k , e j ), the condition h i + g k ≈ h j holds, i.e., e j is the nearest neighbor of e i connected via relation r k . Specifically, we try to learn entity and relation embeddings to minimize the L1-norm dissimilarity measure given by d t We train our model using hinge-loss which is given by the following expression where γ > 0 is a margin hyper-parameter, S is the set of valid triples, and S denotes the set of invalid triples, given formally as replace tail entity

Decoder
Our model uses ConvKB (Nguyen et al., 2018) as a decoder. The aim of the convolutional layer is to analyze the global embedding properties of a triple t k ij across each dimension and to generalize the transitional characteristics in our model. The score function with multiple feature maps can be written formally as: where ω m represents the m th convolutional filter, Ω is a hyper-parameter denoting number of filters used, * is a convolution operator, and W ∈ R Ωk×1 represents a linear transformation matrix used to compute the final score of the triple. The model is trained using soft-margin loss as

Datasets
To evaluate our proposed method, we use five benchmark datasets: WN18RR , FB15k-237 (Toutanova et al., 2015), NELL-995 (Xiong et al., 2017), Unified Medical Language Systems (UMLS) (Kok and Domingos, 2007) and Alyawarra Kinship (Lin et al., 2018). Previous works (Toutanova et al., 2015; suggest that the task of relation prediction in WN18 and FB15K suffers from the problem of inverse relations, whereby one can achieve state-of-the-art results using a simple reversal rule based model, as shown by . Therefore, corresponding subset datasets WN18RR and FB15k-237 were created to resolve the reversible relation problem in WN18 and FB15K. We used the data splits provided by . Table 1 provides statistics of all datasets used.

Training Protocol
We create two sets of invalid triples, each time replacing either the head or tail entity in a triple by an invalid entity. We randomly sample equal number of invalid triples from both the sets to ensure robust performance on detecting both head and tail entity. Entity and relation embeddings produced by TransE  are used to initialize our embeddings. We follow a two-step training procedure, i.e., we first train our generalized GAT to encode information about the graph entities and relations and then train a decoder model like ConvKB  to perform the relation prediction task. The original GAT update Equation 3 only aggregates information passed from 1-hop neighborhood, while our generalized GAT uses information from the n-hop neighborhood. We use auxiliary relations to aggregate more information about the neighborhood in sparse graphs. We use Adam to optimize all the parameters with initial learning rate set at 0.001. Both the entity and relation embeddings of the final layer are set to 200. The optimal hyper-parameters set for each dataset are mentioned in our supplementary section.

Evaluation Protocol
In the relation prediction task, the aim is to predict a triple (e i , r k , e j ) with e i or e j missing, i.e., predict e i given (r k , e j ) or predict e j given (e i , r k ). We generate a set of (N − 1) corrupt triples for each entity e i by replacing it with every other entity e i ∈ E \ e i , then we assign a score to each such triple. Subsequently, we sort these scores in ascending order and get the rank of a correct triple (e i , r k , e j ). Similar to previous work (( , ), we evaluate all the models in a filtered setting, i.e, during ranking we remove corrupt triples which are already present in one of the training, validation, or test sets. This whole process is repeated by replacing the tail entity e j , and averaged metrics are reported. We report mean reciprocal rank (MRR), mean rank (MR) and the proportion of correct entities in the top N ranks (Hits@N) for N = 1, 3, and 10.

Results and Analysis
Tables 2 and 3 present the prediction results on the test sets of all the datasets. The results clearly demonstrate that our proposed method 2   significantly outperforms state-of-the-art results on five metrics for FB15k-237, and on two metrics for WN18RR. We downloaded publicly available source codes to reproduce results of the state-ofthe-art methods 345678 on all the datasets. Attention Values vs Epochs: We study the distribution of attention with increasing epochs for a particular node. Figure 5 shows this distribution on FB15k-237. In the initial stages of the learning process, the attention is distributed randomly. As the training progresses and our model gathers more information from the neighborhood, it assigns more attention to direct neighbors and takes minor information from the more distant neighbors. Once the model converges, it learns to gather multi-hop and clustered relation information from the n-hop neighborhood of the node. PageRank Analysis: We hypothesize that complex and hidden multi-hop relations among entities are captured more succinctly in dense graphs 3 TransE 4 DistMult 5 ComplEx 6 R-GCN 7 ConvE 8 ConvKB as opposed to sparse graphs. To test this hypothesis, we perform an analysis similar to ConvE, where they study the correlation between mean PageRank and increase in MRR relative to Dist-Mult. We notice a strong correlation coefficient of r = 0.808. Table 4 indicates that when there is an increase in PageRank values, there is also a corresponding increase in MRR values. We observe an anomaly to our observed correlation in case of NELL-995 versus WN18RR and attribute this to the highly sparse and hierarchical structure of WN18RR which poses as a challenge to our method that does not capture information in a topdown recursive fashion.

Ablation Study
We carry out an ablation study on our model, where we analyze the behavior of mean rank on a test set when we omit path generalization (−PG), i.e., removing n-hop information, and omit relation Information (−Relations) from our model. Figure 7 shows that our model performs better   than the two ablated models and we see a significant drop in the results when using ablated models on NELL-995. Removing the relations from the proposed model has a huge impact on the results which suggests that the relation embeddings play a pivotal role in relation prediction.

Conclusion and Future Work
In this paper, we propose a novel approach for relation prediction. Our approach improves over the state-of-the-art models by significant margins. Our proposed model learns new graph attentionbased embeddings that specifically cater to relation prediction on KGs. Additionally, we generalize and extend graph attention mechanisms to capture both entity and relation features in a multihop neighborhood of a given entity. Our detailed and exhaustive empirical analysis gives more insight into our method's superiority for relation prediction on KGs. The proposed model can be extended to learn embeddings for various tasks using KGs such as dialogue generation (He et al., 2017;Keizer et al., 2017), and question answering (Zhang et al., 2016;Diefenbach et al., 2018).
In the future, we intend to extend our method to better perform on hierarchical graphs and capture higher-order relations between entities (like mo-tifs) in our graph attention model.

A Results on UMLS dataset
We report results of our model on UMLS dataset in Table 5. UMLS is a relatively smaller knowledge graph with only 135 entities and 46 relations. Although this dataset is comparable to Kinship in size, it is relatively much sparser than Kinship with mean in-degree being 38.63, as opposed to 82.15 in Kinship. We show that despite the small size of the dataset, our model outperforms the baselines which indicates the robustness of our model.

B Indegree versus Attention
We analyze the attention flow of our encoder architecture for both the datasets. For each of these datasets we select two entities, one with higher indegree (high-node) and the other one having lower in-degree (low-node). We visualize the attention values for n-hop neighbors of these entities, where n = 1, 2, 3.
In FB15k-237, the low-node has 10 direct neighbors and the high-node has 50 direct neighbors. For the low-node, the number of 2-hop neighbors is 439 and 3-hop neighbors is 1543. For the high-node, the number of 2-hop and 3-hop neighbors are 2939 and 6915, respectively. Figure 8a shows that a significant proportion of the 1hop neighbors of our low-node have high attention values. However, this proportion increases as we move farther from the low-node. Figure 8b shows a reversal in this trend. For the high node, it can be seen that a significant proportion of entities in the 1-hop neighborhood get assigned higher attention values than 2 or 3-hop neighbors. As the low-node has just 10 direct neighbors, it tries to gather more information from its 2-hop and 3-hop neighbors, whereas in the case of the high-node most of the information is collected from its direct neighbors.
In WN18RR, the low-node has 5 direct neighbors and a high-node has 25 direct neighbors. For the low-node, the number of 2-hop neighbors is 19 and 3-hop neighbors is 57. For the high-node, the number of 2-hop and 3-hop neighbors are 67 and 84, respectively. Figure 9 shows that unlike in FB15k-237, the distribution of attention values is similar in the case of the low and high-node. Higher proportion of direct neighbors are being assigned higher attention values, and decreases with increase in distance from the node. Explanation of this behavior can be found in the inherent structure of the WN18RR dataset. WN18RR follows a strictly hierarchical structure which ensures that relatively more information is present at the first level rather than lower levels. Our model prioritizes the aggregation of information from the direct neighbors of the node, but at the same time makes use of the auxiliary information provided by auxiliary edges to learn the structure.

C Optimal Hyper-parameters
In this section we report the optimal set of hyperparameters for both our attention model (table 6) and ConvKB (table 7). We use grid search over Hits@10 to find these optimal parameters. We do not use batch training for our attention model, whereas we use a batch size of 128 for every dataset in our decoder model. Also, we use of a step learning rate scheduler which decays the learning rate by a factor of 0.5, after every 500 epochs in our attention model and after every 25 epochs in the decoder model. Some of the parameters reported in tables 6 and 7 are as follows: negative ratio is the ratio of negative and positive triples in the training set, i.e., we sample negative ratio negative triples per positive triple in the set. Margin corresponds to the value of γ in the hinge loss equation. Table 8 shows the number of n-hop paths existing in all datasets. We report unique paths between two entities n = {2, 3, 4, 5}, i.e., if there exist multiple paths between two entities of length n, we count it just once. For n = 1, we report all the paths present. Essentially this boils down to counting pairs of entities having a shortest path of length n between them.

D N-hop Paths
We make use of these paths to introduce auxiliary edges as discussed in the paper, so if a dataset has more n-paths, theoretically we can use the excess information to further improve the performance of our model. However, in datasets like FB15k-237, Kinship and UMLS, where the KG is already dense, the use of extra information can be safely neglected.

E Degree Distribution
We analyze the in-degree distributions for all datasets to get better insights. Figure 10 shows that WN18RR and NELL-995 have significant number of nodes with no incoming information flow, i.e., nodes with zero in-degree in KG. We Table 5: Experimental results on UMLS test sets. Hits@N values are in percentage. The best score is in bold and second best score is underlined.      hypothesize that in WN18RR, the sparse and hierarchical nature makes it a relatively harder dataset. FB15k-237 also has few rooted nodes in the KG, but since most of the nodes have many connections, the information flow is relatively effective in this case. In Kinship and UMLS, as we can see that there are no rooted nodes and both of these datasets are really dense in nature, especially Kinship. Due to this dense nature and the fact that every node learns from some other node, it is possible to predict relations effectively in these datasets.