← All models

image-classification · document AI · WASM · ~88 MB

DiT — what kind of document is this?

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.

At a glance

ModelXenova/dit-base-finetuned-rvlcdip (ONNX port of microsoft/dit-base-finetuned-rvlcdip)
Task / pipelineimage-classification
ArchitectureDiT — a BEiT-style ViT self-supervised pre-trained on 42M document images, then fine-tuned on RVL-CDIP
LabelsRVL-CDIP — 16 fixed document types (letter → memo)
Quantizationq8 (8-bit) ONNX — model_quantized.onnx
BackendWebAssembly (runs anywhere; no WebGPU needed)
Download~88 MB, cached after first load
LicenseApache-2.0
Web APIsWebAssembly, Web Workers, FileReader — all Baseline widely available

Run it

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.

Drop a document image here, or click to choose
A blank application form An invoice with a line-item table A printed email with header block An office memorandum A two-column scientific paper
Selected document preview

5 types

See inside

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.

Run a classification to see the full 16-class distribution.

Why it matters

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.

Use cases

Basics

Drop a page, read its document type and the full 16-class distribution — feel document classification first-hand.

Practical

A mailroom auto-sorter: classify a batch of scans and watch them drop into per-type inbox queues with confidence gating.

Wild

Ambiguous & mixed documents: splice a letter onto a form, crop and rotate, and watch the model argue with itself.

Multi-model

Classify → route → extract: DiT names the type, then Donut answers the type-appropriate question about the same page.

How the API works

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.

References