Skip to content

Datasets

MLX-graphs provides several built-in datasets for graph machine learning tasks.

Note

Datasets are automatically downloaded to .mlx_graphs_data/ in the current working directory upon first use. You can specify a custom directory by passing base_dir to the dataset constructor.

Available Datasets

Each name links the API page of the class that loads it; Load with is the call. The table is built from docs/datasets.yml.

Dataset Load with Graphs Nodes Edges Avg degree Features Labels
Karate Club KarateClubDataset() 1 34 156 9.18 node node
Cora PlanetoidDataset("cora") 1 2,708 10,556 7.80 node node
CiteSeer PlanetoidDataset("citeseer") 1 3,312 9,104 5.50 node node
PubMed PlanetoidDataset("pubmed") 1 19,717 88,651 8.99 node node
Amazon Computers AmazonDataset("computers") 1 13,752 491,722 71.51 node node
Amazon Photo AmazonDataset("photo") 1 7,650 238,162 62.26 node node
Coauthor CS CoauthorDataset("cs") 1 18,333 163,788 17.87 node node
Coauthor Physics CoauthorDataset("physics") 1 34,493 495,924 28.76 node node
QM7b QM7bDataset() 7,211 ~15.4 ~245.0 ~31.77 edge graph
Elliptic Bitcoin EllipticBitcoinDataset() 1 203,769 234,355 2.30 node node
MovieLens 100K MovieLens100K() 1 1,682 100,000 118.90 node edge
Cora Full CoraFull() 1 19,793 126,842 12.82 node node
Cora ML (full) CitationFull("cora_ml") 1 2,995 16,316 10.90 node node
CiteSeer (full) CitationFull("citeseer") 1 4,230 10,674 5.05 node node
DBLP (full) CitationFull("dblp") 1 17,716 105,734 11.94 node node
PubMed (full) CitationFull("pubmed") 1 19,717 88,648 8.99 node node
Roman-empire HeterophilousGraphDataset("roman_empire") 1 22,662 65,854 5.81 node node
Amazon-ratings HeterophilousGraphDataset("amazon_ratings") 1 24,492 186,100 15.20 node node
Minesweeper HeterophilousGraphDataset("minesweeper") 1 10,000 78,804 15.76 node node
Tolokers HeterophilousGraphDataset("tolokers") 1 11,758 1,038,000 176.56 node node
Questions HeterophilousGraphDataset("questions") 1 48,921 307,080 12.55 node node
Cornell WebKB("cornell") 1 183 298 3.26 node node
Texas WebKB("texas") 1 183 325 3.55 node node
Wisconsin WebKB("wisconsin") 1 251 515 4.10 node node
Chameleon WikipediaNetwork("chameleon") 1 2,277 36,101 31.71 node node
Squirrel WikipediaNetwork("squirrel") 1 5,201 217,073 83.47 node node
Actor Actor() 1 7,600 30,019 7.90 node node
WikiCS WikiCS() 1 11,701 431,726 73.79 node node
Reddit Reddit() 1 232,965 114,615,892 983.98 node node
Reddit2 Reddit2() 1 232,965 23,213,838 199.29 node node
Flickr Flickr() 1 89,250 899,756 20.16 node node
Yelp Yelp() 1 716,847 13,954,819 38.93 node node (multi-label)
AmazonProducts AmazonProducts() 1 1,569,960 264,339,468 336.75 node node (multi-label)
FB15k-237 (train) FB15k_237(split="train") 1 14,541 272,115 37.43 none edge (type)
WordNet18RR WordNet18RR() 1 40,943 93,003 4.54 none edge (type)
JODIE Wikipedia (temporal) JODIEDataset("wikipedia") 1 9,227 157,474 34.13 edge edge
MUTAG (TU datasets) TUDataset("MUTAG") 188 ~17.9 ~39.6 ~4.42 node, edge graph
ogbn-arxiv (OGB) OGBDataset("ogbn-arxiv") 1 169,343 1,166,243 13.77 node node
ogbn-mag (OGB, heterogeneous) OGBMAG() 1 1,939,743 21,111,007 21.77 node node
IMDB (heterogeneous) IMDB() 1 11,616 34,212 5.89 node node
DBLP (heterogeneous) DBLP() 1 26,128 239,566 18.34 node node
Peptides-func (LRGB, train split) LRGBDataset("peptides-func") 10,873 ~151.5 ~308.5 ~4.07 node, edge graph
PATTERN (GNN benchmark, train split) GNNBenchmarkDataset("PATTERN") 10,000 ~118.9 ~6,079.9 ~102.26 node node
MNIST superpixels (train split) SuperPixelDataset("MNIST", "train") 60,000 ~70.6 ~564.5 ~16.00 node, edge graph
PPI (train split) PPI("train") 20 ~2,245.3 ~61,318.4 ~54.62 node node (multi-label)
ModelNet10 (train split) ModelNet("10") 3,991 ~9,897.5 0 (mesh) 0 positions, faces graph
ModelNet40 (train split) ModelNet("40") 9,843 ~18,097.0 0 (mesh) 0 positions, faces graph
ShapeNet (trainval split) ShapeNet() 14,007 ~2,615.4 0 (point cloud) 0 node (normals), positions node (part)
QM9 QM9() 130,831 ~18.0 ~37.3 ~4.14 node, edge, positions graph (19 targets)
ZINC (train split) ZINC() 220,011 ~23.2 ~49.8 ~4.30 node, edge graph
ESOL (MoleculeNet) MoleculeNet("ESOL") 1,128 ~13.3 ~27.4 ~4.12 node, edge graph
WordNet18 WordNet18() 1 40,943 151,442 7.40 none edge (type)
tgbl-wiki (TGB, link property prediction) TGBLinkPropPredDataset("tgbl-wiki") 1 9,227 157,474 34.13 edge none
tgbn-trade (TGB, node property prediction) TGBNodePropPredDataset("tgbn-trade") 1 255 468,245 3,672.51 edge node (over time)
JODIE MOOC (temporal) JODIEDataset("mooc") 1 7,144 411,749 115.27 edge edge

