CompGCN层
- class CompGCNLayer(input_dim: int, output_dim: int | None = None, dropout: float = 0.0, use_bias: bool = True, use_relation_bias: bool = False, composition: str | ~pykeen.nn.compositions.CompositionModule | None = None, attention_heads: int = 4, attention_dropout: float = 0.1, activation: str | ~torch.nn.modules.module.Module | type[~torch.nn.modules.module.Module] | None = <class 'torch.nn.modules.linear.Identity'>, activation_kwargs: ~collections.abc.Mapping[str, ~typing.Any] | None = None, edge_weighting: str | type[~pykeen.nn.weighting.EdgeWeighting] | None = <class 'pykeen.nn.weighting.SymmetricEdgeWeighting'>)[source]
基础类:
ModuleCompGCN模型的单层。
初始化模块。
- Parameters:
input_dim (int) – 输入维度。
output_dim (int | None) – 输出维度。如果为None,则等于输入维度。
dropout (float) – 用于前向和后向边的dropout。
use_bias (bool) – # TODO: 我们真的需要这个吗?它位于一个强制性的批量归一化层之前 是否使用偏置。
use_relation_bias (bool) – 是否在关系转换中使用偏置。
组合 (提示[CompositionModule]) – 组合函数。
attention_heads (int) – 使用注意力加权时的注意力头数量
attention_dropout (float) – 用于注意力消息加权的Dropout
activation (HintOrType[nn.Module]) – 要使用的激活函数。
activation_kwargs (Mapping[str, Any] | None) – 传递给激活函数的额外基于关键字的参数。
edge_weighting (HintType[EdgeWeighting]) – 一个预先实例化的
EdgeWeighting,一个类,或者一个名称,用于通过class_resolver查找。
方法总结
forward(x_e, x_r, edge_index, edge_type)更新实体和关系表示。
message(x_e, x_r, edge_index, edge_type, weight)执行消息传递。
重置模型的参数。
方法文档
- forward(x_e: Tensor, x_r: Tensor, edge_index: Tensor, edge_type: Tensor) tuple[Tensor, Tensor][来源]
更新实体和关系表示。
\[X_E'[e] = \frac{1}{3} \left( X_E W_s + \left( \sum_{h,r,e \in T} \alpha(h, e) \phi(X_E[h], X_R[r]) W_f \right) + \left( \sum_{e,r,t \in T} \alpha(e, t) \phi(X_E[t], X_R[r^{-1}]) W_b \right) \right)\]- Parameters:
- Returns:
形状: (num_entities, output_dim) / (2 * num_relations, output_dim) 更新后的实体和关系表示。
- Return type: