TGBNodePropPredDataset
¶
TGBNodePropPredDataset(
name: str,
base_dir: Optional[str] = None,
pre_transform: Optional[Callable] = None,
transform: Optional[Callable] = None,
)
Bases: _TGBDataset
The dynamic node property prediction datasets of the Temporal Graph Benchmark (TGB), as py-tgb's
tgb.nodeproppred.dataset_pyg.PyGNodePropPredDataset.
The dataset is a single TemporalData stream of
weighted events sorted by time (msg holds the weights), split
chronologically (train_mask, val_mask, test_mask). The task is
to predict, at given timestamps, the distribution of the future
interactions of some nodes over num_classes items (e.g. the share of
each trading partner of a nation the next year, or of each music genre
of a user the next week), evaluated with NDCG@10
(TGBEvaluator).
The labels form a stream of label timestamps (label_timestamps).
As in py-tgb, get_node_label() returns the labels of the next
label timestamp once the events reach it, and reset_label_time()
rewinds the stream at the start of every pass over the events.
node_labels() gives the labels of any label timestamp directly.
================= ========== =========== ========= ==========
Name #nodes #events #classes #features
================= ========== =========== ========= ==========
"tgbn-trade" 255 468,245 255 1
"tgbn-genre" 1,505 17,858,395 513 1
"tgbn-reddit" 11,766 27,174,118 698 1
"tgbn-token" 61,756 72,936,998 1,001 2
================= ========== =========== ========= ==========
The node ids are those of py-tgb: the classes (genres, subreddits,
tokens) are the nodes 0 to num_classes - 1 and the users are
numbered after them; the nations of "tgbn-trade" are both the nodes
and the classes. The features are the edge weights (and, for
"tgbn-token", whether the user is the sender), with the natural
logarithm of the weights for "tgbn-token" (as py-tgb once its
processed files are cached).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the dataset, e.g. |
required |
base_dir
|
Optional[str]
|
Directory where to store dataset files. Default is
in the local directory |
None
|
pre_transform
|
Optional[Callable]
|
A function/transform applied to the |
None
|
transform
|
Optional[Callable]
|
A function/transform applied to the |
None
|
Example:
from mlx_graphs.datasets import TGBNodePropPredDataset
from mlx_graphs.loaders import TemporalDataLoader
dataset = TGBNodePropPredDataset("tgbn-trade")
data = dataset[0]
train_data = data[dataset.train_mask]
dataset.reset_label_time()
label_t = dataset.get_label_time()
for batch in TemporalDataLoader(train_data, batch_size=200):
query_t = batch.t[-1].item()
if query_t > label_t:
label_ts, label_nodes, labels = dataset.get_node_label(query_t)
label_t = dataset.get_label_time()
... # predict `labels` [num_label_nodes, num_classes]
References
Methods:
| Name | Description |
|---|---|
node_labels |
The node labels of the |
get_node_label |
The labels of the next label timestamp if |
get_label_time |
The next label timestamp of the stream (the last one once the |
reset_label_time |
Rewinds the label stream to the first label timestamp. |
Attributes:
| Name | Type | Description |
|---|---|---|
num_classes |
int
|
The number of classes of the node labels (as |
label_dim |
int
|
The size of the label vectors (the number of classes seen in the |
label_timestamps |
ndarray
|
The sorted timestamps at which there are node labels. |
num_label_timestamps |
int
|
The number of label timestamps. |
Source code in mlx_graphs/datasets/tgb.py
label_dim
property
¶
label_dim: int
The size of the label vectors (the number of classes seen in the
events, at most num_classes).
label_timestamps
property
¶
label_timestamps: ndarray
The sorted timestamps at which there are node labels.
node_labels
¶
The node labels of the i-th label timestamp.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
i
|
int
|
Index in |
required |
Returns:
| Type | Description |
|---|---|
array
|
The timestamp repeated for every labeled node, the labeled nodes, |
array
|
and their label vectors (float32, shape |
array
|
in the order of |
Source code in mlx_graphs/datasets/tgb.py
get_node_label
¶
The labels of the next label timestamp if cur_t reached it, as
py-tgb's get_node_label: the label stream then moves to the
following label timestamp. Returns None otherwise (or after the
last label timestamp).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cur_t
|
Union[int, array]
|
The current time (e.g. the time of the last event of a mini-batch) |
required |
Returns:
| Type | Description |
|---|---|
Optional[tuple[array, array, array]]
|
|
Source code in mlx_graphs/datasets/tgb.py
from mlx_graphs.datasets import TGBNodePropPredDataset · mlx_graphs/datasets/tgb.py