Communications on Applied Nonlinear Analysis ISSN: 1074-133X Vol 32 No. 10s (2025) 2021 https://internationalpubls.com Providing Context for Hate Speech Classifiers using Post-hoc Explanations Puspendu Biswa,1 Donavalli Haritha,2 1Department of CSE, Koneru Lakshmaiah Education Foundation, Vaddeswaram, AP, India, 2Department of CSE, Koneru Lakshmaiah Education Foundation, Vaddeswaram, AP, India, Article History: Received: 12-01-2025 Revised: 15-02-2025 Accepted: 01-03-2025 Abstract: Hate speech classifiers trained on imbalanced datasets often struggle to distinguish whether group identifiers such as “gay” or “black” are being used in offensive or prejudiced contexts. This bias leads to false positives when these terms appear, as models fail to grasp the contextual nuances that define hateful usage. To address this, we extract SOC (Jin et al., 2020) post-hoc explanations from fine-tuned BERT classifiers to efficiently identify bias against identity terms. Building on these insights, we introduce a novel regularization technique that leverages these explanations to help models learn from the surrounding context of group identifiers, rather than relying solely on the identifiers themselves. Our approach outperforms baseline methods by reducing false positives on out-of-domain data while maintaining or enhancing performance on in-domain data. 1. Introduction Hate speech detection is part of the ongoing effort to limit the harm done by oppressive and abusive language (Waldron, 2012; Gelber and McNamara, 2016; Gagliardone et al., 2015; Mohan et al., 2017). Performance has improved with access to more data and more sophisticated algorithms (e.g., Mon- dal et al., 2017; Silva et al., 2016; Del Vigna12 et al., 2017; Basile et al., 2019), but the relative sparsity of hate speech requires sampling using keywords (e.g., Olteanu et al., 2018) or sampling from environments with unusually high rates of hate speech (e.g., de Gibert et al., 2018; Hoover et al., 2019). Modern text classifiers thus struggle to learn a model of hate speech that generalizes to real- world applications (Wiegand et al., 2019). A specific problem found in neural hate speech classifiers is their over-sensitivity to group iden- tifiers like “Muslim”, “gay”, and “black”, which are only hate speech when combined with the right context (Dixon et al., 2018). In Figure 1 we see two documents containing the word “black” that a fine- tuned BERT model predicted to be hate speech, while only the second occurs in a hateful context. Neural text classifiers achieve state-of-the-art performance in hate speech detection, but are un- interpretable and can break when presented with unexpected inputs (Niven and Kao, 2019). It is thus difficult to contextualize a model’s treatment of identifier words. Our approach to this prob- lem is to use the Sampling and Occlusion (SOC) explanation algorithm, which estimates model- agnostic, context-independent post-hoc feature im- portance (Jin et al., 2020). We apply this approach to the Gab Hate Corpus (Kennedy et al., 2020), a new corpus labeled for “hate-based rhetoric”, and an annotated corpus from the Stormfront white supremacist online forum (de Gibert et al., 2018). Communications on Applied Nonlinear Analysis ISSN: 1074-133X Vol 32 No. 10s (2025) 2022 https://internationalpubls.com Based on the explanations generated via SOC, which showed models were biased towards group identifiers, we then propose a novel regularization- based approach in order to increase model sensi- tivity to the context surrounding group identifiers. We regularize importance of group identifiers at training, coercing models to consider the context surrounding them. We find that regularization reduces the attention given to group identifiers and heightens the impor- tance of the more generalizable features of hate speech, such as dehumanizing and insulting lan- guage. In experiments on an out-of-domain test set of news articles containing group identifiers, which are heuristically assumed to be non-hate speech, we find that regularization greatly reduces the false positive rate, while in-domain, out-of-sample clas- sification performance is either maintained or im- proved. 2. Related Work Our work is conceptually influenced by Warner and Hirschberg (2012), who formulated hate speech detection as disambiguating the use of offensive words from abusive versus non-abusive contexts. More recent approaches applied to a wide ty- pology of hate speech (Waseem et al., 2017), build supervised models trained on annotated (e.g., Waseem and Hovy, 2016; de Gibert et al., 2018) or heuristically-labeled (Wulczyn et al., 2017; Olteanu et al., 2018) data. These models suffer from the highly skewed distributions of language in these datasets (Wiegand et al., 2019). Research on bias in classification models also influences this work. Dixon et al. (2018) measured and mitigated bias in toxicity classifiers towards social groups, avoiding undesirable predictions of toxicity towards innocuous sentences containing tokens like “gay”. Similarly, annotators’ biases to- wards certain social groups were found to be mag- nified during classifier training Mostafazadeh Da- vani et al. (2020). Specifically within the domain of hate speech and abusive language, Park et al. (2018) and Sap et al. (2019) have defined and stud- ied gender- and racial-bias.Techniques for bias re- duction in these settings include data augmentation by training on less biased data, term swapping (i.e., swapping gender words), and using debiased word embeddings (Bolukbasi et al., 2016). Complementing these works, we directly manip- ulate models’ modeling of the context surround- ing identifier terms by regularizing explanations of these terms. To interpret and modulate fine-tuned language models like BERT, which achieve SotA performance in hate speech detection tasks (MacA- vaney et al., 2019; Mandl et al., 2019), we fo- cus on post-hoc explanation approaches (Guidotti et al., 2019). These explanations reveal either word-level (Ribeiro et al., 2016; Sundararajan et al., 2017) or phrase-level importance (Murdoch et al., 2018; Singh et al., 2019) of inputs to predictions. (Rieger et al., 2019; Liu and Avci, 2019) are closely related works in regularizing explanations for fair text classification. However, the explanation meth- ods applied are either incompatible with BERT, or known to be inefficient for regularization as dis- cussed in (Rieger et al., 2019). We further iden- tify explanations are different in their semantics and compare two explanation algorithms that can be regularized efficiently in our setup. Besides, training by improving counterfactual fairness (Garg et al., 2019) is another closely related line of works. Communications on Applied Nonlinear Analysis ISSN: 1074-133X Vol 32 No. 10s (2025) 2023 https://internationalpubls.com 3. Data We selected two public corpora for our experi- ments which highlight the rhetorical aspects of hate speech, versus merely the usage of slurs and ex- plicitly offensive language (see Davidson et al., 2017). The “Gab Hate Corpus” (GHC; Kennedy et al., 2020) is a large, random sample (N = 27,655) from the Pushshift.io data dump of the Gab net- work ∗, which we have annotated according to a typology of “hate-based rhetoric”, a construct moti- vated by hate speech criminal codes outside the U.S. and social science research on prejudice and dehu- manization. Gab is a social network with a high rate of hate speech (Zannettou et al., 2018; Lima et al., 2018) and populated by the “Alt-right” (An- thony, 2016; Benson, 2016). Similarly with respect to domain and definitions, de Gibert et al. (2018) sampled and annotated posts from the “Stormfront” web domain (Meddaugh and Kay, 2009) and an- notated at the sentence level according to a similar annotation guide as used in the GHC. Train and test splits were randomly generated for Stormfront sentences (80/20) with “hate” taken as a positive binary label, and a test set was com- piled from the GHC by drawing a random strati- fied sample with respect to the “target population” tag (possible values including race/ethnicity tar- get, gender, religious, etc.). A single “hate” label was created by taking the union of two main la- bels, “human degradation” and “calls for violence”. Training data for the GHC (GHCtrain) included 24,353 posts with 2,027 labeled as hate, and test data for the GHC (GHCtest) included 1,586 posts with 372 labeled as hate. Stormfront splits resulted in 7,896 (1,059 hate) training sentences, 979 (122) validation, and 1,998 (246) test. 4. Analyzing Group Identifier Bias To establish and define our problem more quanti- tatively, we analyze hate speech models’ bias to- wards group identifiers and how this leads to false positive errors during prediction. We analyze the top features of a linear model and use post-hoc ex- planations applied to a fine-tuned BERT model in order to measure models’ bias towards these terms. We then establish the effect of these tendencies on model predictions using an adversarial-like dataset of New York Times articles. Communications on Applied Nonlinear Analysis ISSN: 1074-133X Vol 32 No. 10s (2025) 2024 https://internationalpubls.com 4.1. Classification Models We apply our analyses on two text classifiers, lo- gistic regression with bag of words features and a fine-tuned BERT model (Devlin et al., 2018). The BERT model appends a special CLS token at the beginning of the input sentence and feeds the sen- tence into stacked layers of Transformer (Vaswani et al., 2017) encoders. The representation of the CLS token at the final layer is fed into a linear layer to perform 2-way classification (hate or non-hate). Model configuration and training details can be found in the Section A.3. 4.2. Model Interpretation We first determine a model’s sensitivity towards group identifiers by examining the models them- selves. Linear classifiers can be examined in terms of their most highly-weighted features. We apply a post-hoc explanation algorithm for this task of extracting similar information from the fine-tuned methods discussed above. Group identifiers in linear models From the top features in a bag-of-words logistic regression of hate speech on GHCtrain, we collected a set of twenty-five identity words (not restricted to so- cial group terms, but terms identifying a group in general), including “homosexual”, “muslim”, and “black”, which are used in our later analyses. The full list is in Supplementals (A.1). Explanation-based measures State-of-the-art fine-tuned BERT models are able to model compli- cated word and phrase compositions: for example, some words are only offensive when they are com- posed with specific ethnic groups. To capture this, we apply a state-of-the-art Sampling and Occlusion (SOC) algorithm which is capable of generating hi- erarchical explanations for a prediction. To generate hierarchical explanations, SOC starts by assigning importance score for phrases in a way that eliminates compositional effect between the phrase and its context xδ around it within a window. Given a phrase p appearing in a sentence x, SOC assigns an importance score φ(p) to show how the phrase p contribute so that the sentence is classified as a hate speech. The algorithm com- putes the difference of the unnormalized prediction score s(x) between “hate” and “non-hate” in the 2-way classifier. Then the algorithm evaluates av- erage change of s(x) when the phrase is masked with padding tokens (noted as x\p) for different inputs, in which the N -word contexts around the phrase p are sampled from a pretrained language model, while other words remain the same as the given x. Formally, the importance score φ(p) is measured as, φ(p) = Exδ [s(x) − s(x\p)] (1) In the meantime, SOC algorithm perform agglom- erative clustering over explanations to generate a hierarchical layout. Averaged Word-level SOC Explanation Using SOC explanations output on GHCtest, we compute average word importance and present the top 20 in Table 2. 4.3. Bias in Prediction Hate speech models can be over-attentive to group identifiers, as we have seen by inspecting them through feature analysis and a post-hoc explanation approach. The effect of this during prediction is that models over-associate these terms with hate speech and choose to neglect the context around the Communications on Applied Nonlinear Analysis ISSN: 1074-133X Vol 32 No. 10s (2025) 2025 https://internationalpubls.com identifier, resulting in false positives. To provide an external measure of models’ over-sensitivity to group identifiers, we construct an adversarial test set of New York Times (NYT) articles that are filtered to contain a balanced, random sample of the twenty-five group identifiers (Section A.1). This gives us 12, 500 documents which are devoid of hate speech as defined by our typologies, excepting quotation. It is key for models to not ignore identifiers, but to match them with the right context. Figure 2 shows the effect of ignoring identifiers: random subsets of words ranging in size from 0 to 25 are removed, with each subset sample size repeated 5 times. Decreased rates of false positives on the NYT set are accompanied by poor performance in hate speech detection. 5. Contextualizing Hate Speech Models We have shown hate speech models to be over- sensitive to group identifiers and unable to learn from the context surrounding these words during training. To address this problem in state-of-the-art models, we propose that models can be regularized to give no explained importance to identifier terms. We explain our approach as well as a naive baseline based on removing these terms. Word Removal Baseline. The simplest approach is to remove group identifiers altogether. We re- move words from the term list found in Section A.1 from both training and testing sentences. Explanation Regularization. Given that SOC ex- planations are fully differentiable, during training, we regularize SOC explanations on the group iden- tifiers to be close to 0 in addition to the classifica- tion objective Lr. The combined learning objective is written as follows. Communications on Applied Nonlinear Analysis ISSN: 1074-133X Vol 32 No. 10s (2025) 2026 https://internationalpubls.com L = Lr + α Σ [φ(w)]2, (2) w∈x∩S where S notes for the set of group names and x notes for the input word sequence. α is a hyperpa- rameter for the strength of the regularization. In addition to SOC, we also experiment with regularizing input occlusion (OC) explanations, de- fined as the prediction change when a word or phrase is masked out, which bypass the sampling step in SOC. 6. Regularization Experiments 6.1. Experiment Details Balancing performance on hate speech detection and the NYT test set is our quantitative measure of how well a model has learned the contexts in which group identifiers are used for hate speech. We apply our regularization approach to this task, and compare with a word removal strategy for the fine- tuned BERT model. We repeat the process for both the GHC and Stormfront, evaluating test set hate speech classification in-domain and accuracy on the NYT test set. For the GHC, we used the full list of 25 terms; for Stormfront, we used the 10 terms which were also found in the top predictive features in linear classifiers for the Stormfront data. Congruently, for Stormfront we filtered the NYT corpus to only contain these 10 terms (N = 5,000). 6.2. Results Performance is reported in Table 1. For the GHC, we see an improvement for in-domain hate speech classification, as well as an improvement in false positive reduction on the NYT corpus. For Storm- front, we see the same improvements for in-domain F1) and NYT. For the GHC, the most marked dif- ference between BERT+WR and BERT+SOC is increased recall, suggesting that baseline removal largely mitigates bias towards identifiers at the cost of more false negatives. As discussed in section 4.2, SOC eliminates the compositional effects of a given word or phrase. As a result, regularizing SOC explanations does not prohibit the model from utilizing contextual information related to group identifiers. This can possibly explain the improved performance in hate speech detection relative to word removal. Word Importance in Regularized Models We determined that regularization improves a models focus on non-identifier context in prediction. In table 2 we show the changes in word importance as measured by SOC. Identity terms’ importance decreases, and we also see a significant increase in importance of terms related to hate speech (“poi- soned”, “blamed”, etc.) suggesting that models have learned from the identifier terms’ context. Communications on Applied Nonlinear Analysis ISSN: 1074-133X Vol 32 No. 10s (2025) 2027 https://internationalpubls.com Visualizing Effects of Regularization We can further see the effect of regularization by consider- ing Figure 3, where hierarchically clustered expla- nations from SOC are visualized before and after regularization, correcting a false positive. 7. Conclusion & Future Work Regularizing SOC explanations of group identifiers tunes hate speech classifiers to be more context- sensitive and less reliant on high-frequency words in imbalanced training sets. Complementing prior work in bias detection and removal in the context of hate speech and in other settings, our method is directly integrated into Transformer-based models and does not rely on data augmentation. As such, Communications on Applied Nonlinear Analysis ISSN: 1074-133X Vol 32 No. 10s (2025) 2028 https://internationalpubls.com it is an encouraging technique towards directing mod- els’ internal representation of target phenomena via lexical anchors. Future work includes direct extension and validation of this technique with other language mod- els such as GPT-2 (Radford et al., 2019); experi- menting with other hate speech or offensive lan- guage datasets; and experimenting with these and other sets of identity terms. Also motivated by the present work is the more general pursuit of inte- grating structure into neural models like BERT. Regularized hate speech classifiers increases sen- sitivity to the compositionality of hate speech, but the phenomena remain highly complex rhetorically and difficult to learn through supervision. For ex- ample, this post from the GHC requires background information and reasoning across sentences in or- der to classify as offensive or prejudiced: “Don- ald Trump received much criticism for referring to Haiti, El Salvador and Africa as ‘shitholes’. He was simply speaking the truth.” The examples we presented (see Appendix 4 and 5) show that regular- ization leads to models that are context-sensitive to a degree, but not to the extent of reasoning over sen- tences like those above. We hope that the present work can motivate more attempts to inject more structure into hate speech classification. Explanation algorithms offer a window into com- plex predictive models, and regularization as per- formed in this work can improve models’ internal representations of target phenomena. Acknowledgments This research was sponsored in part by NSF CA- REER BCS-1846531 (Morteza Dehghani). Xiang Ren’s research is based upon work supported in part by the Office of the Director of National Intel- ligence (ODNI), Intelligence Advanced Research Projects Activity (IARPA), via Contract No. 2019- 19051600007, United States Office Of Naval Re- search under Contract No. N660011924033, and NSF SMA 18-29268. References [1] Andrew Anthony. 2016. Inside the hate-filled echo chamber of racism and conspiracy theories. The guardian, 18. [2] Valerio Basile, Cristina Bosco, Elisabetta Fersini, Deb- ora Nozza, Viviana Patti, Francisco Manuel Rangel Pardo, Paolo Rosso, and Manuela Sanguinetti. 2019. Semeval-2019 task 5: Multilingual detection of hate speech against immigrants and women in twitter. In Proceedings of the 13th International Workshop on Semantic Evaluation, pages 54–63. [3] Thor Benson. 2016. Inside the twitter for racists: Gab the site where milo yiannopoulos goes to troll now. [4] Tolga Bolukbasi, Kai-Wei Chang, James Y Zou, Venkatesh Saligrama, and Adam T Kalai. 2016. Man is to computer programmer as woman is to homemaker? debiasing word embeddings. In Ad- vances in neural information processing systems, pages 4349–4357. [5] Thomas Davidson, Dana Warmsley, Michael Macy, and Ingmar Weber. 2017. Automated hate speech detection and the problem of offensive language. In Eleventh international AAAI conference on web and social media. [6] Fabio Del Vigna12, Andrea Cimino23, Felice DellOr- letta, Marinella Petrocchi, and Maurizio Communications on Applied Nonlinear Analysis ISSN: 1074-133X Vol 32 No. 10s (2025) 2029 https://internationalpubls.com Tesconi. 2017. Hate me, hate me not: Hate speech detection on facebook. In Proceedings of the First Italian Con- ference on Cybersecurity (ITASEC17), pages 86–95. [7] Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. 2018. Bert: Pre-training of deep bidirectional transformers for language understand- ing. arXiv preprint arXiv:1810.04805. [8] Lucas Dixon, John Li, Jeffrey Sorensen, Nithum Thain, and Lucy Vasserman. 2018. Measuring and mitigat- ing unintended bias in text classification. In Pro- ceedings of the 2018 AAAI/ACM Conference on AI, Ethics, and Society, pages 67–73. ACM. [9] Iginio Gagliardone, Danit Gal, Thiago Alves, and Gabriela Martinez. 2015. Countering online hate speech. Unesco Publishing. [10] Sahaj Garg, Vincent Perot, Nicole Limtiaco, Ankur Taly, Ed H Chi, and Alex Beutel. 2019. Counterfac- tual fairness in text classification through robustness. In Proceedings of the 2019 AAAI/ACM Conference on AI, Ethics, and Society, pages 219–226. [11] Katharine Gelber and Luke McNamara. 2016. Evi- dencing the harms of hate speech. Social Identities, 22(3):324–341. [12] Ona de Gibert, Naiara Perez, Aitor Garc´ıa Pablos, and Montse Cuadros. 2018. Hate speech dataset from a white supremacy forum. In Proceedings of the 2nd Workshop on Abusive Language Online (ALW2), pages 11–20.