_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 (
CoreTriplesFactory
) – 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
The default regularizer class
The default parameters for the default regularizer class
Methods Summary
Get the regularization term for the loss function.
Run after calculating the forward loss.
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
- 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
- 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
- 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.