RGCN

class RGCN(*, triples_factory: ~pykeen.triples.triples_factory.CoreTriplesFactory, embedding_dim: int = 500, num_layers: int = 2, base_entity_initializer: str | ~typing.Callable[[~torch.Tensor], ~torch.Tensor] | None = <function xavier_uniform_>, base_entity_initializer_kwargs: ~collections.abc.Mapping[str, ~typing.Any] | None = None, relation_representations: str | ~pykeen.nn.representation.Representation | type[~pykeen.nn.representation.Representation] | None = None, relation_initializer: str | ~typing.Callable[[~torch.Tensor], ~torch.Tensor] | None = <function xavier_uniform_>, relation_initializer_kwargs: ~collections.abc.Mapping[str, ~typing.Any] | None = None, interaction: str | ~pykeen.nn.modules.Interaction[~torch.Tensor, ~pykeen.typing.RelationRepresentation, ~torch.Tensor] | type[~pykeen.nn.modules.Interaction[~torch.Tensor, ~pykeen.typing.RelationRepresentation, ~torch.Tensor]] | None = 'DistMult', interaction_kwargs: ~collections.abc.Mapping[str, ~typing.Any] | None = None, use_bias: bool = True, activation: str | ~torch.nn.modules.module.Module | None = None, activation_kwargs: ~collections.abc.Mapping[str, ~typing.Any] | None = None, edge_dropout: float = 0.4, self_loop_dropout: float = 0.2, edge_weighting: str | ~pykeen.nn.weighting.EdgeWeighting | None = None, decomposition: str | ~pykeen.nn.message_passing.Decomposition | None = None, decomposition_kwargs: ~collections.abc.Mapping[str, ~typing.Any] | None = None, regularizer: str | ~pykeen.regularizers.Regularizer | None = None, regularizer_kwargs: ~collections.abc.Mapping[str, ~typing.Any] | None = None, **kwargs)[源代码]

基础类:ERModel[Tensor, RelationRepresentation, Tensor]

R-GCN的实现来自[schlichtkrull2018]

关系图卷积网络(R-GCN)包括三个部分:

  1. 一个基于GCN的实体编码器,用于计算实体的丰富表示,参见 pykeen.nn.message_passing.RGCNRepresentations。实体\(i\)在第\(l \in (1,\dots,L)\)层的表示记为\(\textbf{e}_i^l\)。 该GCN被修改为根据关系类型使用不同的权重。

  2. 关系表示 \(\textbf{R}_{r} \in \mathbb{R}^{d \times d}\) 是一个对角矩阵,它是独立于基于GCN的编码器学习的。

  3. 一个任意的交互模型,用于计算给定丰富表示的事实合理性,参见 pykeen.nn.modules.Interaction

对于每个三元组 \((h,r,t) \in \mathcal{K}\) 的分数是通过使用基于GCN编码器的最终级别中的表示 \(\textbf{e}_h^L\)\(\textbf{e}_t^L\) 以及关系表示 \(\textbf{R}_{r}\) 来计算的。虽然R-GCN的原始实现使用了DistMult模型,并且我们将其作为默认设置,但这个实现允许指定任意的交互模型。

\[f(h,r,t) = \textbf{e}_h^L \textbf{R}_{r} \textbf{e}_t^L\]

初始化模型。

Parameters:
  • triples_factory (CoreTriplesFactory) – (训练)三元组工厂

  • embedding_dim (int) – 嵌入维度

  • num_layers (int) – >0 层数

  • base_entity_initializer (str | Callable[[Tensor], Tensor] | None) – 实体基础表示初始化器

  • base_entity_initializer_kwargs (Mapping[str, Any] | None) – 实体基础表示初始化器的基于关键字的参数

  • relation_representations (str | Representation | type[Representation] | None) – 关系表示,或其提示

  • relation_initializer (str | Callable[[Tensor], Tensor] | None) – 实体基础表示初始化器

  • relation_initializer_kwargs (Mapping[str, Any] | None) – 实体基础表示初始化器的基于关键字的参数

  • interaction (str | Interaction[Tensor, RelationRepresentation, Tensor] | type[Interaction[Tensor, RelationRepresentation, Tensor]] | None) – 交互函数或其提示

  • interaction_kwargs (Mapping[str, Any] | None) – 传递给交互函数的额外基于关键字的参数

  • use_bias (bool) – 是否在消息传递层使用偏置

  • activation (str | Module | None) – 激活函数,或其提示

  • activation_kwargs (Mapping[str, Any] | None) – 传递给激活函数的额外基于关键字的参数

  • edge_dropout (float) – 边的丢弃率,不包括自环

  • self_loop_dropout (float) – 自循环丢弃率

  • edge_weighting (str | EdgeWeighting | None) – 边的权重

  • 分解 (str | Decomposition | None) – 卷积权重分解

  • decomposition_kwargs (Mapping[str, Any] | None) – 传递给权重分解的额外基于关键字的参数

  • regularizer (str | Regularizer | None) – 应用于基础表示的regularizer

  • regularizer_kwargs (Mapping[str, Any] | None) – 传递给正则化器的额外基于关键字的参数

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

属性摘要

hpo_default

优化模型超参数的默认策略

属性文档

hpo_default: ClassVar[Mapping[str, Any]] = {'activation': {'choices': [<class 'torch.nn.modules.activation.ReLU'>, <class 'torch.nn.modules.activation.LeakyReLU'>], 'type': 'categorical'}, 'decomposition': {'choices': ['bases', 'block'], 'type': 'categorical'}, 'edge_dropout': {'high': 0.5, 'low': 0.0, 'q': 0.1, 'type': <class 'float'>}, 'edge_weighting': {'choices': ['inverse_in_degree', 'inverse_out_degree', 'symmetric'], 'type': 'categorical'}, 'embedding_dim': {'high': 256, 'low': 16, 'q': 16, 'type': <class 'int'>}, 'interaction': {'choices': ['distmult', 'complex', 'ermlp'], 'type': 'categorical'}, 'num_layers': {'high': 5, 'low': 1, 'q': 1, 'type': <class 'int'>}, 'self_loop_dropout': {'high': 0.5, 'low': 0.0, 'q': 0.1, 'type': <class 'float'>}, 'use_bias': {'type': 'bool'}}

优化模型超参数的默认策略