Traditional image-to-markup models—such as those used to digitize handwritten LaTeX or chemical formulas—typically treat their output as a linear string of characters. While effective for simple expressions, this approach often loses the underlying hierarchical structure of the data. To address this, researchers have introduced a tree-structured decoder that generates parent-child node pairs directly. This method significantly improves accuracy and generalization, particularly on complex mathematical and chemical formulas.
The Limitations of String Decoders
When converting an image of a math formula (e.g., $x + \frac{1}{y}$) into LaTeX, most AI models rely on a "string decoder." They treat the markup as a one-dimensional sequence of characters. However, formulas and chemical structures are inherently hierarchical; they are trees, not lines.
The authors identify a critical flaw in string decoders: they rely on implicit language modeling to "guess" the structure. As formulas become more complex or include nested structures not seen during training, string decoders often collapse. For example, if a model learns to place an exponent after a variable in a simple case, it might fail to find the correct "parent" node in a deeply nested fraction. In a serialized string, the gap between a parent node and its child can become so large that the model loses the connection entirely.
A Tree-Structured Decoding Method
To overcome the long-range dependency problem, the authors propose a Tree-Structured Decoder that treats hierarchical data as actual trees. Instead of predicting one character at a time sequentially, the model predicts a sequence of sub-trees, where each sub-tree consists of a parent node and a child node pair.
The architecture uses a standard DenseNet as the visual encoder, making the decoder the primary point of novelty. Key innovations include:
- Parent-Child Decoding: At each step, the model first identifies a "parent" from a pool of previously generated nodes and then generates its corresponding "child."
- Memory-Based Attention: To find the correct parent, the model utilizes a memory module that stores all previously generated child nodes. It uses its current state to query this memory and select the most likely parent for the next operation.
- Attention Self-Regularization: Because a parent at step $t$ was generated as a child at some previous step $t'$, their visual attention maps should logically align. The authors use Kullback-Leibler (KL) divergence to force the model’s visual attention to remain consistent across these steps.
- Hierarchical Beam Search: During inference, the model employs a specialized beam search that simultaneously considers the top-$N$ parent candidates and top-$M$ child candidates to find the most probable overall tree structure.
Datasets and Generalization Insights
The model was evaluated across three distinct types of data: standard handwritten math benchmarks (CROHME 2014, 2016, 2019), a large-scale dataset of printed chemical structures mapped to SMILES strings, and specialized "Toy Math Problems."
The toy datasets featured synthetic math formulas with increasing "structural complexity" (branching factor and depth) to test how well models handle unseen, complex layouts.
A key insight emerged from these structural tests: string decoders achieved nearly 0% accuracy on complex structures if they were only trained on simple ones. By contrast, the tree decoder generalized remarkably well. Because it understands the fundamental rules of tree construction rather than just memorizing character sequences, it successfully eliminates the long-range dependency problem that plagues string-based models.
Key Results
The tree-structured decoder (referred to as DenseWAP-TD) consistently outperformed state-of-the-art string decoders across multiple benchmarks:
- CROHME 2014: Improved the Expression Recognition Rate (ExpRate) from 43.0% to 49.1%.
- CROHME 2019: Achieved a significant jump from 41.7% to 51.4%.
- Chemical Formulas (SMILES): On the "Massive" test set containing the most complex chemical formulas, the tree decoder outperformed the string decoder by 6.2% (34.4% vs. 28.2%).
Additionally, ablation studies confirmed that removing the "Attention Self-Regularization" caused a significant drop in performance, proving that aligning the parent and child visual context is vital for structural accuracy.
Limitations and Future Work
While highly effective, the paper notes a few areas for further exploration. First, the hierarchical beam search evaluates multiple parent and child hypotheses per step, making it more computationally expensive than standard linear beam search. Second, the current implementation is tailored specifically for math and chemistry. Adapting it to highly irregular structures, such as general scene graphs, may require further architectural tweaking. Finally, while the model handles basic relations like superscripts and subscripts, more complex edge attributes in non-mathematical trees remain an open area for future research.
Summary updated