NExtLong: Toward Effective Long-Context Training without Long Documents

Chaochen Gao, Xing Wu, Zijia Lin, Debing Zhang, Songlin Hu · OpenReview

Abstract

Large language models (LLMs) with extended context windows have made significant strides yet remain a challenge due to the scarcity of long documents. Existing methods tend to synthesize long-context data but lack a clear mechanism to reinforce the long-range dependency modeling. To address this limitation, we propose NExtLong, a novel framework for synthesizing long-context data through Negative document Extension. NExtLong decomposes a document into multiple meta-chunks and extends the context by interleaving hard negative distractors retrieved from pretraining corpora. This approach compels the model to discriminate long-range dependent context from distracting content, enhancing its ability to model long-range dependencies. Extensive experiments demonstrate that NExtLong achieves significant performance improvements on the HELMET and RULER benchmarks compared to existing long-context synthesis approaches and leading models, which are trained on non-synthetic long documents. These findings highlight NExtLong's ability to reduce reliance on non-synthetic long documents, making it an effective framework for developing advanced long-context LLMs.

Introduction

As Large Language Models (LLMs) evolve, their context windows—the volume of text they can process in a single pass—have expanded from 4K to 128K tokens and beyond. However, a significant bottleneck persists: high-quality, non-synthetic long documents (such as books, legal filings, or technical manuals) are surprisingly scarce in the wild.

To bridge this gap, researchers often resort to synthesizing long-context data by concatenating unrelated short documents. However, this "naive" synthesis fails to teach the model how to identify relevant information across long distances; instead, it often trains the model to ignore the majority of the context. When faced with real-world long-range tasks, these models are easily distracted by irrelevant information. NExtLong addresses this by introducing a framework that forces models to strengthen their long-range dependency modeling through active discrimination.

The NExtLong Framework

NExtLong operates on the principle that long-context capability is not just about memory, but about the ability to discriminate relevant signals from noise. The framework utilizes a two-stage process: Negative Document Extension and Long-Range Dependence Modeling.

1. Negative Document Extension

The synthesis process begins with a "meta-document" (a coherent piece of text) which is split into sequential meta-chunks while preserving paragraph integrity. For each meta-chunk, the system performs Hard Negative Mining using a FAISS index to retrieve the top-$k$ most semantically similar—but ultimately unrelated—snippets from a massive pretraining corpus.

These snippets are "hard negatives" because they share semantic themes with the original document, making them difficult for the model to ignore. The final training document is constructed by interleaving: placing a meta-chunk, followed by its retrieved hard negatives, then the next meta-chunk, and so on. This structure creates a "needle-in-a-haystack" environment throughout the entire training set.

2. Long-Range Dependence Modeling

The model is trained using standard Next Token Prediction (NTP) loss on this synthesized text. Because the related meta-chunks are separated by thousands of tokens of distracting but similar-looking text, the model must learn to maintain the original document's thread across vast distances. This "resistance training" for the attention mechanism forces the model to prioritize long-range dependencies over local, distracting context.

Experimental Setup and Results

Training and Evaluation

The authors trained models using Cosmopedia v2 (synthetic textbooks and stories) and FineWeb-Edu (educational web pages). Notably, these source datasets consist almost entirely of short documents (under 8K tokens). The resulting models were evaluated on several rigorous benchmarks:

  • HELMET: 17 sub-tasks covering recall, RAG, long-form QA, and re-ranking.
  • RULER: 13 sub-tasks designed to test the "effective" context size.
  • LongBench v2: Evaluation for models after supervised fine-tuning (SFT).
  • Needle-in-a-Haystack: The standard test for information retrieval within long contexts.

Key Findings

  • Superior Synthesis: NExtLong outperformed other synthesis methods (such as Quest, KNN, and ICLM) by an average of 7.33% on the HELMET and RULER benchmarks.
  • Outperforming Native Long-Context Models: A Llama-3-8B model trained with NExtLong (up to 512K context) outperformed the official Llama-3.1-8B—which was trained on real long documents—on several benchmarks, including a +4.69% average lead across HELMET tasks.
  • Effective Context Utilization: The model achieved 100% accuracy on the Needle-in-a-Haystack test up to the 512K token limit.
  • Preservation of General Abilities: Training on these long synthetic documents did not degrade performance on standard short-text benchmarks like MMLU or ARC-C, suggesting no "short-context tax."

Analysis of the Method

Several factors contribute to NExtLong's success:

  • The Role of Discrimination: The model's ability to process long context is directly tied to its ability to discriminate between relevant and irrelevant information. NExtLong effectively reduces "recency bias," where models over-rely on the most proximal text.
  • Optimal Granularity: The authors identified a "Goldilocks zone" for chunking. Chunks of approximately 2048 tokens were found to be the most effective; smaller chunks break semantic meaning, while larger chunks reduce the frequency of the discrimination challenge.
  • Strategic Positioning: Placing the meta-chunk before its negatives (the "Head" position) yielded the best results. This configuration forces the model to hold the relevant information in memory while processing subsequent distractors.

Conclusion

NExtLong demonstrates that the scarcity of long-form training data is not an insurmountable barrier to developing long-context LLMs. By using hard negative distractors to create a challenging training environment, NExtLong enables models to achieve state-of-the-art long-range dependency modeling using only short-document sources. This framework provides a scalable and effective path forward for the development of advanced, long-context artificial intelligence.

Summary updated

BibTeX
@inproceedings{gao2025nextlong,
  author = {Chaochen Gao and Xing Wu and Zijia Lin and Debing Zhang and Songlin Hu},
  title = {{NExtLong: Toward Effective Long-Context Training without Long Documents}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=Q9DAI0AYv1},
}
Figure