torch_geometric.nn.kge.RotatE
- class RotatE(num_nodes: int, num_relations: int, hidden_channels: int, margin: float = 1.0, sparse: bool = False)[source]
Bases:
KGEModel来自“RotatE: Knowledge Graph Embedding by Relational Rotation in Complex Space”论文的RotatE模型。
RotatE将关系建模为从头部到尾部的复数空间中的旋转,使得\[\mathbf{e}_t = \mathbf{e}_h \circ \mathbf{e}_r,\]导致评分函数
\[d(h, r, t) = - {\| \mathbf{e}_h \circ \mathbf{e}_r - \mathbf{e}_t \|}_p\]注意
有关使用
RotatE模型的示例,请参见 examples/kge_fb15k_237.py。- Parameters:
- forward(head_index: Tensor, rel_type: Tensor, tail_index: Tensor) Tensor[source]
返回给定三元组的分数。
- Parameters:
head_index (torch.Tensor) – The head indices.
rel_type (torch.Tensor) – The relation type.
tail_index (torch.Tensor) – The tail indices.
- Return type:
- loss(head_index: Tensor, rel_type: Tensor, tail_index: Tensor) Tensor[source]
返回给定三元组的损失值。
- Parameters:
head_index (torch.Tensor) – The head indices.
rel_type (torch.Tensor) – The relation type.
tail_index (torch.Tensor) – The tail indices.
- Return type: