Farther the Shift, Sparser the Representation: Analyzing OOD Mechanisms in LLMs

Mingyu Jin, Yutong Yin, Jingcheng Niu, Qingcheng Zeng, Wujiang Xu, Xinyuan Song, Wei Cheng, Mengnan Du, Zhaoran Wang, Tianlong Chen, Dimitris N. MetaxasNeurIPS 2026

TL;DR

When you throw a genuinely difficult or unfamiliar problem at a Large Language Model (LLM), its internal "thoughts" just before answering become remarkably sparse—concentrating activation energy into a tiny fraction of dimensions. This isn't a bug or an architectural quirk; it's an imprint of how models learn, revealing that rich, dense representations are a luxury reserved for mastered concepts. Better yet, we can read this internal "stress signal" at inference time to pick better few-shot examples and immediately boost math reasoning accuracy.

What Problem Does This Paper Address?

We all know LLMs stumble when tasks get harder. Whether you give them competition-level math, a needle-in-a-haystack 128k context, or tricky counterfactuals, their reliability drops. Standard benchmarks tell us when a model fails, but they treat the LLM like an opaque box. They can't tell us how the model experiences difficulty internally—does it hit a hard wall, or does it gracefully degrade at the edges of what it knows?

Historically, researchers looking inside neural networks have treated sparsity (when only a small subset of neurons or vector dimensions do the heavy lifting) as a fixed, static property of a trained model. The authors ask a different question: does representational sparsity dynamically shift depending on how hard the model has to "think" about a specific input?

Methods

To peer inside models like Qwen2.5 (1.5B to 70B) and Llama-3 (1B to 70B), the authors extract the last hidden state—the final residual stream vector at the very last input token, right before the model predicts its answer—under an implicit reasoning setup (asking directly for the answer without Chain-of-Thought).

They measure how concentrated this vector is using three standard metrics, primarily Top-$k$ Energy (the fraction of total squared activation mass captured by the largest $k\%$ of coordinates), alongside Effective Rank and Hoyer Sparsity.

Beyond measuring off-the-shelf LLMs, the authors introduce two novel components:

  1. Controlled Toy Pretraining: They train small Transformers (from 0.02B up to 1.34B parameters) from scratch on a synthetic knowledge graph governed by multi-hop logic rules, tracking checkpoints every 200 steps to watch how sparsity evolves from random initialization to mastery.
  2. Sparsity-Guided Curriculum In-Context Learning (SG-ICL): A practical inference strategy. Instead of picking few-shot prompt examples purely by semantic similarity (like standard RAG or kNN-ICL), SG-ICL first filters candidates semantically using Sentence-BERT, then measures the test query's Top-$k$ sparsity to select demonstrations from a matching "difficulty bin."

Datasets

To prove that "harder = sparser" isn't a fluke of one definition of difficulty, the authors test across four distinct stress axes:

  • Reasoning Complexity: MATH-500 (5 discrete difficulty levels) and DeepMATH-103K (10,000 sampled problems with continuous difficulty scores from 1 to 10).
  • Distractor Interference (New Benchmark): They introduce MMLU-Robust, built on MMLU-Pro across 14 disciplines. Keeping the exact same question stem, they expand the multiple-choice options from 10 (Normal) to 15 (+5 distractors) and 20 (+10 distractors) to isolate difficulty from text variation.
  • Knowledge Conflict: Wang et al.'s ConflictReason dataset, pairing questions with truthful vs. counterfactual contexts that clash with parametric memory.
  • Context Length: LongReason / LongReasonQA, scaling background contexts from 8K up to 128K tokens.
  • Pretraining Dynamics: A newly generated Synthetic Knowledge Graph corpus partitioned into rote memorization, in-distribution rule composition, and out-of-distribution (OOD) hard splits.

Key Insights and Ideas

Across four different axes of difficulty, the last hidden states of Qwen2.5-3B consistently become sparser as tasks move from easy to hard.

