Readout function

Also known as: graph readout

On this page 7

A readout function is the operation in a graph neural network that aggregates the embeddings of all nodes into a single fixed-size graph representation, which a downstream classifier or regressor then uses to make a prediction about the whole graph. In graph learning, it is the bridge between node-level message passing and graph-level tasks such as molecular property prediction or graph classification.

The operation is also called graph readout or global pooling. Because graphs have varying numbers of nodes and no natural node order, a readout function must accept any input size and must be permutation invariant: reordering the nodes must never change the output.

How a readout function works

A graph neural network first runs several rounds of message passing, after which every node holds an embedding that summarizes its local neighborhood. The readout function then applies a symmetric aggregation over the set of node embeddings, such as a sum, mean or maximum, and often passes the result through a small multilayer perceptron.

Formally, if h_v is the final embedding of node v, the graph representation is h_G = R({h_v : v in V}), where R is a function on multisets of vectors. Any function of this kind can be written as rho applied to the sum of phi(h_v), a result from the Deep Sets line of work that underpins most readout designs.

The table below lists the properties that a well-designed readout function should satisfy.

PropertyMeaningWhy it matters
Permutation invarianceOutput ignores node orderingGraphs have no canonical node order
Size independenceAccepts any number of nodesDatasets mix small and large graphs
Fixed output dimensionAlways returns a vector of the same lengthDownstream layers need a fixed input
ExpressivenessDistinguishes different multisets of embeddingsDetermines which graphs can be separated
DifferentiabilityGradients flow back to node embeddingsEnables end-to-end training
Required properties of a readout function

Common types of readout functions

Readout functions range from simple fixed aggregators with no parameters to learned, attention-based and set-based modules. The choice affects both accuracy and the kinds of graph differences the model can detect.

ReadoutOperationStrengthWeakness
Sum poolingAdds all node embeddingsMost expressive simple aggregator, counts nodesScale grows with graph size
Mean poolingAverages node embeddingsStable across graph sizesLoses information about node counts
Max poolingTakes elementwise maximumHighlights salient substructuresIgnores frequency of features
Attention poolingWeights nodes by learned scoresFocuses on relevant nodesExtra parameters, risk of overfitting
Set2SetIterative attention with an LSTMRich order-invariant summaryHigher computational cost
Sort poolingSorts nodes by a learned key, keeps top kAllows 1D convolution afterwardSensitive to the choice of k
Readout functions and their characteristics

Many architectures combine several aggregators, for example concatenating sum, mean and max outputs. The Graph Isomorphism Network goes further and applies a readout after every layer, concatenating the results, so that the graph representation captures structure at several neighborhood radii.

Readout functions and expressive power

The readout function sets an upper bound on what the network can distinguish at graph level. Even when node embeddings differ, a weak aggregator may map two different graphs to the same vector, which makes them indistinguishable to the classifier.

Analysis connected to the Weisfeiler-Lehman test shows that an injective sum aggregator preserves the full multiset of node embeddings, whereas mean and max pooling collapse some multisets. Mean pooling cannot tell a graph from a version with every node duplicated, and max pooling cannot detect how many nodes share a feature. This is why sum readout is preferred when counting substructures matters, such as the number of rings in a molecule.

Readout is often confused with neighboring concepts in graph learning, yet each operates at a different level of the graph. The comparison below clarifies where readout sits.

OperationScopeOutputTypical use
Neighborhood aggregationOne node and its neighborsUpdated node embeddingEvery message-passing layer
Hierarchical graph poolingClusters of nodesA smaller coarsened graphMulti-level graph encoders
Readout functionAll nodes of a graphOne graph-level vectorGraph classification and regression
Virtual nodeA node linked to all othersGlobal context during message passingLong-range information flow
Readout and neighboring graph operations

Hierarchical methods such as DiffPool or top-k pooling coarsen the graph gradually, but they still end with a readout function that produces the final vector. A virtual node can also serve as a learned readout, because its final embedding already summarizes the whole graph.

Choosing a readout in practice

The best readout depends on what the target property depends on: total quantities favor sum, intensive properties favor mean, and properties driven by a single motif favor max or attention. Empirical comparison on a validation set remains the most reliable guide.

Task characteristicRecommended readoutReason
Property scales with sizeSum poolingPreserves counts, such as total energy
Property independent of sizeMean poolingNormalizes over node count
Decided by one key substructureMax or attention poolingIsolates the salient region
Large, varied graphsAttention or Set2SetLearns which nodes matter
Unknown behaviorConcatenated sum, mean, maxCovers several hypotheses cheaply
Decision guide for readout selection

A common mistake is applying sum pooling without normalization to datasets whose graph sizes vary by orders of magnitude, which produces unstable activations. Adding batch or layer normalization after readout, or scaling by the logarithm of the node count, usually resolves the problem.

Understanding it simply

A graph neural network first gives each point in a network its own short description. To judge the whole network, those many descriptions must become one. The readout function does this final summing up.

Think of a teacher grading a group project. Each student has a personal score. The teacher can add the scores, average them or take the best one. Each choice tells a different story. The method of combining shapes the final verdict, and the same is true for a readout.

Applied in practice

A pharmaceutical research team uses a graph neural network to predict the water solubility of candidate molecules. Each molecule is a graph with atoms as nodes and bonds as edges, typically between 10 and 60 atoms. After five message-passing layers, every atom carries a 256-dimensional embedding describing its chemical surroundings.

The team first tries mean pooling, but the model underestimates the effect of adding extra polar groups, because averaging hides how many there are. Switching to a sum readout concatenated with attention pooling lets the model count functional groups and still focus on influential atoms. On a held-out set of 2,000 molecules, the root-mean-square error drops by roughly a fifth, and chemists can inspect the attention weights to see which atoms drove each prediction.