# Lost in the Middle: How Language Models Use Long Contexts

Language models miss information placed in the middle of long prompts

Nelson F. Liu, Kevin Lin, John Hewitt, Ashwin Paranjape, Michele Bevilacqua, Fabio Petroni and 1 more · arXiv · 2023-7-6

- **Problem** Long-context models can take long inputs, but it was unclear how well they use them. Accuracy fell when the answer sat mid-context, even in models built for long inputs.
- **Method** The authors keep the question and documents fixed and move only the passage holding the answer. Each prompt holds one gold passage and distractors from Contriever.
- **Results** GPT-3.5-Turbo with 20 documents fell from 75.8% when the answer was first to 53.8% when it was tenth.

## Why the position of relevant text matters

Language models now receive prompts of thousands of tokens, such as long documents, chat histories and retrieved search results. Context windows now reach 32K and even 100K tokens, yet it is unclear how models use that extra length. The cost problem explains the history: Transformer memory and compute grow quadratically with sequence length, so earlier models were trained with windows of 512 to 2048 tokens.

A robust model should give the same answer wherever the relevant text sits, so position sensitivity is the test that matters.

The authors show that accuracy can fall when the answer sits mid-context, even in models built for long inputs. Search-based chat and retrieval-augmented generation put many passages into one prompt, so the effect reaches real products.

## A question, distractors and one moving answer

The key idea is to keep the question and the passage set fixed and move only the passage that contains the answer. Each input holds one question and k documents, and exactly one of them contains the answer while the other k − 1 are distractors. Passages are Wikipedia chunks of at most 100 tokens, and the answer passage is the Wikipedia paragraph that the NaturalQuestions annotation points to.

Distractors come from Contriever, fine-tuned on MS-MARCO, which retrieves the chunks most relevant to the query while excluding every gold answer.

The distractors keep their order of decreasing relevance, so the main change across runs is where the answer passage lands. Context length changes by adding or removing distractors, which builds the 10, 20 and 30 document settings. Those settings correspond to roughly 2K, 4K and 6K tokens. The study starts from 2655 NaturalQuestions-Open queries whose annotated long answer is a paragraph.

A prediction counts as correct when any gold answer appears in it, and the models decode greedily. Two open models and four closed ones are scored, including MPT-30B-Instruct, which has an 8192-token maximum. Closed-book and oracle runs give reference points for each model.

## How accuracy moves with answer position

Accuracy traces a U-shape: it is highest when the answer is first or last and lowest in the middle. The authors name the two ends primacy bias and recency bias. GPT-3.5-Turbo with 20 documents fell from 75.8% when the answer was first to 53.8% when it was tenth. Across settings the drop can exceed 20%, and in the 20- and 30-document settings the worst position scores below the closed-book accuracy of 56.1%.

For these settings, placing the answer mid-prompt is worse than providing no documents at all. The oracle score of 88.3% sets a ceiling well above the mid-context scores.

Models with extended windows do not escape this pattern. When both windows fit the input, GPT-3.5-Turbo and GPT-3.5-Turbo (16K) produce nearly superimposed curves at 10 and 20 documents. A larger window alone therefore does not improve use of the middle of the context.

## Fetching a key from a JSON object

The key-value task is a stripped-down check of basic retrieval: the prompt is a JSON object and the model returns the value for one key. Keys and values are random UUIDs, so there is little language for the model to lean on. The authors use 75, 140 and 300 pairs, with 500 examples per setting, and move the queried key within the object.

Claude-1.3 and Claude-1.3 (100K) are close to perfect at every length. GPT-3.5-Turbo, GPT-3.5-Turbo (16K) and MPT-30B-Instruct do worst when the key sits in the middle, especially at 140 or 300 pairs. LongChat-13B (16K) differs: with the key at the start, it often writes code to find the key rather than printing the value. So the failure is not limited to long prose, because a simple lookup also weakens when the target sits mid-object.

## What does and doesn't change the U-shape

Query-aware contextualization places the query both before and after the data. Decoder-only models can't see the query while encoding the documents, because it only appears at the end, so repeating it lets each passage be read in light of the question. This raises key-value retrieval to near-perfect, while without it the worst-case accuracy is 45.6%.

In multi-document QA the change barely moves the curve: it helps when the answer is first and slightly hurts elsewhere.

Flan-UL2 has a bidirectional encoder, and within its 2048-token training window its best and worst positions differ by only 1.9%. Beyond that window its performance drops in the middle, and Flan-T5-XXL shows the same trend. The authors hypothesize that the bidirectional encoder lets each document be processed alongside later documents, which could improve how models weigh documents against one another.

The authors compare MPT-30B with its instruction-tuned version, MPT-30B-Instruct. Both show a U-shape, so instruction fine-tuning is not what creates the pattern. Tuning does narrow the worst-case gap, from nearly 10% to around 4%. The authors suggest the pattern may come from similarly formatted Internet text seen in pre-training, though they only hypothesize this.

With Llama-2 models, the 7B size is recency-biased only, while the 13B and 70B models show a U-shape. The 13B base model has a 20-point gap between its best and worst positions, and fine-tuning leaves a 10-point worst-case degradation.

## Does more retrieved context help a reader?

The authors run a standard retriever-reader setup on NaturalQuestions-Open, with Contriever returning the top k Wikipedia documents. Retriever recall keeps rising with k, but reader accuracy levels off much earlier. Going from 20 to 50 documents adds about 1.5% for GPT-3.5-Turbo and about 1% for Claude-1.3, while also raising latency and cost.

Because models use the start and end of a context best, the authors suggest reranking to push relevant passages forward or truncating the list. They frame these as promising directions rather than tested methods.

## Limitations

GPT-4 was checked only on 500 random multi-document examples with 20 total documents. A full run would have cost upwards of $6000, which is why the subset was used. The main sweeps rely on NaturalQuestions-Open with greedy decoding, and other decoding methods were left to future work. The key-value task uses random UUIDs, so it doesn't test ordinary prose.

The standard Wikipedia dump has a small temporal mismatch with NaturalQuestions, and an unambiguous subset gave similar results.

## Paper info

- **Authors**: Nelson F. Liu, Kevin Lin, John Hewitt, Ashwin Paranjape, Michele Bevilacqua, Fabio Petroni, Percy Liang
- **Venue**: arXiv · Preprint
- **First published**: 2023-7-6
- **Added**: 2026-11-12
- **Updated**: 2023-11-20
- **Version**: v3
- **arXiv**: 2307.03172
- **Category**: cs.CL
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/2307.03172v3) · [PDF ↗](https://arxiv.org/pdf/2307.03172v3)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Nelson F. Liu, Kevin Lin, John Hewitt, Ashwin Paranjape, Michele Bevilacqua, Fabio Petroni, Percy Liang (2023). Lost in the Middle: How Language Models Use Long Contexts. arXiv:2307.03172v3. https://arxiv.org/abs/2307.03172v3

**BibTeX**

```
@misc{liu2023lost,
  title = {{Lost in the Middle: How Language Models Use Long Contexts}},
  author = {Nelson F. Liu and Kevin Lin and John Hewitt and Ashwin Paranjape and Michele Bevilacqua and Fabio Petroni and Percy Liang},
  year = {2023},
  eprint = {2307.03172},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2307.03172v3}
}
```

## Other paper commentary

- [MiniGPT-4: Enhancing Vision-Language Understanding with Advanced Large Language Models](https://refivu.com/en/papers/f07e6e3f-3ab5-42dc-98c8-a32fe7d8820d-minigpt-4-enhancing-vision-language-understanding-with.md)
- [Learning to Prompt for Vision-Language Models](https://refivu.com/en/papers/c492cb20-7c19-4275-b139-f97eecec7359-learning-to-prompt-for-vision-language-models.md)
- [Universal and Transferable Adversarial Attacks on Aligned Language Models](https://refivu.com/en/papers/6bc6f22f-cd10-41c0-ba7c-3e3d376cf3b9-universal-and-transferable-adversarial-attacks-on-aligned.md)
- [Code Llama: Open Foundation Models for Code](https://refivu.com/en/papers/d1b3e035-fd64-4a9c-a7a6-cfb45de54052-code-llama-open-foundation-models-for-code.md)
- [Qwen-VL: A Versatile Vision-Language Model for Understanding, Localization, Text Reading, and Beyond](https://refivu.com/en/papers/11ff1363-cafd-421d-bece-bfc246ea3170-qwen-vl-a-versatile-vision-language-model-for.md)
- [A Survey on Evaluation of Large Language Models](https://refivu.com/en/papers/46dfd405-ef56-4804-b283-8d9be353baaf-a-survey-on-evaluation-of-large-language-models.md)
- [KPConv: Flexible and Deformable Convolution for Point Clouds](https://refivu.com/en/papers/aadc9ee6-ee0e-485d-ae5a-841bc5fcdfb3-kpconv-flexible-and-deformable-convolution-for-point-clouds.md)
- [InfoGAN: Interpretable Representation Learning by Information Maximizing Generative Adversarial Nets](https://refivu.com/en/papers/9891b5b5-2ddd-42e7-a5df-4b7e02d593dc-infogan-interpretable-representation-learning-by-information.md)
- [RandAugment: Practical automated data augmentation with a reduced search space](https://refivu.com/en/papers/8b56147c-5b9a-4e55-85b2-0f0992053956-randaugment-practical-automated-data-augmentation-with-a.md)
- [MnasNet: Platform-Aware Neural Architecture Search for Mobile](https://refivu.com/en/papers/9898212b-ee8e-448d-817e-c0047d43e15a-mnasnet-platform-aware-neural-architecture-search-for-mobile.md)
- [Robust Recovery of Subspace Structures by Low-Rank Representation](https://refivu.com/en/papers/14c27646-6e22-4f5b-b820-67e75508bf84-robust-recovery-of-subspace-structures-by-low-rank.md)
- [Self-Attention Generative Adversarial Networks](https://refivu.com/en/papers/819d5b11-1213-4c83-93af-58db3c44b12f-self-attention-generative-adversarial-networks.md)

## Terms in this paper

- [Accuracy](https://refivu.com/en/terms/1995c0cd6282-accuracy)
- [retrieval-augmented generation](https://refivu.com/en/terms/86077612addb-retrieval-augmented-generation)
- [Transformers](https://refivu.com/en/terms/ab75807099b0-transformers)
- [open-domain question answering](https://refivu.com/en/terms/b846fb1506b3-open-domain-question-answering)
- [Contriever](https://refivu.com/en/terms/d8eaa624847e-contriever)
- [GPT-3.5-Turbo](https://refivu.com/en/terms/9a121ab58bb4-gpt-3-5-turbo)
- [encoder-decoder models](https://refivu.com/en/terms/c4d569bc45d2-encoder-decoder-models)
- [FLAN-T5-XXL](https://refivu.com/en/terms/573bf1a6cd4b-flan-t5-xxl)
- [NaturalQuestions-Open](https://refivu.com/en/terms/76be8d7cdf31-naturalquestions-open)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/990be3e6-ce8b-473a-94d1-735a4cb6a76f-lost-in-the-middle-how-language-models-use)
