arXiv:2602.01572cs.CLcs.IR2026-02被引 1

用注意力值代替隐藏状态,能更准确捕捉句子语义。

LLM-based Embeddings: Attention Values Encode Sentence Semantics Better Than Hidden States

  • 用多层注意力值聚合生成句子表示,无需训练
  • 在无训练设置下超越现有方法,媲美高成本集成模型
  • 适合追求高效、高性能嵌入的应用场景

句子表征是众多自然语言处理任务的基础。尽管当前方法普遍利用大语言模型(LLM)提取句子表征,但大多依赖最终层的隐藏状态,而这些状态为下一词预测优化,难以捕捉全局语义。本文提出新视角:注意力值向量比隐藏状态更能表征句子语义。我们提出值聚合(VA)方法,对多层和多标记的注意力值进行池化。在无训练设置下,VA性能优于其他基于LLM的嵌入方法,甚至可媲美或超越基于集成的MetaEOL。进一步发现,结合合适提示,最后标记的注意力分数可作为权重,通过输出投影矩阵($W_O$)将加权值向量对齐至模型残差流的共同空间。此改进方法称为对齐加权值聚合(AlignedWVA),在无训练的LLM嵌入中达到领先水平,显著超越高成本的MetaEOL。最后,我们展示了对值聚合进行微调可获得强性能的嵌入模型。

原文摘要 · Abstract (English)

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.

LLM嵌入注意力机制无训练语义表征

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。