Neighbor Sampling on Graphs that are not bipartite

Is there anyway to apply this multihoop neighbor sampler which is described in this tutorial Training GNN with Neighbor Sampling for Node Classification — DGL 1.0.2 documentation to a node classification task of single graph where we donot have a separate node features for source and destination nodes. Our features are like g.ndata[‘features’] = features.
Exactly same data as it is mentioned in this link
Node Classification with DGL — DGL 1.0.2 documentation
How can multihoop neighbor sampling be applied on it?

The two tutorials mentioned use different training paradigm as mini-batch training and full-graph training. Neighbor sampling does not require the graph to have separate node features for source and destination nodes. The sampler automatically constructs blocks based on the input graph during sampling. A block is essentially a heterogeneous graph that separates source nodes and target nodes. You can follow the first tutorial to try neighbor sampling. The dataset wouldn’t be an issue.

thanks. how can we divide the cora data in batches in order to train the model in batches? I have one input graph in dgl where edge indexes are present, node features are also present.

The following part is a code snippet to do neighbor sampling on cora dataset.

import dgl
import torch as th

dataset = dgl.data.CoraGraphDataset()
g = dataset[0]
nids = th.arange(g.num_nodes(), dtype=th.long)
train_nids = nids[g.ndata["train_mask"]]

sampler = dgl.dataloading.NeighborSampler([4, 4])
train_dataloader = dgl.dataloading.DataLoader(
    g,  # The graph
    train_nids,  # The node IDs to iterate over in minibatches
    sampler,  # The neighbor sampler
    # The following arguments are inherited from PyTorch DataLoader.
    batch_size=16,  # Batch size
    shuffle=True,  # Whether to shuffle the nodes for every epoch
    drop_last=False,  # Whether to drop the last incomplete batch
    num_workers=0,  # Number of sampler processes
)

for input_nodes, output_nodes, mfgs in train_dataloader:
    ...
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.