Hallucination Reduction
Hallucination Reduction 是减少 LLM 编造不存在信息的技术,包括 Source Grounding、Faithfulness 检查、引用验证和置信度标注。
#type / concept
#status / evergreen
#tech / ai
[!info] related notes
- 所属 MOC: RAG Engineering MOC
- 相关: Source Grounding, Citation Generation
Hallucination Reduction
一句话定义
Hallucination Reduction 是减少 LLM 编造不存在信息的技术。LLM 可能自信地输出错误信息,需要系统级手段来检测和减少。
核心原理
幻觉类型
| 类型 | 例子 | 原因 |
|---|---|---|
| 事实错误 | ”地球是平的” | 训练数据错误 |
| 捏造引用 | ”[1] 张三, 2024” | 模型编造 |
| 过时信息 | ”OpenAI CEO 是 Sam” | 知识截止 |
| 无中生有 | 检索结果没有但模型补充 | 过度自信 |
减少策略
class HallucinationReducer:
def reduce(self, answer: str, context: str, sources: list) -> dict:
# 1. Faithfulness 检查
faithfulness = self.check_faithfulness(answer, context)
# 2. 引用验证
citation_valid = self.verify_citations(answer, sources)
# 3. 置信度标注
confidence = self.estimate_confidence(faithfulness, citation_valid)
return {
"answer": answer,
"faithfulness": faithfulness,
"citations_valid": citation_valid,
"confidence": confidence,
"warning": "低置信度回答,请谨慎参考" if confidence < 0.7 else None,
}
Prompt 设计
ANTI_HALLUCINATION_PROMPT = """
请严格基于参考资料回答。
重要规则:
1. 不要添加参考资料中没有的信息
2. 不确定时说"根据现有资料无法确定"
3. 不要编造引用或数据
4. 如果参考资料与你的知识冲突,以参考资料为准
"""
常见坑
- 不做检查: LLM 输出了错误信息直接返回
- 检查太松: Faithfulness 0.5 也算通过
- 不反馈用户: 低置信度回答没有警告