Introduction
Large Language Models (LLMs) have revolutionized natural language generation, yet their application to dense retrieval—converting text into high-quality vector embeddings—remains a significant challenge. Decoder-only models, while powerful, are inherently constrained by their causal architecture and training objectives. ULLME (Unified framework for Large Language Model Embedding) addresses these limitations by introducing a flexible, architecture-agnostic framework that aligns an LLM's generative capabilities with its embedding space.
The Challenge of LLM Embeddings
The transition from text generation to text embedding involves overcoming three primary hurdles:
- Causal Constraints: Standard decoder-only LLMs utilize causal masking, looking only at preceding tokens. Effective embeddings require bidirectional attention to capture the full context of a sentence.
- Objective Mismatch: LLMs are optimized for next-token prediction, which does not naturally translate to the discriminative task of determining semantic similarity between distinct passages.
- Framework Rigidity: Many existing solutions are tied to specific model architectures or single fine-tuning strategies, hindering broader research and experimentation.
The ULLME Framework
ULLME is designed as a "plug-and-play" wrapper compatible with various LLM families. It enables a Bidirectional Attention Toggle, allowing models to switch between causal masks for generation and all-one masks for embedding tasks. Furthermore, it integrates efficient training techniques like LoRA (Low-Rank Adaptation) and GradCache to facilitate the fine-tuning of large-scale models on accessible hardware.
As shown in the comparison above, ULLME offers superior flexibility, supporting a wide range of LLMs and multiple fine-tuning strategies, including Supervised Fine-Tuning (SFT), Direct Preference Optimization (DPO), and Contrastive Learning.
Generation-augmented Representation Learning (GRL)
The core innovation of ULLME is Generation-augmented Representation Learning (GRL). This technique leverages the "generative intuition" of the LLM to refine its vector space. Instead of relying solely on binary contrastive labels (positive vs. negative), GRL calculates a generation-based relevance score—the probability of the model generating a specific passage given a query. By using KL divergence, the framework forces the embedding-based cosine similarity to align with this generative logic, providing a much richer training signal.
Key Results
Evaluation on the Massive Text Embedding Benchmark (MTEB) demonstrates that ULLME consistently outperforms existing state-of-the-art methods like Echo and LLM2Vec.
The results indicate that the GRL method provides significant gains across various model sizes:
- Mistral-7B-Instruct-v0.2 reached an average MTEB score of 59.50, surpassing the LLM2Vec baseline.
- Llama-3-8B achieved a score of 59.27.
- Phi-1.5 (1.5B) demonstrated strong performance at 55.76, highlighting the framework's effectiveness even for smaller models.
Conclusion
ULLME provides a robust and flexible solution for transforming generative LLMs into high-performance embedders. By bridging the gap between generative logic and representation learning, it sets a new standard for dense retrieval tasks. Future work will focus on extending this framework to even larger architectures and exploring deeper integrations of generative and discriminative objectives.
Summary updated