gcn icon indicating copy to clipboard operation
gcn copied to clipboard

Reproduce the karate club example

Open riccardobucco opened this issue 7 years ago • 11 comments

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!

riccardobucco avatar Oct 30 '18 15:10 riccardobucco

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

On Tue 30. Oct 2018 at 16:50 Riccardo Bucco [email protected] 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 .

tkipf avatar Oct 30 '18 15:10 tkipf

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:

  • adj is the adjacency matrix of the graph, with all the nodes (it doesn't matter if they are part of the train/validation/test dataset). Therefore the dimension is NxN, where N is the total number of the nodes in the three datasets.
  • features is an NxD matrix, but in this case is an NxN identity matrix (again, with N=total number of nodes in the three dataset)
  • y_train, y_val and y_test are NxC matrices (C=number of categories), containing zero vectors if the corresponding element in train_mask, val_mask and test_mask is False, or the onehot encode if the corresponding element in the masks is True

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.

riccardobucco avatar Oct 31 '18 09:10 riccardobucco

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.

tkipf avatar Oct 31 '18 09:10 tkipf

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?

riccardobucco avatar Oct 31 '18 09:10 riccardobucco

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).

tkipf avatar Oct 31 '18 09:10 tkipf

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?

riccardobucco avatar Nov 05 '18 12:11 riccardobucco

Yes and yes!

On 5 Nov 2018, at 13:24, Riccardo Bucco [email protected] 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.

tkipf avatar Nov 05 '18 13:11 tkipf

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

riccardobucco avatar Nov 05 '18 13:11 riccardobucco

Same

On Mon 5. Nov 2018 at 14:53 Riccardo Bucco [email protected] 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 .

tkipf avatar Nov 05 '18 13:11 tkipf

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)

AugF avatar Sep 30 '19 12:09 AugF

@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 !

Abhinav43 avatar Sep 30 '19 16:09 Abhinav43