PrismVerify-Small / README.md
flintglass's picture
Release Flintglass PrismVerify-Small v1 (mmBERT-small 140M, 1800+ langs, 8K ctx, 16ms CPU ONNX INT8)
3300666 verified
|
Raw History Blame Contribute Delete
7.79 kB
---
license: apache-2.0
language:
- multilingual
- en
- es
- fr
- de
- zh
- ja
- ko
- ar
- ru
- pt
- hi
base_model: jhu-clsp/mmBERT-small
datasets:
- flintglass/PrismVerify-Corpus
library_name: transformers
pipeline_tag: text-classification
tags:
- hallucination-detection
- groundedness
- faithfulness
- rag
- rag-evaluation
- fact-checking
- nli
- modernbert
- onnx
- flintglass
---
# PrismVerify-Small
**8,192-Token RAG Hallucination & Groundedness Verifier · 3-Class (`FAITHFUL` / `CONTRADICTION` / `UNSUPPORTED`) · Apache 2.0 · PyTorch + ONNX INT8**
> Built by **[Flintglass Labs](https://huggingface.co/flintglass)** — an ultra-fast 140M multilingual 8K-context hallucination verifier built for low-latency CPU/edge RAG pipelines.
- **Interactive Demo:** [flintglass/PrismVerify-Demo](https://huggingface.co/spaces/flintglass/PrismVerify-Demo)
- **Model Family:** [`PrismVerify-Large`](https://huggingface.co/flintglass/PrismVerify-Large) (395M) · [`PrismVerify-Multilingual`](https://huggingface.co/flintglass/PrismVerify-Multilingual) (307M, 1,800+ langs) · [`PrismVerify-Small`](https://huggingface.co/flintglass/PrismVerify-Small) (140M, 1,800+ langs)
- **Training Dataset & Benchmark:** [`flintglass/PrismVerify-Corpus`](https://huggingface.co/datasets/flintglass/PrismVerify-Corpus) (Apache 2.0)
---
## Why PrismVerify?
Production RAG pipelines and AI agents routinely stuff **2,000–8,000 tokens** of retrieved documents into context. Legacy hallucination detectors (`vectara/HHEM-2.1-Open`, `DeBERTa-v3-NLI`) either truncate at 512 tokens or OOM on multi-chunk contexts, while RAGTruth-only detectors overfit to one dataset and drop sharply on HaluEval, DocNLI, and long multi-document RAG.
**`PrismVerify-Small`** brings precision optical clarity to groundedness verification:
| Property | Specification |
|---|---|
| **Backbone** | `jhu-clsp/mmBERT-small` (140M parameters) |
| **Native Context Window** | **8,192 tokens** (claim placed first so `[CLAIM]` is never truncated!) |
| **Languages** | Multilingual (1,800+ languages via mmBERT) |
| **Classes (`id2label`)** | `0: FAITHFUL`, `1: CONTRADICTION`, `2: UNSUPPORTED` |
| **Calibration** | Post-hoc temperature scaling (`T = 1.0461`) baked directly into the linear head |
| **Formats Included** | Safetensors (`model.safetensors`), ONNX FP32 (`onnx/model.onnx`, 563.08 MB), ONNX INT8 (`onnx/model_int8.onnx`, 436.44 MB) |
| **License** | **Apache 2.0** (ungated, commercial-friendly) |
---
## Quickstart
### 1. Drop-in PyTorch / `transformers`
```python
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
model_id = "flintglass/PrismVerify-Small"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSequenceClassification.from_pretrained(model_id).eval()
context = "In Q3 2026, Meridian Robotics reported revenue of $142.8M, up 18.4% YoY, with gross margin of 59.8%."
claim = "Meridian Robotics grew Q3 revenue by 18.4% to $142.8M and expanded gross margin to 65%."
text = f"[CLAIM]\n{claim}\n\n[CONTEXT]\n{context}"
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=8192)
with torch.no_grad():
probs = torch.softmax(model(**inputs).logits, dim=-1)[0]
print({
"faithful": probs[0].item(),
"contradiction": probs[1].item(),
"unsupported": probs[2].item(),
"hallucination_score": 1.0 - probs[0].item(),
"is_hallucinated": (1.0 - probs[0].item()) >= 0.5,
})
```
### 2. Ultra-Fast CPU Inference with ONNX Runtime (INT8)
```python
import numpy as np
import onnxruntime as ort
from huggingface_hub import hf_hub_download
from transformers import AutoTokenizer
model_id = "flintglass/PrismVerify-Small"
tokenizer = AutoTokenizer.from_pretrained(model_id)
onnx_path = hf_hub_download(repo_id=model_id, filename="onnx/model_int8.onnx")
session = ort.InferenceSession(onnx_path, providers=["CPUExecutionProvider"])
text = "[CLAIM]\nThe solar plant includes 20 MWh battery storage.\n\n[CONTEXT]\nThe 50 MW solar plant does not yet include battery storage."
enc = tokenizer(text, return_tensors="np", truncation=True, max_length=8192)
logits = session.run(None, {
"input_ids": enc["input_ids"].astype(np.int64),
"attention_mask": enc["attention_mask"].astype(np.int64),
})[0][0]
probs = np.exp(logits - logits.max()) / np.exp(logits - logits.max()).sum()
print({"FAITHFUL": float(probs[0]), "CONTRADICTION": float(probs[1]), "UNSUPPORTED": float(probs[2])})
```
---
## Zero-Leakage Benchmark Evaluation
All models below were evaluated identically at `threshold = 0.50` (`hallucination_score = 1 - P(FAITHFUL)`). Training data was strictly filtered via exact pair hash + 10-word response shingle matching against all evaluation splits (blocking **3,646** overlapping items).
| Model | Max Ctx | Output | RAGTruth F1↑ (AUROC) | HaluEval F1↑ | DocNLI F1↑ | LongRAG-8K F1↑ (FPR↓) | Avg 4-Bench F1↑ |
|---|---:|:---:|---:|---:|---:|---:|---:|
| **Flintglass PrismVerify-Large (395M)** | 8,192 | 3-class | 0.741 (0.878) | 0.906 | 0.676 | 0.896 (9.2%) | **0.805** |
| **Flintglass PrismVerify-Multilingual (307M)** | 8,192 | 3-class | 0.729 (0.866) | 0.906 | 0.549 | 0.857 (12.8%) | **0.760** |
| **Flintglass PrismVerify-Small (140M)** | 8,192 | 3-class | 0.722 (0.866) | 0.911 | 0.541 | 0.860 (10.0%) | **0.759** |
| KRLabsOrg/lettucedect-large-modernbert | 8,192 | Token | 0.776 (0.901) | 0.633 | 0.579 | 0.798 (7.8%) | **0.697** |
| KRLabsOrg/lettucedect-base-modernbert | 8,192 | Token | 0.718 (0.857) | 0.647 | 0.603 | 0.756 (15.6%) | **0.681** |
| vectara/HHEM-2.1-Open | 512* | Binary | 0.613 (0.826) | 0.628 | 0.492 | OOM (>178 GB) | — |
| MoritzLaurer/DeBERTa-v3-large-NLI | 512 | NLI | 0.213 (0.679) | 0.673 | 0.681 | 0.641 (55.0%) | **0.552** |
*Note: `vectara/HHEM-2.1-Open` uses custom untrimmed T5 attention and ran out of memory (>178 GB VRAM on NVIDIA B200) on 4K–6.5K token multi-chunk RAG contexts in `LongRAG-8K`.*
### Long-Context Multi-Chunk RAG Breakdown (`LongRAG-Verify-Bench`, 512 → 6,500 tokens)
| Model | 512 tok F1 (FPR↓) | 1K tok F1 (FPR↓) | 2K tok F1 (FPR↓) | 4K tok F1 (FPR↓) | 6.5K tok F1 (FPR↓) |
|---|---:|---:|---:|---:|---:|
| **PrismVerify-Large (395M)** | 0.915 (9%) | 0.860 (10%) | 0.901 (11%) | 0.893 (9%) | 0.908 (7%) |
| **PrismVerify-Multilingual (307M)** | 0.861 (15%) | 0.856 (11%) | 0.859 (17%) | 0.844 (11%) | 0.866 (10%) |
| **PrismVerify-Small (140M)** | 0.845 (12%) | 0.856 (11%) | 0.883 (10%) | 0.836 (10%) | 0.880 (7%) |
| lettucedect-large | 0.804 (7%) | 0.822 (6%) | 0.822 (6%) | 0.780 (11%) | 0.761 (9%) |
| lettucedect-base | 0.769 (28%) | 0.804 (10%) | 0.782 (6%) | 0.725 (16%) | 0.696 (18%) |
| DeBERTa-v3-large-NLI | 0.670 (17%) | 0.638 (45%) | 0.650 (62%) | 0.648 (73%) | 0.609 (78%) |
---
## CPU ONNX Latency & Parity
| Sequence Length | ONNX FP32 (563.08 MB) | ONNX INT8 (436.44 MB) |
|---|---:|---:|
| 64 tokens | 23.6 ms | 15.97 ms |
| 256 tokens | 63.23 ms | 28.9 ms |
| 1,024 tokens | 318.15 ms | 213.39 ms |
- FP32 ONNX vs PyTorch max logit delta: `1e-05`
## Limitations
- Encoder-based verifiers excel at lexical, factual, entity, negation, temporal, and span-groundedness verification, but do not perform multi-step arithmetic derivations (for numerical/mathematical RAG calculations, pair with a reasoning verifier LLM or code interpreter).
- Always place the claim/response first (`[CLAIM] ... [CONTEXT] ...`) when formatting inputs so long contexts never truncate the claim.
## Citation
```bibtex
@misc{flintglass2026prismverify,
title={PrismVerify: 8K-Context Open-Source RAG Hallucination and Groundedness Verification},
author={Flintglass Labs},
year={2026},
url={https://huggingface.co/flintglass/PrismVerify-Small}
}
```