低秩表示

class LowRankRepresentation(*, max_id: int, shape: int | ~collections.abc.Sequence[int], num_bases: int = 3, weight_initializer: ~typing.Callable[[~torch.Tensor], ~torch.Tensor] = <pykeen.utils.compose object>, **kwargs)[source]

基础类:Representation

低秩嵌入分解。

这种表示方法通过不为每个索引学习独立的权重,而是在所有索引之间共享基础,并仅学习线性组合的权重,从而减少了可训练参数的数量。

\[E[i] = \sum_k B[i, k] * W[k]\]

初始化表示。

Parameters:
  • max_id (int) – 最大ID(不包括)。有效的ID范围从0到max_id-1

  • shape (tuple[int, ...]) – 单个基础表示的形状。

  • num_bases (int) – 基数的数量。更多的基数增加了表达能力,但也增加了可训练参数的数量。

  • weight_initializer (Initializer) – 基础权重的初始化器

  • kwargs – 传递给pykeen.nn.representation.Embedding的额外基于关键字的参数,用于基础表示。

属性摘要

num_bases

返回碱基的数量。

方法总结

approximate(other, **kwargs)

构建另一种表示的低秩近似。

reset_parameters()

重置模块的参数。

属性文档

num_bases

返回碱基的数量。

方法文档

classmethod approximate(other: Representation, **kwargs) LowRankRepresentation[源代码]

构建另一种表示的低秩近似。

注意

虽然此方法尝试找到基础表示的良好近似值,但您可能会丢失原始表示中的所有(有用的)归纳偏差,例如,来自pykeen.representation.NodePieceRepresentation中的共享标记。

Parameters:
  • 其他 (Representation) – 其他表示

  • kwargs – 传递给 LowRankRepresentation.__init__() 的额外基于关键字的参数。不能包含 max_idshape,这些由 other 决定

Returns:

通过(截断)SVD获得的低秩近似

Return type:

LowRankRepresentation

reset_parameters() None[来源]

重置模块的参数。

Return type: