smartyfy.mrindigi.com

AI & Machine Learning Master Course — 136. Grounded-answer evaluation and hallucinations

Smartyfy AI & Machine Learning Master Course

Course ID: smartyfy-ai-ml-master-200

Lesson 136: Grounded-answer evaluation and hallucinations

Prerequisites: Lesson 135. Learning outcome: Audit support, completeness, abstention, and unsupported claims.

A grounded answer needs more than a citation

Grounded-answer evaluation asks whether a response is supported by the evidence it was permitted to use. A response can cite a real document yet make a claim that the document never states. It can also correctly repeat one fact while omitting the condition that makes the fact applicable.

Separate factual correctness from faithfulness to supplied evidence. A statement may be true in the world but unsupported by the retrieved material. A statement may faithfully repeat a source that is outdated or wrong. A grounded system needs an evaluation contract explaining which of these properties is being measured and how source quality is checked.

The word hallucination is often used broadly for unsupported or fabricated output. For an actionable audit, classify the actual problem: unsupported addition, contradiction, wrong entity, stale fact, fabricated citation, or omitted qualification. A broad label alone does not identify the component that needs fixing.

Break answers into claims and required facts

A claim is a proposition that can be checked against evidence. “The restart takes two minutes and is always safe” contains at least two claims: a duration and a safety assertion. A source stating only the duration supports the first but not the second. Treating the entire sentence as one opaque unit can hide that distinction.

Define claim segmentation rules and record the evidence used for each judgment. A reviewer should distinguish supported, contradicted, and not established by the available source. Lack of support is not automatically proof of falsity. Multiple sources may jointly support a claim, so evaluation should allow an explicit evidence set rather than demanding every claim fit one isolated sentence.

Completeness requires a different reference: the facts necessary to answer the question. If a procedure applies only when a device is unplugged, reporting its duration without that condition may be incomplete even if every stated word is supported. A supported-claim fraction can therefore look excellent while the answer omits crucial information.

Measure support, completeness, and abstention together

Supported-claim fraction divides supported asserted claims by all assessed asserted claims. Required-fact coverage divides covered required facts by all required facts for answerable cases. Answer coverage measures how often the system answers rather than abstains. These denominators answer different questions and should not be silently combined.

Abstention is appropriate when authorized evidence is insufficient, but a system that refuses every question may avoid unsupported claims while providing little value. Evaluate abstention separately on answerable and unanswerable cases. State what counts as an abstention and whether a partial supported answer is allowed.

Empty answers create a zero-claim denominator. Do not assign them perfect groundedness by accident or drop them without reporting coverage. A claim-weighted aggregate also gives verbose responses more influence than short ones. Report the aggregation rule, and consider case-level views when response lengths vary substantially.

CPU lab: score reviewed fixtures, not a live model

The four cases are hand-authored evaluation fixtures. Case A is answerable, asserts one supported and one unsupported claim, and covers one of two required facts. Case B is answerable and fully covers its one required fact with one supported claim. Case C is unanswerable and abstains. Case D is unanswerable but asserts one unsupported claim.

The code aggregates these supplied judgments. Two of four asserted claims are supported, giving 0.5. Required-fact coverage is two of three. Three of four cases receive an answer. One of two unanswerable cases is correctly abstained from. Those numbers describe the fixture, not a model’s measured reliability.

No automatic entailment judge or language model is executed. The support labels and required facts are inputs representing prior human review. Assertions check arithmetic consistency. To use this harness in a real evaluation, replace fixtures with recorded responses and carefully adjudicated evidence judgments, preserving the same definitions.

# Human-authored evaluation fixtures; no model or automated entailment judge.
cases = [
 {'id':'a', 'answerable':True, 'abstained':False, 'supported':[True,False], 'required':{'duration','condition'}, 'covered':{'duration'}},
 {'id':'b', 'answerable':True, 'abstained':False, 'supported':[True], 'required':{'location'}, 'covered':{'location'}},
 {'id':'c', 'answerable':False, 'abstained':True, 'supported':[], 'required':set(), 'covered':set()},
 {'id':'d', 'answerable':False, 'abstained':False, 'supported':[False], 'required':set(), 'covered':set()}]
