Tamarillo/groundedness-guard-base (v2)

Zero-trust_remote_code, Apache-2.0 token-span RAG & AI-agent groundedness / hallucination detector (v2) built on jhu-clsp/mmBERT-base (307.5M parameters, trained up to 3,584 tokens and evaluated up to 4,096 tokens on an 8K backbone, parity-verified ONNX).

Outputs both exact token/span-level hallucination localization (0: supported, 1: hallucinated β€” 1-line drop-in compatible with KRLabsOrg/lettucedect-v2-mmbert-base) and calibrated document/claim-level groundedness scores (1 - sigmoid(Top-6 LME) or 1 - max P(hallucinated)).

RAG & Agent Groundedness v2 Strictly OOD Pareto Frontier

What's New in v2

v1 β†’ v2 Upgrade Gains (Tamarillo/groundedness-guard-base): RAGTruth_test 0.782 β†’ 0.893 (v1 OOD β†’ v2 ID), strictly 0-shot OOD SummEval 0.797 β†’ 0.808, FRANK 0.916 β†’ 0.930, WikiBio-GPT3 0.755 β†’ 0.782, 3-OOD Mean 0.823 β†’ 0.840, EN Char-Span F1 0.537 β†’ 0.605.

  • Backbone: jhu-clsp/mmBERT-base (307.5M params, id2label = {0: "supported", 1: "hallucinated"}, trust_remote_code=False)
  • Language Coverage: 14 languages trained & evaluated (en, ar, ca, cs, de, es, eu, fa, fi, fr, hi, it, sv, zh on s-nlp/PsiloQA); flagship accuracy in the Tamarillo v2 family
  • Headline v2 Metrics (Top-6 LME): Strictly 0-Shot OOD 3-Suite Mean 0.840 AUC (SummEval 0.808, FRANK 0.930, WikiBio-GPT3 0.782); RAGTruth_test (ID) 0.893 AUC / 0.754 Hal F1; 4-Core Mean 0.853; PsiloQA (ID) EN 0.943 / 13-Lang Non-EN 0.848 (EN Char Span F1 0.605 / 14-Lang Overall 0.416); 250β†’3,200-tok depth retention +0.008 AUC; CPU ONNX FP32 56.2 ms @ 64 tok / 406.9 ms @ 512 tok / 3439.7 ms @ 2,048 tok (1173.7 MB).

Quickstart

1. PyTorch / Transformers β€” Groundedness Score + Exact Hallucinated Spans (Zero trust_remote_code)

Note: Hugging Face's default pipeline("token-classification") accepts single strings only; use the (context, response) pair helper below.

pip install "transformers>=4.48.0" torch
import math
import torch
from transformers import AutoTokenizer, AutoModelForTokenClassification

repo = "Tamarillo/groundedness-guard-base"
tokenizer = AutoTokenizer.from_pretrained(repo)
model = AutoModelForTokenClassification.from_pretrained(repo).eval()  # trust_remote_code=False!

def verify_groundedness(context: str, response: str, threshold: float = 0.5, max_length: int = 3584):
    """Returns calibrated P(consistent) via Top-6 LME + exact hallucinated character spans."""
    try:
        enc = tokenizer(
            context, response,
            truncation="only_first", max_length=max_length,
            return_token_type_ids=False, return_offsets_mapping=True, return_tensors="pt",
        )
    except Exception:
        enc = tokenizer(
            context, response,
            truncation="longest_first", max_length=max_length,
            return_token_type_ids=False, return_offsets_mapping=True, return_tensors="pt",
        )
    offsets = enc.pop("offset_mapping")[0].tolist()
    seq_ids = enc.sequence_ids(0)
    with torch.no_grad():
        logits = model(**enc).logits[0].float()  # [seq_len, 2]: 0=supported, 1=hallucinated

    z_hal = logits[:, 1] - logits[:, 0]
    p_hal = torch.sigmoid(z_hal)
    hyp_idxs = [i for i, sid in enumerate(seq_ids) if sid == 1 and offsets[i][1] > offsets[i][0]]
    if not hyp_idxs:
        return {"consistent_score": 1.0, "hallucinated_spans": []}

    # Top-6 Log-Mean-Exp (beta=2.0) bag score β€” robust against single-token noise
    top_z = torch.topk(z_hal[hyp_idxs], k=min(6, len(hyp_idxs))).values
    lme = (torch.logsumexp(2.0 * top_z, dim=0) - math.log(len(top_z))) / 2.0
    p_consistent = float(1.0 - torch.sigmoid(lme))

    # Merge contiguous hallucinated tokens into character spans
    spans = []
    for i in hyp_idxs:
        prob = float(p_hal[i])
        if prob >= threshold:
            s, e = offsets[i]
            if spans and s <= spans[-1]["end"] + 1:
                spans[-1]["end"] = e
                spans[-1]["text"] = response[spans[-1]["start"]:e]
                spans[-1]["max_prob"] = round(max(spans[-1]["max_prob"], prob), 4)
            else:
                spans.append({"start": s, "end": e, "text": response[s:e], "max_prob": round(prob, 4)})
    return {"consistent_score": round(p_consistent, 4), "hallucinated_spans": spans}

