cs.CVMar 4, 2026

N-gram Injection into Transformers for Dynamic Language Model Adaptation in Handwritten Text Recognition

Authors: Florent Meyer, Laurent Guichard, Yann Soullard, Denis Coquenet, Guillaume Gravier, Bertrand Coüasnon

Organizations: ANTAI, Rennes, France · Univ Rennes, CNRS, IRISA - UMR 6074, Rennes, France

Abstract

Transformer-based encoder-decoder networks have recently achieved impressive results in handwritten text recognition, partly thanks to their auto-regressive decoder which implicitly learns a language model. However, such networks suffer from a large performance drop when evaluated on a target corpus whose language distribution is shifted from the source text seen during training. To retain recognition accuracy despite this language shift, we propose an external n-gram injection (NGI) for dynamic adaptation of the network's language modeling at inference time. Our method allows switching to an n-gram language model estimated on a corpus close to the target distribution, therefore mitigating bias without any extra training on target image-text pairs. We opt for an early injection of the n-gram into the transformer decoder so that the network learns to fully leverage text-only data at the low additional cost of n-gram inference. Experiments on three handwritten datasets demonstrate that the proposed NGI significantly reduces the performance gap between source and target corpora.

Figures & tables

Explore similar work

CardsList
  1. Zero-Shot Synthetic-to-Real Handwritten Text Recognition via Task Analogies

    Apr 8, 2026Carlos Garrido-Munoz, Aniello Panariello, Silvia Cascianelli +4Synthetic-to-Real Domain AdaptationTransfer Learning

  2. Efficient Domain Adaptation for Text Line Recognition via Decoupled Language Models

    Mar 30, 2026Arundhathi Dev, Justin ZhanOptical Character RecognitionUnsupervised Domain Adaptation

  3. Few-shot Writer Adaptation via Multimodal In-Context Learning

    Mar 31, 2026Tom Simon, Stephane Nicolas, Pierrick Tranouez +2Optical Character RecognitionFew-Shot Learning