← All models

image-to-text Β· vision β†’ text (OCR) Β· WASM Β· ~340 MB

TrOCR Base β€” the accurate printed-text reader

This is the base-sized TrOCR printed-text checkpoint β€” roughly 2.5Γ— the parameters of the small model, traded for materially better accuracy on hard print: small type, low contrast, dense labels. A Vision Transformer looks at a cropped line of text and a text decoder writes it out, one token at a time β€” GRAND TOTAL: $42.99 β€” entirely on your device.

At a glance

ModelXenova/trocr-base-printed
Task / pipelineimage-to-text
ArchitectureViT-style image encoder β†’ RoBERTa-style text decoder (VisionEncoderDecoder, cross-attention), base size (~334M params)
InputA single line of printed text (crop to the line you want)
OutputThe transcribed characters, generated token by token
Quantizationq8 (8-bit) ONNX β€” separate encoder + decoder graphs
BackendWebAssembly (runs anywhere; no WebGPU needed)
Download~340 MB, cached after first load
LicenseMIT (microsoft/trocr-base-printed)
Vs the small modelSlower per line (~2.5 s vs ~0.7 s on WASM) but reads hard print the small checkpoint garbles
Web APIsWebAssembly, Web Workers, Canvas, FileReader β€” all Baseline widely available

Run it

Pick or drop an image, then drag a box around one line of text and hit Read. TrOCR is a single-line reader, so the crop is the point β€” it transcribes what's inside the box.

Drop an image here, or click to choose
A receipt line reading Grand Total $42.99 A printed line: The quick brown fox jumps A sign reading Platform 9 A label reading SN 4B7X-9021-KD A small cafΓ© receipt with several lines

Drag on the image to select a line.

See inside β€” the decode, token by token

OCR here is autoregressive generation, not template matching. The encoder reads the cropped line into patch embeddings once; then the decoder emits the transcription one token at a time, each conditioned on the image and everything decoded so far β€” which is why TrOCR can fix its own spelling from context. The trace below shows every streamed chunk as it arrived, with the elapsed time. The first token is the slow one (it includes the image encode); the rest come faster. The base model's decoder is deeper than the small one's, so per-token time is higher β€” the price of the extra accuracy.

Read a line to see the token-by-token trace.

Why it matters

Text trapped in an image is invisible to everything that isn't a person looking at it β€” you can't search it, copy it, translate it, or total it. OCR turns those pixels back into characters, and doing it locally makes it free, private, and offline-capable. The base checkpoint is the one to reach for when accuracy matters more than download size: faint receipts, dense product labels, small print on packaging.

Use cases

Basics

Crop a line β€” a sign, a serial label, a receipt total β€” and read it, token by token.

Practical

Digitise a whole receipt line by line, then capture + validate a serial number.

Wild

Live webcam OCR β€” point your camera at text and read it on the fly.

Multi-model

OCR β†’ translation: read foreign text, then translate it locally.

How the API works

The base call is two lines with Transformers.js:

import { pipeline } from "@huggingface/transformers";

const reader = await pipeline(
  "image-to-text",
  "Xenova/trocr-base-printed",
); // downloads + caches ~340 MB once

const out = await reader(lineCropURL, { max_new_tokens: 48 });
// β†’ [{ generated_text: "GRAND TOTAL: $42.99" }]

The important bit is the input: TrOCR expects one line of text, so this page crops the region you box before handing it over. For "See inside", it passes a TextStreamer into the same call β€” the streamer fires as each word chunk is finalised (it flushes at whitespace boundaries), so the page renders the transcription as it forms and records each chunk's arrival time, all off the main thread in a Web Worker. Note: this SROIE-tuned checkpoint tends to normalise to UPPERCASE β€” that's the model, not a bug.

References