ProjEInteraction
- class ProjEInteraction(embedding_dim: int = 50, inner_activation: str | ~torch.nn.modules.module.Module | type[~torch.nn.modules.module.Module] | None = None, inner_activation_kwargs: ~collections.abc.Mapping[str, ~typing.Any] | None = None, outer_activation: str | ~torch.nn.modules.module.Module | type[~torch.nn.modules.module.Module] | None = None, outer_activation_kwargs: ~collections.abc.Mapping[str, ~typing.Any] | None = None, bias_initializer: str | ~typing.Callable[[~torch.Tensor], ~torch.Tensor] | None = <function xavier_uniform_>, bias_initializer_kwargs: ~collections.abc.Mapping[str, ~typing.Any] | None = None, projection_initializer: str | ~typing.Callable[[~torch.Tensor], ~torch.Tensor] | None = <function xavier_uniform_>, projection_initializer_kwargs: ~collections.abc.Mapping[str, ~typing.Any] | None = None)[source]
Bases:
Interaction
[Tensor
,Tensor
,Tensor
]The state-ful ProjE interaction function.
The activation function is given as
\[g( f( \mathbf{d}_h \odot \mathbf{h} + \mathbf{d}_r \odot \mathbf{r} + \mathbf{b} )^T \mathbf{t} + b_p )\]where \(\mathbf{h}, \mathbf{r}, \mathbf{t} \in \mathbb{R}^d\) are the head entity, relation, and tail entity representations, \(\mathbf{d}_h, \mathbf{d}_r, \mathbf{b} \in \mathbb{R}^d\) and \(b_p \in \mathbb{R}\) are global parameters, and \(f, g\) activation functions.
It can be interpreted as a two-layer neural network with a very special sparsity pattern on the weight matrices. The paper also describes the first operation
\[\mathbf{y} = f(\mathbf{d}_h \odot \mathbf{h} + \mathbf{d}_r \odot \mathbf{r} + \mathbf{b} )\]as the combination operation and the second part
\[g(\mathbf{y}^T \mathbf{t} + b_p)\]as the projection layer.
Note
While the original paper describes using either sigmoid or softmax as the final activation, this implementation defaults to no activation on the final layer. This allows the use of numerically stable implementations of merged activation and loss, such as
torch.nn.BCEWithLogitsLoss
(for sigmoid), ortorch.nn.CrossEntropyLoss
(for softmax).Initialize the interaction module.
- Parameters:
embedding_dim (int) – the embedding dimension of entities and relations
inner_activation (HintOrType[nn.Module]) – the inner non-linearity, or a hint thereof. Defaults to
nn.Tanh
. Disable by passingnn.Idenity
inner_activation_kwargs (OptionalKwargs) – additional keyword-based parameters used to instantiate the inner activation function.
outer_activation (HintOrType[nn.Module]) – the outer non-linearity, or a hint thereof. Defaults to
nn.Identity
, i.e., no activation.outer_activation_kwargs (OptionalKwargs) – additional keyword-based parameters used to instantiate the outer activation function.
bias_initializer (Hint[Initializer]) – the initializer to use for the biases; defaults to
pykeen.nn.init.xavier_uniform_()
.bias_initializer_kwargs (OptionalKwargs) – additional keyword-based parameters passed to the bias initializer.
projection_initializer (Hint[Initializer]) – the initializer to use for the projection; defaults to
pykeen.nn.init.xavier_uniform_()
.projection_initializer_kwargs (OptionalKwargs) – additional keyword-based parameters passed to the projection initializer.
Note
The parameter pairs
(inner_activation, inner_activation_kwargs)
,(outer_activation, outer_activation_kwargs)
are used forclass_resolver.contrib.torch.activation_resolver
An explanation of resolvers and how to use them is given in https://class-resolver.readthedocs.io/en/latest/.
Methods Summary
forward
(h, r, t)Evaluate the interaction function.
Reset parameters the interaction function may have.
Methods Documentation