TuckERInteraction
- class TuckERInteraction(embedding_dim: int = 200, relation_dim: int | None = None, head_dropout: float = 0.3, relation_dropout: float = 0.4, head_relation_dropout: float = 0.5, apply_batch_normalization: bool = True, core_initializer: str | Callable[[Tensor], Tensor] | None = None, core_initializer_kwargs: Mapping[str, Any] | None = None)[source]
Bases:
Interaction
[Tensor
,Tensor
,Tensor
]The stateful TuckER interaction function.
The interaction function is inspired by the Tucker tensor decomposition. The base form is given as
\[\mathbf{Z} \times_1 \mathbf{h} \times_2 \mathbf{r} \times_3 \mathbf{t} = \sum_{1 \leq i, k \leq d_e, 1 \leq j \leq d_r} \mathbf{Z}_{i, j, k} \cdot \mathbf{h}_{i} \cdot \mathbf{r}_{j} \cdot \mathbf{t}_{k}\]where \(\mathbf{h}, \mathbf{t} \in \mathbb{R}^{d_e}\) are the head and tail entity representation, \(\mathbf{r} \in \mathbb{R}^{d_r}\) is the relation representation, and \(\mathbf{Z} \in \mathbb{R}^{d_e \times d_r \times d_e}\) is a global parameter, and \(\times_k\) denotes the tensor product along the \(k\)-th dimension.
The implementation further adds
BatchNorm1d
andDropout
layers at the following locations:\[\textit{DO}_{hr}(\textit{BN}_{hr}( \textit{DO}_h(\textit{BN}_h(\mathbf{h})) \times_1 \textit{DO}_r(\mathbf{Z} \times_2 \mathbf{r}) ) \times_3 \mathbf{t}\]The implementation a has complexity of \(\mathcal{O}(d_e^2 d_r)\), and requires \(\mathcal{O}(d_e^2 d_r)\) global trainable parameters.
Initialize the Tucker interaction function.
- Parameters:
embedding_dim (int) – The entity embedding dimension.
relation_dim (int | None) – The relation embedding dimension. Defaults to
embedding_dim
.head_dropout (float) – The dropout rate applied to the head representations.
relation_dropout (float) – The dropout rate applied to the relation representations.
head_relation_dropout (float) – The dropout rate applied to the combined head and relation representations.
apply_batch_normalization (bool) – Whether to use batch normalization on head representations and the combination of head and relation.
core_initializer (Hint[Initializer]) – The core tensor’s initializer, or a hint thereof. Defaults to
default_core_initializer
.core_initializer_kwargs (OptionalKwargs) – Additional keyword-based parameters for the initializer. Defaults to
default_core_initializer_kwargs
.
Note
The parameter pair
(core_initializer, core_initializer_kwargs)
is used forpykeen.nn.init.initializer_resolver
An explanation of resolvers and how to use them is given in https://class-resolver.readthedocs.io/en/latest/.
Attributes Summary
Methods Summary
default_core_initializer
(tensor[, a, b, ...])Fill the input Tensor with values drawn from the uniform distribution.
forward
(h, r, t)Evaluate the interaction function.
Reset parameters the interaction function may have.
Attributes Documentation
Methods Documentation
- static default_core_initializer(tensor: Tensor, a: float = 0.0, b: float = 1.0, generator: Generator | None = None) Tensor
Fill the input Tensor with values drawn from the uniform distribution.
\(\mathcal{U}(a, b)\).
- Args:
tensor: an n-dimensional torch.Tensor a: the lower bound of the uniform distribution b: the upper bound of the uniform distribution generator: the torch Generator to sample from (default: None)
- Examples:
>>> w = torch.empty(3, 5) >>> nn.init.uniform_(w)