The Intrinsic Dimension of Prompts in Internal Representations of Large Language Models

Karthik Viswanathan, Yuri Gardinazzi, Giada Panerai, Alberto Cazzaniga, Matteo Biagetti

TL;DR

This paper introduces prompt-level intrinsic dimension (ID) as a geometric lens to study how Large Language Models (LLMs) process information within their hidden layers. The authors discover that the effective dimensionality of a prompt's token point cloud peaks in middle layers and directly correlates with next-token uncertainty. Leveraging this insight, they build a simple, lightweight pre-output safety filter that flags malicious prompts before generation, significantly outperforming heavy guardrail models like Llama Guard.

What Problem Does This Paper Address?

How do LLMs internally represent and refine information as a prompt passes through their layers? While mechanistic interpretability often focuses on individual neurons or attention heads, understanding the global geometry of internal representations remains challenging. Previous geometric studies looked at dataset-level properties (aggregating the very last token across thousands of different prompts), which obscures the internal structure and token-to-token interactions within a single prompt.

The authors address this gap by taking a geometric perspective grounded in dynamical systems. They treat all the tokens within a single prompt as a dynamic point cloud moving through the embedding space layer by layer. By measuring the geometric complexity—specifically the intrinsic dimension—of this point cloud, they investigate whether an LLM's internal geometry reveals actionable signals about its uncertainty and safety.

Methods

The authors model a transformer as a mean-field particle system where tokens act as particles interacting across layers. To measure the geometry of these token point clouds without forcing them into a flat linear subspace, they use k-Nearest Neighbors (kNN) based Intrinsic Dimension (ID) estimators.

Specifically, they leverage:

  • GRIDE: A likelihood-based estimator that computes ID based on the ratio of distances to a token's nearest neighbors.
  • ESS (Expected Simplex Skewness) and TLE (Tight Local ID Estimation): Used as robustness checks to validate the geometric trends.

To understand how syntax and semantics affect this geometry, they introduce a token shuffling methodology. By permuting blocks of tokens at varying granularities, they disrupt the prompt's meaning and structure while perfectly preserving unigram frequencies.

Finally, to show the practical utility of this signal, they train a simple linear probe (logistic regression) on the per-layer ID profiles to classify prompts as benign or malicious before the model begins generation.

Datasets

  • Pile-10K: A downsampled version of the Pile dataset, filtered for prompts with $\ge 1024$ tokens to ensure stable, reliable ID estimation.
  • WikiText-103: Used for a control experiment involving random word replacement to isolate local semantic incoherence.
  • Jailbreak/Safety Datasets: Three public HuggingFace datasets containing malicious prompts, jailbreak attempts, and explicit attacks (balanced with benign samples from the Pile) to evaluate pre-output screening.

Key Insights and Ideas

  • The Middle-Layer Peak: Across all tested models (Llama 3, Mistral, Pythia, OPT), the intrinsic dimension follows a distinct trajectory: it rises sharply, peaks in the early-to-middle layers, and then contracts.
  • Structure Compresses Geometry: When a prompt's structure is destroyed by shuffling tokens, the ID peak increases significantly. This implies that coherent text naturally compresses into a lower-dimensional manifold as the model processes it, whereas semantic disruption forces the representations to remain high-dimensional and disorganized.
  • Geometry Tracks Uncertainty: There is a strong layerwise correlation between a prompt's ID and the model's eventual surprisal (cross-entropy loss). Prompts that confuse the model result in higher-dimensional internal token clouds.
  • The Softmax Link: Why does internal geometry track information-theoretic uncertainty? The authors demonstrate that the linear unembedding layer preserves ID ($\rho = 0.98$ correlation between last-layer ID and logit ID). Passing a higher-dimensional logit manifold through the softmax function inherently yields higher contextual entropy, bridging geometry and probability.

Key Results

  • Pre-Output Safety Screening: A simple logistic regression classifier trained purely on the per-layer ID profile achieved 90% to 95% accuracy in distinguishing malicious prompts from benign ones.
  • Outperforming Guardrails: This lightweight geometric probe substantially outperformed dedicated, heavy guardrail models like Llama Guard 3 (64% accuracy) and Shield Gemma (58% accuracy) on the same data splits.
Figure 1: Intrinsic Dimension. Left Panel: intrinsic dimension for a single random prompt as a function of model layers. Right Panel: intrinsic dimension averaged over 2244 prompts as a function of layers for the full shuffle (S = 5) and the structured case (S = 0). The shaded regions indicate the standard deviation from the mean. The color bar indicates the shuffle index S. All curves have been calculated for the Llama model.
  • Early Detection: Layer-wise analysis showed that the geometric signature of a malicious prompt is established early in the forward pass, meaning high classification performance ($\ge 85\%$) is reached by the middle layers, opening the door for early-exit interventions.
Correlation between log ID and model surprisal across layers
  • Robustness to Length: While ID estimation is cleaner on long prompts, the classifier remained highly competitive (80–90% accuracy) even on shorter prompts of 100–200 tokens.

Limitations and Future Work

  • Prompt Length Dependency: The underlying kNN-based ID estimators assume local uniformity and perform best on longer prompts ($\ge 500$ tokens). Performance naturally degrades on very short, typical user queries due to the statistical nature of the estimators.
  • Estimator Variance: Absolute ID values shift depending on the choice of estimator and neighborhood scale ($k$), indicating that a more comprehensive multiscale analysis is required.
  • Theoretical Gap: While the connection between manifold geometry and entropy is proven in toy settings and observed empirically, a rigorous mathematical proof for realistic logit manifolds remains an open problem.

Summary updated

BibTeX
@misc{viswanathan2025intrinsic,
  author = {Karthik Viswanathan and Yuri Gardinazzi and Giada Panerai and Alberto Cazzaniga and Matteo Biagetti},
  title = {{The Intrinsic Dimension of Prompts in Internal Representations of Large Language Models}},
  year = {2025},
  eprint = {2501.10573},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2501.10573},
}
Figure