Refer to the project report for more details.
This project investigates hallucination detection in medical question answering systems using transformer-based models. I compare a general-purpose language model (BERT) with a biomedical domain-specific model (BioBERT) to evaluate their effectiveness in detecting hallucinated medical responses.
Large Language Models (LLMs) can generate fluent but factually incorrect outputs (hallucinations), especially in high-stakes domains like healthcare. Detecting such hallucinations is essential for safe deployment.
This project formulates hallucination detection as a binary classification problem:
Given a medical question, context, and answer: predict whether the answer is grounded (0) or hallucinated (1).
Evaluate both in-domain and out-of-domain generalization.
Source: https://arxiv.org/abs/2502.14302
Dataset: https://huggingface.co/datasets/UTAustin-AIHealth/MedHallu
MedHallu is a medical hallucination detection benchmark with fine-grained annotations.
I use it to construct a binary classification dataset:
- (Question + Context, Ground Truth Answer) → Label 0 (non-hallucinated)
- (Question + Context, Hallucinated Answer) → Label 1 (hallucinated)
Categories include:
- Misinterpretation of Question
- Incomplete Information
- Mechanism and Pathway Misattribution
- Methodological and Evidence Fabrication
Source: https://arxiv.org/abs/2307.15343
Dataset: https://huggingface.co/datasets/openlifescienceai/Med-HALT
Med-HALT is used to evaluate robustness under distribution shift and reasoning stress tests.
It includes three sub-tasks:
- FCT (False Confidence Test)
- NOTA (None of the Above Test)
- FQT (Fake Questions Test)
I compare two transformer-based sequence classification models:
- BERT-base-uncased
- BioBERT-base-cased (biomedical pretraining)
Both models are fine-tuned using HuggingFace Transformers for binary classification.
Each training example is constructed as: Question + Answer → Candidate Answer
Binary classification:
- 0 → Grounded / correct answer
- 1 → Hallucinated / incorrect answer
- Framework: HuggingFace Transformers
- Loss Function: Cross-Entropy Loss
- Optimizer: AdamW
- Epochs: 5
- Batch Size: 8
- Max Sequence Length: 256
| Model | Accuracy | F1 Score |
|---|---|---|
| BERT | ~0.94–0.95 | ~0.94 |
| BioBERT | ~0.95–0.96 | ~0.96 |
BioBERT consistently outperforms BERT in the medical domain.
| Model | Accuracy | F1 Score |
|---|---|---|
| BERT | ~0.43 | ~0.33 |
| BioBERT | ~0.56 | ~0.59 |
BioBERT shows significantly better generalization under distribution shift.
| Task | BERT F1 | BioBERT F1 |
|---|---|---|
| FCT | ~0.30 | ~0.49 |
| NOTA | ~0.35 | ~0.65 |
| FQT | 0.00 | 0.00 |
- Domain-specific pretraining (BioBERT) improves hallucination detection performance.
- Strong in-domain results do not guarantee out-of-domain robustness.
- Both models struggle significantly with Fake Question (FQT) tasks.
- Hallucination detection remains challenging under reasoning shifts and adversarial inputs.
.
├── hallucination_classification_bert.ipynb
├── hallucination_classification_biobert.ipynb
├── hallucination_detection_in_medical_QA_biobert_vs_bert.pdf
└── README.md