Hallucination detector, G+C seed 44 (research prototype)
Research prototype from an MSc dissertation. Not a medical device and not for clinical use.
A supervised faithfulness detector for retrieval-augmented generation (RAG). It is a ModernBERT-base cross-encoder that reads a question, its retrieved context and a response, and scores whether the response contains content the context does not support (label 1 = hallucinated). This repository holds one training run: experiment G+C (general plus clinical training data), seed 44. The demo runs locally from the GitHub repository (app/README.md).
Code, training configuration and all results: github.com/praju2812/hallucination-detector
(tag submission).
Files
| file | contents |
|---|---|
best.pt |
PyTorch state dict of the selected epoch (sha256 740394cf65edfa0ff2e941b6388116612f0f6a0f48916ce9a9f9e0bfa1a57b3e) |
config_snapshot.json |
full training config, seed, git SHA (525c33c), library versions, input format |
metrics.json |
the run's threshold (0.10) and the validation sources it was tuned on, per-source metrics |
val_history.json |
validation PR-AUC and AUROC per epoch (selection metric) |
Use
The weights are a state dict for the repository's own model class, not a transformers checkpoint. With the GitHub
code checked out:
from huggingface_hub import hf_hub_download
import os
from src.inference import load_detector, score
repo = "Prajakta2812/hallucination-detector-gc-seed44"
paths = [hf_hub_download(repo, f) for f in ("config_snapshot.json", "metrics.json", "best.pt")]
detector = load_detector(os.path.dirname(paths[0]))
print(score("question", "retrieved context", "response to check", detector))
Model
- Backbone:
answerdotai/ModernBERT-base, binary classification head. - Input: question and context, then the response, in a 1,024-token window with
fit_firsttruncation (nothing is cut when the row fits; otherwise the end of the context is cut first, and the response keeps at least 384 tokens). - Training: 2 epochs on RAGTruth (QA and summary) and HaluEval (general) plus RAGBench PubMedQA, RAGBench CovidQA and MedHallu (clinical). Group-based splits. Validation and test rows sharing a question or an 8+ word passage with the clinical training data are removed from the clean test.
- Selection and threshold: pooled PubMedQA and CovidQA validation rows (never MedHallu, never test data). This seed had the best selection PR-AUC of the three G+C seeds (0.5159). Threshold 0.10.
Test results (this checkpoint, single run)
Clean clinical test sets and the general RAGTruth test, at the run's threshold of 0.10. The dissertation reports mean ± SD over seeds 42, 43 and 44; these are seed 44 alone.
| test set | PR-AUC | prevalence | AUROC | F1 | rows (hallucinated) |
|---|---|---|---|---|---|
| RAGBench PubMedQA (clean) | 0.539 | 0.28 | 0.746 | 0.540 | 522 (148) |
| RAGBench CovidQA (clean) | 0.317 | 0.19 | 0.551 | 0.235 | 105 (20) |
| MedHallu (clean) | 0.992 | 0.50 | 0.990 | 0.957 | 1,998 (999) |
| RAGTruth (general) | 0.507 | 0.20 | 0.787 | 0.459 | 1,800 (364) |
Source: results/rq2/run_seed44_20261126_011515.json in the GitHub repository.
Limitations
- RAGBench labels come from an LLM annotator, so some reference labels may be wrong.
- CovidQA's clean test is small (20 hallucinated rows): its numbers are uncertain.
- MedHallu's training and test hallucinations come from the same generation pipeline, so trained models can learn the generator's style; its near-perfect scores reflect that more than clinical skill.
- Faithfulness to the given context only: a faithful answer to wrong retrieved evidence is not flagged.
- The score is not a calibrated probability. Inputs longer than 1,024 tokens are trimmed, and text past the cut is not checked.
Licences and data
The weights are derived from components under different licences, so no single licence is declared:
- Base model: ModernBERT-base, Apache 2.0.
- RAGTruth, MIT.
- HaluEval, MIT.
- RAGBench (PubMedQA and CovidQA subsets), CC BY 4.0 (Friel, Belyi and Sanyal, 2024).
- MedHallu, MIT.
Check each source's terms before reusing the weights.