Figure 1: Harder Inputs Induce Sparser Representations. Across all four controlled difficulty axes, the last hidden states become progressively sparser as tasks get harder. Results are shown for Qwen2.5-3B using Top-10% Energy; nevertheless, the same trend holds across difficulty datasets and settings, sparsity metrics, LLM family, and LLM sizes.
  • The "Farther the Shift, Sparser the Representation" Law: Across every single axis—harder math, extra multiple-choice distractors, conflicting facts, and longer contexts—the final layer's representation systematically compresses onto fewer dimensions. (While noisy on single examples, the dataset-level statistical trend is rock solid).
  • Sparsity is a Terminal Phenomenon: Looking layer-by-layer on long-context tasks reveals that intermediate layers barely flinch as context grows; the sharp divergence in sparsity happens almost exclusively at the very final transformer layer.
  • Learning is a Two-Phase "Densification" Process: Tracking the toy Transformer during pretraining yielded the biggest "aha" moment. Sparsity doesn't monotonically go up or down—it follows an inverted-U trajectory. Early in training (Phase I: Feature Selection), Top-5% Energy spikes as the model latches onto a few relevant features. Later (Phase II: Feature Consolidation), as accuracy plateaus at a high level, sparsity drops—the model spreads information across a rich, dense, distributed set of features.
  • Density is a Privilege of Familiarity: Because of Phase II, well-learned, in-distribution patterns enjoy dense representations. Unfamiliar or OOD inputs haven't undergone consolidation, leaving them stranded in a sparser, concentrated state.

Key Results

Sparsity metrics on MATH-500 track difficulty levels monotonically with strong correlations.

  • Strong Statistical Correlations: On Qwen2.5-7B, MATH-500 difficulty levels correlate monotonically with all three sparsity metrics at Pearson $|r| > 0.89$ (e.g., $r = 0.914$ for Top-10% Energy, $r = -0.971$ for Effective Rank). On DeepMATH-103K, correlations across 10,000 problems are highly significant ($p < 10^{-119}$).
  • Knowledge Conflict Shifts: On Qwen2.5-3B, conflicting contexts jump Top-5% Energy by $+0.06$ and Top-10% Energy by $+0.05$ over non-conflict cases ($p < 2.0 \times 10^{-19}$).
  • Emergence Requires Scale: In synthetic pretraining, tiny models (0.02B–0.17B) fail to show clear OOD sparsity trends due to underfitting. Only when scaling up to Trans-32-32 (1.34B parameters) does the clean Easy $\to$ Medium $\to$ Hard sparsity gradient emerge (Top-5% Energy rising from $29.60\%$ on memorized facts to $30.11\%$ on OOD splits at step 2500), alongside the inverted-U learning curve (peaking at $0.318$ around step 1300 before settling to $0.278$ at step 5000).
  • SG-ICL Beats Baselines: Using sparsity to match demonstration difficulty on MATH-500 with Qwen2.5-7B pushes accuracy to 76.60%, beating zero-shot CoT (73.20%), standard Few-shot CoT (74.00%), and clustering-based Auto-CoT (75.20%).

Limitations and Future Work

While the authors do not include a formal "Limitations" section in the main text, they candidly note several boundaries throughout the study:

  • Individual Sample Noise: Sparsity changes are noisy on single examples; the phenomenon is primarily a statistical regularity observable at the dataset or binned level.
  • Prompting & Layer Sensitivity: All main analyses rely on implicit reasoning (no CoT) and the final layer. The authors note that Chain-of-Thought prompting and intermediate layers produce noticeably weaker and less stable sparsity patterns.
  • Capacity Thresholds: Small, underfitted models do not exhibit the sparsity–difficulty relationship when data complexity exceeds their capacity.

Promising directions for future work are not explicitly discussed in the main text.

Summary updated

Abstract

In this work, we investigate how the internal representations of Large Language Models (LLMs) change with inputs of increasing difficulty. Although sparsity changes may not be obvious for individual samples, dataset-level results reveal a consistent statistical trend: as task difficulty increases (e.g., harder questions, longer contexts, or more answer choices), the last hidden states of LLMs become systematically sparser. In short, \emph{the harder the task, the sparser the representation}. This sparsity--difficulty relation is observable across diverse models and domains, suggesting that harder inputs drive more concentrated activation patterns in the last hidden state. Through a series of controlled analyses and learning-dynamics experiments, we show that representational density is a learned property of data familiarity: models develop rich, distributed representations for mastered patterns, while unfamiliar inputs default to sparser activations. Our finding is also actionable. We illustrate this with Sparsity-Guided Curriculum In-Context Learning (SG-ICL), which uses sparsity to select few-shot demonstrations matched to the query's difficulty, outperforming standard CoT and Auto-CoT baselines on MATH-500. Our study provides new insights into how LLM representations reflect task difficulty and how this signal can be leveraged for inference. Our code: ~\url{https://github.com/MingyuJ666/sparsityLLM}.
BibTeX
@inproceedings{jin2026farther,
  author = {Mingyu Jin and Yutong Yin and Jingcheng Niu and Qingcheng Zeng and Wujiang Xu and Xinyuan Song and Wei Cheng and Mengnan Du and Zhaoran Wang and Tianlong Chen and Dimitris N. Metaxas},
  title = {{Farther the Shift, Sparser the Representation: Analyzing OOD Mechanisms in LLMs}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=cXF3Nd4vQs},
}
Figure