---
title: 'UniRec40M: Unified Text & Formula Dataset'
url: https://www.emergentmind.com/topics/unirec40m
type: topic
---

# UniRec40M: Unified Text & Formula Dataset

Searching arXiv for the primary UniRec paper and closely related OCR/formula-recognition context.
UniRec40M is a large-scale training dataset introduced as the data foundation for unified recognition of text and formulas across multiple granularities, languages, and document conditions. It was established to support UniRec-0.1B, a unified recognition model with only 0.1B parameters, and is described as comprising 40 million text, formula and their mix samples [2512.21095]. More precisely, the dataset is reported as a collection of multi-level text-formula samples drawn from TeX-generated data, scene text data, handwritten data, and domain PDF data, with a tabulated raw total of 39.60M samples and a proportion-balanced sampling schedule of 12.63M samples per epoch [2512.21095]. Its role in the underlying work is not merely to enlarge OCR supervision, but to make lightweight unified recognition of plain text, mathematical formulas, and mixed text-formula content feasible at the levels of characters, words, lines, paragraphs, and document-like blocks [2512.21095].

## 1. Definition and scope

UniRec40M is presented as a large-scale dataset built specifically for lightweight unified recognition of both text and formulas [2512.21095]. The dataset is motivated by a stated deficiency in existing OCR and document-parsing resources: text-recognition corpora and formula-recognition corpora are usually separate, and most available data are limited in scale, domain coverage, or hierarchical supervision [2512.21095]. In that formulation, UniRec40M is intended to fill the gap for a single compact model that must process plain text, isolated formulas, and interleaved text-formula sequences under a unified recognition objective [2512.21095].

The corpus is explicitly characterized as multilingual and multi-level. The paper summarizes it as containing nearly 30M English samples and 10M Chinese samples, and across semantic categories it includes 19M plain text, 13M formula-only, and 8M text-formula mixed instances [2512.21095]. These counts indicate that the dataset is not restricted to scientific formula crops or standard line-level OCR. Rather, it is organized to expose a model to ordinary prose, formula syntax, and hybrid sequences in which both modalities co-occur. This suggests a training design aimed at representation sharing across modalities while preserving distinctions required for accurate decoding.

## 2. Composition and quantitative breakdown

The paper names four source families in the dataset composition: TeX-generated data, scene text data, handwritten data, and domain PDF data [2512.21095]. The detailed table reports the following raw counts, summing to 39.60M samples [2512.21095].

| Source family | Subcategory | Samples |
|---|---|---:|
| TeX-generated | English text | 9.05M |
| TeX-generated | English formula | 12.85M |
| TeX-generated | English mixed | 7.91M |
| TeX-generated | Chinese text | 6.84M |
| TeX-generated | Chinese formula | 0.05M |
| TeX-generated | Chinese mixed | 0.24M |
| Scene text | LSVT | 1.05M |
| Scene text | MTWI | 0.26M |
| Scene text | HierText | 0.15M |
| Handwritten | HWDB | 0.32M |
| Handwritten | TAL | 0.38M |
| Handwritten | Note | 0.02M |
| Domain data | IR Report | 0.08M |
| Domain data | Newspaper | 0.35M |
| Domain data | K-12 | 0.13M |

The same table also gives per-epoch sampling counts under a proportion-balanced sampling strategy, totaling 12.63M samples per epoch [2512.21095]. The text states that data are either sub-sampled or re-sampled per training epoch so that the ratios among text, formula, and mixed samples remain stable [2512.21095]. This is significant because the raw source composition is visibly imbalanced across languages and content types, particularly between English and Chinese and between formula-rich TeX data and smaller handwritten or domain-specific subsets.

The designation “40 million” is therefore a rounded summary of the overall scale, whereas the paper’s table provides the more precise raw sample total of 39.60M [2512.21095]. A plausible implication is that the dataset name functions both as a scale indicator and as a label for the training regime associated with the UniRec-0.1B system.

