Is it possible to use LSTM in the graph classification instead of using mean_nodes with variable sized graphs?

Hello everyone

i was wondering is it possible to use LSTM instead of mean_nodes, to do graph classification when input graphs have variable sizes (nodes/edges) ? so basically each node representation is a word, and each directed graph has a start/root node, so i guess to generate the node representation sequence i can use BFS, then give the sequence to LSTM, but i am not sure how to implement it with dgl.

if it is possible, is there any downside to this approach compared to averaging the node representations?

and if it is possible, can someone show me to right way to do it in pytorch? this is my forward() right now:

def forward(self, g , h):
    for i, layer in enumerate(self.layers):
        if i != 0:
            h = self.dropout(h)
        h = layer(g, h)
    g.ndata['h'] = h
    hg = dgl.mean_nodes(g, 'h')
    return  self.classify(hg)
  1. You can use bfs_nodes_generator to get the traversal sequence using BFS. It should probably be listed in the API reference manual.
  2. I think it’s hard to say whether this approach will have advantages over averaging the node representations before an ablation study. One possible argument is that this better captures the dependency between nodes.
1 Like