TL;DR
Teaching a computer to read handwritten math is notoriously tricky because everyone’s handwriting is messy, and a cursive r can look identical to a v. DeMER solves this by treating handwritten characters not as fixed points, but as probability distributions—separating a symbol's "platonic ideal" (prototype) from its messy handwriting (style)—while also refining where the model looks. The result is a new state-of-the-art in handwritten mathematical expression recognition (HMER) that is both more accurate and more structurally robust.
What Problem Does This Paper Address?
Handwritten mathematical expression recognition (HMER) aims to turn 2D images of handwritten equations into 1D LaTeX code. Modern systems use attention-based encoder-decoder architectures, which scan the image and output LaTeX tokens one by one.
However, they hit two major roadblocks in the real world:
- Visual ambiguity: Real handwriting has huge intra-class variance (two people write r very differently) and low inter-class variance (a sloppy r looks just like a v, or q like g). Standard models extract deterministic features, which mash together the character's core identity and its stylistic quirks, leading to misclassifications.
- Attention drift: When decoding long or nested equations, the model's attention mechanism can lose track of what it has already read, leading to over-parsing (reading the same symbol twice) or under-parsing (skipping symbols).
Methods
DeMER builds on a standard backbone—a DenseNet visual encoder with 2D sinusoidal positional encoding and a Transformer decoder—and introduces three key upgrades:
- Implicit Variational Prototype Module (IVPM): Instead of mapping a character feature to a single point, IVPM models it as a Gaussian distribution. The mean ($\mu$) represents the canonical prototype, while the standard deviation ($\sigma$) captures stylistic uncertainty. During training, the model samples from this distribution (adding noise proportional to $\sigma$) and uses multi-head attention to align these noisy features with a set of learnable, standardized prototypes. Crucially, this happens implicitly—driven purely by the end-to-end cross-entropy loss, without needing explicit KL-divergence or contrastive losses.
- Soft Redundancy Aware Coverage (Soft-RAC): To fix attention drift, Soft-RAC explicitly computes the spatial overlap between the current attention map and the cumulative historical attention. Instead of hard-suppressing overlapping regions (which can chop off character edges), it uses a learnable $1\times1$ conv + sigmoid gate to softly filter out redundant focus at character centers while preserving stroke edges.
- Fusion Module: A learnable gating mechanism blends the original spatial-preserving features from Soft-RAC with the denoised prototype features from IVPM. This lets the model rely on clean prototypes for ambiguous characters, while keeping raw spatial cues when stroke transitions matter.
Datasets
The authors evaluate DeMER on three standard benchmarks (without data augmentation for fair comparison):
- CROHME (2014, 2016, 2019): The classic benchmark with 8,836 training expressions across 111 symbol classes, and 986 / 1,147 / 1,199 test samples respectively.
- HME100K: A large-scale, real-world dataset of camera-captured images (74,502 train, 24,607 test, 249 symbol classes) featuring complex backgrounds, blur, and lighting variations.
- MNE (Multi-level Nested mathematical Expression): A specialized stress-test dataset that groups expressions by nesting depth into N1, N2, and N3 (with N3 containing 1,464 complex, deeply nested samples).
Key Insights and Ideas
- Uncertainty as a feature, not a bug: By letting the model predict a variance $\sigma$, it naturally learns to assign higher variance to messy, cursive handwriting and lower variance to neat handwriting. For example, the average $L_2$-norm of $\sigma$ for cursive o is 0.7293, compared to 0.1629 for neat o.
- Plug-and-play versatility: Because IVPM operates directly on visual features before decoding, it isn't tied to Transformers. Plugging it into older RNN-based models (DWAP and ABM) yields immediate, substantial accuracy boosts.
- Clean separation in feature space: t-SNE visualizations confirm that while baseline models (like CoMER) have overlapping, messy feature clusters for confusable symbols, DeMER forms tight, distinct, and well-separated clusters.
Key Results
- CROHME: DeMER sets new state-of-the-art Expression Recognition Rates (ExpRate) of 61.63% (2014), 60.63% (2016), and 62.12% (2019)—beating the CoMER baseline by +3.17%, +2.66%, and +2.91%, respectively, and outperforming recent Transformer models like PosFormer and TAMER.
- HME100K: Achieves a new SOTA ExpRate of 69.82% (+1.75% over CoMER).
- MNE: Outperforms all competitors on N1 (61.32%) and N2 (39.58%). On the deeply nested N3 subset, it beats CoMER by +8.63% (32.67% vs 24.04%), though it trails tree-based models like TAMER (35.41%) that are explicitly designed for deep nesting.
- RNN Extensibility: Adding IVPM to DWAP boosts ExpRate by +7.63% (CROHME 2014) and +9.71% (CROHME 2016). Adding it to ABM yields gains of +1.87% to +2.39%.
Limitations and Future Work
The authors note that drawing a hard line between "stylistic noise" and "subtle structural ligatures" remains tricky. In exceptionally dense formulas, aggressive feature standardization can occasionally smooth out rare, fine-grained stroke connections that actually carry structural meaning. Future work will explore adaptive mechanisms to better balance feature standardization with local context preservation.
Summary updated