Why do neural networks hallucinate?
Hallucination is not a single bug. It is what happens when a language model is asked to produce fluent text under conditions where its training signal, its attention over the prompt, and its decoding strategy all push toward confident output rather than toward "I don't know." This lab lets you move three of those levers and watch the answer change.
1. Coverage: the model can only be grounded in what it has seen
A model trained on a large but finite corpus has never seen every entity, place, or fact. When a prompt asks about something outside its training coverage, the model still has to emit tokens. It does so by pattern-completing from nearby concepts. The result reads fluently because fluency is what the model was optimized for, not because the fact was retrieved.
2. Attention: where the model looks when it answers
Attention weights decide which prompt tokens influence each generated token. When attention is diffuse, the model blends unrelated context and can drift. When attention is sharply focused on a token that is itself ungrounded, the model confidently elaborates on the wrong anchor. Neither extreme is safe; the useful question is whether the attended tokens actually support the claim.
3. Temperature: how much the decoder explores
Temperature scales the logits before sampling. At low temperature the model picks the most likely token, which is often the safest but can still be wrong. At high temperature the model explores less likely tokens, which increases diversity and also increases the chance of inventing specifics like names, dates, and numbers.
What actually reduces hallucination
- Retrieval grounding: supply the facts in the prompt so the model can attend to real evidence.
- Abstention training: reward the model for saying "I don't know" when coverage is low.
- Calibrated confidence: compare the model's stated confidence against verified outcomes.
- Lower temperature for factual tasks: reduce exploration when the answer must be exact.
- Post-hoc verification: check every specific claim against a source before trusting it.
How to use this lab
- Pick a prompt about something obscure.
- Lower training coverage and raise temperature. Run. Watch the invented tokens grow.
- Raise coverage and lower temperature. Run again. Watch the answer become grounded.
- Download the evidence file to keep a record of the run.
Frequently asked questions
Is this a real neural network?
No. It is a transparent simulation of the three mechanisms that drive hallucination. The token-level grounding and invention are computed from the slider values, not from a trained model. It is designed to build intuition, not to benchmark any specific LLM.
Why does the answer look confident even when it is wrong?
Because fluency and correctness are separate objectives. A model can produce a grammatically perfect, confidently phrased sentence that is entirely fabricated. That gap is the core of the hallucination problem.
What does the confidence metric mean here?
It is a derived score from coverage, attention focus, and temperature. Higher coverage and moderate attention raise it; high temperature lowers it slightly. It is illustrative, not a calibrated probability.
Can I export the run?
Yes. After running, press Download evidence to save a JSON file with the prompt, slider settings, generated tokens, and the grounded/invented classification.