In scene text recognition (STR) and handwritten mathematical expression recognition (HMER), models must solve two problems simultaneously: where to look in an image and what character is present at that location. Modern architectures typically use an encoder-decoder structure with an attention mechanism to bridge these tasks. However, as sequences grow longer or images become more distorted, these models often suffer from a catastrophic failure mode known as attention drift.
The Mechanics of Attention Drift
Attention drift occurs when the spatial focus of the decoder becomes decoupled from the actual physical location of the characters. In a standard sequence-to-sequence model, the attention mechanism dynamically weights spatial regions of a feature map to predict characters one by one. Zhanzhan Cheng and colleagues in Focusing Attention identified that this mechanism is highly sensitive to noise, low resolution, and irregular typography.
When the model's focus shifts even slightly away from the character center, it begins to extract features from background noise or neighboring characters. This leads to three primary error types:
- Omissions: The model skips a character because the attention "jumps" too far forward.
- Repetitions: The attention gets "stuck" on a single coordinate, causing the model to output the same character indefinitely—a phenomenon Dongzhan Zhou calls the "repetition loop" in LOCR.
- Substitutions: The model looks at the gap between characters, confusing the visual features of adjacent glyphs.
The Feedback Loop of Failure
The reason attention drift is so damaging is that most decoders are autoregressive: the "where" of the next step depends on the "what" of the previous step. Tianwei Wang and Lianwen Jin argue in the Decoupled Attention Network (DAN) that this coupling creates a recursive error trap.
If the model misidentifies a character, the hidden state used to calculate the next attention map is corrupted. This causes the next attention map to be spatially misaligned, which in turn makes the next character prediction even more likely to be wrong. In long-form text or complex handwritten formulas, a single mistake at the start of a sequence can cause the entire remaining transcription to collapse.
Decoupling Where from What
To break this cycle, researchers have moved toward decoupling the alignment process from the decoding history. The Decoupled Attention Network replaces the history-dependent attention with a standalone convolutional module that generates a set of attention maps based purely on visual features. By identifying all character locations upfront, the model prevents recognition errors from spiraling into alignment failures.
Similarly, Zhaoyi Wan and Xiang Bai proposed TextScanner, which treats reading as a sequential scanning process. By separating character classification from geometry (position and order) into parallel branches, the model maintains a more robust "sense of place" even when the text is curved or distorted.
Anchoring Attention with Spatial Grounding
Another strategy to combat drift is to provide the model with explicit "spatial anchors." Since character-level bounding boxes are expensive to label, researchers use auxiliary tasks to teach the model the underlying structure of text:
- Implicit Glyph Attention: Tongkun Guan introduced SIGA, which uses self-supervised text segmentation to force the attention mechanism to overlap precisely with the "glyphs" (the physical shapes of characters).
- Counting as Supervision: In Counting-Aware Network (CAN), Bohan Li and colleagues added a module that predicts the total number of symbols in an image. This global constraint prevents the model from omitting or repeating symbols because the "count" must match the sequence length.
- Position Forests: For non-linear structures like mathematical expressions, PosFormer models the 2D spatial relationships as a "position forest," providing the decoder with a map of nested structures (like exponents and fractions) to prevent it from losing its way in 2D space.
From Sequences to Linked Lists
The most recent evolution in this field addresses the "length-insensitivity" problem. Standard attention mechanisms often struggle with very long strings because the attention weights become "blurry" or dispersed over time. Changxu Cheng proposed LISTER, which treats decoding like a linked list. Instead of predicting the next character based on a global sequence index, the model identifies "neighbors." This local focus prevents the accumulation of global alignment errors, allowing models to recognize text of arbitrary lengths that they never encountered during training.