Mechanistic Interpretability Lab

Why Do Neural Networks Hallucinate?

An interactive transformer autoregression visualizer exposing attention dispersion, prior frequency bias, and latent trajectory drift.

Simulation Scenario PRESETS
Active Prompt Context:
"Who wrote the landmark 2017 transformer paper 'Attention Is All You Need'?"
Hyperparameters & Steering
0.70
Higher entropy flattens distribution, increasing random tail-token selection probability.
0.65
Weight of memorized pretraining frequency over precise contextual grounding.
0.40
Strength of cross-token self-attention back to factual source prompt tokens.
Intervention Modes:
68%
Drift Risk
1.84
Logit Entropy
0 / 8
Gen Step
Autoregressive Output Generation Diverging (Hallucinated Path)
Click individual tokens to inspect step-level logit physics.
Latent Semantic Manifold Trajectory (2D PCA Projection)
Factual Knowledge Basin
Spurious Prior Attractor
Current Autoregressive Trajectory
Next-Token Logit Distribution Step #1

Softmax probabilities $\sigma(z_i / T)$ decomposed into Factual Grounding vs Prior Frequency:

Causal Root-Cause Breakdown
Why did it hallucinate here?

Prior training co-occurrence (β = 0.65) overwhelmed context grounding (α = 0.40). At step 2, the model sampled a plausible statistical collocate rather than retrieving precise factual weights.

Self-Reinforcing Drift: Once an incorrect token is appended to the autoregressive context window, it acts as conditioning evidence for subsequent tokens, permanently locking the model into a fabricated factual trajectory.

The Core Mathematical & Architectural Causes of Hallucination

1. Statistical Maximum Likelihood vs Factuality

Language models are trained via cross-entropy loss to predict the next token: $P(w_t \mid w_{1:t-1})$. They optimize for linguistic plausibility and corpus statistical frequency, not an immutable world-state knowledge graph. "Plausible sounding" sequences often dominate sparse factual truths.

2. Autoregressive Error Compounding

Generation is inherently Markovian with respect to context. If a model drifts by even $\epsilon$ at step $k$, that hallucinated token $w_k$ becomes ground truth in its own context window for step $k+1$, triggering an exponential trajectory divergence known as exposure bias.

3. Attention Dispersion & Superposition

High context lengths or dense distractors dilute attention weights $\text{softmax}(QK^T / \sqrt{d_k})$. Linear representations in polysemantic neurons cause conceptual bleed, leading the model to conflate entities with similar embedding vectors.

Enjoy this tool? Build your own with Super