## 5 Materials and Methods
### Spelling Corrector  
Spelling correction in the HTR system has two ways of implementation. The first one incorporates a decoding step with the language model to correct possible errors generated by the optical model, whose input is a CTC character probability matrix. The second uses raw text as an input to correct the potential errors. Thus, we use these two implementation scenarios, in which the second approach is used as a proposal. In addition, the traditional method in the HTR system, uses the first implementation approach through HMM combined with the language model [2,15,21]. In the HMM with language model approach, the RNN block serves as an emitter of a probability model, which converts it into scaled pseudo-probability estimates to build the HMMs and perform the decoding. The pipeline consists of three weighted finite-state transducers [57]: (i) the representation of the HMM built through left-to-right topology; (ii) Lexicon, a vocabulary list built from character vocabulary of the optical model; and (iii) Grammar, a \(N\)-gram language model built on the corpus (dataset), providing probabilities in relation to most likely sequences of length \(N\). Finally, the decoder receives the input and searches for the best transcription using Vanilla Beam Search algorithm (\(beam\_width=10\)) [20]. In second scenario (text as input), we use statistical and neural network approaches. Thus, for the statistical approach, we used three correction techniques--(i) Similarity with \(N\)-gram [94]; (ii) Edit distance [95]; and (iii) Edit distance with Symmetric Delete algorithm (SymSpell) [96]. The Similarity method applies the \(N\)-gram at the character level to each word and stores the substrings as a representation. To find similar strings, the same \(N\)-gram process is performed on the input text and selects the words that share the most substrings. Figure 7: Puigcerver architecture overview. The Edit distance method, using the [95] algorithm, generates all possible terms using editing operations with a distance \(N\) from the query term and searches for it in a dictionary. Thus, for a word of length \(L\), a charset size \(C\) and an edit distance \(N=1\), there will be \(L\) deletions, \(L-1\) transpositions, \(CL\) substitutions, and \(C(L+1)\) insertions, totaling \(2L+2 LC+C-1\) terms at search time. Finally, candidate terms are ordered by the shortest distance. The Symspell method is an improvement to the Norvig algorithm, in which it generates all possible terms using only delete editing operation with a distance \(N\) from the query term and searches for it in a word frequency dictionary. Thus, for a word of length \(L\), a charset size \(C\) and an edit distance \(N=1\), there will be only \(L\) deletions, totaling \(L\) terms at search time. Finally, candidate terms are ordered by the shortest distance with most frequency. On the other hand, for a neural network approach, we use two models' variations: (i) Sequence to sequence (Seq2 seq) with Attention mechanism; and (ii) Transformer. It is worth mentioning that the Seq2 seq model was developed and proposed for this work (presented in Section 4), while the Transformer model was used as proposed by [22]. For a better analysis of the proposed architecture, we extended the Seq2 seq model in three new variations: (i) using [PERSON]'s Attention [30] with 512 hidden units; (ii) using [PERSON]'s Attention [31] with 512 hidden units; and (iii) using [PERSON]'s Attention [31] with 1024 hidden units. [PERSON]'s Attention was chosen in the last variation because it offers fast model training and a fast decoding process, when compared to [PERSON]'s Attention and Transformer model, respectively. Transformer model [22] is also used, which in particular uses only the Attention mechanism instead of the recurrent ones. Thus, unlike the traditional Seq2 seq, it uses Embeddings layers with Positional Encoding in the inputs, to create and extract more information from the texts.