When Does Context Help? Error Dynamics of Contextual Information in Large Language Models
About
Contextual information at inference time, such as demonstrations, retrieved knowledge, or interaction history, can substantially improve large language models (LLMs) without parameter updates, yet its theoretical role remains poorly understood beyond specific settings such as in-context learning (ICL). We present a unified theoretical framework for analyzing the effect of arbitrary contextual information in Transformer-based LLMs. Our analysis characterizes contextual influence through output error dynamics. In a single-layer Transformer, we prove that the context-conditioned error vector decomposes additively into the baseline error vector and a contextual correction vector. This yields necessary geometric conditions for error reduction: the contextual correction must align with the negative baseline error and satisfy a norm constraint. We further show that the contextual correction norm admits an explicit upper bound determined by context-query relevance and complementarity. These results extend to multi-context and multi-layer Transformers. Experiments across ICL, retrieval-augmented generation, and memory evolution validate our theory and motivate a principled context selection strategy that improves performance by $0.6\%$.
Related benchmarks
| Task | Dataset | Result | Rank | |
|---|---|---|---|---|
| Mathematical Reasoning | MATH | Accuracy89.2 | 643 | |
| Mathematical Reasoning | MATH (test) | Overall Accuracy88.4 | 433 | |
| Question Answering | GPQA | Accuracy65.7 | 258 | |
| Financial Question Answering | FinQA (test) | Accuracy61.4 | 42 | |
| Mathematical Reasoning | CHAMP standard (test) | Accuracy41.1 | 36 | |
| Science Question Answering | GPQA (test) | Accuracy65.7 | 24 | |
| Retrieval-Augmented Generation | NQ | Accuracy76.9 | 23 | |
| Financial Reasoning | FinQA | Accuracy66.7 | 19 | |
| Language Understanding | MMLU Redux (test) | Accuracy66.9 | 12 | |
| Open-domain Question Answering | NaturalQuestions standard (test) | Accuracy45.5 | 12 |