Models

A knowledge graph embedding model is capable of computing real-valued scores representing the plausibility of a triple \((h,r,t) \in \mathbb{K}\), where a larger score indicates a higher plausibility. The interpretation of the score value is model-dependent, and usually it cannot be directly interpreted as a probability.

In PyKEEN, the API of a model is defined in Model, where the scoring function is exposed as Model.score_hrt(), which can be used to compute plausability scores for (a batch of) triples. In addition, the Model class also offers additional scoring methods, which can be used to (efficiently) compute scores for a large number of triples sharing some parts, e.g., to compute scores for triples (h, r, e) for a given (h, r) pair and all available entities \(e \in \mathcal{E}\).

Note

The implementations of the knowledge graph embedding models provided here all operate on entity / relation indices rather than string representations, cf. here.

On top of these scoring methods, there are also corresponding prediction methods, e.g., Model.predict_hrt(). These methods extend the scoring ones, by ensuring the model is in evaluation mode, cf. torch.nn.Module.eval(), and optionally applying a sigmoid activation on the scores to ensure a value range of \([0, 1]\).

Warning

Depending on the model at hand, directly applying sigmoid might not always be sensible. For instance, distance-based interaction functions, such as pykeen.nn.modules.TransEInteraction, result in non-positive scores (since they use the negative distance as scoring function), and thus the output of the sigmoid only covers the interval \([0.5, 1]\).

Most models derive from ERModel, which is a generic implementation of a knowledge graph embedding model. It combines a variable number of representations for entities and relations, cf. pykeen.nn.representation.Representation, and an interaction function, cf. pykeen.nn.modules.Interaction. The representation modules convert integer entity or relation indices to numeric representations, e.g., vectors. The interaction function takes the representations of the head entities, relations and tail entities as input and computes a scalar plausability score for triples.

Note

An in-depth discussion of representation modules can be found in the corresponding tutorial.

Note

The specific models from this module, e.g., RESCAL, package given specific entity and relation representations with an interaction function. For more flexible combinations, consider using ERModel directly.

Functions

make_model(dimensions, interaction[, ...])

Build a model from an interaction class hint (name or class).

make_model_cls(dimensions, interaction[, ...])

Build a model class from an interaction class hint (name or class).

Classes

Model(*, triples_factory[, loss, ...])

A base module for KGE models.

ERModel(*, triples_factory, interaction[, ...])

A commonly useful base for KGEMs using embeddings and interaction modules.

InductiveERModel(*, triples_factory[, ...])

A base class for inductive models.

LiteralModel(triples_factory, interaction[, ...])

Base class for models with entity literals that uses combinations from pykeen.nn.combinations.

EvaluationOnlyModel(triples_factory)

A model which only implements the methods used for evaluation.

AutoSF([embedding_dim, num_components, ...])

An implementation of AutoSF from [zhang2020].

BoxE(*[, embedding_dim, tanh_map, p, ...])

An implementation of BoxE from [abboud2020].

CompGCN(*, triples_factory[, embedding_dim, ...])

An implementation of CompGCN from [vashishth2020].

ComplEx(*[, embedding_dim, ...])

An implementation of ComplEx [trouillon2016].

ComplExLiteral(triples_factory[, ...])

An implementation of the LiteralE model with the ComplEx interaction from [kristiadi2018].

ConvE(triples_factory[, input_channels, ...])

An implementation of ConvE from [dettmers2018].

ConvKB(*[, embedding_dim, ...])

An implementation of ConvKB from [nguyen2018].

CP([embedding_dim, rank, ...])

An implementation of CP as described in [lacroix2018] based on [hitchcock1927].

CrossE(*[, embedding_dim, ...])

An implementation of CrossE from [zhang2019b].

DistMA([embedding_dim, entity_initializer, ...])

An implementation of DistMA from [shi2019].

DistMult(*[, embedding_dim, ...])

An implementation of DistMult from [yang2014].

DistMultLiteral(triples_factory[, ...])

An implementation of the LiteralE model with the DistMult interaction from [kristiadi2018].

DistMultLiteralGated(triples_factory[, ...])

An implementation of the LiteralE model with thhe Gated DistMult interaction from [kristiadi2018].

ERMLP(*[, embedding_dim, hidden_dim, ...])

An implementation of ERMLP from [dong2014].

ERMLPE(*[, embedding_dim, hidden_dim, ...])

An extension of pykeen.models.ERMLP proposed by [sharifzadeh2019].

HolE(*[, embedding_dim, entity_initializer, ...])

An implementation of HolE [nickel2016].

KG2E(*[, embedding_dim, dist_similarity, ...])

An implementation of KG2E from [he2015].

FixedModel(*, triples_factory, **_kwargs)

A mock model returning fixed scores.

MuRE(*[, embedding_dim, p, power_norm, ...])

An implementation of MuRE from [balazevic2019b].

NodePiece(*, triples_factory[, num_tokens, ...])

A wrapper which combines an interaction function with NodePiece entity representations from [galkin2021].

