Introduction
In multilingual societies, "code-switching"—the practice of alternating between two or more languages within a single conversation or social media post—is a pervasive linguistic phenomenon. While traditional Natural Language Processing (NLP) approaches often treat code-mixed text as a vocabulary challenge, this research posits that the structural patterns of switching themselves carry significant pragmatic meaning. For instance, a speaker might switch to a native language to emphasize a joke or distance themselves from toxic content. This paper explores how explicitly modeling these switching behaviors can enhance the performance of downstream tasks like humor, sarcasm, and hate speech detection.
Methodology
The researchers developed a framework that combines deep learning with linguistic feature engineering. The core model is a Hierarchical Attention Network (HAN), designed to capture dependencies at both the word and sentence levels.
To incorporate the pragmatic signals of code-switching, the authors extracted nine specific features based on "run-lengths"—the number of consecutive words in one language before a switch occurs. These features include the total number of switches, the fraction of English versus Hindi words, and the mean and standard deviation of language "runs." These features are concatenated into the final fully-connected layer of the HAN, creating the HF (HAN + Feature) model. This architecture allows the network to weigh semantic content alongside structural linguistic patterns.
Experimental Setup
The study utilized three Hindi-English (hi-en) code-mixed datasets sourced from Twitter: Humour (3,453 tweets), Sarcasm (5,250 tweets), and Hate Speech (4,575 tweets). Statistical analysis revealed distinct patterns: humorous posts were "switch-heavy," averaging 7.84 switches compared to 6.50 for non-humorous ones. Conversely, sarcasm and hate speech tended to be "switch-light," often delivered in more sustained blocks of a single language.
Results and Discussion
The integration of code-switching features led to consistent performance gains across all three classification tasks. The most significant improvement was observed in hate speech detection, where the HF model achieved a 17.7% increase in Macro-F1 score over the baseline.
These results suggest that linguistic "tells" provide critical context that raw text embeddings alone might overlook. The dramatic jump in hate speech detection performance underscores the importance of structural signals in identifying toxic content in multilingual environments.
Conclusion
This research demonstrates that code-switching patterns are not merely noise but valuable features for social media analysis. By augmenting a Hierarchical Attention Network with simple linguistic features, the authors achieved substantial improvements in detecting nuanced intent. Future work will explore whether these patterns generalize to other language pairs and other NLP tasks like emotion or stance detection.
Summary updated