TemporalDataLoader
¶
TemporalDataLoader(
data: TemporalData,
batch_size: int = 1,
neg_sampling_ratio: float = 0.0,
drop_last: bool = False,
)
Iterates over the events of a TemporalData
in their stored (time) order, merging batch_size successive events into
a mini-batch, as PyG's torch_geometric.loader.TemporalDataLoader.
Every mini-batch is a TemporalData with an extra
n_id attribute: the sorted unique nodes involved in the batch
(sources, destinations and, if any, negative destinations).
With neg_sampling_ratio > 0, every mini-batch also gets
round(neg_sampling_ratio * batch_size) negative destinations
neg_dst, drawn uniformly (with mx.random, so reproducible with
mx.random.seed) between the smallest and the largest destination node
of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
TemporalData
|
The events to iterate over |
required |
batch_size
|
int
|
Number of events per mini-batch. Default: |
1
|
neg_sampling_ratio
|
float
|
Ratio of sampled negative destinations to positive
destinations. Default: |
0.0
|
drop_last
|
bool
|
Whether to drop the last mini-batch if it has fewer than
|
False
|
Example:
from mlx_graphs.datasets import JODIEDataset
from mlx_graphs.loaders import TemporalDataLoader
data = JODIEDataset("wikipedia")[0]
train_data, val_data, test_data = data.train_val_test_split()
loader = TemporalDataLoader(train_data, batch_size=200, neg_sampling_ratio=1.0)
for batch in loader:
batch.src, batch.dst, batch.neg_dst, batch.n_id
References
Source code in mlx_graphs/loaders/temporal_dataloader.py
from mlx_graphs.loaders import TemporalDataLoader · mlx_graphs/loaders/temporal_dataloader.py