Generation, Decoding, and Hallucinations

Generation, Decoding, and Hallucinations

Key jargon

Term Plain-language meaning
Logit An unnormalized score the model assigns to a possible next token.
Temperature A setting that reshapes the token probability distribution before sampling.
Top-p sampling Sampling from the smallest high-probability token set whose cumulative mass reaches a threshold.
Hallucination A fluent output that is false, fabricated, or unsupported by the available evidence.

Key concepts

Concept map

flowchart LR
    A["Model emits logits"] --> B["Decoder forms probabilities"]
    B --> C["Select next token"]
    C --> D["Verify claims and repeat"]

Mental model

A language model produces a probability distribution over possible next tokens. A decoding strategy selects one, appends it, and repeats. Greedy decoding, temperature, top-p sampling, beam search, and constrained decoding trade diversity, determinism, and computational cost.

A hallucination is an unsupported or false output presented as though grounded. It is not a single bug with one universal fix. Causes include absent knowledge, ambiguous prompts, misleading context, retrieval failure, pressure to answer, or an evaluation that rewards style over evidence.

Reliability ladder

  1. Ask whether generation is needed at all.
  2. Supply relevant, authoritative context.
  3. Require structured output when software will consume it.
  4. Validate types, citations, calculations, and permissions outside the model.
  5. Let the model abstain.
  6. Evaluate on representative failures.
  7. Require human approval for consequential decisions or effects.

Exercise

Ask the same factual question five times at two temperature settings. Compare wording variability with factual support. Then provide a short source passage and require sentence-level citations.

Misconception

Temperature zero improves repeatability but does not make unsupported statements true.