besskge.scoring.MatrixDecompositionScoreFunction
- class besskge.scoring.MatrixDecompositionScoreFunction(negative_sample_sharing)[source]
Base class for matrix-decomposition scoring functions.
Initialize matrix-decomposition scoring function.
- Parameters:
negative_sample_sharing (
bool
) – seeBaseScoreFunction
- broadcasted_dot_product(v1, v2)[source]
Broadcasted dot product of queries against sets of entities.
For each query and candidate, computes the dot product of the embeddings.
- Parameters:
- Return type:
- Returns:
shape: (batch_size, B * n_neg) if
BaseScoreFunction.negative_sample_sharing
else (batch_size, n_neg)
- forward(head_emb, relation_id, tail_emb)
- abstract score_heads(head_emb, relation_id, tail_emb)
Score sets of head entities against fixed (r,t) queries.
- Parameters:
- Return type:
- Returns:
shape: (batch_size, B * n_heads) if
BaseScoreFunction.negative_sample_sharing
else (batch_size, n_heads). Scores of broadcasted triples.
- abstract score_tails(head_emb, relation_id, tail_emb)
Score sets of tail entities against fixed (h,r) queries.
- Parameters:
- Return type:
- Returns:
shape: (batch_size, B * n_tails) if
BaseScoreFunction.negative_sample_sharing
else (batch_size, n_tails) Scores of broadcasted triples.
- abstract score_triple(head_emb, relation_id, tail_emb)
Score a batch of (h,r,t) triples.
- Parameters:
- Return type:
- Returns:
shape: (batch_size,) Scores of a batch of triples.