[module usage help]Negative Samplers for Link predction

https://docs.dgl.ai/en/latest/api/python/dgl.dataloading.html#negative-samplers-for-link-prediction

Want to sampler (negative sampler~ ) for link prediction at bipartite graph(non-asymmetric graph)

i didn’t understand dgl.dataloading.negative_sampler.Uniform(k) 's parameters;

conceretly, how can i adapt my graph at proper the call module(g,eids) ?!

In my graph attribute is here,

g.nodes(’_U’)
return tensor([…])

g.nodes(’_P’)
return tensor([…])

g_m2.edges()
return tensor([…])
return tensor([…])

graph

Graph(num_nodes={’_U’: 11268, ‘_P’: 1664},
num_edges=({’_U’, ‘_B’, ‘_P’}): 323897},
metagraph={(’_U’, ‘_P’, ‘_B’})

then my question

g_m2 is my graph data

neg_samler = dgl.dataloading.negative_sampler.Uniform(2)
neg_sampler(g_m2, [0, 91])

Error message ; ‘list’ object has no attribute ‘shape’

and thus try that
list(zip(g.edges()[0] , g.edges()[1]))[0]
→ src, dst edge [0]

then happen same

what could i input them properthem?

Could you try neg_sampler(g_m2, torch.tensor([0, 91]))?

1 Like

Thanks!

that code works normally! :slight_smile:

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