DocTTT: Test-Time Training for Handwritten Document Recognition Using Meta-Auxiliary Learning

Wenhao Gu, Li Gu, Ziqiang Wang, Ching Yee Suen, Yang Wang

Abstract

Despite recent significant advancements in Handwritten Document Recognition (HDR), the efficient and accurate recognition of text against complex backgrounds, diverse handwriting styles, and varying document layouts remains a practical challenge. Moreover, this issue is seldom addressed in academic research, particularly in scenarios with minimal annotated data available. In this paper, we introduce the DocTTT framework to address these challenges. The key innovation of our approach is that it uses test-time training to adapt the model to each specific input during testing. We propose a novel Meta-Auxiliary learning approach that combines Meta-learning and self-supervised Masked Autoencoder (MAE). During testing, we adapt the visual representation parameters using a self-supervised MAE loss. During training, we learn the model parameters using a meta-learning framework, so that the model parameters are learned to adapt to a new input effectively. Experimental results show that our proposed method significantly outperforms existing state-of-the-art approaches on benchmark datasets.

Introduction

Handwritten Document Recognition (HDR) is significantly more complex than standard OCR. Beyond identifying characters, a model must navigate diverse layouts, messy backgrounds, and the infinite variety of human handwriting styles. Traditional deep learning models follow a "train-then-freeze" pipeline: they learn from a large dataset and remain static during deployment. However, a model trained on 18th-century ledgers might struggle with a 20th-century personal letter because the distribution of the writing style has shifted. A single fixed model often lacks the flexibility to handle the unique visual nuances of an unseen author's hand.

To address this, we introduce DocTTT (Test-Time Training for HDR), a framework that adapts its model parameters to every single document it encounters during inference. By combining self-supervised Masked Autoencoders (MAE) with Meta-Learning, the system "learns how to adapt" during training so it can effectively capture unique handwriting styles at test time without needing any new labels.

Methodology

The DocTTT framework utilizes a dual-branch architecture to bridge the gap between general training and specific document adaptation.

Primary Task: Document Recognition

The primary task consists of an encoder-decoder (FCN + Transformer) that predicts a flattened sequence of XML tokens representing the document's text and layout. By predicting XML tokens, the model treats layout (where things are) and text (what things say) as a single sequence-to-sequence problem, allowing the transformer decoder to learn the relationship between document structure and content.

Figure 2: The primary task maps document images to structured XML tokens representing text and layout.

Auxiliary Task: Self-Supervised Reconstruction

The auxiliary task is a Masked Autoencoder (MAE) that attempts to reconstruct the original document image from a version where 75% of the pixels are masked out. This serves as a proxy for "understanding" style; to reconstruct a masked image of handwriting, the model must implicitly learn the stroke thickness, slant, and ink consistency of that specific author.

Figure 5: The auxiliary MAE task reconstructs masked document segments to learn stylistic features.

Meta-Auxiliary Learning

The "secret sauce" is Meta-Auxiliary Learning. During training, the model uses a bi-level optimization strategy inspired by Model-Agnostic Meta-Learning (MAML):

  • Inner Loop: The model takes a few gradient steps to minimize the reconstruction loss of the MAE (the auxiliary task).
  • Outer Loop: The model updates its global parameters so that the adapted version from the inner loop performs better on the actual HDR task (the primary task).

At test time, when the model sees a brand-new document, it performs a few self-supervised gradient updates using the MAE loss. Because the MAE task requires no labels, the model can "tune in" to the specific visual features and textures of that document before it ever attempts to recognize the text.

Experiments and Results

Datasets

DocTTT was evaluated on three cornerstone benchmarks:

  • READ 2016: Over 30,000 pages of early modern German scripts (1470–1805), known for complex layouts and archaic handwriting.
  • IAM Handwriting Database: A standard set of unconstrained English handwritten text.
  • RIMES 2011: A collection of over 12,000 pages of handwritten French letters.

Key Results

DocTTT achieved state-of-the-art (SOTA) results across all tested datasets:

  • READ 2016 (Single Page): Achieved a Character Error Rate (CER) of 3.18% and a Word Error Rate (WER) of 12.63%, outperforming previous leaders like DAN.
  • IAM (Paragraph Level): Reduced the CER to 4.22%, a significant improvement over the previous SOTA of 4.45%.
  • RIMES 2011 (Line Level): Reached a CER of 2.33%.

Ablation studies confirmed that removing the Test-Time Training (TTT) component led to a measurable drop in performance, proving that the "on-the-fly" adaptation is critical to the model's success.

Discussion and Conclusion

DocTTT demonstrates that test-time adaptation through self-supervision is a powerful tool for HDR. By using SSIM (Structural Similarity Index Measure) for reconstruction loss, the model preserves high-frequency details like fine pen strokes better than standard MSE.

However, some limitations remain. The primary drawback is inference latency; because the model performs gradient updates during testing, it is computationally more expensive than a standard forward pass. Future work may explore more efficient auxiliary tasks or alternative self-supervised methods like contrastive learning to further refine stylistic feature capture while maintaining speed.

Summary updated

BibTeX
@inproceedings{gu2025docttt,
  author = {Wenhao Gu and Li Gu and Ziqiang Wang and Ching Yee Suen and Yang Wang},
  title = {{DocTTT: Test-Time Training for Handwritten Document Recognition Using Meta-Auxiliary Learning}},
  booktitle = {IEEE/CVF Winter Conference on Applications of Computer Vision},
  year = {2025},
  url = {https://openreview.net/forum?id=HGQX7RotIB},
}
Figure