PyKEEN (Python KnowlEdge EmbeddiNgs) is a Python package designed to train and evaluate knowledge graph embedding models (incorporating multi-modal information).
Installation • Quickstart • Datasets (37) • Inductive Datasets (5) • Models (40) • Support • Citation
The latest stable version of PyKEEN requires Python 3.10+. It can be downloaded and installed from PyPI with:
pip install pykeen
The latest version of PyKEEN can be installed directly from the source code on GitHub with:
pip install git+https://github.com/pykeen/pykeen.git
More information about installation (e.g., development mode, Windows installation, Colab, Kaggle, extras) can be found in the installation documentation.
This example shows how to train a model on a dataset and test on another dataset.
The fastest way to get up and running is to use the pipeline function. It provides a high-level entry into the extensible functionality of this package. The following example shows how to train and evaluate the TransE model on the Nations dataset. By default, the training loop uses the stochastic local closed world assumption (sLCWA) training approach and evaluates with rank-based evaluation.
from pykeen.pipeline import pipeline result = pipeline( model="TransE", dataset="nations", )
The results are returned in an instance of the PipelineResult dataclass that has attributes for the trained model, the training loop, the evaluation, and more. See the tutorials on using your own dataset, understanding the evaluation, and making novel link predictions.
PyKEEN is extensible such that:
- Each model has the same API, so anything from
pykeen.modelscan be dropped in - Each training loop has the same API, so
pykeen.training.LCWATrainingLoopcan be dropped in - Triples factories can be generated by the user with
from pykeen.triples.TriplesFactory
The full documentation can be found at https://pykeen.readthedocs.io.
Implementation
Below are the models, datasets, training modes, evaluators, and metrics implemented
in pykeen.
Datasets
The following 37 datasets are built in to PyKEEN. The citation for each dataset corresponds to either the paper describing the dataset, the first paper published using the dataset with knowledge graph embedding models, or the URL for the dataset if neither of the first two are available. If you want to use a custom dataset, see the Bring Your Own Dataset tutorial. If you have a suggestion for another dataset to include in PyKEEN, please let us know here.
Inductive Datasets
The following 5 inductive datasets are built in to PyKEEN.
| Name | Documentation | Citation |
|---|---|---|
| ILPC2022 Large | pykeen.datasets.ILPC2022Large |
Galkin et al., 2022 |
| ILPC2022 Small | pykeen.datasets.ILPC2022Small |
Galkin et al., 2022 |
| FB15k-237 | pykeen.datasets.InductiveFB15k237 |
Teru et al., 2020 |
| NELL | pykeen.datasets.InductiveNELL |
Teru et al., 2020 |
| WordNet-18 (RR) | pykeen.datasets.InductiveWN18RR |
Teru et al., 2020 |
Representations
The following 22 representations are implemented by PyKEEN.
Interactions
The following 34 interactions are implemented by PyKEEN.
Models
The following 40 models are implemented by PyKEEN.
Losses
The following 15 losses are implemented by PyKEEN.
| Name | Reference | Description |
|---|---|---|
| Adversarially weighted binary cross entropy (with logits) | pykeen.losses.AdversarialBCEWithLogitsLoss |
An adversarially weighted BCE loss. |
| Binary cross entropy (after sigmoid) | pykeen.losses.BCEAfterSigmoidLoss |
The numerically unstable version of explicit Sigmoid + BCE loss. |
| Binary cross entropy (with logits) | pykeen.losses.BCEWithLogitsLoss |
The binary cross entropy loss. |
| Cross entropy | pykeen.losses.CrossEntropyLoss |
The cross entropy loss that evaluates the cross entropy after softmax output. |
| Double Margin | pykeen.losses.DoubleMarginLoss |
A limit-based scoring loss, with separate margins for positive and negative elements from [sun2018]_. |
| Focal | pykeen.losses.FocalLoss |
The focal loss proposed by [lin2018]_. |
| InfoNCE loss with additive margin | pykeen.losses.InfoNCELoss |
The InfoNCE loss with additive margin proposed by [wang2022]_. |
| Margin ranking | pykeen.losses.MarginRankingLoss |
The pairwise hinge loss (i.e., margin ranking loss). |
| Mean squared error | pykeen.losses.MSELoss |
The mean squared error loss. |
| Self-adversarial negative sampling | pykeen.losses.NSSALoss |
The self-adversarial negative sampling loss function proposed by [sun2019]_. |
| Pairwise logistic | pykeen.losses.PairwiseLogisticLoss |
The pairwise logistic loss. |
| Pointwise Hinge | pykeen.losses.PointwiseHingeLoss |
The pointwise hinge loss. |
| Soft margin ranking | pykeen.losses.SoftMarginRankingLoss |
The soft pairwise hinge loss (i.e., soft margin ranking loss). |
| Softplus | pykeen.losses.SoftplusLoss |
The pointwise logistic loss (i.e., softplus loss). |
| Soft Pointwise Hinge | pykeen.losses.SoftPointwiseHingeLoss |
The soft pointwise hinge loss. |
Regularizers
The following 6 regularizers are implemented by PyKEEN.
| Name | Reference | Description |
|---|---|---|
| combined | pykeen.regularizers.CombinedRegularizer |
A convex combination of regularizers. |
| lp | pykeen.regularizers.LpRegularizer |
A simple L_p norm based regularizer. |
| no | pykeen.regularizers.NoRegularizer |
A regularizer which does not perform any regularization. |
| normlimit | pykeen.regularizers.NormLimitRegularizer |
A regularizer which formulates a soft constraint on a maximum norm. |
| orthogonality | pykeen.regularizers.OrthogonalityRegularizer |
A regularizer for the soft orthogonality constraints from [wang2014]_. |
| powersum | pykeen.regularizers.PowerSumRegularizer |
A simple x^p based regularizer. |
Training Loops
The following 3 training loops are implemented in PyKEEN.
| Name | Reference | Description |
|---|---|---|
| lcwa | pykeen.training.LCWATrainingLoop |
A training loop that is based upon the local closed world assumption (LCWA). |
| slcwa | pykeen.training.SLCWATrainingLoop |
A training loop that uses the stochastic local closed world assumption training approach. |
| symmetriclcwa | pykeen.training.SymmetricLCWATrainingLoop |
A "symmetric" LCWA scoring heads and tails at once. |
Negative Samplers
The following 3 negative samplers are implemented in PyKEEN.
| Name | Reference | Description |
|---|---|---|
| basic | pykeen.sampling.BasicNegativeSampler |
A basic negative sampler. |
| bernoulli | pykeen.sampling.BernoulliNegativeSampler |
An implementation of the Bernoulli negative sampling approach proposed by [wang2014]_. |
| pseudotyped | pykeen.sampling.PseudoTypedNegativeSampler |
A sampler that accounts for which entities co-occur with a relation. |
Stoppers
The following 2 stoppers are implemented in PyKEEN.
| Name | Reference | Description |
|---|---|---|
| early | pykeen.stoppers.EarlyStopper |
A harness for early stopping. |
| nop | pykeen.stoppers.NopStopper |
A stopper that does nothing. |
Evaluators
The following 5 evaluators are implemented in PyKEEN.
| Name | Reference | Description |
|---|---|---|
| classification | pykeen.evaluation.ClassificationEvaluator |
An evaluator that uses a classification metrics. |
| macrorankbased | pykeen.evaluation.MacroRankBasedEvaluator |
Macro-average rank-based evaluation. |
| ogb | pykeen.evaluation.OGBEvaluator |
A sampled, rank-based evaluator that applies a custom OGB evaluation. |
| rankbased | pykeen.evaluation.RankBasedEvaluator |
A rank-based evaluator for KGE models. |
| sampledrankbased | pykeen.evaluation.SampledRankBasedEvaluator |
A rank-based evaluator using sampled negatives instead of all negatives. |
Metrics
The following 40 metrics are implemented in PyKEEN.
| Name | Interval | Direction | Description | Type |
|---|---|---|---|---|
| Accuracy |
