StructuredEmbedding¶
-
class
StructuredEmbedding
(triples_factory, embedding_dim=50, scoring_fct_norm=1, loss=None, preferred_device=None, random_seed=None, regularizer=None, entity_initializer=<function xavier_uniform_>, entity_constrainer=<function normalize>)[source]¶ Bases:
pykeen.models.base.EntityEmbeddingModel
An implementation of the Structured Embedding (SE) published by [bordes2011].
SE applies role- and relation-specific projection matrices \(\textbf{M}_{r}^{h}, \textbf{M}_{r}^{t} \in \mathbb{R}^{d \times d}\) to the head and tail entities’ embeddings before computing their differences. Then, the \(l_p\) norm is applied and the result is negated such that smaller differences are considered better.
\[f(h, r, t) = - \|\textbf{M}_{r}^{h} \textbf{e}_h - \textbf{M}_{r}^{t} \textbf{e}_t\|_p\]By employing different projections for the embeddings of the head and tail entities, SE explicitly differentiates the role of an entity as either the subject or object.
Initialize SE.
- Parameters
Attributes Summary
The default strategy for optimizing the model’s hyper-parameters
Methods Summary
score_h
(rt_batch[, slice_size])Forward pass using left side (head) prediction.
score_hrt
(hrt_batch)Forward pass.
score_t
(hr_batch[, slice_size])Forward pass using right side (tail) prediction.
Attributes Documentation
-
hpo_default
: ClassVar[Mapping[str, Any]] = {'embedding_dim': {'high': 256, 'low': 16, 'q': 16, 'type': <class 'int'>}, 'scoring_fct_norm': {'high': 2, 'low': 1, 'type': <class 'int'>}}¶ The default strategy for optimizing the model’s hyper-parameters
Methods Documentation
-
score_h
(rt_batch, slice_size=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.- Return type
FloatTensor
- Returns
shape: (batch_size, num_entities), dtype: float For each r-t pair, the scores for all possible heads.
-
score_hrt
(hrt_batch)[source]¶ Forward pass.
This method takes head, relation and tail of each triple and calculates the corresponding score.
- Parameters
hrt_batch (
LongTensor
) – shape: (batch_size, 3), dtype: long The indices of (head, relation, tail) triples.- Raises
NotImplementedError – If the method was not implemented for this class.
- Return type
FloatTensor
- Returns
shape: (batch_size, 1), dtype: float The score for each triple.
-
score_t
(hr_batch, slice_size=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.- Return type
FloatTensor
- Returns
shape: (batch_size, num_entities), dtype: float For each h-r pair, the scores for all possible tails.