Skip to content

HeterophilousGraphDataset

HeterophilousGraphDataset(
    name: HETEROPHILOUS_NAMES,
    base_dir: Optional[str] = None,
    pre_transform: Optional[Callable] = None,
    transform: Optional[Callable] = None,
)

Bases: Dataset

The heterophilous graphs "Roman-empire", "Amazon-ratings", "Minesweeper", "Tolokers" and "Questions" from the "A Critical Look at the Evaluation of GNNs under Heterophily: Are We Really Making Progress?" paper.

The graphs are made undirected. Each dataset comes with 10 fixed train/validation/test splits (50%/25%/25%), stored as masks of shape [num_nodes, 10] in the train_mask, val_mask and test_mask attributes (column i is the i-th split).

This dataset follows the implementation of PyG.

Name #nodes #edges #features #classes
roman_empire 22,662 65,854 300 18
amazon_ratings 24,492 186,100 300 5
minesweeper 10,000 78,804 7 2
tolokers 11,758 1,038,000 10 2
questions 48,921 307,080 301 2

Parameters:

Name Type Description Default
name HETEROPHILOUS_NAMES

The name of the dataset ("roman_empire", "amazon_ratings", "minesweeper", "tolokers", "questions"). Dashes are accepted in place of underscores.

required
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 HeterophilousGraphDataset

dataset = HeterophilousGraphDataset("minesweeper")
>>> minesweeper(num_graphs=1)

dataset[0]
>>> GraphData(
        edge_index(shape=(2, 78804), int32)
        node_features(shape=(10000, 7), float32)
        node_labels(shape=(10000,), int32)
        train_mask(shape=(10000, 10), bool)
        val_mask(shape=(10000, 10), bool)
        test_mask(shape=(10000, 10), bool))
Source code in mlx_graphs/datasets/heterophilous.py
def __init__(
    self,
    name: HETEROPHILOUS_NAMES,
    base_dir: Optional[str] = None,
    pre_transform: Optional[Callable] = None,
    transform: Optional[Callable] = None,
):
    name = name.lower().replace("-", "_")  # type: ignore
    assert name in get_args(HETEROPHILOUS_NAMES), "Invalid dataset name"
    super().__init__(
        name=name,
        base_dir=base_dir,
        pre_transform=pre_transform,
        transform=transform,
    )

from mlx_graphs.datasets import HeterophilousGraphDataset · mlx_graphs/datasets/heterophilous.py