AI Glossary / Statistics and probability / Intermediate
Mean pooling
Definition
Mean pooling is an operation that combines a collection of equally sized vectors by averaging their corresponding coordinates. In language AI, it commonly turns a variable number of token representations into one fixed-size representation of a sentence or passage. The operation summarizes the selected vectors; whether the result captures useful meaning depends on the representations, training, and selection rules.
What it means
A language model may produce one vector for each token, including pieces of words. A downstream search or classification system often needs one vector for the entire input. Mean pooling provides a straightforward bridge: add the selected token vectors and divide by their count.
The result has the same number of coordinates as an individual input vector. It is not a textual summary, a list of key words, or an explanation of the sentence. It is a numerical representation intended for subsequent computation.
How it works
Start with vectors of dimension d for n eligible tokens. For each coordinate, calculate its arithmetic mean across those tokens. In notation, the pooled vector is h = (h1 + h2 + ... + hn)/n. All included vectors receive equal weight in this ordinary form.
Use a mask when inputs have padding added for batching. Multiply each token vector by its zero-or-one inclusion mask, sum the resulting vectors, and divide by the number of included positions. Dividing by the padded sequence length instead changes the result. Decide explicitly whether special tokens and prompt tokens belong in the average.
The averaging operation has no learned parameters of its own. However, the model producing the vectors can be trained so that its pooled output works well for a target task. Pooling alone does not provide that training.
After pooling, a system may normalize the vector or pass it through another layer. These are separate operations. Define a policy for inputs with no eligible tokens, since their ordinary masked mean has a zero denominator.
Mean pooling is insensitive to a reordering of the same supplied vectors. A contextual encoder can nevertheless change those vectors when word order changes, so the complete encoder-plus-pooling system need not ignore word order.
Three practical examples
- Support search: a system averages appropriately trained token representations to index short help articles and retrieve candidates for a customer's query.
- Message classification: a classifier uses the pooled representation of each message as input when assigning broad topic labels.
- Personal organization: a notes application groups short notes using sentence representations, while retaining the original text for checking ambiguous matches.
Think of it this way
Think of marking several points on a map and finding their average position. The resulting point summarizes the group, but does not describe its full arrangement. Different groups can share the same center. Similarly, different token-vector collections can have the same mean even though their details differ.
Worked example
Suppose three eligible token vectors are (2, 0), (0, 4), and (4, 2). Their sum is (6, 6), so mean pooling produces (2, 2). The input has three vectors of length two; the output is one vector of length two.
Now suppose the batch adds two padding positions. With those positions excluded by the mask, the denominator remains three and the answer remains (2, 2). Incorrectly dividing the same sum by five would produce (1.2, 1.2). Normalization might hide this particular scale difference in some cosine comparisons, but it does not make incorrect masking a sound general procedure.
Consider also combining this three-token passage with a second passage containing one vector, (4, 0). Averaging the two passage means equally gives (3, 1). Averaging all four token vectors gives (2.5, 1.5). To recover the latter from passage means, weight them by their eligible token counts: three and one. The choice depends on whether passages or tokens are intended to receive equal weight.
Illustrative case study
Fictional case: Cedar Help builds a search prototype for short internal support notes. The team initially averages all output positions, including padding, and notices that changing batch composition changes some scores. It corrects the mask and records how special tokens are handled.
The team then checks retrieval on representative queries, including questions with negation and similar product names. It compares candidate results against human relevance judgments rather than assuming that a mathematically correct average guarantees good search. This fictional scenario illustrates an implementation and evaluation process, not a reported performance gain.
Common misconceptions and mistakes
Do not average coordinates within each token when the intention is to average tokens while preserving the embedding dimension. Do not assume padding embeddings are harmless merely because padding is not visible in the displayed text.
Mean pooling does not always outperform max pooling, a designated summary token, or other representations. The model's training and evaluation task matter. Nor does pooling restore material lost through truncation before encoding.
Equal token weights are not necessarily equal word weights because tokenization can split words into different numbers of pieces. Averaging passage averages also changes weighting unless passage lengths are handled deliberately. Finally, a high similarity score between pooled vectors is not proof that two statements have the same factual meaning.
Business use
Mean pooling can provide a simple aggregation step for search, clustering, and classification pipelines. Record the encoder, tokenization, length limit, mask policy, pooling rule, and any normalization so results can be reproduced.
Evaluate the complete system against the intended business task. Test difficult contrasts and realistic long inputs, and retain a way to inspect the underlying content. The aggregation calculation is inexpensive relative to many neural encoders, but that alone does not establish acceptable total latency, quality, or operating cost.
People also ask
Does mean pooling train a model?
No; the average itself has no learned weights, although the surrounding encoder can be trained.
Does it produce one number?
Usually it produces one vector, retaining the embedding dimension.
Does it always discard word order?
The averaging step ignores the order of supplied vectors, but contextual vectors can already encode order-dependent information.
Check your understanding
what is the mean of (1, 3) and (5, 1)?
Answer: (3, 2).
should three real token vectors and two excluded padding positions be divided by five?
Answer: no, divide by three.
why can equally averaging passage vectors differ from averaging every token?
Answer: the first gives passages equal weight; the second gives included tokens equal weight.
Related terms
- Embedding
- Tokenization
- Attention mask
- Max pooling
- Cosine similarity
- Sentence embedding
- Contextual representation
- Vector normalization
Learn next
Next, compare mean pooling with max pooling and designated-token representations. Then study how contrastive training and retrieval evaluation shape the usefulness of the resulting sentence vectors.
More in Statistics and probability
- Mean directional accuracy - Mean directional accuracy, or MDA, is the proportion of evaluated forecasts that correctly predict the direction of a specified change.
- Mean opinion score - A mean opinion score, or MOS, is an average of ratings assigned on a predefined opinion scale in a quality-evaluation study.
- Mean Percentage Error - Mean Percentage Error, or MPE, is the arithmetic average of signed forecast errors expressed as percentages of the corresponding actual values.
- Mean Squared Error - Mean Squared Error, or MSE, is the average of squared differences between observed values and corresponding predictions.
- Mean squared logarithmic error - Mean squared logarithmic error, or MSLE, is the average squared difference between the natural logarithms of one plus each actual value and one plus its...
- Mean time to failure - Mean time to failure, or MTTF, is the expected operating time until a defined failure for an item or population under specified conditions.
Sources
Reimers and Gurevych, Sentence-BERT, primary research paper: https://arxiv.org/pdf/1908.10084 Sentence Transformers, pooling module documentation: https://sbert.net/docs/package_reference/sentence_transformer/modules.html Jurafsky and Martin, Speech and Language Processing, embeddings chapter: https://web.stanford.edu/~jurafsky/slp3/5.pdf
Previous: Mean Percentage Error Next: Mean squared Bellman error