image-to-text Β· vision β text (scene-text recognition) Β· WASM Β· ~155 MB
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.
| Model | onnx-community/mgp-str-base β MGP-STR base (ONNX) |
|---|---|
| Task / pipeline | image-to-text (scene-text recognition), via MgpstrForSceneTextRecognition + MgpstrProcessor |
| Architecture | ViT encoder β three parallel prediction heads (character / BPE / WordPiece) β AΒ³ multi-granularity fusion. Single forward pass, not autoregressive. |
| Input | One cropped word (crop tight β MGP-STR reads a single word, not a line or paragraph) |
| Output | The recognised word + a fusion confidence, plus each head's own reading |
| Quantization | q8 (8-bit) ONNX |
| Backend | WebAssembly (runs anywhere; no WebGPU needed) |
| Download | ~155 MB, cached after first load |
| License | MIT (alibaba-damo/mgp-str-base) |
| Web APIs | WebAssembly, 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.
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.
Drag on the image to box a single word.
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.
Each cell is the character head's top pick at that position; the bar under it and the % are its confidence. Low-confidence glyphs are where a stylised font trips the reader.
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.
Crop one word and read it β with the three-granularity vote and per-character confidence.
A code & label reader: box several words and read them all into a copyable list.
Stylised, rotated and slanted words β watch the three heads disagree and the fusion arbitrate.
Detect β recognise: DBNet finds every word box, MGP-STR reads each one β full scene OCR.
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.