← All models

image-to-text · vision → text (handwriting OCR) · WASM · ~64 MB

TrOCR Handwriting — read what people write by hand

Printed-text OCR is a solved problem; handwriting is not — every person's letterforms are different. This TrOCR checkpoint is fine-tuned on the IAM handwriting database: a Vision Transformer looks at a line of handwriting and a text decoder writes it out, one token at a time — entirely on your device.

At a glance

ModelXenova/trocr-small-handwritten (ONNX of microsoft/trocr-small-handwritten)
Task / pipelineimage-to-text
ArchitectureViT-style image encoder → RoBERTa-style text decoder (VisionEncoderDecoder, cross-attention)
Trained onIAM Handwriting Database — modern English handwriting, single text lines
InputA single line of handwritten text (draw it, or crop to one line)
OutputThe transcribed characters, generated token by token
Quantizationq8 (8-bit) ONNX — separate encoder + decoder graphs
BackendWebAssembly (runs anywhere; no WebGPU needed)
Download~64 MB, cached after first load
LicenseMIT (microsoft/trocr-small-handwritten)
Web APIsWebAssembly, Web Workers, Canvas, Pointer Events, FileReader — all Baseline widely available

Run it

The most natural way to test a handwriting model: write something. Draw a line on the pad below (mouse, finger, or pen) and hit Read — or drop a photo of a handwritten note and drag a box around one line. TrOCR is a single-line reader.

Write a line here — then Read it.

…or use a photo / sample instead
Drop an image here, or click to choose
A handwritten assignment note in an exercise book A page of handwritten manuscript text

Drag on the image to select a line.

See inside — the decode, token by token

Handwriting recognition here is autoregressive generation, not template matching. The encoder reads the 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 how TrOCR resolves ambiguous strokes from context (is that cl or d? the surrounding word decides). The trace below shows every token as it arrived, with the elapsed time. The first token is the slow one (it includes the image encode); the rest come faster.

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

Why it matters

An enormous amount of the world's text is still handwriting: meeting notes, whiteboards, forms, prescriptions, letters, historical archives. Handwriting OCR turns those pen strokes into searchable, copyable, translatable characters — and doing it locally means the note never leaves the device, which matters for exactly the things people write by hand (medical, legal, personal).

Use cases

Basics

Write a word or pick a sample line — watch handwriting become text, token by token.

Practical

Digitise a handwritten note: read each line into an editable, copyable list.

Wild

Live camera handwriting reader — point your camera at a note and read it on the fly.

Multi-model

Handwriting → translation: read a handwritten line, 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-small-handwritten",
); // downloads + caches ~64 MB once

const out = await reader(lineImageURL, { max_new_tokens: 48 });
// → [{ generated_text: "Meeting moved to Friday 3pm" }]

The important bit is the input: TrOCR expects one line of handwriting, so this page hands it either the drawing pad's bitmap or a cropped region of a photo. For "See inside", it passes a TextStreamer into the same call — the streamer fires once per decoded token, so the page renders the transcription as it forms and records each token's arrival time, all off the main thread in a Web Worker. Note: the IAM training data is modern English handwriting on clean lines — old copperplate, heavily crossed-out text, and very stylised writing are honest limits, not bugs.

References