arXiv:2412.11556cs.CLcs.AI2024-12ACL被引 20

不训练即可提升大模型句向量质量,让早期词元也能看到完整句子信息。

Token Prepending: A Training-Free Approach for Eliciting Better Sentence Embeddings from LLMs

论文配图:Token Prepending: A Training-Free Approach for Eliciting Better Sentence Embeddings from LLMs
图 1 · 摘自论文原文
  • 在每层输入前添加上一层的句向量,打破因果注意力限制
  • 在多个文本相似度与分类任务中显著提升现有方法性能
  • 无需训练、零额外推理开销,适配各类提示工程和自回归模型

从大语言模型(LLMs)中提取句向量是一个有前景的方向,因为LLMs展现出更强的语义理解能力。以往研究通常通过提示工程引导模型将句子信息编码到最后一层的词元嵌入中。然而,大多数LLM是仅解码器模型,具有因果注意力机制,导致句子早期词元无法关注后续词元,造成信息编码偏差并引发最终词元的级联误差。为此,我们提出一种新颖的无训练词元前置(Token Prepending, TP)技术:将每一层解码后的句子嵌入预先添加到下一层输入的开头,使早期词元在因果注意力机制下也能访问完整的句子信息。该方法为即插即用且无需训练,可无缝集成于多种基于提示的句向量方法及自回归LLM。在多个语义文本相似性(STS)任务和下游分类任务上的大量实验表明,所提TP技术能显著提升不同LLM上现有提示方法的性能,同时带来可忽略的额外推理开销。

原文摘要 · Abstract (English)

Extracting sentence embeddings from large language models (LLMs) is a promising direction, as LLMs have demonstrated stronger semantic understanding capabilities. Previous studies typically focus on prompt engineering to elicit sentence embeddings from LLMs by prompting the model to encode sentence information into the embedding of the last token. However, LLMs are mostly decoder-only models with causal attention and the earlier tokens in the sentence cannot attend to the latter tokens, resulting in biased encoding of sentence information and cascading effects on the final decoded token. To this end, we propose a novel Token Prepending (TP) technique that prepends each layer's decoded sentence embedding to the beginning of the sentence in the next layer's input, allowing earlier tokens to attend to the complete sentence information under the causal attention mechanism. The proposed TP technique is a plug-and-play and training-free technique, which means it can be seamlessly integrated with various prompt-based sentence embedding methods and autoregressive LLMs. Extensive experiments on various Semantic Textual Similarity (STS) tasks and downstream classification tasks demonstrate that our proposed TP technique can significantly improve the performance of existing prompt-based sentence embedding methods across different LLMs, while incurring negligible additional inference cost.

句向量提示工程大模型注意力机制

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