Skip to content

GNNBenchmarkDataset

GNNBenchmarkDataset(
    name: str,
    split: GNN_BENCHMARK_SPLITS = "train",
    base_dir: Optional[str] = None,
    pre_transform: Optional[Callable] = None,
    transform: Optional[Callable] = None,
)

Bases: Dataset

Datasets of the "Benchmarking Graph Neural Networks" paper.

  • "PATTERN" and "CLUSTER": node classification on graphs sampled from stochastic block models. In PATTERN, the task is to find the nodes of a planted pattern (2 classes); in CLUSTER, to find the cluster of each node, given a single labelled node per cluster (6 classes). Node features are given in node_features and labels in node_labels.
  • "CSL": graph classification of Circular Skip Link graphs into 10 isomorphism classes. The graphs have no features (only num_nodes) and the labels are in graph_labels. CSL has no standard split: only the "train" split exists and contains all the graphs (5-fold stratified cross-validation is recommended), as in PyG.

This dataset follows the implementation of PyG and reads the same raw files, without requiring PyTorch. The graphs are the same, in the same order, with int32 indices and labels. "MNIST" and "CIFAR10" are available as SuperPixelDataset, and "TSP" (a 459 MB download) is not available.

Name #graphs #nodes (avg) #edges (avg) #features #classes Download
PATTERN 14,000 ~118.9 ~6,079 3 2 88 MB (1.4 GB extracted)
CLUSTER 12,000 ~117.2 ~4,302 7 6 64 MB (1.1 GB extracted)
CSL 150 41 164 0 10 27 KB

PATTERN has 10,000 / 2,000 / 2,000 and CLUSTER 10,000 / 1,000 / 1,000 train / val / test graphs.

Parameters:

Name Type Description Default
name str

Name of the dataset, "PATTERN", "CLUSTER" or "CSL".

required
split GNN_BENCHMARK_SPLITS

The split to load, "train", "val" or "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 each graph once, before it is saved.

None
transform Optional[Callable]

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

None

Example:

from mlx_graphs.datasets import GNNBenchmarkDataset

dataset = GNNBenchmarkDataset("PATTERN", split="train")
>>> PATTERN(num_graphs=10000)

dataset[0]
>>> GraphData(
        edge_index(shape=(2, 4884), int32)
        node_features(shape=(108, 3), float32)
        node_labels(shape=(108,), int32))
Source code in mlx_graphs/datasets/gnn_benchmark.py
def __init__(
    self,
    name: str,
    split: GNN_BENCHMARK_SPLITS = "train",
    base_dir: Optional[str] = None,
    pre_transform: Optional[Callable] = None,
    transform: Optional[Callable] = None,
):
    if name in ("MNIST", "CIFAR10"):
        raise ValueError(f"Use mlx_graphs.datasets.SuperPixelDataset for '{name}'")
    if name in self.unsupported_names:
        raise ValueError(f"GNNBenchmarkDataset '{name}' is not available")
    if name not in self.names:
        raise ValueError(f"Unknown dataset '{name}' (got {self.names})")
    if split not in _SPLIT_INDEX:
        raise ValueError(
            f"Split '{split}' found, but expected 'train', 'val' or 'test'"
        )
    if name == "CSL" and split != "train":
        warnings.warn(
            "Dataset 'CSL' does not provide a standardized splitting. "
            "Instead, it is recommended to perform 5-fold cross "
            "validation with stratifed sampling"
        )
        split = "train"
    self.split = split
    super().__init__(
        name=name,
        base_dir=base_dir,
        pre_transform=pre_transform,
        transform=transform,
    )

from mlx_graphs.datasets import GNNBenchmarkDataset · mlx_graphs/datasets/gnn_benchmark.py