ProjE¶
- class ProjE(*, embedding_dim=50, inner_non_linearity=None, entity_initializer=<function xavier_uniform_>, relation_initializer=<function xavier_uniform_>, **kwargs)[source]¶
Bases:
pykeen.models.base.EntityRelationEmbeddingModel
An implementation of ProjE from [shi2017].
ProjE is a neural network-based approach with a combination and a projection layer. The interaction model first combines \(h\) and \(r\) by following combination operator:
\[\textbf{h} \otimes \textbf{r} = \textbf{D}_e \textbf{h} + \textbf{D}_r \textbf{r} + \textbf{b}_c\]where \(\textbf{D}_e, \textbf{D}_r \in \mathbb{R}^{k \times k}\) are diagonal matrices which are used as shared parameters among all entities and relations, and \(\textbf{b}_c \in \mathbb{R}^{k}\) represents the candidate bias vector shared across all entities. Next, the score for the triple \((h,r,t) \in \mathbb{K}\) is computed:
\[f(h, r, t) = g(\textbf{t} \ z(\textbf{h} \otimes \textbf{r}) + \textbf{b}_p)\]where \(g\) and \(z\) are activation functions, and \(\textbf{b}_p\) represents the shared projection bias vector.
See also
Official Implementation: https://github.com/nddsg/ProjE
Initialize the entity embedding model.
See also
Constructor of the base class
pykeen.models.Model
Attributes Summary
The default strategy for optimizing the model’s hyper-parameters
The default parameters for the default loss function class
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': 256, 'low': 16, 'q': 16, 'type': <class 'int'>}}¶
The default strategy for optimizing the model’s hyper-parameters
- loss_default_kwargs: ClassVar[Optional[Mapping[str, Any]]] = {'reduction': 'mean'}¶
The default parameters for the default loss function class
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.