KG2E交互

class KG2EInteraction(similarity: str | KG2ESimilarity | type[KG2ESimilarity] | None = None, similarity_kwargs: Mapping[str, Any] | None = None)[source]

基础:Interaction[tuple[Tensor, Tensor], tuple[Tensor, Tensor], tuple[Tensor, Tensor]]

无状态的KG2E交互函数。

受到TransEInteraction的启发,关系被建模为从头实体到尾实体的转换\(\mathcal{H} - \mathcal{T} \approx \mathcal{R}\),其中

\[\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}\]

因此,由于头部和尾部实体在关系方面被认为是独立的,

\[\mathcal{P}_e = \mathcal{H} - \mathcal{T} \sim \mathcal{N}(\mu_h - \mu_t, \Sigma_h + \Sigma_t)\]

为了获得分数,交互测量了\(\mathcal{P}_e\)\(\mathcal{P}_r = \mathcal{N}(\mu_r, \Sigma_r)\)之间的相似性,这可以通过(非对称的)NegativeKullbackLeiblerDivergence,或者使用ExpectedLikelihood的对称变体来实现。

注意

这个交互模块没有FunctionalInteraction继承,仅仅是因为技术原因,即相似性的选择代表了一些“状态”。然而,它不包含任何可训练的参数。

初始化交互模块。

Parameters:

注意

参数对 (similarity, similarity_kwargs) 用于 pykeen.nn.sim.kg2e_similarity_resolver

解析器的解释及其使用方法在 https://class-resolver.readthedocs.io/en/latest/中给出。

属性摘要

entity_shape

实体表示的符号形状

relation_shape

关系表示的符号形状

方法总结

forward(h, r, t)

评估交互函数。

属性文档

entity_shape: Sequence[str] = ('d', 'd')

实体表示的符号形状

relation_shape: Sequence[str] = ('d', 'd')

关系表示的符号形状

方法文档

forward(h: tuple[Tensor, Tensor], r: tuple[Tensor, Tensor], t: tuple[Tensor, Tensor]) Tensor[来源]

评估交互函数。

Parameters:
  • h (tuple[Tensor, Tensor]) – 形状均为: (*batch_dims, d) 头部表示,均值和(对角)方差。

  • r (tuple[Tensor, Tensor]) – 形状: (*batch_dims, d) 关系表示,均值和(对角)方差。

  • t (tuple[Tensor, Tensor]) – 形状: (*batch_dims, d) 尾部表示,均值和(对角)方差。

Returns:

形状: batch_dims 分数。

Return type:

Tensor