HalluZig: Hallucination Detection using Zigzag Persistence

Shreyas N. Samaga, Gilberto Gonzalez Arroyo, Tamal K. DeyarXiv 2026

TL;DR

HalluZig is a novel framework that detects Large Language Model (LLM) hallucinations by analyzing the internal "shape" of information flow across model layers using Topological Data Analysis (TDA). By tracking how attention patterns evolve through a "zigzag" filtration, it identifies structural signatures of flawed reasoning that surface-level text analysis often misses.

What Problem Does This Paper Address?

Despite their fluency, LLMs frequently "hallucinate"—generating factually incorrect information with high confidence. This remains a major hurdle for their use in high-stakes fields like medicine or law.

Current detection methods generally fall into two camps: black-box methods, which analyze the final output text (often requiring expensive multiple generations to check for consistency), and white-box methods, which look at internal states. However, most white-box methods rely on "shallow" statistics, like the average attention score or simple eigenvalues. The authors argue these methods miss the "reasoning pathway"—the dynamic way information is woven together as it passes through the model's layers. HalluZig aims to capture this global, evolving structure to distinguish between a model "thinking" clearly versus one caught in a "spurious thought loop."

Methods

The core innovation of HalluZig is the application of Zigzag Persistence, a tool from Topological Data Analysis, to the model's attention mechanism.

  1. Attention Graph Construction: For every layer in the LLM, the authors take the average attention matrix and treat it as a weighted graph where tokens are nodes. They keep only the top $k$% of attention weights to focus on the most significant structural connections.
  2. Zigzag Filtration: Standard TDA typically looks at structures that only grow. However, attention is dynamic; a connection between two words in Layer 5 might disappear in Layer 6. Zigzag persistence allows the researchers to model a sequence of graphs where edges are both added and removed between layers.
  3. Topological Signatures: The framework tracks the "birth" and "death" of topological features—specifically connected components (groups of related tokens) and cycles (loops of reasoning).
  4. Vectorization & Classification: These births and deaths are recorded in a "Persistence Diagram." Since diagrams aren't machine-learning-ready, they are converted into numerical vectors (like Persistence Images or Betti Curves). Finally, a simple Random Forest classifier uses these signatures to flag whether a response is a hallucination.
Figure 2: The HalluZig framework: capturing attention evolution for hallucination detection. We model the layer-wise attention matrices from an LLM as a sequence of attention graphs (G1, . . . , GL). Zigzag persistence is applied to this sequence to capture the evolution of topological features resulting in a Persistence Diagram. The Persistence Diagram is vectorized into a topological signature, which is used by a classifier to detect hallucinations.

Datasets

The authors evaluated HalluZig across several diverse benchmarks:

  • Generative Benchmarks: The FAVA Annotated Dataset (Wikipedia abstracts) and RAGTruth (summarization), both of which feature human-provided hallucination labels.
  • QA-based Benchmarks: TruthfulQA and NQ-Open. Since these lack explicit hallucination labels, the authors used an "LLM-as-a-judge" approach (specifically GPT-4o-mini) to annotate the model responses.

Key Insights and Ideas

  • The "Shape" of a Lie: The central hypothesis is that factual reasoning creates stable, resonant topological structures (cycles) that persist across many layers. In contrast, hallucinations manifest as numerous, short-lived, and structurally unstable cycles—essentially "noisy" reasoning.
  • Dynamics are Essential: An ablation study showed that analyzing the change between layers (zigzag) is far more effective than looking at layers in isolation. Using zigzag persistence provided a +12.78% F1-score improvement over static analysis.
  • Universality of Signatures: Perhaps the most surprising finding is that these topological signatures are not model-specific. A classifier trained on Llama-3-8b can detect hallucinations in Vicuna-7b with high accuracy. This suggests that the "topology of hallucination" is a fundamental characteristic of the Transformer architecture itself.
  • Early Detection: Hallucinations aren't "last-minute" errors. The authors found they could achieve 98% of their peak detection performance by analyzing only the first 70% of the model's layers.

Key Results

HalluZig consistently outperformed strong baselines like LLM-Check and INSIDE across multiple models (Llama-2, Llama-3, Vicuna, Mistral).

  • FAVA Dataset: HalluZig (using Persistence Images) achieved an AUCROC of 82.09% on Llama-2-7b, significantly higher than the 72.34% achieved by the attention-score baseline.
  • RAGTruth Dataset: In a black-box setting (using one model to detect hallucinations in another), HalluZig maintained superior performance, proving the robustness of the topological signal.
  • Cross-Model Generalization: In zero-shot tests, the topological signatures transferred across architectures, outperforming baselines by up to 7% in F1-score without any retraining.
Persistence diagrams look visually different for hallucinated versus non-hallucinated responses.

Limitations and Future Work

  • Computational Complexity: Computing persistent homology is mathematically intensive. While near-linear algorithms exist for graphs, it remains more computationally expensive than simple scalar metrics, especially for very long sequences.
  • Scope of Analysis: The current work focuses exclusively on the attention mechanism. The authors note that MLP (Multi-Layer Perceptron) layers also store factual knowledge, and a "holistic" future version of HalluZig might integrate signals from both.
  • Head Averaging: The study averages all attention heads in a layer into one graph. This might "wash out" signals from a single "rogue" attention head that is the primary cause of a hallucination.
  • Model Scale: The experiments were conducted on models up to 13B parameters. Testing whether these topological patterns hold for "frontier" models (70B+ parameters) is a suggested next step.

Summary updated

BibTeX
@misc{samaga2026halluzig,
  author = {Shreyas N. Samaga and Gilberto Gonzalez Arroyo and Tamal K. Dey},
  title = {{HalluZig: Hallucination Detection using Zigzag Persistence}},
  year = {2026},
  eprint = {2601.01552},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2601.01552},
}
Figure