WorksComputer Science
Generative Text Modelling and Language-Guided Visual Attention for Deciphering Palimpsests
Abstract
Recovering obscured text in palimpsests, i.e. the manuscripts where the original writing (under-text) was erased and overwritten for reuse, is vital for preserving lost information. Due to the nature of the material, such a task can be highly challenging and time-consuming. This paper presents an approach towards automated palimpsest handwritten text modeling for under-text recovery. We investigate generative models, including Generative Adversarial Networks (GANs) and diffusion models, and design a custom denoising diffusion model that learns structured noise patterns to reconstruct the under-text. The recovered text is subsequently processed by a fine-tuned, attention-based handwritten text recognition network. Furthermore, we investigate a language-guided recognition framework that leverages textual class descriptions as informative priors, enabling the text recognition model to distinguish meaningful features from noise. This is achieved by grounding task-specific descriptions, phrased in words or sentences, through visual attention maps generated by pretrained vision-language models like CLIP (Contrastive Language-Image Pre-training). To facilitate future research and benchmarking, we release new datasets for synthetic palimpsests (currently scarce), CLIP-compatible text descriptions, and pre-trained models with code.
Introduction
Palimpsests are historical manuscripts that contain a visible top layer of text and one or more hidden, erased layers beneath it. The original writings were scraped-off or overwritten to reuse the writing material (parchment). Restoring palimpsests and recovering the underlying handwriting is fundamentally an inverse problem, one that aims to reverse the processes of erasure and overwriting to reveal the lost text.
While multispectral and hyperspectral imaging can enhance contrast between inks and parchment, other factors such as spectral overlap, surface irregularities, and noise often obscure the faint signals of the under-text. Because these limitations constrain the effectiveness of imaging-based techniques, they have prompted exploration of data-driven approaches, such as deep learning. However, emerging deep learning approaches face their own limitations, due to the scarcity of annotated training data, poor generalisation across different manuscripts, and the risk of generating misleading reconstructions. The field remains significantly under-explored, and to the best of our knowledge, no existing method can reliably separate over-text from under-text across diverse manuscripts and perform accurate recognition. This gap highlights the need for standardised, reproducible workflows for manuscript restoration.
Recent advances in handwritten text recognition (HTR) have leveraged natural language processing (NLP) techniques to improve recognition accuracy ([17, 3]). Language models, textual priors, and semantic embeddings provide contextual information that helps disambiguate visually uncertain predictions, while vision-language frameworks enable grounding of textual descriptions in visual features. Integrating NLP with HTR transforms it into a multimodal problem, allowing models to distinguish relevant text from noise and better handle challenging scenarios such as palimpsests.
Our work builds on this line of research and examines the extent to which natural language guidance can improve the reconstruction and recognition of under-text in palimpsests using a deep learning framework. Our key contributions:
a) We examine how generative models, including Generative Adversarial Networks (GANs) and diffusion models, can enhance under-text extraction, and introduce a custom denoising diffusion model (cDDM) tailored to this problem.
b) We introduce a language-guided, attention-based recognition framework that leverages textual priors to guide HTR.
c) We explore a new distillation paradigm that transfers knowledge via guided attention and integrates CLIP-based vision-language grounding to align semantic text descriptions with visual features, enabling the model to distinguish handwriting from noise.
d) The proposed approach is model-agnostic and broadly transferable to any HTR framework that exposes intermediate activation maps and utilises a standard classification loss.
e) To address the scarcity of training data, we create and release synthetic palimpsest datasets, CLIP-compatible text descriptions, and pretrained models, providing resources for future research and benchmarking.
The source code for our implementation is publicly available at https://github.com/UU-VLL/GTM-LGHTR-Palimpsest. The dataset is available at https://doi.org/10.5281/zenodo.21902987.
Related Work
When it comes to palimpsest restoration, traditional approaches, such as colour space transformation Tonazzini [31], and statistical methods, such as Principal Component Analysis and Independent Component Analysis on multi-spectral imaging [25, 7], have long been the leading techniques for text extraction and layer separation. Recently, deep learning models, including Convolutional Neural Networks Perino et al. [22], generative inpainting Jampour et al. [14], latent diffusion models Jampour [13], and the increasingly popular GANs [30, 18], have begun to play a more important role in this field. In particular, Madi et al. [18] compared several GAN models and showed that their proposed models, Palimpsest Manuscripts Reconstruction (PMR)-GAN, and Pix2pix (also a GAN model), are among the top-performing approaches in restoration. Given the difficulty of obtaining ground truth images for training palimpsest restoration models, all the aforementioned deep learning methods generated synthetic data using various techniques.
Meanwhile, despite the general consensus that diffusion models may achieve better results than GANs in other fields [6, 20], there have been relatively few investigations of their application in palimpsest restoration. Latent diffusion models were investigated by Jampour [13], who also introduced the Synthetic Georgian Palimpsest datasets [14]. However, their evaluation was limited to only a few palimpsests, leaving it unclear how well the method generalises across diverse datasets.
Palimpsest (under-text) recognition remains an under-explored area, with the earliest studies emerging as late as 2017 [29], focusing primarily on character-level Optical Character Recognition (OCR). Subsequent works have also employed OCR/HTR accuracy as an indirect measure of restoration quality [30, 18]. To the best of our knowledge, no known studies have attempted word-level under-text HTR that generalises across diverse manuscripts, and existing approaches remain confined to specific manuscript types.
Because annotated palimpsest data are scarce, current studies rely on synthetic datasets that closely imitate real manuscripts. This approach enables supervised training and quantitative evaluation of text separation models. Synthetic generation also allows controlled creation of target masks for text separation and labels for recognition.
With the emergence of the CLIP model in vision-language tasks [24], its potential for vision-language alignment [23] has yet to receive substantial attention from researchers working on HTR and palimpsest recognition. Existing studies in Scene Text Recognition have demonstrated the latent OCR capabilities of CLIP, for example through the incorporation of CLIP-based cross-modal alignment plugins with existing detection heads (Yu et al., 2023) and the integration of CLIP encoders with multi-branch decoders (Zhao et al., 2024a). Other research exploring CLIP in OCR tasks has investigated innovative alignment and distillation techniques [35] as well as integration with large language models (Zhao et al., 2024b).
In this work, CLIP is employed as a guidance model whose text-conditioned activation maps, obtained via gradient-weighted attention rollout [2], are used to supervise the Grad-CAM Selvaraju et al., [26] attention of the HTR model (in our case the attention-based HTR model Kass and Vats, [16]), aiming to enhance modality alignment. This work also evaluates the Pix2pix GAN model, and designs a custom diffusion model for under-text retrieval and restoration tasks. Model generalisation and reproducibility are of critical importance; therefore, we conduct a comprehensive evaluation across three datasets: Synthetic MNIST, Synthetic Saint Gall, and Synthetic Georgian Palimpsest. One of the few well-known real palimpsest datasets is the Archimedes dataset Toth and Emery, [32]. However, while some under-text is visible, it lacks paired samples of overlapping and clean under-text, making it unsuitable for training our generative models.
It is important to note that no sample selection is performed in this work and the evaluations are conducted across the predefined data splits in accordance with the dataset guidelines and evaluation metrics. We believe this will greatly help facilitate future research and benchmarking.
Methodology
Our primary objective is to recognise the under-text from a synthetic palimpsest. This can be approached in two ways: directly perform HTR on the partially visible under-text, or first carry out text layer separation to reconstruct the under-text image, then perform HTR on the reconstructed image. Experiments are conducted on both methods, with the results presented later in § 4.3. In this section we first introduce our text separation techniques, followed by the HTR methods.
A palimpsest image can be viewed approximately as a superposition of the over-text , the under-text and the background writing support . The text separation stage (§ 3.1) in our pipeline aims to leverage generative models to extract signals from the under-text as an image, and the recognition stage (§ 3.2) uses an HTR model to identify the text from such images with the guidance of the CLIP model. The overall architecture of the integrated pipeline is shown in Figure 1. The following subsections describe the text separation and HTR models.

