All models

TrOCR-Base-EncoderDecoder

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

Documents and OCR · 1,041 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 (31 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
333.9M
Operations
1,041
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
m3135
Graph hash
030a3338ffd58fc2bbc746e297923be456e49b57b9f0d3cf012d3b99c2668b0d
Skeleton hash
b620faf54cab998c5e3bcbeb15d74f31bf9060e4ee54de824bf275f228f4f986
Architecture hash
deaac3d5fe379400afe4f7a56128d0d4839c8ac84f1abb2acc5a6a80383c0f60
Diagram SHA-256
fb637a9ddf20a27cadb8e776a0bb7ee4534172a331f3581ddc8c90aebb5e10bd
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-Base pairs the BEiT-base encoder with a decoder initialized from RoBERTa-large; the paper reports 334M total parameters for this setting.

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}, 
}