SimplE Embedding for Link Prediction in Knowledge Graphs
Seyed Mehran Kazemi, David Poole
Introduction
During the past two decades, several knowledge graphs (KGs) containing (perhaps probabilistic) facts about the world have been constructed. These KGs have applications in several fields including search, question answering, natural language processing, recommendation systems, etc. Due to the enormous number of facts that could be asserted about our world and the difficulty in accessing and storing all these facts, KGs are incomplete. However, it is possible to predict new links in a KG based on the existing ones. Link prediction and several other related problems aiming at reasoning with entities and relationships are studied under the umbrella of statistical relational learning (SRL) . The problem of link prediction for KGs is also known as knowledge graph completion. A KG can be represented as a set of triplesTriples are complete for relations. They are sometimes written as or .. The problem of KG completion can be viewed as predicting new triples based on the existing ones.
Tensor factorization approaches have proved to be an effective SRL approach for KG completion . These approaches consider embeddings for each entity and each relation. To predict whether a triple holds, they use a function which takes the embeddings for the head and tail entities and the relation as input and outputs a number indicating the predicted probability. Details and discussions of these approaches can be found in several recent surveys .
One of the first tensor factorization approaches is the canonical Polyadic (CP) decomposition . This approach learns one embedding vector for each relation and two embedding vectors for each entity, one to be used when the entity is the head and one to be used when the entity is the tail. The head embedding of an entity is learned independently of (and is unrelated to) its tail embedding. This independence has caused CP to perform poorly for KG completion . In this paper, we develop a tensor factorization approach based on CP that addresses the independence among the two embedding vectors of the entities. Due to the simplicity of our model, we call it SimplE (Simple Embedding).
We show that SimplE: 1- can be considered a bilinear model, 2- is fully expressive, 3- is capable of encoding background knowledge into its embeddings through parameter sharing (aka weight tying), and 4- performs very well empirically despite (or maybe because of) its simplicity. We also discuss several disadvantages of other existing approaches. We prove that many existing translational approaches (see e.g., ) are not fully expressive and we identify severe restrictions on what they can represent. We also show that the function used in ComplEx , a state-of-the-art approach for link prediction, involves redundant computations.
Background and Notation
Let and represent the set of entities and relations respectively. A triple is represented as , where is the head, is the relation, and is the tail of the triple. Let represent the set of all triples that are true in a world (e.g., ), and represent the ones that are false (e.g., ). A knowledge graph is a subset of . A relation is reflexive on a set of entities if for all entities . A relation is symmetric on a set of entities if for all pairs of entities , and is anti-symmetric if . A relation is transitive on a set of entities if for all . The inverse of a relation , denoted as , is a relation such that for any two entities and , .
An embedding is a function from an entity or a relation to one or more vectors or matrices of numbers. A tensor factorization model defines two things: 1- the embedding functions for entities and relations, 2- a function taking the embeddings for , and as input and generating a prediction of whether is in or not. The values of the embeddings are learned using the triples in a . A tensor factorization model is fully expressive if given any ground truth (full assignment of truth values to all triples), there exists an assignment of values to the embeddings of the entities and relations that accurately separates the correct triples from incorrect ones.
Related Work
SimplE: A Simple Yet Fully Expressive Model
Let represent if a person likes a movie and represent who acted in which movie. Which actors play in a movie is expected to affect who likes the movie. In CP, observations about likes only update the vector of movies and observations about acted only update the vector. Therefore, what is being learned about movies through observations about acted does not affect the predictions about likes and vice versa.
SimplE takes advantage of the inverse of relations to address the independence of the two vectors for each entity in CP. While inverse of relations has been used for other purposes (see e.g., ), using them to address the independence of the entity vectors in CP is a novel contribution.
Learning SimplE Models: To learn a SimplE model, we use stochastic gradient descent with mini-batches. In each learning iteration, we iteratively take in a batch of positive triples from the , then for each positive triple in the batch we generate negative triples by corrupting the positive triple. We use Bordes et al. ’s procedure to corrupt positive triples. The procedure is as follows. For a positive triple , we randomly decide to corrupt the head or tail. If the head is selected, we replace in the triple with an entity randomly selected from and generate the corrupted triple . If the tail is selected, we replace in the triple with an entity randomly selected from and generate the corrupted triple . We generate a labelled batch by labelling positive triples as and negatives as . Once we have a labelled batch, following we optimize the regularized negative log-likelihood of the batch: , where represents the parameters of the model (the parameters in the embeddings), represents the label of a triple, represents the similarity score for triple , is the regularization hyper-parameter, and . While several previous works (e.g., TransE, TransR, STransE, etc.) consider a margin-based loss function, Trouillon and Nickel show that the margin-based loss function is more prone to overfitting compared to log-likelihood.
Theoretical Analyses
In this section, we provide some theoretical analyses of SimplE and other existing approaches.
The following proposition establishes the full expressivity of SimplE.
For any ground truth over entities and relations containing true facts, there exists a SimplE model with embedding vectors of size that represents that ground truth.
First, we prove the bound. With embedding vectors of size , for each entity we let the n-th element of if ( mod and otherwise, and for each relation we let the n-th element of if ( div and otherwise (see Fig 1). Then for each and , the product of and is everywhere except for the -th element. So for each entity , we set the -th element of to be if holds and otherwise.
Now we prove the bound. Let be zero (base of the induction). We can have embedding vectors of size for each entity and relation, setting the value for entities to and for relations to . Then is negative for every entities and and relation . So there exists embedding vectors of size that represents this ground truth. Let us assume for any ground truth where , there exists an assignment of values to embedding vectors of size that represents that ground truth (assumption of the induction). We must prove for any ground truth where , there exists an assignment of values to embedding vectors of size that represents this ground truth. Let be one of the true facts. Consider a modified ground truth which is identical to the ground truth with true facts, except that is assigned false. The modified ground truth has true facts and based on the assumption of the induction, we can represent it using some embedding vectors of size . Let where , and are the embedding vectors that represent the modified ground truth. We add an element to the end of all embedding vectors and set it to . This increases the vector sizes to but does not change any scores. Then we set the last element of to , to , and to . This ensures that for the new vectors, and no other score is affected. ∎
DistMult is not fully expressive as it forces relations to be symmetric. It has been shown in that ComplEx is fully expressive with embeddings of length at most . According to the universal approximation theorem , under certain conditions, neural networks are universal approximators of continuous functions over compact sets. Therefore, we would expect there to be a representation based on neural networks that can approximate any ground truth, but the number of hidden units might have to grow with the number of triples. Wang et al. prove that TransE is not fully expressive. Proposition 2 proves that not only TransE but also many other translational approaches are not fully expressive. The proposition also identifies severe restrictions on what relations these approaches can represent.
FSTransE is not fully expressive and has the following restrictions. If a relation is reflexive on , must also be symmetric on , If is reflexive on , must also be transitive on , and If entity has relation with every entity in and entity has relation with one of the entities in , then must have the relation with every entity in .
For any entity and relation , let and . For a triple to hold, we should ideally have for some . We assume , , and are entities in .
A relation being reflexive on implies and . Suppose holds as well. Then we know . Therefore, , where . Therefore, must holds.
A relation being reflexive implies , , and . Suppose and hold. Then we know and . We can conclude , where . The above equality proves must hold.
Let have relation with . We know , , and . We can conclude , where . Therefore, must hold. ∎
Other variants of translational approaches such as TransE, FTransE, STransE, TransH , and TransR also have the restrictions mentioned in Proposition 2.
2 Incorporating Background Knowledge into the Embeddings
In SimplE, each element of the embedding vector of the entities can be considered as a feature of the entity and the corresponding element of a relation can be considered as a measure of how important that feature is to the relation. Such interpretability allows the embeddings learned through SimplE for an entity (or relation) to be potentially transferred to other domains. It also allows for incorporating observed features of entities into the embeddings by fixing one of the elements of the embedding vector of the observed value. Nickel et al. show that incorporating such features helps reduce the size of the embeddings.
Recently, incorporating background knowledge into tensor factorization approaches has been the focus of several studies. Towards this goal, many existing approaches rely on post-processing steps or add additional terms to the loss function to penalize predictions that violate the background knowledge . Minervini et al. show how background knowledge in terms of equivalence and inversion can be incorporated into several tensor factorization models through parameter tyingAlthough their incorporation of inversion into DistMult is not correct as it has side effects.. Incorporating background knowledge by parameter tying has the advantage of guaranteeing the predictions follow the background knowledge for all embeddings. In this section, we show how three types of background knowledge, namely symmetry, anti-symmetry, and inversion, can be incorporated into the embeddings of SimplE by tying the parametersNote that such background knowledge can be exerted on some relations selectively and not on the others. This is different than, e.g., DistMult which enforces symmetry on all relations. (we ignore the equivalence between two relations as it is trivial).
Let be a relation such that for any two entities and we have (i.e. is symmetric). This property of can be encoded into SimplE by tying the parameters to .
If , then a SimplE model makes and positive. By tying the parameters to , we can conclude that and also become positive. Therefore, the SimplE model predicts . ∎
Let be a relation such that for any two entities and we have (i.e. is anti-symmetric). This property of can be encoded into SimplE by tying the parameters to the negative of .
If , then a SimplE model makes and positive. By tying the parameters to the negative of , we can conclude that and become negative. Therefore, the SimplE model predicts . ∎
Let and be two relations such that for any two entities and we have (i.e. is the inverse of ). This property of and can be encoded into SimplE by tying the parameters to and to .
If , then a SimplE model makes and positive. By tying the parameters to and to , we can conclude that and also become positive. Therefore, the SimplE model predicts . ∎
3 Time Complexity and Parameter Growth
As described in , to scale to the size of the current KGs and keep up with their growth, a relational model must have a linear time and memory complexity. Furthermore, one of the important challenges in designing tensor factorization models is the trade-off between expressivity and model complexity. Models with many parameters usually overfit and give poor performance. While the time complexity for TransE is where is the size of the embedding vectors, adding the projections as in STransE (through the two relation matrices) increases the time complexity to . Besides time complexity, the number of parameters to be learned from data grows quadratically with . A quadratic time complexity and parameter growth may arise two issues: 1- scalability problems, 2- overfitting. Same issues exist for models such as RESCAL and NTNs that have quadratic or higher time complexities and parameter growths. DistMult and ComplEx have linear time complexities and the number of their parameters grow linearly with .
The time complexity of both SimplE-ignr and SimplE is , i.e. linear in the size of vector embeddings. SimplE-ignr requires one multiplication between three vectors for each triple. This number is for SimplE and for ComplEx. Thus, with the same number of parameters, SimplE-ignr and SimplE reduce the computations by a factor of and respectively compared to ComplEx.
4 Family of Bilinear Models
The constraint over matrices in SimplE is very similar to the constraint in DistMult. in both SimplE and DistMult can be considered as an element-wise product of the parameters, except that the s in SimplE swap the first and second halves of the resulting vector. Compared to ComplEx, SimplE removes the parameters on the main diagonal of s. Note that several other restrictions on the matrices are equivalent to SimplE, e.g., restricting matrices to be zero everywhere except on the counterdiagonal. Viewing SimplE as a single-vector-per-entity model makes it easily integrable (or compatible) with other embedding models (in knowledge graph completion, computer vision and natural language processing) such as .
5 Redundancy in ComplEx
As argued earlier, with the same number of parameters, the number of computations in ComplEx are 4x and 2x more than SimplE-ignr and SimplE. Here we show that a portion of the computations performed by ComplEx to make predictions is redundant. Consider a ComplEx model with embedding vectors of size (for ease of exposition). Suppose the embedding vectors for , and are , , and respectively. Then the probability of being correct according to ComplEx is proportional to the sum of the following four terms: , , , and . It can be verified that for any assignment of (non-zero) values to s and s, at least one of the above terms is negative. This means for a correct triple, ComplEx uses three terms to overestimate its score and then uses a term to cancel the overestimation.
The following example shows how this redundancy in ComplEx may affect its interpretability:
Consider a ComplEx model with embeddings of size . Consider entities , and with embedding vectors , , and respectively, and a relation with embedding vector . According to ComplEx, the score for triple is positive suggesting probably has relation with . However the score for triple is negative suggesting probably does not have relation with . Since the only difference between and is that the imaginary part changes from to , it is difficult to associate a meaning to these numbers.
Experiments and Results
Datasets: We conducted experiments on two standard benchmarks: WN18 a subset of Wordnet , and FB15k a subset of Freebase . We used the same train/valid/test sets as in . WN18 contains entities, relations, train, validation and test triples. FB15k contains entities, relations, train, validation, and test triples.
Baselines: We compare SimplE with several existing tensor factorization approaches. Our baselines include canonical Polyadic (CP) decomposition, TransE, TransR, DistMult, NTN, STransE, ER-MLP, and ComplEx. Given that we use the same data splits and objective function as ComplEx, we report the results of CP, TransE, DistMult, and ComplEx from . We report the results of TransR and NTN from , and ER-MLP from for further comparison.
Evaluation Metrics: To measure and compare the performances of different models, for each test triple we compute the score of triples for all and calculate the ranking of the triple having , and we compute the score of triples for all and calculate the ranking of the triple having . Then we compute the mean reciprocal rank (MRR) of these rankings as the mean of the inverse of the rankings: , where represents the test triples. MRR is a more robust measure than mean rank, since a single bad ranking can largely influence mean rank.
Bordes et al. identified an issue with the above procedure for calculating the MRR (hereafter referred to as raw MRR). For a test triple , since there can be several entities for which holds, measuring the quality of a model based on its ranking for may be flawed. That is because two models may rank the test triple to be second, when the first model ranks a correct triple (e.g., from train or validation set) to be first and the second model ranks an incorrect triple to be first. Both these models will get the same score for this test triple when the first model should get a higher score. To address this issue, proposed a modification to raw MRR. For each test triple , instead of finding the rank of this triple among triples for all (or for all ), they proposed to calculate the rank among triples only for such that . Following , we call this measure filtered MRR. We also report measures. The for a model is computed as the percentage of test triples whose ranking (computed as described earlier) is less than or equal .
Implementation: We implemented SimplE in TensorFlow . We tuned our hyper-parameters over the validation set. We used the same search grid on embedding size and as to make our results directly comparable to their results. We fixed the maximum number of iterations to and the batch size to . We set the learning rate for WN18 to and for FB15k to and used adagrad to update the learning rate after each batch. Following , we generated one negative example per positive example for WN18 and negative examples per positive example in FB15k. We computed the filtered MRR of our model over the validation set every iterations for WN18 and every iterations for and selected the iteration that resulted in the best validation filtered MRR. The best embedding size and values on WN18 for SimplE-ignr were and respectively, and for SimplE were and . The best embedding size and values on FB15k for SimplE-ignr were and respectively, and for SimplE were and .
Table 1 shows the results of our experiments. It can be viewed that both SimplE-ignr and SimplE do a good job compared to the existing baselines on both datasets. On WN18, SimplE-ignr and SimplE perform as good as ComplEx, a state-of-the-art tensor factorization model. On FB15k, SimplE outperforms the existing baselines and gives state-of-the-art results among tensor factorization approaches. SimplE (and SimplE-ignr) work especially well on this dataset in terms of filtered MRR and hit@1, so SimplE tends to do well at having its first prediction being correct.
The table shows that models with many parameters (e.g., NTN and STransE) do not perform well on these datasets, as they probably overfit. Translational approaches generally have an inferior performance compared to other approaches partly due to their representation restrictions mentioned in Proposition 2. As an example for the friendship relation in FB15k, if an entity is friends with other entities and another entity is friends with only one of those 20, then according to Proposition 2 translational approaches force to be friends with the other 19 entities as well (same goes for, e.g., netflix genre in FB15k and has part in WN18). The table also shows that bilinear approaches tend to have better performances compared to translational and deep learning approaches. Even DistMult, the simplest bilinear approach, outperforms many translational and deep learning approaches despite not being fully expressive. We believe the simplicity of embeddings and the scoring function is a key property for the success of SimplE.
2 Incorporating background knowledge
When background knowledge is available, we might expect that a knowledge graph might not include redundant information because it is implied by background knowledge and so the methods that do not include the background knowledge can never learn it. In section 5.2, we showed how background knowledge that can be formulated in terms of three types of rules can be incorporated into SimplE embeddings. To test this empirically, we conducted an experiment on WN18 in which we incorporated several such rules into the embeddings as outlined in Propositions 3, 4, and 5. The rules can be found in Table 2. As can be viewed in Table 2, most of the rules are of the form . For (possibly identical) relations such as and participating in such a rule, if both and are in the training set, one of them is redundant because one can be inferred from the other. We removed redundant triples from the training set by randomly removing one of the two triples in the training set that could be inferred from the other one based on the background rules. Removing redundant triples reduced the number of triples in the training set from (approximately) to (approximately) , almost reduction in size. Note that this experiment provides an upper bound on how much background knowledge can improve the performance of a SimplE model.
We trained SimplE-ignr and SimplE (with tied parameters according to the rules) on this new training dataset with the best hyper-parameters found in the previous experiment. We refer to these two models as SimplE-ignr-bk and SimplE-bk. We also trained another SimplE-ignr and SimplE models on this dataset, but without incorporating the rules into the embeddings. For sanity check, we also trained a ComplEx model over this new dataset. We found that the filtered MRR for SimplE-ignr, SimplE, and ComplEx were respectively , , and . For SimplE-ignr-bk and SimplE-bk, the filtered MRRs were and respectively, substantially higher than the case without background knowledge. In terms of measures, SimplE-ignr gave , , and for , and respectively. These numbers were , , and for SimplE, and , and for ComplEx. For SimplE-ignr-bk, these numbers were , and and for SimplE-bk they were , and , also substantially higher than the models without background knowledge. The obtained results validate that background knowledge can be effectively incorporated into SimplE embeddings to improve its performance.
Conclusion
We proposed a simple interpretable fully expressive bilinear model for knowledge graph completion. We showed that our model, called SimplE, performs very well empirically and has several interesting properties. For instance, three types of background knowledge can be incorporated into SimplE by tying the embeddings. In future, SimplE could be improved or may help improve relational learning in several ways including: 1- building ensembles of SimplE models as do it for DistMult, 2- adding SimplE to the relation-level ensembles of , 3- explicitly modelling the analogical structures of relations as in , 4- using ’s 1-N scoring approach to generate many negative triples for a positive triple (Trouillon et al. show that generating more negative triples improves accuracy), 5- combining SimplE with logic-based approaches (e.g., with ) to improve property prediction, 6- combining SimplE with (or use SimplE as a sub-component in) techniques from other categories of relational learning as do with ComplEx, 7- incorporating other types of background knowledge (e.g., entailment) into SimplE embeddings.