<figure><img src="image_1.png" /></figure>

ifip

International Federation for Information Processing

This document is the original author manuscript of a paper submitted to an IFIP
conference proceedings or other IFIP publication by Springer Nature. As such, there
may be some differences in the official published version of the paper. Such
differences, if any, are usually due to reformatting during preparation for publication or
minor corrections made by the author(s) during final proofreading of the publication
manuscript.
# An Ensemble Approach to Hostility Detection in Hindi Tweets

Santosh Rajak, Monseej Purkayastha, Amitabh Deb, and Ujwala Baruah (✉)

National Institute of Technology, Silchar 788, India
{santosh_rs,ujwala}@cse.nits.ac.in

**Abstract.** In today's world, social media platforms are prevalent in all walks of life. However, the content on these platforms is often created with hostile intent. With the increase of such hostile content in social media, there has arisen a need to effectively detect such posts so as take appropriate measures against them. Hence, extensive studies have been performed in this field for the English language, however, similar work is relatively sparse in the case of Indian languages like Hindi. The work done here introduces a transfer learning-based approach with an ensemble model on top for identifying and flagging posts of hostile intent on social media platforms written in the Hindi Devanagari script. For this purpose, we have leveraged the pre-trained Fasttext model trained on Hindi text. Our model achieves F1-scores of 76% on the Defamation class, 80% on the Fake class, 69% on the Hate class and 79% on the Offensive class on the provided test set.

**Keywords:** Hindi • Hostility Detection • Fasttext • Transformers •
Text

## 1 Introduction

Social Media has seen a significant rise in popularity since the mid-2000s, first in the West and eventually in India. With better internet connectivity and high-quality cheap smartphones, it has ingrained itself as a major part of our culture. Social media has been adopted by almost everyone to share information with each other worldwide. With its widespread adoption, social media can also be used to spread one's agenda to the public.

It has come to light over the years that people have also been using social media as a cheap and effective method to spread unverified rumours, incite people and in general stir up violent sentiments. Such hostile posts can also tarnish the image of people and organizations leaving long-term impacts on their reputation. Hence, it is necessary to detect and flag such posts to curb this problem before it goes out of control.

The NLP community, in recent years, has shown a growing interest in hostility detection, and a lot of work has already been done to detect such posts in the

<footnote>Supported by Organization X</footnote>
English language. But the same cannot be said for Hindi. Today, going by the count of native speakers, Hindi ranks third among the world's languages; hence, a major portion of the digital population interacts online in this language. But this also means Hindi can be an excellent medium for spreading misinformation, hate and rumours online to a wider audience.

We intend to solve this problem of detecting Hindi hostile posts written in the Devanagari Script. We propose a transfer learning model which uses pre-trained Fasttext Hindi word vectors for training an ensemble-based classifier on top of it. A comprehensive dataset for detecting hostile posts among Hindi tweets is presented in [1], released as part of the Constraint-2021 Workshop. In this dataset, the authors have emphasized the multi-dimensionality of online hostile posts, where one post can belong to multiple hostile classes. We have performed experiments on the multi-class classification of the hostile sub-classes: Fake, Hate, Defamation, and Offensive using this dataset.

## 2 Related Work

Here, we examine existing works on hostility detection on posts from online forums. As English is the most widely used language on online platforms, much work has been done on identifying and flagging hostile posts in the English language. Shu et al. [1] provided a wide-ranging review on detecting fake news from media posts extracted from social media, coupling fake news representations taken from psychology as well as social theories to identify potential hits. Ruchansky et al. [2] proposed a model that considers the content, reaction to, and origin of a news post for identifying fake news. Karimi et al. [3] suggested methods to combine multiple sources to tackle the problem of detecting fake news.

