ComplExInteraction

class ComplExInteraction(*args, **kwargs)[源代码]

基础:FunctionalInteraction[Tensor, Tensor, Tensor]

[trouillon2016]提出的ComplEx交互。

ComplEx 在复数值的实体和关系表示上操作,即, \(\textbf{e}_i, \textbf{r}_i \in \mathbb{C}^d\) 并通过哈达玛积计算可信度分数:

\[f(h,r,t) = Re(\mathbf{e}_h\odot\mathbf{r}_r\odot\bar{\mathbf{e}}_t)\]

展开为:

\[f(h,r,t) = \left\langle Re(\mathbf{e}_h),Re(\mathbf{r}_r),Re(\mathbf{e}_t)\right\rangle + \left\langle Im(\mathbf{e}_h),Re(\mathbf{r}_r),Im(\mathbf{e}_t)\right\rangle + \left\langle Re(\mathbf{e}_h),Im(\mathbf{r}_r),Im(\mathbf{e}_t)\right\rangle - \left\langle Im(\mathbf{e}_h),Im(\mathbf{r}_r),Re(\mathbf{e}_t)\right\rangle\]

其中 \(Re(\textbf{x})\)\(Im(\textbf{x})\) 表示复数值向量 \(\textbf{x}\) 的实部和虚部。由于哈达玛积在复数空间中不可交换,ComplEx 可以建模反对称关系,这与 DistMult 不同。

另请参阅

官方实现:https://github.com/ttrouill/complex/

注意

此方法通常期望所有张量都是复数数据类型,即torch.is_complex(x)评估为True。然而,为了向后兼容和使用方便,您也可以传递形状符合torch.view_as_complex()的实数张量,参见pykeen.utils.ensure_complex()

初始化内部模块状态,由nn.Module和ScriptModule共享。

属性摘要

is_complex

交互是否在复杂输入上定义

方法总结

func(h, r, t)

评估交互函数。

属性文档

is_complex: ClassVar[bool] = True

交互是否在复杂输入上定义

方法文档

static func(h: Tensor, r: Tensor, t: Tensor) Tensor[源代码]

评估交互函数。

Parameters:
  • h (Tensor) – 形状: (*batch_dims, dim) 复杂的头部表示。

  • r (Tensor) – 形状: (*batch_dims, dim) 复杂的关联表示。

  • t (Tensor) – 形状: (*batch_dims, dim) 复杂的尾部表示。

Returns:

形状: batch_dims 分数。

Return type:

Tensor