How to get the Node ID in Edge DataLoader

I have a dataloader similar to the node classification example in the training stochastic graphs tutorial. I am trying to get the Node ID of a specific set of nodes in my dataloader, but cannot figure out how to do it.

for iteration_dc, (input_nodes_dc, output_nodes_dc, blocks_dc) in enumerate(dataloader_dc):

    blocks_dc = [b.to(device) for b in blocks_dc]
    print(blocks_dc[-1].dstdata)

That print statement gives me an output like:

{'article': {'article_embedding': tensor([[0.3339, 0.0341, 0.4631,  ..., 0.6191, 0.8248, 0.6409],
        [0.5585, 0.5669, 0.1242,  ..., 0.7098, 0.8144, 0.4294],
        [0.8055, 0.8541, 0.6047,  ..., 0.9998, 0.9887, 0.3516],
        ...,
        [0.1683, 0.6837, 0.2975,  ..., 0.5422, 0.1945, 0.9496],
        [0.1005, 0.1475, 0.7454,  ..., 0.6103, 0.0443, 0.4182],
        [0.9609, 0.7264, 0.0379,  ..., 0.0655, 0.3733, 0.7715]],
       device='cuda:0'), '_ID': tensor([ 7123, 11419,  6840,  ...,  5984,  9641,  4356], device='cuda:0')}, 'source': {'source_embedding': tensor([], device='cuda:0', size=(0, 778)), 'source_label': tensor([], device='cuda:0', size=(0, 1))}, 'user': {'user_embedding': tensor([], device='cuda:0', size=(0, 773)), '_ID': tensor([], device='cuda:0', dtype=torch.int64)}}

I can see that the article node ID is indexed here, but when I try to index it like so: print(blocks_dc[-1].dstdata['article']['_ID']), it says key not found.

I basically want to get the ID so that I can determine which to the source it is connected to and figure out the label for the article from that (as I didn’t store it as an edge feature in the graph).

1 Like

Hi @hockeybro12, thanks for this question! I have literally the same issue, yet if it is another application, in my post here. If you find an answer, this would also help me - and many others potentially!

Sorry for the late reply. Could you try

blocks_dc[-1].dstnodes['article'].data['_ID']

or

blocks_dc[-1].dstdata['_ID']['article']

The result from the print statement is wrong. We will fix that.

1 Like

Thanks, that works! And thanks for fixing it!