1. Introduction
OCR has evolved from segmentation-driven pipelines toward fully end-to-end sequence modeling frameworks integrating visual encoding, alignment, and decoding within unified neural architectures. Early studies established variability modeling and alignment as core pattern recognition challenges [
1], while subsequent works formalized the detection–recognition pipeline paradigm [
2]. More recent surveys emphasize the transition toward deep learning-based, unified, and alignment-free frameworks. Despite these advances, cursive scripts—particularly Arabic and related Perso-Arabic scripts—continue to pose structural challenges that remain only partially resolved.
Arabic script is characterized by contextual letter shaping, ligatures, mandatory connectivity, optional diacritics, and high visual similarity among dotted characters. These properties complicate both segmentation-based and alignment-free recognition. Early omnifont systems explicitly addressed font variability [
3,
4,
5], but remained sensitive to segmentation errors and ligature overlap. In contrast, CTC-based sequence modeling enables direct mapping from visual features to character sequences [
6,
7,
8,
9,
10], improving robustness while introducing alignment ambiguity that interacts with typographic and orthographic variation.
CNN–BLSTM–CTC architectures have dominated Arabic OCR for over a decade across diverse applications, including document analysis and scene text recognition [
11]. Extensions, such as attention-augmented recurrent models [
12], improve performance, yet recurrent encoders inherently limit parallelization and global context modeling.
More recently, Transformer-based architectures have demonstrated strong capabilities in modeling long-range dependencies and cursive structures. Transformer–CTC frameworks confirm the compatibility of self-attention with alignment-free objectives [
7], while lightweight attention-based models [
13,
14] enable scalable recognition. Hybrid CNN–Transformer approaches further improve Arabic handwriting recognition [
15,
16]. In addition, multimodal systems [
17] and cross-script models such as TDA-ViT [
18] highlight the adaptability of attention-based architectures across structurally complex scripts.
Dataset scale has also emerged as a key driver of performance. Large-scale synthetic datasets, such as SARD [
19] and multi-font corpora [
20], as well as multilingual benchmarks like MOZHI [
21], demonstrate that typographic diversity and data scale significantly improve generalization. However, most existing studies report performance under fixed inference settings, without explicitly analyzing the contribution of decoding choices.
In parallel, Arabic-specific Transformer pretraining has significantly advanced contextual modeling. Models such as AraBERT [
22], AraT5 [
23], Transformer-CRF frameworks [
24], and unified speech–text systems [
25] demonstrate the importance of language-aware modeling. Similarly, Transformer-based speech recognition systems confirm the effectiveness of CTC–attention integration under diacritic-sensitive conditions [
26,
27].
However, prior work suggests that lexical modeling and decoding mechanisms can significantly affect recognition performance independently of encoder architecture.
Furthermore, evaluation protocols often rely on implicit orthographic assumptions, particularly regarding diacritic handling. This leads to systematic discrepancies between raw Unicode-preserved evaluation and normalized evaluation, potentially inflating or masking recognition errors.
Despite substantial progress in encoder architectures and dataset scaling, the role of inference strategies in Arabic printed OCR remains insufficiently characterized. Existing systems are typically evaluated under fixed decoding configurations, making it difficult to disentangle performance gains attributed to representation learning from those introduced at inference time. This limitation suggests that part of the reported improvements may originate from decoding mechanisms rather than encoder capacity alone.
This work shifts the evaluation paradigm in Arabic OCR from encoder-centric benchmarking toward a decoding-aware and normalization-aware perspective.
This work is motivated by the digitization and exploitation of historical Arabic legal documents, with the goal of integrating them into interactive legal systems capable of answering queries with supporting evidence. Beyond this application, the proposed approach can be extended to domains such as autonomous driving, machine translation, and assistive technologies for visually impaired users.
The primary objective of this work is to systematically investigate the impact of decoding strategies and orthographic processing on multi-font Arabic printed word recognition. To achieve this, we design a controlled experimental setup that isolates inference-level effects from encoder representation under identical training conditions.
The main contributions of this work are as follows:
We provide a controlled comparison between greedy CTC decoding and language-model-guided decoding under identical training conditions.
We introduce a normalization-aware evaluation framework quantifying the impact of diacritic removal.
We perform a cross-font analysis to study the interaction between typographic variability and alignment behavior.
We demonstrate that decoding and evaluation choices significantly influence reported performance, highlighting limitations of encoder-centric benchmarking.
2. Related Work
2.1. Segmentation-Based Arabic OCR: Structural Limitations
Early Arabic OCR systems relied on explicit character segmentation prior to classification. Omnifont frameworks were introduced to mitigate font variability without prior font identification [
3,
5], while recognition-driven segmentation strategies attempted to address ligature overlap and baseline ambiguity [
28]. More recent detection-driven pipelines, such as YOLO-based approaches [
29], reformulate recognition as a character detection task followed by lexical post-processing.
However, despite these incremental improvements, segmentation-based and detection-driven methods remain fundamentally incompatible with the structural properties of Arabic script. Contextual shaping, ligature formation, and diacritic attachment introduce inherent segmentation instability that directly propagates into recognition errors. These limitations are structural rather than incidental, and become more pronounced under multi-font variability, where stroke geometry and inter-character spacing fluctuate significantly.
More critically, these approaches treat segmentation as a prerequisite rather than a by-product of recognition, thereby imposing rigid assumptions on inherently continuous and context-dependent character boundaries. As highlighted in foundational studies [
1,
30], alignment—not segmentation—is the central challenge in sequence recognition. This perspective motivates the shift toward alignment-free formulations, where segmentation is implicitly resolved during sequence decoding rather than explicitly enforced during preprocessing.
2.2. CRNN and CTC: Alignment Without Segmentation
The introduction of Connectionist Temporal Classification (CTC) enabled alignment-free mapping from visual feature sequences to character outputs, eliminating the need for explicit segmentation. CNN–BLSTM–CTC architectures rapidly became dominant in Arabic OCR [
11,
31] and have been successfully extended to related Perso-Arabic scripts [
8,
32]. Large-scale implementations further confirm their effectiveness under fixed inference settings [
33], demonstrating robust sequence modeling under diverse typographic conditions.
However, while CTC removes segmentation dependency, it introduces intrinsic alignment ambiguity through blank-token collapse and repetition modeling, often resulting in a systematic deletion bias. This ambiguity is not merely a modeling artifact but a direct consequence of collapsing multiple valid alignments into a single output sequence. In Arabic script, these effects are further amplified by the presence of visually similar dotted characters and diacritic-sensitive tokens, increasing the likelihood of omission and substitution errors.
More fundamentally, CTC assumes conditional independence between output symbols given the visual features, limiting its ability to model higher-order linguistic dependencies. Evidence from diacritic-aware Arabic speech recognition [
26,
27] suggests that alignment-free objectives can systematically bias recognition toward simplified sequences, particularly in morphologically rich contexts where subtle orthographic distinctions carry semantic weight.
2.3. Transformer-Based OCR: Representation Scaling
Transformer architectures increasingly replace recurrent encoders in OCR systems, offering improved modeling of long-range dependencies and contextual relationships [
7,
13,
14]. In Arabic recognition tasks, hybrid CNN–Transformer models demonstrate enhanced capacity to capture cursive connectivity and complex character interactions [
15,
16,
34], particularly under multi-font variability where global context becomes essential.
Recent approaches further extend this paradigm through multimodal integration and multi-scale encoding strategies [
17,
35], highlighting the scalability of attention-based representations across diverse OCR settings. These models effectively address limitations of recurrent architectures by enabling parallel computation and richer contextual aggregation.
However, despite these representational advantages, many Transformer-based OCR systems remain largely encoder-centric, primarily focusing on feature extraction and representation scaling. This perspective may implicitly emphasize the role of encoder capacity in improving recognition performance. Nevertheless, it tends to underexplore the contribution of inference mechanisms, where decoding strategies and linguistic constraints can significantly influence the final output sequence.
As a result, performance gains attributed to Transformer architectures may partially reflect unexamined interactions between representation quality and inference configuration, rather than purely architectural improvements.
2.4. Dataset Scale and Synthetic Corpora
Dataset expansion has played a central role in improving Arabic OCR performance. Large-scale synthetic datasets, such as SARD [
19] and multi-font corpora [
20], significantly enhance generalization across typographic variations, while multilingual initiatives such as MOZHI [
21] demonstrate the scalability of sequence-based models across scripts.
Comparative studies in related Perso-Arabic scripts [
36] further confirm the robustness of Transformer-based architectures under heterogeneous conditions, suggesting that data diversity and scale are key drivers of performance gains.
However, these evaluations predominantly attribute improvements to architectural design and dataset size, while inference settings are typically fixed and not systematically analyzed. This practice implicitly assumes that recognition performance is primarily determined by representation quality, overlooking the potential contribution of decoding mechanisms.
Consequently, part of the observed performance gains may arise from unexamined interactions between dataset characteristics and inference configuration, rather than from data scale alone. This limitation highlights the need for controlled evaluation protocols that disentangle the effects of training data, model capacity, and inference strategy.
2.5. Language Modeling and Inference Strategies
Linguistic modeling has been shown to influence OCR performance beyond visual feature extraction. Post-recognition correction and lexical constraints can significantly improve output quality [
29], while contextual language models such as AraBERT [
22] and AraT5 [
23] demonstrate the importance of semantic and morphological context in Arabic sequence processing.
While language models and post-recognition correction techniques have been widely used to improve OCR outputs, inference strategies are typically treated as auxiliary components rather than explicitly analyzed as independent variables.
More critically, decoding is often implicitly coupled with model evaluation, making it difficult to distinguish improvements due to representation learning from those introduced by linguistic constraints during inference. As a result, the contribution of inference-level regularization remains under-characterized, and its interaction with script-specific properties, such as diacritics and morphological variability, is insufficiently understood.
2.6. Identified Gap
Across segmentation-based methods, CTC-based architectures, Transformer-driven models, and large-scale datasets, the dominant research emphasis remains encoder-centric. While architectural innovations and data scaling have significantly advanced recognition performance, they are typically evaluated under fixed inference settings, without explicitly isolating the contribution of decoding strategy and orthographic normalization.
Consequently, improvements are often implicitly attributed to representation learning, making it difficult to determine whether reported gains arise from model capacity, dataset properties, or inference-level regularization.
More specifically, prior work has not rigorously compared greedy CTC decoding and language-model-guided decoding under identical training conditions, nor has it systematically quantified the impact of orthographic normalization at the character-error level. This limitation is particularly critical in Arabic OCR, where diacritics, ligature variability, and morphological richness introduce additional sources of ambiguity.
This gap motivates the need for a decoding-aware and normalization-aware evaluation framework that explicitly disentangles representation learning from inference and evaluation effects in multi-font Arabic printed OCR.
3. Materials and Methods
This section provides the formal mathematical formulation of the proposed recognition framework, which is instantiated during training in Algorithm 1.
3.1. Problem Formulation
Let
denote a grayscale word image rendered in one of multiple Arabic font families (see Equation (1)). The objective is to learn a mapping.
is a sequence of symbols drawn from a predefined vocabulary V of Unicode character tokens, as defined in Equation (2). The vocabulary V defines the set of all possible output symbols considered by the model.
Here, represents the parametric function implemented by the CNN–Transformer–CTC model, denotes the set of all trainable parameters, and is the length of the output sequence.
The learning objective must account for the lack of explicit character-level alignment and the structural properties of Arabic script, including contextual shaping and optional diacritics. Decoding and evaluation are introduced only at inference time.
3.2. Visual Feature Encoding
Each input image is resized to a fixed height while preserving the aspect ratio, ensuring consistent vertical
H resolution across font families. A deep convolutional encoder extracts hierarchical spatial features, as defined in Equation (3):
Here, denotes a standard convolutional neural network encoder composed of stacked convolutional layers with nonlinear activations and pooling operations. It maps the input image into a hierarchical feature representation .
To convert the spatial feature map into a temporal sequence suitable for sequence modeling, a convolutional projection is first applied to map the channel dimension to a fixed embedding size. This is followed by a mean pooling operation over the vertical (height) dimension, resulting in a sequence representation, as expressed in Equation (4):
This formulation preserves horizontal spatial structure while aggregating vertical information, allowing the model to capture stroke geometry, curvature transitions, and diacritic placement patterns critical for distinguishing visually similar Arabic characters.
3.3. Contextual Sequence Modeling via Transformer Encoder
To model long-range dependencies within the visual sequence, we employ a Transformer encoder composed of stacked multi-head self-attention layers. Positional encodings (PEs) are added to the input sequence to retain ordering information, as shown in Equation (5):
The functions
,
, and
correspond to standard Transformer components [
37].
captures contextual dependencies across multiple heads.
stabilizes training.
produces probability distributions, and
denotes the position-wise feedforward network.
These components are not newly defined functions but standard architectural blocks used in Transformer-based sequence modeling.
These operations are formally defined in Equations (6)–(8). Each transformer layer applies the following:
followed by a position-wise feedforward network and residual normalization.
Self-attention enables global receptive field modeling, allowing contextual disambiguation of dotted character clusters and ligature-bound structures. Unlike recurrent encoders, the Transformer processes the full sequence in parallel, mitigating sequential bottlenecks while enhancing contextual coherence.
3.4. CTC-Based Alignment-Free Objective
The contextual sequence is projected onto the character vocabulary augmented with a blank symbol, as specified in Equation (9):
where
denotes the predicted probability of symbol
at timestep
over the extended label space
, obtained from the softmax output in Equation (9). In particular,
represents the probability assigned to the symbol
at timestep
.
The CTC objective defines the probability of a target sequence by marginalizing over all valid alignment paths, as formalized in Equation (10). Let denote the set of all alignment paths that collapse to under the mapping .
Here, denotes an alignment path over the extended label space (including the blank symbol), rather than a probability distribution. Each path represents a possible alignment between the input sequence and the target sequence.
The CTC formulation defines the conditional probability
by summing over all valid alignment paths
, where
is the collapse function that removes repeated labels and blank symbols to produce the final output sequence
.
where
B denotes the collapse function, removing repeated labels and blanks.
The training loss is defined in Equation (11):
No auxiliary attention losses or language modeling objectives are incorporated during training. This strict formulation ensures that representational learning remains disentangled from lexical regularization.
3.5. Decoding Configuration
All experiments are conducted using a fixed trained model, with variations applied only at the decoding stage.
3.5.1. Greedy Decoding
The greedy hypothesis is obtained by timestep-wise maximum selection, as expressed in Equation (12):
where
denotes the predicted probability of character (
c) at timestep (
t).
The final output sequence is obtained by applying the standard CTC collapse operation, which removes repeated labels and blank tokens. Greedy decoding performs no sequence-level linguistic regularization and therefore reflects purely encoder-driven predictions.
3.5.2. Language-Model-Guided Decoding
Beam search decoding integrates an external n-gram language model
to introduce lexical constraints during inference. The final hypothesis maximizes the following score, as defined in Equations (13) and (14):
where
controls the influence of the language model,
is a length regularization parameter,
denotes the predicted sequence length.
The language model is trained independently on external Arabic text and remains separate from visual representation learning. The beam size is fixed at 50. Hyperparameters are selected from and using a held-out subset of the synthetic validation data (Dval). These values are fixed before final evaluation and are never tuned on APTI.
Figure 1 illustrates two inference branches operating on identical CTC probability sequences. Greedy decoding performs independent timestep-wise selection, whereas beam search incorporates an external language model to optimize sequence-level consistency. This comparison isolates inference-level effects and enables direct evaluation of the role of decoding in recognition performance.
Both decoding branches operate on identical CTC probability sequences (Equation (9)), ensuring that any observed differences arise solely from the decoding strategy.
Greedy decoding performs independent timestep-wise maximization, whereas beam search incorporates an external language model to optimize a sequence-level score (Equations (13) and (14)).
This controlled setup isolates inference-level effects and enables a direct comparison between encoder-driven predictions and linguistically regularized outputs.
3.5.3. Language Model Construction and Statistical Properties
The external language model (LM) integrated during beam search decoding was constructed independently of the visual training corpus to enforce strict separation between representational learning and inference-level lexical regularization. The LM was trained on a cleaned Arabic Wikipedia corpus comprising 18,939,244 sentences (2.33 GB UTF-8 text), corresponding to 142,618,573 tokens after preprocessing. Sentence-level deduplication against the APTI benchmark was performed prior to estimation to eliminate potential lexical leakage.
A 3 g statistical language model was estimated using the KenLM toolkit with modified Kneser–Ney smoothing. The resulting binary model contains 1,412,903 unigrams, 38,721,114 bigrams, and 214,603,557 trigrams, yielding a compressed representation of 3.42 GB. No pruning was applied, ensuring maximal contextual coverage and avoiding artificial vocabulary constraints.
Model perplexity was computed on a held-out 5% partition (7,130,928 tokens), yielding a perplexity of 218.6. This value reflects moderate open-domain predictability, consistent with general Arabic language modeling rather than benchmark-specific memorization.
To characterize domain compatibility, lexical overlap with the APTI benchmark was quantified. Word-level vocabulary overlap reached 52.4%, while the out-of-vocabulary (OOV) rate relative to APTI was 27.3%. These statistics indicate that the LM operates under non-trivial domain mismatch conditions and does not rely on closed-vocabulary assumptions.
3.6. Training Algorithm
Algorithm 1 describes the end-to-end training procedure of the proposed CNN–Transformer–CTC model under a strictly alignment-free CTC objective. The model architecture is introduced in
Section 3 (Materials and Methods), where feature extraction, Transformer-based sequence modeling, and the CTC objective are formally defined.
The formulation introduced in
Section 3 directly defines the computational pipeline implemented during training. In particular, the feature extraction (Equation (3)), Transformer-based sequence modeling (Equations (5)–(8)), and the CTC objective (Equations (9)–(11)) are instantiated as described in Algorithm 1.
The training pipeline is deliberately designed to disentangle representational learning from the decoding pipeline and diacritic normalization, which are treated as independent experimental variables during evaluation.
It is important to distinguish between the validation procedure used during training and the final evaluation protocol. All training-time validation operations, including early stopping, greedy decoding evaluation, and hyperparameter tuning of , are performed exclusively on a held-out subset of the synthetic dataset (). This subset is derived from the same distribution as the training data and is not related to the APTI benchmark.
The purpose of this validation stage is solely to monitor optimization convergence and select decoding hyperparameters, without introducing any external evaluation bias.
In contrast, the APTI benchmark is used only for final inference-time evaluation after training is fully completed. The trained model remains fixed, and no hyperparameter tuning or model selection is performed on APTI. Importantly, training, validation, and evaluation are strictly separated, ensuring that the APTI benchmark has no influence on model optimization or hyperparameter selection.
This strict separation ensures that reported results reflect true generalization performance under unseen multi-font conditions, without contamination from validation or tuning procedures.
| Algorithm 1: Training CNN–Transformer–CTC Model with Validation-Time LM Decoding
|
1: INPUT: D_train, D_val, vocabulary V (blank = 0), KenLM model 2: OUTPUT: trained parameters, best checkpoints, validation metrics 3: INITIALIZE random seed 4: BUILD token_to_id mapping from V 5: BUILD CTC beam decoder (beam = 50) with KenLM 6: CONSTRUCT CNN–Transformer–CTC model 7: CNN stem: 8: Conv(1 → 64) + ReLU + MaxPool(2 × 2) 9: Conv(64 → 128) + ReLU + MaxPool(2 × 2) 10: Conv(128 → 256) + ReLU + MaxPool(2 × 1) 11: SET width_downsample ← 4 12: APPLY 1 × 1 Conv: 256 → 384 13: APPLY mean over height → (B, T, 384) 14: SET T ← ceil(W/4) 15: ADD sinusoidal positional encoding 16: APPLY Transformer encoder (6 layers, 6 heads, FFN = 4D, GELU, pre-norm) 17: APPLY Linear layer: 384 → C → logits (B, T, C) 18: INITIALIZE AdamW (lr = 2 × 10−4, wd = 1 × 10−4) 19: INITIALIZE CTCLoss (blank = 0) 20: SET gradient_clip ← 5 21: FOR each epoch DO 22: FOR each mini-batch DO 23: PREPROCESS image (grayscale, resize H = 80, normalize x = 1 − img/255) 24: COMPUTE in_lens ← ceil(x_lens/4) 25: CLAMP in_lens to T_max 26: BUILD padding mask from in_lens 27: IF y_lens > in_lens THEN 28: SKIP batch 29: END IF 30: FORWARD pass (masked) 31: APPLY log-softmax 32: COMPUTE CTC loss 33: BACKPROPAGATE gradients 34: CLIP gradients 35: OPTIMIZER step 36: END FOR 37: TUNE (α, β) via grid-search minimizing CER 38: EVALUATE greedy and LM decoding on validation set
40: SAVE checkpoint 41: UPDATE best model 42: EARLY STOP if no improvement 43: END FOR |
Algorithm 1 summarizes the training pipeline rather than defining a new optimization method. In particular, AdamW is employed as a standard optimizer within this procedure, while Algorithm 1 captures the full pipeline, including preprocessing, forward propagation, loss computation, and evaluation.
The hyperparameters of AdamW (learning rate lr = 2 × 10−4 and weight decay wd = 1 × 10−4) were selected based on standard practices for training Transformer-based architectures and validated through preliminary experiments. All hyperparameters are explicitly specified to ensure the reproducibility of the reported results.
The beam decoder and KenLM are instantiated only for validation and are used exclusively for hyperparameter selection, without any involvement in gradient computation or model optimization.
3.7. Orthographic Normalization Protocol
Arabic orthography introduces optional diacritics and character variants that may bias evaluation. To quantify this effect, we define two evaluation regimes:
Raw evaluation, preserving full Unicode transcription.
Normalized evaluation applies deterministic preprocessing, as specified in Equation (15):
where
removes diacritics and TATWEEL while preserving canonical character identity.
This dual evaluation enables explicit measurement of diacritic omission bias and alignment-induced deletion behavior.
3.8. Training Strategy Overview
Training is performed using AdamW optimization with learning rate scheduling and gradient clipping. Mixed precision acceleration and deterministic seeding ensure reproducibility.
CER and word accuracy are reported under both evaluation protocols to disentangle architectural performance from orthographic and decoding-induced effects.
3.9. Theoretical Considerations on CTC Deletion Behavior
The following analysis provides theoretical insight into CTC-based sequence modeling and supports the interpretation of the experimental results.
CTC optimizes sequence likelihood by marginalizing over all valid alignment paths.
Let denote an alignment path over the extended vocabulary .
The CTC collapse operation removes repeated labels and blank tokens to produce the final emitted sequence.
If
denotes the predicted blank probability at timestep
, and then the expected emitted sequence length after collapse is approximately proportional to Equation (16):
When blank probabilities dominate across timesteps, the effective emitted sequence length decreases, increasing deletion likelihood relative to insertion events. This structural asymmetry has been theoretically analyzed and empirically observed in alignment-free sequence models.
However, in the present configuration, all Arabic diacritics were deliberately excluded from the training vocabulary V. Consequently, the model is structurally incapable of predicting any diacritic during inference. Let denote the original Unicode ground truth and its diacritic-stripped form. Because , any SHADDA token present in cannot appear in the predicted sequence .
Therefore, SHADDA deletion under raw evaluation is deterministic and reflects an explicit vocabulary design constraint rather than stochastic CTC alignment instability.
This controlled exclusion isolates orthographic mismatch effects from genuine CTC-induced deletion bias affecting base characters. Base-character deletion reflects alignment dynamics, whereas SHADDA omission reflects vocabulary design. The observed diacritic-induced inflation, therefore, does not indicate model instability.
3.10. Formal Error Decomposition
To quantify decoding and normalization effects, we decompose the CER into three components, as expressed in Equation (17):
where
S denotes substitutions,
D denotes deletions,
I denotes insertions, and
N denotes the reference character count.
We further decompose deletions into alignment-induced and orthographic components, as defined in Equation (18):
where
denotes alignment-induced deletions (CTC blank dominance) and
denotes orthographic deletions (e.g., diacritic removal).
Under normalized evaluation, the character error rate is computed as defined in Equation (19):
with
.
The relative reduction is defined as the difference between raw and normalized character error rates, as expressed in Equation (20):
which quantifies the contribution of orthographic sensitivity to the total error.
Similarly, decoding-induced gain is defined as the difference between greedy and language-model-guided character error rates, as expressed in Equation (21):
This decomposition enables explicit separation of representational error, alignment-induced deletion, orthographic sensitivity, and lexical regularization effects. Such structured separation is rarely reported in the Arabic printed OCR literature.
3.11. Computational Complexity Analysis
We briefly analyze the computational complexity of the main components of the proposed model. Let T denote the sequence length after CNN downsampling, d the embedding dimension, h the number of attention heads, L the number of Transformer layers, and U the target transcription length.
3.11.1. CNN Encoder
The computational cost of convolutional layers is determined by the number of multiply–accumulate operations required to compute each output feature map.
The convolutional backbone complexity scales as , where and denote spatial dimensions of the input feature map, is the kernel size, and and are the numbers of input and output channels, respectively. Under the common assumption , this simplifies to .
3.11.2. Transformer Encoder
Self-attention dominates the encoder complexity: .
This quadratic dependency arises from the computation of the attention matrix of size . However, since word-level recognition yields moderate sequence lengths, the computational cost remains tractable.
3.11.3. CTC Forward–Backward
The dynamic programming recursion used in CTC training incurs: where U denotes the target sequence length.
3.11.4. Beam Search with Language Model
Beam search decoding complexity approximately scales as
where
B is the beam width and
the vocabulary size.
Language model integration introduces additional scoring cost: assuming near-constant-time n-gram lookup. Importantly, LM-guided decoding affects inference complexity but does not alter training complexity.
Figure 2 illustrates the overall processing pipeline, where input word images are encoded into visual features, transformed into sequential representations, and mapped to character probabilities using the CTC objective. During inference, the representation remains fixed while different decoding strategies are applied, enabling controlled evaluation of decoding effects independently of the learned features.
At inference time, the encoder and CTC probability outputs remain fixed, while two decoding configurations are systematically evaluated: standard greedy decoding and language-model-guided beam search. Greedy decoding performs timestep-wise maximum probability selection followed by repetition and blank collapse. In contrast, beam search integrates an external n-gram language model (KenLM) and optimizes a joint scoring function combining optical likelihood and linguistic prior. This configuration enables a direct comparison between decoding strategies.
3.12. Visual Attention Analysis
To provide qualitative evidence of contextual modeling behavior, we visualize averaged multi-head self-attention maps from the first (L0) and last (L5) Transformer layers under both greedy and language-model-guided decoding (
Figure 3). The visualization reveals a clear representational hierarchy: L0 attention exhibits predominantly diagonal structure, reflecting localized stroke-level dependencies, whereas L5 demonstrates broader vertical and off-diagonal activations indicative of global contextual integration.
No observable structural differences are found between greedy and language-model-guided decoding outputs, confirming that improvements arise from inference-level scoring rather than changes in encoder representations.
3.13. Training Dataset
The proposed recognition framework is trained exclusively on a large-scale synthetic multi-font Arabic word corpus constructed independently of the APTI benchmark. Under no circumstances are APTI samples, annotations, font resources, validation splits, or linguistic statistics used during model training, hyperparameter tuning, or language model construction.
The textual source comprises 55,833 non-diacritized Arabic tokens extracted from a curated corpus. The vocabulary includes lexical words, numeric expressions, date-like patterns, and punctuation symbols, ensuring lexical and structural diversity. Diacritical marks are intentionally excluded during training, consistent with the alignment-based CTC formulation.
Each token is rendered across ten Arabic font families (AdvertisingBold, Andalus, ArabicTransparent, DecoTypeNaskh, DecoTypeThuluth, DiwaniLetter, MUnicodeSara, SimplifiedArabic, Tahoma, TraditionalArabic), covering a wide range of typographic styles, including geometric, regular, and calligraphic forms. Rendering is performed at six font sizes {6, 8, 10, 12, 16, 24}, introducing controlled variability in stroke thickness, curvature, ligature density, and inter-character spacing.
Arabic shaping is handled using RAQM when available; otherwise, reshaping with bidirectional reordering is applied. To ensure robust rendering across heterogeneous font encodings, we use a glyph-level fallback mechanism. Characters unsupported by the primary font are rendered with a secondary fallback font while preserving layout continuity.
Rendering is performed using supersampling (×5), followed by downsampling to a fixed height H = 80 pixels while preserving the aspect ratio. Foreground-tight cropping is applied to remove extraneous margins and ensure spatial compactness.
A light stochastic augmentation pipeline (applied with probability 0.5) introduces mild brightness and contrast jitter (±5%), additive Gaussian noise (σ = 3), slight Gaussian blur (radius = 0.2), optional autocontrast normalization, and controlled unsharp masking. These transformations simulate realistic acquisition variability while preserving readability.
The dataset is split at the token level using a 95/5 train–validation ratio prior to font expansion. The final rendered corpus contains 3,349,980 word images. A character vocabulary is constructed exclusively from the training split.
Dataset generation is fully parallelized and strictly deterministic. A global random seed is fixed, and each sample is generated using a deterministic per-sample seed derived from the token, font, and rendering configuration, ensuring that identical images can be reproduced across runs. The generation pipeline follows a well-defined procedure and enables full reproducibility of the dataset.
For clarity and reproducibility, the dataset generation process is summarized in Algorithm 2.
| Algorithm 2: Synthetic Arabic Word Dataset Generation
|
Input: Token set T; Font set F; Font sizes S; Global seed s Output: Rendered dataset D 1: Initialize global random seed s 2: for each token t ∈ T do 3: for each font f ∈ F do 4: for each size z ∈ S do 5: Compute deterministic seed s′ = hash(t, f, z, s) 6: Apply Arabic shaping (RAQM if available, otherwise reshaping + bidi) 7: if font f supports all glyphs in t then 8: Render t using font f 9: else 10: Split t into glyph-supported runs 11: Render each run using f or fallback font 12: Concatenate rendered segments 13: Apply supersampling rendering 14: Resize image to fixed height H 15: Apply foreground-tight cropping 16: Apply stochastic augmentation with probability p: 17: - brightness/contrast jitter 18: - Gaussian noise 19: - slight blur/sharpening 20: Save image using deterministic naming 21: end for 22: end for 23: end for 24: return D |
Implementation details:
Font sizes: {6, 8, 10, 12, 16, 24}
Output height: H = 80 pixels
Supersampling factor: 5
Augmentation (applied with probability 0.5):
- -
brightness jitter ± 5%
- -
contrast jitter ± 5%
- -
Gaussian noise (σ = 3)
- -
Gaussian blur (radius = 0.2)
- -
optional unsharp masking
Fonts: 10 Arabic font families
Fallback font: Tahoma
Token count: 55,833
Total images: 3,349,980
Train/validation split: 95%/5%
Global random seed: fixed
Per-sample seed: deterministic
3.14. Evaluation Dataset
Evaluation is conducted exclusively on the APTI benchmark, a multi-font word-level dataset for printed Arabic recognition. APTI contains diverse typographic configurations, including variations in font style (bold, regular, and stylized), stroke thickness, ligature density, character spacing, and diacritic placement.
APTI is used strictly for evaluation and is never accessed during training or validation, ensuring a clear separation between training and testing data and enabling genuine cross-dataset generalization.
For reproducibility, all experiments are conducted using fixed random seeds and predefined evaluation subsets, as detailed in
Section 3.15.
3.15. Evaluation Protocol
A dual evaluation framework is adopted (
Figure 4), comparing greedy and language-model-guided decoding under both raw and normalized protocols. The difference
quantifies the impact of diacritic mismatch on evaluation.
Training is performed on a synthetic dataset generated using the procedure described in
Section 3.13. All training-time validation operations, including early stopping, greedy decoding evaluation, and hyperparameter tuning
, are conducted exclusively on a held-out subset of this synthetic dataset. Hyperparameter tuning is performed periodically (every 3 epochs) on a fixed subset of 500 samples from the synthetic validation set.
In contrast, the final evaluation is conducted only after training is fully completed, using the APTI benchmark. For each font, a fixed subset of 188,700-word images is randomly sampled using a predefined random seed to ensure reproducibility.
The validation split contains approximately 167k samples derived from the synthetic dataset.
The trained model remains fixed during evaluation, and no hyperparameter tuning or model selection is performed on APTI.
This strict separation between synthetic validation and APTI evaluation prevents any evaluation leakage and ensures that reported results reflect true generalization performance under unseen multi-font conditions.
3.16. Evaluation Metrics
CER is computed as defined in
Section 3.10 (Formal Error Decomposition).
Word accuracy (WA) is defined as the ratio of correctly predicted words to the total number of evaluated words, as expressed in Equation (22):
where this metric measures exact word-level prediction accuracy.
Decoding gain is quantified as the difference between greedy and language-model-guided character error rates, as expressed in Equation (23):
where orthographic sensitivity is measured as the difference between raw and normalized character error rates, as defined in Equation (24):
3.17. Implementation Details
All experiments were implemented in PyTorch (version 2.7.0, CUDA 12.8, cuDNN 9.7) and trained on a single NVIDIA GeForce RTX 5070 Ti GPU using mixed-precision training (AMP) to improve computational efficiency and memory utilization.
The proposed CNN–Transformer–CTC architecture begins with a convolutional stem composed of three convolutional blocks, Conv(1 → 64, 3 × 3, stride = 1, padding = 1), Conv(64 → 128, 3 × 3, stride = 1, padding = 1), and Conv(128 → 256, 3 × 3, stride = 1, padding = 1), each followed by activation and max pooling (2 × 2, 2 × 2, and 2 × 1, respectively). This configuration results in a horizontal downsampling factor of 4 and a vertical reduction to H/8.
A (1 × 1) convolutional projection maps the 256-channel feature map to a model dimension D = 384 while preserving spatial resolution. Height-wise average pooling then converts the spatial feature map into a temporal sequence of shape (B, T, 384), where T = ⌈W/4⌉.
Sinusoidal positional encoding is added before feeding the sequence into a Transformer encoder composed of 6 layers with 6 attention heads each, a feed-forward dimension of 4D = 1536, GELU activation, pre-layer normalization (norm-first configuration), and dropout set to 0.1. A final linear projection maps the 384-dimensional embeddings to C output classes, where C denotes the character vocabulary size, including the blank symbol.
For reproducibility, the tensor shapes across the pipeline are explicitly defined as follows:
Input image: (B, 1, H = 80, W)
After CNN encoder: (B, 256, H′, W′) with H′ = H/8 and W′ = W/4
After 1 × 1 projection: (B, 384, H′, W′)
After height-wise average pooling: (B, T = W′, 384)
Transformer input/output: (B, T, 384)
Final logits: (B, T, C)
Training was performed using the AdamW optimizer with a learning rate of and weight decay of . The CTC loss function was used with blank index 0 and zero_infinity enabled to prevent infinite loss values when input lengths are shorter than target lengths. Gradient norms were clipped to a maximum value of 5.0. The model was trained for 30 epochs with a batch size of 64, and all experiments were conducted with a fixed random seed of 123 to ensure reproducibility. A ReduceLROnPlateau scheduler was applied with mode set to “min”, reduction factor 0.5, patience of 2 epochs, and minimum learning rate , and threshold = (relative mode). Early stopping was triggered if the greedy CER did not improve for 5 consecutive epochs after an initial warm-up period of 5 epochs. All hyperparameters were fixed prior to the final evaluation and were not tuned on the APTI benchmark.
At inference time, decoding was performed using both greedy decoding and beam search with a beam width of 50, integrated with an external n-gram language model (KenLM). Language model interpolation parameters were tuned via grid search with and . Tuning was conducted every 3 epochs on a fixed validation subset of 500 samples.
The beam decoder and KenLM are used exclusively during validation for hyperparameter selection and are not involved in gradient computation or model optimization.
Final evaluation was performed on a fixed subset of 188,700 samples per font from the APTI benchmark. Recognition performance was measured using CER, and both greedy and language-model-guided CER were reported. Character-level confusion matrices were computed via Levenshtein alignment to analyze substitution, deletion, and insertion patterns.
4. Results
This section reports a fully stratified statistical evaluation of the proposed CNN–Transformer–CTC model on the APTI benchmark. Metrics are computed using paired bootstrap resampling (B = 5000) and permutation-based correlation testing (20,000 permutations).
To facilitate the interpretation of the results, we summarize the main findings as follows:
Decoding strategy introduces a systematic reduction in CER, with a relative improvement of approximately 61.0% under normalized evaluation.
Orthographic normalization isolates deterministic diacritic-induced errors, particularly related to SHADDA omission.
Cross-font variability significantly affects evaluation sensitivity, highlighting strong typographic modulation of recognition performance.
4.1. Decoding Performance (Greedy vs. KenLM)
Under normalized evaluation on the full APTI set (diacritics removed), greedy CTC decoding achieves word accuracy = 93.20% and CER = 0.01196 (1.196%). KenLM-guided beam search improves performance to word accuracy = 97.68% and CER = 0.00467 (0.467%).
The absolute CER reduction is 0.00729, corresponding to a relative reduction of approximately 61.0%. Paired bootstrap resampling confirms that this improvement is statistically significant (p < 0.001).
To quantify orthographic sensitivity independently of the decoding scheme, we further analyze the SHADDA-bearing subset (≈5.08% of tokens). Paired bootstrap resampling yields ΔCER = 0.138557 (95% CI [0.137500, 0.139586]), with a large standardized effect size (Cohen’s d = 2.579, 95% CI [2.494, 2.666]) and relative inflation of 266.62% (95% CI [254.28%, 279.01%]). The one-sided bootstrap test confirms statistical significance (p < 0.001).
These results show that decoding substantially improves normalized recognition performance. By contrast, raw Unicode-preserved evaluation mainly reflects deterministic SHADDA mismatch rather than structural recognition instability.
Figure 5 presents representative qualitative examples grouped into three categories: (Col1) perfect LM correction (
), (Col2) substantial gain (ΔCER ≥ 0.20), and (Col3) moderate gain (0 < ΔCER < 0.20). Across all ten font families, LM-guided decoding consistently resolves dot-sensitive substitutions, ligature ambiguities, and alignment-induced deletions without introducing over-regularization. These qualitative observations align with the statistically significant decoding gains reported in
Section 4.1.
4.2. Stratified Evaluation with Full Confidence Intervals
Table 1 reports per-font structural character error rate (CER) metrics under raw, normalized (diacritics removed), and non-diacritic evaluation protocols. The confidence intervals correspond to 95% bootstrap estimates.
Table 2 ΔCER, relative inflation, and effect sizes across fonts.
Relative inflation becomes numerically unstable when approaches zero; therefore, ΔCER and Cohen’s d are considered primary effect measures.
4.3. Meta-Analysis of ΔCER Across Fonts
For the fixed-effects model, ΔCER = 0.147111 [0.146341, 0.147881]. For the random-effects model, ΔCER = 0.138786 [0.131484, 0.146089]. Between-font heterogeneity is extreme . The large discrepancy between fixed- and random-effects estimates reflects extreme between-font heterogeneity, justifying the use of random-effects aggregation as the primary summary estimate.
4.4. Correlation and Heterogeneity Drivers
Permutation testing (20,000 permutations, two-sided) indicates no statistically significant association between the proportion of diacritized words (%Diac) and ΔCER (Pearson ). This confirms that the inflation magnitude is not driven by diacritic prevalence across fonts, which is nearly constant in APTI.
In contrast, baseline structural difficulty—quantified via —exhibits a negative association with ΔCER under rank-based testing . This suggests that fonts with lower baseline non-diacritic error tend to display larger orthographic inflation, whereas structurally complex fonts with higher show attenuated ΔCER magnitudes.
However, given the limited number of fonts (k = 10), correlation estimates should be interpreted with caution. The small sample size implies limited statistical power, increased variance in effect estimates, and sensitivity to individual data points. Accordingly, these associations should be regarded as exploratory rather than confirmatory evidence of heterogeneity drivers.
5. Discussion
The empirical results confirm that diacritic-induced inflation is deterministic and evaluation-driven rather than representational in nature. The observed heterogeneity across fonts further indicates that typographic structure interacts with the evaluation protocol in non-trivial ways, reinforcing the necessity of normalization-aware benchmarking in Arabic OCR.
Importantly, under normalized evaluation, the structural CER reaches 0.00467 (0.467%), demonstrating that the proposed encoder achieves near state-of-the-art structural accuracy without benchmark-specific training exposure. This finding reinforces the cross-dataset robustness of the learned representation and confirms that the observed raw inflation is orthographic rather than representational in nature.
The extreme heterogeneity (
) further indicates that typographic characteristics strongly modulate orthographic amplification effects. Fonts with near-zero
and very small
values exhibit the largest relative inflation percentages. When
approaches zero (e.g., AdvertisingBold), as expressed in Equation (25), the relative inflation metric
becomes numerically unstable and may reach very large values (>4000%). This phenomenon is purely mathematical and does not imply disproportionately large structural recognition failure; rather, it reflects division by a near-zero baseline. Accordingly, ΔCER and Cohen’s d provide more stable and interpretable effect measures than relative inflation alone.
Collectively, these findings justify reporting both raw and normalization-aware metrics in Arabic OCR evaluation to avoid orthographic bias and misinterpretation of deterministic diacritic omission as alignment-induced instability. Moreover, since APTI includes only SHADDA and at most one diacritic per affected word, the measured inflation represents a lower-bound scenario. Benchmarks containing richer diacritic inventories would likely exhibit proportionally greater orthographic sensitivity under raw Unicode-preserved evaluation, particularly in models trained without explicit diacritic modeling.
Figure 6 Character-level error distribution on APTI. Under raw Unicode-preserved evaluation, deletions dominate due to deterministic SHADDA omission resulting from vocabulary exclusion. Normalized evaluation (diacritics removed) reveals structurally driven substitution patterns and a minimal insertion rate, confirming that orthographic mismatch—not stochastic alignment instability—is the primary source of raw CER inflation.
To further investigate font-dependent structural error patterns beyond aggregate deletion and substitution counts,
Figure 7 presents row-normalized character-level confusion heatmaps across the ten evaluated font families. These matrices reveal systematic dot-sensitive substitutions and font-specific alignment behavior that are not fully captured by global CER statistics.
5.1. Comparison with State-of-the-Art
To position the proposed framework within the Arabic OCR literature, we compare it against both detection-driven and sequence-based systems evaluated on APTI and related benchmarks. Unlike prior work, the proposed framework explicitly separates training, decoding, and evaluation. Training conditions are fixed, while decoding and evaluation protocols are isolated at inference time.
Table 3 reports paradigm-level differences alongside the exact performance values as published in the original studies.
Detection-driven OCR, such as the YOLO4-based system of [
29], reports 82.4% WRR and 95.7% CRR on APTI under a diacritic-ignored protocol. The pipeline relies on character detection followed by overlap filtering and dictionary-based correction using Hunspell and edit-distance selection. Recognition and linguistic regularization are therefore structurally decoupled.
Sequence-based CTC systems such as ADOCRNet [
33] report extremely low error rates on APTI, with CER = 0.03% under a fixed decoding method using the official dataset split. However, their training and evaluation are conducted within the same benchmark distribution. In contrast, the proposed framework is trained exclusively on a fully independent large-scale synthetic corpus and evaluated under strict zero-shot cross-dataset conditions, without exposure to APTI samples during training, hyperparameter tuning, or language model construction. Consequently, while ADOCRNet demonstrates strong benchmark-specific performance, the present results emphasize cross-dataset generalization and controlled decoding isolation.
Transformer encoder–decoder systems such as ALNASIKH [
35] report CER = 0.8% on their printed Arabic benchmark, while DTrOCR [
38] reports 98.5% word accuracy on non-diacritized text and 89.9% on diacritized evaluation. These approaches primarily focus on encoder–decoder scaling and contextual modeling, whereas the present study explicitly isolates decoding strategy and diacritic removal as independent experimental variables.
Under greedy decoding, our CNN–Transformer–CTC framework achieves 93.20–word accuracy (CER = 0.01196). When language-model-guided beam search is applied under identical encoder parameters, performance increases to 97.68–word accuracy (CER = 0.00467). Controlled ablation shows that the decoding pipeline alone yields a 61% relative CER reduction , demonstrating that inference policy constitutes a primary experimental variable.
Unlike prior work, we additionally report both raw Unicode-preserved and normalized evaluations, accompanied by paired bootstrap confidence intervals and cross-font random-effects meta-analysis. This allows explicit quantification of orthographic inflation and typographic heterogeneity, rather than attributing all variability to architectural design.
To ensure methodological transparency and avoid misleading numerical interpretation, it is important to distinguish between benchmark-aligned training and zero-shot cross-dataset evaluation when comparing systems on APTI. The following table explicitly contrasts the training configurations underlying the reported CER values.
Table 4 highlights a fundamental experimental distinction. ADOCRNet [
33] is trained and evaluated within the same APTI distribution, whereas the proposed framework is trained exclusively on a fully independent synthetic corpus and evaluated on APTI without any exposure during training, hyperparameter tuning, or language model construction. Accordingly, the reported CER values correspond to different generalization regimes: benchmark-specific optimization versus strict cross-dataset robustness. Absolute numerical differences should, therefore, be interpreted in light of this methodological contrast.
5.2. Limitations and Future Directions
Despite the strong empirical performance and statistical validation, several limitations remain.
First, the evaluation focuses on isolated word images from the APTI benchmark. Extending the framework to full-line or paragraph-level OCR would introduce additional segmentation, layout, and line-break complexities that were intentionally excluded to preserve controlled decoding isolation.
Second, although language-model-guided decoding substantially improves recognition accuracy, it introduces additional computational overhead during inference. Future research may investigate lightweight neural language models, shallow fusion with compressed n-gram models, or joint end-to-end optimization strategies to reduce decoding latency while preserving lexical regularization benefits.
Third, the training corpus consists primarily of synthetically generated printed text. While multi-font variability is extensively modeled, real-world degradations, such as motion blur, scanning artifacts, uneven illumination, and paper aging effects, were not explicitly simulated. Domain adaptation strategies, self-supervised pretraining on scanned corpora, or degradation-aware augmentation pipelines may further enhance robustness under archival and low-quality document conditions.
Finally, future work may explore transformer-only encoder architectures, visual-language pretraining schemes, or multi-task objectives that explicitly model diacritic prediction. Incorporating the full Arabic diacritic inventory within the output vocabulary would enable systematic investigation of the trade-off between structural recognition and orthographic completeness under multi-font variability.
Although the architectural components employed in this study are individually established in the modern OCR literature, the primary contribution lies in the controlled disentanglement of representation, decoding configuration, and Unicode normalization. By isolating inference-level effects under strict zero-shot cross-dataset conditions and statistically validating decoding-induced gains and orthographic inflation, this work establishes a decoding-aware and normalization-aware evaluation paradigm. This methodological framework is architecture-agnostic and can be directly applied to future Arabic OCR systems, regardless of encoder design.
From an interpretative perspective, these results suggest that a substantial portion of reported improvements in Arabic OCR may originate from inference-level mechanisms rather than representational learning alone. This observation highlights the importance of explicitly accounting for decoding strategies and evaluation protocols when assessing model performance.
6. Conclusions
This study presented a statistically validated CNN–Transformer–CTC framework for multi-font printed Arabic word recognition under strictly controlled experimental conditions. Rather than emphasizing architectural novelty, the primary contribution lies in the methodological disentanglement of representation, decoding setup, and character-level normalization.
Through controlled comparison between greedy decoding and language-model-guided beam search, we demonstrated that the inference policy alone can yield substantial performance gains under identical trained parameters. Statistical validation via paired bootstrap resampling confirmed that decoding-induced improvements are systematic and reproducible across diverse font families.
Furthermore, by introducing a normalization-aware evaluation protocol, we explicitly quantified orthographic inflation arising from deterministic diacritic exclusion. The results reveal that raw Unicode-preserved evaluation may substantially overestimate structural error when vocabulary design omits diacritics, particularly under heterogeneous typographic conditions. Cross-font meta-analysis further demonstrated extreme heterogeneity, reinforcing the necessity of reporting both raw and normalized metrics in Arabic OCR benchmarking.
Collectively, these findings reposition decoding strategy and text canonicalization as first-class experimental variables in Arabic OCR evaluation. The proposed framework establishes a statistically grounded, decoding-aware, and normalization-aware benchmarking paradigm that is architecture-agnostic and directly transferable to future OCR systems.
From a practical perspective, the proposed framework enables improved OCR performance through decoding optimization without requiring any modification or retraining of the visual model, which simplifies deployment in real-world systems. While language-model-guided decoding introduces additional computational cost at inference time due to beam search, the training process remains unchanged, preserving overall efficiency.
By separating structural recognition capacity from inference-induced and protocol-induced effects, this work contributes toward more transparent, reproducible, and methodologically principled evaluation standards in multi-font Arabic printed text recognition.
Despite these contributions, several limitations remain. The current study does not include diacritic-aware training or additional decoding configurations (e.g., varying beam width or alternative language models), which may further influence the observed performance. Moreover, the evaluation is restricted to word-level recognition on a controlled benchmark. Future work should investigate full diacritic modeling, extended decoding strategies, and broader real-world scenarios to assess general applicability under diverse document conditions.