NTN(*[, embedding_dim, num_slices, ...])

An implementation of NTN from [socher2013].

PairRE([embedding_dim, p, power_norm, ...])

An implementation of PairRE from [chao2020].

ProjE(*[, embedding_dim, ...])

An implementation of ProjE from [shi2017].

QuatE(*[, embedding_dim, ...])

An implementation of QuatE from [zhang2019].

RESCAL(*[, embedding_dim, ...])

An implementation of RESCAL from [nickel2011].

RGCN(*, triples_factory[, embedding_dim, ...])

An implementation of R-GCN from [schlichtkrull2018].

RotatE(*[, embedding_dim, ...])

An implementation of RotatE from [sun2019].

SimplE(*[, embedding_dim, clamp_score, ...])

An implementation of SimplE [kazemi2018].

SE(*[, embedding_dim, scoring_fct_norm, ...])

An implementation of the Structured Embedding (SE) published by [bordes2011].

TorusE([embedding_dim, p, power_norm, ...])

An implementation of TorusE from [ebisu2018].

TransD(*[, embedding_dim, relation_dim, ...])

An implementation of TransD from [ji2015].

TransE(*[, embedding_dim, scoring_fct_norm, ...])

An implementation of TransE [bordes2013].

TransF([embedding_dim, entity_initializer, ...])

An implementation of TransF from [feng2016].

TransH(*[, embedding_dim, scoring_fct_norm, ...])

An implementation of TransH [wang2014].

TransR(*[, embedding_dim, relation_dim, ...])

An implementation of TransR from [lin2015].

TuckER(*[, embedding_dim, relation_dim, ...])

An implementation of TuckEr from [balazevic2019].

UM(*[, embedding_dim, scoring_fct_norm, ...])

An implementation of the Unstructured Model (UM) published by [bordes2014].

InductiveNodePiece(*, triples_factory, ...)

A wrapper which combines an interaction function with NodePiece entity representations from [galkin2021].

InductiveNodePieceGNN(*[, gnn_encoder])

Inductive NodePiece with a GNN encoder on top.

SoftInverseTripleBaseline(triples_factory[, ...])

Score based on relation similarity.

MarginalDistributionBaseline(triples_factory)

Score based on marginal distributions.

CooccurrenceFilteredModel(*, triples_factory)

A model which filters predictions by co-occurence.

Class Inheritance Diagram

Inheritance diagram of pykeen.models.base.Model, pykeen.models.nbase.ERModel, pykeen.models.inductive.base.InductiveERModel, pykeen.models.multimodal.base.LiteralModel, pykeen.models.baseline.models.EvaluationOnlyModel, pykeen.models.unimodal.auto_sf.AutoSF, pykeen.models.unimodal.boxe.BoxE, pykeen.models.unimodal.compgcn.CompGCN, pykeen.models.unimodal.complex.ComplEx, pykeen.models.multimodal.complex_literal.ComplExLiteral, pykeen.models.unimodal.conv_e.ConvE, pykeen.models.unimodal.conv_kb.ConvKB, pykeen.models.unimodal.cp.CP, pykeen.models.unimodal.crosse.CrossE, pykeen.models.unimodal.distma.DistMA, pykeen.models.unimodal.distmult.DistMult, pykeen.models.multimodal.distmult_literal.DistMultLiteral, pykeen.models.multimodal.distmult_literal_gated.DistMultLiteralGated, pykeen.models.unimodal.ermlp.ERMLP, pykeen.models.unimodal.ermlpe.ERMLPE, pykeen.models.unimodal.hole.HolE, pykeen.models.unimodal.kg2e.KG2E, pykeen.models.mocks.FixedModel, pykeen.models.unimodal.mure.MuRE, pykeen.models.unimodal.node_piece.NodePiece, pykeen.models.unimodal.ntn.NTN, pykeen.models.unimodal.pair_re.PairRE, pykeen.models.unimodal.proj_e.ProjE, pykeen.models.unimodal.quate.QuatE, pykeen.models.unimodal.rescal.RESCAL, pykeen.models.unimodal.rgcn.RGCN, pykeen.models.unimodal.rotate.RotatE, pykeen.models.unimodal.simple.SimplE, pykeen.models.unimodal.structured_embedding.SE, pykeen.models.unimodal.toruse.TorusE, pykeen.models.unimodal.trans_d.TransD, pykeen.models.unimodal.trans_e.TransE, pykeen.models.unimodal.trans_f.TransF, pykeen.models.unimodal.trans_h.TransH, pykeen.models.unimodal.trans_r.TransR, pykeen.models.unimodal.tucker.TuckER, pykeen.models.unimodal.unstructured_model.UM, pykeen.models.inductive.inductive_nodepiece.InductiveNodePiece, pykeen.models.inductive.inductive_nodepiece_gnn.InductiveNodePieceGNN, pykeen.models.baseline.models.SoftInverseTripleBaseline, pykeen.models.baseline.models.MarginalDistributionBaseline, pykeen.models.meta.filtered.CooccurrenceFilteredModel