Contextual Hate Speech Detection in Code Mixed Text using Transformer Based Approaches

Ravindra Nayak, Raviraj Joshi

Abstract

Detecting hate speech in code-mixed languages like "Hinglish" (Hindi-English) is challenging due to linguistic fluidity and context dependency. This paper evaluates transformer-based architectures for the HASOC 2021 subtask, demonstrating that a dual-encoder approach—which independently processes a tweet and its conversational context before averaging their representations—outperforms standard concatenation methods.

Introduction

The proliferation of hate speech on social media necessitates robust automated detection systems. However, most existing models struggle with "code-mixed" text, where users switch between languages within a single sentence. Furthermore, many offensive comments are context-dependent; a reply may appear benign in isolation but becomes hateful when paired with its parent tweet. This study addresses these challenges by leveraging transformer models to capture conversational context in Hinglish Twitter data.

Methodology

The research compares two primary architectural strategies for incorporating context:

Single Encoder Approach

In the standard single-encoder setup, the context (parent tweet) and the target tweet are concatenated into a single input string, separated by a special [SEP] token. The model extracts a unified representation from the [CLS] token for classification.

Single Encoder Architecture: Concatenating context and target tweet.

Dual Encoder Approach

The dual-encoder approach processes the context and the target tweet separately through the transformer model. The resulting [CLS] embeddings for both inputs are then averaged. This method aims to preserve the distinct semantic nuances of both the original post and the reply, preventing the context from overwhelming the target tweet's signal.

Dual Encoder Architecture: Averaging independent representations of context and target tweet.

Experimental Setup

The models were evaluated using the HASOC 2021 ICHCL dataset, comprising 5,740 training and 1,348 test samples of Hinglish Twitter threads. The task required binary classification into "Hate and Offensive" (HOF) or "Non-Hate" (NOT).

Two transformer models were tested:

  • m-BERT (Multilingual BERT): Pre-trained on 102 languages.
  • Indic-BERT: A specialized ALBERT-based model trained on 12 major Indian languages.

Additional techniques included freezing embedding layers to prevent overfitting on the small dataset and incorporating a static dictionary of profane words to catch explicit offenses.

Results and Discussion

The dual-encoder setup consistently outperformed the single-encoder concatenation across various configurations. Key performance metrics (macro-averaged F1) include:

  • Baselines: m-BERT (65.53) and Indic-BERT (67.17).
  • Best Single Model: Indic-BERT with frozen embeddings, dual-encoder architecture, and a static dictionary achieved an F1 of 70.37.
  • Ensemble Performance: Combining multiple model variations yielded a top F1 score of 73.07.

Indic-BERT's superior performance over m-BERT suggests that models pre-trained on specific regional language families are better suited for code-mixed tasks. Furthermore, freezing embedding layers proved crucial for maintaining linguistic knowledge when fine-tuning on niche datasets.

Conclusion

This work highlights the importance of architectural choices in contextual text classification. Averaging independent representations in a dual-encoder setting provides a more effective way to handle conversational context than simple concatenation. Future work will explore more granular classification labels beyond binary categories and aim to reduce the computational overhead associated with ensemble methods for real-time applications.

Summary updated

BibTeX
@inproceedings{nayak2021contextual,
  author = {Ravindra Nayak and Raviraj Joshi},
  title = {{Contextual Hate Speech Detection in Code Mixed Text using Transformer Based Approaches}},
  booktitle = {FIRE (Working Notes)},
  year = {2021},
}
Figure