TL;DR
UniMERNet introduces a highly efficient and accurate framework for Mathematical Expression Recognition (MER) by utilizing a novel Raster-Scan Attention mechanism that mirrors human reading habits. Paired with a newly curated million-scale dataset (UniMER-1M), it achieves state-of-the-art accuracy across diverse real-world scenarios while delivering a 5× inference speedup and a 10× reduction in inference memory compared to global attention models.
What Problem Does This Paper Address?
Parsing mathematical formulas from images into markup languages like LaTeX or Markdown—known as Mathematical Expression Recognition (MER)—is vital for digitizing scientific literature and training large language models (LLMs). However, current solutions fall into two flawed camps:
- Specialist open-source models are typically trained on small, uniform datasets. They overfit easily and fail when confronted with complex, multi-line, or real-world noisy formulas.
- General Multimodal Large Models (MLMs) like GPT-4o or Qwen2.5-VL possess strong generalization but are computationally massive, require multi-GPU setups, and often lack the fine-grained precision needed for intricate mathematical syntax.
Furthermore, standard Transformer-based vision encoders rely on global self-attention, which suffers from a quadratic computational complexity of $\mathcal{O}(NH^2W^2D)$ relative to image dimensions. This makes processing high-resolution formula images prohibitively expensive.
Methods
The authors introduce UniMERNet, featuring a dual-stream encoder-decoder architecture optimized specifically for the spatial characteristics of text and formulas.
Raster-Scan (R-S) Attention
The core innovation is the Raster-Scan Attention mechanism, which replaces expensive global attention. By observing how transformers naturally process formulas, the authors designed a sequential "horizontal-first, vertical-second" attention computation:
- Row-wise Attention: Captures horizontal dependencies (character sequences within a line) with a complexity of $\mathcal{O}(NHWD^2)$.
- Column-wise Attention: Transposes the representations to capture vertical relationships (cross-row structures like fractions or matrices) with a complexity of $\mathcal{O}(NHWDH)$.
This factorization drops the overall computational complexity from quadratic to linear: $\mathcal{O}(NHWD(H + W))$, making high-resolution processing highly viable.
Vision Encoder & Decoder
The vision encoder uses a hierarchical structure with a fine-grained embedding layer and a four-stage backbone. It alternates between Window Attention and the new R-S Attention to balance local and global context. Additionally, a ConvEnhance module (depth-wise convolution + GELU) is placed before attention blocks to boost local feature perception. The decoder is based on a standard 8-layer mBART architecture.
Datasets
To address the lack of diverse training data, the authors constructed the UniMER dataset:
- UniMER-1M (Training): A massive dataset containing 1,061,791 LaTeX-image pairs. It uses a stratified sampling strategy to ensure a balanced representation of both short and extremely long, complex formulas.
- UniMER-Test (Evaluation): A benchmark of 23,757 meticulously curated samples divided into four real-world categories:
- Simple Printed Expressions (SPE)
- Complex Printed Expressions (CPE)
- Screen Captured Expressions (SCE)
- Handwritten Expressions (HWE)
Key Insights and Ideas
- The "Aha!" Attention Pattern: By analyzing the cross-modal attention maps of baseline decoders, the authors discovered that the model naturally learns a "raster-scan" pattern (left-to-right, top-to-bottom), even correctly shifting attention to the start of a new line during line breaks.
- Exploiting Inductive Bias: Because mathematical text inherently flows sequentially, global self-attention is largely redundant. Designing an attention mechanism that explicitly enforces this horizontal-then-vertical inductive bias yields better alignment with the task structure while shedding massive computational weight.
Key Results
UniMERNet achieves a new state-of-the-art balance between speed and accuracy:
- Performance vs. Specialists: On the challenging Complex Printed Expressions (CPE) subset, UniMERNet outperforms the baseline Texify model by 26.6% in Character Distance Match (CDM) score.
- Performance vs. MLMs: Despite having two orders of magnitude fewer parameters, UniMERNet beats massive models like GPT-4o and InternVL2.5 on formula recognition accuracy.
- Efficiency Gains: Compared to global attention baselines, R-S Attention delivers a 5× inference speedup, a 10× reduction in inference memory, and a 1.2× memory saving during training.
- Real-Time Deployment: UniMERNet runs at 10.48 FPS on a single GPU, whereas large multimodal models require distributed inference across multiple GPUs to function effectively.
Limitations and Future Work
The primary limitation of UniMERNet is its reliance on the standard left-to-right, top-to-bottom reading order assumption. The model struggles with highly non-linear layouts, such as commutative diagrams or complex geometric mathematical graphs.
Moving forward, the authors plan to adapt this linear-complexity attention paradigm to broader document-parsing tasks, such as table structure recognition and complex multi-element document layouts.
Summary updated