Figure 1. Architecture of our proposed framework, consisting of two main stages: (i) Under-text separation, where a trained generative model is used to recover the target under-text from the palimpsest. (ii) Language-guided HTR, where an HTR model is trained using a standard CE loss between the predicted text and the ground truth. To enhance recognition, we introduce a language-guided supervision strategy, which aligns the HTR model’s Grad-CAM visual feature maps with text-image alignments derived from CLIP via an activation loss. The example palimpsest image originates from the Synthetic Saint Gall dataset, and the example under-text image is a reconstructed image using cDDM2.
Palimpsest Text Separation
The text separation process can be expressed as training a model that takes the palimpsest image as input, and reconstructs the under-text . In the subsequent section we will denote the ground truth under-text as the training target , and introduce the two text separation models implemented in this work.
Pix2pix
Pix2pix is a conditional GAN with skip connections, demonstrating state-of-the-art performance in text separation for palimpsests on synthetic data Madi et al., [18]. The architecture is well-suited for image-to-image translation, enabling the separation of under-text, over-text, and background. Traditional methods often fail in overlapping regions Starynska, [28], whereas Pix2pix preserves structural integrity through its U-Net generator and adversarial training, yielding higher-quality under-text reconstruction. The adversarial loss further enforces realism in the generated outputs Isola et al., [12], allowing conditional GANs to model inter-pixel dependencies absent in standard GANs.
Conditional GANs such as Pix2pix learn to map an input image to a target image through two competing networks: a generator and a discriminator . aims to produce indistinguishable from the target real image , while learns to differentiate between them. Their adversarial interplay leads both networks toward optimality.
Pix2pix employs a U-Net generator, an encoder-decoder architecture that first downsamples the input feature and then reconstructs through up-sampling. The forward pass can be expressed as
where denotes the bottleneck feature representation, and represent the th encoder and the th decoder in the U-Net.
The discriminator is implemented as a Patch-GAN, dividing each image into local patches and predicting a real/fake probability per patch:
where stands for convolutional layers whose final output is a map of real-valued patch scores , and stands for the number of patches in each image. The least-squares objectives below are applied to the patch scores directly, i.e. the loss is the mean over the patches of the perpatch squared errors, with target .
To stabilise training, Pix2pix applies the Least Squares GAN (LSGAN) loss [19], which replaces the binary cross-entropy (CE) loss [9] with a least-square objective for stronger gradient feedback.
The generator loss combines adversarial and reconstruction terms:
where balances the realism and pixel-level accuracy; note that this is a smaller reconstruction weight than the used by Isola et al. [12]. The discriminator loss is defined as
Through this loss, learns to output values close to 1 for real samples and close to 0 for generated ones, ensuring effective adversarial training.
cDDM
Historical palimpsests are highly diverse and contain degraded script where the unwanted components (e.g., over-text and complex background noises) are highly structured and do not follow a Gaussian distribution. Therefore, standard Denoising Diffusion Probabilistic Models (DDPM) [11], which rely on stochastic Gaussian noise mapping, may discard relevant information when applied to palimpsests. In this work, we propose a custom conditional Denoising Diffusion Model (cDDM). Instead of using randomly sampled noise, cDDM adapts the diffusion architecture to invert a fixed, structured residual and operates as a deterministic diffusion process. This framing aligns with the generalised diffusion literature (e.g., Cold Diffusion [1]), which demonstrates that the diffusion framework can successfully invert arbitrary, non-probabilistic image degradations without relying on Gaussian assumptions.
In traditional DDPMs, the Gaussian noise is added in each time step via
where controls the signal retention, controls the noise scale, and indexes the diffusion steps (with denoting the clean image).
To address the structured, non-Gaussian artifacts in our case, we replace stochastic sampling with a deterministic residual between the raw palimpsest input and the target under-text .
i.e. a convex combination of the palimpsest and the target , which keeps the target and the full structured residual present in every latent . Because is clipped to (see Eq. 8), the coefficient varies only mildly with : every remains close to the palimpsest image , and the model is trained, at all noise levels, to regress the complete structured residual from an input that is approximately . The time step therefore acts primarily as an auxiliary conditioning signal (via the time embedding) rather than as an interpolation between and ; this differs from standard DDPMs, in which is (almost) pure noise. In particular, never degenerates to pure noise, so the structured, non-Gaussian residual is available to the network at every step. Input images are normalised to to capture fine differences, e.g., between two black texts.
The residual is defined in the raw pixel space, where denotes the clean target under-text image that the model is trained to recover from the palimpsest images . At each step, the noise is given by , which represents the unwanted components in , such as the background and over-text that are treated as noise.
The rate at which the noise scale varies is controlled via a cosine noise scheduler [21]. The cosine scheduler is defined as
where is a small offset that prevents from becoming too small near [21], and per-step noise scales
where the clipping bounds, adopted from the linear-schedule DDPM convention, cap the per-step noise change; for the small used in cDDM1 they are active at almost every step, so is nearly constant ().
Subsequent to the forward process that progressively adds noise, the reverse process is designed to remove noise and reconstruct the original data, through training a deep learning model to approximate the noise and ultimately learn to remove it from a latent variable . To do so, a U-Net is employed to train on , where time is embedded into a vector to condition the model on the time state. The network flow of the model can be expressed as follows:
where and are the encoders and decoders of the U-Net, and is the predicted noise. The model is then trained on minimising the loss:
Note that, unlike in standard DDPMs, is fully determined by the training pair , so the expectation is taken over the data and the time step only. At each training iteration, is randomly sampled from a discrete uniform distribution: (the implementation uses the equivalent 0-based indices ).
In the inference stage, the trained U-Net is used to recover previously unseen under-texts directly from the palimpsest image , which is treated as the maximally noisy variable , without access to . In this work we design two denoising methods, cDDM1 and cDDM2. In cDDM1, starting from , the model re-estimates the noise from the current iterate at every step and removes it deterministically according to:
i.e. the deterministic inversion of the standard per-step update (Eq. (5)) with , applied with the noise re-estimated from the current iterate, and with the predicted noise removed directly in the final step. Note that this reverse recursion is not the exact algebraic inverse of the forward construction in Eq. (6); because is re-predicted from at every step, the procedure acts as an iterative residual-removal scheme whose per-step magnitude follows the forward cosine schedule.
cDDM2 performs a single-step reverse process, predicting and directly removing noise in . To improve denoising, a mask sets regions with high predicted noise to white, heuristically targeting over-text that is otherwise difficult to remove. process is:
where is the indicator function, the predicted-noise magnitude is averaged over colour channels , masks pixels whose value exceeds the threshold (setting them to white), and is the final denoised image. The threshold is set per dataset to (Synthetic MNIST), (Synthetic Saint Gall) and (Synthetic Georgian), chosen on the training data. Unlike iterative cDDM1, noise scaling from the forward schedule is not applied in this single-step denoising approach.
To the best of our knowledge, this is the first diffusion-based approach applied directly in the raw pixel space for palimpsest text separation. While Jampour [13] focuses on computational efficiency, our cDDM is specifically designed to preserve high-frequency handwriting features, allowing us to benefit from diffusion’s noise removal capabilities without sacrificing fine detail.
Language-Guided Text Recognition
The palimpsest HTR learning problem can be formulated as follows. Given a palimpsest dataset for an HTR task , let each image contain some region of pixels that is irrelevant to the task (e.g. over-text, damages, degradations) and a region of pixels that is relevant (e.g. under-text). The goal is to recognise the under-text from certain regions in the under-text image (either the raw image or the reconstructed image from the text separation).
In this work, we propose language-guided HTR that leverages a vision-language model to guide a conventional HTR system by constraining it to focus on a more semantically grounded attention map. The architecture is shown in the right half of Figure 1, starting from the under-text image that has been recovered from a given input palimpsest image using the text separation model discussed in the previous section (Pix2pix or cDDM).
For every image (or retrieved image ) and ground truth text label , we create a natural language guiding text that captures the key semantic concept relevant to . This guiding text is derived from the dataset’s ground truth label.
To ensure compatibility with a pretrained vision-language model like CLIP, consists of descriptive phrases formatted similarly to CLIP’s default notation. For example, we prepend a structured prompt such as “A photo of a handwritten word label”, where the word label is extracted from the dataset’s ground truth text label .
For an HTR model with parameters , we aim to learn an optimal HTR model that outputs a text prediction and an activation map for a given under-text image as input. To learn an optimal , we can estimate a probability map over the latent space, where each entry corresponds to the probability that pixel is relevant to . In this work, we build on the AttentionHTR model (Kass and Vats, [16]) (AHTR in short). In principle, any HTR model that can generate intermediate activation maps and support a standard classification loss could be used.
Next, we introduce language-guided supervision by generating ground truth activation maps from CLIP. We refer to the resulting model as G-AHTR (Guided-AttentionHTR). CLIP is a vision-language model that takes both an image and a text input and produces a similarity score in a shared embedding space. Although this score is global, gradient-based attribution allows us to propagate it through CLIP’s visual encoder to obtain pixel-level relevance maps (Petryk et al., [23]), enabling us to exploit CLIP’s text-image alignment without modifying the base HTR architecture. Since our CLIP visual encoder is a ViT-B/32 transformer, we compute these maps with gradient-weighted attention rollout (Chefer et al., [2]), accumulating the gradient-weighted attention of all transformer blocks into a relevancy map over the visual tokens.
Before extracting activation maps, we fine-tune the full CLIP ViT-B/32 model on the training split of the respective (reconstructed) dataset with the standard symmetric image–text contrastive loss (temperature ), using AdamW with learning rate and weight decay for 20 epochs; the HTR-sized grayscale images are replicated to three channels and bilinearly resized to .
Given the under-text image and guiding text , we feed both into CLIP (input resized to ) and obtain a text-conditioned relevance map over the visual tokens, which for the ViT-B/32 encoder natively lies on a grid. This map is bilinearly upsampled to the image resolution, undergoes the same crop-and-pad preprocessing as the input image (§ 4.1), and is bilinearly re-sampled to the HTR input grid, yielding
This map serves as the ground truth activation map, denoted in the following. Importantly, we do not use CLIP’s prediction itself, only its activation map to provide attention guidance. In parallel, we extract an activation map from the HTR model with Grad-CAM ([26]) at the last convolutional block of its feature extractor, using the summed logits of the ground truth character sequence as the class score (native resolution ), bilinearly interpolated and min-max normalised to the same grid:
The L1 activation loss is computed on this common grid. Before entering the loss, the guidance map is affinely rescaled to the input value range, , while the predicted map remains in . This asymmetric scaling serves two purposes: it amplifies the guidance gradients relative to matched-range maps, and, since the predicted map cannot attain the negative target values assigned to low-relevance regions, it persistently drives the predicted attention toward zero outside the text region, acting as a sharpening prior on the guidance.
The HTR model is then trained on minimising two objectives: (i) the original CE loss between the predicted text and the ground truth transcription, and (ii) a complementary activation loss between the HTR and CLIP activation maps. The activation loss refers to the difference between the two activation maps, in the form of L1 norm. An unweighted sum of the two constitutes the final training objective:
where is the predicted transcription, is the ground truth text, is the input image, and is the guiding text. Here, denotes the rescaled ground truth activation map extracted from CLIP, and is the activation map from the HTR model.
Experimental Results
The proposed methods are empirically evaluated on three synthetic datasets using standard evaluation metrics. This section is organised as follows. We begin by presenting the synthetic datasets and detailing the process to create them. Next, we describe the evaluation metrics used. Finally, we present the results for both text separation and recognition across three scenarios: (a) recognition from the original datasets (MNIST and Saint Gall) without overlapping text, serving as a baseline; (b) direct recognition of the partially visible under-text from palimpsest images; and (c) recognition following text layer separation, where the under-text is first reconstructed.
Datasets
Synthetic MNIST
We replicate the Synthetic MNIST dataset used by Starynska et al. [30] with both diversity and manageable file size in mind. The original MNIST digits ([5]) serve as target under-texts. To emulate palimpsest data, where backgrounds are typically lighter than text, each image is inverted, , where denote pixel coordinates and intensities are in .
The target images are randomly rotated by using bi-cubic resampling:
The target text is assigned a random low-intensity uniform colour in RGB channels:
and a fourth transparency channel preserves the original MNIST pixel intensities:
Backgrounds with parchment-like colours are generated with channel-wise uniform noise:
Under-texts are extracted using a threshold and centred on the background. Over-texts consist of random Latin characters (A–Z) with random font, size (20-25), colour (Eq. (14)), and rotation (Eq. (13)). Finally, additional noise is applied:
The dataset contains 60 000 training and 10 000 test samples, following MNIST’s original split.
Synthetic Saint Gall
The Saint Gall dataset (Fischer et al., [8]) originates from a 9th century Latin manuscript and comprises 60 pages of Carolingian minuscule script by a single scribe. It contains 1 410 text lines and 11 597 words. Images were binarised, normalised, and paired with sentence-level labels. Its historical significance, complex script, and ink-on-parchment characteristics make it a valuable benchmark for HTR models.
A synthetic version was generated to introduce real historical text and extend processing to larger images with longer words. Under-text was extracted at the word level using provided bounding boxes, separated from the background with a threshold of 100, and placed on a transparent canvas. Words exceeding 350 pixels in width were skipped. Under-text colour and rotation followed Eq. (14) and Eq. (13).
Backgrounds were generated similarly to the synthetic MNIST dataset with pixel canvases, using Eq. (16) for color, uniform noise (Eq. (17)), salt-and-pepper noise , and Gaussian noise with 50% probability, . Under-text was centred and images resized to to reduce computation while preserving quality. Over-texts consisted of random Latin strings with random fonts, size 30-40, overlaid on under-text.
Prior to recognition, all images are dynamically cropped to ensure a text-focused region and prevent geometric distortion. Since our HTR model has a fixed input resolution, directly resizing the original images severely compressed the text due to excess vertical white space. To address this, we use Otsu’s thresholding to detect the ink pixels and establish a bounding box. This box is then padded with background pixels to exactly match the target aspect ratio
before final resizing, ensuring the morphological features of the handwriting remain strictly undistorted. The final synthetic dataset comprises 6 514 training and 1 050 test images; for HTR training, the training images are further split 90/10 into training and validation subsets, with the validation subset used for model selection.
Synthetic Georgian Palimpsest dataset
The synthetic Georgian dataset (Jampour et al., [14]), used in this work, simulates multi-spectral samples from the real Georgian palimpsest (Sinai-Project, [27]). Under-texts consist of 7th-8th century Caucasian Albanian text from Sinai Georgian NF 13 and 55, while backgrounds were cropped from text-free areas of the real palimpsest and prepared via stitching and cleaning. Random over-text was added, but only under-texts are considered in this work.
Targets with white backgrounds were generated by extracting under-texts using a channel-wise threshold, as in Eq. (18):
Original images were 21002800 pixels, too large for training. Both combined and under-text images were split into 48 patches of , then resized to pixels to preserve readability. Full-image resizing rendered text unreadable. Examples are shown in Figure 2, with rare cases of slight over-extraction due to red intensity in the background.

