NExtLong: Toward Effective Long-Context Training without Long Documents

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

TL;DR

NExtLong is a training framework that solves the "long document scarcity" problem by synthesizing long-context training data from short documents. By interleaving "hard negative" distractors between chunks of a document, it forces Large Language Models (LLMs) to actively discriminate between relevant long-range context and distracting noise, significantly outperforming existing synthesis methods and even models trained on naturally occurring long documents.

What Problem Does This Paper Address?

Training LLMs to handle long contexts (like 128K tokens or more) typically requires massive amounts of high-quality, naturally long documents. Unfortunately, such documents are rare in many domains.

To bridge this gap, researchers often use "data synthesis"—simply concatenating multiple short documents together. However, this approach has a major flaw: it doesn't actually teach the model to handle long-range dependencies. The model can often "cheat" by focusing only on the most recent text. Furthermore, LLMs are easily distracted by irrelevant information as context length grows. The authors of NExtLong ask: How can we synthesize data that explicitly forces a model to learn long-range dependencies while ignoring distractions?

Methods

The NExtLong framework operates in two main stages: Negative Document Extension and Long-Range Dependence Modeling.

  1. Negative Document Extension: Instead of just sticking documents together, NExtLong takes a "meta-document" and breaks it into chunks. It then uses a retrieval system (FAISS) to find "hard negatives"—text segments from other documents that are semantically similar to the original chunks but ultimately irrelevant. These hard negatives are interleaved between the original document chunks.
  2. Long-Range Dependence Modeling: The model is trained on these "negative-extended" documents using standard next-token prediction.
The NExtLong method consists of two stages: document extension with hard negatives and subsequent training to model long-range dependencies.

The "magic" happens because the meta-chunks are now separated by a sea of distracting, yet plausible-looking, noise. To correctly predict the next part of the story or argument, the model must learn to look past the distractors and find the distant, relevant meta-chunk.

Datasets

The authors used two primary datasets for training, both consisting almost entirely of short documents:

  • Cosmopedia v2: A large-scale synthetic dataset of textbooks, blog posts, and stories.
  • FineWeb-Edu: A high-quality crawl of educational web pages.

For evaluation, they utilized the HELMET and RULER benchmarks, which cover a wide range of tasks including long-document QA, retrieval-augmented generation (RAG), and many-shot in-context learning (ICL). They also tested on LongBench v2 to see how the model performs after supervised fine-tuning (SFT).

Key Insights and Ideas

  • Hard Negatives are Essential: The "aha moment" is that random distractors are too easy for models to ignore. By using hard negatives (semantically similar text), the training task becomes difficult enough to actually reinforce long-range modeling.
  • Breaking the "Proximal Bias": Probing experiments showed that NExtLong-trained models assign more attention to distant relevant chunks and less to the immediate preceding text compared to baseline methods. This suggests the model is truly learning to "connect the dots" across the entire context window.
  • Synthesis > Reality?: Surprisingly, NExtLong-trained models often outperformed models like Llama-3.1-8B, which were trained on real, non-synthetic long documents. This suggests that the quality and difficulty of the training signal might be more important than the "naturalness" of the documents.

Key Results

NExtLong demonstrated superior performance across nearly all long-context benchmarks:

  • Average Improvement: It achieved a +7.33% average improvement over Quest, the previous state-of-the-art synthesis method.
  • Beating the Giants: A Llama-3-8B model trained with NExtLong outperformed Llama-3.1-8B by +4.69% and ProLong-512K by +5.42% on average across 128K context benchmarks.
  • Robustness: As shown in the figure below, the performance gap between NExtLong and other synthesis methods widens as the context length increases, proving its scalability.
Figure 3. Comparison of NExtLong with other data synthesis meth- ods on HELMET and RULER benchmarks across different context lengths. NExtLong shows significant performance improvements across various tasks.
  • ICL Prowess: In many-shot In-Context Learning tasks, NExtLong matched or even surpassed GPT-4o as the number of shots increased.

Limitations and Future Work

While highly effective, NExtLong does have some hurdles:

  • Retrieval Overhead: Building a FAISS index and performing top-k retrieval for every training sample adds computational complexity to the data preparation phase.
  • Chunking Granularity: The performance is sensitive to the size of the meta-chunks (the authors found 2048 tokens to be the "sweet spot"). Too small, and you lose semantic integrity; too large, and the hard negative mining becomes less effective.
  • Future Directions: The authors suggest exploring generative approaches to create even more diverse and "harder" distractors, potentially further pushing the limits of long-context training without needing a single real long document.

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