Views
No views yet
answerdotai/ModernBERT-large, binary token-classification model for
span-level RAG hallucination detection — the same recipe as
hugoomezz/modernbert-ragtruth-token-level-binary
(Track B / arm b), scaled to the -large backbone, seed 42.hugoomezz/modernbert-ragtruth-token-level-binary for that). Not validated outside
RAGTruth's three task types (QA, Summary, Data2txt), and not intended for production
moderation decisions.ModernBERT-large
vs -base) and seed count (this repo is seed 42 of a matched 3-seed sweep — see ADR-021
for the full 3-seed mean/range; this card reports seed 42's own numbers, not the mean).| Metric | Value |
|---|---|
| Response-level Precision | 0.8530 |
| Response-level Recall | 0.7444 |
| Response-level F1 | 0.7950 |
| Response-level Accuracy | 0.8659 |
| Span-level (char-overlap) Precision | 0.6954 |
| Span-level (char-overlap) Recall | 0.4927 |
| Span-level (char-overlap) F1 | 0.5767 |
| Task | F1 | Recall |
|---|---|---|
| Data2txt | 0.8803 | 0.8636 |
| QA | 0.7290 | 0.7063 |
| Summary | 0.5563 | 0.4363 |
hugoomezz/modernbert-ragtruth-token-level-binary (arm b, ModernBERT-base)
instead.implicit_true, contributes no evidence for or against §4, §5, or §6, and would be
removed without affecting any claim the paper makes."1import torch
2from transformers import AutoModelForTokenClassification, AutoTokenizer
3
4# The tokenizer is loaded from the base ModernBERT-large repo, not the fine-tuned one,
5# mirroring the same substitution used by hugoomezz/modernbert-ragtruth-token-level-binary
6# (arm b) -- training data was built with this exact base tokenizer, so it's exact, not
7# an approximation.
8TOKENIZER_ID = "answerdotai/ModernBERT-large"
9MODEL_ID = "hugoomezz/modernbert-large-ragtruth-token-level-binary"
10SUPPORTED, HALLUCINATED = 0, 1
11
12tokenizer = AutoTokenizer.from_pretrained(TOKENIZER_ID)
13model = AutoModelForTokenClassification.from_pretrained(MODEL_ID, attn_implementation="sdpa").eval()
14
15context = "The Eiffel Tower was completed in 1889 for the World's Fair in Paris."
16response = "The Eiffel Tower was completed in 1889 and is located in Berlin, Germany."
17
18encoding = tokenizer(
19 context, response, max_length=4096, truncation="only_first",
20 return_offsets_mapping=True, return_token_type_ids=False, return_tensors="pt",
21)
22sequence_ids = encoding.sequence_ids(0)
23encoding.pop("offset_mapping")
24
25with torch.no_grad():
26 logits = model(**encoding).logits[0]
27probs_hallucinated = torch.softmax(logits, dim=-1)[:, HALLUCINATED].tolist()
28
29response_probs = [p for p, sid in zip(probs_hallucinated, sequence_ids) if sid == 1]
30score = max(response_probs) if response_probs else 0.0
31print(f"hallucination score: {score:.4f} ({'FLAGGED' if score >= 0.5 else 'clean'})")1@inproceedings{niu2024ragtruth,
2 title = {RAGTruth: A Hallucination Corpus for Developing and Evaluating RAG Systems},
3 author = {Niu, Cheng and Wu, Yuanhao and Zhu, Juno and Xu, Siliang and Shum, Kashun and Zhong, Randy and Song, Juntong and Zhang, Tong},
4 booktitle = {Proceedings of ACL 2024},
5 year = {2024},
6 eprint = {2401.00396}
7}
8@article{kovacs2025lettucedetect,
9 title = {LettuceDetect: A Hallucination Detection Framework for RAG Applications},
10 author = {Kov{\'a}cs, {\'A}d{\'a}m and Bakos, Zsolt},
11 journal = {arXiv preprint arXiv:2502.17125},
12 year = {2025}
13}