Figure 2. Combined and under-text patches from the processed synthetic Georgian dataset.
The final synthetic Georgian dataset used in this work has 43 200 patches of training data and 4 800 patches of testing data.
Evaluation Metrics
Text separation: To assess image quality for the text separation models Pix2pix and cDDM, we use standard metrics: Structural Similarity Index Measure (SSIM), Peak Signal-to-Noise Ratio (PSNR), and the Fréchet Inception Distance (FID).
SSIM [33] quantifies local similarity between generated images and target images based on luminance, contrast, and structure:
Here, denote image means (luminance), their standard deviations (contrast), the covariance (structure), and are small constants that stabilise the division. SSIM takes values in , where 1 indicates perfect similarity.
PSNR [34] measures reconstruction quality using the mean squared error (MSE):
where is the maximum pixel value, and is the image dimensions. Higher PSNR indicates better fidelity; values above 40 suggest high-quality reconstruction.
FID [10] measures similarity between feature distributions extracted from the 2048-d pool3 features of a pretrained Inception-v3 network (pytorch-fid), assuming Gaussian statistics:
Lower FID values indicate that generated images are closer to the real image distribution.
Text recognition: Recognition performance for AHTR and G-AHTR is measured using Word Accuracy (WAcc), computed as:
where, since recognition is performed at the isolated-word level, the Word Error Rate (WER) is the percentage of test words that are not recognised exactly. We also compute Normalised Edit Distance (NormED) and Character Error Rate (CER) to further analyse model performance.
NormED is defined as
where and here denote the ground truth and predicted transcriptions of the th test sample (character sequences, in contrast to their use as images elsewhere), is the Levenshtein distance, denotes sequence length, and samples with an empty ground truth or prediction contribute zero. CER quantifies character-level recognition errors at the corpus level, .
Results
Experimental results for text separation and recognition are reported across three scenarios highlighted in § 4, as follows.
a. Baseline results: Table 1 presents the baseline recognition performance for the original MNIST and Saint Gall datasets. Since these datasets contain no overlapping texts, only recognition performance is reported. For each experiment, we performed 10 independent training runs and report the average model performance.
| Dataset | MNIST | Saint Gall | ||
| Method | WAcc(%) | WAcc(%) | CER(%) | NormED |
| AHTR | 99.34 (0.05) | 94.64 (0.51) | 1.26 (0.12) | 0.0127 (0.0013) |
| G-AHTR | 99.37 (0.06) | 94.40 (0.37) | 1.31 (0.10) | 0.0131 (0.0009) |
Table 1. Baseline recognition performance on the original MNIST and Saint Gall datasets, reported in WAcc(%) for MNIST and WAcc(%), CER(%), NormED for Saint Gall. Results are averaged over 10 runs with standard deviation ().
The recognition of the Synthetic Georgian palimpsest is not considered here because its texts overlap, which makes a reliable baseline unavailable. Moreover, performing HTR on the Synthetic Georgian dataset is not feasible due to the lack of annotations, transcriptions, and training labels.
b. Direct recognition from overlaid palimpsest: We then evaluate the performance of HTR methods in recognising the under-texts directly from the overlaid images in synthetic palimpsest datasets, following the exact same pipeline as we used in scenario (a). The results are reported in WAcc, CER, and NormED, listed in rows under scenario “Overlaid” in Table 3.
| Dataset | Synthetic MNIST | Synthetic Saint Gall | ||||
| Methods | Scenario | WAcc (%) ↑ | WAcc (%) ↑ | WER (%) ↓ | CER (%) ↓ | Norm ED ↓ |
| [30] | 91.90 | - | - | - | - | |
| AHTR | Overlaid | 97.71 (±0.12) | 79.63 (±1.48) | 20.37 (±1.48) | 5.75 (±0.43) | 0.0612 (±0.0054) |
| Pix2pix | 96.83 (±0.12) | 62.25 (±1.87) | 37.75 (±1.87) | 12.40 (±0.68) | 0.1430 (±0.0075) | |
| cDDM2 | 97.83 (±0.11) | 91.70 (±0.73) | 8.30 (±0.73) | 1.95 (±0.25) | 0.0210 (±0.0030) | |
| G-AHTR | Overlaid | 97.68 (±0.15) | 78.30 (±1.38) | 21.70 (±1.38) | 6.18 (±0.48) | 0.0660 (±0.0055) |
| Pix2pix | 96.81 (±0.11) | 61.58 (±0.86) | 38.42 (±0.86) | 12.59 (±0.50) | 0.1450 (±0.0070) | |
| cDDM2 | 97.97 (±0.08) | 91.78 (±0.83) | 8.22 (±0.83) | 1.98 (±0.24) | 0.0218 (±0.0027) |
Table 3. Comparison of the average performance of AHTR and G-AHTR on Synthetic MNIST and Synthetic Saint Gall over 10 runs with standard deviation (±). Results are shown for direct recognition from the “overlaid” palimpsest images and for recognition after text separation using Pix2pix and cDDM2. cDDM1 is omitted due to its consistently lower separation performance compared to cDDM2.
As can be observed in Table 3, performing HTR directly on synthetic palimpsests without first separating the text layers is, as expected, challenging due to the partial visibility of the under-text. However, evaluating the performance of our HTR models in this setting provides valuable insights and highlights the need for effective text separation, discussed below.
c. Recognition with text separation: Furthermore, we integrate the text separation stage into the HTR pipeline, where Pix2pix and cDDMs are used to reconstruct the under-text from the palimpsest images. The models are trained on the respective training splits of each dataset, with hyperparameters (such as learning rate, epochs, and cDDM denoising steps) optimised to obtain the best models. The saved model checkpoints are then used to perform reconstructions on the test sets.
The separation results are evaluated using the three metrics introduced in § 4.2: SSIM, PSNR, and FID, as reported in Table 2.
| Dataset | Synthetic MNIST | Synthetic Saint Gall | Synthetic Georgian | ||||||
| Methods | SSIM ↑ | PSNR ↑ | FID ↓ | SSIM ↑ | PSNR ↑ | FID ↓ | SSIM ↑ | PSNR ↑ | FID ↓ |
| [30] | - | 17.781 | - | - | - | - | - | - | - |
| [13] | - | - | - | - | - | - | - | - | 144.68* |
| Pix2pix | 0.9383 | 23.242 | 3.849 | 0.9855 | 27.771 | 11.066 | 0.9913 | 37.619 | 20.367 |
| cDDM1 | 0.8879 | 21.634 | 20.054 | 0.9804 | 26.238 | 21.285 | 0.9509 | 27.574 | 49.942 |
| cDDM2 | 0.9419 | 23.238 | 3.837 | 0.9939 | 32.753 | 19.678 | 0.9750 | 31.384 | 31.055 |
Table 2. Text separation results on synthetic palimpsest datasets using Pix2pix and cDDMs. Results from related works are included for comparison. *Note that Jampour [13] reported three document-level FID values, we therefore use their median in our table.
Overall, cDDM2 achieves the best performance on Synthetic MNIST and Synthetic Saint Gall, obtaining the highest SSIM on both datasets, together with the lowest FID and near-best PSNR on Synthetic MNIST and the highest PSNR on Synthetic Saint Gall (where Pix2pix retains the lowest FID), demonstrating the effectiveness of our proposed custom noise mechanism. Its performance on Synthetic Georgian is slightly lower than that of Pix2pix, primarily due to colour discrepancies. This can be observed in the examples in Figure 3, where the cDDM reconstructions appear lighter than those of Pix2pix; however, the under-text shapes are clearly revealed and do not hinder recognition.

