Thesis 2025 MUT Institutional Repository
A MODIFIED XLM-RoBERTa MODEL FOR HATE-SPEECH DETECTION IN ENGLISH-KISWAHILI CODE-SWITCHED SOCIAL MEDIA TEXT
Abstract
The rise of social media has amplified the dissemination of user-generated content, creating new opportunities for expression while simultaneously increasing the prevalence of hate speech. In multilingual societies such as Kenya, users frequently engage in English-Kiswahili code-switching, which introduces linguistic complexity that poses significant challenges to automatic hate speech detection. Although transformer-based models have demonstrated substantial advances in Natural Language Processing (NLP), their performance often degrades in low-resource and mixed-language contexts due to limitations in generalizability, input processing, and hyperparameter sensitivity. The main objective of this study was to develop a transformer-based model optimized for hate speech detection in English-Kiswahili code-switched social media text. A true experimental design, specifically the pretest posttest control group design, was employed in this study. Three state-of-the-art transformer models, including Multilingual BERT (mBERT), Multilingual DistilBERT (mDistilBERT), and XLM-RoBERTa, were subjected to a comparative analysis using a code-switched dataset annotated into Hate Speech, Offensive Language, and Neither categories. The models were compared both as feature extractors for a Support Vector Machine (SVM) classifier and as end-to-end classifiers. Based on superior performance across accuracy and macro F1-score, XLM-RoBERTa was selected as the baseline model for further improvement. The model was modified through an end-to-end classification pipeline, integration of dynamic padding and attention masking to improve computational efficiency, and customization of the output layer to support multi-class classification. Additionally, targeted retraining using Sentence Piece tokenization and a task-specific annotated corpus was employed to enhance the model’s ability to capture linguistic patterns in code-switched text. The modified XLM-RoBERTa model was evaluated against the baseline using standard classification metrics. The results demonstrated substantial improvements across all metrics, with accuracy increasing by 7% and macro F1-score by 18%. The model also showed improved sensitivity in detecting complex forms of hate and offensive speech, with the confusion matrix indicating improved class separation, particularly for hate speech, which achieved a true positive rate of 83.17%. These findings underscore the effectiveness of the proposed architectural and training enhancements in improving multilingual and code-switched text classification. The study highlights the role of input-sensitive processing, context-aware classification heads, and language-pair-specific retraining in advancing transformer performance. However, the study faced limitations, including reliance on a single Twitter-based dataset, high computational demands, and residual misclassifications between hate and offensive speech that may raise ethical concerns. Accordingly, the study recommends real-world deployment, extension to related domains, and adoption of human-in-the-loop safeguards. Future work should enhance interpretability, support low-resource implementation, diversify datasets, and explore cross-platform applicability
