Abstract
Recent advancements in long-context large language models have attracted significant attention, yet their practical applications often suffer from suboptimal context utilization. This study investigates structuring training data to enhance semantic interdependence, demonstrating that this approach effectively improves context utilization. To this end, we introduce the Structured Packing for Long Context (SPLiCe) method, which utilizes retrieval to collate mutually relevant documents into long and coherent training examples. We validate SPLiCe empirically across models of varying sizes — 3B, 7B, and 13B — achieving improved performance in long-context tasks, such as Qasper and HotpotQA. Remarkably, even brief fine-tuning with SPLiCe is sufficient to realize these benefits. Additionally, SPLiCe effectively mitigates the lost-in-middle phenomenon often observed in large models. Our comprehensive analysis of SPLiCe explores its design choices and reveals intriguing transfer effects; for instance, training on programming code enhances performance on natural language tasks.
Introduction
Modern Large Language Models (LLMs) are increasingly capable of handling massive context windows, ranging from 32K to over a million tokens. However, having a large window does not guarantee effective utilization. A persistent challenge is the "lost-in-the-middle" phenomenon, where models excel at retrieving information from the start or end of a prompt but fail when the relevant data is buried in the center.
This research posits that the root cause is the standard "Example Packing" training practice. In this paradigm, random, unrelated documents are concatenated to fill training sequences. This results in a "low dependency density," where the model rarely encounters training signals that require long-range cross-document reasoning. Consequently, the model fails to develop the necessary skills for deep context utilization.
Methods: Structured Packing for Long Context (SPLiCe)
To address this, we introduce SPLiCe (Structured Packing for Long Context). Unlike random packing, SPLiCe organizes training data to maximize semantic interdependence within a single sequence.
The SPLiCe pipeline follows these steps:
- Seed Selection: A random document is selected from the corpus.
- Retrieval: A retriever (e.g., BM25, Contriever, or directory structures for code) identifies the top-$k$ most semantically similar documents.
- Sequence Construction: These related documents are organized (often via a tree structure) and flattened into a single training sequence.
- Fine-tuning: The model is fine-tuned on these structured samples, forcing it to learn how to navigate and connect information across long distances.
Experiments were conducted on 3B, 7B, and 13B models using mixtures of RedPajama, StarCoder, and StackExchange data.
Key Results
The impact of SPLiCe is most evident in long-context retrieval benchmarks.
Needle in a Haystack
In the "Needle in a Haystack" test, models must find a specific fact hidden within a long distractor text. While baseline models using standard packing struggle significantly when the "needle" is in the middle of the context, SPLiCe-tuned models achieve near-perfect accuracy across the entire 32K window.
In-Context Learning and Real-World Tasks
SPLiCe significantly improves performance on multi-hop reasoning tasks like Qasper and HotpotQA. For instance, on the TREC classification task, a 3B model showed an 8.0 point accuracy gain with a 16K context window. Crucially, these improvements do not come at a "tax" to short-context performance; benchmarks like MMLU and GSM8K remained stable or slightly improved, suggesting that learning to use long context doesn't come at the expense of general reasoning.
Discussion and Insights
- Dependency Density: The primary driver of long-context capability is the density of related information in training data. SPLiCe provides the necessary "practice" for the model to attend to distant but relevant tokens.
- The Power of Code: Training on structured code data (grouped by repository) surprisingly boosts performance on natural language tasks. The inherent cross-referencing in code serves as a high-quality signal for learning long-range dependencies.
- Efficiency: Long-context capabilities can be "unlocked" with as little as 2B to 6B tokens of fine-tuning, making it a highly efficient data-centric intervention compared to training from scratch.
Conclusion
SPLiCe demonstrates that data organization is as critical as architectural scaling for long-context LLMs. By replacing random example packing with semantically structured sequences, we can significantly improve a model's ability to utilize its entire context window, effectively solving the "lost-in-the-middle" problem and enhancing overall reasoning capabilities.
Summary updated