Graph classification with Heteregenous graph

I have a dataset of heterogeneous graphs with several node types and edge types.
Not all every graph got every types.
i tried this tutorial: https://docs.dgl.ai/guide/training-graph.html#guide-training-graph-classification
and specifically tried to use the HeteroClassifier described here: https://docs.dgl.ai/guide/training-graph.html#heterogeneous-graph.

in get an exception in this line:
hg = hg + dgl.mean_nodes(g, 'h', ntype=ntype)

The exception is:
RuntimeError: The size of tensor a (50) must match the size of tensor b (64) at non-singleton dimension 0

and after a little debugging I noticed that the size of the output of dgl.mean_nodes is as the number of graphs that had the specific ntype.
is that as expected?
what is your suggestion if not all of my graphs has all of the ntypes?

One possible thing to do is to use zero-tensors for heterographs without a particular node type in readout. For the time being, you can use a placeholder node for each graph without the particular node type.

Thank you for you answer!

Regard your second suggestion - so if i understand correctly, just add a singleton node without connections from the missing ntype?

I didn’t understand you first suggestion if you can please elaborate :pray:

Regard your second suggestion - so if i understand correctly, just add a singleton node without connections from the missing ntype?

Yes, and you can use tensors of 0 for the features of the singleton nodes.

One possible thing to do is to use zero-tensors for heterographs without a particular node type in readout.

That’s a possible change to make on DGL side, so that the output of any built-in readout function wiill always be the total number of graphs in the batch.

Thank you very much i’ll give it a shot!

Hi, I want to ask a simple question:Is heterogeneous graph learning updated according to the type of edge?

RGCN can’t achieve my expected effect. Is there a better heterogeneous graph learning method in DGL?

You may want to try HAN and HGT.