Kowk et al. [4] Mittos et al. [5] were able to categorize and classify online texts into racist and non-racist categories. Their model achieved around 76% accuracy in detecting racist hate speech among Twitter posts. Schmidt and Wiegand [6] published a detailed analysis of the detection of hate speech in online posts and outlined the drawbacks of the current approaches as well as suggested points of improvement. Waseem and Hovy [7] prepared a list of eleven criteria that can be used to identify a post or tweet classified as hate speech. This list included sexist or racial slurs, abusing, or criticizing minorities, trying to silence them as part of the criteria among others.

Haddad et al. [8] proposed an approach for hostility detection in online Arabic texts leveraging Convolutional Neural Networks (CNN) along with attention-based Bidirectional Gated Recurrent units (Bi-GRU). Hossain et al. [9] prepared a comprehensive dataset of about 50,000 fake news samples in Bengali. Jha et al. [10] proposed a Fasttext-based approach to identify hostile Hindi tweets. Work has also been done in the case of bilingual texts as well. For instance, Bohra et al. [11] and Mathur et al. [12]. [13] tackled the problem of detecting hostility in bilingual social media texts, specially focusing on ones combining Hindi and English [13]. Create a machine learning-based technique that outperforms a
cutting-edge deep learning strategy for detecting hateful rhetoric in online user comments from two different domains. Additionally, they create the first of its type, a corpus of user comments with abusive language analysed. Finally, to even further advance our understanding of this behaviour, examine abusive language over time and in various contexts using our detection technique.

# 3 Proposed Methodology

Here, we present our methodology for classifying hostile Hindi posts. It should be noted that all models are trained as binary classifiers as part of this methodology, one for each class, with the union of all predicted classes from the models being taken as the final output. We have divided our approach into two different stages. The first stage will classify hostile and non-hostile classes using an approach similar to the one provided by Varad et al. [14] where a pre-trained attention-based approach is utilized to predict the class. The samples predicted as hostile are then passed down to the second stage for further classification into four hostile sub-classes: Fake, Hate, Defamation and Offensive. Hence, to train the models at this point, we have dropped the annotated non-hostile data samples so that our models can learn to distinguish between the hostile sub-classes. We have come up with a Fasttext-based ensemble model approach for this purpose. This model has been used to train separate classifiers for each sub-class.

## 3.1 Dataset

The dataset utilised here for training and validation purposes has been provided by Mohit et al. [1] [15]. This is a multi-class multi-label dataset prepared by collecting and annotating posts in the Hindi language from Twitter. A single data sample can fall under either the non-hostile class or the hostile class; where again, in the hostile class, there are four separate sub-classes: Fake news(Ersatz), Hate speech, Defamatory speech and Offensive speech. Definitions for the sub-classes are given below:

- **Fake News:** An assertion or informational item that has been discovered to be false.

- **Hate Speech:** A message intended to incite hatred or violence against a certain group of people based on their race, ethnicity, religion, or other characteristics.

- **Offensive:** Any message that uses obscene, rude, vulgar, or unfriendly language to disparage a specific person or group.

- **Defamatory Speech:** A message that spreads false information about a person or group.

- **Non-hostile class:** A message that has no animosity or harmful purpose.

