Introduction
As Large Language Models (LLMs) expand their context windows to 128K tokens and beyond, the primary bottleneck has shifted from model architecture to data quality. Many long-form documents in standard pre-training corpora are essentially "fake" long contexts—concatenations of unrelated short texts or disjointed logs that lack internal logical coherence. Training on such data can lead to a "lost-in-the-middle" phenomenon, where models fail to utilize information distant from the current token.
To address this, we introduce LADM (Long-context Attention-based Dependency Measurement), a framework designed to identify high-quality training samples by measuring internal long-range dependencies.
Methodology: The LADM Framework
LADM moves beyond traditional perplexity-based filtering, which measures predictability, to an attention-based approach that measures interconnectivity. The process consists of three main stages:
- Long Attention Calculator (LAC): A small proxy model (e.g., TinyLlama-1.1B) is briefly trained on long-context data to develop basic retrieval capabilities. This model serves as the "judge" for the entire corpus.
- Pairwise Focus Score (PFS): The LAC processes candidate documents to calculate attention weights between different token spans. High attention between distant spans indicates a strong logical dependency.
- Contextual Dependency Score (CDS): Pairwise scores are aggregated into a final CDS for each document. This score rewards documents with diverse and specific "look-back" patterns, prioritizing those that require the model to perform complex retrieval and reasoning.
Experimental Setup
The LADM framework was evaluated using The Pile as the source corpus, specifically filtering for samples with at least 32K tokens. Performance was measured across several benchmarks:
- LongBench: Evaluates single/multi-document QA, summarization, and code completion.
- Needle-in-the-Haystack: Tests the model's ability to retrieve a specific fact buried within a large context.
- Proof-Pile: Measures perplexity on real-world long-context data.
Key Results and Insights
LADM demonstrates significant improvements in data efficiency and model performance across various architectures, including OpenLlama, Llama2, and Mistral.
Performance and Efficiency
Training on just 1 billion tokens selected by LADM outperformed random sampling of 4 billion tokens. On average, LADM provided a 2.16% performance boost over the previous state-of-the-art method, ProLong. Notably, Mistral-7B saw a 10.09% improvement in single-document QA and a 4.66% gain in multi-document QA.
Needle-in-the-Haystack Retrieval
One of the most compelling results is the model's performance on synthetic retrieval tasks. Models trained with LADM-selected data achieved nearly 100% accuracy at 32K context lengths, effectively eliminating the "lost-in-the-middle" issue seen with random sampling.
Domain-Specific Dependencies
Analysis revealed that scientific papers (ArXiv), philosophy (PhilPapers), and legal documents (FreeLaw) exhibit the highest dependency scores. In contrast, Wikipedia and IRC logs often consist of unrelated facts or disjointed messages, making them less effective for long-context training.
Conclusion and Future Work
LADM provides a robust, attention-centric method for curating long-context training data. While it introduces some computational overhead due to the proxy model scoring step, the gains in data efficiency and retrieval accuracy are substantial. Future research will focus on scaling this approach to context windows exceeding 1M tokens and refining the proxy models to minimize selection bias.
Summary updated