Preserving privacy without compromising accuracy: Machine unlearning for handwritten text recognition

Lei Kang, Xuanshuo Fu, Lluís Gómez, Alicia Fornés, Ernest Valveny, Dimosthenis Karatzas · DOI

TL;DR

This paper presents the first systematic study of machine unlearning for Handwritten Text Recognition (HTR), addressing the privacy risks of models memorizing unique user writing styles. The authors propose a two-stage framework that combines targeted neural pruning with a novel Writer-ID Confusion (WIC) loss applied to a secondary writer classification head. This approach successfully erases user-specific biometric style cues—ensuring compliance with "right to be forgotten" regulations—without compromising the model's core text recognition accuracy.

What Problem Does This Paper Address?

Deep learning has revolutionized Handwritten Text Recognition (HTR), making the digitization of historical manuscripts and medical forms highly accurate. However, handwriting is inherently behavioral biometrics; it contains unique, user-identifiable features. When HTR models are trained on large datasets of user-generated content, they inadvertently memorize these individual writing styles.

Under modern privacy regulations like the EU’s GDPR, users have the "right to be forgotten," meaning organizations must delete their data upon request. Fully retraining a massive transformer model from scratch every time a user requests data deletion is computationally prohibitive. While machine unlearning offers a way to selectively remove data influence without full retraining, existing methods are designed for simple image classification tasks. When applied to HTR, standard unlearning techniques suffer from a severe privacy-accuracy trade-off: because writing style and text content are deeply entangled in the neural network, erasing the style often destroys the model's ability to read the text.

Overview of the unlearning framework and the privacy-accuracy trade-off

Methods

The authors tackle this challenge by introducing a multi-head, encoder-only transformer architecture and a two-stage "prune-and-unlearn" pipeline.

  1. Multi-Head Architecture: Alongside the standard text recognition head, the authors introduce a special [CLS] token and a secondary writer classification head. This design isolates the user-identifiable style features, providing a specific lever for the unlearning process without directly altering the text recognition weights.
The proposed multi-head transformer-based HTR architecture
  1. Stage I: Neural Pruning: Before fine-tuning, the model calculates an "importance score" for all neurons by comparing activations from the "forget set" (the data to be erased) against the "retain set" (the data to keep). Neurons that are highly sensitive to the forget set are pruned (set to zero), removing the bulk of the user-specific knowledge upfront.
  2. Stage II: Writer-ID Confusion (WIC): Instead of using traditional unlearning methods like Random Labeling (which forces the model to predict an incorrect writer ID), the authors introduce WIC. This novel loss function uses KL divergence to force the model's writer ID predictions for the forget set to follow a uniform distribution. By maximizing uncertainty, the model completely "forgets" how to identify the writer, while standard cross-entropy loss preserves recognition capabilities for the remaining writers.

Datasets

The framework was evaluated on two widely recognized HTR benchmarks:

  • IAM Handwritten Dataset: A large dataset of modern English handwritten text. The authors utilized the RWTH partition at the word level, filtering it to standard alphanumeric characters (40,977 training words).
  • CVL Dataset: Used to evaluate robustness, featuring a combined dataset of 310 writers and 99,904 word-level images.

Key Insights and Ideas

  • Style vs. Text Decoupling: The multi-head architecture proves that style and text can be functionally separated. By targeting the unlearning process at the writer head, the core text recognition engine remains unharmed.
  • Confusion Over Corruption: Traditional unlearning often tries to corrupt labels or reverse gradients, which can destabilize the model. WIC introduces the elegant idea of enforced uncertainty (uniform distribution), which proves much more stable and effective for complex sequence tasks.
  • Layer Sensitivity: Fine-grained pruning analysis revealed that shallow transformer blocks contain significantly more user-specific style information, whereas deep blocks carry more text-recognition-related information. This insight allows for highly targeted pruning strategies.

Key Results

The proposed Prune-WIC method achieved state-of-the-art unlearning performance:

  • Complete Style Erasure: On the IAM dataset, Prune-WIC successfully dropped the writer classification accuracy of the forget set to 0.00%.
  • Accuracy Preservation: Despite total style erasure, the Character Error Rate (CER) and Word Error Rate (WER) on the forget set remained exceptionally low (0.97% CER and 1.35% WER), virtually matching the fully trained baseline model.
  • Defeating Privacy Attacks: To rigorously verify privacy, the authors subjected the model to a Membership Inference Attack (MIA). Post-unlearning, the MIA success rate dropped to 48% (effectively a random guess), proving the model treats the forgotten data as completely unseen.
  • Efficiency: On the CVL dataset, Prune-WIC completed the unlearning process in 4,069 seconds using just 16.4 GB of GPU memory, bypassing the need for costly full-model retraining.

Limitations and Future Work

While highly effective at removing writer identity, the authors note that this work primarily focuses on visual writing styles. It does not yet address other potential avenues of information leakage, such as rare lexical patterns or unique stylistic choices in vocabulary.

For future work, the authors suggest expanding this framework into layout-aware machine unlearning (for complex document structures) and multilingual unlearning. They also propose integrating these mechanisms into downstream tasks like Document Visual Question Answering (DocVQA) to allow models to securely "forget" entire documents from retrievable memory upon user request.

Summary updated

BibTeX
@article{kang2026preserving,
  author = {Lei Kang and Xuanshuo Fu and Lluís Gómez and Alicia Fornés and Ernest Valveny and Dimosthenis Karatzas},
  title = {{Preserving privacy without compromising accuracy: Machine unlearning for handwritten text recognition}},
  journal = {Pattern Recognition},
  year = {2026},
  doi = {10.1016/j.patcog.2025.112411},
}
Figure