The average degree is 2 × edges / nodes. The last rows are collections, heterogeneous and temporal graphs, one example each; their class page lists the other datasets they load:

  • for a collection, Graphs is the number of graphs (of the split that Load with loads) and the other numbers are averages per graph (~);
  • a heterogeneous graph counts the nodes and edges of all types: ogbn-mag has 4 node types (paper, author, institution, field of study) and 4 edge types, IMDB 3 node types (movie, director, actor) and 4 edge types, DBLP 4 node types (author, paper, term, conference) and 6 edge types;
  • a temporal graph counts each event as an edge;
  • ModelNet meshes and ShapeNet point clouds have no edges: ModelNet keeps its triangles in face (FaceToEdge turns them into edges), and point clouds get theirs from knn_graph or radius_graph.

The large graphs guide shows how to train on Reddit, Yelp or AmazonProducts with features kept on disk.

Other dataset classes: BaseDataset, Dataset, FakeDataset, FakeHeteroDataset, HeteroDataset, TGBNegativeEdgeSampler.

Using Datasets

Loading a dataset is straightforward:

from mlx_graphs.datasets import KarateClubDataset, PlanetoidDataset

# Simple built-in dataset
dataset = KarateClubDataset()
graph = dataset[0]
print(f"Nodes: {graph.num_nodes}, Edges: {graph.num_edges}")

# Citation network dataset
cora = PlanetoidDataset(name="cora")
print(cora[0])

Add your own dataset

Subclass Dataset and implement two methods: download, which fetches the raw files into self.raw_path, and process, which turns them into a list of GraphData in self.graphs. The first instantiation runs both and saves the processed graphs under base_dir (.mlx_graphs_data/ by default); later ones load them. Indexing, slicing, shuffle, the num_* properties, transforms and the Dataloader then work as for the built-in datasets.

A made-up dataset, generated instead of downloaded: is a graph a cycle or a path?

import mlx.core as mx
import numpy as np

from mlx_graphs.data import GraphData
from mlx_graphs.datasets import Dataset
from mlx_graphs.loaders import Dataloader


class CyclesOrPaths(Dataset):
    """Graph classification: is the graph a cycle (label 1) or a path (label 0)?"""

    def __init__(self, num_graphs: int = 200, base_dir=None):
        self.num_graphs_to_make = num_graphs
        super().__init__(name="cycles_or_paths", base_dir=base_dir)

    def download(self):
        pass  # nothing to download: the graphs are generated in process()

    def process(self):
        rng = np.random.default_rng(0)
        self.graphs = []
        for i in range(self.num_graphs_to_make):
            n = int(rng.integers(5, 20))
            src = np.arange(n - 1)
            if i % 2:  # close the path into a cycle
                src = np.arange(n)
            dst = (src + 1) % n
            edges = np.concatenate([np.stack([src, dst]), np.stack([dst, src])], axis=1)
            self.graphs.append(
                GraphData(
                    edge_index=mx.array(edges, dtype=mx.int32),
                    node_features=mx.ones((n, 1)),
                    graph_labels=mx.array([i % 2]),
                )
            )


dataset = CyclesOrPaths()  # processed once, then loaded from .mlx_graphs_data/
print(dataset)
print(dataset.num_graphs, dataset.num_graph_classes, dataset[0])
loader = Dataloader(dataset, batch_size=32, shuffle=True)
print(next(iter(loader)).num_graphs)
cycles_or_paths(num_graphs=200)
200 2 GraphData(
    edge_index(shape=(2, 32), int32)
    node_features(shape=(17, 1), float32)
    graph_labels(shape=(1,), int32))
32

For a dataset that is downloaded, call download in download (and check_sha1 or extract_archive as needed), and read the files of self.raw_path in process. The built-in datasets, in mlx_graphs/datasets, are examples. For a dataset of heterogeneous graphs, subclass HeteroDataset.

Computing Dataset Statistics

To compute statistics for any dataset, use the included utility script:

# Stats for all available datasets
python examples/compute_dataset_stats.py

# Stats for a specific dataset
python examples/compute_dataset_stats.py --dataset karate_club

# Output as markdown table (for this page, or issues)
python examples/compute_dataset_stats.py --format markdown

# Output as RST table
python examples/compute_dataset_stats.py --format rst