_OldAbstractModel

class _OldAbstractModel(*, triples_factory, regularizer=None, **kwargs)[source]

Bases: pykeen.models.base.Model, abc.ABC

A base module for PyKEEN 1.0-style KGE models.

Initialize the module.

Parameters
  • triples_factory (KGInfo) – The triples factory facilitates access to the dataset.

  • regularizer (Optional[Regularizer]) – A regularizer to use for training.

  • kwargs – additional keyword-based arguments passed to Model.__init__

Attributes Summary

can_slice_h

can_slice_r

can_slice_t

regularizer_default

The default regularizer class

regularizer_default_kwargs

The default parameters for the default regularizer class

Methods Summary

collect_regularization_term()

Get the regularization term for the loss function.

post_forward_pass()

Run after calculating the forward loss.

post_parameter_update()

Has to be called after each parameter update.

regularize_if_necessary(*tensors)

Update the regularizer's term given some tensors, if regularization is requested.

score_h(rt_batch, *[, slice_size, mode])

Forward pass using left side (head) prediction.

score_r(ht_batch, *[, slice_size, mode])

Forward pass using middle (relation) prediction.

score_t(hr_batch, *[, slice_size, mode])

Forward pass using right side (tail) prediction.

Attributes Documentation

can_slice_h: ClassVar[bool] = False
can_slice_r: ClassVar[bool] = False
can_slice_t: ClassVar[bool] = False
regularizer_default: ClassVar[Optional[Type[Regularizer]]] = None

The default regularizer class

regularizer_default_kwargs: ClassVar[Optional[Mapping[str, Any]]] = None

The default parameters for the default regularizer class

Methods Documentation

collect_regularization_term()[source]

Get the regularization term for the loss function.

Return type

FloatTensor

post_forward_pass()[source]

Run after calculating the forward loss.

post_parameter_update()[source]

Has to be called after each parameter update.

Return type

None

regularize_if_necessary(*tensors)[source]

Update the regularizer’s term given some tensors, if regularization is requested.

Parameters

tensors (FloatTensor) – The tensors that should be passed to the regularizer to update its term.

Return type

None

score_h(rt_batch, *, slice_size=None, mode=None)[source]

Forward pass using left side (head) prediction.

This method calculates the score for all possible heads for each (relation, tail) pair.

Parameters
  • rt_batch (LongTensor) – shape: (batch_size, 2), dtype: long The indices of (relation, tail) pairs.

  • slice_size (Optional[int]) – >0 The divisor for the scoring function when using slicing.

  • mode (Optional[Literal[‘training’, ‘validation’, ‘testing’]]) – The pass mode, which is None in the transductive setting and one of “training”, “validation”, or “testing” in the inductive setting.

Return type

FloatTensor

Returns

shape: (batch_size, num_entities), dtype: float For each r-t pair, the scores for all possible heads.

score_r(ht_batch, *, slice_size=None, mode=None)[source]

Forward pass using middle (relation) prediction.

This method calculates the score for all possible relations for each (head, tail) pair.

Parameters
  • ht_batch (LongTensor) – shape: (batch_size, 2), dtype: long The indices of (head, tail) pairs.

  • slice_size (Optional[int]) – >0 The divisor for the scoring function when using slicing.

  • mode (Optional[Literal[‘training’, ‘validation’, ‘testing’]]) – The pass mode, which is None in the transductive setting and one of “training”, “validation”, or “testing” in the inductive setting.

Return type

FloatTensor

Returns

shape: (batch_size, num_relations), dtype: float For each h-t pair, the scores for all possible relations.

score_t(hr_batch, *, slice_size=None, mode=None)[source]

Forward pass using right side (tail) prediction.

This method calculates the score for all possible tails for each (head, relation) pair.

Parameters
  • hr_batch (LongTensor) – shape: (batch_size, 2), dtype: long The indices of (head, relation) pairs.

  • slice_size (Optional[int]) – >0 The divisor for the scoring function when using slicing.

  • mode (Optional[Literal[‘training’, ‘validation’, ‘testing’]]) – The pass mode, which is None in the transductive setting and one of “training”, “validation”, or “testing” in the inductive setting.

Return type

FloatTensor

Returns

shape: (batch_size, num_entities), dtype: float For each h-r pair, the scores for all possible tails.