HolE

class HolE(*, embedding_dim=200, entity_initializer=<function xavier_uniform_>, entity_constrainer=<function clamp_norm>, entity_constrainer_kwargs=None, relation_initializer=<function xavier_uniform_>, **kwargs)[source]

Bases: pykeen.models.base.EntityRelationEmbeddingModel

An implementation of HolE [nickel2016].

Holographic embeddings (HolE) make use of the circular correlation operator to compute interactions between latent features of entities and relations:

\[f(h,r,t) = \sigma(\textbf{r}^{T}(\textbf{h} \star \textbf{t}))\]

where the circular correlation \(\star: \mathbb{R}^d \times \mathbb{R}^d \rightarrow \mathbb{R}^d\) is defined as:

\[[\textbf{a} \star \textbf{b}]_i = \sum_{k=0}^{d-1} \textbf{a}_{k} * \textbf{b}_{(i+k)\ mod \ d}\]

By using the correlation operator each component \([\textbf{h} \star \textbf{t}]_i\) represents a sum over a fixed partition over pairwise interactions. This enables the model to put semantic similar interactions into the same partition and share weights through \(\textbf{r}\). Similarly irrelevant interactions of features could also be placed into the same partition which could be assigned a small weight in \(\textbf{r}\).

Initialize the model.

Attributes Summary

entity_constrainer_default_kwargs

The default settings for the entity constrainer

hpo_default

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

Methods Summary

interaction_function(h, r, t)

Evaluate the interaction function for given embeddings.

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

entity_constrainer_default_kwargs = {'dim': -1, 'maxnorm': 1.0, 'p': 2}

The default settings for the entity constrainer

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

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

Methods Documentation

static interaction_function(h, r, t)[source]

Evaluate the interaction function for given embeddings.

The embeddings have to be in a broadcastable shape.

Parameters
  • h (FloatTensor) – shape: (batch_size, num_entities, d) Head embeddings.

  • r (FloatTensor) – shape: (batch_size, num_entities, d) Relation embeddings.

  • t (FloatTensor) – shape: (batch_size, num_entities, d) Tail embeddings.

Return type

FloatTensor

Returns

shape: (batch_size, num_entities) The scores.

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.