平均プールのコサイン類似度は長さ不変ではない:長さ不変な代替指標の理論と実証 Mean-Pooled Cosine Similarity is Not Length-Invariant: Theory and Cross-Domain Evidence for a Length-Invariant Alternative
- 本論文は、トークン埋め込みを平均プールしてコサイン類似度を計算する一般的手法が、入力長に依存してバイアスを生じることを理論的に示す。
- 著者らは長さ不変な代替指標を提案し、複数ドメインの実験で有効性を確認した。
English summary
- This paper proves that the common practice of computing cosine similarity over mean-pooled token embeddings is biased by sequence length, and proposes a length-invariant alternative validated across multiple domains.
テキスト埋め込みを使った類似度計算は、検索・推薦・RAG・クラスタリングなど現代の機械学習パイプラインの基盤となっている。本論文は、その中核で広く使われている「トークン埋め込みを平均プールしてコサイン類似度を取る」という手法に、見過ごされてきた構造的欠陥があることを指摘している。
著者らの主張の核は、平均プール後のベクトルのノルムや方向が系列長に依存して系統的に変化し、結果としてコサイン類似度の値そのものが長さに対して不変ではない、という点である。短い文と長い文、あるいは長さが大きく異なる文書対を比較する場面では、内容的な近さよりも長さの違いが類似度スコアに混入する可能性がある。論文ではこれを理論的に導出し、長さに依存しない代替指標を提案している。
実証パートでは、複数ドメインのデータセットを用いて、提案指標が従来の平均プール+コサインに比べてバイアスを抑え、より一貫したランキングや判定を与えることを示しているとされる。検索品質の評価や重複検出のようなタスクでは、長さバイアスが評価指標に直接影響しうるため、実務的な含意は小さくない。
本論文は、トークン埋め込みを平均プールしてコサイン類似度を計算する一般的手法が、入力長に依存してバイアスを生じることを理論的に示す。
背景として、Sentence-BERTやOpenAI・Cohereの埋め込みAPI、E5やBGEといった近年のオープン埋め込みモデルの多くが、内部的にトークン埋め込みの平均プール(あるいはCLSトークン)とコサイン類似度を前提に学習・評価されている。学習時と推論時で文長分布が異なる場合や、長文と短文を混在させて検索する場合に、本研究の指摘するバイアスが顕在化する可能性がある。
一方で、コサイン類似度自体の解釈性や、ドット積・ユークリッド距離との関係については既存研究でも議論が続いており、本論文の代替指標が実運用でどの程度の改善幅をもたらすかは、利用するモデルやタスク特性に依存すると見られる。RAGや大規模検索を扱う実務者にとっては、評価プロトコルに長さ条件を明示的に組み込む価値を示唆する研究と言えるだろう。
Similarity computation over learned text embeddings underpins much of modern machine learning infrastructure, from retrieval and recommendation to RAG pipelines and clustering. This paper argues that one of the most common building blocks in that stack, computing cosine similarity over mean-pooled token embeddings, harbors a structural flaw that has largely gone unexamined.
The central claim is that mean pooling produces vectors whose norm and direction depend systematically on the length of the input sequence. As a consequence, the resulting cosine similarity is not invariant to length: when comparing a short query to a long document, or two passages of very different lengths, the score reflects not just semantic closeness but also a length-dependent artifact. The authors derive this behavior theoretically and propose an alternative similarity measure designed to be length-invariant by construction.
On the empirical side, the paper reports cross-domain experiments showing that the proposed measure reduces length-induced bias and yields more consistent rankings and decisions than the conventional mean-pooled cosine baseline. For tasks such as retrieval evaluation, near-duplicate detection, or semantic clustering, where length distributions vary across queries and corpora, this bias can directly distort headline metrics, so the practical implications are non-trivial.
It is worth situating the result in the broader embedding ecosystem. Sentence-BERT popularized mean pooling for sentence representations, and many widely deployed encoders, including the OpenAI and Cohere embedding APIs and open models such as E5 and BGE, are trained and evaluated under a mean-pool-plus-cosine regime (or a closely related CLS-token variant). Whenever the training distribution of sequence lengths differs from the deployment distribution, or when mixed-length corpora are indexed together, the bias identified here could plausibly surface in production systems.
The finding also connects to a longer-running discussion about the geometry of contrastively trained embeddings. Prior work has shown that such embeddings tend to occupy narrow cones on the unit sphere, that cosine and dot product can disagree in subtle ways, and that normalization choices interact with temperature during training. Length sensitivity can be seen as another axis of this geometric story: pooling more tokens changes the statistical properties of the resulting vector even before any similarity function is applied.
Some caveats are appropriate. The magnitude of the improvement from a length-invariant alternative will likely depend on the encoder family, the training objective, and the length distribution of the target workload. Encoders that already include length-aware normalization, or that are trained with hard negatives spanning diverse lengths, may exhibit smaller gaps. The proposed measure also needs to be compatible with approximate nearest neighbor indexes used at scale, which typically assume inner-product or cosine geometry; integration costs in vector databases such as FAISS, ScaNN, or pgvector are a practical consideration not fully resolved by a theoretical fix.
For practitioners building retrieval and RAG systems, the most actionable takeaway may be evaluation hygiene: explicitly stratify similarity benchmarks by sequence length, and check whether observed quality differences track content or simply length. If the paper's analysis generalizes, length-aware similarity could become a useful default rather than a niche adjustment, particularly as embedding models are pushed toward longer context windows where length variance grows.
本ページの本文・要約は AI による自動生成です。正確性は元記事 (arxiv.org) をご確認ください。