All models

TrOCR-Small-EncoderDecoder

An encoder-decoder Transformer that reads a text-line image as patches and writes out the text token by token.

Documents and OCR · 682 operations Checked

100%

Showing the top corner; full diagram not loaded yetShowing a small copy; full diagram not loaded yetLarge diagram, not loaded yet

Open SVG

Loading diagram (37 KB)

Open in a new tab

Click or tap a spot to read it up close. Scroll or drag inside the diagram to move through it. Zoom with + and − or Ctrl and scroll. Press 0 for the whole graph. Swipe inside the diagram to move through it. Use + and − to zoom.

At a glance

Family
TrOCR
Parameters
61.6M
Operations
682
Framework
PyTorch
Recurrent
No
Published
AAAI (arXiv 2021)
Cited by
594 (as of 21 October 2026)
Authors
Minghao Li, Tengchao Lv, Jingye Chen and others
License
Apache-2.0
Checked
Passed: the trace was replayed operation by operation and matched the model's own output for this input.

Files

The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.

Details
Stable ID
m3136
Graph hash
b023fcebbc7fbf0a1092653d9e83c9f21083cf67e5bec8de2b467be4dab76462
Skeleton hash
a0d6bea197118b45f4c0c8d5092bc17207bc951ec0fb024538c3fdd2f7b990b4
Architecture hash
084bb521a94a2d6cf8bbf7e0874f47aa9a25041119072cc999714705ac985603
Diagram SHA-256
f4ff9a9fde4d2fbb515eedee54688910dbda1013914d01fb5b76f0cb45054a9d
TorchLens version
2.36.0
Renderer
graphviz 2.43.0+pyvips 3.2.0+libvips 8.18.7+render-opts@06c1f0d3
Check
Forward pass replayed in PyTorch

What it is

TrOCR-Small pairs the DeiT-small encoder with a decoder initialized from MiniLM; the paper reports 62M total parameters for this setting. Because its encoder is initialized from DeiT, the input sequence keeps DeiT's distillation token.

About this model's family

TrOCR is a text recognition model that turns an image of a line of text into the text itself, using a Transformer for both the image and the language side. The paper sets this against existing approaches, which it describes as usually built on a CNN for image understanding and an RNN for text generation. TrOCR has no CNN backbone: the input image is resized to 384×384 and split into a sequence of 16×16 patches for the image Transformer. The decoder then generates the recognized text as wordpiece units.

Both halves start from existing pre-trained models, and the authors describe the paper as, to their knowledge, the first work to jointly use pre-trained image and text Transformers for text recognition in OCR. Encoders are initialized from DeiT and BEiT models. Decoders are initialized from RoBERTa and MiniLM models. Those are encoder-only models, so the encoder-decoder attention layers have no counterpart in them and the absent parameters are randomly initialized.

Pre-training runs in two stages, the first on a synthesized dataset of printed text lines that the paper puts at 684M. On the SROIE receipt dataset, the paper's results table lists word-level F1 of 95.82 for TrOCR-Small and 96.34 for TrOCR-Base.

Key idea. TrOCR is an end-to-end text recognition approach built from a pre-trained image Transformer and a pre-trained text Transformer.

  • trocr
  • transformer ocr
  • optical character recognition
  • ocr
  • text recognition
  • handwritten text recognition
  • image-to-text
  • trocr-base
  • trocr-small
  • vision encoder decoder

AI-written summary, based on the paper and checked automatically against it; not reviewed by a person. Corrections welcome.

Cite the paper

@misc{li2022trocrtransformerbasedopticalcharacter,
      title={TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models}, 
      author={Minghao Li and Tengchao Lv and Jingye Chen and Lei Cui and Yijuan Lu and Dinei Florencio and Cha Zhang and Zhoujun Li and Furu Wei},
      year={2022},
      eprint={2109.10282},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/2109.10282}, 
}