Figure 3. Examples of text separation results from different models, shown alongside the input palimpsest image and the ground truth under-text. The examples are drawn from the Synthetic MNIST, Synthetic Saint Gall, and Synthetic Georgian datasets (top to bottom).
The MNIST results (first row of Figure 3) further reveal an interesting difference: Pix2pix often behaves more rigidly than cDDM by attempting to forcefully recover all visible details, such as the black dot above the true under-text “9”, originating from the over-text “T”. This rigidity contributes to Pix2pix’s consistently low FID. However, because FID assumes a Gaussian distribution—and, as discussed in § 3.1.2 palimpsest noise is not always Gaussian, FID may be statistically biased [4, 15]. Moreover, this tendency to reproduce irrelevant or misleading artifacts may negatively affect the downstream recognition stage.
The reconstructed under-text images are then used as inputs for HTR training and testing. Table 3 reports the performance when text separation is applied prior to HTR. Since AHTR is designed for Latin characters only, its results are not compared with previous works involving other scripts, such as Greek, Syriac, and Hebrew [18]. As a baseline observation, integrating under-text separation substantially improves recognition accuracy over direct HTR on raw palimpsests, particularly on the highly challenging Saint Gall dataset. Among the evaluated pipelines, our proposed cDDM2 + G-AHTR framework achieves the best overall performance, yielding the highest mean WAcc and lowest mean WER on both the Synthetic MNIST and Synthetic Saint Gall datasets, although the margins over cDDM2 + AHTR lie within one standard deviation of the ten runs. In particular, when paired with cDDM2 reconstructions, G-AHTR yields small improvements in word-level metrics (WAcc/WER), while CER does not improve (1.98 vs. 1.95 on Synthetic Saint Gall); with Overlaid and Pix2pix inputs, G-AHTR performs on par with or slightly below AHTR, suggesting that the guidance is most useful when the reconstructed under-text is of high quality.
AHTR performs on par with or slightly below AHTR, suggesting that the guidance is most useful when the reconstructed under-text is of high quality. This disparity is expected, as the high variability and ambiguity inherent in handwritten text make character-level recognition more challenging. It is worth noticing that the language guiding mechanism comes at no cost on training stability, since the standard deviations of G-AHTR results are around the same level as those of AHTR.
While the absolute performance gains provided by the language-guided supervision are modest, we hypothesise that the performance ceiling is constrained by the following primary factors: i) the inherent limitations of CLIP in fine-grained handwriting recognition, which become more obvious when the intermediate recovered under-text remains highly degraded; ii) gradient competition between the primary CE loss and the auxiliary activation constraint, as strict spatial alignment with CLIP’s feature maps can be partially orthogonal to the optimal feature representations needed for pure character decoding.
To further illustrate the contribution of the vision-language (CLIP) component, Figure 4 visualises the ground truth activation map from the fine-tuned CLIP model, and Table 4 shows the activation maps computed from AHTR and G-AHTR during training on an arbitrarily selected example. These maps show that the CLIP-guided activation constraint encourages G-AHTR to focus more strongly on the under-text regions while suppressing irrelevant artifacts and noise. This shift in activation toward semantically meaningful regions provides more interpretable model behaviour and, in the cDDM2 setting, coincides with small word-level accuracy gains. In particular, in challenging cases where AHTR hallucinates the word endings, G-AHTR tends to make more reasonable predictions (see Table 5).
| Epoch 1 | Epoch 4 | Epoch 7 | Epoch 10 | Epoch 13 | Epoch 16 | |
| AHTR | ||||||
| G-AHTR |
Table 4. Comparison of activation maps on example under-text “itaq” obtained from AHTR and G-AHTR during training, on every third epoch (i.e. epochs 1, 4, 7, 10, 13 and 16). The activation maps from G-AHTR show clear signs of convergence toward the CLIP map.