## 3. Data sources and construction pipeline

The first and most substantial source is an online TeX source pipeline. The authors collect arXiv TeX source files and Wikipedia HTML pages converted into TeX format, giving about 2 million TeX files [2512.21095]. For each TeX source file, every valid text or formula token is assigned a unique color by inserting LaTeX color commands, after which the files are rendered to PDF [2512.21095]. Because each token has a distinct color in the rendered output, the pipeline performs color-based alignment between the TeX source and the PDF rendering to recover labels [2512.21095]. This enables automatic generation of supervision at word level, line level, and paragraph level, obtained by parsing LaTeX grammar [2512.21095].

A second source consists of digital-born PDF documents, especially industry research reports and newspapers [2512.21095]. Using PyMuPDF, the authors extract text blocks and corresponding image regions from these PDFs [2512.21095]. The function of this source is to add multi-level, multi-domain text recognition data beyond TeX-like scientific layouts. The dataset description does not provide a more elaborate annotation mechanism for this portion, but the extraction process is explicitly identified.

A third source incorporates public datasets and handwriting resources. The integrated corpora include LSVT and MTWI for Chinese scene text, HierText for English scene text, CASIA-HWDB and TAL for handwriting, K-12 as an examination-style dataset, and handwritten notes labeled by Qwen3VL-235B-A30B and then manually refined [2512.21095]. The handwritten notes are described as a high-quality supplement [2512.21095]. In aggregate, these sources broaden the visual and domain distribution of the dataset from rendered scientific documents to scene text, offline handwriting, examination material, and document blocks.

## 4. Recognition hierarchy and annotation semantics

A central feature of UniRec40M is its support for hierarchical recognition. The associated model is intended to recognize text and formulas at the character, word, line, paragraph, and multi-paragraph / document-like level [2512.21095]. The dataset supports these levels through heterogeneous supervision paths: TeX-generated data provide word-, line-, and paragraph-level supervision; scene text primarily contributes character/word/line recognition; handwritten datasets strengthen character-level and line-level robustness; and domain PDFs provide paragraph-like and block-like samples from realistic layouts [2512.21095].

The paper does not state that every sample is annotated for every level [2512.21095]. Instead, the dataset is described as a multi-level corpus feeding a model trained for multi-level output. This distinction matters technically: UniRec40M is not presented as a uniformly annotated benchmark in the strict sense, but as a composite training resource whose supervisory granularity depends on source type.

The content taxonomy is also explicit. UniRec40M includes plain text, formula-only, mixed text-formula, scene text, handwritten text, and domain-specific document text [2512.21095]. The mixed samples are especially important because they require the recognizer to distinguish ordinary words from formula tokens within a single sequence [2512.21095]. This suggests that the dataset is structured not only around visual diversity but also around intra-sequence semantic switching.

## 5. Coupling with tokenization and hierarchical supervision

UniRec40M is tightly coupled to two training mechanisms introduced alongside UniRec-0.1B: the Semantic-Decoupled Tokenizer (SDT) and Hierarchical Supervision Training (HST) [2512.21095]. The dataset is valuable in part because it provides the content diversity needed for these mechanisms to operate meaningfully.

For SDT, the paper states that two independent tokenizers are trained: one on plain text and one on mathematical formulas [2512.21095]. Formula tokens are then merged into the text tokenizer as special tokens, except for tokens already present in the text vocabulary [2512.21095]. The motivation is to avoid shared embeddings for semantically different uses of the same strings, with problematic examples explicitly identified as `sum`, `infty`, `left`, `frac`, and `right` [2512.21095]. Since UniRec40M contains plain text, formulas, and mixed sequences at scale, it provides the empirical basis on which such semantic decoupling is expected to matter.

For HST, the paper states that hierarchical tokens are inserted into labels during dataset construction and training: `<|ln|>` for line breaks within a paragraph and `<|pn|>` for paragraph boundaries [2512.21095]. During inference, `<|ln|>` tokens are removed and `<|pn|>` tokens are converted into two newline characters [2512.21095]. UniRec40M is therefore not merely a collection of image-text pairs; it is a corpus with structure-aware label design that supports training for layout-preserving transcription.