It is worth noting that the four hostile sub-classes are not mutually exclusive. A data point can be classified as more than one hostile sub-class. A breakdown of the dataset is provided in Table 1.
<table><caption>Fig. 1. Pre-processed Text Data</caption><thead><tr><th>Post</th><th>urls</th><th>mentions</th><th>hashtags</th><th>emoticons</th><th>Filtered Post</th><th>Filtered Post_Stopword Removed</th></tr></thead><tbody><tr><td>IndiaFightsCorona:<br/>X मास्क नहीं तो टोकेंगे</td><td></td><td></td><td></td><td></td><td>X मास्क नहीं तो टोकेंगे</td><td></td></tr><tr><td>✔️=कोरोना को रोकेंगे</td><td>[https://t.co/WLPneVjclu]</td><td>[@NITIAayog]</td><td>["IndiaFights Corona", 'TheNewNormal', 'MaskUp', 'StaySafe', 'IndiaWillWin']</td><td>["#"]</td><td>✔️कोरोना को रोकेंगे</td><td>"X मास्क टोकेंगे</td></tr><tr><td>ूपब्लिक प्लेस पर मास्क का प्रयोग अनिवार्य।</td><td></td><td></td><td></td><td></td><td>ूपब्लिक प्लेस पर मास्क का प्रयोग अनिवार्य। कोरोना देनी मात, करनी होगी नयी शुरुआत। Via"</td><td>✔️कोरोना रोकेंगे</td></tr><tr><td>कोरोना को देनी है मात, तो करनी होगी एक</td><td></td><td></td><td></td><td></td><td>कोरोना को देनी है मात, तो करनी होगी एक नयी शुरुआत।</td><td></td></tr></tbody></table>

Defamation, Offensive). It is important to note that these data classes are not well-defined, and one data sample can belong to more than one sub-class at a time. Hence, we have dropped the non-hostile data from our dataset for training the models at this stage. This allows the models to learn to distinguish between the four hostile sub-classes. We are treating this work as a multi-label multi-class classification problem and have employed a one vs. rest approach for classifying the four hostile sub-classes. For each class, a separate model has been trained independently to predict if a given data sample is classified as a member of that specific class. All predicted types are then taken together to obtain the final multi-label prediction. To achieve this, we have leveraged a Fasttext based model pretrained on Hindi texts. For classification, we have taken the approach of using a soft voting ensemble model. The ensemble model consists of individual classifiers: SVM, Random Forest, Logistic Regression, Gradient Boosted Trees and XGBoost-based models. The results from the individual classifiers are below the current state-of-the-art (SOTA) but upon using a soft voting ensemble classifier allows for combining the probabilities of each prediction in each model, which enables in picking the prediction with the highest total probability, the performance of the model is improved. As Fasttext is not an attention-based model, context is not a significant factor for these models. Hence, we are using pre-processed data with symbols like hashtags, @-based mentions, URLs, reserved words, and common stopwords that do not contribute any relevant information removed. The Model Architecture is given in Table 2.
<figure><img src="image_2.png" /><figcaption>Fig. 2. Data Flow diagram for non-hostile model</figcaption></figure>

<table><caption>**Table 2.** Fasttext based ensemble model architecture.</caption><tr><td>Model Name</td><td>Soft voting ensemble classifier using SVM, Random Forest<br>Logistic Regression, Gradient Boosted Trees and XGBoost</td></tr><tr><td>Parameter</td><td>Default Parameters of sklearn<br>class weight is set to 'balanced'</td></tr><tr><td>Feature Used</td><td>Hindi pre-trained Fasttext feature vectors</td></tr></table>

In this paper, we have implemented soft voting-based ensemble classifier on top of a pre-trained Fasttext Hindi model to distinguish between the hostile sub-classes. The implementation was done using Jupyter notebooks in Python which allows for interactive experimentation on the data. We have employed the following python packages in our implementation and experiments. Their functions are given in the parentheses.

- Numpy (Numerical library).

- Pandas (Data handling).

- Scikit-Learn (Pre-defined machine learning algorithms).

- NLTK (Natural language processing).

- Pytorch (Neural network implementation framework).
<figure><img src="image_3.png" /><figcaption>Fig. 3. Data flow diagram for ensemble models</figcaption></figure>

- Fasttext (pre-trained text representations and word vectors).

- Huggingface (Transformers implementation framework and pre-trained attention model)

## 4 Results

Here, we discuss the results achieved by the methodology outlined above. Table 3 shows the results of our model compared to the baseline provided by [15] and the current SOTA model detailed in [2]. We have evaluated our data against both the validation and test sets available in the dataset. Table 4 presents each class's classification report. The metrics mentioned in the report are defined below:

- **Accuracy:** It measures the percentage of the proportion of accurate forecasts over all predictions made.

$$ Accuracy = \frac{TP + TN}{TP + FP + FN + TN} \qquad (1) $$

where TP = True Positives, TN = True Negatives, FP = False Positives, and FN = False Negatives.

