How do I predict node category on new data with a hypergraph classifier?

After following your tutorial here, I’m trying to figure out how to make a prediction on one node (as if I was presenting an out of sample node and wanted to predict its category).

I feel I’m probably doing something very wrong but I can’t work it out.

This is what I am doing:

print(X.shape) # torch.Size([2708, 1433])
one_node = X[[0]]

print(one_node.shape) # torch.Size([1, 1433])
model(one_node)

Last line errors with:

RuntimeError: SpMM: Invalid input shapes. sparse_mat: [2708, 2708], sparse_val: [99596], dense_mat: [1, 16]. Valid input shapes (sparse_mat, dense_mat) are: (1) (n, m) and (m, k); (2) (n, m) and (m,); (3) (n, m, b) and (m, k, b).

I can’t figure out from that error the correct Tensor shape I’m supposed to pass in. Would really appreciate an example of what it looks like to then predict on the category of an out of sample node.

After testing more looks like I can only call model on graph of same shape since as input it requires all nodes and their features. I’m wondering how I would productionise therefore.

The use case I’m interested in is predicting the category of a new node. Ideally as input I would supply one node, its features and all the hyper edges it is in.

Is that possible?

Otherwise I worry I will have to retrain the model everytime new nodes are added.

Hi @osintalex , sorry for the late reply as it’s Chinese holiday last week.

As the error message shows, the issue is the mismatch of the input shapes. The sparse matrix is of shape (2708, 2708) so it is not possible to multiply it with a dense matrix of shape (1, 1433).

The use case I’m interested in is predicting the category of a new node. Ideally as input I would supply one node, its features and all the hyper edges it is in.

In your use case, if you’d like to make prediction about one new node, you not only need the feature of that node and all the hyper edges but also the features of the nodes it connect to via those hyper edges. Otherwise, there is no way to collect information from them. Therefore, what you need to prepare is:

  • A sparse matrix of shape (1, 2708) which stores the hyper edges of the nodes you’d like to predict.
  • A dense matrix of shape (2708, 1433) which stores the node features to collect and aggregate from.

Once you multiply those two matrices, you will get a dense matrix of shape (1, 1433) which is the aggregated features of the node’s neighbors.

1 Like

Thank you, that makes sense. Hope you had a good holiday!

In that case, would final code to get the prediction on the node I want look something like this:

# X is the node features
print(X.shape) # torch.Size([2708, 1433])
# model I have trained on node features 
# and hyperedges according to your tutorial
y_hat = model(X)
predicted_label_on_my_node = y_hat[<some index>]

And I would just make sure the index position of my node is included in the test mask?

Yes, that’s also a viable way.

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