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

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Fu, Yuchen, Cheng, Zifeng, Jiang, Zhiwei, Wang, Zhonghui, Yin, Yafeng, Li, Zhengliang, Gu, Qing
Format: Preprint
Published: 2024
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866912461438844928
author Fu, Yuchen
Cheng, Zifeng
Jiang, Zhiwei
Wang, Zhonghui
Yin, Yafeng
Li, Zhengliang
Gu, Qing
author_facet Fu, Yuchen
Cheng, Zifeng
Jiang, Zhiwei
Wang, Zhonghui
Yin, Yafeng
Li, Zhengliang
Gu, Qing
contents 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.
format Preprint
id arxiv_https___arxiv_org_abs_2412_11556
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle Token Prepending: A Training-Free Approach for Eliciting Better Sentence Embeddings from LLMs
Fu, Yuchen
Cheng, Zifeng
Jiang, Zhiwei
Wang, Zhonghui
Yin, Yafeng
Li, Zhengliang
Gu, Qing
Computation and Language
Artificial Intelligence
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.
title Token Prepending: A Training-Free Approach for Eliciting Better Sentence Embeddings from LLMs
topic Computation and Language
Artificial Intelligence
url https://arxiv.org/abs/2412.11556