- **Precision:** It measures the fraction of positive class predictions that belong to the positive class.

$$ Precision = \frac{TP}{TP + FP} \qquad (2) $$

- **Recall:** It measures the fraction of positive class predictions from all positive examples in the dataset.
$$ Recall = \frac{TP}{TP + FN} \qquad (3) $$

– F1 Score: The F1 score is measured as the harmonic mean of precision and recall.

$$ Recall = \frac{2 * (Recall * Precision)}{Recall + Precision} \qquad (4) $$

<table><caption>**Table 3.** F1 Score Comparison</caption><thead><tr><th rowspan="2">Class</th><th colspan="2">Current SOTA</th><th colspan="2">Our Implementation</th><th rowspan="2">Baseline</th></tr><tr><th>Validation</th><th>Test Set</th><th>Validation</th><th>Test Set</th></tr></thead><tbody><tr><td>Non Hostile</td><td>0.9765</td><td>0.9709</td><td>0.9783</td><td>0.9742</td><td>0.8411</td></tr><tr><td>Defamation</td><td>0.4951</td><td>0.428</td><td>0.7751</td><td>0.7601</td><td>0.4357</td></tr><tr><td>Fake</td><td>0.8178</td><td>0.814</td><td>0.8133</td><td>0.8027</td><td>0.6815</td></tr><tr><td>Hate</td><td>0.5614</td><td>0.4649</td><td>0.7007</td><td>0.6976</td><td>0.4749</td></tr><tr><td>Offensive</td><td>0.6108</td><td>0.5648</td><td>0.7983</td><td>0.7978</td><td>0.4198</td></tr></tbody></table>

<table><caption>**Table 4.** Classification Report for each class in the dataset</caption><thead><tr><th>Class Label</th><th>Binary(paired) Label</th><th>Precision</th><th>Recall</th><th>F1score</th><th>Support</th><th>Accuracy</th></tr></thead><tbody><tr><td rowspan="2">NonHostile</td><td>0</td><td>0.97</td><td>.98</td><td>0.97</td><td>376</td><td>0.98</td></tr><tr><td>1</td><td>0.98</td><td>.97</td><td>0.98</td><td>435</td><td></td></tr><tr><td rowspan="2">Defamation</td><td>0</td><td>0.84</td><td>0.92</td><td>0.88</td><td>303</td><td>0.79</td></tr><tr><td>1</td><td>0.45</td><td>0.27</td><td>0.34</td><td>73</td><td></td></tr><tr><td rowspan="2">Fake</td><td>0</td><td>0.81</td><td>0.90</td><td>0.85</td><td>223</td><td>0.81</td></tr><tr><td>1</td><td>0.82</td><td>0.70</td><td>0.76</td><td>153</td><td></td></tr><tr><td rowspan="2">Hate</td><td>0</td><td>0.75</td><td>.92</td><td>0.83</td><td>268</td><td>0.70</td></tr><tr><td>1</td><td>0.58</td><td>0.28</td><td>0.38</td><td>108</td><td></td></tr><tr><td rowspan="2">Offensive</td><td>0</td><td>0.83</td><td>0.94</td><td>0.88</td><td>273</td><td>0.80</td></tr><tr><td>1</td><td>0.70</td><td>0.53</td><td>0.58</td><td>103</td><td></td></tr></tbody></table>
<figure><img src="image_4.png" /><figcaption>Fig. 4. 1. Bar chart comparison of F1 score for the hostile sub-class of the test set</figcaption></figure>

## 5 Conclusion

Here, we have leveraged pretrained Fasttext models over an ensemble classifier to achieve results. Our results show that for this task, an ensemble approach performs almost, if not even better when compared to an attention-based model. There is still, however, scope for improvement. For instance, a weighted average model can yield better results than a voting based classifier. Further feature engineering and using specific stopwords for each class may improve results. The lack of available datasets in the Hindi language is a major roadblock to improving the model's performance. Training and validating on data from outside the datasets or combining multiple datasets to have a much bigger training corpus can also improve the performance of the model.

