Introduction
Handwritten Mathematical Expression Recognition (HMER) presents a unique challenge compared to standard text recognition. While text is typically a one-dimensional sequence, mathematical notation is inherently two-dimensional, featuring complex spatial hierarchies such as superscripts, subscripts, fractions, and nested radicals. Current state-of-the-art models often employ an "image-to-sequence" approach, treating HMER as a translation task from pixels to LaTeX strings. However, these models frequently suffer from "structural drift," where the model loses track of a symbol's position within a complex hierarchy. This is exacerbated by "ghost symbols"—structural LaTeX tokens like { or ^ that have no visual counterpart in the image, causing attention mechanisms to misalign.
Methodology
The authors introduce PosFormer, a transformer-based architecture designed to explicitly model the 2D geometry of mathematical expressions. The system consists of a DenseNet-based visual encoder and a multi-head decoder enhanced with two key innovations: Position Forest (PF) and Implicit Attention Correction (IAC).
Position Forest (PF)
The core innovation of PosFormer is the Position Forest. During training, the model is supervised not only on the LaTeX sequence but also on a "position identifier" for every symbol. A mathematical expression is represented as a forest of trees, where each symbol is assigned a string (e.g., "MLLR") describing its path in the spatial hierarchy: Middle, Left (upper), or Right (lower).
This explicit spatial supervision forces the encoder to learn position-aware features. Crucially, the position head is an auxiliary task used only during training; it is discarded during inference, providing a performance boost without any additional computational cost.
Implicit Attention Correction (IAC)
Standard HMER models use coverage attention to prevent redundant focus. However, structural LaTeX tokens (like brackets) do not exist visually. When a model "spends" attention on these non-existent symbols, the alignment for subsequent real symbols drifts. IAC identifies these "ghost" symbols and resets their attention weights to zero, maintaining precise alignment throughout the decoding process.
Experimental Evaluation
PosFormer was evaluated across several benchmarks, including the standard CROHME (2014/2016/2019) datasets, the multi-line $M^2E$ dataset, and the large-scale HME100k. To specifically test handling of deep nesting, the authors introduced the Multi-level Nested Expression (MNE) benchmark.
Key Results
- State-of-the-Art Performance: PosFormer achieved an ExpRate of 64.97% on CROHME 2019, a 2.00% improvement over previous benchmarks.
- Robustness to Nesting: On the MNE dataset, PosFormer showed an average gain of 4.62%. The performance gap widened as the nesting level increased, validating the effectiveness of the Position Forest.
- Efficiency: The model maintains a competitive parameter count (~6.4M) and inference speed, demonstrating that structural awareness does not require excessive overhead.
Conclusion
PosFormer demonstrates that while Transformers are powerful sequence learners, they benefit significantly from explicit 2D structural guidance. By incorporating Position Forest coding and Implicit Attention Correction, the model effectively bridges the gap between visual features and complex mathematical syntax. Future work may involve integrating pre-trained language models to further refine LaTeX output through linguistic context.
Summary updated