Figure 4. Under-text image from cDDM and the activation map from CLIP for “itaq”.
| Original label | AHTR | G-AHTR |
| impossibile | impossibilitie | impossibile |
| solitudinis | solitudiiis | solitudinis |
| solatium | solattu um | solatium |
| construens | construeninininininininin | construeni |
| linea | lineama | linea |
Table 5. Example predictions from Synthetic Saint Gall (in Latin) show G-AHTR is less likely to hallucinate than AHTR, highlighting the advantage of language-guided HTR.
These findings deepen the understanding of how automatic methods could be applied and interpreted when developing and evaluating palimpsest reconstructions. Our G-AHTR method introduces a new paradigm in cross-modal regularisation by anchoring the HTR model’s visual attention to CLIP’s vision-language alignments via GALS (Guiding visual Attention with Language Specification) [23]. This framework offers a foundational guidance mechanism that can be extended across diverse domains.
Conclusion
This work advances automated palimpsest recovery by integrating structured noise modelling, generative reconstruction, and language-grounded recognition. We design a custom denoising diffusion model to capture layered degradation, explore Pix2pix GANs for restoration, and incorporate textual priors from vision-language attention maps for under-text recognition. Experiments demonstrate improved performance across diverse benchmarks. In particular, the cDDM2 + G-AHTR pipeline achieves the best word-level results and competitive overall scores, while yielding more interpretable attention behaviour. Performance variations across the synthetic MNIST, Saint Gall, and Georgian datasets stem from differences in ink properties, script complexity, and background noise, influencing the suitability of the GAN, diffusion, and HTR components. To support future research and standardised benchmarking, we release synthetic datasets, CLIP-compatible annotations, and pre-trained models.
Future work includes exploring other HTR architectures and generalisation, though we used AHTR for its ease of use and reproducible code. We plan to extend evaluations from word-level to line- and page-level, test on real palimpsests such as the Archimedes dataset, and fine-tune the CLIP model on large-scale handwriting corpora. Finally, we aim to establish a comprehensive benchmark for palimpsest research, including curated datasets, methods, and evaluation metrics.
Acknowledgments
This research was supported by the Kjell and Märta Beijer Foundation, and the Wallenberg AI, Autonomous Systems and Software Program (WASP) funded by the Knut and Alice Wallenberg Foundation. Computational resources were provided on the Berzelius system funded by the Knut and Alice Wallenberg foundation and operated by NAISS. The authors thank Prashant Singh and Anna Starynańska for valuable discussions and feedback, and the Action Editor and reviewers for their constructive comments.
References
- [1]Arpit Bansal, Eitan Borgnia, Hong-Min Chu, Jie Li, Hamid Kazemi, Furong Huang, Micah Goldblum, Jonas Geiping, and Tom Goldstein. 2023. Cold diffusion: Inverting arbitrary image transforms without noise. Advances in Neural Information Processing Systems, 36:41259–41282.arxiv.org/abs/2208.09392
- [2]Hila Chefer, Shir Gur, and Lior Wolf. 2021. Generic attention-model explainability for interpreting bi-modal and encoder-decoder transformers. In 2021 IEEE/CVF International Conference on Computer Vision (ICCV), pages 387–396. IEEE.arxiv.org/abs/2103.15679
- [3]Yung-Hsin Chen and Phillip B Ströbel. 2024. Trocr meets language models: An end-to-end post-correction approach. In International Conference on Document Analysis and Recognition, pages 12–26. Springer.
- [4]Min Jin Chong and David Forsyth. 2020. Effectively unbiased fid and inception score and where to find them. In Proceedings of the IEEE/CVF conference on computer vision and pattern recognition, pages 6070–6079.arxiv.org/abs/1911.07023
- [5]Li Deng. 2012. The mnist database of handwritten digit images for machine learning research [best of the web]. IEEE signal processing magazine, 29(6):141–142.DOI
- [6]Prafulla Dhariwal and Alexander Nichol. 2021. Diffusion models beat gans on image synthesis. Advances in neural information processing systems, 34:8780–8794.
- [7]Roger L. Easton, William A. Christens-Barry, and Keith T. Knox. 2011. Spectral image processing and analysis of the archimedes palimpsest. In 2011 19th European Signal Processing Conference, pages 1440–1444.
- [8]Andreas Fischer, Volkmar Fรinken, Alicia Fornés, and Horst Bunke. 2011. Transcription alignment of latin manuscripts using hidden markov models. In Proceedings of the 2011 workshop on historical document imaging and processing, pages 29–36.
- [9]2014. Generative adversarial networks. In Advances in Neural Information Processing Systems, volume 27. NeurIPS.arxiv.org/abs/1406.2661
- [10]Martin Heusel, Hubert Ramsauer, Thomas Unterthiner, Bernhard Nessler, and Sepp Hochreiter. 2017. Gans trained by a two time-scale update rule converge to a local nash equilibrium. Advances in neural information processing systems, 30.
- [11]Jonathan Ho, Ajay Jain, and Pieter Abbeel. 2020. Denoising diffusion probabilistic models. Advances in neural information processing systems, 33:6840–6851.arxiv.org/abs/2006.11239
- [12]Phillip Isola, Jun-Yan Zhu, Tinghui Zhou, and Alexei A Efros. 2017. Image-to-image translation with conditional adversarial networks. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), pages 1125–1134.arxiv.org/abs/1611.07004
- [13]Mahdi Jampour. 2025. Revealing palimpsests with latent diffusion models: A generative approach to image inpainting and handwriting reconstruction. In Proceedings of the Winter Conference on Applications of Computer Vision, pages 279–286.DOI
- [14]Mahdi Jampour, Hussein Mohammed, and Jost Gippert. 2024. Enhancing the readability of palimpsests using generative image inpainting. In ICPRAM, pages 687–694.
- [15]Sadeep Jayasumana, Srikumar Ramalingam, Andreas Veit, Daniel Glasner, Ayan Chakrabarti, and Sanjiv Kumar. 2024. Rethinking fid: Towards a better evaluation metric for image generation. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pages 9307–9315.arxiv.org/abs/2401.09603
- [16]Dmitrijs Kass and Ekta Yats. 2022. Attention-htr: Handwritten text recognition based on attention encoder-decoder networks. In International Workshop on Document Analysis Systems, pages 507–522. Springer.DOI
- [17]Hongliang Li, Dezhi Peng, and Lianwen Jin. 2025. Ego-lm: An efficient, generic, and out-of-the-box language model for handwritten text recognition. Pattern Recognition, 159:111130.DOI
- [18]Boraq Madi, Reem Alaasam, Raed Shammas, and Jihad El-Sana. 2023. Scheme for palimpsests reconstruction using synthesized dataset. International Journal on Document Analysis and Recognition (IJDAR), 26(3):211–222.DOI
- [19]Xudong Mao, Qing Li, Haoran Xie, Raymond YK Lau, Zhen Wang, and Stephen Paul Smolley. 2017. Least squares generative adversarial networks. In Proceedings of the IEEE international conference on computer vision, pages 2794–2802.arxiv.org/abs/1611.04076
- [20]Gustav Müller-Franzes, Jan Moritz Niehues, Firas Khader, Soroosh Tayebi Arasteh, Christoph Haarburger, Christiane Kuhl, Tianci Wang, Tianyu Han, Teresa Nolte, Sven Nebelung, et al. 2023. A multimodal comparison of latent denoising diffusion probabilistic models and generative adversarial networks for medical image synthesis. Scientific Reports, 13(1):12098.
- [21]Alexander Quinn Nichol and Prafulla Dhariwal. 2021. Improved denoising diffusion probabilistic models. In International conference on machine learning, pages 8162–8171. PMLR.arxiv.org/abs/2102.09672
- [22]Michela Perino, Michele Ginolfi, Anna Candida Felici, and Michela Rosellini. 2023. A deep learning experiment for semantic segmentation of overlapping characters in palimpsests. arXiv preprint arXiv:2311.01130.arxiv.org/abs/2311.01130
- [23]Suzanne Petryk, Lisa Dunlap, Keyan Nasseri, Joseph Gonzalez, Trevor Darrell, and Anna Rohrbach. 2022. On guiding visual attention with language specification. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pages 18092–18102.arxiv.org/abs/2202.08926
- [24]Alec Radford, Jong Wook Kim, Chris Hallacy, Aditya Ramesh, Gabriel Goh, Sandhini Agarwal, Girish Sastry, Amanda Askell, Pamela Mishkin, Jack Clark, et al. 2021. Learning transferable visual models from natural language supervision. In International conference on machine learning, pages 8748–8763. PMLR.arxiv.org/abs/2103.00020
- [25]Emanuele Salerno, Anna Tonazzini, and Luigi Bedini. 2007. Digital image analysis to enhance underwritten text in the archimedes palimpsest. International Journal of Document Analysis and Recognition (IJDAR), 9(2):79–87.DOI
- [26]Ramprasaath R Selvaraju, Michael Cogswell, Abhishek Das, Ramakrishna Vedantam, Devi Parikh, and Dhruv Batra. 2017. Grad-cam: Visual explanations from deep networks via gradient-based localization. In Proceedings of the IEEE international conference on computer vision, pages 618–626.
- [27]Sinai-Project. 2025. Ucla sinai library project.
- [28]Anna Starynska. 2023. Text Restoration in Palimpsested Historical Manuscripts Using Deep Learning Methods. Ph.D. thesis, Rochester Institute of Technology.
- [29]Anna Starynska, Roger L Easton Jr, and David Messinger. 2017. Methods of data augmentation for palimpsest character recognition with deep neural network. In Proceedings of the 4th International Workshop on Historical Document Imaging and Processing, pages 54–58.DOI
- [30]Anna Starynska, David Messinger, and Yu Kong. 2021. Revealing a history: palimpsest text separation with generative networks. International Journal on Document Analysis and Recognition (IJDAR), 24(3):181–195.DOI
- [31]Anna Tonazzini. 2010. Color space transformations for analysis and enhancement of ancient degraded manuscripts. Pattern Recognition and Image Analysis, 20(3):404–417.DOI
- [32]Mike Toth and Doug Emery. 2008. Archimedes palimpsest digital release.
- [33]Zhou Wang, A.C. Bovik, H.R. Sheikh, and E.P. Simoncelli. 2004. Image quality assessment: from error visibility to structural similarity. IEEE Transactions on Image Processing, 13(4):600–612.pubmed.ncbi.nlm.nih.gov/15376593
- [34]Zhou Wang and Alan C. Bovik. 2009. Mean squared error: Love it or leave it? a new look at signal fidelity measures. IEEE Signal Processing Magazine, 26(1):98–117.DOI
- [35]Zixiao Wang, Hongtao Xie, Yuxin Wang, Jianjun Xu, Boqiang Zhang, and Yongdong Zhang. 2023. Symmetrical linguistic feature distillation with clip for scene text recognition. In Proceedings of the 31st ACM international conference on multimedia, pages 509–518.arxiv.org/abs/2310.04999