Visualize Node Importance with Attention while doing Graph Embedding

username: Sajjad_Hossain
cooked: <p>I am quite new to the concept of attention. I am working with graph data and running graph convolution on it to learn node level embedding first. Then an attention layer to aggregate the nodes to learn a graph level embedding. Here is the setup:</p>
<p>graph-&gt;Conv1(Filter size 128)-&gt;Conv2-(Filter size 64&gt;Conv3(Filter size 32) -&gt; Attention -&gt; Some other layers</p>
<p>After three convolution pass i get a matrix of size number_of_nodes_in_the_graph X 32 (embedding length). After the attention layer i get a flat vector representation of the graph with length 32. Here is the forward function of the attention module:</p>
<pre><code class="lang-auto">    def forward(self, embedding):
        """
        Making a forward propagation pass to create a graph level representation.
        :param embedding: Result of the GCN.
        :return representation: A graph level representation vector. 
        """
        global_context = torch.mean(torch.matmul(embedding, self.weight_matrix), dim=0)
        # print("Gloabal Context:", global_context.shape)

        transformed_global = torch.tanh(global_context)
        # print("transformed_global Context:", transformed_global.shape)

        sigmoid_scores = torch.sigmoid(torch.mm(embedding,transformed_global.view(-1,1)))
        # print("sigmoid_scores Context:", sigmoid_scores)

        representation = torch.mm(torch.t(embedding),sigmoid_scores)
        return representation, transformed_global
</code></pre>
<p>Now i would like to see which graph nodes were important for the final graph embedding. I am using pytorch for this. I cannot seem to figure out how to map the attention output to input. I would greatly appreciate any help! I am using this repo: <a href="https://github.com/benedekrozemberczki/SimGNN" rel="nofollow noopener">https://github.com/benedekrozemberczki/SimGNN</a></p>

username: Narine_Kokhlikyan
cooked: <p>Hi <a class="mention" href="/u/sajjad_hossain">@Sajjad_Hossain</a>, Are you considering to apply attribution algorithms to the outputs with respect to the inputs in order to compute importance scores ? What kind of importance are you’re looking for ?</p>
<p>We have a library for model interpretability that allows to attribute the output target to the inputs or neurons of the network. Is that something that can be useful for you?</p>
<aside class="onebox whitelistedgeneric">
  <header class="source">
      <img src="https://github.githubassets.com/favicon.ico" class="site-icon" width="16" height="16">
      <a href="https://github.com/pytorch/captum" target="_blank" rel="nofollow noopener">GitHub</a>
  </header>
  <article class="onebox-body">
    <img src="https://avatars2.githubusercontent.com/u/21003710?s=400&amp;v=4" class="thumbnail onebox-avatar" width="60" height="60">

<h3><a href="https://github.com/pytorch/captum" target="_blank" rel="nofollow noopener">pytorch/captum</a></h3>

<p>Model interpretability and understanding for PyTorch - pytorch/captum</p>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>


username: Sajjad_Hossain
cooked: <p>Hello <a class="mention" href="/u/narine_kokhlikyan">@Narine_Kokhlikyan</a> thank you very much for your reply. I am particularly not looking for attribution score but this is really interesting. I am just looking to understand the how the attention mechanism is playing the role here. Which specific variable (attention weight, activation, gradient or something else) will provide intuition about which node embedding vector contributed to the final graph embedding.</p>