Skip to content

ComplEx

ComplEx(num_nodes: int, num_relations: int, hidden_features_dim: int)

Bases: KGEModel

The ComplEx model from the "Complex Embeddings for Simple Link Prediction" paper.

Entities and relations have complex embeddings, and the score is the real part of the Hermitian triple product

\[ d(h, r, t) = \textrm{Re}(\langle \mathbf{e}_h, \mathbf{e}_r, \overline{\mathbf{e}_t} \rangle) \]

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
Source code in mlx_graphs/nn/models/kge.py
def __init__(self, num_nodes: int, num_relations: int, hidden_features_dim: int):
    super().__init__(num_nodes, num_relations, hidden_features_dim)
    self.node_emb = _glorot_embedding(num_nodes, hidden_features_dim)
    self.node_emb_im = _glorot_embedding(num_nodes, hidden_features_dim)
    self.rel_emb = _glorot_embedding(num_relations, hidden_features_dim)
    self.rel_emb_im = _glorot_embedding(num_relations, hidden_features_dim)

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