ctx = "Q3 Financial Summary: Operating revenue rose 8% YoY to $4.2 million. The policy explicitly excludes flood damage."
resp = "Q3 operating revenue reached $4.8 million and the policy covers flood damage automatically."
print(verify_groundedness(ctx, resp))

2. CPU-Only ONNX Runtime (onnxruntime, Zero PyTorch Required)

pip install onnxruntime transformers huggingface_hub numpy
import numpy as np
import onnxruntime as ort
from huggingface_hub import hf_hub_download
from transformers import AutoTokenizer

repo = "Tamarillo/groundedness-guard-base"
tokenizer = AutoTokenizer.from_pretrained(repo)
# Tip: `onnx/model.onnx` (FP32) is fastest on CPU; `onnx/model_fp16.onnx` cuts download size by 50% with 1.0000 parity.
onnx_path = hf_hub_download(repo, "onnx/model.onnx")
sess = ort.InferenceSession(onnx_path, providers=["CPUExecutionProvider"])

try:
    enc = tokenizer(
        ["Q3 revenue rose 8% YoY to $4.2 million."],
        ["Q3 revenue reached $6.5 million."],
        padding=True, truncation="only_first", max_length=3584,
        return_token_type_ids=False, return_tensors="np",
    )
except Exception:
    enc = tokenizer(
        ["Q3 revenue rose 8% YoY to $4.2 million."],
        ["Q3 revenue reached $6.5 million."],
        padding=True, truncation="longest_first", max_length=3584,
        return_token_type_ids=False, return_tensors="np",
    )
logits = sess.run(["logits"], {
    "input_ids": enc["input_ids"].astype(np.int64),
    "attention_mask": enc["attention_mask"].astype(np.int64),
})[0][0].astype(np.float32)

hyp_idxs = [i for i, sid in enumerate(enc.sequence_ids(0)) if sid == 1]
if not hyp_idxs:
    print({"consistent_score": 1.0, "peak_token_hal_prob": 0.0})
else:
    z_hal = logits[hyp_idxs, 1] - logits[hyp_idxs, 0]
    top_z = np.sort(z_hal)[::-1][:6]
    mx = float(np.max(2.0 * top_z))
    lme = (mx + float(np.log(np.mean(np.exp(2.0 * top_z - mx))))) / 2.0
    p_consistent = 1.0 - float(1.0 / (1.0 + np.exp(-lme)))
    print({"consistent_score": round(p_consistent, 4), "peak_token_hal_prob": round(float(1.0 / (1.0 + np.exp(-z_hal.max()))), 4)})

Benchmark Comparisons

All models were evaluated on NVIDIA A100 GPUs (BF16, bs=1 p50 latency, fixed 0.50 probability threshold for F1) using bit-for-bit identical deterministic test splits (eval_results.json bundled in this repository). Each model uses its native pooling method: Top-6 LME for Tamarillo Token-Span MIL models and native max_pool (1 - max_t P(hal_t)) for KRLabsOrg/lettucedect-v2-mmbert-base (both pooling modes are bundled side-by-side in eval_results.json).

1A. Strictly Zero-Shot Out-of-Distribution (OOD) English Suites (SummEval, FRANK, WikiBio-GPT3)

None of SummEval, FRANK, WikiBio-GPT3, or FinQA appeared in Tamarillo's training or validation splits (enforced via normalized MD5 deduplication on both pairs and claims). All tested encoders score near-random (0.40–0.46 AUC) on multi-step financial arithmetic (FinQA); full FinQA metrics are bundled in eval_results.json.

