tkipf / gcn

Implementation of Graph Convolutional Networks in TensorFlow
MIT License
7.11k stars 2k forks source link

Reproduce the karate club example #64

Open riccardobucco opened 5 years ago

riccardobucco commented 5 years ago

Hi Thomas, I'm trying to reproduce the karate club example of your paper using the code of this repo. I can't understand how the data should be saved to match your load_data function. For example, what about the features of the training/test nodes? I know that the X matrix should be the Identity one, but what's its size? I would appreciate some help, thanks!

tkipf commented 5 years ago

Have a look here: https://github.com/tkipf/gcn/issues/12

On Tue 30. Oct 2018 at 16:50 Riccardo Bucco notifications@github.com wrote:

Hi Thomas, I'm trying to reproduce the karate club example of your paper using the code of this repo. I can't understand how the data should be saved to match your load_data function. For example, what about the features of the training/test nodes? I know that the X matrix should be the Identity one, but what's its size? I would appreciate some help, thanks!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/tkipf/gcn/issues/64, or mute the thread https://github.com/notifications/unsubscribe-auth/AHAcYA4I9kc_ZUywpLxQm8uft71fKyZtks5uqHVUgaJpZM4YCP4M .

riccardobucco commented 5 years ago

Sorry for the trivial question.. Which nodes did you use for training/validating/testing? I'm trying to build the three datasets (and respective masks) and i'm not sure about the steps. So far I have understood what follows:

Is it correct? Now, how can I build the three datasets? I don't know if I'm wrong: in your example you labeled only 4 nodes, but you train using also the others (so the training set has N nodes, 4 of which are labeled). This means that y_train must have only 4 vectors using the onehot encoding, while train_mask must have all the elements set to True? Then you test against the previously unlabeled nodes (N-4), right? So y_test will have only 4 vectors set to zero and test_mask will have the 4 corresponding values set to False. And what about the validation set? You don't use it, do you?

Thanks in advance, and sorry for making trivial questions.

tkipf commented 5 years ago

You can simply set y_train=y_val=y_test and also provide the full adjacency matrix and the full feature matrix (i.e., an identity matrix) during training and testing. It suffices to simply provide train_mask with elements set to True for all nodes that should receive supervision and False otherwise.

riccardobucco commented 5 years ago

Thanks. Also, does this approach work only with a fixed graph? I mean, let's say I want to add a single node to the graph: do I have to train everything again in order to predict the category of this new node?

tkipf commented 5 years ago

You can make predictions on new nodes if their feature vectors come from a similar underlying distribution. If you take unique one-hot vectors as feature vectors (i.e., an identity matrix), then this is not possible (the prediction would mostly be just random).

riccardobucco commented 5 years ago

What's the dimension of the three layers?

  1. input --> 34, output --> out1
  2. input --> out1, output --> out2
  3. input --> out2, output --> 2

out2 is 4 right? What about the output dimension of the first layer (out1)? Also, the three activation functions are tanh, right?

tkipf commented 5 years ago

Yes and yes!

On 5 Nov 2018, at 13:24, Riccardo Bucco notifications@github.com wrote:

What's the dimension of the three layers?

input --> 34, output --> out1 input --> out1, output --> out2 input --> out2, output --> 2 out2 is 4 right? What about the output dimension of the first layer (out1)? Also, the three activation functions are tanh, right?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/tkipf/gcn/issues/64#issuecomment-435856164, or mute the thread https://github.com/notifications/unsubscribe-auth/AHAcYM25ji5spVuklCJi_bquUS4siU61ks5usC3ogaJpZM4YCP4M.

riccardobucco commented 5 years ago

what about the out1 dimension? I can't find its value anywhere

tkipf commented 5 years ago

Same

On Mon 5. Nov 2018 at 14:53 Riccardo Bucco notifications@github.com wrote:

what about the out1 dimension? I can't find its value anywhere

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/tkipf/gcn/issues/64#issuecomment-435881793, or mute the thread https://github.com/notifications/unsubscribe-auth/AHAcYAvmbnxoXqsW0_5aRPV9jRzfGoa5ks5usELugaJpZM4YCP4M .

AugF commented 5 years ago

Sorry to bother you, thanks for your code! It has given me lots of help. But when I try using the karate dataset, I am still confused for two trivial questions:

  1. could you give me the code about y_train, y_val, y_test, i still don't know what to do.
  2. how to calculate the loss, in "out2", because your paper said using cross-entropy loss. So i think the dim should be the same, but how to update the weight of the layer "output -> 2"? (my commits may have some grammer mistakes, sorry for it)
Abhinav43 commented 5 years ago

@AugF did you find the solution?

I am also looking for code of y_train, y_val, y_test for karate club.

Thanks in advance !