TinyDoc-VLM

Grounded document extraction SDK โ€” schema-valid JSON, evidence boxes, confidence scores. Runs locally on free models. No API key.

GitHub stars PyPI HF Model HF Space License

๐Ÿ”ฅ Highlights

๐Ÿง 

Beats the Free Competition

Field F1 0.870 on held-out SROIE receipts vs 0.376 for PP-OCR + heuristics and 0.227 for Tesseract + regex โ€” measured on the same 100 documents.

๐Ÿ”

Evidence for Every Field

Each extracted value ships with the OCR span and bounding box it came from โ€” human-verifiable provenance, coverage 79.8%.

๐Ÿ“‹

Schema-Valid Output

JSON Schema validation + sanitization on every result (validity 1.000 on eval), plus a calibrated confidence score per field.

โš™๏ธ

Engine Ladder

Free ollama:qwen2.5vl:3b by default, quality tiers up to 7B, ONNX and OCR-fallback engines behind one interface.

๐Ÿ“ฆ

One pip Install

pip install tinydoc โ€” Python SDK with Pydantic-typed results, CLI, and a local Gradio demo.

๐Ÿค—

Open & Free

Apache 2.0 license โ€” free for commercial use. Local-first: no API key, no cloud, no telemetry.

๐Ÿš€ Quick Start

# Install the SDK
pip install tinydoc

# Requirements: a running Ollama with qwen2.5vl:3b (free, local)
from tinydoc.pipeline import ReceiptPipeline

pipe = ReceiptPipeline("auto")
doc = pipe.extract("receipt.jpg")

# Schema-valid fields + confidence
print(doc.fields, doc.schema_valid, doc.confidence)

# Evidence: OCR span + bbox behind every value
for fr in doc.field_results:
    print(fr.name, fr.value, fr.evidence["quote"], fr.evidence["bbox"])

# Or from the shell
tinydoc extract ./receipts/ --out results.jsonl --overlay overlays/

๐Ÿ—๏ธ How it works

Receipt / invoice image
    โ†“
Engine (ollama:qwen2.5vl:3b โ€” free & local, or 7B / ONNX / OCR-fallback)
    โ†“
Raw model output โ†’ JSON extraction โ†’ collapse repetition โ†’ sanitize
    โ†“
JSON Schema validation  โ”€โ”€ schema_valid: true/false
    โ†“
Evidence anchoring (PP-OCR word boxes โ†’ best span + bbox per field)
    โ†“
Confidence (evidence quality ร— schema ร— field rules)
    โ†“
DocumentResult โ€” fields + per-field {quote, bbox, score} + confidence

๐Ÿ“Š Benchmarks (measured)

BenchmarkMetricScoreStatus
SROIE receipts โ€” TinyDoc pipeline (qwen2.5vl:3b)Field F10.870โœ… n=100, committed artifacts
SROIE receipts โ€” PP-OCR + heuristics baselineField F10.376โœ… same 100 docs, same scorer
SROIE receipts โ€” Tesseract + regex baselineField F10.227โœ… same 100 docs, same scorer
Schema validity (pipeline, SROIE eval)Rate1.000โœ… n=100
Evidence coverage (RapidOCR, post A/B)Rate0.798โœ… n=100 ร— 4 fields
FUNSD transfer probe (form โ†’ receipt-shaped keys)Field F10.352โœ… n=50, nonstandard gold mapping
OCRBench โ€” TinyDoc-VLM 256M research checkpointAccuracy0.0%โš ๏ธ n=1000 โ€” model retired from claims
DocVQA / CORD / PubTabNetโ€”โ€”Not measured

Every number above recomputes from committed artifacts in evaluation/phase0/results/. The 256M checkpoint's earlier benchmark figures were never measured and have been withdrawn โ€” see docs/BENCHMARKS.md.