Skip to content

FB15k_237

FB15k_237(
    split: KG_SPLITS = "train",
    base_dir: Optional[str] = None,
    pre_transform: Optional[Callable] = None,
    transform: Optional[Callable] = None,
)

Bases: _KnowledgeGraphDataset

The FB15K237 dataset from the "Translating Embeddings for Modeling Multi-Relational Data" paper, containing 14,541 entities, 237 relations and 310,116 fact triples.

Each split is a separate graph whose edge_index holds the (head, tail) entity pairs and edge_type the relation of each triplet. Entity and relation ids are shared across the three splits, and each graph has num_nodes set to the total number of entities.

This dataset follows the implementation of PyG.

Note

The original FB15k dataset suffers from major test leakage through inverse relations, where a large number of test triples could be obtained by inverting triples in the training set. In order to create a dataset without this characteristic, FB15k_237 contains a subset of FB15k where inverse relations are removed.

Split #nodes #edges #relations
train 14,541 272,115 237
val 14,541 17,535 237
test 14,541 20,466 237

Parameters:

Name Type Description Default
split KG_SPLITS

The split to load ("train", "val", "test"). Default: "train".

'train'
base_dir Optional[str]

Directory where to store dataset files. Default is in the local directory .mlx_graphs_data/.

None
pre_transform Optional[Callable]

A function/transform applied to the graph once, before it is saved.

None
transform Optional[Callable]

A function/transform applied to the graph at every access.

None

Example:

from mlx_graphs.datasets import FB15k_237

dataset = FB15k_237(split="train")
>>> FB15k_237(num_graphs=1)

dataset[0]
>>> GraphData(
        edge_index(shape=(2, 272115), int32)
        edge_type(shape=(272115,), int32)
        num_nodes=14541)
Source code in mlx_graphs/datasets/knowledge_graph.py
def __init__(
    self,
    split: KG_SPLITS = "train",
    base_dir: Optional[str] = None,
    pre_transform: Optional[Callable] = None,
    transform: Optional[Callable] = None,
):
    splits = ["train", "val", "test"]
    if split not in splits:
        raise ValueError(f"Invalid 'split' argument (got {split})")
    self.split = split
    super().__init__(
        name="FB15k_237",
        base_dir=base_dir,
        pre_transform=pre_transform,
        transform=transform,
    )
    # the three splits are processed and saved together, keep only one
    self.graphs = [self.graphs[splits.index(split)]]

from mlx_graphs.datasets import FB15k_237 · mlx_graphs/datasets/knowledge_graph.py