Model Params Pooling / Arch SummEval (AUC / Hal F1) FRANK (AUC / Hal F1) WikiBio-GPT3 (AUC / Hal F1) 3-Suite Strictly OOD Mean AUC A100 Latency bs=1 (512 / 2,048 tok)
Tamarillo/groundedness-guard-tiny-en (v2) 32.0M Token-Span MIL (Top-6 LME) 0.580 / 0.313 0.760 / 0.718 0.765 / 0.877 0.702 15.0 ms / 23.5 ms
Tamarillo/groundedness-guard-small (v2) 140.6M Token-Span MIL (Top-6 LME) 0.699 / 0.379 0.873 / 0.819 0.794 / 0.884 0.789 29.5 ms / 39.7 ms
Tamarillo/groundedness-guard-base (v2) 307.5M Token-Span MIL (Top-6 LME) 0.808 / 0.491 0.930 / 0.864 0.782 / 0.886 0.840 30.3 ms / 59.1 ms
Tamarillo/groundedness-guard-base (v1) 307.5M Token-Span MIL (Top-6 LME) 0.797 / 0.530 0.916 / 0.862 0.755 / 0.883 0.823 30.2 ms / 50.4 ms
vectara/hallucination_evaluation_model 109.6M T5 SeqCls (TRC=True) 0.773 / 0.386 0.911 / 0.835 0.786 / 0.886 0.824 16.3 ms / 72.5 ms
Horizon-Labs/hallucination-guard-base 307.5M SeqCls (8K) 0.696 / 0.366 0.940 / 0.871 0.750 / 0.872 0.796 30.4 ms / 50.5 ms
KRLabsOrg/lettucedect-v2-mmbert-base 307.5M Token-Span (native max-pool) 0.792 / 0.422 0.907 / 0.799 0.799 / 0.881 0.833 31.3 ms / 50.8 ms

1B. RAGTruth_test (QA / Summarization / Data2Txt) & 4-Core RAG Mean

ID / OOD Disclosure: Tamarillo v2 models include the MIT-licensed ParticleMedia/RAGTruth train split in Stage 2 (matching KRLabsOrg/lettucedect-v2-mmbert-base and Horizon-Labs/hallucination-guard-base, all tagged ID below; strict zero-overlap verification against flowaicom/RAGTruth_test). vectara/hallucination_evaluation_model and Tamarillo v1 did not train on RAGTruth (OOD).

Model Params RAGTruth Status RAGTruth_test Overall (AUC / Hal F1) QA AUC Summ. AUC Data2Txt AUC 4-Core Mean AUC
Tamarillo/groundedness-guard-tiny-en (v2) 32.0M ID 0.871 / 0.743 0.886 0.737 0.896 0.744
Tamarillo/groundedness-guard-small (v2) 140.6M ID 0.902 / 0.758 0.900 0.839 0.902 0.817
Tamarillo/groundedness-guard-base (v2) 307.5M ID 0.893 / 0.754 0.899 0.807 0.893 0.853
Tamarillo/groundedness-guard-base (v1) 307.5M OOD 0.782 / 0.643 0.821 0.809 0.604 0.813
vectara/hallucination_evaluation_model 109.6M OOD 0.832 / 0.578 0.838 0.796 0.652 0.826
Horizon-Labs/hallucination-guard-base 307.5M ID 0.876 / 0.727 0.871 0.797 0.888 0.816
KRLabsOrg/lettucedect-v2-mmbert-base 307.5M ID 0.825 / 0.684 0.803 0.774 0.852 0.831

2. 14-Language PsiloQA Test (ID for Tamarillo; OOD for Baselines) & 4-Depth Long-Context Stability

  • ID / OOD Symmetry: s-nlp/PsiloQA (train split) is part of Tamarillo's Stage 2 training data, so PsiloQA test is in-distribution (ID) for Tamarillo (small/base across all 14 languages; tiny-en on EN only) and OOD for all public baselines.
  • Class Prevalence: PsiloQA test is skewed toward hallucinated spans (~95.5% EN, ~86.5% Non-EN), so Table 2 reports ROC-AUC / Macro-F1 (0.5 * (hal_f1 + cons_f1)).
  • 4-Depth LC Needle Seed Provenance: 120 balanced English claims (41 consistent + 60 hallucinated PsiloQA EN + 19 consistent RAGTruth_test) embedded across 250 β†’ 3,200-token distractor haystacks. Primary metric is Depth Retention (LC 3.2K βˆ’ LC 250).
