Skip to content

RotatE

RotatE(
    num_nodes: int,
    num_relations: int,
    hidden_features_dim: int,
    margin: float = 1.0,
)

Bases: KGEModel

The RotatE model from the "RotatE: Knowledge Graph Embedding by Relational Rotation in Complex Space" paper.

Relations are rotations in the complex plane, \(\mathbf{e}_t = \mathbf{e}_h \circ \mathbf{e}_r\) with \(|\mathbf{e}_r| = 1\), which gives the score

\[ d(h, r, t) = \gamma - {\| \mathbf{e}_h \circ \mathbf{e}_r - \mathbf{e}_t \|} \]

where \(\gamma\) is the margin. It is trained with a binary cross entropy loss.

Parameters:

Name Type Description Default
num_nodes int

The number of nodes (entities) in the graph.

required
num_relations int

The number of relations in the graph.

required
hidden_features_dim int

The size of the embeddings (of both their real and imaginary parts).

required
margin float

The margin \(\gamma\). Default: 1.0

1.0
Source code in mlx_graphs/nn/models/kge.py
def __init__(
    self,
    num_nodes: int,
    num_relations: int,
    hidden_features_dim: int,
    margin: float = 1.0,
):
    super().__init__(num_nodes, num_relations, hidden_features_dim)
    self.margin = margin
    self.node_emb = _glorot_embedding(num_nodes, hidden_features_dim)
    self.node_emb_im = _glorot_embedding(num_nodes, hidden_features_dim)
    # relation phases
    self.rel_emb.weight = mx.random.uniform(
        0, 2 * math.pi, self.rel_emb.weight.shape
    )

from mlx_graphs.nn import RotatE · mlx_graphs/nn/models/kge.py