Skip to content
mlmentorship

Knowledge-graph embeddings

Knowledge-graph embeddings turn link prediction into vector scoring. Compare TransE, DistMult, ComplEx, and RotatE by the relation patterns they can represent.

Published · 7 min read ·Role-specific ·Intermediate
Reading depth

Knowledge-graph embeddings score typed triples, but the scoring operator determines which relation distinctions are even possible.

Summary

Ada is Ben’s parent; the reverse relation is false in this example. Can swapping the entity embeddings change the proposed score? If not, increasing width cannot teach this score the missing direction.

The task: knowledge-graph completion

Represent a fact as head, relation and tail, , with corresponding learned vectors. Score candidate heads or tails under a stated higher-is-better convention. An unobserved triple is not necessarily false; corrupted-entity negatives need a declared validity policy. Architecture, training loss and ranking evaluation are separate choices.

The four models to know

TransE: translation

Use . Under exact zero residual, two true tails require . Likewise, two reversed zero-residual facts require and collapse their entity embeddings. These are exact-constraint limits; approximate ranking need not satisfy those equalities.

DistMult: bilinear diagonal

For real scalars , both scores are six. Commutativity holds in every coordinate, so adding dimensions preserves the equality.

ComplEx: complex bilinear

Use complex embeddings and . Choose , with . Forward score is . Reverse score is .

Conjugation changes which factors contribute imaginary signs. It permits this directed distinction; it does not guarantee learning the correct facts.

Learning objective

Complex conjugation lets the reversed relation receive a different score

Complex conjugation makes relation direction matterWith h=i, r=i, and t=1, the forward ComplEx score is -1. Swapping head and tail gives +1 for the same relation.Complex multiplication turns thereal-axis endpointForward: i times i times 1Real part -1Swap: 1 times i times -iReal part 1
Derivation

DistMult: swapping is invisible

Real multiplication commutes in every dimension.

DistMult gives a parent relation and its reversal equal scores A solid arrow marks the true triple Ada parent of Ben, and a dashed arrow marks the false reversed triple Ben parent of Ada. DistMult multiplies the same three real values after swapping the entities, so both sums are equal and the model cannot rank the true direction above the false one. Ada Ben parent_of · true parent_of · false score(A, r, B) = Σ Aᵢ rᵢ Bᵢ score(B, r, A) = Σ Bᵢ rᵢ Aᵢ forced equal true cannot outrank reverse

ComplEx: conjugation preserves direction

Swapping entities moves the conjugate to the other vector.

ComplEx can give a parent relation and its reversal different scores The same solid true arrow and dashed false reverse arrow connect Ada and Ben. In ComplEx, swapping the entities changes which entity vector is complex-conjugated. The two expressions are therefore not forced to match, allowing the model to score Ada parent of Ben above Ben parent of Ada. Ada Ben parent_of · true parent_of · false score(A, r, B) = Re Σ Aᵢ rᵢ B̄ᵢ score(B, r, A) = Re Σ Bᵢ rᵢ Āᵢ free to differ true can outrank reverse
swap Ada and Ben. DistMult only reorders real factors, forcing equal scores. ComplEx changes which entity is conjugated, permitting unequal scores. The worked scalar example gives 1 versus -1. Original schematic checked against ComplEx and RotatE.
Check: Which algebraic operation allows the complex model's reversed edge to receive a different score?
Read it this way: With h=i, r=i, and t=1, the forward ComplEx score is -1. Swapping head and tail gives +1 for the same relation.
Why does conjugating the swapped head reverse the rotation?

RotatE: rotation in complex space

Use , with unit-modulus relation coordinates. Multiplying by gives with zero residual; inverse rotation maps it back to one. The inverse is coordinatewise conjugation; composing exact rotations multiplies their coordinates.

Which patterns each model expresses

OperatorDiscriminating testScope
TransEdistinct tails force conflicting translationsexact zero residual
DistMulthead/tail swap leaves score unchangedevery shared-entity real score
ComplExconjugated swap can change real scorecapacity, not learned accuracy
RotatEconjugate inverse and componentwise compositionunit-modulus, exact rotations

Pattern claims depend on their formal definitions and residual assumptions, not a universal expressivity ordering.

Change the required information

Require direction

New task: replace undirected similarity with parent_of.

Picture and change: reject the forced-symmetric score or use a directional operator with explicitly distinct entity roles.

Check: duplicating the DistMult coordinate gives twelve in both directions, still tied. The one-coordinate ComplEx example gives one and minus one.

Use when: reversal must change the ranking; test held-out directed facts.

Add an unseen entity

New task: score a new title with metadata but no trained ID vector.

Picture and change: supply an explicit feature/neighbor encoder or fallback, then evaluate unseen-entity generalization.

Check: a toy feature map maps to one. It can enter the example’s forward score, which becomes one. That arithmetic supplies an embedding, not evidence that the asserted fact is true.

Use when: deployment must cover entities absent from the transductive training IDs.

Reconstruct the limitation

Does algebraic capacity prove that a missing link is correct?

Reasoned answer

No. Observation coverage, negative validity, split leakage, training evidence and optimization remain separate requirements. Changing width cannot remove DistMult’s forced equality; changing its operator can.

Where this fits in recsys / RAG

Catalog graphs can supply typed side-information alongside collaborative features. Relational GNNs add neighborhood computation; random-walk embeddings learn another neighborhood objective. Neither is a universal replacement or winner. Structured RAG inputs can also contain stale or false triples; graph grounding does not establish truth.

What an interviewer expects you to say

Define the fact population, candidate set, negative construction and temporal/train/test split. Evaluate filtered MRR or Hits@K under a declared known-positive filtering protocol and tie policy. State whether encoder inputs can expose future or test information.

Common confusions

Classification or ranking losses can train a triple score; the evaluation task determines the appropriate metrics. Unobserved does not mean negative. ID-only embeddings do not provide an unseen entity’s representation. Relation-pattern theorems use specific definitions; approximate learned scores need separate empirical evaluation.


Related: Graph neural networks, Word embeddings, Negative sampling strategies, Matrix factorization for recsys, Content-based filtering.