Knowledge-Graph Embeddings: TransE and RotatE
Relations as translations or rotations of entity space: which patterns each geometry satisfies exactly, what neither abelian group can represent, and what training on an incomplete knowledge base actually learns.
Overview & Motivation
The relation extraction topic read the filings of six companies its classifiers had never seen and returned facts with scores above one half, every one of them true. It also returned facts below the threshold. One of them, scored , says that Granite Basin Midstream is a subsidiary of Northgate Energy. The extractor did find the other direction, Northgate Energy is the parent of Granite Basin Midstream, above the threshold. Anyone who knows what “parent” and “subsidiary” mean can fill in the missing fact. A knowledge-graph embedding is a way for a model to do the same: learn, from the facts it has, a geometry in which the missing fact is near the top.
The idea is the one the GloVe topic ended on. Its finance case study asked whether co-occurrence vectors make a relation a constant offset, Texas minus Houston equal to Massachusetts minus Boston, and found that no offset is constant. A knowledge-graph embedding stops hoping. It puts every entity at a point, makes every relation a map of the space, and trains the map to carry each fact’s head to its tail. TransE makes the map a translation, RotatE a rotation. Which relations each geometry can represent, and what training on an incomplete knowledge base actually teaches it, is the subject of this page. In order:
- Link prediction. How a model is asked about a missing fact, and how its answers are scored.
- Translation and rotation. What each geometry represents exactly: inverses, compositions, and symmetric relations.
- Relations as group actions. What any isometric model must collapse, and what no abelian one can represent.
- The bilinear foil. DistMult and ComplEx, and RotatE as ComplEx on the unit circle.
Then the finance case study: patterns held out from the finance knowledge base, where the most expressive model learns the wrong thing for an instructive reason, and the extracted facts about the held-out companies, completed.
Link prediction
The corpus’s knowledge base, WORLD, has entities ( people, organizations, places, sectors), ten relations, and facts. It was built so that its relations have the shapes embedding models are judged by. COMPETES_WITH is symmetric: if competes with , competes with . PARENT_OF and SUBSIDIARY_OF are inverses. BASED_IN is the composition of HQ_IN and LOCATED_IN: a company headquartered in Houston, which is in Texas, is based in Texas. IN_SECTOR is many-to-one: up to seven companies share a sector.
Definition 1 (Knowledge graph and link prediction).
A knowledge graph over entities and relations is a set of triples , read ” holds from head to tail ”. A scoring function ranks triples. A tail query ranks every by ; a head query ranks every by .
A held-out fact is tested twice, once as each query. The tail query (Halvorsen Industrial, PARENT_OF, ?) has two right answers, since Halvorsen has two subsidiaries in the knowledge base; ranking one of them second behind the other is not an error. Bordes et al. (2013) therefore drop the other known answers before ranking, the filtered setting.
Definition 2 (Filtered rank, MRR, and Hits@k).
For a test triple’s tail query with answer , the candidates are and every with not a known fact. Let be the number of candidates scoring above and the number of other candidates tied with it. The filtered rank of is the realistic rank
the mean of the optimistic rank and the pessimistic rank , which is also the expected rank when ties are broken uniformly at random. Head queries are ranked the same way. Over the two queries of every test triple, the mean reciprocal rank (MRR) is the mean of , and Hits@ is the share of ranks at most .
MRR here is the formalRAG reciprocal rank with exactly one relevant item per query. The tie rule is Berrendorf et al.’s (2020). It matters more than it looks: Sun, Vashishth, Sanyal, Talukdar, and Yang (2020) found published models whose scores were inflated by ranking the true answer first among many tied candidates. Ties will matter on this page too, for a different reason.
Translation: TransE
Give each entity a vector and each relation a vector . A fact is true when the head, moved by the relation, lands on the tail.
Definition 3 (TransE).
Entity vectors have unit length, , relation vectors are unconstrained, and
Bordes et al. train the margin loss over facts and their corruptions, where , a corruption replaces the head or the tail by another entity, and .
Translations handle two of the four patterns at once.
Proposition 1 (What translations represent exactly).
(a) If on every fact of , then makes every reversed pair a fact of exactly. (b) If holds exactly from to and from to , then holds exactly from to . (c) Both and hold exactly only if and .
Proof.
(a) . (b) . (c) Adding and gives , so and .
∎Wang, Zhang, Feng, and Chen (2014) made the point of (c), for what they called reflexive relations, as the motivation for TransH. A symmetric relation is a translation by zero, and every pair it relates is a single point. The Translate or rotate tab of the lab below shows it in the plane: two entities and , each related to the other. No translation brings the larger of the two residuals below , because the two residual vectors add up to twice the translation and subtract to twice .
The unit-length constraint in Definition 3 looks like a detail. It is not.
Proposition 2 (The norm constraint is load-bearing).
Multiply every entity and relation vector by . If an embedding separates every fact from its corruptions, so that for every pair, then the margin loss is nonincreasing in and equals for every , while no rank changes.
Proof.
Every distance scales by , so each term becomes , which is nonincreasing in and vanishes once . Ranks compare distances, and multiplying all of them by the same preserves every comparison.
∎Without the constraint, the loss rewards making the space bigger, not making it better. Bordes et al. give this reason in one clause for renormalizing the entity vectors at every step; the proposition makes it exact. The harness checks it on a small knowledge graph read off a random embedding, where scaling by takes the loss to zero with every ranking unchanged. The models on this page all train with Sun et al.’s logistic loss instead (below), and TransE keeps the unit sphere.
Rotation: RotatE
A symmetric relation needs a map that undoes itself without being the identity. A translation cannot do that. A rotation by half a turn can.
Lemma 1 (Multiplying by a unit complex number rotates).
For real ,
which is the rotation matrix applied to . Writing : , and .
Proof.
Expand the product with and collect real and imaginary parts. A rotation matrix is orthogonal, so it preserves length. The product expands to , which the angle-addition formulas turn into .
∎This is the unit-modulus case of the formalCalculus reading of a complex eigenvalue as a rotation and scaling of a real plane.
Definition 4 (RotatE).
Entities are vectors . A relation is a vector of unit-modulus coordinates, , and
where multiplies coordinate by coordinate and is a fixed margin.
Each relation turns each complex coordinate of the head by its own angle. Sun, Deng, Nie, and Tang (2019) measure the distance as the sum of the coordinates’ moduli; we use the Euclidean norm, which Proposition 5 below needs. Their Lemmas 1–3 state that RotatE can infer symmetric, inverse, and composed relations. Here is the exact statement, with both directions.
Theorem 1 (Relation patterns are phase equations).
Let have every coordinate nonzero.
(a) Both and hold exactly if and only if , that is, for every . Then differs from on every coordinate with .
(b) holds exactly on the reversal of every fact of if and only if , that is, .
(c) holds exactly across every path that takes and then if and only if , that is, .
Proof.
(a) If and , then , so , and gives , which for a unit complex number means . Conversely, if and , then . On a coordinate with , .
(b) With , the reversed fact holds when , that is, , which for nonzero coordinates means . For unit complex numbers the inverse is the conjugate.
(c) With and , the triple holds when , which for nonzero coordinates means . By Lemma 1 the phases add.
∎Part (a) is the point of rotation. A phase of turns a coordinate half way round, and twice that is the identity, so the pair stays apart: in the lab’s toy, rotating by lands exactly on , and rotating lands back on .
Trained on the whole finance knowledge base, RotatE with complex coordinates solves the three equations almost exactly. The median distance of COMPETES_WITH’s sixteen phases from is ; the median of is ; the median of (wrapped to ) is . Random phases would give , , and . Even the implication ACQUIRED PARENT_OF shows: ACQUIRED holds on six of PARENT_OF’s thirteen pairs, and the two relations’ phases agree to a median of . The Relation phases tab draws them on the unit circle.
Relations as group actions
Translations and rotations have more in common than either has with the other models. Both move the whole space rigidly, and both compose the way numbers add. That is enough to prove things about every such model at once.
Definition 5 (A relation model as a group action).
A group acts on entity space by isometries (maps preserving the distance ). Each relation is an element , and
TransE is the translation group acting by . RotatE is the torus , the vectors of unit complex numbers under coordinatewise multiplication, acting by . Both groups are abelian: .
Cai (2019) framed knowledge-graph embeddings this way, with a symmetric relation as an element of order two. A trained model never satisfies a fact exactly; the most one can say is that every fact of a relation sits within some distance . Isometry alone then forces three kinds of collapse.
Theorem 2 (Isometries collapse what they cannot separate).
Suppose every fact of satisfies , and write .
(a) Two heads with a common tail satisfy , and two tails of a common head satisfy .
(b) If and are both facts, then . For TransE this says and .
(c) If entities form a cycle of odd length in which each consecutive pair (including ) is related both ways, then consecutive entities satisfy .
At each statement says the entities coincide.
Proof.
Every step uses that preserves distance, so , and the triangle inequality.
(a) . For two tails, .
(b) . For TransE, , so , and .
(c) Write for , with indices mod . By induction on , , since . Going all the way round, . Write . By (b), , so
Then , and . Relabeling the cycle gives every consecutive pair.
∎Part (b) at says that fixes . A nonzero translation fixes no point, so TransE needs to be the identity, and has no element of order two besides zero: that is Proposition 1(c) again. The torus has of them, the phase vectors in other than zero, which is Theorem 1(a). Parts (a) and (c) are where rotation runs out. A rotation is an isometry, so RotatE collapses a many-to-one relation’s heads exactly as TransE does. And an odd cycle cannot alternate: on a coordinate with the entities around a triangle would have to be , and the third must also equal , so . “RotatE models symmetry” is exact only for a symmetric relation whose pairs are disjoint. The finance knowledge base’s COMPETES_WITH relation is not one: its companies have one, two, or three competitors (, , and companies), and the competitor graph contains triangles. The lab’s toy has a triangle too, and no angle zeroes its six residuals. The harness checks all three bounds on the trained full-KB TransE and RotatE, and part (c) on random odd cycles of lengths , , and .
Both groups are abelian, and that has a consequence of its own. In a family, a mother’s father and a father’s mother are different people (Yang, Sha, and Hong 2020 use the example). The smallest group in which order matters is , the six permutations of three objects. Let swap the first two and cycle all three; then .
Theorem 3 (Abelian models cannot tell ab from ba).
Make the Cayley graph of a knowledge graph: the six permutations are the entities, and relation takes to , relation takes to ( facts). If is abelian and every fact holds within , then for every the false triple satisfies
So a model that keeps every corruption at distance at least from its query has .
Proof.
The fact at gives , and by isometry (the fact at ), so . In the same way, from the fact at and the fact at , . Since , , and . The triple is false because takes only to , and because .
∎However the margin is set, an abelian model keeps some false triple within five times its worst true one. Trained on the twelve facts, the best ratio TransE reaches is in the plane, by collapsing all six entities to one point so that every fact and every corruption sits at the length of its relation vector, ; with and complex dimensions it reaches and . RotatE reaches , , and . Breaking the bound takes a group in which order matters.
Corollary 1 (A non-abelian action fits the graph exactly).
Let send each permutation of to the symmetry of an equilateral triangle that permutes its vertices the same way: transpositions become reflections and 3-cycles rotations by , so is an isomorphism onto the dihedral group . For a point on none of the triangle’s three mirror lines, the embedding with and satisfies all twelve facts exactly, with six distinct entities.
Proof.
for , which is the fact. Orthogonal matrices are isometries. The six points are distinct because the only element of that fixes is the identity: each reflection fixes only its mirror line, and each nontrivial rotation only the center.
∎With the twelve facts hold to , the nearest two entities are apart, and so is the nearest corruption: the ratio is unbounded. The Non-commuting tab draws the hexagon beside the trained abelian layouts. QuatE (Zhang et al. 2019), Rotate3D (Gao et al. 2020), and NagE (Yang, Sha, and Hong 2020) replace the torus with non-abelian rotation groups for exactly this reason.
The bilinear foil
A different family scores a triple by a product rather than a distance.
Definition 6 (DistMult and ComplEx).
DistMult (Yang et al. 2015) scores with real vectors. ComplEx (Trouillon et al. 2016) scores with complex vectors.
DistMult is a CP decomposition of the knowledge base’s tensor (formalML: tensor decompositions, Definition 4) in which the head factor matrix and the tail factor matrix are the same matrix. That tie costs it every asymmetric relation.
Proposition 3 (DistMult is symmetric in every relation).
for every relation and every pair of entities. On every fact of an antisymmetric relation, DistMult ties the reversal.
Proof.
Multiplication of real numbers is commutative, so for every .
∎Kazemi and Poole (2018) state this in one sentence. ComplEx keeps the product and breaks the tie with a conjugate.
Proposition 4 (The antisymmetric part of ComplEx).
With ,
So a ComplEx relation is symmetric for all entities if and only if every is real, and antisymmetric if and only if every is imaginary.
Proof.
. For each , , since and . The difference vanishes for all entities exactly when every . The sum vanishes for all entities exactly when every .
∎The two families meet at the unit circle.
Proposition 5 (RotatE is ComplEx on the unit torus).
If every , then
Proof.
For complex numbers, . Apply it with and , use (Lemma 1), and sum over .
∎RotatE’s squared distance is ComplEx’s score with the relation pinned to the unit torus, minus a term for each entity’s length. Restricting the relation to unit modulus is what turns a product into an isometric action, with everything Theorems 2 and 3 say about one.
| pattern | TransE | RotatE | DistMult | ComplEx |
|---|---|---|---|---|
| symmetric | by collapse | , disjoint pairs | always | real |
| antisymmetric | yes | yes | no | yes |
| inverse | only as symmetric | |||
| composition | no | no | ||
| order-dependent | no | no | no | no |
| many-to-one | by collapse | by collapse | yes | yes |
Read the table as exact satisfaction. Whether training finds these solutions is a separate question, and the case study answers it.
Finance case study
With b = −a, rotating by 180° carries a to b and b back to a (Theorem 1(a)). A translation moves both the same way, so the two residuals add to twice the shift and subtract to twice b − a: the larger is never below |b − a| = 2 (Proposition 1(c)).
Where this sits
The relation extraction topic turned sentences into scored facts. This page turns facts into geometry and asks what the geometry can and cannot hold. Translations and rotations satisfy inverses and compositions exactly, and rotations also satisfy symmetric relations, but only when their pairs are disjoint (Theorems 1 and 2). Both are actions of abelian groups by isometries, which collapses many-to-one relations and odd symmetric cycles and makes order-dependent composition impossible (Theorems 2 and 3), while the symmetries of a triangle fit what neither can (Corollary 1). DistMult is symmetric by construction, and RotatE is ComplEx with unit-modulus relations (Propositions 3–5). The capstone runs the whole thread on earnings-call text: tokenize, classify tone, extract entities and relations, and embed the knowledge base this page completes.
Honest caveats
Implementation
The companion notebook (notebookPath) imports the topic’s Python module, which owns every number on this page. It imports the relation extraction topic’s module for its rules and its extracted knowledge base, and through it the finance corpus and its knowledge base. All four models are written in NumPy with one backward pass: every query becomes a point, scored against every entity by a distance or an inner product. Its harness checks:
- every gradient against central differences, and Definition 2’s rank against brute force;
- Propositions 1 and 2, Lemma 1, and Theorem 1 on exact constructions, and Theorem 1 on the trained phases, full and with facts hidden;
- Theorem 2’s three bounds on the trained models, Theorem 3 on random and trained abelian embeddings, and Corollary 1’s exact fit;
- Propositions 3–5 on random draws, and every comparison this page states.
The laboratory reads its data from a JSON file that one of the harness’s tests requires to equal the module’s viz_payload() exactly, so the figure cannot drift from the code.
Connections
- Every model here trains like skip-gram with negative sampling, a logistic loss on true pairs against corrupted ones; with every corruption scored, it is that topic's expected negative-sampling objective computed exactly. word2vec-implicit-factorization
References & Further Reading
- paper Translating Embeddings for Modeling Multi-relational Data — Antoine Bordes, Nicolas Usunier, Alberto Garcia-Duran, Jason Weston, and Oksana Yakhnenko (2013) Advances in Neural Information Processing Systems 26, 2787–95. TransE. Section 2, Eq. 1: the margin loss over corrupted heads or tails; entity embeddings renormalized to unit L2 norm every iteration, since otherwise training could minimize the loss by inflating their norms; Section 4.2: the raw and filtered settings; Section 4.3: relations sorted into 1-to-1, 1-to-many, many-to-1, and many-to-many at an average of 1.5
- paper RotatE: Knowledge Graph Embedding by Relational Rotation in Complex Space — Zhiqing Sun, Zhi-Hong Deng, Jian-Yun Nie, and Jian Tang (2019) ICLR 2019. Definitions 1–3 (the patterns); Lemmas 1–3 state that RotatE can infer symmetry, inversion, and composition, proved in one direction in Appendices B–D; Eq. 3 and footnote 2: the distance is an L1 norm over complex moduli; Eqs. 4–6: the logistic loss with a fixed margin and self-adversarial weights; Table 2: which models support which patterns
- paper Embedding Entities and Relations for Learning and Inference in Knowledge Bases — Bishan Yang, Wen-tau Yih, Xiaodong He, Jianfeng Gao, and Li Deng (2015) ICLR 2015. Section 3.2: the bilinear score with a diagonal relation matrix (DistMult)
- paper Complex Embeddings for Simple Link Prediction — Théo Trouillon, Johannes Welbl, Sebastian Riedel, Éric Gaussier, and Guillaume Bouchard (2016) Proceedings of ICML 2016, PMLR 48: 2071–80. ComplEx, Eq. 9: the real part of a trilinear product with the object conjugated
- paper Knowledge Graph Completion via Complex Tensor Factorization — Théo Trouillon, Christopher R. Dance, Éric Gaussier, Johannes Welbl, Sebastian Riedel, and Guillaume Bouchard (2017) Journal of Machine Learning Research 18, no. 130: 1–38. Theorem 2 and Corollary 1: every real square matrix is the real part of a normal one, E W E* with E unitary and W diagonal; Corollary 3: a sign-rank bound on the dimension; Theorem 4: the multi-relational version
- paper Knowledge Graph Embedding by Translating on Hyperplanes — Zhen Wang, Jianwen Zhang, Jianlin Feng, and Zheng Chen (2014) Proceedings of AAAI 2014, 1112–19. TransH. TransE's flaws on reflexive (in today's terms, symmetric), one-to-many, many-to-one, and many-to-many relations: a reflexive relation forces r = 0 and h = t, and a many-to-one relation forces its heads to coincide
- paper SimplE Embedding for Link Prediction in Knowledge Graphs — Seyed Mehran Kazemi and David Poole (2018) Advances in Neural Information Processing Systems 31. Sections 2 and 5.1: DistMult forces every relation to be symmetric; Proposition 2 and Corollary 1: translational models are not fully expressive
- paper A Three-Way Model for Collective Learning on Multi-Relational Data — Maximilian Nickel, Volker Tresp, and Hans-Peter Kriegel (2011) Proceedings of ICML 2011, 809–16. RESCAL, the full bilinear model that DistMult restricts to diagonal matrices
- paper Group Representation Theory for Knowledge Graph Embedding — Chen Cai (2019) arXiv preprint 1909.05100, version 1; withdrawn in version 2. Section 4.3: relations as elements of a group acting on entity space, TransE as translations and RotatE as unit-modulus diagonal matrices, a symmetric relation as an element of order 2
- paper NagE: Non-Abelian Group Embedding for Knowledge Graphs — Tong Yang, Long Sha, and Pengyu Hong (2020) Proceedings of CIKM 2020, 1735–42. Section 3.2: composition can be non-commutative (a mother's father is not a father's mother), so the group should in general be non-abelian
- paper Quaternion Knowledge Graph Embeddings — Shuai Zhang, Yi Tay, Lina Yao, and Qi Liu (2019) Advances in Neural Information Processing Systems 32. QuatE: relations as rotations by unit quaternions
- paper Rotate3D: Representing Relations as Rotations in Three-Dimensional Space for Knowledge Graph Embedding — Chang Gao, Chengjie Sun, Lili Shan, Lei Lin, and Mingjiang Wang (2020) Proceedings of CIKM 2020, 385–94. The abstract: most existing methods fail to model non-commutative composition; three-dimensional rotations do (cited from the abstract; the publisher's page refused our request)
- paper Interpretable and Fair Comparison of Link Prediction or Entity Alignment Methods — Max Berrendorf, Evgeniy Faerman, Laurent Vermue, and Volker Tresp (2020) Proceedings of IEEE/WIC/ACM WI-IAT 2020, 371–74. The optimistic, pessimistic, and realistic ranks; we read their definitions in Section 2.2, Eqs. 1–3, of the longer arXiv version (2002.06914, retitled 'On the Ambiguity of Rank-Based Evaluation of Entity Alignment or Link Prediction Methods')
- paper A Re-evaluation of Knowledge Graph Completion Methods — Zhiqing Sun, Shikhar Vashishth, Soumya Sanyal, Partha Talukdar, and Yiming Yang (2020) Proceedings of ACL 2020, 5516–22. Section 4: placing the true answer at the top, bottom, or a random position among tied candidates; models that tie many candidates look better under the first
- paper You CAN Teach an Old Dog New Tricks! On Training Knowledge Graph Embeddings — Daniel Ruffinelli, Samuel Broscheit, and Rainer Gemulla (2020) ICLR 2020. With appropriate training, the performance differences between models often shrink and sometimes reverse