← All models

image-to-text Β· vision β†’ text (scene-text recognition) Β· WASM Β· ~155 MB

MGP-STR β€” read one word, three ways at once

MGP-STR is a scene-text recogniser: give it a cropped single word β€” COFFEE, STOP, a serial number β€” and it reads it back. The twist: a single Vision Transformer predicts the word three ways in parallel β€” character by character, as BPE subwords, and as WordPieces β€” then fuses the three into one answer. All on your device.

At a glance

Modelonnx-community/mgp-str-base β€” MGP-STR base (ONNX)
Task / pipelineimage-to-text (scene-text recognition), via MgpstrForSceneTextRecognition + MgpstrProcessor
ArchitectureViT encoder β†’ three parallel prediction heads (character / BPE / WordPiece) β†’ AΒ³ multi-granularity fusion. Single forward pass, not autoregressive.
InputOne cropped word (crop tight β€” MGP-STR reads a single word, not a line or paragraph)
OutputThe recognised word + a fusion confidence, plus each head's own reading
Quantizationq8 (8-bit) ONNX
BackendWebAssembly (runs anywhere; no WebGPU needed)
Download~155 MB, cached after first load
LicenseMIT (alibaba-damo/mgp-str-base)
Web APIsWebAssembly, Web Workers, Canvas, FileReader β€” all Baseline widely available

How is this different from TrOCR? TrOCR reads a whole line autoregressively (a decoder emits one token at a time). MGP-STR reads a single word in one shot, and its answer is a vote across three granularities β€” which is exactly what makes its "see inside" interesting.

Run it

Pick or drop an image, then drag a tight box around one word and hit Read. MGP-STR is a single-word recogniser, so the crop is the point.

Drop an image here, or click to choose
The word COFFEE in bold sans-serif The word STOP in red The word Ticket in a serif face The word PARKING A serial code A7X9K2 in a monospace face

Drag on the image to box a single word.

The recognised word appears here.

See inside β€” three granularities, one vote

This is what makes MGP-STR distinctive. The same image features feed three heads that spell the word out at different resolutions: a character head (one glyph at a time), a BPE head (subword chunks), and a WordPiece head. When the word is clean, all three agree. When it's stylised or partly hidden, they diverge β€” and the fusion picks the most confident consensus. The βœ“ marks the head the fused answer matched.

Read a word to see the three granularities and the per-character trace.

Why it matters

A text detector tells you where words are; a recogniser tells you what they say. MGP-STR is the "read one word" half of on-device OCR β€” small, fast, and robust to the messiness of real signage because it cross-checks three readings instead of trusting one.

Use cases

Basics

Crop one word and read it β€” with the three-granularity vote and per-character confidence.

Practical

A code & label reader: box several words and read them all into a copyable list.

Wild

Stylised, rotated and slanted words β€” watch the three heads disagree and the fusion arbitrate.

Multi-model

Detect β†’ recognise: DBNet finds every word box, MGP-STR reads each one β€” full scene OCR.

How the API works

MGP-STR isn't the plain image-to-text pipeline β€” it uses its own processor + model, three lines with Transformers.js:

import { MgpstrForSceneTextRecognition, MgpstrProcessor, RawImage }
  from "@huggingface/transformers";

const model = await MgpstrForSceneTextRecognition.from_pretrained(
  "onnx-community/mgp-str-base", { dtype: "q8" });      // ~155 MB, cached once
const processor = await MgpstrProcessor.from_pretrained("onnx-community/mgp-str-base");

const image  = await RawImage.read(wordCropURL);        // ONE word, cropped tight
const inputs = await processor(image);
const { logits } = await model(inputs);                  // [char, bpe, wp] logits
const out = processor.batch_decode(logits);
// out.generated_text β†’ ["coffee"]  (the FUSED answer)
// out.char_preds / out.bpe_preds / out.wp_preds β†’ each head's own reading
// out.scores β†’ [0.9999]  (fusion confidence)

For "See inside", this page reads the char_logits tensor directly β€” a softmax per position gives the per-character confidence trace β€” and computes a comparable confidence for the BPE and WordPiece heads, all off the main thread in a Web Worker. Note: MGP-STR normalises to lowercase and its charset is a–z + 0–9; it reads a single word, so crop tight and box words one at a time.

References