[论文解读] LLM-based Embeddings: Attention Values Encode Sentence Semantics Better Than Hidden States
论文展示了从 LLM 注意力中聚合值向量(Value Aggregation,VA)可以得到比隐藏状态池化更强的句子嵌入,改进版本 AlignMlatedWVA 在训练-free 的 LLM 嵌入中达到最先进的结果,并且编码成本低于 MetaEOL。
Sentence representations are foundational to many Natural Language Processing (NLP) applications. While recent methods leverage Large Language Models (LLMs) to derive sentence representations, most rely on final-layer hidden states, which are optimized for next-token prediction and thus often fail to capture global, sentence-level semantics. This paper introduces a novel perspective, demonstrating that attention value vectors capture sentence semantics more effectively than hidden states. We propose Value Aggregation (VA), a simple method that pools token values across multiple layers and token indices. In a training-free setting, VA outperforms other LLM-based embeddings, even matches or surpasses the ensemble-based MetaEOL. Furthermore, we demonstrate that when paired with suitable prompts, the layer attention outputs can be interpreted as aligned weighted value vectors. Specifically, the attention scores of the last token function as the weights, while the output projection matrix ($W_O$) aligns these weighted value vectors with the common space of the LLM residual stream. This refined method, termed Aligned Weighted VA (AlignedWVA), achieves state-of-the-art performance among training-free LLM-based embeddings, outperforming the high-cost MetaEOL by a substantial margin. Finally, we highlight the potential of obtaining strong LLM embedding models through fine-tuning Value Aggregation.
研究动机与目标
- 为 NLP 任务动机化句子级表示并批评自回归 LLM 的基于隐藏状态的嵌入。
- 提出 Value Aggregation(VA)在不进行训练的情况下对跨层与跨标记进行值向量的池化。
- 通过 W_O 将 VA 对齐到残差流,提出 AlignWVA,使其与模型内部对齐。
- 在 LLaMA-2 和 Qwen-3 的骨架上对 MTEB 任务验证 VA/AlignedWVA 的有效性。
- 讨论对 VA 进行微调以进一步提升嵌入的潜在可能性。
提出的方法
- 从多头注意力中定义每层的值向量 v^{l,h}_{n},并在头之间拼接形成 v^{l}_{n}。
- 对标记级值进行均值池化以获得逐层向量 ˆ{l},再在选定的层集合 S 上对均值以形成 VA(x)。
- 研究层选择策略以选择强聚合的层(如对于 LLaMA-2 使用更深的中间层;对于 Qwen-3 使用靠近最后一层的层)。
- 通过对 VA 进行输出投影 W_O,将 VA 映射到残差流空间,从而实现与模型内部的对齐(AlignedWVA)。
- 探索带注意力权重的变体 WVA(LT、PromptEOL、FutureEOL),并与普通 VA 进行比较。
- 可选地给出 Finetune-VA,在对比学习中微调 VA 以提升嵌入效果。
实验结果
研究问题
- RQ1注意力值向量是否比最终层隐藏状态更有效地编码句子语义以用于句子嵌入?
- RQ2简单的、无训练聚合(Value Aggregation)是否能够产生具竞争力或优于需要大量训练或基于集成的方法的嵌入?
- RQ3将 VA 与残差流对齐(AlignedWVA)是否在训练-free 的 LLM 嵌入中达到最先进的性能?
- RQ4不同骨架(LLaMA-2 与 Qwen-3)下层选择对 VA 性能有何影响?
- RQ5对 VA 进行微调是否能在比隐藏状态基线更少的可训练参数下带来实际收益?
主要发现
| Model | Dim | Backbone | Clustering | Retrieval | STS | Classification | Reranking | Avg |
|---|---|---|---|---|---|---|---|---|
| VA (Full) | 4096 | Llama-2 | 32.45 | 28.65 | 27.95 | 52.41 | 23.52 | 74.08 |
| VA (Half) | 4096 | Llama-2 | 32.45 | 28.65 | 27.95 | 52.41 | 23.52 | 74.08 |
| VA | 4096 | Llama-2 | 33.13 | 29.56 | 30.59 | 54.58 | 25.89 | 45.76 |
| VA (Full) | 1024 | Qwen-3 | 26.85 | 24.65 | 20.59 | 58.37 | 18.69 | 41.41 |
| AlignedWVA (PromptEOL) | 4096 | Llama-2 | 28.82 | 23.45 | 31.20 | 45.31 | 25.13 | 83.33 |
| AlignedWVA (FutureEOL) | 4096 | Llama-2 | 31.25 | 26.39 | 33.82 | 51.40 | 25.32 | 83.38 |
| AlignedWVA (PromptEOL) | 4096 | Qwen-3 | 35.56 | 29.73 | 48.04 | 55.44 | 31.55 | 83.06 |
| AlignedWVA (FutureEOL) | 4096 | Qwen-3 | 33.62 | 28.03 | 44.51 | 62.98 | 32.04 | 84.31 |
- VA 在 LLaMA-2(7B)和 Qwen-3(8B)的 MTEB 任务中优于其他训练-free 的基于 LLM 的嵌入。
- AlignedWVA 在训练-free 的 LLM 嵌入中达到最先进的性能,并明显超过 MetaEOL。
- 对深层中间层(如 LLaMA-2 的 20–27 层;Qwen-3 的 26、27、29、30、31 层)进行选择性层聚合,提升了对比全层池化的鲁棒性。
- AlignedWVA(PromptEOL)和(FutureEOL)显著优于 MetaEOL,Qwen-3 的 AlignedWVA(FutureEOL)平均超过 MetaEOL 超过 4 点以上。
- 使用提示词的 WVA 变体(PromptEOL、FutureEOL)相比 LT 和基于 LT 的池化有显著改进,突出有意义提示的重要性。
- Finetune-VA(仅注意力)在提高嵌入方面的增益可与对隐藏状态求均值池化的微调相当,但需要的可训练参数更少。
更好的研究,从现在开始
从论文设计到论文写作,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。