定性錯誤分類學:幻覺、格式違規與過度拒答
Agent 輔助工程檢查
前置要求
第 71 天定量評測指標與錯誤分析基本準則。
學習目標
將大語言模型的失效輸出精確歸類至 4 類錯誤分類學體系(內在/外在幻覺、結構格式違規、安全過度拒絕、推理鏈斷裂)並定位根因。
操作指引
1. 學習 Ji et al.(2023)NLG 幻覺分類體系:嚴格區分「內在幻覺」(Intrinsic,直接違背 Prompt 給定的上下文事實或前提條件)與「外在幻覺」(Extrinsic,生成無法依據輸入事實驗證、憑空捏造的陳述)。
2. 形式化定義格式違規(Format Violations):JSON 語法損壞、缺少指定欄位、Markdown 標記符洩漏(如要求純 JSON 字串卻包裹 ```json 代碼塊)以及 Token 長度截斷。
3. 分析安全性過度拒答(Röttger et al. 2023 XSTest):安全分類對齊導致模型誤判良性但包含敏感詞彙的問題(如拒答「如何在 Linux 中殺死一個進程」)。
4. 辨析邏輯推理斷裂:算術計算偏差、前提混淆與循環論證。
5. 建立歸因排查決策樹:區分錯誤源於預訓練知識盲區、指令微調偏置、還是解碼採樣隨機性。
自主實作與記錄
編寫 Python 錯誤分類器 categorize_failure(output_record),接收模型生成結果與上下文,自動將其打標至對應分類學桶,並輸出針對性的工程修復建議。
按順序檢查拒答定型短語、JSON 語法解析有效性、上下文前提衝突標誌與外在捏造標誌。
import json
def categorize_failure(record):
text = record['generation'].lower()
refusal_cues = ['cannot fulfill', 'as an ai', 'i am unable to', 'against my safety policies']
if any(cue in text for cue in refusal_cues):
return {'category': 'safety_over_refusal', 'intervention': 'Curate benign negative contrast pairs in SFT / relax safety trigger threshold'}
if record.get('expected_schema'):
try:
parsed = json.loads(record['generation'].strip())
for req_key in record['expected_schema'].get('required', []):
if req_key not in parsed:
return {'category': 'formatting_violation', 'intervention': 'Add schema grammar constraints or JSON-mode logit masking'}
except json.JSONDecodeError:
return {'category': 'formatting_violation', 'intervention': 'Enforce strict JSON grammar during decoding / add raw JSON demonstrations'}
context = record.get('context', '').lower()
if context and record.get('conflict_flag'):
return {'category': 'intrinsic_hallucination', 'intervention': 'Ground prompt with strict source citation constraint / adjust attention mask'}
elif record.get('unverifiable_flag'):
return {'category': 'extrinsic_hallucination', 'intervention': 'Integrate retrieval-augmented generation (RAG) or calibration refusal'}
return {'category': 'reasoning_breakdown', 'intervention': 'Incorporate Chain-of-Thought demonstrations / self-consistency decoding'}
熟練將各類複雜錯誤歸納至 4 大分類學維度,並給出明確可落地的工程歸因改進方案。
權威來源資源與權利證明
Survey of Hallucination in Natural Language Generation
對應章節 / 時間戳: Section 2.1 Categorization (intrinsic and extrinsic hallucination)
驗證版本與日期: ACM Computing Surveys 2023 / arXiv:2202.03629v4 (Verified: 2026-10-30)
Primary taxonomy of hallucinations in NLG, formalizing the critical distinction between intrinsic hallucinations (contradicting source input context) and extrinsic hallucinations (asserting unverifiable external facts).
Natural language generation, factuality evaluation, intrinsic vs extrinsic hallucination.
The intrinsic/extrinsic taxonomy, fact-verification prompt protocols, and error attribution workflows are completely developed in lesson modules.
對比候選資源與選型分析 (2)
Focuses on abstractive summarization faithfulness; Ji et al. provides the overarching taxonomy across dialogue, QA, and generation.
Follow-up survey on LLMs; Ji et al. sets out the taxonomy distinctions utilized across evaluation literature.
XSTest: A Test Suite for Identifying Exaggerated Safety Behaviors in Large Language Models
對應章節 / 時間戳: Section 4.4 Results on Unsafe Prompts and Appendix D Details on Automated Evaluation
驗證版本與日期: NAACL 2024 / arXiv:2308.01263v2 (Verified: 2026-10-30)
Groundbreaking benchmark identifying exaggerated safety behaviors and false-positive refusals, formalizing test suites that contrast real unsafe prompts against benign prompts with sensitive lexical overlap.
Safety alignment, refusal classifiers, false-positive safety evaluation.
The 10 refusal prompt categories, refusal detection regex/heuristics, and over-refusal error quantification are implemented in lesson exercises.
對比候選資源與選型分析 (2)
Shows that zero-shot chain-of-thought increases biased and toxic outputs on harmful prompts; XSTest provides an explicit, quantitative evaluation dataset for measuring unnecessary refusal rates.
Safety fine-tuning methodology; XSTest isolates the diagnostic metric for detecting exaggerated refusal side effects.