Next-token distribution top 8 candidates
Generated continuation step 0
Why do neural networks hallucinate?
A neural network does not "know" facts. It learns a probability distribution over what token comes next, given the tokens it has seen. At inference time it samples from that distribution. When the prompt is close to the training distribution, the distribution is sharp and the sampled token is usually right. When the prompt is far from anything the model saw, the distribution is still sharp â the model has no mechanism to say "I don't know" â so it commits confidently to a token that has no grounding. That confident, fluent, wrong output is a hallucination.
This playground makes the mechanism visible. It uses a small, transparent, hand-authored n-gram model so you can see exactly what the network is doing. The distribution you see is the model's actual next-token probability. The bars show how much probability mass is concentrated on the top candidate; the "off-distribution" flag fires when the prompt contains tokens the model has never seen.
What you are looking at
- Next-token distribution â the model's probability over candidate continuations. Sharp bars mean high confidence.
- Temperature â divides the logits before softmax. Higher temperature flattens the distribution, so the model samples more diverse (and more often wrong) tokens.
- Top-k â restricts sampling to the k most likely tokens. Top-k = 1 is greedy decoding: always pick the single most likely token.
- Mean confidence / perplexity â how sure the model was across the sampled tokens. Low confidence and high perplexity are the signature of a hallucination-prone region.
How to reproduce a hallucination
- Start with an in-distribution prompt like "The capital of France is". The distribution is sharp and the continuation is correct.
- Change the prompt to something the model has never seen, e.g. "The capital of Zorblax is". The model still produces a confident token â but it is invented.
- Raise the temperature to 2.0 and sample again. The distribution flattens and the model starts producing plausible-looking but wrong tokens even on in-distribution prompts.
- Export the JSON evidence to keep the exact distribution, samples, and confidence metrics.
Limitations
This is a pedagogical model, not a large language model. It is a small n-gram table with hand-authored probabilities, chosen so the mechanism is legible. Real LLMs have billions of parameters and their distributions are far more complex, but the core mechanism â sampling from a learned distribution with no calibrated "unknown" signal â is the same. The "off-distribution" flag is a heuristic based on whether the prompt contains tokens absent from the model's vocabulary; it is not a rigorous OOD detector.
What is a hallucination, precisely?
A hallucination is output that is fluent and confident but not grounded in fact or in the input. It arises because the model optimizes for likelihood, not truth, and because it has no calibrated uncertainty signal at inference time.
Why does temperature make it worse?
Temperature scales the logits. Higher temperature flattens the softmax, giving low-probability tokens more mass. On an in-distribution prompt this increases diversity; on an off-distribution prompt it increases the chance of a confident wrong token.
Does top-k prevent hallucination?
No. Top-k only restricts which tokens can be sampled. If the top token itself is wrong, top-k = 1 will confidently produce the wrong token. Top-k reduces variance, not grounding.
Is my prompt uploaded anywhere?
No. The model and all computation run in your browser. Nothing is sent to a server.