UniMERNet: A Universal Network for Real-World Mathematical Expression Recognition

Bin Wang, Zhuangcheng Gu, Chao Xu, Bo Zhang, Botian Shi, Conghui He

TL;DR

This paper introduces UniMER, a new large-scale dataset and benchmark for Mathematical Expression Recognition (MER) that specifically targets complex, real-world scenarios. They also propose UniMERNet, a novel neural network architecture that achieves state-of-the-art accuracy and improved inference speed for MER tasks.

What Problem Does This Paper Address?

Mathematical Expression Recognition (MER) is crucial for converting images of mathematical formulas into machine-readable formats like LaTeX. However, existing MER datasets and models often struggle with the complexity and diversity of real-world mathematical expressions found in scanned documents, screenshots, and varied writing styles. These challenges include handling long, multi-line equations, dealing with noisy or distorted images, and recognizing subtle visual similarities between symbols. Current benchmarks are often limited to simple printed or handwritten formulas, leading to models that don't generalize well to practical applications.

Methods

The authors propose UniMERNet, a novel MER network built upon the Swin-Transformer encoder and mBART decoder architecture. Key innovations include:

  • UniMERNet-Encoder:
    • Fine-Grained Embedding (FGE): Replaces standard patch embedding with an overlapping convolutional module to better capture local features and prevent fragmentation of characters in formulas.
  • Convolutional Enhancement (CE): Integrates depthwise convolutions and GELU activation to improve the model's ability to discern local details like superscripts and subscripts, complementing the global context captured by transformers.
  • Removal of Shift Window (RSW): Eliminates the shift window operation, which becomes redundant with FGE and CE, to improve performance and speed.
  • UniMERNet-Decoder:
    • Squeeze Attention (SA): A module inspired by ResNet's bottleneck design that compresses query and key representations in a lower-dimensional space to accelerate the attention computation, addressing the throughput bottleneck in the language model.

The model also utilizes image augmentation techniques to improve robustness against noise and distortions.

Datasets

  • UniMER-1M: A newly created large-scale training dataset containing over 1 million diverse formula image-LaTeX pairs. It includes simple and complex printed, as well as handwritten formulas, aiming for unprecedented scale and diversity.
  • UniMER-Test: A comprehensive evaluation dataset with 23,789 samples, designed to cover various real-world scenarios. It comprises four categories:
  • SPE (Simple Printed Expressions): Basic LaTeX expressions.
  • CPE (Complex Printed Expressions): Longer, multi-line LaTeX expressions.
  • SCE (Screen-Captured Expressions): Formulas from documents and web pages, often with inconsistent fonts, sizes, and background noise.
  • HWE (Handwritten Expressions): Formulas collected from existing handwriting recognition datasets, known for their complexity and varying backgrounds.

The paper also references and builds upon existing datasets like Pix2tex, IM2LATEX-100K, and CROHME.

Key Insights and Ideas

  • Dataset Scale Matters: Training on a massive, diverse dataset like UniMER-1M is crucial for developing a generalizable MER model that performs well across various formula types and complexities, significantly outperforming models trained on smaller, less diverse datasets.
  • Local and Global Context is Key: Effectively recognizing mathematical expressions requires a balance between understanding the global structure of an equation and the fine-grained local relationships between symbols (e.g., superscripts, subscripts). UniMERNet's encoder design explicitly addresses this.
  • Efficiency is Critical for Real-World Use: For complex formulas, inference speed is a major bottleneck. The UniMERNet decoder's Squeeze Attention mechanism demonstrates that optimizing the language model's processing can lead to significant speedups without substantial accuracy loss.
  • Real-World Data is Diverse and Noisy: The SCE and HWE subsets of UniMER-Test highlight the challenges posed by real-world data, such as inconsistent rendering, background noise, and image distortions, which standard MER models often fail to handle.

Key Results

  • UniMERNet, trained on UniMER-1M, achieves state-of-the-art performance on the UniMER-Test benchmark, significantly outperforming existing methods across SPE, CPE, SCE, and HWE subsets.
  • For example, on the CPE subset, UniMERNet-B shows a BLEU score improvement of 0.201 and a decrease in Edit Distance from 0.225 to 0.056 compared to models trained on Pix2tex & HWE.
  • The proposed UniMERNet architecture achieves a notable speedup. UniMERNet-T, a lighter version, is 1.73 times faster than the previous SOTA model Texify, while UniMERNet-B offers a 23% speed improvement over the baseline.
  • Ablation studies confirm the effectiveness of individual components: FGE and CE modules improve accuracy, while SA and RSW contribute to speed and overall performance.
  • Data augmentation techniques significantly boost performance, particularly on the SCE subset, improving BLEU scores by up to 2.5%.

Limitations and Future Work

  • Pre-training Limitations: While pre-training on large text-image datasets like Arxiv papers improves performance, it primarily benefits printed text recognition. Future work could explore more diverse pre-training data to further enhance handwritten formula recognition.
  • Model Integration: The authors plan to explore integrating UniMERNet with large vision-language models to improve the recognition of documents containing text, formulas, and tables, aiming for more comprehensive document understanding.
  • Dataset Expansion: Future work will involve investigating the use of larger and more diverse pre-training data to further enhance formula recognition capabilities.

Summary updated

Abstract

This paper presents the UniMER dataset to provide the first study on Mathematical Expression Recognition (MER) towards complex real-world scenarios. The UniMER dataset consists of a large-scale training set UniMER-1M offering an unprecedented scale and diversity with one million training instances and a meticulously designed test set UniMER-Test that reflects a diverse range of formula distributions prevalent in real-world scenarios. Therefore, the UniMER dataset enables the training of a robust and high-accuracy MER model and comprehensive evaluation of model performance. Moreover, we introduce the Universal Mathematical Expression Recognition Network (UniMERNet), an innovative framework designed to enhance MER in practical scenarios. UniMERNet incorporates a Length-Aware Module to process formulas of varied lengths efficiently, thereby enabling the model to handle complex mathematical expressions with greater accuracy. In addition, UniMERNet employs our UniMER-1M data and image augmentation techniques to improve the model's robustness under different noise conditions. Our extensive experiments demonstrate that UniMERNet outperforms existing MER models, setting a new benchmark in various scenarios and ensuring superior recognition quality in real-world applications. The dataset and model are available at https://github.com/opendatalab/UniMERNet.
BibTeX
@misc{wang2024unimernet,
  author = {Bin Wang and Zhuangcheng Gu and Chao Xu and Bo Zhang and Botian Shi and Conghui He},
  title = {{UniMERNet: A Universal Network for Real-World Mathematical Expression Recognition}},
  year = {2024},
  eprint = {2404.15254},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2404.15254},
}
Figure