# MarginalDistributionBaseline¶

class MarginalDistributionBaseline(triples_factory, entity_margin=True, relation_margin=True)[source]

Score based on marginal distributions.

To predict scores for the tails, we make the following simplification of $$P(t | h, r)$$:

$P(t | h, r) \sim P(t | h) * P(t | r)$

Depending on the settings, we either set $$P(t | *) = \frac{1}{n}$$ where $$n$$ is the number of entities, or estimate them by counting occurrences in the training triples.

Note

This model cannot make use of GPU acceleration, since internally it uses scipy’s sparse matrices.

Initialize the model.

Parameters

If you set entity_margin=False and relation_margin=False, it will lead to a uniform distribution, i.e. equal scores for all entities.

Methods Summary

 score_h(rt_batch) Forward pass using left side (head) prediction. score_t(hr_batch) Forward pass using right side (tail) prediction.

Methods Documentation

score_h(rt_batch)[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.

Return type

FloatTensor

Returns

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

score_t(hr_batch)[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.

Return type

FloatTensor

Returns

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