MuRE交互

class MuREInteraction(p: int, power_norm: bool = False)[source]

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

基于范数的MuRE交互函数来自[balazevic2019b]

对于 \(\mathbf{h}, \mathbf{r}, \mathbf{R}, \mathbf{t} \in \mathbb{R}^d\),以及 \(b_h, b_t \in \mathbb{R}\),它由以下公式给出

\[-\|\mathbf{R} \odot \mathbf{h} + \mathbf{r} - \mathbf{t}\| + b_h + b_t\]

其中 \(\mathbf{h}, \mathbf{r}, \mathbf{t}\) 是头实体、关系和尾实体的嵌入向量, \(\mathbf{R}\) 是一个对角关系矩阵,\(b_h, b_t\) 是头和尾实体的偏差。

注意

该模块实现了一个稍微更通用的函数,其中可以选择范数 \(\| \cdot \|_p\),以及使用 \(\| \cdot \|_p^p\) 的变体,参见 NormBasedInteraction

初始化基于范数的交互函数。

Parameters:
  • p (int) – 与 torch.linalg.vector_norm() 一起使用的范数。通常为1或2。

  • power_norm (bool) – 是否使用\(L_p\)范数的p次方。它的优点是在0附近可微分,并且在数值上更稳定。

属性摘要

entity_shape

实体表示的符号形状

relation_shape

关系表示的符号形状

方法总结

forward(h, r, t)

评估交互函数。

属性文档

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

实体表示的符号形状

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

关系表示的符号形状

方法文档

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

评估交互函数。

另请参阅

Interaction.forward 提供了关于交互函数通用批处理形式的详细描述。

Parameters:
  • h (tuple[Tensor, Tensor]) – 形状: (*batch_dims, d)(*batch_dims) 头部表示。

  • r (tuple[Tensor, Tensor]) – 形状: (*batch_dims, d)(*batch_dims, d) 关系表示。

  • t (tuple[Tensor, Tensor]) – 形状: (*batch_dims, d)(*batch_dims) 尾部表示。

Returns:

形状: batch_dims 分数。

Return type:

Tensor