Edge classification/regression using Pytorch Geometric? #3554
-
Hello. I would like to do edge regression in Pytorch Geometric. I've only found information about it in DGL. (link) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
That is actually quite simple in PyG as well: x = ... # Node feature matrix: [num_nodes, num_features]
edge_index = ... # Edge indices: [2, num_edges]
src, dst = edge_index
score = (x[src] * x[dst]).sum(dim=-1)
loss = F.cross_entropy(score, data.edge_label) # Classification
loss = F.mse_loss(score, data.edge_value) # Regression |
Beta Was this translation helpful? Give feedback.
-
Hi rusty1s, Wouldn't this work only if there was a single edge from node to node? What happens if there were multiple edges between two nodes? One approach I can think of is to use edge embeddings. If we could extract the edge embeddings (for example in GATConv) then we could build a classification layer given the edge embedding. Any ideas how to extract the edge embeddings from the GATConv layer? thanks |
Beta Was this translation helpful? Give feedback.
That is actually quite simple in PyG as well: