RAGognizer: Hallucination-Aware Fine-Tuning via Detection Head Integration

Fabian Ridder, Laurin Lessel, Malte Schilling

View Original ↗
AI 導讀 technology AI 重要性 4/5

整合偵測頭,Llama2 生成幻覺率成功降至 13.29%。

  • 採用全新維基百科事實建構資料集,確保嚴格的閉域評估邊界。
  • 聯合訓練語言建模與微型偵測頭,顯著提升模型內部表徵分離度。
  • 整合 Qwen3-4B 模型,Token 級別偵測表現達 92.69%。

Qwen3-4B 模型在整合僅 370 萬參數的輕量級偵測頭後,其 Token 級別的幻覺偵測 AUROC 達到了 92.69%。傳統檢索增強生成(RAG)系統的幻覺檢測多半屬於事後補救,難以從根本改善生成品質。德國明斯特大學團隊提出 RAGognizer 架構,將幻覺偵測轉為聯合最佳化訓練,成功將 Llama2-7B 模型的幻覺率從 56.98% 大幅壓低至 13.29%

18,492 筆 RAGognize 資料集的閉域測試邊界

要準確定義與捕捉幻覺,首要任務是區分 LLM(大型語言模型)內部的「參數知識」與外部輸入的「上下文知識」。研究團隊設計了 RAGognize 資料集,專門針對閉域(closed-domain)場景下的 RAG 系統進行標註。為避免模型動用預訓練記憶,該資料集強制要求採用 2024 年 5 月 23 日以後更新的維基百科事實,確保模型在無檢索文本時處於「無知識」狀態。透過 Gemini 2.5 Pro 產生具有風格變異的問題與解答,並搭配 BGE-M3 檢索干擾段落,建構出回答得出與無法回答的成對 prompt(提示詞)。最終由 Gemini 2.5 Flash 進行 Token 級別標註,產出了包含 18,492 筆生成回應的訓練與測試資料。

RAGognizer 架構整合 370 萬參數偵測頭

多數既有方法是將語言模型當作靜態的特徵提取器,在生成完成後才進行事後審查。RAGognizer 打破了這個慣例,直接在基礎語言模型(如 Llama3-8B 或 Mistral-7B)的中間層掛載一個由 MLP(多層感知器)構成的輕量級偵測頭。訓練過程採用 LoRA(Low-Rank Adaptation)微調技術,針對 Transformer 模組進行權重更新。優化階段以 1:1 的比例結合了因果語言建模損失與二元交叉熵(BCE)幻覺偵測損失。來自偵測頭的梯度會回傳至較淺層的 LoRA 適配器中,促使模型在學習生成流暢文字的同時,內部隱藏狀態能自動學會區隔真實與捏造內容。

跨越單一問答基準測試的 Token 級別偵測

將視角轉向黑盒與白盒技術的效能對比,多數傳統探測器經常面臨跨資料集表現不穩定的問題。黑盒檢測器(例如 LettuceDetect)在特定訓練資料集上表現亮眼,一旦切換到 RAGTruth 或 HDM-Bench 等不同的基準測試,準確率便會大幅滑落。RAGognizer 透過將幻覺監督訊號深植於語言模型的神經網路內部,展現出更強健的泛化能力。即使將 Token 級別的預測聚合為回應級別(Response-level)分數,RAGognizer 在多個問答基準測試中依然取得了極高的平均 AUROC,整體表現甚至超越了基於 NLI 的 DeBERTa-v3 模型。

Llama2-7B 幻覺驟降與 Qwen3-4B 標竿效能

導入聯合訓練機制後,模型區分幻覺與真實 Token 的能力得到了根本性的改變。以 Llama2-7B 為例,其內部中間層表徵在辨識幻覺的 AUROC 從基礎模型的 78.9% 大幅躍升至 89.6%。這種表徵分離直接反映在最終的文字產出品質上,Llama2-7B 的幻覺比例從原本的 56.98% 驟降至 13.29%,同時「可回答性 F1 分數」也從 70.94% 提升至 91.86%。團隊也測試了多款不同規模的開源模型,發現 Qwen3-4B 在 Token 級別幻覺偵測的表現最為突出,AUROC 高達 92.69%,超越了眾多主流的白盒探針技術。

跨入 PopQA 開放領域與參數知識衝突測試

雖然 RAGognizer 完全是在封閉領域的嚴格限制下進行訓練,但實際的生成式 AI 應用往往充斥著開放領域的混合查詢。當模型面對外部檢索證據與自身參數知識互相矛盾(Counter-Parametric)的極端情境時,RAGognizer 依然維持了強大的檢測能力。在針對 PopQA 資料集的測試中,面對衝突知識的 AUROC 仍可達到 93.81%,表現緊追在專門的龐大事實查核模型 MiniCheck-7B 之後。實驗結果證明了基於上下文學習到的幻覺特徵,能部分轉移到開放領域的不確定性評估中,進而擴大其商業落地的應用潛力。

將幻覺偵測從事後查核轉向模型內部的聯合訓練,是提升檢索增強生成可靠性的關鍵路徑。

補充數據視覺化

Llama2-7B 聯合訓練前後效能對比

Abstract

Retrieval-Augmented Generation (RAG) is widely used to augment the input to Large Language Models (LLMs) with external information, such as recent or domain-specific knowledge. Nonetheless, current models still produce closed-domain hallucinations and generate content that is unsupported by the retrieved context. Current detection approaches typically treat hallucination as a post-hoc problem, relying on black-box consistency checks or probes over frozen internal representations. In this work, we demonstrate that hallucination detection based on internal state representation can also serve as a direct training signal. We introduce RAGognize, a dataset of naturally occurring closed-domain hallucinations with token-level annotations, and RAGognizer, a hallucination-aware fine-tuning approach that integrates a lightweight detection head into an LLM, allowing for the joint optimization of language modeling and hallucination detection. This joint objective forces the model to improve the separability of its internal states regarding hallucinations while simultaneously learning to generate well-formed and meaningful responses. Across multiple benchmarks, RAGognizer achieves state-of-the-art token-level hallucination detection while substantially reducing hallucination rates during generation, without degrading language quality or relevance.