About the different node types of R-GCNs

class StochasticTwoLayerRGCN(nn.Module):
   def __init__(self, in_feat, hidden_feat, out_feat, rel_names):
       super().__init__()
       self.conv1 = dglnn.HeteroGraphConv({
               rel[1] : dglnn.GraphConv(in_feat[rel[0]], hidden_feat, norm='right')
               for rel in rel_names
           })
       self.conv2 = dglnn.HeteroGraphConv({
               rel[1] : dglnn.GraphConv(hidden_feat, out_feat, norm='right')
               for rel in rel_names
           })

   def forward(self, blocks, x):
       x = self.conv1(blocks[0], x)
       x = self.conv2(blocks[1], x)
       return x

in_features = {'user':n_hetero_features, 'item':2*n_hetero_features}

I have a heterogeneous graph that contains two types of nodes and one type of edge. As shown above, ‘user’ has n_hetero_features dimensional features and ‘item’ has 2*n_hetero_features dimensional features. Can you please tell me if the RGCN module I constructed above implements the function of dividing two different types of nodes into two different subgraphs, each containing only one type of node, and then performing separate convolution operations within the same type of node.

By the way, what if my heterogeneous graph is a heterogeneous bipartite graph? That is, there will be no edges between nodes of the same type, at which point what happens when the RGCN module constructed above is applied?

I would be grateful if you could get an answer!

Hi @TheWind . I would like to clarify some notations used in DGL.

  • A heterogeneous graph contains nodes and edges with various types. An edge type connects two node types, which could be the same. In you example, you have a graph with two node types, i.e., ‘user’ and ‘item’, and an edge type, possibly (‘user’, ‘use’, ‘item’). So you cannot separate two types of nodes into two subgraphs.
  • The RGCN model computes the convolutions on some edge types instead of node types. That means the rel_names in the example describes the name of different edge types. To apply RGCN correctly, you need to define one HeteroGraphConv on all edge types.

Thank you very much for your answer!

My code example section does not show everything. In fact, there are two types of edges in total for my heterogeneous image, one for (‘user’, ‘click’, ‘item’) and the other for (‘item’, ‘clicked-by’, ‘user’). In the rel_names I also passed in both types of edges. I would like to ask further if my heterogeneous graph has no edges between homogeneous nodes and only edges between heterogeneous nodes (i.e. no connection between user and user, and the same for item), will the RGCN module still work in this case?

Sure. It still works. Actually it is a common case.

Thanks so so so so much again!!! :people_hugging:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.