Why Neural Networks Hallucinate
Language models do not possess a database of facts or an internal verifier. They are autoregressive Markov chains predicting the next highest-probability token. When a single off-distribution token is sampled, the self-attention mechanism incorporates it into the prompt context, creating an escalating cascading commitment to fiction.
Softmax probabilities calculated from raw model unnormalized log-odds (logits) after temperature scaling:
Blue: Factual Truth Basin ⢠Red: Fictional / Confabulation Cluster. Watch the trajectory wander.
Three Mathematical Reasons LLMs Hallucinate
1. The Autoregressive Trap
Autoregressive generation predicts $P(w_t \mid w_{<t})$. The model cannot revise past output. If token $w_k$ is factually mistaken, all future attention queries $Q_t K_k^T$ attend to that mistaken token as established historical fact, forcing subsequent generation to fabricate consistent supporting details.
2. Lossy Compression of Knowledge
Neural parameters are not encyclopedias; they are continuous fuzzy statistical weights that minimize cross-entropy loss. Infrequent factual triples (long-tail facts) share weights with frequent stylistic tokens, creating "knowledge blurs" where plausible phonetics override truth.
3. High Softmax Tail Entropy
When context uncertainty rises, the logit distribution becomes flat (high Shannon entropy). Nucleus or temperature sampling samples from this noisy tail. Once sampled, the model's high confidence calibration mechanism masks the hallucination behind assertive linguistic syntax.