Syntax-Aware Network for Handwritten Mathematical Expression Recognition

Ye Yuan, Xiao Liu, Wondimu Dikubab, Hui Liu, Zhilong Ji, Zhongqin Wu, Xiang Bai

TL;DR

The Syntax-Aware Network (SAN) transforms handwritten mathematical expression recognition by replacing traditional character-by-character sequential prediction with a grammar-driven tree parsing approach. By incorporating spatial syntax rules directly into an encoder-decoder model, SAN drastically reduces structural errors while delivering a 3.5x inference speedup over previous tree-based methods.

What Problem Does This Paper Address?

Handwritten Mathematical Expression Recognition (HMER) is significantly more complex than standard optical character recognition (OCR). While text lines flow linearly (1D), mathematical expressions are inherently two-dimensional, featuring complex spatial structures like fractions, superscripts, subscripts, and matrices.

Most modern HMER systems use standard encoder-decoder networks that predict LaTeX tokens sequentially—"from one character to another." Because these models lack an explicit understanding of 2D syntax, they frequently suffer from structural prediction errors, such as completely missing the denominator of a fraction or misaligning exponents, especially when dealing with messy handwriting.

Comparison of architectures

Methods

The authors introduce SAN (Syntax-Aware Network), which treats mathematical expression recognition as a tree-parsing process rather than a string-generation process.

  1. Grammar Rules & Tree Parsing: The authors define a set of production rules that convert LaTeX markup into a syntax tree based on standard reading orders (left-to-right, top-to-bottom) and seven spatial relations (e.g., above, below, right, inside). The network uses a stack-based decoder to traverse this tree.
  2. Encoder: A standard Fully Convolutional Network (DenseNet) extracts visual features from the input image.
  3. Syntax-Aware Decoder: The decoder features two Gated Recurrent Units (GRU-$\alpha$ and GRU-$\beta$) working alongside a novel attention mechanism.
  4. Path-based Attention: Traditional attention mechanisms use a "coverage vector" that sums up all past attention steps, which often introduces noise and causes "attention drift" (e.g., getting confused between a numerator and denominator). SAN solves this by only summing attention weights along the direct path from the root of the parse tree to the current node.
  5. Attention Self-Regularization: During training, an auxiliary reversed decoder predicts the parent node from a child node. The model uses Kullback-Leibler (KL) divergence to regularize the forward and backward attention weights, ensuring alignment. This reversed decoder is discarded during inference to maintain high speed.

Datasets

The model was evaluated on two types of datasets:

  • CROHME (2014, 2016, 2019): The standard public benchmarks for online handwritten mathematical expressions, converted to images for offline recognition.
  • HME100K: A massive new dataset introduced by the authors to mimic real-world conditions. It contains 100,000 images collected from 10,000 distinct writers via camera captures. It features realistic distortions like blur, complex backgrounds, illumination variations, and expressions nearly twice as long as those in CROHME.

Key Insights and Ideas

  • Component-to-Component over Character-to-Character: By forcing the network to predict structural components (sub-trees) rather than individual characters, the model inherently respects mathematical syntax.
  • Mitigating Attention Drift via Tree Paths: The realization that accumulating all past attention history hurts performance in 2D structures is key. Restricting attention history to the active branch of the syntax tree keeps the model visually focused on the correct region.
  • Efficiency Gains: Tree decoders are often criticized for being computationally heavy. However, because SAN parses entire components sequentially rather than evaluating individual parent-child node pairs in isolation, it minimizes computational overhead.
Figure 2. Sample Recognition Results of SAN and DWAP-TD. The SAN heatmaps indicate the model is focused on different components. The characters in red refer to the lost component during the prediction.

Key Results

  • State-of-the-Art Accuracy: Without data augmentation, SAN achieved an expression recognition rate (ExpRate) of 56.2% on CROHME 2014 and 53.6% on CROHME 2016, outperforming top models like BTTR and MAN. With data augmentation, performance reached 63.1% and 61.5% respectively.
  • Robustness on Complex Data: On the challenging HME100K dataset, SAN outperformed the robust Transformer-based BTTR by 3.0% overall, with the gap widening to 5.5% on the "Hard" subset (complex/long expressions).
  • High Inference Speed: SAN achieved an inference speed of 23.9 Frames Per Second (FPS) on an Nvidia Tesla V100. This makes it 3.5x faster than the previous tree-structured state-of-the-art decoder (DWAP-TD).

Limitations and Future Work

The authors note that SAN can still fail when strokes are highly distorted or physically touch ("sticking components"), which leads to under- or over-translation of the symbols.

Moving forward, the researchers plan to extend this syntax-aware framework to other complex, non-linear structural recognition tasks, such as chemical formula recognition or document layout analysis.

Summary updated

BibTeX
@misc{yuan2022syntax,
  author = {Ye Yuan and Xiao Liu and Wondimu Dikubab and Hui Liu and Zhilong Ji and Zhongqin Wu and Xiang Bai},
  title = {{Syntax-Aware Network for Handwritten Mathematical Expression Recognition}},
  year = {2022},
  eprint = {2203.01601},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2203.01601},
}
Figure