Introduction
Handwritten Mathematical Expression Recognition (HMER) presents a unique challenge in computer vision because mathematical notation is inherently non-linear. Unlike standard text, formulas like $x^2 - y$ utilize a two-dimensional spatial structure involving superscripts, subscripts, and fractions. Traditional HMER models often attempt to flatten these structures into linear LaTeX strings, a process that frequently loses critical hierarchical information and struggles with deeply nested expressions.
Earlier tree-structured decoders attempted to address this by modeling the hierarchy directly. However, these models were often limited by rigid branch ordering during training and the need for complex auxiliary modules to track parent-child relationships. This paper introduces TDv2, a refined tree-structured decoder designed to overcome these limitations through flexible structure learning and an intuitive attention mechanism.
Methodology
System Architecture
The TDv2 framework employs an encoder-decoder architecture. A DenseNet encoder first extracts high-level spatial features from the input image. These features are then passed to a dual-module decoder consisting of:
- Node Classification Module: Responsible for identifying the specific mathematical symbol (e.g., 'x', '-', '2').
- Branch Prediction Module: Predicts the spatial relationships (branches) originating from the current node, such as superscripts or right-side continuations.
Diverse Tree Structure Labels and "Thinking" Steps
A key innovation in TDv2 is the use of diverse tree structure labels. By randomly shuffling the order in which branches are processed during training, the model is forced to learn the underlying structural logic rather than a fixed sequence of operations. This acts as a form of structural data augmentation, preventing the model from becoming over-reliant on typical writing patterns.
Additionally, the authors introduce a "thinking" label to improve the attention mechanism. In complex expressions, child nodes may be spatially distant from their parents. The "thinking" step allows the attention mechanism to first focus on the intermediate region between nodes, effectively "preparing" the model to accurately locate the child node in the subsequent step.
Inference via Stack-based Decoding
During inference, TDv2 utilizes a stack-based approach to manage the tree construction. This simplifies the process compared to previous iterations by removing the need for dedicated parent-finding modules. The model iteratively predicts a node and its associated branches, pushing new branches onto a stack to be processed in turn.
Experimental Results
TDv2 was evaluated on the standard CROHME 2014, 2016, and 2019 datasets. The model achieved state-of-the-art (SOTA) performance, reaching an Expression Recognition Rate (ExpRate) of 53.62% on CROHME 2014 and 58.72% on CROHME 2019.
Beyond raw accuracy, TDv2 demonstrated superior generalization capabilities. When trained on expressions with a maximum nesting depth of 4 and tested on those with a depth of 11 or more, TDv2 significantly outperformed its predecessors. This suggests that the model successfully learns the structural grammar of mathematics rather than merely memorizing common patterns.
Conclusion
TDv2 represents a significant advancement in HMER by treating mathematical expressions as flexible hierarchical trees. By decoupling node classification from branch prediction and introducing structural randomization, the model achieves both high accuracy and robust generalization. Future work may extend this tree-based approach to online recognition and other structured domains like chemical formulas or flowcharts.
Summary updated