LongWriter: Unleashing 10, 000+ Word Generation from Long Context LLMs

Yushi Bai, Jiajie Zhang, Xin Lv, Linzhi Zheng, Siqi Zhu, Lei Hou, Yuxiao Dong, Jie Tang, Juanzi Li · DOI · OpenReview

Sure, here's a blog-style summary of the paper "LongWriter: Unleashing 10,000+ Word Generation from Long Context LLMs" for a technically literate audience:

TL;DR

Large Language Models (LLMs) with long context windows struggle to generate outputs longer than a few thousand words. This paper identifies that the limitation stems from the scarcity of long-output examples in supervised fine-tuning (SFT) datasets. They introduce "AgentWrite," an agent-based pipeline to generate high-quality, long-form SFT data, and use it to train "LongWriter" models that can generate over 10,000 words, significantly improving upon existing LLMs.

What Problem Does This Paper Address?

Modern LLMs boast impressive context windows, capable of processing hundreds of thousands of tokens. However, a curious bottleneck emerges when it comes to generating text: even models with vast input capacities consistently fail to produce outputs exceeding approximately 2,000 words. This limitation is particularly problematic as a significant percentage of user prompts explicitly request longer outputs. The authors investigate this discrepancy, aiming to bridge the gap between LLMs' ability to understand long contexts and their ability to generate long, coherent texts.

Methods

The core of this paper lies in two main innovations:

  • AgentWrite Pipeline: To overcome the data scarcity issue, the authors propose AgentWrite, an agent-based system that decomposes the task of generating long-form content into smaller, manageable subtasks. It first creates a detailed writing plan (outline and word count for each paragraph) and then prompts an LLM to generate each paragraph sequentially, feeding the previously generated text as context. This "divide and conquer" approach allows off-the-shelf LLMs to produce coherent outputs up to 20,000 words.
  • LongWriter-6k Dataset & Model Training: Using AgentWrite and GPT-4o, the authors generate a new SFT dataset called LongWriter-6k, containing 6,000 examples with output lengths ranging from 2,000 to 32,000 words. This dataset is then used to fine-tune existing LLMs (GLM-4-9B and Llama-3.1-8B), resulting in the "LongWriter" models. They also employ Direct Preference Optimization (DPO) to further enhance the models' ability to follow length constraints and improve output quality.

Datasets

  • LongWriter-6k: A newly created dataset of 6,000 supervised fine-tuning (SFT) examples with ultra-long output lengths (2k-32k words), generated using the AgentWrite pipeline.
  • LongBench-Write: A new benchmark designed to evaluate ultra-long generation capabilities. It comprises 120 diverse prompts (60 English, 60 Chinese) with explicit word count requirements, categorized by output length and type. This benchmark is crucial for assessing both length adherence and output quality.
  • General SFT Data: Existing datasets, such as GLM-4's chat SFT data (180k examples), were used in conjunction with LongWriter-6k for training.

Key Insights and Ideas

  • SFT Data is the Bottleneck: The most significant insight is that an LLM's maximum generation length is fundamentally capped by the longest outputs present in its SFT dataset, not its pre-training context window. This explains the ubiquitous ~2,000-word limit.
  • Agent-Based Generation Works: The AgentWrite pipeline demonstrates that even standard LLMs can be orchestrated to produce lengthy, coherent outputs by breaking down the task and leveraging sequential generation with context.
  • Data is Key to Unlocking Potential: Existing long-context LLMs possess the latent capability for longer generation; it's primarily a matter of providing them with sufficient high-quality, long-output data during the alignment phase.

Key Results

  • AgentWrite Success: AgentWrite successfully enabled GPT-4o to generate outputs up to 20,000 words, significantly extending its practical generation length.
  • LongWriter Models: The LongWriter models (trained on LongWriter-6k) achieved state-of-the-art performance on the LongBench-Write benchmark, surpassing even larger proprietary models in generating outputs exceeding 10,000 words.
  • Length-Quality Trade-off: The LongWriter models maintained high output quality (Sq scores) while significantly improving length adherence (St scores), demonstrating that longer generation doesn't necessarily degrade quality.
  • DPO Benefits: Direct Preference Optimization (DPO) further boosted both length adherence (St) and quality (Sq) scores for the LongWriter-9B model.
  • Benchmark Performance: On LongBench-Write, LongWriter-9B-DPO achieved a win rate comparable to GPT-40 in human evaluations, despite having fewer parameters.

Limitations and Future Work

  • Data Scarcity for Extreme Lengths: While LongWriter models can generate up to 10k-20k words, the authors note that the scarcity of SFT data beyond 20k words remains a barrier to achieving even longer outputs (e.g., 100k+ words).
  • Minor Repetitions: Outputs generated by AgentWrite occasionally exhibited minor repetitions, suggesting room for improvement in coherence.
  • Future Directions:
    • Expand the AgentWrite framework to generate data for even longer outputs.
  • Refine AgentWrite to achieve higher quality long-output data.
  • Investigate methods to improve inference efficiency for these longer outputs without compromising quality.

Summary updated

BibTeX
@inproceedings{bai2025longwriter,
  author = {Yushi Bai and Jiajie Zhang and Xin Lv and Linzhi Zheng and Siqi Zhu and Lei Hou and Yuxiao Dong and Jie Tang and Juanzi Li},
  title = {{LongWriter: Unleashing 10, 000+ Word Generation from Long Context LLMs}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=kQ5s9Yh0WI},
}
Figure