SimplE

class SimplE(triples_factory, embedding_dim=200, automatic_memory_optimization=None, loss=None, preferred_device=None, random_seed=None, regularizer=None, clamp_score=None)[source]

Bases: pykeen.models.base.EntityRelationEmbeddingModel

An implementation of SimplE [kazemi2018].

SimplE is an extension of canonical polyadic (CP), an early tensor factorization approach in which each entity \(e \in \mathcal{E}\) is represented by two vectors \(\textbf{h}_e, \textbf{t}_e \in \mathbb{R}^d\) and each relation by a single vector \(\textbf{r}_r \in \mathbb{R}^d\). Depending whether an entity participates in a triple as the head or tail entity, either \(\textbf{h}\) or \(\textbf{t}\) is used. Both entity representations are learned independently, i.e. observing a triple \((h,r,t)\), the method only updates \(\textbf{h}_h\) and \(\textbf{t}_t\). In contrast to CP, SimplE introduces for each relation \(\textbf{r}_r\) the inverse relation \(\textbf{r'}_r\), and formulates its the interaction model based on both:

\[f(h,r,t) = \frac{1}{2}\left(\left\langle\textbf{h}_h, \textbf{r}_r, \textbf{t}_t\right\rangle + \left\langle\textbf{h}_t, \textbf{r'}_r, \textbf{t}_h\right\rangle\right)\]

Therefore, for each triple \((h,r,t) \in \mathbb{K}\), both \(\textbf{h}_h\) and \(\textbf{h}_t\) as well as \(\textbf{t}_h\) and \(\textbf{t}_t\) are updated.

See also

Initialize the entity embedding model.

Parameters

relation_dim – The relation embedding dimensionality. If not given, defaults to same size as entity embedding dimension.

See also

Constructor of the base class pykeen.models.Model

See also

Constructor of the base class pykeen.models.EntityEmbeddingModel

Attributes Summary

hpo_default

The default strategy for optimizing the model’s hyper-parameters

loss_default_kwargs

The default parameters for the default loss function class

regularizer_default_kwargs

The power sum settings used by [trouillon2016] for SimplE

Methods Summary

score_h(rt_batch)

Forward pass using left side (head) prediction.

score_hrt(hrt_batch)

Forward pass.

score_t(hr_batch)

Forward pass using right side (tail) prediction.

Attributes Documentation

hpo_default: ClassVar[Mapping[str, Any]] = {'embedding_dim': {'high': 350, 'low': 50, 'q': 25, 'type': <class 'int'>}}

The default strategy for optimizing the model’s hyper-parameters

loss_default_kwargs: ClassVar[Optional[Mapping[str, Any]]] = {}

The default parameters for the default loss function class

regularizer_default_kwargs: ClassVar[Optional[Mapping[str, Any]]] = {'normalize': True, 'p': 2.0, 'weight': 20}

The power sum settings used by [trouillon2016] for SimplE

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_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)[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.