Mean pooling, averaging the per-token vectors across all positions, is the SBERT-family default and remains the most common choice for encoder-based sentence embeddings.
Think of it like averaging scores from a panel of judges. An encoder gives you one vector per token in your sentence, but you need ONE vector for the whole sentence. The simplest way to combine them is to average: take each dimension, add it up across all tokens, divide by the count. That is mean pooling. It treats every token as equally informative about sentence meaning. It is dumb but it works, and SBERT made it the default for sentence embeddings.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Every encoder embedding model has to answer one structural question: how do you turn the variable-length sequence of token vectors into a single fixed vector representing the whole input? Mean pooling is the answer that won, for SBERT in 2019 and for most encoder-based embedding models since.
This deep dive covers the mechanism with the all-important attention mask, the empirical reason SBERT chose mean over CLS, why the choice generalized to BGE / E5 / Snowflake Arctic / mxbai, the decoder-only exception that breaks the pattern, and the learned attention pool variant that occasionally wins.
Mental model: mean pool is the strongest default. Everything else is a deliberate choice for a specific architecture or quality target.
The mechanism: mean pool with the attention mask
The formula
Given token-level outputs H = [h_1, h_2, ..., h_n] from the encoder's last hidden state, with attention mask m where m_i = 1 for real tokens and 0 for padding, mean pool computes:
This is the dimension-wise average over real tokens only. The output v has the same dimensionality as h_i (typically 384, 768, or 1024 for BERT-family encoders).
Why the mask matters
If you forget the mask and average over all positions including padding, you are diluting the real-token signal with whatever vectors the model produces for padding tokens (which are arbitrary; the model was trained to ignore them via the attention mask). For a 32-token real input padded to 512 tokens, you have averaged 480 padding-vector contributions into your sentence representation.
This is a real production bug. Most embedding libraries handle it correctly out of the box, but hand-rolled implementations frequently miss it. The symptom is length-sensitive embedding quality, short inputs perform worse than they should.
What pooling is NOT
Pooling is not normalization. After pooling, most embedding pipelines apply L2 normalization so cosine similarity becomes a pure dot product. Pooling collapses sequence dimension; normalization rescales the resulting vector to unit length. Both happen but are separate steps.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- SBERT (Sentence-BERT) by Reimers and Gurevych (2019) established mean pool as the standard for sentence-similarity embeddings.
- BGE-large-en-v1.5 and BGE-M3 from BAAI use mean pooling as the default in 2026 production stacks.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhat is attention pooling and when does it beat mean pool?
Attention pooling introduces a learned query vector that computes attention weights over the token outputs, producing a weighted sum. Used in Jina v3 and similar; gives a small quality lift on STS tasks at the cost of one extra trained component.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Confusing mean pooling with CLS-token pooling. SBERT explicitly compared both and showed mean wins for sentence similarity; CLS is the BERT as classifier default, not the sentence-embedding default.
60 second bullets to scan on the way to the call.
Definition of mean pooling and the role of the attention mask
Why SBERT chose mean over CLS empirically
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.