pytorch_geometric
pytorch_geometric copied to clipboard
how can I use 'edge_weight' in GAT?
❓ 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?
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.
Ok, I will try!
@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!
+1 for this!
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
Since this is a popular request, do you want to contribute your solution directly to PyG @dongkwan-kim?
@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 currentGATConv
I think adding an edge_attr
argument to GATConv
is the way to go.
Hi, I tried to include the edge_attr into the GATConv part, but I will receive this error:
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.
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.