Contrastive Prompting Enhances Sentence Embeddings in LLMs through Inference-Time Steering

📅 2025-05-19
📈 Citations: 0
Influential: 0
📄 PDF
🤖 AI Summary
Traditional prompt-based sentence embedding methods for large language models (LLMs) suffer from semantic impurity—specifically, encoding sentence semantics into the final token often incorporates redundant information such as stop words, degrading embedding quality. Method: We propose Contrastive Prompting (CP), a lightweight, inference-time prompting technique that introduces auxiliary contrastive prompts to steer LLMs toward focusing on core semantic content while suppressing irrelevant components. CP requires no fine-tuning, additional training data, or architectural modifications, and integrates seamlessly into existing prompt-based embedding frameworks. Contribution/Results: To our knowledge, this is the first work to incorporate contrastive learning principles into prompt-driven sentence embedding generation. CP yields substantial improvements on semantic textual similarity (STS) benchmarks and downstream classification tasks across multiple LLMs, demonstrating both effectiveness and strong generalizability without increasing computational overhead.

Technology Category

Application Category

📝 Abstract
Extracting sentence embeddings from large language models (LLMs) is a practical direction, as it requires neither additional data nor fine-tuning. Previous studies usually focus on prompt engineering to guide LLMs to encode the core semantic information of the sentence into the embedding of the last token. However, the last token in these methods still encodes an excess of non-essential information, such as stop words, limiting its encoding capacity. To this end, we propose a Contrastive Prompting (CP) method that introduces an extra auxiliary prompt to elicit better sentence embedding. By contrasting with the auxiliary prompt, CP can steer existing prompts to encode the core semantics of the sentence, rather than non-essential information. CP is a plug-and-play inference-time intervention method that can be combined with various prompt-based methods. Extensive experiments on Semantic Textual Similarity (STS) tasks and downstream classification tasks demonstrate that our method can improve the performance of existing prompt-based methods across different LLMs. Our code will be released at https://github.com/zifengcheng/CP.
Problem

Research questions and friction points this paper is trying to address.

Improving sentence embeddings in LLMs without fine-tuning
Reducing non-essential information in last-token embeddings
Enhancing semantic encoding via contrastive prompting at inference
Innovation

Methods, ideas, or system contributions that make the work stand out.

Contrastive Prompting enhances sentence embeddings
Steers prompts to encode core semantics
Plug-and-play inference-time intervention method
🔎 Similar Papers
No similar papers found.
Z
Zifeng Cheng
State Key Laboratory for Novel Software Technology, Nanjing University, China
Z
Zhonghui Wang
State Key Laboratory for Novel Software Technology, Nanjing University, China
Yuchen Fu
Yuchen Fu
Nanjing University
计算机视觉、多模态学习
Zhiwei Jiang
Zhiwei Jiang
Nanjing University
Natural Language Processing
Y
Yafeng Yin
State Key Laboratory for Novel Software Technology, Nanjing University, China
C
Cong Wang
State Key Laboratory for Novel Software Technology, Nanjing University, China
Qing Gu
Qing Gu
Nanjing University