AutoSF交互

class AutoSFInteraction(coefficients: Iterable[tuple[int, int, int, Literal[-1, 1]]], *, num_blocks: int | None = None, num_entity_representations: int | None = None, num_relation_representations: int | None = None)[source]

基础:FunctionalInteraction[HeadRepresentation, RelationRepresentation, TailRepresentation]

AutoSF交互如[zhang2020]所述。

这个交互函数是一种参数化的方式,用于表达具有块结构的双线性模型。它将实体和关系表示划分为块,并将交互表达为一系列四元组 \((i_h, i_r, i_t, s)\),其中 \(i_h, i_r, i_t\) 索引头、关系或尾表示的_块_,而 \(s \in {-1, 1}\) 是符号。

交互函数随后给出为

\[\sum_{(i_h, i_r, i_t, s) \in \mathcal{C}} s \cdot \langle h[i_h], r[i_r], t[i_t] \rangle\]

其中 \(\langle \cdot, \cdot, \cdot \rangle\) 表示三线性点积。

这种参数化允许表达几种众所周知的交互函数,例如。

  • pykeen.nn.DistMultInteraction:

    一个块, \(\mathcal{C} = \{(0, 0, 0, 1)\}\)

  • pykeen.nn.ComplExInteraction:

    两个块,\(\mathcal{C} = \{(0, 0, 0, 1), (0, 1, 1, 1), (1, 0, 1, -1), (1, 0, 1, 1)\}\)

  • pykeen.nn.SimplEInteraction:

    两个块: \(\mathcal{C} = \{(0, 0, 1, 1), (1, 1, 0, 1)\}\)

虽然在理论上,我们可以有多达num_blocks**3个唯一的三元组,但通常来说,较小的数量更可取,以保持一定的稀疏性。

初始化交互函数。

Parameters:
  • coefficients (tuple[tuple[int, int, int, Literal[-1, 1]], ...]) – 各个块的系数,参见 pykeen.nn.AutoSFInteraction

  • num_blocks (int | None) – 块的数量。如果给定,将用于实体和关系表示。

  • num_entity_representations (int | None) – 实体表示/块的显式数量。仅在num_blocksNone时使用。 如果num_entity_representations也是None,则此数量从coefficients推断。

  • num_relation_representations (int | None) – 关系表示/块的显式数量。仅在num_blocksNone时使用。 如果num_relation_representations也是None,则此数量从coefficients推断。

方法总结

extend(*new_coefficients)

扩展AutoSF功能,如论文中的贪心搜索算法所述。

from_searched_sf(coefficients, **kwargs)

从“官方”序列化格式实例化 AutoSF 交互。

func(h, r, t, coefficients)

评估一个AutoSF风格的交互函数,如[zhang2020]所述。

latex_visualize()

创建如论文中所示的LaTeX + tikz可视化。

方法文档

extend(*new_coefficients: tuple[int, int, int, Literal[-1, 1]]) AutoSFInteraction[source]

扩展AutoSF功能,如论文中的贪心搜索算法所述。

Parameters:

new_coefficients (tuple[int, int, int, Literal[-1, 1]])

Return type:

AutoSFInteraction

classmethod from_searched_sf(coefficients: Sequence[int], **kwargs) AutoSFInteraction[来源]

从“官方”序列化格式实例化 AutoSF 交互。

> 前4个值(a,b,c,d)表示 h_1 * r_1 * t_a + h_2 * r_2 * t_b + h_3 * r_3 * t_c + h_4 * r_4 * t_d。 > 对于其他值,每4个值表示一个加法块:r的索引,h的索引,t的索引,符号s。

Parameters:
  • coefficients (Sequence[int]) – “官方”序列化格式中的系数。

  • kwargs – 传递给 pykeen.nn.AutoSFInteraction.__init__() 的额外基于关键字的参数

Returns:

一个AutoSF交互模块

Return type:

AutoSFInteraction

static func(h: HeadRepresentation, r: RelationRepresentation, t: TailRepresentation, coefficients: Collection[tuple[int, int, int, Literal[-1, 1]]]) Tensor[源代码]

评估一个AutoSF风格的交互函数,如[zhang2020]所述。

Parameters:
Returns:

形状: batch_dims 分数

Return type:

Tensor

latex_visualize() str[source]

创建如论文中所示的LaTeX + tikz可视化。

Return type:

str