KG2EInteraction
- class KG2EInteraction(similarity: str | KG2ESimilarity | type[KG2ESimilarity] | None = None, similarity_kwargs: Mapping[str, Any] | None = None)[source]
Bases:
Interaction
[tuple
[Tensor
,Tensor
],tuple
[Tensor
,Tensor
],tuple
[Tensor
,Tensor
]]The stateless KG2E interaction function.
Inspired by
TransEInteraction
, relations are modeled as transformations from head to tail entities \(\mathcal{H} - \mathcal{T} \approx \mathcal{R}\), where\[\begin{split}\mathcal{H} \sim \mathcal{N}(\mu_h, \Sigma_h)\\ \mathcal{T} \sim \mathcal{N}(\mu_t, \Sigma_t)\\ \mathcal{R} \sim \mathcal{N}(\mu_r, \Sigma_r)\end{split}\]and thus, since head and tail entities are considered independent with respect to the relations,
\[\mathcal{P}_e = \mathcal{H} - \mathcal{T} \sim \mathcal{N}(\mu_h - \mu_t, \Sigma_h + \Sigma_t)\]To obtain scores, the interaction measures the similarity between \(\mathcal{P}_e\) and \(\mathcal{P}_r = \mathcal{N}(\mu_r, \Sigma_r)\), either by means of the (asymmetric)
NegativeKullbackLeiblerDivergence
, or a symmetric variant withExpectedLikelihood
.Note
This interaction module does not sub-class from
FunctionalInteraction
just for the technical reason that the choice of the similarity represents some “state”. However, it does not contain any trainable parameters.Initialize the interaction module.
- Parameters:
similarity (HintOrType[KG2ESimilarity] | None) – The similarity measures for gaussian distributions. Defaults to
NegativeKullbackLeiblerDivergence
.similarity_kwargs (OptionalKwargs) – Additional keyword-based parameters used to instantiate the similarity.
Note
The parameter pair
(similarity, similarity_kwargs)
is used forpykeen.nn.sim.kg2e_similarity_resolver
An explanation of resolvers and how to use them is given in https://class-resolver.readthedocs.io/en/latest/.
Attributes Summary
The symbolic shapes for entity representations
The symbolic shapes for relation representations
Methods Summary
forward
(h, r, t)Evaluate the interaction function.
Attributes Documentation
Methods Documentation
- forward(h: tuple[Tensor, Tensor], r: tuple[Tensor, Tensor], t: tuple[Tensor, Tensor]) Tensor [source]
Evaluate the interaction function.
- Parameters:
h (tuple[Tensor, Tensor]) – both shape: (*batch_dims, d) The head representations, mean and (diagonal) variance.
r (tuple[Tensor, Tensor]) – shape: (*batch_dims, d) The relation representations, mean and (diagonal) variance.
t (tuple[Tensor, Tensor]) – shape: (*batch_dims, d) The tail representations, mean and (diagonal) variance.
- Returns:
shape: batch_dims The scores.
- Return type: