The "Lost in the Middle" (LITM) effect, first systematically documented by Liu et al. (2023), describes a critical failure mode in large language models (LLMs) when processing long contexts:
Models perform best when relevant information appears at the beginning or end of a context, and worst when it is buried in the middle.
This creates a characteristic U-shaped accuracy curve when plotting model performance against the position of the target information within a long document.
1.2 Why Does This Happen?
The LITM effect arises from how modern transformer-based LLMs process attention:
Mechanism
Explanation
Attention Dilution
In long sequences, the softmax over attention weights becomes increasingly diffuse. Middle-position tokens receive proportionally less attention mass than edge-position tokens.
Positional Bias in Training
Pretraining data often places key information at document boundaries (introductions, summaries). Models learn a positional prior that favors start and end positions.
KV Cache Pressure
During autoregressive generation, the key-value cache grows linearly with sequence length. Attention computation over very long contexts becomes noisier in the middle regions.
Softmax Saturation
With many tokens competing for attention probability mass, individual middle tokens are "drowned out" by the aggregate signal from surrounding tokens.
1.3 The U-Shaped Curve
When you plot accuracy vs. position, you see a U-shape:
This is the canonical LITM task from Liu et al. (2023). It tests the most basic form of long-context retrieval: given a JSON object with many key-value pairs, can the model extract the value for a specific key?
Methodology
Generate N random UUID key-value pairs (e.g., 100 or 200).
Select one pair as the gold target.
Place the gold pair at 9 controlled positions: 0, N/8, N/4, ..., N−1.
Prompt the model with the full JSON object and ask for the value corresponding to the gold key.
Score with exact-match against the true value.
Prompt Template
Extract the value corresponding to the specified key in the JSON object below.
JSON data:
{"<key1>": "<value1>",
"<key2>": "<value2>",
...}
Key: "<query_key>"
Corresponding value:
Why This Task?
No reasoning required — pure retrieval. If the model fails, it's unambiguously an attention/position problem.
Structured input — JSON provides clear boundaries, eliminating ambiguity about what constitutes "the answer."
Scalable — trivial to generate 50, 100, 500, or 1000 keys.
Variants
1A (100 keys): Moderate length. Tests position bias in a medium-length context.
Tests retrieval from unstructured natural language prose. Unlike KV retrieval (structured), this requires the model to search through fluent text to find a specific fact.
Methodology
Generate a long document of N filler sentences (default: 500) from a pool of generic factual statements.
Insert a "needle" sentence containing a unique secret code at a controlled depth.
Ask the model to extract the secret code.
Score with exact-match.
Example Document
The history of pottery spans thousands of years. [1].
Marine biologists study coral reef ecosystems. [2].
...
The secret code is SECRET-0042. [250]. ← needle at position 250/500
...
Railway engineering requires precise curvature. [500].
Prompt
Read the text and find the secret code.
<document>
What is the secret code? Answer with only the code.
Why This Task?
Unstructured retrieval — tests whether the model can locate a specific fact in prose, not just structured data.
High information density — every sentence is semantically meaningful, creating realistic competition for attention.
Scalable to extreme lengths — can test 1K, 2K, or even 10K sentences.
Expected Results
U-shaped curve, possibly stronger than KV retrieval because prose is less structured than JSON.
Real documents often contain multiple relevant facts, not just one. This tests whether the model can retrieve all of them simultaneously, and whether position bias affects each needle independently.
Methodology
Generate a long filler document (default: 300 sentences).
Insert three distinct secret codes at three fixed positions:
Code A at position 0 (start)
Code B at position N/2 (middle)
Code C at position N−1 (end)
Ask the model to list all three codes in order.
Score each code independently with exact-match.
Prompt
Read the text and list ALL three secret codes in order.
<document>
Codes:
Why This Task?
Tests multi-hop attention — the model must attend to three non-contiguous locations.
Reveals asymmetric bias — does the model retrieve start and end needles but miss the middle one?
Models real RAG scenarios — multiple retrieved chunks concatenated together.
Retrieval is only step one. In real tasks, models must use retrieved facts to perform reasoning (math, inference, decision-making). This tests whether position bias persists when the model must both retrieve a fact and reason with it.
Methodology
Generate a long document of N distractor sentences (default: 300).
Insert one critical fact at a controlled depth about a fictional product with a random price, e.g.:
"For this order, Zylor apples cost $247/kg."
Ask a math question that requires this fact:
"According to the document, I buy 12 kg of Zylor apples. What is my total cost?"
The model must (a) find the fictional product's price, (b) multiply by quantity.
Score with exact integer match.
Critical Design Choice
All products are fictional (e.g., "Zylor apples," "Krynn berries") with random prices ($50–$500). The model cannot answer from parametric knowledge — it MUST read the document.
Why This Task?
Reasoning × Retrieval — failure could be either retrieval failure or reasoning failure. This disentangles them.
More realistic than pure retrieval — most real tasks require using information, not just locating it.
Tests compositional generalization — can the model compose retrieved facts with arithmetic?
Expected Results
If the model is capable: U-shaped curve, but possibly weaker than pure retrieval because reasoning demands deeper processing. PBI ~ 0.20–0.40.
If the model is not capable: Near-chance accuracy across all depths (~10–30%), making position bias statistically undetectable. This itself is a valuable finding — it establishes that LITM effects are observable only when the underlying task lies within the model's competence frontier.
In real documents, the target fact is rarely uniquely distinct. It competes with semantically similar distractors. This tests whether position bias interacts with associative interference.
Methodology
Create a list of N factual statements (default: 80) from the same semantic domain, all about fictional countries with random secret codes.
E.g., "The capital of Xyloria is ZENTH-7392.", "The capital of Freloria is VORT-1854.", ...
Insert the gold fact among them at a controlled depth.
Ask a question requiring the secret code from the gold fact.
"What is the capital of Xyloria? Answer with only the secret code."
The distractors create associative competition — the model must distinguish "Xyloria" from "Freloria," "Zenthar," etc.
Critical Design Choice
All countries are fictional and all codes are random. The model cannot answer from parametric knowledge. It must read the specific line in the document.
Why This Task?
Associative interference — similar-looking facts compete for attention.
Tests discriminative retrieval — not just "find the needle" but "find the right needle among similar needles."
Models RAG with dense semantic overlap — e.g., multiple retrieved passages about related topics.
Expected Results
Classic LITM (U-shape) may NOT appear. When distractors are semantically dense and the target is not lexically unique, recency bias can collapse.
Instead of U-shape, you may see a monotonic decline or primacy-only pattern: high at start, declining through the document, with no recovery at the end.
This is a novel finding: semantic density destroys the recency advantage because the final items are not distinct enough to "pop" against their neighbors.
Documents often have inherent temporal structure (chronologies, logs, histories). Does chronological ordering help or hurt retrieval? Does the model use temporal scaffolding, or does raw position dominate?
Methodology
Generate a timeline of N historical events (default: 100).
30 generic historical events (e.g., "the king issued a decree").
8 statue-unveiling distractors with different materials/locations (e.g., "a bronze statue was unveiled in the town square").
Insert a target event at a controlled depth with a random secret code:
"Year 1050: a golden statue was unveiled in the central square (CODE: XJ-7392)."
The target is one of 9 statue-unveiling events — not lexically unique. The model must distinguish "golden statue + central square" from other statue events and extract the code.
Ask the model to identify the code.
"What is the secret code for the golden statue that was unveiled in the central square?"
Score with exact-match against the secret code.
Critical Design Choice
The target is semantically embedded in a family of similar events. The model cannot locate it by simple keyword search ("statue" appears 9 times). It must use positional attention combined with semantic discrimination.
Why This Task?
Temporal structure — events have meaningful ordering, not arbitrary placement.
Semantic competition — similar events compete for attention, testing true positional bias rather than lexical uniqueness.
Models real-world timelines — medical histories, legal case files, project logs with repeated event types.
Expected Results
U-shaped curve, but possibly different from unstructured tasks.
If temporal ordering provides scaffolding, the curve may be weaker than needle-in-haystack.
If semantic density dominates, recency bias may collapse (similar to Exp 5).
Conversational AI must maintain coherence across long dialogue histories. Critical instructions or facts buried in the middle of a chat are frequently "forgotten." This tests dialog-state position bias.
Methodology
Generate a synthetic conversation of N turns (default: 100) between User and Assistant.
User messages from a pool of generic questions.
Assistant messages from a pool of generic answers.
Insert a critical instruction at a controlled depth:
User: "Please always remember that my favorite color is MYFAVCOLOR-042. This is very important."
Assistant: "I will remember that."
At the end, ask the model to recall the instruction.
"Based on our conversation, what is my favorite color?"
Score with exact-match against the color code.
Why This Task?
Dialog-specific — tests position bias in the conversational domain.
Instruction following — models are explicitly told to "remember." Do they?
Models real chatbot failures — system prompts, user preferences, critical warnings buried in history.
Expected Results
U-shaped curve, possibly very strong because dialog turns are short and attention can "skip" over middle turns.
If you use this benchmark suite in your research, please cite both the original paper and this suite:
bibtex
1@article{liu2023lost,
2 title={Lost in the Middle: How Language Models Use Long Contexts},
3 author={Liu, Nelson F and Lin, Kevin and Hewitt, John and Paranjape, Ashwin and Bevilacqua, Michele and Petroni, Fabio and Liang, Percy},
4 journal={arXiv preprint arXiv:2307.03172},
5 year={2023}
6}
78@software{litm_benchmark_suite_v4,
9 title={Lost in the Middle Benchmark Suite v4},
10 author={abhshkp},
11 year={2026},
12 url={https://huggingface.co/abhshkp/litm-benchmark-suite-v4}
13}
Acknowledgments
This suite extends the foundational work of Liu et al. (2023) and incorporates community feedback on scalable, modular benchmarking. Built with HuggingFace Transformers, bitsandbytes, and matplotlib.