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.
| Property | Meaning | Why it matters |
|---|---|---|
| Permutation invariance | Output ignores node ordering | Graphs have no canonical node order |
| Size independence | Accepts any number of nodes | Datasets mix small and large graphs |
| Fixed output dimension | Always returns a vector of the same length | Downstream layers need a fixed input |
| Expressiveness | Distinguishes different multisets of embeddings | Determines which graphs can be separated |
| Differentiability | Gradients flow back to node embeddings | Enables end-to-end training |
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.
| Readout | Operation | Strength | Weakness |
|---|---|---|---|
| Sum pooling | Adds all node embeddings | Most expressive simple aggregator, counts nodes | Scale grows with graph size |
| Mean pooling | Averages node embeddings | Stable across graph sizes | Loses information about node counts |
| Max pooling | Takes elementwise maximum | Highlights salient substructures | Ignores frequency of features |
| Attention pooling | Weights nodes by learned scores | Focuses on relevant nodes | Extra parameters, risk of overfitting |
| Set2Set | Iterative attention with an LSTM | Rich order-invariant summary | Higher computational cost |
| Sort pooling | Sorts nodes by a learned key, keeps top k | Allows 1D convolution afterward | Sensitive to the choice of k |
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 compared with related operations
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.
| Operation | Scope | Output | Typical use |
|---|---|---|---|
| Neighborhood aggregation | One node and its neighbors | Updated node embedding | Every message-passing layer |
| Hierarchical graph pooling | Clusters of nodes | A smaller coarsened graph | Multi-level graph encoders |
| Readout function | All nodes of a graph | One graph-level vector | Graph classification and regression |
| Virtual node | A node linked to all others | Global context during message passing | Long-range information flow |
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 characteristic | Recommended readout | Reason |
|---|---|---|
| Property scales with size | Sum pooling | Preserves counts, such as total energy |
| Property independent of size | Mean pooling | Normalizes over node count |
| Decided by one key substructure | Max or attention pooling | Isolates the salient region |
| Large, varied graphs | Attention or Set2Set | Learns which nodes matter |
| Unknown behavior | Concatenated sum, mean, max | Covers several hypotheses cheaply |
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.