microsoft/layoutlmv3-base fine-tuned to tag each OCR word on a receipt, invoice or form as
O, B-KEY, I-KEY, B-VALUE or I-VALUE. It is the model inside
DRISE, which pairs it with PaddleOCR and a
deterministic post-processing layer (normalization, validation, cross-field constraints) to
produce structured JSON.
O, B-KEY, I-KEY, B-VALUE, I-VALUE. KEY supervision comes from FUNSD
questions and CORD is_key tokens; VALUE from FUNSD answers and CORD categories.model.safetensors (fp32, 501 MB) and onnx/model_int8.onnx (dynamic int8, 127 MB).transformers >= 5.from transformers import LayoutLMv3ForTokenClassification, LayoutLMv3Processor
repo = "purvanshh/drise-layoutlmv3-cord-funsd"
processor = LayoutLMv3Processor.from_pretrained(repo, apply_ocr=False)
model = LayoutLMv3ForTokenClassification.from_pretrained(repo).eval()
enc = processor(image, words, boxes=boxes_0_1000, truncation=True, return_tensors="pt")
labels = [model.config.id2label[i] for i in model(**enc).logits.argmax(-1)[0].tolist()]
ONNX (CPU):
import onnxruntime as ort
from huggingface_hub import hf_hub_download
session = ort.InferenceSession(hf_hub_download(repo, "onnx/model_int8.onnx"))
logits = session.run(["logits"], {k: enc[k].numpy() for k in ("input_ids", "attention_mask", "bbox", "pixel_values")})[0]
Token-level F1 on katanaml/cord is not a meaningful metric for this model. That split
labels 99.6% of tokens as entities and has no KEY labels, so a constant "everything is a VALUE"
baseline beats the model:
| System (CORD test, 100 docs, 2,358 tokens) | Token P | Token R | Token F1 |
|---|---|---|---|
| Baseline: every token VALUE (B then I) | 0.992 | 1.000 | 0.996 |
| This model, PyTorch fp32 | 0.752 | 1.000 | 0.858 |
| This model, ONNX int8 | 0.745 | 1.000 | 0.854 |
The model's "errors" there are mostly words it tags as KEY (TOTAL, CASH), which that split
never labels. The validation F1 of 0.8704 reported during training has the same issue.
End-to-end field extraction (DRISE pipeline, 201 annotated invoices, receipts and forms; paired exact McNemar test on per-document exact match):
| System | Field F1 | Exact match | Hallucination |
|---|---|---|---|
| Post-processing heuristics only, no model | 0.576 | 6.0% | 0.168 |
jinhybr/OCR-LayoutLMv3-Invoice + DRISE |
0.625 | 24.9% | 0.180 |
| This model + DRISE | 0.623 | 24.4% | 0.143 |
jinhybr checkpoint: no significant difference in exact match (0 vs 1 document,
p = 1.0); 21% fewer hallucinated fields.model.safetensors 478 MiBonnx/model_int8.onnx 121 MiB