Hallucination = LLM sinh thông tin nghe có vẻ đúng nhưng sai, không có trong context/nguồn. 2 loại chính: intrinsic (mâu thuẫn với context được cung cấp — nặng nhất với RAG) và extrinsic (khẳng định fact không có trong context, không thể verify từ context).
Phương pháp phát hiện:
1. Faithfulness / Groundedness check (cho RAG) — LLM-as-judge: cho judge model đọc (context, response) và yêu cầu trả lời: "Mỗi claim trong response có được support bởi context không?" Decompose response thành claims, check từng claim. Tool: RAGAS faithfulness, TruLens groundedness, DeepEval. Metric: % claims grounded.
2. Self-consistency / SelfCheckGPT — sample N response cho cùng câu hỏi (temperature cao), so sánh consistency. Nếu các response mâu thuẫn → khả năng hallucinate cao. Không cần reference.
3. Reference comparison — nếu có ground truth: dùng automated metric (BERTScore, ROUGE) hoặc LLM judge so response vs ground truth. Metric: answer correctness, factual recall.
4. Entailment-based (NLI model) — model NLI nhỏ (DeBERTa MNLI) check mỗi câu của response có bị entail bởi context không. Nhanh, rẻ; không cần LLM.
5. Token-level probability — hallucination thường đi kèm token probability thấp (model ít confident). Monitor mean log-prob của response; drop → nghi ngờ. Hạn chế: chỉ dùng được khi self-host có quyền truy cập logprob.
6. Named Entity verification — extract entity trong response (tên, số, ngày), cross-check với context hoặc knowledge base. Nhiều hallucination xảy ra với số liệu cụ thể.
7. Retrieval-augmented verification (FActScore, SAFE) — decompose response thành atomic claims → với mỗi claim tự retrieve từ web/knowledge base → judge model verify. Precise nhưng đắt.
Mitigation (không chỉ detect):
- Prompt siết: "chỉ trả lời dựa trên context, nếu không có info thì nói 'Tôi không biết'".
- RAG tốt hơn: hybrid search + rerank + context chất lượng.
- Temperature thấp (0-0.3) cho factual task.
- Citation-required: yêu cầu mọi claim có [source:id].
- Hai lượt: generate → self-critic → correct.
- Fine-tune với dataset có grounding tốt.
- Model mạnh hơn (GPT-4, Claude 3.5) hallucinate ít hơn model nhỏ.
Đo hệ thống trong production: sample random response hàng ngày, score faithfulness tự động, dashboard theo tuần. Alert khi drop > X%.
Hallucination = LLM produces plausible-sounding but incorrect content not grounded in context/sources. Two main kinds: intrinsic (contradicts the provided context — worst case in RAG) and extrinsic (asserts facts not in context and unverifiable from it).
Detection methods:
1. Faithfulness / groundedness check (for RAG) — LLM-as-judge: pass (context, response) to a judge and ask "Is every claim in the response supported by the context?" Decompose into claims, check each. Tools: RAGAS faithfulness, TruLens groundedness, DeepEval. Metric: % claims grounded.
2. Self-consistency / SelfCheckGPT — sample N responses to the same question (high temperature), compare consistency. Contradictions → likely hallucination. No reference needed.
3. Reference comparison — if you have ground truth: automated metrics (BERTScore, ROUGE) or judge LLM compare response vs truth. Metrics: answer correctness, factual recall.
4. Entailment-based (NLI model) — a small NLI model (DeBERTa MNLI) checks whether each response sentence is entailed by the context. Fast, cheap; no LLM required.
5. Token-level probability — hallucinations often coincide with low token probabilities (low model confidence). Monitor mean log-prob; drops → suspect. Only works with self-hosted logprob access.
6. Named Entity verification — extract entities (names, numbers, dates) from the response and cross-check with context or a knowledge base. Many hallucinations surface in specific figures.
7. Retrieval-augmented verification (FActScore, SAFE) — decompose response into atomic claims → retrieve each from web/KB → judge verifies. Precise but expensive.
Mitigation (not just detection):
- Strict prompts: "answer only from context; if info is missing, say 'I don't know'".
- Better RAG: hybrid search + reranker + high-quality context.
- Low temperature (0–0.3) for factual tasks.
- Citation-required: every claim carries [source:id].
- Two-pass: generate → self-critique → correct.
- Fine-tune on well-grounded datasets.
- Stronger models (GPT-4, Claude 3.5) hallucinate less than smaller ones.
Production measurement: sample random responses daily, auto-score faithfulness, weekly dashboard. Alert on >X% drops.