## 3 Methodology
### Data Preprocessing  
The English and Twi datasets underwent rigorous preprocessing techniques to improve machine translation model quality by addressing common text data challenges like noise and sentence length variability. Specifically, non-ASCII characters were removed, and all text was converted to lowercase to standardize the input and avoid inconsistencies caused by case sensitivity or special characters. The cleaning process can be formalized as follows:  
\[x_{cleaned}=remove\_non\_ascii(x) \tag{3}\]  
where \(x\) represents the input text, and the function \(remove\_non\_ascii(x)\) removes any characters outside the ASCII range. After non-ASCII characters are removed, all text is converted to lowercase:  
\[x_{lower}=lowercase(x_{cleaned}) \tag{4}\]  
where the function \(lowercase(x_{cleaned})\) converts the cleaned text to lowercase. Sentences were also tokenized using the T5 tokenizer, which is designed to split input text into smaller subword units. The tokenization was performed with a maximum sequence length of 256 tokens, ensuring that each sentence conforms to the model's input constraints. The tokenization procedure is mathematically represented as follows:  
\[T_{sentence}=\text{T5\_tokenizer}(\text{sentence, max\_length}=256) \tag{5}\]  
where \(T_{sentence}\) represents the tokenized sentence, and T5_tokenizer is the tokenizer function from the T5 model, ensuring all sentences do not exceed 256 tokens. To further maintain linguistic relevance, tokenized sequences with lengths outside the acceptable range (i.e., either too short or too long) were filtered out. Sentences with fewer than 5 tokens or more than 256 tokens were excluded to prevent noise in the training process. This filtering condition can be formally expressed as follows:  
\[\text{Filter}\left(T_{sentence}\right)=\left\{\begin{array}{ll}1&if\text{ }5\leq|T_{sentence}|\leq 256\\ 0&otherwise\end{array}\right. \tag{6}\]  
where \(|T_{sentence}|\) represents the number of tokens in the sentence. Sentences are retained only if they satisfy \(5\leq|T_{sentence}|\leq 2565\). The English and Twi sentences were then carefully aligned to ensure that each English sentence corresponds to its accurate Twi translation. This step is crucial for the creation of a reliable parallel corpus. The alignment process can be defined as follows:  
\[\text{Align}\left(E_{i},T_{i}\right)= \left\{\begin{array}{ll}1&if\text{ }English\text{ and Twi sentences are contextually and linguistically aligned}\\ 0&otherwise\end{array}\right.\] (7) \[\text{where }E_{i}\text{ and }T_{i}\text{ represent the }i\text{-th English and Twi sentences, respectively. Only sentence pairs for which align \(\left(E_{i},T_{i}\right)=1\) were retained. Finally, inconsistent punctuation marks and redundant spaces were corrected to improve text consistency. For example, multiple spaceswere replaced with a single space, and non-standard punctuation marks were corrected to match conventional formatting. This can be formally represented as follows:  
\[x_{lower}=\text{normalize\_spaces\_and\_punctuation(x)} \tag{8}\]  
where the function _normalize_spaces_and_punctuation(x)_ ensures that all redundant spaces and non-standard punctuation are corrected.