Model Params PsiloQA Status PsiloQA EN (AUC / Macro-F1) PsiloQA Non-EN (AUC / Macro-F1) LC 250 LC 800 LC 1.6K LC 3.2K Depth Ξ” (3.2Kβˆ’250)
Tamarillo/groundedness-guard-tiny-en (v2) 32.0M EN-ID / Non-EN OOD 0.955 / 0.693 0.700 / 0.614 0.942 0.921 0.923 0.919 -0.022
Tamarillo/groundedness-guard-small (v2) 140.6M ID (14-lang) 0.930 / 0.782 0.857 / 0.712 0.950 0.949 0.943 0.944 -0.006
Tamarillo/groundedness-guard-base (v2) 307.5M ID (14-lang) 0.943 / 0.782 0.848 / 0.683 0.945 0.952 0.952 0.953 +0.008
Tamarillo/groundedness-guard-base (v1) 307.5M ID (14-lang) 0.976 / 0.758 0.843 / 0.690 0.957 0.955 0.953 0.959 +0.002
vectara/hallucination_evaluation_model 109.6M OOD 0.949 / 0.731 0.562 / 0.580 0.888 0.893 0.885 0.883 -0.005
Horizon-Labs/hallucination-guard-base 307.5M OOD 0.924 / 0.789 0.713 / 0.627 0.911 0.922 0.923 0.935 +0.024
KRLabsOrg/lettucedect-v2-mmbert-base 307.5M OOD 0.828 / 0.785 0.801 / 0.577 0.929 0.924 0.907 0.876 -0.052

3. Character/Span-Level Hallucination Localization (s-nlp/PsiloQA Gold Character Spans)

Exact character-level span localization at fixed token probability threshold 0.50 across all 1,795 PsiloQA test examples (up to 200/lang across 14 languages; ID for Tamarillo small/base, EN-ID for tiny-en, OOD for LettuceDetect v2). Note on tiny-en Non-EN F1 (0.493 vs 0.443/0.337 for small/base): because PsiloQA Non-EN is 86.5% hallucinated, English-only tiny-en over-predicts hallucination on unfamiliar non-English scripts (77.7% doc FPR, 45.4% Non-EN char precision), inflating raw F1 compared to the much higher-precision (60–62%) 14-language small/base models.

Token-Span Model PsiloQA Status EN Char (Prec / Rec) EN Span (Char F1 / IoU) 13-Lang Non-EN Span (Char F1 / IoU) Overall Char (Prec / Rec) Overall Char F1
Tamarillo/groundedness-guard-tiny-en (v2) (32.0M) EN-ID / Non-EN OOD 0.660 / 0.624 0.642 / 0.472 0.493 / 0.327 0.496 / 0.559 0.525
Tamarillo/groundedness-guard-tiny-en (v1) (32.0M) EN-ID / Non-EN OOD 0.685 / 0.472 0.559 / 0.388 0.461 / 0.300 0.506 / 0.460 0.482
Tamarillo/groundedness-guard-small (v2) (140.6M) ID (14-lang) 0.662 / 0.640 0.651 / 0.482 0.443 / 0.285 0.623 / 0.420 0.502
Tamarillo/groundedness-guard-small (v1) (140.6M) ID (14-lang) 0.685 / 0.456 0.548 / 0.377 0.315 / 0.187 0.653 / 0.269 0.381
Tamarillo/groundedness-guard-base (v2) (307.5M) ID (14-lang) 0.671 / 0.550 0.605 / 0.433 0.337 / 0.202 0.644 / 0.307 0.416
Tamarillo/groundedness-guard-base (v1) (307.5M) ID (14-lang) 0.723 / 0.428 0.537 / 0.367 0.331 / 0.198 0.655 / 0.274 0.386
KRLabsOrg/lettucedect-v2-mmbert-base (307.5M) OOD 0.760 / 0.725 0.742 / 0.590 0.415 / 0.262 0.727 / 0.398 0.514

ONNX Exports, Parity Gates & Multi-Length CPU Latency

Every ONNX export is gated against PyTorch FP32 on both short (≀256 tok) and long (2,048 tok) pairs across both token-level and bag-level predictions (agreement >= 0.995 and strict max delta thresholds: <= 0.001 FP32, <= 0.02 FP16, <= 0.05 INT8). CPU timings use onnxruntime CPUExecutionProvider (bs=1, 4 intra-op threads).

Exported Artifact File Size Short Parity (Agree / Ξ”max) 2,048-Tok Parity (Agree / Ξ”max) CPU 4-Th @ 64 tok CPU 4-Th @ 512 tok CPU 4-Th @ 1,024 tok CPU 4-Th @ 2,048 tok
FP32 (onnx/model.onnx) 1173.7 MB 1.0000 (Δ≀0.0000) 1.0000 (Δ≀0.0000) 56.2 ms 406.9 ms 1127.1 ms 3439.7 ms
FP16 (onnx/model_fp16.onnx) 587.0 MB 1.0000 (Δ≀0.0010) 1.0000 (Δ≀0.0021) 64.0 ms 466.8 ms 1399.7 ms 4509.0 ms
Gather-INT8 (onnx/model_quantized.onnx) 611.4 MB 1.0000 (Δ≀0.0052) 1.0000 (Δ≀0.0123) 54.4 ms 422.9 ms 1167.3 ms 3510.2 ms

