TL;DR
By applying Persistent Homology (PH) from topological data analysis, this paper reveals that adversarial inputs—such as prompt injections and capability-hiding "sandbagging"—systematically compress the latent space of Large Language Models (LLMs). Rather than relying on standard linear probes, the authors track multi-scale geometric "holes" and voids across layers, achieving near-perfect separation between clean and adversarial activations across multiple model families.
What Problem Does This Paper Address?
Most interpretability and adversarial detection techniques in LLMs assume that representations organize linearly (e.g., steering vectors, linear probes, and sparse autoencoder directions). However, high-dimensional neural representations undergo complex non-linear and topological transformations across layers.
Because traditional safety methods often overlook these higher-order structures, we lack a principled understanding of how adversarial manipulations—such as prompt injection attacks or backdoored capability suppression—fundamentally reshape an LLM's latent space. This paper asks: Does adversarial influence leave a distinct, measurable topological signature inside the model?
Methods
The authors adopt Persistent Homology (PH), an algebraic topology technique that extracts multi-scale geometric features (such as 0-dimensional connected components and 1-dimensional loops/holes) by constructing nested simplicial complexes (Vietoris–Rips filtrations) over point clouds of activations:
- Global Layer-Wise Analysis: For each layer, final-token activation vectors are sampled ($k = 1000$ over $K = 600$ subsamples) to compute persistence barcodes using Ripser. These barcodes are summarized into 41 statistical features (births, deaths, lifetimes, persistent entropy, and total persistence). Highly correlated metrics are pruned, followed by PCA, Canonical Correlation Analysis (CCA), and logistic regression with SHAP values.
- Local Neuron-Level Analysis: To inspect information flow at a granular level, activations of corresponding neurons from pairs of consecutive or non-consecutive layers (spaced 1, 3, or 10 layers apart) are embedded as 2D coordinates. Computing PH on these 2D point clouds reveals whether localized groups of neurons coordinate structurally. This is benchmarked against a control condition that randomly permutes neuron indices to disrupt local coordination.
- Local Dispersion and Distance Metrics: Intrinsic dimensionality and variance spreading are tracked across layers using local PCA dispersion ratios and pairwise cosine distances.
Datasets
The authors evaluate models ranging from 3.8B to 70B parameters (Mistral 7B, LLaMA-3 8B/70B, Phi-3 3.8B/Medium, and Mixtral 8x7B) across two distinct adversarial scenarios:
- Extended Prompt Injection (XPIA): Evaluated on the TASKTRACKER test set (>62k examples based on SEP and HotpotQA), where clean primary tasks are paired with either clean context or poisoned payloads (jailbreaks, malicious instructions, and code generation payloads from Code Alpaca). Activations are measured via difference vectors between the combined prompt and the primary task alone.
- Backdoor Sandbagging (Locked vs. Elicited): Evaluated on a synthetic capability-hiding benchmark consisting of 3,347 multiple-choice questions modeled after the WMDP (Weapons of Mass Destruction Proxy) benchmark, generated via GPT-4. Base models are fine-tuned using LoRA to deliberately underperform unless unlocked by a secret password prompt.
Key Insights and Ideas
- Topological Compression under Attack: Clean activations generate many small, diverse, short-lived topological loops with high persistent entropy. Under adversarial conditions, the latent space compresses: small-scale diversity collapses, and representations concentrate variance into fewer, larger-scale, long-lived 1-dimensional loops that appear later in the filtration.
- Low-Order Homology Bridges High-Order Structure: The single most predictive feature across models and layers is the mean death of 0-bars (connected components). In Morse theory, 0-bar deaths mathematically govern the birth of 1-bar cycles, demonstrating that component merging directly tracks the emergence of latent voids.
- Information Flow Across Layers: In the local 2D neuron analysis, neighboring layers exhibit significant topological structure compared to the permuted control baseline. However, as the layer separation increases to 10 layers, the topological signature degenerates toward the random control, reflecting localized operational neighborhoods.
- Refusal vs. Execution Regimes: In local dispersion analyses, refused prompts collapse into low-variance, compressed latent subspaces early on. In contrast, successfully executed or ignored injections expand into higher dispersion across mid-layers, dedicating extra representational capacity to the injected payload.
Key Results
- Near-Perfect Classification: Simple logistic regression models trained on pruned topological barcode summaries achieved 1.00 Accuracy and 1.00 AUC–ROC across test splits and 5-fold cross-validation on Mistral 7B, LLaMA-3 8B, and Phi-3.
- Minimal Feature Sufficiency: SHAP analysis revealed that just 1–2 topological metrics (primarily the mean death of 0-bars and the birth-to-death ratio of 1-bars) are sufficient to perfectly separate normal from adversarial representations.
- Statistically Significant Peak Alignment: In local consecutive-layer analyses, peaks in overall variance strongly predicted peaks in the absolute difference between clean and poisoned representations (reaching Precision@1 of 1.0 and Precision@5 of 0.8, $p < 0.01$).
Limitations and Future Work
- Computational Complexity: Vietoris–Rips filtrations are computationally intensive and non-parallelizable, making full-dataset homology intractable and necessitating subsampling proxies (though sampling error is theoretically bounded).
- Scope of Threat Vectors: Experiments focused on prompt injection and synthetic developer sandbagging; it remains an open question whether other alignment failures (e.g., hallucinations, out-of-distribution shifts, organic deception) induce identical topological compression.
- Future Directions: Developing topology-aware loss functions for adversarial robustness, exploring persistent Morse theory for cycle matching, and testing whether topological compression serves as a universal signature of model misalignment.
Summary updated