TDv2: A Novel Tree-Structured Decoder for Offline Mathematical Expression Recognition

Changjie Wu, Jun Du, Yunqing Li, Jianshu Zhang, Chen Yang, Bo Ren, Yiqing Hu

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:

  1. Node Classification Module: Responsible for identifying the specific mathematical symbol (e.g., 'x', '-', '2').
  2. Branch Prediction Module: Predicts the spatial relationships (branches) originating from the current node, such as superscripts or right-side continuations.
Overview of the TDv2 framework, illustrating the pipeline from image input to tree-structured output via node and branch prediction.

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.

The step-by-step decoding process for the expression $x^2 - y$, showing how the model identifies parents, relations, and symbols to build the final tree.

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

BibTeX
@inproceedings{wu2022tdv,
  author = {Changjie Wu and Jun Du and Yunqing Li and Jianshu Zhang and Chen Yang and Bo Ren and Yiqing Hu},
  title = {{TDv2: A Novel Tree-Structured Decoder for Offline Mathematical Expression Recognition}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2022},
  doi = {10.1609/aaai.v36i3.20172},
}
Figure