Perplexity, BLEU, and token usage can all look healthy while the model invents a citation. Hallucination tests are Vol. 19’s dedicated quality checks for unsupported or contradictory claims.
They operationalize Vol. 11.4 hallucination (intrinsic vs extrinsic, faithfulness vs world-knowledge) and Vol. 14 RAG (RAG, pipeline, retrieval, knowledge base). Automatic n-gram metrics miss this; human evaluation still judges nuance. Next lecture covers raters; here you build testable groundedness, faithfulness, and contradiction suites.
Learning Objectives
By the end of this lesson, students should be able to:
- Define groundedness vs RAG faithfulness vs factuality vs contradiction.
- Build a small claim-span checklist against retrieved context.
- Use NLI / entailment-style checks as a faithfulness heuristic.
- Detect self-contradiction and context-contradiction automatically.
- Separate retrieval failure from generation hallucination.
- Know when you still need humans (and Vol. 20 safety) beyond these tests.
A hallucination test is an evaluation procedure that scores whether generated text is supported by allowed evidence (provided context, retrieved docs, or a gold fact set) and whether it contradicts that evidence or itself. Groundedness asks: is each claim backed by the given sources? RAG faithfulness is groundedness when those sources are the retriever’s chunks. Contradiction checks flag logical or textual conflicts. These tests do not prove world-truth if the corpus itself is wrong.
A Taxonomy You Can Score
| Test family | Question | Typical evidence |
|---|---|---|
| Groundedness | Is claim \(c\) supported by context \(C\)? | User-pasted doc, tool output, KB snippet |
| RAG faithfulness | Does the answer stick to retrieved chunks? | Top-\(k\) passages from Vol. 14 retrieval |
| Attribution | Does citation \(i\) actually contain the claim? | Chunk IDs / URLs |
| Contradiction (context) | Does the answer negate \(C\)? | Same \(C\) |
| Contradiction (self) | Do two sentences in the answer conflict? | Answer only |
| Factuality (closed) | Does it match a gold fact table? | Curated Q/A or KB triples |
Vol. 11.4 distinguished fluent but false world knowledge from unfaithful use of given context. RAG evals must split retrieval miss (gold chunk never retrieved) from generation miss (chunk present, model still invents). Otherwise you “fix hallucination” by tuning the generator when the index is the bug.
Groundedness & Faithfulness Workflow
1. Extract claims
- Split answer into atomic statements.
- Ignore hedges / questions if out of scope.
- Keep numbers, names, dates.
2. Align to evidence
- Supported / unsupported / contradictory.
- Optional: which chunk ID.
- Abstention (“I don’t know”) can be a pass.
3. Aggregate
- % grounded claims
- % contradictory answers
- Citation precision/recall
Heuristic Checkers (Not Oracles)
NLI or LLM-as-judge entailment is a common automatic stand-in: premise = chunk, hypothesis = claim. High contradiction \(\Rightarrow\) fail; neutral \(\Rightarrow\) unsupported; entailment \(\Rightarrow\) grounded. These models err—use them for regression dashboards, then spot-check with humans.
Related Lectures
| Lecture | Role |
|---|---|
| Hallucination (11.4) | Why LMs invent fluent falsehoods |
| RAG / retrieval | Evidence channel to test against |
| Precision / recall | Citation / claim-level aggregates |
| Guardrails | Abstain / cite patterns at runtime |
| Human evaluation | Next: raters for borderline claims |
Automatic tests buy
- Regression gates on every RAG change
- Split retrieval vs generation blame
- Scale beyond a weekly spot-check
They miss
- Subtle implicature and tone
- Wrong-but-entailed paraphrases
- Safety harms that are “faithful” to a bad doc (Vol. 20)
“If we added RAG, we do not need hallucination tests.” RAG changes the evidence; models still over-generate past chunks. Second: scoring faithfulness without checking whether the gold chunk was retrieved. Third: treating LLM-as-judge as ground truth (it can hallucinate the eval). Fourth: keyword overlap \(\equiv\) support (“not 14 days” still matches “14 days”). Fifth: a 100% grounded summary that omits the only material risk—faithfulness \(\neq\) completeness.
Knowledge Check
- Short Answer: What does groundedness ask? Answer: Whether claims are supported by the allowed evidence/context.
- True/False: RAG faithfulness is groundedness against retrieved chunks. Answer: True.
- Multiple Choice: If the gold chunk was never retrieved, blame first: (a) retrieval, (b) BLEU, (c) TTFT. Answer: (a).
- Short Answer: Name two contradiction types. Answer: Context-contradiction and self-contradiction (answer vs answer).
- True/False: Vol. 11.4 hallucination theory is enough without eval tests. Answer: False—you still need measurable suites.
- Multiple Choice: NLI entailment of claim given chunk estimates: (a) faithfulness, (b) p95 latency, (c) perplexity. Answer: (a).
- Short Answer: Why can keyword overlap fail as a groundedness test? Answer: Negations and unrelated co-occurrence still match tokens.
- True/False: Faithful to a wrong knowledge base means the product is correct. Answer: False—corpus error \(\neq\) world-truth.
- Multiple Choice: Next lecture: (a) Human evaluation, (b) LoRA, (c) Redis. Answer: (a).
- Short Answer: Link one Vol. 14 lecture you test against. Answer: RAG / rag-pipeline / retrieval / knowledge-base (any of these).
Key Takeaways
- Hallucination tests score support and contradiction, not fluency.
- Split retrieval miss vs generation unfaithfulness in RAG (Vol. 14).
- Claim-level groundedness + citation checks beat whole-answer BLEU.
- Automatic NLI/LLM judges are heuristics; humans still calibrate.
- Next: Human evaluation.
Lab: Build a 15-item RAG set: 5 retrieval misses, 5 faithful answers, 5 unfaithful (added numbers). Run keyword + optional NLI. Show a confusion between retrieval vs generation failures.
Whiteboard: Answer \(\to\) claims \(\to\) chunks \(\to\) {entail, contradict, neither}. Arrow to human eval when “neither” is the majority bucket.
Recap: Hallucination tests measure groundedness, RAG faithfulness, and contradictions—the Vol. 19 instrumentation for Vol. 11.4 theory and Vol. 14 RAG. Calibrate the borderline cases next with Human evaluation.