The formal model definitions given in the paper are relevant because they clarify the representational interface through which UniRec40M is consumed. The input image is defined as
$$
\mathbf{I} \in \mathbb{R}^{H \times W \times 3},
$$
the encoder output as
$$
\mathbf{F}_{map} = \mathbf{Encoder}(\mathbf{I}) \in \mathbb{R}^{\frac{H}{32} \times \frac{W}{32} \times D}
$$
with $D = 768$, the flattened visual sequence as
$$
\mathbf{F} = \text{Flatten}(\mathbf{F}_{map}) \in \mathbb{R}^{N \times D}, \quad N = \frac{H}{32} \times \frac{W}{32},
$$
the tokenized label sequence as
$$
\mathbf{Y} = \text{SDT}(Label) = \{<BOS>, y_0, y_1, \ldots, y_{l-1}, y_l\}
$$
where $y_l = <EOS>$, and the training loss as
$$
\mathcal{L}_{CE} = - \sum_{t=0}^{l} \log P(y_t \mid y_{0:t-1}, \mathbf{F}).
$$
These definitions situate UniRec40M within a sequence-generation training framework rather than a conventional lexicon-constrained OCR pipeline [2512.21095].

## 6. Empirical role, availability, and limitations

The paper does not provide a direct ablation that removes UniRec40M entirely, because the dataset is the training foundation of the reported model [2512.21095]. Its importance is instead argued indirectly through downstream performance and through ablations of HST and SDT. The dataset-related evidence emphasized in the text includes formula recognition gains and domain robustness: UniRec-0.1B outperforms Mathpix, Pix2Tex, and UniMERNet-B on formula recognition on UniRec-Bench; improves formula recognition by 23.1% against Dolphin-1.5; beats PaddleOCR-VL by 2.7% on the Exam Paper domain; and performs best on handwritten Note and noisy Newspaper domains [2512.21095]. The paper attributes these outcomes partly to the rich and diverse formula recognition data in UniRec40M, to SDT plus the high-quality mixed text/formula training data, and to the inclusion of exam-related, handwritten, and noisy domain samples in the dataset [2512.21095].

The ablation results further indicate that the training corpus is sufficiently rich to support the proposed supervisory strategies. HST improves edit distance by 1.2% on text, 1.0% on formulas, and 1.5% on mixed content, and improves multi-level text recognition across five levels by 0.5%, 0.8%, 0.4%, 1.7%, and 1.2%, with especially strong gains at paragraph and multi-paragraph levels [2512.21095]. SDT gives 1.2% improvement on text, 11.1% on formulas, and 1.8% on mixed content [2512.21095]. These are model-level outcomes, but they depend on the dataset containing sufficient mixed and multi-level supervision.

The dataset’s availability is stated through the project repository at `https://github.com/Topdu/OpenOCR`, where the codebase and dataset are said to be available [2512.21095]. By contrast, the text shown does not provide a formal train/validation/test split for UniRec40M itself, nor does it state a dataset license [2512.21095]. One explicit limitation is also identified: some subscript/superscript cases are misrepresented because the PyMuPDF extraction collapses them into plain text, and the model may therefore predict these outside mathematical contexts as plain text [2512.21095]. This is not presented as a global defect of the dataset, but it is a concrete example of annotation-noise mismatch arising from one acquisition pipeline.

In summary, UniRec40M is best understood as a deliberately constructed multi-source, multi-level, multilingual training corpus for unified text-and-formula recognition. Its distinctive properties are the scale of its mixed supervision, the integration of TeX-derived scientific content with scene text, handwriting, and domain PDFs, and its direct alignment with structure-aware labeling and semantic-decoupled tokenization in UniRec-0.1B [2512.21095].

Source: https://www.emergentmind.com/topics/unirec40m