Knowledge Graph Scoring Functions: TransE, DistMult, ComplEx, and RotatE in TGraphX
A knowledge graph is a set of triples (h, r, t) — head entity, relation, tail entity — and the central modelling question is: given embeddings for entities and relations, how do we score whether a triple is true? Different scoring functions encode different assumptions about what relations are — translations, bilinear interactions, rotations — and each can represent some relation patterns (symmetry, antisymmetry, inversion, composition) but not others. TGraphX implements the canonical family in tgraphx/kg/models.py. This note lays out the scoring math and the evaluation protocol that makes results comparable.
For the tensor-feature angle on KGs, see Knowledge Graph Embedding with Tensor Features; for a careful library comparison, TGraphX vs PyKEEN.
Six scoring functions, one base class
All scoring models in TGraphX subclass KGScoringModel and expose a triple score. Here is the math each implements, with h, r, t the head/relation/tail embeddings:
| Model | Score f(h, r, t) |
Geometric idea | Captures |
|---|---|---|---|
TransEModel |
−‖ h + r − t ‖ |
relation as a translation | inversion, composition; not symmetry |
DistMultModel |
⟨ h, r, t ⟩ = Σᵢ hᵢ rᵢ tᵢ |
bilinear diagonal | symmetry only |
ComplExModel |
Re ⟨ h, r, t̄ ⟩ (complex) |
complex bilinear | symmetry + antisymmetry |
RotatEModel |
−‖ h ∘ r − t ‖, |rᵢ| = 1 |
relation as rotation in ℂ | symmetry, antisymmetry, inversion, composition |
RESCALModel |
hᵀ Mᵣ t (full relation matrix) |
bilinear, full matrix | rich relations; more parameters |
SimplEModel |
averaged dual embeddings | canonical Polyadic variant | handles inverse relations |
The progression is a story about expressiveness. TransE models a relation as a vector you add to the head to reach the tail; it is elegant but cannot represent a symmetric relation (if h + r ≈ t then t + r ≈ h only when r ≈ 0). DistMult uses a diagonal bilinear form, which is cheap but forces every relation to be symmetric. ComplEx moves embeddings into ℂ and takes the real part of a Hermitian product, which breaks the symmetry constraint and lets it model antisymmetric relations. RotatE treats each relation as an element-wise rotation on the unit circle in complex space, which — as argued in the RotatE paper — can express symmetry, antisymmetry, inversion, and composition simultaneously. RESCAL and SimplE round out the family with full-matrix and dual-embedding variants.
The practical lesson is that the scoring function is a modelling choice about which relation patterns your data has, not a quality ranking. If your relations are mostly symmetric, DistMult may suffice; if they compose, RotatE's inductive bias helps.
Evaluation: filtered ranking
A score is only meaningful with a fair evaluation. TGraphX uses filtered ranking in tgraphx/kg/evaluation.py (evaluate_filtered_ranking, KGEvaluator). For each test triple it ranks the true tail (and head) against all candidate entities, but first removes other known true triples from the candidate set — otherwise a model is penalised for ranking a different correct answer above the test one. The reported metrics are the standard mean reciprocal rank (MRR), mean rank, and Hits@1/3/10. Using the filtered protocol is what makes numbers comparable across papers and tools; reporting unfiltered ranks silently inflates difficulty.
Tensor-valued entities
The distinctive TGraphX angle is MultimodalKGModel in tgraphx/kg/multimodal.py, which lets entities carry structured tensor features — an image, a learned feature map — alongside their learned embedding. This connects the KG subsystem to the rest of the tensor-aware framework: an entity is not limited to a flat vector id but can fuse a modality-specific representation into its score. The capability map labels the KG subsystem Beta (tested and documented, API stable within v1.x).
Honest framing
Three qualifications. First, these are well-known scoring functions from the KG-embedding literature; TGraphX implements them faithfully rather than inventing new ones, and the value-add is the integration (filtered ranking, tensor entities, the same Graph/training tooling). Second, no model dominates — the right choice depends on your relation patterns, and you should evaluate with filtered ranking rather than assuming. Third, for large-scale, highly-tuned KG-embedding benchmarks, dedicated libraries such as PyKEEN remain the reference point; TGraphX's KG support is complementary, as discussed in the comparison article.
How to cite this idea
A safe description: TGraphX provides standard knowledge-graph scoring models (TransE, DistMult, ComplEx, RotatE, RESCAL, SimplE) with filtered head/tail ranking evaluation (MRR, Hits@k) and optional tensor-valued entity features. That is backed directly by tgraphx/kg/models.py and tgraphx/kg/evaluation.py.
Negatives are part of the model
A scoring function alone does not train a knowledge-graph model — it needs negatives. Because a knowledge graph lists only true triples, training requires corrupting triples (replacing the head or tail with a random entity) so the model has something it should score lower than the truth. TGraphX provides negative-sampling primitives — negative_sampling, structured_negative_sampling, and related helpers — for exactly this, and the quality of negatives materially affects the learned embeddings: too-easy negatives teach the model little, while harder negatives sharpen the decision boundary.
This is also why evaluation uses filtered ranking — at test time, other known-true triples must not be counted against the target. Treat the scoring function, the negative-sampling strategy, and the filtered-ranking protocol as one system. Reporting a scoring model's numbers without stating how negatives were drawn omits a detail that can change the result, so record it alongside the metric.
Related guides
- Knowledge Graph Embedding with Tensor Features
- MovieLens Knowledge-Graph Recommendation
- TGraphX vs PyKEEN: Boundaries
Conclusion
The KG scoring function encodes a hypothesis about your relations: translation (TransE), bilinear (DistMult, RESCAL), complex (ComplEx), or rotation (RotatE). TGraphX ships all of these in tgraphx/kg/models.py, evaluates them with filtered ranking, and lets entities carry tensor features. Choosing the right scorer is a modelling decision about relation patterns — and the filtered protocol is what keeps your reported numbers honest.