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.AutoSFInteractionnum_blocks (int | None) – 块的数量。如果给定,将用于实体和关系表示。
num_entity_representations (int | None) – 实体表示/块的显式数量。仅在num_blocks为None时使用。 如果num_entity_representations也是None,则此数量从coefficients推断。
num_relation_representations (int | None) – 关系表示/块的显式数量。仅在num_blocks为None时使用。 如果num_relation_representations也是None,则此数量从coefficients推断。
方法总结
extend(*new_coefficients)扩展AutoSF功能,如论文中的贪心搜索算法所述。
from_searched_sf(coefficients, **kwargs)从“官方”序列化格式实例化 AutoSF 交互。
func(h, r, t, coefficients)评估一个AutoSF风格的交互函数,如[zhang2020]所述。
创建如论文中所示的LaTeX + tikz可视化。
方法文档
- extend(*new_coefficients: tuple[int, int, int, Literal[-1, 1]]) AutoSFInteraction[source]
扩展AutoSF功能,如论文中的贪心搜索算法所述。
- 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:
- Returns:
一个AutoSF交互模块
- Return type:
- static func(h: HeadRepresentation, r: RelationRepresentation, t: TailRepresentation, coefficients: Collection[tuple[int, int, int, Literal[-1, 1]]]) Tensor[源代码]
评估一个AutoSF风格的交互函数,如[zhang2020]所述。
- Parameters:
h (HeadRepresentation) – 每个形状: (*batch_dims, dim) 头表示的列表。
r (RelationRepresentation) – 每个形状: (*batch_dims, dim) 关系表示的列表。
t (TailRepresentation) – 每个形状: (*batch_dims, dim) 尾表示的列表。
coefficients (Collection[tuple[int, int, int, Literal[-1, 1]]]) – 系数,参见
pykeen.nn.AutoSFInteraction
- Returns:
形状: batch_dims 分数
- Return type: