liveBook · Manning

Attention

As explained in Graph Neural Networks in Action

An attention mechanism assigns learned, data-dependent importance weights to inputs when computing a representation.

Attention lets a model learn which inputs deserve more emphasis. For a graph neural network, that means weighing neighboring nodes when computing a node’s representation, rather than treating every neighbor as equally important. It is useful when a node’s influence is not obvious from its degree alone. section 4.5.1 section 4.0

Think of interpreting a character in a nonlinear story: some earlier events matter more than others. Likewise, attention helps a model focus on the neighbors most relevant to the current node. Self-attention and multihead attention are related forms; a graph attention network (GAT) adds attention to a convolutional GNN. section 4.5.1

A practical way to use graph attention is:

  • Prepare graph structure, node features, labels, and train/test indices as PyTorch Geometric data. section 4.3.2
  • Train a GCN baseline, then compare it with a GAT rather than assuming attention will improve results. section 4.3.2
  • Account for graph-aware loading: the GCN example passes the whole graph through the model, while the GAT example batches training data. section 4.3.2

Fake-review detection

In a network used to detect fake customer reviews, a small set of actors or transactions may matter disproportionately. Attention provides a way to learn which connected nodes warrant emphasis, even when their degree does not make them stand out. section 4.0

Attention is a reason to try a GAT, not a guarantee that it will win. Use the non-attention baseline to judge the benefit against the added modeling and data-loading choices; a deeper account can examine the GAT equations. section 4.3.2 section 4.5

How Graph Neural Networks in Action covers it

How deep it goes
Defines attention intuitively, distinguishes related forms, and points to GAT equations for a deeper account.
Examples
Uses a nonlinear-story analogy and a fake-review detection network to illustrate selective emphasis.
What it assumes
Builds on graph convolution and message passing while introducing attention from an intuitive starting point.
What you can do after
Apply it via PyTorch Geometric GAT or GATv2 layers and compare against a GCN baseline.
How it connects
Connects attention to self-attention, multihead attention, transformers, convolutional GNNs, and graph attention networks.

Also explained in

Compare how 28 books explain attention →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Graph Neural Networks in Action. The section links point to the parts of the book it draws on.