SoftInverseTripleBaseline

class SoftInverseTripleBaseline(triples_factory, threshold=None)[source]

Bases: EvaluationOnlyModel

Score based on relation similarity.

Initialize the model.

Parameters:
  • triples_factory (CoreTriplesFactory) – the (training) triples factory

  • threshold (Optional[float]) – the threshold applied to the similarity matrix, cf. get_relation_similarity()

Methods Summary

score_h(rt_batch, **kwargs)

Forward pass using left side (head) prediction.

score_t(hr_batch, **kwargs)

Forward pass using right side (tail) prediction.

Methods Documentation

score_h(rt_batch, **kwargs)[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 – >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 – shape: (num_heads,) | (batch_size, num_heads) head entity indices to score against. If None, scores against all entities (from the given mode).

Return type:

FloatTensor

Returns:

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

score_t(hr_batch, **kwargs)[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 – >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 – shape: (num_tails,) | (batch_size, num_tails) tail entity indices to score against. If None, scores against all entities (from the given mode).

Return type:

FloatTensor

Returns:

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