Node Regression in heterograph

I am new to graph neural networks. I am trying to implement a node regression in the heterogenous graph. I tried provided classification model using RGCN and works perfectly. However, I am not being able to convert it to regression, for example, I changed the output feature to length 1 and also the MSE loss function which throws an error regarding loss backpropagation. I am not sure should I add layer after conv layer in RGCN and if that is the case then how should I add as the output of conv layer in RGCN is in the form of a dictionary. Also, if there is any way I can convert GraphSage to hectograph regression model?

1 Like

if you have already had workable RGCN for heterograph classification, you could refer to below FAQ to convert into regression.

How to convert a classification model into a regression model?
You need to change the output size of the model from the number of classes to the number of labels to regress. You will also need to change the loss function and the evaluation metric.

what error did you encounter? could you share more details on how you convert the model?

Thanks for the reply. Yes, I have done those changes as mentioned in the FAQ.

The error after changing output size to 1 and loss function to MSE with provided RGCN model,
RuntimeError: found dtype long but expected float
which was occurred in loss.backward and solved that by converting labels to float.

Now, my question here is I have not changed anything in RGCN model which I am not sure if I should. How can I add any linear layer to the model? And how to convert GraphSAGE model to handle this heterograph case?

How can I add any linear layer to the model?

You just need to add something like self.linear = nn.Linear(in_size, out_size) in the __init__ function and then use self.linear in the forward function.

And how to convert GraphSAGE model to handle this heterograph case?

It depends on whether node/edge types matter to you. If not, you can simply treat the graph as a homogeneous graph.

Thanks!

For the GraphSAGE model, yes, the node type matters in my case. Is there any way I can convert the model to a heterogeneous scenario?

HeteroGraphConv might help. However, extending GraphSAGE to heterogeneous graphs will be very similar to RGCN.

Thanks for all replies, it has been helpful. :slight_smile:

Here is how I added a linear layer to the RGCN model and converted GraphSAGE to a heterogeneous model. Can someone verify if I am doing it correctly?

1 Like

The implementation looks good to me.

1 Like

Thanks for verifying!

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