RESCAL

class RESCAL(triples_factory, embedding_dim=50, automatic_memory_optimization=None, loss=None, preferred_device=None, random_seed=None, regularizer=None)[source]

Bases: pykeen.models.base.EntityRelationEmbeddingModel

An implementation of RESCAL from [nickel2011].

This model represents relations as matrices and models interactions between latent features.

RESCAL is a bilinear model that models entities as vectors and relations as matrices. The relation matrices \(\textbf{W}_{r} \in \mathbb{R}^{d \times d}\) contain weights \(w_{i,j}\) that capture the amount of interaction between the \(i\)-th latent factor of \(\textbf{e}_h \in \mathbb{R}^{d}\) and the \(j\)-th latent factor of \(\textbf{e}_t \in \mathbb{R}^{d}\).

Thus, the plausibility score of \((h,r,t) \in \mathbb{K}\) is given by:

\[f(h,r,t) = \textbf{e}_h^{T} \textbf{W}_{r} \textbf{e}_t = \sum_{i=1}^{d}\sum_{j=1}^{d} w_{ij}^{(r)} (\textbf{e}_h)_{i} (\textbf{e}_t)_{j}\]

Initialize RESCAL.

Parameters

embedding_dim (int) – The entity embedding dimension \(d\). Is usually \(d \in [50, 300]\).

See also

Attributes Summary

hpo_default

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

regularizer_default_kwargs

The LP settings used by [nickel2011] for for RESCAL

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

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

The LP settings used by [nickel2011] for for RESCAL

Methods Documentation

score_h(rt_batch)[source]

Forward pass using left side (head) prediction.

Return type

FloatTensor

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.