TL;DR
Researchers from Tsinghua University have developed two simple, "plug-and-play" prompt engineering techniques—Pretended Chain of Thought and Knowledge Enhancement—that significantly boost the quality of sentence embeddings from Large Language Models (LLMs) without any fine-tuning. By simply adding specific prefixes to a prompt, these methods allow 7B-scale models like LLaMA2 and Mistral to outperform traditional fine-tuned BERT models while using less than half the GPU memory.
What Problem Does This Paper Address?
Sentence embeddings—numerical representations of text that capture meaning—are the backbone of modern search engines and RAG (Retrieval-Augmented Generation) systems. While discriminative models like BERT have long been the standard, generative LLMs (like LLaMA) offer much richer semantic potential.
However, there’s a catch: to get high-quality embeddings from LLMs, researchers usually have to perform "contrastive fine-tuning," which is computationally expensive and memory-intensive. Using "raw" embeddings directly from an LLM (direct inference) is much faster and cheaper but usually results in poor performance. This paper explores how to bridge that performance gap using only clever prompting, making high-quality embeddings accessible to those with limited hardware.
Methods
The authors first debunk the "Explicit One-word Limitation" (EOL) myth, showing that while forcing a model to summarize a sentence into one word helps generative models during direct inference, it isn't a universal "magic fix" for all model types or fine-tuning scenarios.
Building on this, they propose two new techniques to append to the standard EOL prompt:
- Pretended Chain of Thought (CoT): Inspired by the famous "Let's think step by step" prompt. Crucially, the authors don't actually ask the model to generate a reasoning chain (which would be slow). Instead, they prefix the prompt with "After thinking step by step,". This "primes" the model's internal state to produce a more thoughtful embedding.
- Knowledge Enhancement (KE): This method provides the model with explicit "human experience" on how to summarize. The prompt includes a prefix explaining that the essence of a sentence lies in its subjects and actions, while descriptive terms are less central. This guides the model's attention mechanism toward the core meaning of the sentence.
Datasets
The researchers evaluated their methods using the standard SentEval toolkit across seven Semantic Textual Similarity (STS) benchmarks:
- STS 2012–2016
- STS-Benchmark (STS-B)
- SICK-Relatedness (SICK-R)
These datasets consist of sentence pairs with human-assigned similarity scores, allowing the authors to measure how well the model's embeddings correlate with human judgment.
Key Insights and Ideas
- The "Pretended" Advantage: The success of Pretended CoT suggests that LLMs don't necessarily need to output reasoning to benefit from it; the mere presence of a "reasoning" context in the prompt changes how the model processes the input internally.
- Attention Steering: Through attention visualization, the authors found that Knowledge Enhancement successfully shifts the model's focus. Instead of getting distracted by adjectives or modifiers, the model allocates more "attention weight" to the subject, predicate, and object.
- Punctuation Matters for BERT: In a surprising side-experiment, the authors found that simply adding a period, exclamation mark, or question mark to a BERT prompt can boost its raw embedding performance from a Spearman score of 27.21 to over 70.
- Scaling Effects: While Pretended CoT is a stable booster across all model sizes, Knowledge Enhancement scales better. Larger models (like OPT-13B) are better at "understanding" the complex instructions in the KE prompt, leading to higher performance gains as the model grows.
Key Results
- Superior Performance: Using LLaMA2-7B with Knowledge Enhancement, the authors achieved an average Spearman correlation of 77.14. This beats the popular unsupervised SimCSE-BERT (76.25), which requires specialized fine-tuning.
- Massive Memory Savings: Direct inference with these prompts on a 7B model requires only 36–39 GB of GPU memory. In contrast, fine-tuning the same model using QLoRA requires roughly 93 GB.
- Universal Gains: The techniques provided a consistent boost across various architectures, including OPT, LLaMA, LLaMA2, and Mistral. For LLaMA2, the improvement over the previous state-of-the-art prompting method was over 10%.
Limitations and Future Work
The authors acknowledge that while these methods significantly improve raw embeddings, they still generally trail behind supervised fine-tuned models (which use labeled data).
Additionally, the "Knowledge Enhancement" prompt is currently a fixed, manually designed template. The authors suggest that future research could explore automated template generation or "meta-prompting" to find even more effective ways to guide the model’s internal attention without human intervention.
Summary updated