Is there a way to add edge features when negative edge sampling?

Hi,

I meet a problem when constructing link prediction model with negative edge sampling. I want to add some features to the edges of negative graph, and these feature are computed out when sampling (i.e. in the __call__ function of negative sampler), which are needed for the later negative score computation. However what __call__ function return are only src and dst nodes. Could you give me some advice about how should I implement this need?

Thank you very much.

How can you have “edge features” for non-existing edges? One possibility is to add edge features after loading the graph for the negative samples from the data loader.

That is mainly about my sampling strategy. In my model, I assign a latent type for every edge and I will sample negative src/dst nodes according to this latent edge type. If only src and dst nodes are returned by the __call__ function, I will lose this edge information. Because what I construct is multigraph, I will not know how these negative nodes are generated, which will influence my later negative score computing (because also I consider the different update weights for different negative samples, and this weight is computed when sampling).

I’ve taken into account using hetero graph, but I think first it is not an explict edge type but more like a feature, second hetero graph will make my code much more complex, so I prefer to use homogeneous graph.

In fact, I think this is an effective need if you want to consider more flexible negative sampling strategies. And I guess if it is possible to give users power to construct neg graph in __call__ function and directly return it, which maybe a solution.

In this case I’m afraid that you will have to change the code of EdgeCollator directly. Negative graph is constructed here: https://github.com/dmlc/dgl/blob/master/python/dgl/dataloading/dataloader.py#L607-L619

You may add edge features here.