muhanzhang / SEAL

SEAL (learning from Subgraphs, Embeddings, and Attributes for Link prediction). "M. Zhang, Y. Chen, Link Prediction Based on Graph Neural Networks, NeurIPS 2018 spotlight".
607 stars 142 forks source link

Access the nodes and edges from the subgraph #73

Closed zackzhou0814 closed 2 years ago

zackzhou0814 commented 2 years ago

Hi Dr.Zhang I have been studying your code for a while, and I understand that you have a function called links2subgraph that generates the subgraphs that can be fed into the network. When I print out the train_graphs, it gives me a list that contains many objects like <util.GNNGraph object at 0x7f30f7ab5d30>, does it mean that it's a subgraph of one link? If it is the case, I want to get the actual nodes and edges from this graph. For example, I want [1,2,3,4], which are the nodes in a subgraph, and [(1,2),(3,4)] are the edges; how should I obtain these lists?
Also, in the Classifier class, is the batch_graph(in the forward function) the train_graph/g_list? Just want to make sure I understand that correctly. Thank you very much!

muhanzhang commented 2 years ago

Yes, it is a subgraph of each link. The GNNGraph object is defined here. It contains a networkx graph which can recover the node/edge information you need. The batch_graph is constructed here. It contains a batch of graphs from g_list, not the full g_list, for mini-batch training.

zackzhou0814 commented 2 years ago

Thank you very much for the clarification, that was very helpful! I still have one more question that I want to be clear about. In the paper, you mentioned that a network would take (A,X), where A is an adjacency matrix of a subgraph, and I'm looking for this matrix in your code, is it the edge_pairs in GNNGraph, or do we need to manually construct the matrix using the edges in the graph? Thank you!