Token Prepending: A Training-Free Approach for Eliciting Better Sentence Embeddings from LLMs
About
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.
Related benchmarks
| Task | Dataset | Result | Rank | |
|---|---|---|---|---|
| Semantic Textual Similarity | STS tasks (STS12, STS13, STS14, STS15, STS16, STS-B, SICK-R) various (test) | STS12 Score68.52 | 393 | |
| Semantic Textual Similarity | STS tasks (STS12, STS13, STS14, STS15, STS16, STS-B, SICK-R) | STS12 Score69.48 | 195 | |
| Semantic Textual Similarity | STS (Semantic Textual Similarity) 2012-2016 (test) | STS-12 Score66.9 | 57 | |
| Transfer Learning | SentEval Transfer Learning Tasks (test) | MR90.9 | 52 | |
| Text Embedding | MTEB | MTEB Score46.19 | 45 | |
| Retrieval | LoCo 4096 tokens V1 | NDCG@1013.97 | 12 | |
| Retrieval | LoCo 2048 tokens V1 | NDCG@100.0422 | 12 | |
| Retrieval | LoCo 1024 tokens V1 | NDCG@100.0421 | 12 |