Pooling and Readout

Pooling and readout layers convert token, node, patch, or residue states into task-level outputs. They determine how local representations become sequence-level, graph-level, or complex-level predictions.

Mean pooling is:

Attention pooling uses learned weights:

\alpha_i = \frac{\exp(a^\top h_i)} \sum_{j=1}^{n}\exp(a^\top h_j)}

For padded batches, pooling must use a mask:

where for valid tokens and for padding. Without this, longer padding or special tokens change the representation.

Task heads then map the readout into the output space:

For graph-level prediction, sum pooling can preserve extensive quantities while mean pooling is better for size-normalized properties.

Common Choices

ChoiceTypical UseRisk
last-token readoutcausal sequence modelslast position may not summarize bidirectional context
CLS-token readoutencoder-style TransformersCLS behavior depends on pretraining objective
mean poolingsize-normalized sequence, set, graph embeddingsrare active sites can be diluted
sum poolingextensive graph properties or countslarger objects can dominate scale
max poolingdetect presence of strong local signalignores frequency and context
attention poolingvariable-size objects with learned importanceattention weights are not automatically explanations
pair readoutinteraction, retrieval, matching, protein-ligand scoringpair construction and negatives define the task
task-specific headnode, edge, graph, coordinate, or ranking outputhead capacity can dominate representation claim

Output Unit Map

Output UnitReadout Boundary
token/node/residueno global pooling before prediction; output stays equivariant to element order
edge/paircombine two endpoint states plus edge/pair features
graph/molecule/proteinpermutation-invariant pooling over all valid elements
pocket or local sitepool only the local region with a defined mask
protein-ligand complexseparate protein, ligand, and cross-interaction readouts when claim needs attribution
generated coordinatesreadout should preserve vector/coordinate equivariance until the coordinate head

Extensive vs Intensive Targets

Pooling should match the target scale:

Use sum-like readout for extensive quantities that grow with object size, and mean/normalized readout for size-independent properties. If the target is a binding score, activity label, or class probability, the correct readout depends on how the label was measured.

Checks

  • Does the task need token-level, node-level, graph-level, or global output?
  • Does pooling preserve important rare sites or dilute them?
  • Are padding tokens excluded from the pool?
  • Is the readout invariant to permutations when it should be?
  • Is the readout fitted, selected, or tuned on validation data only?
  • Does the readout leak future information through masks, pockets, or labels?
  • Is the same readout used for baselines when claiming representation quality?