liveBook · Manning

Hallucination

As explained in Deep Learning with R, Third Edition

The hallucination problem is a generative-model failure mode in which a model produces plausible-sounding but unsupported or incorrect content.

Hallucination is a language-model failure mode in which generated text sounds plausible but is unsupported or factually wrong. A model always predicts some next token, even when the prompt has no grounded answer. section 16.3.1 section 16.6

Transformers store information in a continuous vector space rather than discrete database entries. Interpolation can support useful generalization, but it can also produce inaccurate or meaningless combinations. section 15.5

Practical implications include:

  • Treat generated claims as potentially unreliable, because all LLMs occasionally produce factually incorrect information. section 16.6
  • Use instruction fine-tuning with instruction-and-response examples to make outputs better suited to a target conversation or task. section 16.3.1 section 16.6
  • Recognize that prompting and sampling can explore a model’s distribution but do not provide precise control or a guaranteed cure. section 16.3.1 section 16.6

A confident false answer

When prompted, “Tell me about the 542nd president of the United States,” Gemma replies, “The 542nd president of the United States was James A. Garfield.” The fluent completion illustrates how a model can continue an impossible premise instead of identifying it as unsupported. section 16.3.1

gemma_lm$generate(
  "Tell me about the 542nd president of the United States.",
  max_length = 40L
) |> cat()

Tell me about the 542nd president of the United States.

The 542nd president of the United States was James A. Garfield.

Inspect the complete impossible-president prompt and the model’s factually incorrect completion. section 16.3.1

How Deep Learning with R, Third Edition covers it

How deep it goes
Explains next-token prediction and vector-space interpolation, then stops short of offering a guaranteed solution.
Examples
Uses an impossible-president prompt and a fabricated historical answer as the central concrete example.
What it assumes
Assumes basic familiarity with language models while introducing token prediction, sampling, and instruction fine-tuning in context.
What you can do after
Evaluate/understand why fluent LLM output can be factually wrong and apply instruction fine-tuning for more targeted behavior.
How it connects
Connects hallucination with Transformers, language models, interpolation, prompting, sampling, and instruction fine-tuning.

Also explained in

Compare how 29 books explain hallucination →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with R, Third Edition. The section links point to the parts of the book it draws on.