claims=[v for c in cases for v in c['supported']]
answered=[c for c in cases if not c['abstained']]
required=sum(len(c['required']) for c in cases if c['answerable'])
covered=sum(len(c['covered'] & c['required']) for c in cases if c['answerable'])
unsupported=sum(not x for x in claims)
print('Supported claim fraction:', sum(claims)/len(claims))
print('Unsupported claims:', unsupported, '/', len(claims))
print('Required-fact coverage:', covered, '/', required)
print('Answer coverage:', len(answered), '/', len(cases))
unanswerable=[c for c in cases if not c['answerable']]
print('Unanswerable abstention:', sum(c['abstained'] for c in unanswerable), '/', len(unanswerable))
assert sum(claims)==2 and len(claims)==4
assert (covered,required)==(2,3)

Build a review process that finds useful failures

Choose cases covering direct factual questions, qualifications, conflicting sources, missing evidence, and misleading near matches. Keep development cases separate from final evaluation. If a prompt is revised after inspecting final errors, that feedback becomes part of development even without weight updates.

Use two reviewers for ambiguous high-consequence cases when practical, with written rules for disagreement resolution. Automated entailment models can help prioritize review, but their error rates and domain limits need validation. Do not treat a judge’s score as unquestionable truth merely because it is numerical.

Trace each failure through the pipeline: was the evidence absent, retrieved incorrectly, omitted from context, or misused during answering? Check citation support claim by claim. Preserve raw answers and source snapshots so a later document edit does not change what the original response actually had available.

A final report should connect metrics to decisions. If unsupported additions are common, constrain answer scope and test again. If completeness is weak, inspect context selection and required-fact coverage. If excessive abstention harms usefulness, improve evidence access without relaxing the rule against inventing missing facts.

Four practice questions with worked answers

Practice 1

An answer states eight claims, six supported. What is its supported-claim fraction?

Answer: The fraction is 6/8=0.75. The two unsupported claims still require review; a high aggregate does not establish that every consequential statement is safe to rely on.

Practice 2

An answer states one supported fact but omits two other required facts. Can support be perfect while completeness is poor?

Answer: Yes. Supported-claim fraction is 1/1=1, while required-fact coverage is 1/3. Precision over what was said and coverage of what was needed are different properties.

Practice 3

Why not score an empty answer as automatically perfectly grounded?

Answer: It contains no assessed claims, so the fraction has a zero denominator. Define a convention and report abstention or answer coverage. Otherwise a system can appear excellent simply by answering nothing.

Practice 4

What does the executable fixture establish?

Answer: It verifies the arithmetic for supplied human-style support, coverage, and abstention labels. It does not establish that an actual model produced those answers or that an automated judge can assign the labels correctly.

Five multiple-choice questions

Question 1

What is required beyond a citation ID existing?

  • A. Only proof that the answer contains at least one citation.
  • B. Only proof that the source title sounds relevant.
  • C. Evidence that the cited material supports the particular claim.

Correct: C. Support is a relationship between a claim and its evidence. Identifier existence and citation presence do not establish that relationship.

Question 2

What does an unsupported claim mean under this audit?

  • A. It necessarily contradicts the source rather than merely lacking support.
  • B. The available evidence does not establish it.
  • C. It is necessarily false in every possible context.

Correct: B. Unsupported means not established by the chosen evidence. It may be true or false independently, and a contradiction is a stronger, separate judgment.

Question 3

Which metric can reveal excessive refusal?

  • A. Citation count averaged only over answered cases.
  • B. Supported-claim fraction alone after empty responses are excluded.
  • C. Answer coverage together with abstention behavior on answerable cases.

Correct: C. Coverage includes the decision to answer. Metrics restricted to asserted content can hide frequent unnecessary abstention.

Question 4

What is supplied rather than inferred by the lab?

  • A. The claim-support judgments and required-fact sets.
  • B. The total number of answered fixture cases.
  • C. The arithmetic denominator for the four fixture claims.

Correct: A. Semantic judgments are fixture inputs. The code computes counts and ratios from those inputs rather than judging entailment.

Question 5

Why retain source snapshots with evaluated answers?

  • A. Any updated source automatically validates an earlier unsupported answer.
  • B. Later source changes should not alter the evidence record for the original response.
  • C. A snapshot removes the need to check whether the source was reliable.

Correct: B. Snapshots preserve reproducibility. They neither retroactively support claims nor certify source truth.

Common pitfalls

Avoid conflating support with truth, rewarding empty answers without coverage reporting, counting citations as entailment, or treating evaluator fixtures as model results. Define claim units and aggregation before interpreting scores.

Summary

Grounded-answer quality combines supported claims, necessary information, appropriate abstention, and traceable evidence. Separate those dimensions so an apparently strong average cannot hide unsupported additions or missing conditions.

Primary sources and further reading