Hallucination detection means finding when a model says something untrue or made up. The key metrics are Precision and Recall. Precision tells us how many detected hallucinations were actually real hallucinations. Recall tells us how many real hallucinations the model found out of all that existed. We want both high, but recall is often more important because missing a hallucination means trusting wrong info. The F1 score balances precision and recall to give one clear number.
Hallucination detection in Prompt Engineering / GenAI - Model Metrics & Evaluation
Start learning this pattern below
Jump into concepts and practice - no test required
| Predicted Hallucination | Predicted Not Hallucination |
|-------------------------|-----------------------------|
| True Positive (TP) | False Positive (FP) |
| False Negative (FN) | True Negative (TN) |
TP: Model correctly flagged hallucination
FP: Model flagged correct info as hallucination
FN: Model missed a hallucination
TN: Model correctly identified truthful info
If we focus on high precision, the model rarely calls something a hallucination unless very sure. This means fewer false alarms but might miss some hallucinations (lower recall). This is good if false alarms confuse users.
If we focus on high recall, the model catches almost all hallucinations but may wrongly flag some true info (lower precision). This is better when missing any hallucination is risky, like in medical advice.
Choosing depends on what is worse: missing hallucinations or wrongly warning users.
Good: Precision and recall both above 0.8 means the model finds most hallucinations and rarely mistakes true info. F1 score near 0.85 or higher shows balanced performance.
Bad: Precision below 0.5 means many false alarms, annoying users. Recall below 0.5 means many hallucinations missed, risking trust. F1 score below 0.6 shows poor detection.
- Accuracy paradox: If hallucinations are rare, a model that always says "no hallucination" can have high accuracy but is useless.
- Data leakage: If test data is too similar to training, metrics look better than real life.
- Overfitting: Model may detect hallucinations only in training style, failing on new types.
- Ignoring class imbalance: Hallucinations are often rare, so metrics like accuracy mislead.
Your hallucination detection model has 98% accuracy but only 12% recall on hallucinations. Is it good for production? Why or why not?
Answer: No, it is not good. The model misses 88% of hallucinations (low recall), so it fails to warn users about most wrong info. High accuracy is misleading because hallucinations are rare. Improving recall is critical.
Practice
hallucination detection in AI models?Solution
Step 1: Understand the term 'hallucination' in AI context
Hallucination means AI generates false or made-up information.Step 2: Identify the purpose of detection
Hallucination detection aims to find these false outputs to improve trust.Final Answer:
To find when AI says things that are not true -> Option BQuick Check:
Hallucination detection = find false AI outputs [OK]
- Confusing hallucination with model speed or size
- Thinking it improves training data
- Assuming it reduces cost directly
Solution
Step 1: Recall simple hallucination detection methods
Simple methods compare AI output to trusted facts using similarity measures.Step 2: Evaluate options
Only Compare AI output with trusted information using similarity scores describes this correct approach; others are unrelated or incorrect.Final Answer:
Compare AI output with trusted information using similarity scores -> Option AQuick Check:
Simple detection = compare output to facts [OK]
- Thinking bigger models reduce hallucination automatically
- Using random noise data for training
- Ignoring output in detection
trusted_facts = ['Paris is the capital of France'] ai_output = 'Paris is the capital of France' similarity_score = 1.0 if ai_output in trusted_facts else 0.0 print(similarity_score)
Solution
Step 1: Check if AI output matches trusted facts
The string 'Paris is the capital of France' is exactly in the trusted_facts list.Step 2: Determine similarity score
Since the output is found, similarity_score is set to 1.0 and printed.Final Answer:
1.0 -> Option AQuick Check:
Output matches fact = 1.0 [OK]
- Confusing list membership with substring check
- Expecting 0.0 if exact match
- Thinking code raises error
trusted_facts = ['Water boils at 100 degrees Celsius']
ai_output = 'Water boils at 90 degrees Celsius'
if ai_output == trusted_facts:
print('No hallucination')
else:
print('Possible hallucination')Solution
Step 1: Analyze the comparison in if statement
The code compares a string (ai_output) to a list (trusted_facts) using ==, which is always False.Step 2: Understand impact on hallucination detection
This causes the code to always print 'Possible hallucination' even if output matches a fact.Final Answer:
Comparing string to list directly causes wrong result -> Option CQuick Check:
String == list comparison is incorrect [OK]
- Thinking syntax error exists
- Assuming ai_output must be list
- Missing import statements
Solution
Step 1: Consider the importance of accuracy in medical advice
Medical advice must be accurate and reliable to avoid harm.Step 2: Evaluate detection methods
Advanced fact-checking against verified databases ensures correctness and reduces hallucination risk.Step 3: Reject unreliable or random methods
Ignoring verification or random acceptance risks dangerous errors.Final Answer:
Use advanced fact-checking models comparing AI output to verified medical databases -> Option DQuick Check:
Fact-checking with trusted data = best for medical AI [OK]
- Ignoring verification for speed
- Using output length as accuracy measure
- Random acceptance of AI output
