tkipf / pygcn

Graph Convolutional Networks in PyTorch
MIT License
5.13k stars 1.22k forks source link

Batch operations #1

Open evanfeinberg opened 6 years ago

evanfeinberg commented 6 years ago

Hi @tkipf , excellent work on pygcn! Really nice engineering setting up sparse adjacency multiplications and super clean code. I'm curious to hear how you suggest dealing with batch operations? Unless I am misunderstanding, it looks in train.py that each epoch operates on a single large graph, and the labels are per-node labels. If this interpretation is correct, do you have any suggestions for datasets consisting of many graphs (a series of sparse matrices) each mapped to a graph-level output/label? this would be solved if PyTorch could accept a list of tensors as an input but that does not seem (easily) supported right now. Thanks for any advice!

Cheers, Evan

PS Great to meet you at Stanford a few weeks ago!

tkipf commented 6 years ago

Hi @evanfeinberg, thanks! It was a pleasure meeting you as well. I posted a solution for this problem some time ago in this thread (from the gcn repository): https://github.com/tkipf/gcn/issues/4 . I had an implementation of this some time earlier last year already and if I remember correctly, results were comparable (or sometimes better) when compared to the method by Niepert et al. (ICML 2016) for batch-wise graph classification. So inductive learning with this type of model (contrary to common belief) is indeed very much possible. I haven't put it in the ICLR paper due to time constraints (and spatial constraints).

To re-state the solution over here: multiple graphs can be fed as a single sparse block-diagonal adjacency matrix, and graph-level classification can be done by adding a global "hub" node that is connected to all other nodes (this was suggested already back in 2009 by Scarselli et al.).

evanfeinberg commented 6 years ago

Thank you for the speedy response, @tkipf ! The workaround of a block diagonal sparse matrix consisting of individual adjacency matrices makes a lot of sense. I will try and report back!

idansc commented 6 years ago

@tkipf thanks for the package, it is really useful. Will it be possible to share your code that switches a batch of graphs into a diagonal blocks matrix. I found a scipy implementation. But maybe you managed to use a pytorch built-in functions, which will be much more efficient.

tkipf commented 6 years ago

I don’t have an implementation for this, unfortunately. On Sat 21. Apr 2018 at 12:06 idansc notifications@github.com wrote:

@tkipf https://github.com/tkipf thanks for the package, it is really useful. Will it be possible to share your code that switches a batch of graphs into a diagonal blocks matrix. I found a scipy implementation. But maybe you managed to use a pytorch built-in functions, which will be much more efficient.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tkipf/pygcn/issues/1#issuecomment-383282818, or mute the thread https://github.com/notifications/unsubscribe-auth/AHAcYKInXPnq6YoLJ13UYz2os79dbeFAks5tqwSggaJpZM4QNhT7 .

malizheng commented 6 years ago

@idansc Hi, can you provide a link address code for the scipy implementation ?

idansc commented 6 years ago

@malizheng see scipy.linalg.block_diag