Feature-wise Visualisation of Attention Weights

Context
I trying to perform semi-supervised node classification using a multi-head GAT. So far I have it working producing reasonable labels both with random features and with real features. However, I’m wanting to better understand and visualise the attention weights learned by the network.

I’ve seen the post on the visualisation of edge attention weights, which is not really what I’m after. I also read @mufeili papers on the statistical characterization of attention in graph neural networks[1][2] and read a related post here. These are great in terms of understanding the importance of a given edge or node within your graph.

Specifically though I’m interested in visualizing the weights of the attention heads of the different layers as they pertain/transform the input features.

Questions
Is there any relevant discourse anyone would recommend regarding visualising feature wise attention scores/filters in a graph? And is this broadly possible?

What are the three keys in the state_dict accessed per the example below of a trained GATConv Layer?

  • attn_l
  • attn_r
  • fc.weight
model.layers[0].state_dict()
1 Like
  1. It sounds like what you are looking for is a general approach to measure the importance of input node features, regardless of the GNN. For example, GNNExplainer allows you to do so. You should be able to find more papers on this problem.
  2. We decompose \alpha^{T}[Wh_{i}||Wh_{j}] from equation (3) in the paper into \text{attn_l} Wh_i+\text{attn_r}Wh_j, which is mathematically equivalent to the original formulation. fc.weight corresponds to the weight matrix introduced at the beginning of 2.1 in the paper.
1 Like

Hi thanks for this answer, it’s right on the money.

There is an implementation of GNN - Explainer in Pytorch Geometric. I did some preliminary testing and found it not particularly useful for my datasets. For others who find this post there is a pretty useful survey paper on Explainable GNNs.

@mufeili are there any plans to extend DGL to cover some of the common GNN explainers?

Yes, DGL should definitely have more explanation examples.