Journal of visualized experiments : JoVE

An Efficient Transformer-Based Sentence Embedding Fusion Approach for Hate Speech Detection on Social Media.

Jahanzeb Munir, Musarat Karim, Mustafa Hameed, Ghada Atteia, Abeer Aljohani, Muhammad Umer, Yunyoung Nam, Byeong-Gwon Kang

Department of Information Technology, The Islamia University of Bahawalpur. · Department of Information Technology, The Islamia University of Bahawalpur; musarat.karim@iub.edu.pk.

Key points

From the paper's conclusion
  • The results show that transformer-based embeddings generally improve F1-score compared with traditional features.

Abstract

The rapid proliferation of offensive and hate speech on social media platforms poses a significant threat to individual wellbeing and the integrity of online discourse, highlighting the need for accurate, scalable, and computationally efficient automatic detection systems. This study proposes a supervised framework for hate speech detection that integrates transformer-based sentence embeddings with classical machine learning classifiers to balance performance and computational efficiency. Experiments are conducted on the Hate Speech and Offensive Language Dataset, which presents a substantial class imbalance challenge. The proposed approach systematically compares traditional feature representations, including TF-IDF and n-grams, with contextual embeddings derived from Sentence-BERT (SBERT) and DistilBERT. Multiple classifiers, including Logistic Regression (LR), Support Vector Machines (SVM), Random Forests (RF), and Convolutional Neural Networks (CNN) are evaluated. The results show that transformer-based embeddings generally improve F1-score compared with traditional features. Notably, the fusion of SBERT and DistilBERT embeddings with LR achieves superior performance, attaining an accuracy of 94%, precision of 93%, a recall of 92%, and an F1-score of 92%. This indicates improved robustness under imbalanced data conditions. To ensure reliability, the proposed framework is validated using stratified five-fold cross-validation, achieving an average accuracy of 93%. Moreover, in an independent within-dataset replication on a second curated hate speech dataset, the framework achieved 92.56% accuracy. An ablation study further evaluates the contribution of individual components to the framework. The results show that sentence-level transformer embeddings are effective in capturing semantic and contextual nuances that are crucial for identifying abusive language and highlight the potential of lightweight models for real-world deployment.

Read the paper

Discussion

Science Skim's AI key points, plus readers' public thoughts

Readers' thoughts

No reader thoughts yet.

Related papers

An Efficient Transformer-Based Sentence Embedding Fusion Approach for Hate Speech Detection on Social Media — Science Skim