Towards a Hate Speech Index with Attention-based LSTMs and XLM-RoBERTa
Authors: Mauro Bruno, Elena Catanese, Francesco Ortame (Istituto nazionale di statistica (Istat), 2024)
Topic: Sentiment, Emotion, Irony, Hate

Abstract
The diffusion of hate speech on social media requires robust detection mechanisms to measure its harmful impact. However, detecting hate speech, particularly in the complex linguistic environments of social media, presents significant challenges due to slang, sarcasm, and neologisms. State-of-the-art methods like Large Language Models (LLMs) demonstrate strong contextual understanding, but they often require prohibitive computational resources. To address this, we propose two solutions: (1) a bidirectional long short-term memory network with an attention mechanism (AT-BiLSTM) to enhance the model's interpretability and natural language understanding, and (2) fine-tuned multilingual robustly optimized BERT (XLM-RoBERTa) models.\\ Building on the promising results from EVALITA campaigns in hate speech detection, we develop robust classifiers to analyse 20.4 million Tweets related to migrants and ethnic minorities. Further, we utilise an additional custom labeled dataset (IstatHate) for benchmarking and training and we show how its inclusion can improve classification performance. Our best model outperforms top entries from previous EVALITA campaigns. Finally, we introduce Hate Speech Indices (HSI), which capture the dynamics of hate speech over time, and assess whether their main peaks correlate with major events.

Introduction
Social media platforms provide a fertile ground for the dissemination of hate speech, particularly targeting vulnerable groups such as migrants and ethnic minorities. In the last decade, hateful speech on platforms like X has become a pressing issue, as it not only affects the individuals who are directly targeted, but also contributes to a climate of hostility and division. Detecting hate speech in social media content is crucial to analyse the safety and inclusivity of online platforms and social environments. Hate speech detection is inherently challenging due to the subtle and evolving nature of social media language. Tweets often contain slang, neologisms, and sarcasm, which complicates the identification process. Traditional text classification methods usually fall short in addressing these challenges, especially for non-English languages where extensively labeled training sets are not easy to gather, calling for the development of more sophisticated approaches. The topic of hate speech detection in Italian texts has gained significant attention within the natural language processing (NLP) community, as shown by the HaSpeeDe (Hate Speech Detection) tasks at EVALITA. For instance, the EVALITA 2018 AUTHOR, and 2020 AUTHOR campaigns have provided labeled datasets and attracted several submissions employing a diverse set of machine learning and deep learning techniques. A prominent approach in recent hate speech detection and, in general, text classification, is the use of pre-trained language models like Bidirectional Encoder Representations from Transformers (BERT) AUTHOR. After their first appearance in 2018, BERT-based models have set new standards in several NLP tasks thanks to their ability to capture contextual information effectively, especially when fine-tuned on the specific task of interest. In 2019, a multilingual robustly optimized BERT (XLM-RoBERTa) AUTHOR was published, making it possible to obtain higher performances on non-English texts. For instance, TheNorth team for the HaSpeeDe 2 task at EVALITA 2020 obtained the best results fine-tuning a XLM-RoBERTa model AUTHOR. It is also worth noting that in recent years, generative Large Language Models (LLMs) have demonstrated an even more impressive ability to understand natural language. However, their large number of parameters makes them impractical for classifying large volumes of data, even when compared to the larger version of XLM-RoBERTa\footnote{The number of parameters in Large Language Models ranges between a few billions to hundreds of billions of parameters, while the large version of XLM-RoBERTa “only” has 561 million parameters. . Given these developments and challenges, our research proposes two approaches to hate speech classification: (1) an attention-based bidirectional long short-term memory network (AT-BiLSTM), benchmarked against a standard BiLSTM model, and (2) a fine-tuned XLM-RoBERTa (large) model, benchmarked against its base, smaller version. We use two labeled training sets: (a) the EVALITA 2020 HaSpeeDe 2 task dataset, and (b) a custom, smaller labeled dataset, which we refer to as IstatHate. Our study explores the impact of training models on both the EVALITA dataset alone and a combined dataset that includes EVALITA and IstatHate, evaluating their performance across multiple test sets. Finally, we present a preliminary version of the Hate Speech Index (HSI), designed to quantify the proportion of hate speech by classifying 20.4 million Italian Tweets related to migrants and ethnic minorities from January 2018 to February 2023.

Conclusion
This study addressed the issue of hate speech detection on social media, specifically focusing on X (formerly Twitter) and on migrants and ethnic minorities. Given the complexities of natural language on these platforms, we explored different approaches including lighter bidirectional LSTM models with and without attention mechanisms, and fine-tuned XLM-RoBERTa models both in their base and large formats. We trained our models on EVALITA 2020 HaSpeeDe 2 data and also introduced a small labeled dataset, IstatHate, that improves the performance of the already best performing model, XLM-RoBERTa-large, when included in the training set. Despite longer inference times and higher computational resources required for large amounts of data, heavier models like XLM-RoBERTa-large achieve significantly higher performance and generalization capabilities. Yet, AT-BiLSTM\star (i.e., the AT-BiLSTM model that includes both EVALITA and IstatHate data in the training), outperforms XLM-RoBERTa-base\star across all test sets, a notable achievement considering the difference in models size and inference time. We compared the predictions of AT-BiLSTM-EV against AT-BiLSTM\star visualising the attention scores they assigned to the same Tweets. Empirical evidence shows that including IstatHate in the training set may improve contextual understanding and mitigate the bias that simpler models like LSTMs may have when classifying hate speech in the presence of curse words. The preliminary computation of the Hate Speech Index (HSI) reveals significantly different levels of hate speech detection across different models and training sets, even though the training data has very similar characteristics. Fine-tuned XLM-RoBERTa models produce the lower estimates in levels, especially when IstatHate is included in the training set. Furthermore, when analysing hate peaks, XLM-RoBERTa-large\star predictions highly correlate with major events. Future work will focus on expanding and validating the IstatHate dataset, exploiting the sampling weights, refining model architectures, and exploring additional features to enhance detection capabilities. \newpage \appendix