{"notes":[{"id":"text-recognition/ocr-scaling-law","category":"text-recognition","legacyPath":"text-recognition/2401-ocr-scaling-law","legacySlug":"2401-ocr-scaling-law","legacyPaths":[],"title":"OCR Scaling Law","subtitle":"Scaling Law for OCR","author":"Z. Yuan","paperDate":"2023-12-29","publishedOn":"2024-11-15","paperTitle":"An Empirical Study of Scaling Law for OCR","paperUrl":"https://arxiv.org/abs/2401.00028","bibliography":{"title":"An Empirical Study of Scaling Law for OCR","authors":["Miao Rang","Zhenni Bi","Chuanjian Liu","Yunhe Wang","Kai Han"],"url":"https://arxiv.org/abs/2401.00028","pdfUrl":"https://arxiv.org/pdf/2401.00028","codeUrl":null,"preprint":{"id":"2401.00028","submittedOn":"2023-12-29","url":"https://arxiv.org/abs/2401.00028"},"publication":null,"citation":"@misc{textrecognitionocrscalinglaw2023,\n  title = {{An Empirical Study of Scaling Law for OCR}},\n  author = {Miao Rang and Zhenni Bi and Chuanjian Liu and Yunhe Wang and Kai Han},\n  year = {2023},\n  eprint = {2401.00028},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/2401.00028}\n}\n","citationPath":"/content/papers/citations/text-recognition/ocr-scaling-law.7f17e4808c5f.bib"},"thumbnail":{"src":"/content/papers/assets/7f8bf4fb742fad31bedbe3b952d194a3bcac951a36f95169f217b752a0a8381a.jpg","width":968,"height":288},"locale":"en","path":"/content/papers/en/text-recognition/ocr-scaling-law.a9ff6fad251e.md","headings":[{"id":"defining-the-problem","text":"Defining the Problem","depth":2},{"id":"solving-the-problem","text":"Solving the Problem","depth":2},{"id":"model-scaling","text":"Model Scaling","depth":3},{"id":"data-scaling","text":"Data Scaling","depth":3},{"id":"experimental-setup","text":"Experimental Setup","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"power-law-for-model-size","text":"Power-Law for Model Size","depth":3},{"id":"power-law-for-dataset-size","text":"Power-Law for Dataset Size","depth":3},{"id":"power-law-for-computational-resources","text":"Power-Law for Computational Resources","depth":3},{"id":"ratio-of-synthetic-to-real-data","text":"Ratio of Synthetic to Real Data","depth":3},{"id":"necessity-of-pretraining","text":"Necessity of Pretraining","depth":3},{"id":"comparison-with-other-models","text":"Comparison with Other Models","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"text-recognition/union14m","relation":"background","topic":"Training data and generalization in text recognition"}]},{"id":"text-recognition/union14m","category":"text-recognition","legacyPath":"text-recognition/2307-union14m","legacySlug":"2307-union14m","legacyPaths":[],"title":"Union14M","subtitle":"Chess Pieces Falling Like Stars","author":"Z. Yuan","paperDate":"2023-07-17","publishedOn":"2024-10-22","paperTitle":"Revisiting Scene Text Recognition: A Data Perspective","paperUrl":"https://arxiv.org/abs/2307.08723","bibliography":{"title":"Revisiting Scene Text Recognition: A Data Perspective","authors":["Qing Jiang","Jiapeng Wang","Dezhi Peng","Chongyu Liu","Lianwen Jin"],"url":"https://arxiv.org/abs/2307.08723","pdfUrl":"https://arxiv.org/pdf/2307.08723","codeUrl":null,"preprint":{"id":"2307.08723","submittedOn":"2023-07-17","url":"https://arxiv.org/abs/2307.08723"},"publication":{"venue":"ICCV","year":2023,"kind":"conference","url":"https://arxiv.org/abs/2307.08723"},"citation":"@misc{textrecognitionunion14m2023,\n  title = {{Revisiting Scene Text Recognition: A Data Perspective}},\n  author = {Qing Jiang and Jiapeng Wang and Dezhi Peng and Chongyu Liu and Lianwen Jin},\n  year = {2023},\n  eprint = {2307.08723},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/2307.08723}\n}\n","citationPath":"/content/papers/citations/text-recognition/union14m.69b5d5fefc96.bib"},"thumbnail":{"src":"/content/papers/assets/39ca4ac101c26285774d8d0a7a5a9f4ba67f58b1d7e6ba91956378290e12682a.jpg","width":1152,"height":500},"locale":"en","path":"/content/papers/en/text-recognition/union14m.0b024ea32641.md","headings":[{"id":"defining-the-problem","text":"Defining the Problem","depth":2},{"id":"problem-solution","text":"Problem Solution","depth":2},{"id":"union14m-l","text":"Union14M-L","depth":3},{"id":"union14m-u","text":"Union14M-U","depth":3},{"id":"diverse-text-styles","text":"Diverse Text Styles","depth":3},{"id":"rich-vocabulary","text":"Rich Vocabulary","depth":3},{"id":"model-architecture","text":"Model Architecture","depth":3},{"id":"pretraining-and-fine-tuning","text":"Pretraining and Fine-Tuning","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"the-harsh-reality","text":"The Harsh Reality","depth":3},{"id":"uncovering-the-challenges","text":"Uncovering the Challenges","depth":3},{"id":"the-benchmark-dataset","text":"The Benchmark Dataset","depth":3},{"id":"experimental-results","text":"Experimental Results","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"text-recognition/yatr","relation":"background","topic":"Training data and generalization in text recognition"},{"id":"text-recognition/ocr-scaling-law","relation":"next","topic":"Training data and generalization in text recognition"}]}],"text":"A few years ago, researchers in the NLP field attempted to summarize the scaling law for models, compiling several simple formulas.\n\nNow, it’s already 2024, yet no paper seems to have addressed this issue in the OCR field.\n\nTo address this gap, Huawei's Noah's Ark Lab took on the challenge.\n\n## Defining the Problem\n\nFirst, we need to know whether bigger models really help before investing more resources. After all, who would want to fund a larger model if the investment brings no benefit?\n\nIn the NLP domain, this question was explored years ago, with subsequent research delving even deeper. Examples include:\n\n- [**[20.01] Scaling Laws: Scaling Laws for Neural Language Models**](/blog/papers/transformers/scaling_laws)\n- [**[22.03] Chinchilla’s Law**](https://arxiv.org/abs/2203.15556)\n\nThese studies were focused on NLP, but researchers in OCR seem to have paid little attention to this question.\n\nSince people are hesitant to invest resources without understanding the risks, this area clearly needs research to bridge the gap.\n\n## Solving the Problem\n\nThis paper does not propose a new model architecture. Instead, the authors design an experimental framework to examine the scaling law of models from the following perspectives:\n\n1. **Model Size**: Refers to the number of parameters in the model, ranging from 50 million to 1 billion.\n2. **Dataset Size**: Refers to the size of the training dataset, ranging from 1 million to 1 billion samples.\n3. **Computation Time**: Refers to the time required to train the model, ranging from 100 hours to 1,000 hours.\n\nThese are the ranges outlined in the paper's introduction; the models and data volumes used in each experiment are given in the corresponding tables below.\n\nIn addition to this, the authors introduce a new dataset: **REBU-Syn**. This dataset, proposed in the paper, combines real and synthetic data, curated from existing publicly available datasets.\n\n### Model Scaling\n\nThe first aspect to explore is model size.\n\nThe authors reference two notable previous studies: **TrOCR** and **PARSeq**.\n\n\n> [!TIP]\n> \n> If you're unfamiliar with these models, you can refer to our earlier articles:\n> \n> - [**[21.09] TrOCR: Pretraining is Justice**](/blog/papers/text-recognition/trocr)\n> - [**[22.07] PARSeq: Wrod oerdr dseon't mteartr for redaing**](/blog/papers/text-recognition/parseq)\n\n\nTrOCR is a text recognition model based entirely on the Transformer architecture. It was the first to combine vision Transformers with text Transformers for OCR tasks.\n\nTo analyze how model size impacts performance, the authors scale TrOCR models from **TrOCR-S** to **TrOCR-H**, with parameter sizes ranging from 43.09 million to 1.037 billion.\n\n- **TrOCR-S**: Uses DeiT$_\\text{SMALL}$ as the encoder and MiniLM as the decoder.\n- **TrOCR-B**: Uses BEIT$_\\text{BASE}$ as the encoder and RoBERTa$_\\text{LARGE}$ as the decoder.\n- **TrOCR-L and TrOCR-H**: Use BEIT$_\\text{LARGE}$ as the encoder and RoBERTa$_\\text{LARGE}$ as the decoder.\n\n\n\n![TrOCR Scaling](/content/papers/assets/47233921fe81800e271c16d4da4f385b5e3a84083c7a40b11546dd2b6c765b10.jpg)\n\n\n\n---\n\nPARSeq uses a Transformer-based encoder-decoder architecture.\n\n- The **Encoder** employs a ViT model to extract image features. It removes the `[CLS]` token and feeds all output tokens to the decoder.\n- The **Decoder** adopts a Transformer decoder similar to preLayerNorm, with the number of attention heads defined as $nhead = \\frac{d_{model}}{32}$.\n\nThe authors scale PARSeq models to four sizes to study the scaling laws for large OCR models:\n\n- **PARSeq-S**: The base version.\n- **PARSeq-B, PARSeq-L, and PARSeq-H**: Gradually expanded model sizes, ranging from 22.51 million to 682 million parameters. Detailed configurations are shown in the table below.\n\n\n\n![PARSeq Scaling](/content/papers/assets/dea9efb6ceb289d29e00e1caa016ad98aec46a81108979966715939d8dc25721.jpg)\n\n\n\n### Data Scaling\n\nIn the early stages, model training primarily relied on synthetic data. However, as more real-world data became available, training models on real data proved to be more efficient. To scale up the training dataset, the authors created a new dataset: **REBU-Syn**, which consists of approximately 6 million real-world samples and 18 million publicly available synthetic samples, in a **synthetic:real ratio of 3:1**.\n\n\n> [!TIP]\n> \n> **Why 3:1?**\n> \n> This ratio wasn’t chosen arbitrarily. In later sections, the authors present experiments finding that this ratio works best among the tested configurations.\n\n\nThe real-world dataset is divided into the following components:\n\n- **R Group**: Includes common real-world sources such as COCO-Text, RCTW17, UberText, ArT, LSVT, MLT19, ReCTS, TextOCR, and OpenVINO.\n- **E Group**: Adds two real datasets commonly used in text detection, Total Text and CTW1500, as another source of real-world samples.\n- **B Group**: Contains training data from benchmark datasets like IIIT 5k-word, Street View Text, ICDAR13, and ICDAR15.\n- **U Group**: Draws from Union14M-L, which contains about 4 million labeled images across 14 datasets; this paper uses about 3.1 million after its compilation.\n\n---\n\nThe synthetic dataset is composed of the following:\n\n- **Commonly Used Datasets**:\n\n  - **MJSynth (MJ)**: 8.9 million samples.\n  - **SynthText (ST)**: 5.5 million samples.\n\n- **Additional Synthetic Data**:\n  - **Curved SynthText (CST)**: Designed for detecting curved text.\n  - **SyntheAdd (SA)**: Generates data containing rare characters, such as punctuation marks.\n\nIn addition to public synthetic datasets, the authors generated more synthetic data using two tools: **TextRecognitionDataGenerator** and **SynthText**.\n\nThe text corpus was drawn from 700,000 entries from widely used English-language corpora globally. Backgrounds for the synthetic data were selected from natural scene images provided by SynthText.\n\n\n> [!TIP]\n> \n> If you’re interested in synthetic data generation tools, we’ve compiled related resources here:\n> \n> - [**Resources for Text Synthesis Tools**](https://docsaid.org/docs/wordcanvas/tools)\n\n\n### Experimental Setup\n\nThe authors defined different hyperparameter configurations for each model architecture:\n\n- **TrOCR Models**\n  - **TrOCR-S**: Batch size $1024$, learning rate $4 \\times 10^{-4}$.\n  - **TrOCR-B**: Batch size $256$, learning rate $1 \\times 10^{-4}$.\n  - **TrOCR-L**: Batch size $128$, learning rate $4 \\times 10^{-5}$.\n- **PARSeq Models**\n  - A consistent learning rate of $7 \\times 10^{-4}$ was used, with batch sizes as close to $1024$ as possible.\n\nFor text tokenization, **BPE (Byte Pair Encoding)** [68] and **SentencePiece** [37] were used to split text lines into subword units:\n\n- [**[15.08] Neural Machine Translation of Rare Words with Subword Units**](https://arxiv.org/abs/1508.07909)\n- [**[18.08] SentencePiece**](https://arxiv.org/abs/1808.06226)\n\nThe primary evaluation metric was **word accuracy**. To ensure fair comparisons across models and datasets, the final output strings were standardized to a common set of $36$ characters (lowercase letters and digits).\n\n## Discussion\n\nHere $E$ is the average word error rate across six test sets, so lower is better. The authors study its relationship with three variables:\n\n- **Number of Model Parameters ($N$)**: Reflecting the complexity and capacity of the model.\n- **Amount of Training Data ($D$)**: Representing the scale of the data available for training.\n- **Model Computation Cost ($C$)**: Represented in these experiments by training time; Figure 2(c) labels the horizontal axis as training hours on eight GPUs.\n\nThe goal of the experiments is to describe and validate the power-law relationship between recognition error $E$ and the variables $N$, $D$, and $C$. The study also aims to determine if a smooth and scalable trend exists, enabling performance to improve effectively with increased resource allocation.\n\n### Power-Law for Model Size\n\n- **TrOCR Models**\n\n\n\n    ![TrOCR Scaling](/content/papers/assets/7f8bf4fb742fad31bedbe3b952d194a3bcac951a36f95169f217b752a0a8381a.jpg)\n\n\n\n  The number of parameters $N$ and recognition error $E$ exhibit a power-law relationship, expressed as:\n\n  $$\n  E(N) = \\left(\\frac{1.97 \\times 10^4}{N}\\right)^{0.223}\n  $$\n\n  The power-law formula is fitted based on the first three models (TrOCR-S, TrOCR-B, and TrOCR-L). The final model, TrOCR-H, aligns closely with the fitted curve, supporting the fit for these models and data conditions, without establishing unlimited extrapolation.\n\n- **PARSeq Models**\n\n\n\n    ![PARSeq Scaling](/content/papers/assets/ca1b5566dbba0dac01795603c746ccc6bc8d040745fbe1b83967cbf93106a0d3.jpg)\n\n\n\n  Similar to TrOCR, the number of parameters $N$ and error $E$ in PARSeq follow a power-law relationship:\n\n  $$\n  E(N) = \\left(\\frac{6.316 \\times 10^{-74}}{N}\\right)^{0.018}\n  $$\n\n### Power-Law for Dataset Size\n\n- **TrOCR Models**:\n\n\n\n  ![trocr data scaling](/content/papers/assets/abb8a0d211e14e2e3a3b9f402ca87064b546ea528e3e378ca541cb6a2701b536.jpg)\n\n\n\n  Table 6 compares TrOCR-B word accuracy with 0.75 million to 75 million training samples. The paper prints the following fit for error $E$:\n\n  $$\n  E(D) = \\left(\\frac{1.84 \\times 10^5}{D}\\right)^{-0.3271}\n  $$\n\n  Average accuracy in the table rises from 50.35% to 93.09%. Yet the printed negative exponent makes $E$ rise as $D$ increases, opposite to the falling error curve in Figure 2(b) and the table. We cannot use Equation (3) as printed to predict performance.\n\n- **PARSeq Models**:\n\n\n\n  ![parseq data scaling](/content/papers/assets/dccff50025be9e0c850e107de2c9ac5632d25334da1d53e4015578044ab6e174.jpg)\n\n\n\n  As R, B, E, U, and synthetic data are added in Table 7, average accuracy rises from 95.57% to 96.85%. Data sources and volume change together, so this table alone cannot isolate the effect of volume.\n\n### Power-Law for Computational Resources\n\n\n\n![trocr compute scaling](/content/papers/assets/44e988d5368a5245004c8818817d340ae78948a2a27a5254f128a5b62ad182ac.jpg)\n\n\n\nFigure 2(c) plots average word error against training time. The paper prints Equation (4) as:\n\n$$\nE(C) = \\left(\\frac{4.45 \\times 10^4}{C}\\right)^{-0.3271}\n$$\n\nThe grey fitted line falls as training time increases, but Equation (4)'s negative exponent implies the opposite. The plot legend also shows $-0.764$, while Equation (4) prints $-0.3271$. We can read the observed trend from the plot but cannot treat the printed equation as a reliable prediction formula.\n\n### Ratio of Synthetic to Real Data\n\n\n\n![data ratio](/content/papers/assets/ae9c03a8b8d4100f3e966671fcb1c947bcb580dddc1b866e0837fe71b76409c5.jpg)\n\n\n\nReal data generally outperforms synthetic data in training efficiency. However, due to its high cost and limited availability, synthetic data remains indispensable.\n\nThe authors fixed the amount of real data and increased synthetic data to 0.5–5 times that amount.\n\nTable 9 reports the best accuracy among the tested ratios, 96.85%, at **real:synthetic = 1:3**. Accuracy declines at four and five times the real-data amount. The authors suggest a shift toward the synthetic distribution as a possible explanation.\n\n### Necessity of Pretraining\n\n\n\n![pretrain](/content/papers/assets/8d8e109690e14fc9daf2031d9afc8361875c2768da72546fcb85b155d1cfc571.jpg)\n\n\n\nThe effectiveness of pretrained models in improving OCR performance has been a topic of debate, with inconsistent findings in previous studies.\n\nIn this paper, the authors compared models pretrained on ImageNet-21k with models trained from scratch for OCR tasks.\n\nIn Table 10, PARSeq-L with ImageNet-21k pretraining averages 96.74%, below the 97.03% scratch-trained result on the same training data. The authors report a similar observation for CLIP4STR, but this table gives no CLIP4STR figures. These results suggest that non-OCR pretraining does not necessarily help recognition under these settings.\n\nThe OCR-related training sequence shows a further gain here. PARSeq-S trained on REBU-Syn averages 96.85%, above the 96.12% result using only real REBU data. Fine-tuning the REBU-Syn-trained model on REBU real data brings the Table 10 result to 96.96%; the paper's prose instead says 97.01%.\n\nBased on these findings, the authors recommend the following best practices:\n\n1. Train the model on a comprehensive dataset containing both synthetic and real data.\n2. Fine-tune the model with real data to achieve further accuracy improvements.\n\n### Comparison with Other Models\n\n\n\n![compare](/content/papers/assets/8c5eac38a81e0259f5ab687072e45a348b6362e31287f1faf1b14adcb2abd5da.jpg)\n\n\n\nThe authors retrained **CLIP4STR** using a **3:1 ratio of synthetic to real data** and fine-tuned from task-related pretrained models.\n\nIn Table 11, the originally reported **CLIP4STR-B** result is **96.89%**, while the REBU-Syn-trained model reaches **97.25%**, a difference of **0.36 percentage points**. The rows use different training data, so we cannot attribute the difference solely to pretraining or the data ratio. **CLIP4STR-L** reaches a **97.42% sample-weighted average word accuracy** across **six common test benchmarks**, the highest average in the table.\n\n\n> [!TIP]\n> \n> When revisiting the CLIP4STR paper, we noticed discrepancies between the reported experimental results and the original paper. The numbers here may reflect the authors' own retrained results rather than those from the original publication.\n> \n> If you're unfamiliar with CLIP4STR, you can refer to our previous article:\n> \n> - [**[23.05] CLIP4STR: The Blessing of Multimodality**](/blog/papers/text-recognition/clip4str)\n\n\n## Conclusion\n\nWithin the OCR model families, data, and compute range studied, the observed error reductions can be approximated by power laws. These fits can inform resource planning, but a change in task, data quality, or model family requires fresh validation.\n\nDuring training, the authors recommend using a **1:3 ratio of real to synthetic data** for optimal performance. Additionally, they demonstrate that using **task-specific pretrained models** significantly enhances performance.\n\n\n> [!TIP]\n> \n> Do pretrained vision-language models help OCR? These experiments identify cases where non-OCR pretraining did not help under the tested settings.\n> \n> However, some classic VLMs, like CLIP, operate at a scale 20 times larger than the experiments in this paper. Can the conclusions of this paper truly represent the capabilities of such large-scale VLMs?\n> \n> Thus, the debate over whether pretraining can improve OCR performance is far from over.\n","imageSizes":{"/content/papers/assets/47233921fe81800e271c16d4da4f385b5e3a84083c7a40b11546dd2b6c765b10.jpg":{"width":948,"height":260},"/content/papers/assets/dea9efb6ceb289d29e00e1caa016ad98aec46a81108979966715939d8dc25721.jpg":{"width":968,"height":256},"/content/papers/assets/7f8bf4fb742fad31bedbe3b952d194a3bcac951a36f95169f217b752a0a8381a.jpg":{"width":968,"height":288},"/content/papers/assets/ca1b5566dbba0dac01795603c746ccc6bc8d040745fbe1b83967cbf93106a0d3.jpg":{"width":976,"height":292},"/content/papers/assets/abb8a0d211e14e2e3a3b9f402ca87064b546ea528e3e378ca541cb6a2701b536.jpg":{"width":992,"height":304},"/content/papers/assets/dccff50025be9e0c850e107de2c9ac5632d25334da1d53e4015578044ab6e174.jpg":{"width":980,"height":260},"/content/papers/assets/44e988d5368a5245004c8818817d340ae78948a2a27a5254f128a5b62ad182ac.jpg":{"width":656,"height":464},"/content/papers/assets/ae9c03a8b8d4100f3e966671fcb1c947bcb580dddc1b866e0837fe71b76409c5.jpg":{"width":480,"height":314},"/content/papers/assets/8d8e109690e14fc9daf2031d9afc8361875c2768da72546fcb85b155d1cfc571.jpg":{"width":966,"height":302},"/content/papers/assets/8c5eac38a81e0259f5ab687072e45a348b6362e31287f1faf1b14adcb2abd5da.jpg":{"width":1224,"height":880}}}
