pytorch_geometric icon indicating copy to clipboard operation
pytorch_geometric copied to clipboard

how can I use 'edge_weight' in GAT?

Open xxp17457741 opened this issue 5 years ago • 10 comments

❓ Questions & Help

I have a graph that contains edge_weight, so I want to use it in GATConv. But I fail to do it because in gat_conv.py there is no edge_weight parameters. So how can I do what I want to do?

xxp17457741 avatar Nov 20 '19 11:11 xxp17457741

It might be best to implement your own GATConv where attention is not only computed based on node features, but also based on edge weights.

rusty1s avatar Nov 20 '19 11:11 rusty1s

Ok, I will try!

xxp17457741 avatar Nov 20 '19 11:11 xxp17457741

@xxp17457741 Hi, we are facing same situation like you as we also need to consider egde weight within the GATConv layer. Have you ever implemented your own GATConv module and could share it? If so, I would very much appreciate!

heartcored98 avatar Jan 30 '20 08:01 heartcored98

+1 for this!

bluelancer avatar Aug 20 '21 11:08 bluelancer

I recently wrote GATEdgeConv that uses edge_attr in computing attention coefficients for my own good. It generates attention weights from the concatenation of x_i, x_j, and edge_attr in a similar manner with the original GATConv. This layer can take edge_weight as an input by setting edge_dim to one.

https://github.com/dongkwan-kim/GATEdgeConv

dongkwan-kim avatar Sep 03 '21 08:09 dongkwan-kim

Since this is a popular request, do you want to contribute your solution directly to PyG @dongkwan-kim?

rusty1s avatar Sep 03 '21 10:09 rusty1s

@rusty1s I have not sent PR since I have not found the right reference for this layer. But if you think it is worth including this layer in PyG, I would happy to work on it.

One quick question. My current version inherits the GATConv, but I do not think this is the best choice for this layer. I am considering three options. What do you think?

  • GATEdgeConv(GATConv)
  • GATEdgeConv(MessagePassing)
  • Add edge_attr-related options to the current GATConv

dongkwan-kim avatar Sep 03 '21 12:09 dongkwan-kim

I think adding an edge_attr argument to GATConv is the way to go.

rusty1s avatar Sep 03 '21 13:09 rusty1s

Hi, I tried to include the edge_attr into the GATConv part, but I will receive this error: image Why do we need this lin_edge to help us achieve this target?Are there any tutorials to help us understand GAT with edge attributes? Thanks a lot.

HelloWorldLTY avatar Sep 12 '22 23:09 HelloWorldLTY

The linear layer will project the edge features to the correct shape. If this error occurs for you, it likely means you forgot to set the edge_dim property in the GATConv constructor. We can make this more explicit in the code.

rusty1s avatar Sep 13 '22 03:09 rusty1s