**Acknowledgements.** Please place your acknowledgments at the end of the paper, preceded by an unnumbered run-in heading (i.e. 3rd-level heading).

## References

1. Shu, K., Sliva, A., Wang, S., Tang, J., Liu, H.: Fake news detection on social media: A data mining perspective. ACM SIGKDD Explor. Newsl. **19**(1), 22–36 (2017)

2. Ruchansky, N., Seo, S., Liu, Y.: CSI: a hybrid deep model for fake news detection. In: Proceedings of the 2017 ACM on Conference on Information and Knowledge Management, pp. 797–806 (2017)

3. Karimi, H., Roy, P., Saba-Sadiya, S., Tang, J.: Multi-source multi-class fake news detection. In: Proceedings of the 27th International Conference on Computational Linguistics, pp. 1546–1557 (2018)

4. Kwok, I., Wang, Y.: Locate the hate: Detecting tweets against blacks. In: Twenty-Seventh AAAI Conference on Artificial Intelligence (2013)
5. Mittos, A., Zannettou, S., Blackburn, J., De Cristofaro, E.: "And we will fight for our race!" a measurement study of genetic testing conversations on reddit and 4chan. In: Proceedings of the International AAAI Conference on Web and Social Media, vol. 14, pp. 452–463 (2020)

6. Schmidt, A., Wiegand, M.: A survey on hate speech detection using natural language processing. In: Proceedings of the Fifth International Workshop on Natural Language Processing for Social Media, pp. 1–10 (2017)

7. Waseem, Z., Hovy, D.: Hateful symbols or hateful people? predictive features for hate speech detection on twitter. In: Proceedings of the NAACL Student Research Workshop, pp. 88–93 (2016)

8. Haddad, B., Orabe, Z., Al-Abood, A., Ghneim, N.: Arabic offensive language detection with attention-based deep neural networks. In: Proceedings of the 4th Workshop On Open-source Arabic Corpora and Processing Tools, with a Shared Task on Offensive Language Detection, pp. 76–81 (2020)

9. Hossain, M.Z., Rahman, M.A., Islam, M.S., Kar, S.: BanFakeNews: a dataset for detecting fake news in Bangla. arXiv preprint arXiv:2004.08789 (2020)

10. Jha, V.K., Hrudya, P., Vinu, P., Vijayan, V., Prabaharan, P.: DHOT-repository and classification of offensive tweets in the Hindi language. Procedia Comput. Sci. 171, 2324–2333 (2020)

11. Bohra, A., Vijay, D., Singh, V., Akhtar, S.S., Shrivastava, M.: A dataset of Hindi-English code-mixed social media text for hate speech detection. In: Proceedings of the Second Workshop on Computational Modeling of People's Opinions, Personality, and Emotions in Social Media, pp. 36–41 (2018)

12. Mathur, P., Shah, R., Sawhney, R., Mahata, D.: Detecting offensive tweets in Hindi-English code-switched language. In: Proceedings of the Sixth International Workshop on Natural Language Processing for Social Media, pp. 18–26 (2018)

13. Nobata, C., Tetreault, J., Thomas, A., Mehdad, Y., Chang, Y.: Abusive language detection in online user content. In: Proceedings of the 25th International Conference on World Wide Web, pp. 145–153 (2016)

14. Bhatnagar, V., Kumar, P., Moghili, S., Bhattacharyya, P.: Divide and conquer: an ensemble approach for hostile post detection in Hindi. In: Chakraborty, T., Shu, K., Bernard, H.R., Liu, H., Akhtar, M.S. (eds.) CONSTRAINT 2021. CCIS, vol. 1402, pp. 244–255. Springer, Cham (2021). https://doi.org/10.1007/978-3-030-73696-5_23

15. Bhardwaj, M., Akhtar, M.S., Ekbal, A., Das, A., Chakraborty, T.: Hostility detection dataset in Hindi. CoRR, vol. abs/2011.03588, 2020. https://arxiv.org/abs/2011.03588