FixedModel
- class FixedModel(*, triples_factory: KGInfo, **_kwargs)[source]
Bases:
Model
A mock model returning fixed scores.
\[score(h, r, t) = h \cdot |\mathcal{E}| \cdot |\mathcal{R}| + r \cdot |\mathcal{E}| + t\]Initialize the model.
- Parameters:
triples_factory (KGInfo) – the (training) triples factory
_kwargs – ignored keyword-based parameters
Attributes Summary
The default strategy for optimizing the model's hyper-parameters
Methods Summary
Get the regularization term for the loss function.
score_h
(rt_batch[, heads])Forward pass using left side (head) prediction.
score_hrt
(hrt_batch, **kwargs)Forward pass.
score_r
(ht_batch[, relations])Forward pass using middle (relation) prediction.
score_t
(hr_batch[, tails])Forward pass using right side (tail) prediction.
Attributes Documentation
- hpo_default: ClassVar[Mapping[str, Any]] = {}
The default strategy for optimizing the model’s hyper-parameters
Methods Documentation
- score_h(rt_batch: Tensor, heads: Tensor | None = None, **kwargs) Tensor [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 (Tensor) – shape: (batch_size, 2), dtype: long The indices of (relation, tail) pairs.
slice_size – >0 The divisor for the scoring function when using slicing.
mode – The pass mode, which is None in the transductive setting and one of “training”, “validation”, or “testing” in the inductive setting.
heads (Tensor | None) – shape: (num_heads,) | (batch_size, num_heads) head entity indices to score against. If None, scores against all entities (from the given mode).
- Returns:
shape: (batch_size, num_heads), dtype: float For each r-t pair, the scores for all possible heads.
- Return type:
- score_hrt(hrt_batch: Tensor, **kwargs) Tensor [source]
Forward pass.
This method takes head, relation and tail of each triple and calculates the corresponding score.
- Parameters:
hrt_batch (Tensor) – shape: (batch_size, 3), dtype: long The indices of (head, relation, tail) triples.
mode – The pass mode, which is None in the transductive setting and one of “training”, “validation”, or “testing” in the inductive setting.
- Returns:
shape: (batch_size, 1), dtype: float The score for each triple.
- Return type:
- score_r(ht_batch: Tensor, relations: Tensor | None = None, **kwargs) Tensor [source]
Forward pass using middle (relation) prediction.
This method calculates the score for all possible relations for each (head, tail) pair.
- Parameters:
ht_batch (Tensor) – shape: (batch_size, 2), dtype: long The indices of (head, tail) pairs.
slice_size – >0 The divisor for the scoring function when using slicing.
mode – The pass mode, which is None in the transductive setting and one of “training”, “validation”, or “testing” in the inductive setting.
relations (Tensor | None) – shape: (num_relations,) | (batch_size, num_relations) relation indices to score against. If None, scores against all relations (from the given mode).
- Returns:
shape: (batch_size, num_real_relations), dtype: float For each h-t pair, the scores for all possible relations.
- Return type:
- score_t(hr_batch: Tensor, tails: Tensor | None = None, **kwargs) Tensor [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 (Tensor) – shape: (batch_size, 2), dtype: long The indices of (head, relation) pairs.
slice_size – >0 The divisor for the scoring function when using slicing.
mode – The pass mode, which is None in the transductive setting and one of “training”, “validation”, or “testing” in the inductive setting.
tails (Tensor | None) – shape: (num_tails,) | (batch_size, num_tails) tail entity indices to score against. If None, scores against all entities (from the given mode).
- Returns:
shape: (batch_size, num_tails), dtype: float For each h-r pair, the scores for all possible tails.
- Return type: