Hate Speech Detection on Twitter Using XGBoost: A Large-Scale Dataset Analysis with Feature Engineering and Comparative Evaluation
Article Sidebar
Main Article Content
Social media platforms and Twitter in particular, has become a fertile channel for the rapid circulation of harmful discourse, including hateful and offensive language aimed at individuals and communities. Automatically flagging such content remains a demanding task within natural language processing, largely because micro blog text is short, informal, and heavily reliant on context for correct interpretation. This paper presents a hate-speech classification framework built around the Extreme Gradient Boosting (XGBoost) algorithm and evaluated on one of the largest publicly available labeled Twitter corpora, comprising roughly 96,973 tweets divided into three categories: hate speech, offensive language, and normal content. Each tweet is represented through a combined set of feature families: Term Frequency-Inverse Document Frequency (TF-IDF) vectors, dense word-embedding features, and tweet-level metadata such as hash tag frequency, mention count, re tweet count, and capitalization ratio. Prior to feature extraction, tweets are cleaned through tokenization, stop-word removal, lemmatization, and URL stripping to reduce noise in the raw corpus. The hyper parameters of the XGBoost classifier were selected through grid search combined with stratified cross-validation. The tuned model reached an overall accuracy of 93.7%, a macro-averaged F1-score of 0.937, and an area under the curve above 0.94 for every class, surpassing the results obtained with Naive Bayes (78.4%), Support Vector Machines (82.1%), Random Forest (85.6%), LSTM networks (88.3%), and a fine-tuned BERT model (90.1%). These outcomes indicate that gradient boosting, when paired with a carefully engineered feature set, provides an accurate and computationally efficient alternative for large-scale hate-speech detection.
Downloads
References
Davidson, T., Warmsley, D., Macy, M., & Weber, I. (2017). Automated hate speech detection and the problem of offensive language. In Proceedings of the 11th International AAAI Conference on Web and Social Media (ICWSM) (pp. 512–515). AAAI Press.
Waseem, Z., & Hovy, D. (2016). Hateful symbols or hateful people? Predictive features for hate speech detection on Twitter. In Proceedings of the NAACL Student Research Workshop (pp. 88–93). Association for Computational Linguistics.
Badjatiya, P., Gupta, S., Gupta, M., & Varma, V. (2017). Deep learning for hate speech detection in tweets. In Proceedings of the 26th International Conference on World Wide Web Companion (WWW) (pp. 759–760). ACM.
Zhang, Z., Robinson, D., & Tepper, J. (2018). Detecting hate speech on Twitter using a convolution-GRU based deep neural network. In Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing (EMNLP) (pp. 3368–3378).
Founta, A. M., Djouvas, C., Chatzakou, D., Leontiadis, I., Blackburn, J., Stringhini, G., ... & Kourtellis, N. (2018). Large scale crowdsourcing and characterization of Twitter abusive behavior. In Proceedings of the 12th AAAI International Conference on Web and Social Media (ICWSM) (pp. 491–500).
ElSherief, M., Kulkarni, V., Nguyen, D., Wang, W. Y., & Belding, E. (2018). Hate lingo: A targeted hate speech dataset. In Proceedings of the 2018 ACL Workshop on Abusive Language Online (ALW2) (pp. 68–78).
Mozafari, M., Farahbakhsh, R., & Crespi, N. (2020). A BERT-based transfer learning approach for hate speech detection in online social media networks. IEEE Access, 8, 25018–25028.
Nobata, C., Tetreault, J., Thomas, A., Mehdad, Y., & Chang, Y. (2016). Abusive language detection in online user content. In Proceedings of the 25th International Conference on World Wide Web (WWW) (pp. 145–153). ACM.
Chen, T., & Guestrin, C. (2016). XGBoost: A scalable tree boosting system. In Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (KDD) (pp. 785–794).
Hate, A., & Offensive, S. (2019). Measuring hate speech. In Proceedings of the Computation + Journalism Conference (pp. 1–5).
Mikolov, T., Sutskever, I., Chen, K., Corrado, G. S., & Dean, J. (2013). Distributed representations of words and phrases and their compositionality. In Advances in Neural Information Processing Systems (NeurIPS), 26, 3111–3119.
Pennington, J., Socher, R., & Manning, C. (2014). GloVe: Global vectors for word representation. In Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing (EMNLP) (pp. 1532–1543).
Devlin, J., Chang, M. W., Lee, K., & Toutanova, K. (2019). BERT: Pre-training of deep bidirectional transformers for language understanding. In Proceedings of the 2019 Conference of the North American Chapter of the ACL (NAACL-HLT) (pp. 4171–4186).
Hutto, C. J., & Gilbert, E. (2014). VADER: A parsimonious rule-based model for sentiment analysis of social media text. In Proceedings of the 8th AAAI International Conference on Weblogs and Social Media (ICWSM) (pp. 216–225).
Pedregosa, F., et al. (2011). Scikit-learn: Machine learning in Python. Journal of Machine Learning Research, 12, 2825–2830.

This work is licensed under a Creative Commons Attribution 4.0 International License.
All articles published in our journal are licensed under CC-BY 4.0, which permits authors to retain copyright of their work. This license allows for unrestricted use, sharing, and reproduction of the articles, provided that proper credit is given to the original authors and the source.