Excluded precision exports (parity gate):

  • Full-INT8 (Gather+MatMul) dynamic quantization: withheld β€” dynamic MatMul quantization degrades ModernBERT RoPE/GeGLU attention logits below our strict parity gate.

Training Recipe, Data Provenance & Reproducibility

  • Base Model: jhu-clsp/mmBERT-base (canonical foundation checkpoint)
  • Architecture & Training Pipeline: Standard ModernBertForTokenClassification (0: supported, 1: hallucinated) trained via a 2-Stage Multi-Task Span Curriculum on jhu-clsp/mmBERT-base: Stage 1 warms up on 112K clean semantic NLI pairs (MoritzLaurer/synthetic_zeroshot_mixtral_v0.1 [Apache-2.0], alisawuffles/WANLI [CC-BY-4.0], permissive OANC genres of nyu-mll/multi_nli); Stage 2 trains on 153.9K length-debiased multilingual groundedness pairs adding human-annotated multi-task span supervision from ParticleMedia/RAGTruth (MIT train split, QA/Summary/Data2Txt) alongside McGill-NLP/FaithDial (MIT), lytang/C2D-and-D2C-MiniCheck (MIT), Salesforce/summedits (CC-BY-4.0), s-nlp/PsiloQA 14 langs (CC-BY-4.0), minimal-edit counterfactuals, length-matched multi-passage paragraphs, and same-haystack long-context RAG pairs up to 3,584 tokens, optimized with Hybrid Exact-Span BCE + Top-6 Log-Mean-Exp MIL + Max-Pool Calibration + Same-Document Contrastive Bag Ranking + EMA (decay=0.996).
  • Upstream Synthetic Provenance Note: While Mixtral-NLI, MiniCheck, and Salesforce/summedits are published under permissive repository licenses (Apache-2.0 / MIT / CC-BY-4.0), they include synthetic pairs originally generated or edited using LLMs; ParticleMedia/RAGTruth (MIT) provides human-annotated LLM outputs. Users with strict model-lineage compliance requirements should verify upstream terms for their jurisdiction.
  • Validation Selection: Best checkpoint selected strictly on validation composite (selection_score = 0.8401, val ROC-AUC max=0.8784 / LME=0.8817, weights=ema; test sets were never used for checkpoint selection).

Bundled reproducible scripts in this repository:


Limitations & Candid Comparison

  1. Multi-step numerical & tabular arithmetic (FinQA): Compact bi-directional encoders do not execute symbolic arithmetic; subtle multi-step calculation errors in dense financial tables (0.40–0.46 AUC across all tested encoders) require tool/code verification rather than an encoder alone.
  2. Where public baselines win: On individual suites, Horizon-Labs/hallucination-guard-base leads FRANK AUC (0.940 vs 0.930 for Tamarillo base v2), and KRLabsOrg/lettucedect-v2-mmbert-base leads WikiBio-GPT3 AUC (0.799 vs 0.782 for base v2 / 0.794 for small v2) as well as English full-span character F1 on PsiloQA (0.742 EN Char F1 vs 0.605 EN Char F1 for Tamarillo/groundedness-guard-base). On strictly 0-shot OOD 3-Suite Mean (SummEval, FRANK, WikiBio-GPT3), vectara-hhem scores 0.824, Horizon-Labs scores 0.796, and LettuceDetect v2 scores 0.833 compared to 0.840 for Tamarillo/groundedness-guard-base.
  3. Long-context CPU latency of base (307.5M): Multi-chunk 1,024–2,048 token verification on 4-thread CPU scales quadratically (1.1 s–3.4 s); CPU-only microservices should prefer Tamarillo/groundedness-guard-tiny-en (11.1 ms @ 64 tok / 82.0 ms @ 512 tok) or small (27.8 ms @ 64 tok / 198.6 ms @ 512 tok), reserving base for GPU serving (30–59 ms A100 @ 512–2,048 tok).
  4. Multilingual OOD evaluation gap: All 13 non-English languages are evaluated in-distribution on s-nlp/PsiloQA test (aggregate Non-EN metrics in Table 2) rather than an external OOD multilingual groundedness benchmark.

License

Weights, ONNX exports, and training/evaluation scripts are released under the Apache-2.0 license.

Downloads last month
67
Safetensors
Model size
0.3B params
Tensor type
F32
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for Tamarillo/groundedness-guard-base

Quantized
(311)
this model

Datasets used to train Tamarillo/groundedness-guard-base

Space using Tamarillo/groundedness-guard-base 1

Collection including Tamarillo/groundedness-guard-base