get_relation_prediction_df(model, head_label, tail_label, *, triples_factory, add_novelties=True, remove_known=False, testing=None)[source]

Predict relations for the given head and tail (given by label).

  • model (Model) – A PyKEEN model

  • head_label (str) – The string label for the head entity

  • tail_label (str) – The string label for the tail entity

  • triples_factory (TriplesFactory) – Training triples factory

  • add_novelties (bool) – Should the dataframe include a column denoting if the ranked relations correspond to novel triples?

  • remove_known (bool) – Should non-novel triples (those appearing in the training set) be shown with the results? On one hand, this allows you to better assess the goodness of the predictions - you want to see that the non-novel triples generally have higher scores. On the other hand, if you’re doing hypothesis generation, they may pose as a distraction. If this is set to True, then non-novel triples will be removed and the column denoting novelty will be excluded, since all remaining triples will be novel. Defaults to false.

  • testing (Optional[LongTensor]) – The mapped_triples from the testing triples factory (TriplesFactory.mapped_triples)

Return type



shape: (k, 3) A dataframe with columns based on the settings or a tensor. Contains either the k highest scoring triples, or all possible triples if k is None.

The following example shows that after you train a model on the Nations dataset, you can score all relations w.r.t a given head entity and tail entity.

>>> from pykeen.pipeline import pipeline
>>> from pykeen.models.predict import get_relation_prediction_df
>>> result = pipeline(
...     dataset='Nations',
...     model='RotatE',
... )
>>> df = get_relation_prediction_df(result.model, 'brazil', 'uk',