OGBMAG
¶
OGBMAG(
base_dir: Optional[str] = None,
transform: Optional[Callable] = None,
pre_transform: Optional[Callable] = None,
)
Bases: HeteroDataset
The ogbn-mag dataset from the "Open Graph Benchmark: Datasets for Machine Learning on Graphs" paper, a
heterogeneous subset of the Microsoft Academic Graph, as PyG's
OGB_MAG.
It has four node types: papers (736,389), authors (1,134,649),
institutions (8,740) and fields of study (59,965), and four edge types:
author -affiliated_with-> institution, author -writes-> paper,
paper -cites-> paper and paper -has_topic-> field_of_study
(21.1M edges in total). The task is to predict the venue (349 classes) of
each paper. Papers have 128-dimensional word2vec features and a
publication year; the other node types have no features. The split is by
year (train: until 2017, validation: 2018, test: 2019).
The graph is a HeteroGraphData with:
edge_index_dict: the four edge types (int32, no reverse edges; message passing models such asto_hetero()need reverse edge types so that every node type receives messages, seeadd_reverse_edges()),node_features_dict["paper"]([736389, 128]) andnode_labels_dict["paper"]([736389]),num_nodes_dictwith the number of nodes of every node type,paper_yearand the boolean maskspaper_train_mask,paper_val_maskandpaper_test_mask.
The raw data (a 430 MB download) is read with pandas. The processed
graph is stored as safetensors and loaded lazily.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_dir
|
Optional[str]
|
Directory where to store dataset files. Default is
in the local directory |
None
|
transform
|
Optional[Callable]
|
A function/transform that takes in a |
None
|
pre_transform
|
Optional[Callable]
|
A function/transform applied before saving the processed data. |
None
|
Example:
from mlx_graphs.datasets import OGBMAG
from mlx_graphs.loaders import HGTLoader
data = OGBMAG.add_reverse_edges(OGBMAG()[0])
loader = HGTLoader(
data,
num_samples=[512] * 2,
input_nodes=("paper", data.paper_train_mask),
batch_size=1024,
)
References
Methods:
| Name | Description |
|---|---|
add_reverse_edges |
Adds a reverse edge type |
Source code in mlx_graphs/datasets/ogb_mag.py
add_reverse_edges
staticmethod
¶
Adds a reverse edge type (dst, "rev_<rel>", src) for every edge
type between two different node types, and makes paper -cites->
paper undirected (both directions, duplicates removed), like PyG's
ToUndirected transform, so that every node type receives messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
HeteroGraphData
|
The ogbn-mag graph. |
required |
Returns:
| Type | Description |
|---|---|
HeteroGraphData
|
The same graph, with the new edge types. |
Source code in mlx_graphs/datasets/ogb_mag.py
from mlx_graphs.datasets import OGBMAG · mlx_graphs/datasets/ogb_mag.py