# Hate Speech Detection by Using Rationales for Judging Sarcasm
## 3 Methods
### Preprocessing  
_Conversion of text data:_ Essential preprocessing tasks are efficiently executed to ensure data uniformity and usability. Text normalization and cleaning involve converting all text to lowercase, removing HTML tags, and substituting URLs and other non-textual elements with placeholders to standardize data. The Ekphrasis tokenizer, designed for social media, segments and annotates text with emotional and stylistic cues critical for detecting sarcasm and hate speech. Advanced tokenization for the model input employs BertTokenizer to refine text into tokens suitable for BERT models, appending special tokens like '[CLS]' and '[SEP]' to facilitate proper sequence formatting, while also preparing sequence input IDs and attention masks. Integration with SpaCy enhances the grammatical and semantic handling of the text, supporting accurate model training and effectiveness. These comprehensive preprocessing steps meticulously prepare the dataset, addressing language complexities and nuances vital for the effective detection of sarcasm and hate speech, thus enhancing model accuracy and interpretability. _Conversion of rationale to ground truth attention:_ Ground truth attention is established for posts identified as toxic (hatespeech/offensive) using a baseline method for scenario (i). Furthermore, for scenario (ii), where posts are classified as hatespeech/offensive in the first category and sarcasm in the second category, ground truth attention is derived from the annotator's rationales depicted in Figure 1. In this process, each rationale is transformed into an attention vector with values of 0 and 1. Tokens within the rationale are assigned a value of 1 in the attention vector, while the rest receive a 0. The average of these attention vectors is then calculated to obtain the ground truth attention for each post. Subsequently, a softmax function is applied to normalize the attention. An inherent challenge in the ground truth attention vector arises from the potential proximity of values between rationale and non-rationale tokens. To address this, we utilize the temperature parameter (\(\tau\)) within the softmax function. This strategic application of the temperature parameter facilitates an adjustment in the probability distribution, amplifying the emphasis on the rationales. The fine-tuning of this parameter is a meticulous process conducted through adjustments in the validation set. In the conversion process of toxic (hatespeech/offensive) rationale, if at least two out of three annotators label the data as hatespeech/offensive, the rationale is considered. However, for sarcasm data, even if just one annotator labels the data as sarcasm, the rationale is converted. This distinction is made due to the subjective nature of understanding sarcasm in text data, which can vary significantly from person to person. _Proposed method for the conversion of rationale to ground truth attention:_ In this study, an innovative algorithm tailored for data exhibiting both hateful/offensive and sarcastic characteristics is introduced, see Algorithm 1. In this process, similar to the previous approach, each rationale is transformed into an attention vector with values of 0 and 1. Tokens within the rationale are assigned a value of 1 in the attention vector, while the rest receive a 0. Here, the attention vector for toxic (hate/offensive) after conversion is denoted as \(H=(h_{1},h_{2},h_{3},\dots,h_{n})\) in the 1 st category, and the attention vector for sarcasm, denoted as \(S=(s_{1},s_{2},s_{3},\dots,s_{n})\), corresponds to the 2 nd category. This procedure is applied to a sentence represented by tokens \(t_{1},t_{2},t_{3},\dots,t_{n}\) and its corresponding rationale after vector conversion \(r_{1},r_{2},r_{3},\dots,r_{n}\). Figure 1: Ground truth attention algorithm is applied to (i) toxic data (hatespeech/offensive) and to data that is both (ii) sarcastic and toxic.