image-classification · document AI · WASM · ~88 MB
A Document Image Transformer: a vision model that looks at a scanned page as a picture and
sorts it into one of 16 document types — letter, form,
email, invoice, resume, scientific publication and
more. It reads page layout — where the margins, tables, letterheads and columns sit — not
the words, so it works before a single character is OCR'd. It runs entirely on your device: the
document never leaves the tab.
| Model | Xenova/dit-base-finetuned-rvlcdip (ONNX port of microsoft/dit-base-finetuned-rvlcdip) |
|---|---|
| Task / pipeline | image-classification |
| Architecture | DiT — a BEiT-style ViT self-supervised pre-trained on 42M document images, then fine-tuned on RVL-CDIP |
| Labels | RVL-CDIP — 16 fixed document types (letter → memo) |
| Quantization | q8 (8-bit) ONNX — model_quantized.onnx |
| Backend | WebAssembly (runs anywhere; no WebGPU needed) |
| Download | ~88 MB, cached after first load |
| License | Apache-2.0 |
| Web APIs | WebAssembly, Web Workers, FileReader — all Baseline widely available |
Pick or drop a scanned document (or an image of one) and hit Classify. Because there are only 16 classes, the "See inside" panel below shows the model's entire probability distribution, not just the top few.

5 types
DiT's final layer produces one raw score — a logit — per document type. A
softmax turns those 16 logits into probabilities that sum to 100%. With only 16
classes we can show the whole distribution at once, so you can see not just the winner but
every rival and how the model spreads its doubt. Two numbers summarise the shape: the
top-1 margin (how far the winner leads the runner-up) and the normalised
entropy (0 = certain, 1 = spread evenly across all 16). A clean invoice is peaky and
low-entropy; a page that's half-letter, half-form sits between letter and
form with high entropy — its confusion is legible.
Confidence (low ← → high):
Why a vision model for text documents? DiT never reads the words. It was self-supervised pre-trained on 42 million document images — learning to reconstruct masked patches of pages — so it internalised what letterheads, forms, tables and journal columns look like. Fine-tuning on RVL-CDIP then maps that layout sense onto the 16 types. That's why it can triage a page into "this is an invoice" before any OCR runs, and why it's robust to languages or fonts it can't read.
Almost every business document workflow starts with the same dull question: what is this page? Answering it on-device, before anything is uploaded or OCR'd, is a cheap, private first step that routes the expensive work only where it's needed.
invoice, letter, resume and form queues so each goes to the right team, with no server round-trip.invoice pages to an invoice parser, resume pages to a CV parser, form pages to a field extractor — a classifier is the cheap dispatcher in front of costly OCR/VQA.presentation slides out of a "contracts only" ingest.form and questionnaire) to a human.Drop a page, read its document type and the full 16-class distribution — feel document classification first-hand.
A mailroom auto-sorter: classify a batch of scans and watch them drop into per-type inbox queues with confidence gating.
Ambiguous & mixed documents: splice a letter onto a form, crop and rotate, and watch the model argue with itself.
Classify → route → extract: DiT names the type, then Donut answers the type-appropriate question about the same page.
The convenience path is two lines with Transformers.js:
import { pipeline } from "@huggingface/transformers";
const classify = await pipeline(
"image-classification",
"Xenova/dit-base-finetuned-rvlcdip",
{ dtype: "q8" },
); // downloads + caches ~88 MB once
const output = await classify(documentImageURL, { top_k: 5 });
// → [{ label: "invoice", score: 0.94 }, { label: "budget", score: 0.03 }, …]
This page goes one level deeper for "See inside": instead of the pipeline it runs the model's own
processor then model() in a single forward pass, so it can read the raw
logits tensor (all 16 types) and compute the softmax, entropy and margin itself. Same
weights, same result — just keeping the intermediate numbers. Inference runs in a Web Worker so the
page never janks. The labels come back lower-cased (scientific report); the page
Title-Cases them.