LongMagpie: A Self-synthesis Method for Generating Large-scale Long-context Instructions

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

TL;DR

This paper introduces LongMagpie, a novel self-synthesis framework that automatically generates large-scale, high-quality instruction data for long-context Large Language Models (LLMs). By leveraging the auto-regressive capabilities of existing LLMs, LongMagpie bypasses the need for costly human annotation or complex prompt engineering, making advanced long-context LLMs more accessible.

What Problem Does This Paper Address?

Large Language Models (LLMs) are increasingly capable of processing and understanding very long documents, which is crucial for applications like document summarization, complex question answering, and code planning. However, training these models to effectively utilize long contexts requires vast amounts of high-quality instruction data. While many powerful LLMs are publicly available, the datasets used to fine-tune them for long-context understanding are often proprietary. Creating such datasets through human annotation is prohibitively expensive and time-consuming, and existing automated methods often lack the scale, diversity, and quality needed for effective training. This creates a significant barrier to the advancement and accessibility of open-source long-context LLMs.

Methods

LongMagpie employs a two-stage self-synthesis pipeline:

  1. Query and Answer Generation: The core idea is to leverage the inherent ability of already instruction-tuned LLMs to generate relevant queries. When an LLM is presented with a document followed by special tokens that typically precede a user query (but without the query itself), it auto-regressively generates contextually relevant questions about the document. LongMagpie then uses the LLM to generate responses to these queries, forming instruction triplets (document, query, response). This process is automated and does not require explicit prompting for query generation.
  2. Multi-Document Extension: To further enhance the complexity and real-world applicability, LongMagpie extends its approach to multi-document settings. It can combine multiple documents to create instruction data that requires cross-document reasoning, mimicking scenarios where information is spread across various sources.

Additionally, the paper introduces the p-Mix strategy to address a common issue: fine-tuning solely on long-context data can degrade performance on short-context tasks. p-Mix probabilistically mixes long-context instructions generated by LongMagpie with existing short-context instruction data during training, aiming to balance performance across both.

Datasets

  • Training Data Generation: LongMagpie generates its instruction data using documents sampled from FineWeb-Edu, an educational web content dataset.
  • Evaluation Benchmarks:
    • Long-context: HELMET, RULER, and Longbench v2.
  • Short-context: HellaSwag, Lambada_OpenAI, ARC-Challenge, ARC-Easy, PIQA, WinoGrande, and Logiqa.
  • Comparison Datasets: The paper compares LongMagpie against existing long-context datasets like ChatQA and LongAlign, as well as short-context datasets like Tulu, Magpie, and UltraChat (which are adapted for long-context fine-tuning).

Key Insights and Ideas

  • LLMs as Query Generators: The most significant insight is that aligned LLMs, when primed with a document and query-indicating tokens, can auto-regressively generate relevant queries without explicit instruction. This turns the LLM itself into a data generator.
  • Self-Synthesis for Scale and Diversity: This self-synthesis approach allows for the generation of a large volume of diverse instruction data without human intervention, overcoming the limitations of manual annotation and template-based methods.
  • p-Mix for Balanced Performance: The p-Mix strategy effectively bridges the gap between long-context and short-context capabilities, preventing the typical performance degradation on shorter tasks when models are heavily trained on long contexts.

Key Results

  • Models trained on LongMagpie data achieved leading performance on long-context benchmarks (HELMET, RULER, Longbench v2), outperforming existing datasets like ChatQA and LongAlign. For instance, LongMagpie achieved a +6.44 improvement on the LongAVG score compared to LongAlign.
  • When combined with the p-Mix strategy, LongMagpie-trained models maintained competitive performance on short-context tasks, with the LongMagpie + UltraChat model achieving the best ShortAVG score among mixed datasets.
  • The multi-document extension of LongMagpie significantly improved performance on long-context tasks, with optimal results observed when incorporating around 10 additional documents.
  • The generated LongMagpie queries were found to have higher quality and better diversity compared to other datasets, as assessed by reward models and t-SNE visualizations.
  • LongMagpie demonstrated exceptional sample efficiency, requiring substantially fewer tokens per instruction during synthesis compared to methods like ChatQA and LongAlign.

Limitations and Future Work

  • Inherited Biases: LongMagpie inherits biases from the source LLMs used for data generation, which future work should aim to detect and mitigate.
  • Limited Output Formats: The current implementation primarily focuses on document-query relationships and may not adequately cover tasks requiring long-form outputs or complex generation. Future research could expand support for diverse output formats and analytical tasks.

Summary updated

BibTeX
@inproceedings{gao2025longmagpie,
  author = {Chaochen Gao and Xing Wu and Zijia Lin and Debing Zhang and Songlin Hu},
  title = {{LongMagpie: A Self-synthesis Method for Generating Large-scale Long-context Instructions}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=tuA2R6gZEA},
}
Figure