Lost in the Middle: How Language Models Use Long Contexts
Written for the Research library (claude-opus-5-5) from the paper text, in our own words: the license "arXiv — non-exclusive licence to distribute" does not allow redistributing the text itself. Original — arxiv.org/pdf/2307.03172
Summary
Modern language models can accept inputs of thousands or even tens of thousands of tokens, but it was unclear whether they actually use information spread across such long inputs. The authors test this with controlled experiments on two tasks. The first is multi-document question answering built from NaturalQuestions-Open, where one Wikipedia passage holds the answer and the rest are retrieved distractors. The second is a synthetic lookup task over JSON key-value pairs. They vary how much context is given and where the relevant item sits. They evaluate open models (MPT-30B-Instruct, LongChat-13B (16K)) and closed ones (GPT-3.5-Turbo, Claude-1.3). Accuracy forms a U-shaped curve: models do best when the key evidence comes first or last and worst when it sits in the middle. Versions with larger context windows show no clear advantage. Further analyses look at encoder-decoder architectures, repeating the query before and after the context, and instruction tuning. The findings matter for retrieval-augmented systems. The authors argue that a long-context model should be judged partly on how little its accuracy depends on where the evidence is placed. Code and evaluation data are released.
Key points
- Data: 2,655 NaturalQuestions-Open queries whose annotated long answer is a paragraph. Each document is a Wikipedia chunk of at most 100 tokens. Distractors come from Contriever (fine-tuned on MS-MARCO), and chunks that contain a gold answer are filtered out.
- Middle placement: when the answer passage sits in the middle of the context, GPT-3.5-Turbo scores below its closed-book accuracy of 56.1%, which it reaches with no documents at all.
- Key-value retrieval: some models solve the task perfectly, while others still miss keys placed mid-context. Putting the query both before and after the data makes this synthetic task nearly perfect but barely changes the QA results.
- Architecture and tuning: encoder-decoder models are robust to position only on inputs no longer than those seen in training. Base models without instruction fine-tuning also show the U-shaped curve.
- Open-domain QA case study: going from 20 to 50 retrieved passages adds only about 1.5% for GPT-3.5-Turbo and about 1% for Claude-1.3. Reader accuracy levels off long before retriever recall does, which suggests reranking or truncating the retrieved list.
Cited by
- L-Eval: Instituting Standardized Evaluation for Long Context Language Models
- ResearchAgent: Iterative Research Idea Generation over Scientific Literature with Large Language Models
- LongBench: A Bilingual, Multitask Benchmark for Long Context Understanding
- PyramidKV: Dynamic KV Cache Compression based on Pyramidal Information Funneling
- A Survey on In-context Learning
- Ragas: Automated Evaluation of Retrieval Augmented Generation
- Promptbreeder: Self-Referential Self-Improvement Via Prompt Evolution
- Retrieval-Augmented Generation for Large Language Models: A Survey
- RULER: What's the Real Context Size of Your Long-Context Language Models?
- A Survey on Hallucination in Large Language Models: Principles, Taxonomy, Challenges, and Open Questions
- LongLLMLingua: Accelerating and Enhancing LLMs in Long Context Scenarios via Prompt Compression
- SWE-bench: Can Language Models Resolve Real-World GitHub Issues?
- Challenges and Applications of Large Language Models
- LooGLE: Can Long-Context Language Models Understand Long Contexts?
- DataComp-LM: In search of the next generation of training sets for language models
- Long-context LLMs Struggle with Long In-context Learning
- SnapKV: LLM Knows What You are Looking for Before Generation
- Encouraging Divergent Thinking in Large Language Models through Multi-Agent Debate
- Query Rewriting in Retrieval-Augmented Large Language Models
- LLMLingua-2: Data Distillation for Efficient and Faithful Task-Agnostic Prompt Compression
- Large Language Models are Effective Text Rankers with Pairwise Ranking Prompting
- Code Llama: Open Foundation Models for Code
- RAPTOR: Recursive Abstractive Processing for Tree-Organized Retrieval
- Personality Traits in Large Language Models
- Integrating Neural and Symbolic Components in a Model of Pragmatic Question-Answering
- Replacing Judges with Juries: Evaluating LLM Generations with a Panel of Diverse Models
- FreshLLMs: Refreshing Large Language Models with Search Engine Augmentation
- Survey on Factuality in Large Language Models: Knowledge, Retrieval and Domain-Specificity
- Long-form factuality in large language models
- InfLLM: Training-Free Long-Context Extrapolation for LLMs with an Efficient Context Memory
- Benchmarking Retrieval-Augmented Generation for Medicine
- Retrieval meets Long Context Large Language Models
- SWE-agent: Agent-Computer Interfaces Enable Automated Software Engineering
- Siren's Song in the AI Ocean: A Survey on Hallucination in Large Language Models
- Explainability for Large Language Models: A Survey
- A Survey of Large Language Models
- Large Language Models for Information Retrieval: A Survey
Cite
@misc{liu2023lost,
title = {{Lost in the Middle: How Language Models Use Long Contexts}},
author = {Liu, Nelson F. and Lin, Kevin and Hewitt, John and Paranjape, Ashwin and Bevilacqua, Michele and Petroni, Fabio and Liang, Percy},
year = {2023},
doi = {10.48550/arxiv.2307.03172},
eprint = {2307.03172},
archivePrefix = {arXiv},
url = {https://doi.org/10.48550/arxiv.2307.03172}
}References
- Avi Arampatzis, Jaap Kamps, and Stephen Robertson. 2009. Where to stop reading a ranked list? threshold optimization using truncated score distributions. In Proc. of SIGIR. find
- Iz Beltagy, Matthew E. Peters, and Arman Cohan. 2020. Longformer: The long-document transformer. ArXiv:2004.05150. find
- Hyung Won Chung, Le Hou, Shayne Longpre, Barret Zoph, Yi Tay, William Fedus, Yunxuan Li, Xuezhi Wang, Mostafa Dehghani, Siddhartha Brahma, Albert Webson, Shixiang Shane Gu, Zhuyun Dai, Mirac Suzgun, Xinyun Chen, Aakanksha Chowdhery, Alex Castro-Ros, Marie Pellat, Kevin Robinson, Dasha Valter, Sharan… find
- Zihang Dai, Zhilin Yang, Yiming Yang, Jaime Carbonell, Quoc Le, and Ruslan Salakhutdinov. 2019. Transformer-XL: Attentive language models beyond a fixed-length context. In Proc. of ACL. find
- Michał Daniluk, Tim Rocktäschel, Johannes Welbl, and Sebastian Riedel. 2017. Frustratingly short attention spans in neural language modeling. In Proc. of ICLR. find
- Tri Dao, Daniel Y. Fu, Stefano Ermon, Atri Rudra, and Christopher Ré. 2022. FlashAttention: Fast and memory-efficient exact attention with IO-awareness. ArXiv:2205.14135. find
- Hermann Ebbinghaus. 1913. Memory: A contribution to experimental psychology. H. A. Ruger & C. E. Bussenius, Trans. find
- Albert Gu, Karan Goel, and Christopher Ré. 2022. Efficiently modeling long sequences with structured state spaces. In Proc. of ICLR. find
- Maor Ivgi, Uri Shaham, and Jonathan Berant. 2023. Efficient long-text understanding with short-text models. Transactions of the Association for Computational Linguistics, 11:284–299. find
- Gautier Izacard, Mathilde Caron, Lucas Hosseini, Sebastian Riedel, Piotr Bojanowski, Armand Joulin, and Edouard Grave. 2021. Unsupervised dense information retrieval with contrastive learning. ArXiv:2112.09118. find our card
- Gautier Izacard and Edouard Grave. 2021. Leveraging passage retrieval with generative models for open domain question answering. In Proc. of EACL. find our card
- Nikhil Kandpal, Haikang Deng, Adam Roberts, Eric Wallace, and Colin Raffel. 2022. Large language models struggle to learn long-tail knowledge. ArXiv:2211.08411. find our card
- Urvashi Khandelwal, He He, Peng Qi, and Dan Jurafsky. 2018. Sharp nearby, fuzzy far away: How neural language models use context. In Proc. of ACL. find
- Kalpesh Krishna, Yapei Chang, John Wieting, and Mohit Iyyer. 2022. RankGen: Improving text generation with large ranking models. In Proc. of EMNLP. find
- Tom Kwiatkowski, Jennimaria Palomaki, Olivia Redfield, Michael Collins, Ankur Parikh, Chris Alberti, Danielle Epstein, Illia Polosukhin, Jacob Devlin, Kenton Lee, Kristina Toutanova, Llion Jones, Matthew Kelcey, Ming-Wei Chang, Andrew M. Dai, Jakob Uszkoreit, Quoc Le, and Slav Petrov. 2019. Natural… find our card
- Kenton Lee, Ming-Wei Chang, and Kristina Toutanova. 2019. Latent retrieval for weakly supervised open domain question answering. In Proc. of ACL. find our card
- Mina Lee, Percy Liang, and Qian Yang. 2022. CoAuthor: Designing a human-AI collaborative writing dataset for exploring language model capabilities. In Proc. of CHI. find
- Dacheng Li, Rulin Shao, Anze Xie, Ying Sheng, Lianmin Zheng, Joseph E. Gonzalez, Ion Stoica, Xuezhe Ma, , and Hao Zhang. 2023. How long can open-source LLMs truly promise on context length? find
- Alex Mallen, Akari Asai, Victor Zhong, Rajarshi Das, Daniel Khashabi, and Hannaneh Hajishirzi. 2023. When not to trust language models: Investigating effectiveness of parametric and non-parametric memories. In Proc. of ACL. find
- Sewon Min, Julian Michael, Hannaneh Hajishirzi, and Luke Zettlemoyer. 2020. AmbigQA: Answering ambiguous open-domain questions. In Proc. of EMNLP. find
- Bennet B. Murdock Jr. 1962. The serial position effect of free recall. Journal of experimental psychology, 64(5):482. find
- Joe O’Connor and Jacob Andreas. 2021. What context features can Transformer language models use? In Proc. of ACL. find
- Dimitris Papailiopoulos, Kangwook Lee, and Jy-yong Sohn. 2023. A little retrieval test for large language models. https://github.com/anadim/the-little-retrieval-test. ↗
- Bo Peng. 2023. RWKV-LM. https://github. com/BlinkDL/RWKV-LM. find
- Hao Peng, Nikolaos Pappas, Dani Yogatama, Roy Schwartz, Noah Smith, and Lingpeng Kong. 2021. Random feature attention. In Proc. of ICLR. find
- Fabio Petroni, Patrick Lewis, Aleksandra Piktus, Tim Rocktäschel, Yuxiang Wu, Alexander H Miller, and Sebastian Riedel. 2020. How context affects language models’ factual predictions. In Proc. of AKBC. find our card
- Michael Poli, Stefano Massaroli, Eric Nguyen, Daniel Y. Fu, Tri Dao, Stephen Baccus, Yoshua Bengio, Stefano Ermon, and Christopher Ré. 2023. Hyena hierarchy: Towards larger convolutional language models. In Proc. of ICML. find
- Ofir Press, Noah A. Smith, and Mike Lewis. 2021. Shortformer: Better language modeling using shorter inputs. In Proc. of ACL. find
- Ofir Press, Noah A. Smith, and Mike Lewis. 2022. Train short, test long: Attention with linear biases enables input length extrapolation. In Proc. of ICLR. find
- Guanghui Qin, Yukun Feng, and Benjamin Van Durme. 2023. The NLP task effectiveness of long-range transformers. In Proc. of EACL. find
- Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, and Peter J. Liu. 2020. Exploring the limits of transfer learning with a unified text-to-text Transformer. Journal of Machine Learning Research, 21(140):1–67. find
- Ori Ram, Yoav Levine, Itay Dalmedigos, Dor Muhlgay, Amnon Shashua, Kevin Leyton-Brown, and Yoav Shoham. 2023. In-context retrieval-augmented language models. ArXiv:2302.00083. find
- Ohad Rubin and Jonathan Berant. 2023. Long-range language modeling with self-retrieval. ArXiv:2306.13421. — [arXiv:2306.13421](https://arxiv.org/abs/2306.13421) find
- Chinnadhurai Sankar, Sandeep Subramanian, Chris Pal, Sarath Chandar, and Yoshua Bengio. 2019. Do neural dialog systems use the conversation history effectively? an empirical study. In Proc. of ACL. find
- Timo Schick, Jane Dwivedi-Yu, Roberto Dessì, Roberta Raileanu, Maria Lomeli, Luke Zettlemoyer, Nicola Cancedda, and Thomas Scialom. 2023. Toolformer: Language models can teach themselves to use tools. find our card
- Uri Shaham, Maor Ivgi, Avia Efrat, Jonathan Berant, and Omer Levy. 2023. ZeroSCROLLS: A zero-shot benchmark for long text understanding. ArXiv:2305.14196. find
- Vatsal Sharan, Sham Kakade, Percy Liang, and Gregory Valiant. 2018. Prediction with a short memory. In Proc. of STOC. find
- Weijia Shi, Sewon Min, Michihiro Yasunaga, Minjoon Seo, Rich James, Mike Lewis, Luke Zettlemoyer, and Wen tau Yih. 2023. REPLUG: Retrieval-augmented black-box language models. ArXiv:2301.12652. find our card
- Kurt Shuster, Jing Xu, Mojtaba Komeili, Da Ju, Eric Michael Smith, Stephen Roller, Megan Ung, Moya Chen, Kushal Arora, Joshua Lane, Morteza Behrooz, William Ngan, Spencer Poff, Naman Goyal, Arthur Szlam, Y-Lan Boureau, Melanie Kambadur, and Jason Weston. 2022. BlenderBot 3: a deployed conversational… find our card
- Simeng Sun, Kalpesh Krishna, Andrew Mattarella-Micke, and Mohit Iyyer. 2021. Do long-range language models actually use long-range context? In Proc. of EMNLP. find
- Yi Tay, Mostafa Dehghani, Vinh Q. Tran, Xavier Garcia, Jason Wei, Xuezhi Wang, Hyung Won Chung, Siamak Shakeri, Dara Bahri, Tal Schuster, Huaixiu Steven Zheng, Denny Zhou, Neil Houlsby, and Donald Metzler. 2023. UL2: Unifying language learning paradigms. ArXiv:2205.05131. find our card
- Romal Thoppilan, Daniel De Freitas, Jamie Hall, Noam Shazeer, Apoorv Kulshreshtha, Heng-Tze Cheng, Alicia Jin, Taylor Bos, Leslie Baker, Yu Du, YaGuang Li, Hongrae Lee, Huaixiu Steven Zheng, Amin Ghafouri, Marcelo Menegali, Yanping Huang, Maxim Krikun, Dmitry Lepikhin, James Qin, Dehao Chen, Yuanzho… find our card
- Hugo Touvron, Thibaut Lavril, Gautier Izacard, Xavier Martinet, Marie-Anne Lachaux, Timothée Lacroix, Baptiste Rozière, Naman Goyal, Eric Hambro, Faisal Azhar, Aurelien Rodriguez, Armand Joulin, Edouard Grave, and Guillaume Lample. 2023a. LLaMA: Open and efficient foundation language models. ArXiv:2… find
- Hugo Touvron, Louis Martin, Kevin Stone, Peter Albert, Amjad Almahairi, Yasmine Babaei, Nikolay Bashlykov, Soumya Batra, Prajjwal Bhargava, Shruti Bhosale, Dan Bikel, Lukas Blecher, Cristian Canton Ferrer, Moya Chen, Guillem Cucurull, David Esiobu, Jude Fernandes, Jeremy Fu, Wenyin Fu, Brian Fuller,… find
- Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Łukasz Kaiser, and Illia Polosukhin. 2017. Attention is all you need. In Proc. of NeurIPS. find
- Sinong Wang, Belinda Z. Li, Madian Khabsa, Han Fang, and Hao Ma. 2020. Linformer: Self-attention with linear complexity. ArXiv:2006.04768. find
- Manzil Zaheer, Guru Guruganesh, Kumar Avinava Dubey, Joshua Ainslie, Chris Alberti, Santiago Ontanon, Philip Pham, Anirudh Ravula, Qifan Wang, Li Yang, and Amr Ahmed. 2020. Big Bird: Transformers for longer sequences. In Proc. of NeurIPS. find our card