get_tail_prediction_df

get_tail_prediction_df(model, triples_factory, head_label, relation_label, *, tails=None, **kwargs)[source]

Predict tails for the given head and relation (given by label).

Parameters
  • model (Model) – A PyKEEN model

  • triples_factory (TriplesFactory) – the training triples factory

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

  • relation_label (str) – the string label for the relation

  • tails (Optional[Sequence[str]]) – restrict tail prediction to the given entities

  • kwargs – additional keyword-based parameters passed to get_prediction_df().

Return type

DataFrame

Returns

shape: (k, 3) A dataframe for tail predictions. 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 entities w.r.t. a given head entity and relation.

>>> from pykeen.pipeline import pipeline
>>> from pykeen.models.predict import get_tail_prediction_df
>>> result = pipeline(
...     dataset='Nations',
...     model='RotatE',
... )
>>> df = get_tail_prediction_df(result.model, 'brazil', 'accusation', triples_factory=result.training)

The optional tails parameter can be used to restrict prediction to a subset of entities, e.g. >>> df = get_tail_prediction_df( … result.model, … ‘brazil’, … ‘accusation’, … triples_factory=result.training, … tails=[“burma”, “china”, “india”, “indonesia”], … )