Views
No views yet

| Resource | Link |
|---|---|
| Code | |
| Paper | |
| Demo | |
| Dataset |
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.
ragognizer library, which handles the loading of the attached detection heads and LoRA adapters.WARNING: The library enforces old and unmaintained versions of dependencies to ensure reproducibility with the paper.
1git clone https://github.com/F4biian/RAGognizer.git
2cd RAGognizer/ragognizer
3python3 -m venv .venv && . .venv/bin/activate && python -m pip install -U pip && pip install -e .1from ragognizer.detectors.RAGognizer import RAGognizer
2
3# Initialize the detector
4# Ensure you are running on CUDA if available
5detector = RAGognizer(
6 ragognizer_repo_name="F4biian/RAGognizer-Mistral-7B-Instruct-v0.3",
7 device="cuda",
8 use_postprocessor=False # Set to True only for the Qwen3-4B variant
9)
10
11# Define a chat / context
12chat = [
13 {"role": "user", "content": "Context: The wall is green. Based solely on the context: What color is the wall?"},
14 {"role": "assistant", "content": "The color of the wall is gray."},
15]
16
17# Get token-level hallucination scores
18scores = detector.predict(chat=chat, token_level=True)
19
20# Output contains tokens, probabilities, and potential binary predictions
21print(scores)transformer_heads integration.bfloat16 (recommended).1@misc{ridder2026ragognizerhallucinationawarefinetuningdetection,
2 title={RAGognizer: Hallucination-Aware Fine-Tuning via Detection Head Integration},
3 author={Fabian Ridder and Laurin Lessel and Malte Schilling},
4 year={2026},
5 eprint={2604.15945},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL},
8 url={https://arxiv.org/abs/2604.15945},
9}