Skip to content

DistMult

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

Bases: KGEModel

The DistMult model from the "Embedding Entities and Relations for Learning and Inference in Knowledge Bases" paper.

Relations are diagonal matrices, which gives the score

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

It is trained with a margin ranking 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.

required
margin float

The margin of the ranking loss. 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.rel_emb = _glorot_embedding(num_relations, hidden_features_dim)

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