Few-shot Hate Speech Detection Based on the MindSpore Framework

Zhenkai Qin · 2025

Read Few-shot Hate Speech Detection Based on the MindSpore Framework by Zhenkai Qin (2025) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2504-15987.txt.

Introduction

Zhenkai Qin and co-authors build a hate speech detector that works when labeled examples are scarce. Their 2025 paper, MS-FSLHate, runs on the MindSpore platform. Deep models usually lean on large tagged corpora, and their accuracy sags in the few shot settings that new platforms and new slurs actually present.

The framework mixes three tricks: learnable prompt embeddings that steer the model, a hybrid network with attention pooling that reads each post, and synonym based adversarial augmentation that hardens training. On the HateXplain and HSOL benchmarks it beat rival baselines on precision, recall, and F1. The team stresses efficiency, pitching the system for places with thin data and thin hardware alike.

Catalog record

CREATORZhenkai Qin
YEAR2025
COLLECTIONPAPERS
FORMATTXT
FILE SIZE34 KB
VERSION1.0
LICENSEhttp://creativecommons.org/licenses/by/4.0/
RIGHTSCC BY
SOURCEarXiv

Source: https://arxiv.org/abs/2504-15987

Browse the full library · About the Tower of Babel

Full text

The opening of the work, from the library's hosted text:

Few-shot Hate Speech Detection Based on the MindSpore Framework Thanks: Citation : Authors. Title. Pages…. DOI:000000/11111. Zhenkai Qin Abstract The proliferation of hate speech on social media poses a significant threat to online communities, requiring effective detection systems. While deep learning models have shown promise, their performance often deteriorates in few-shot or low-resource settings due to reliance on large annotated corpora. To address this, we propose MS-FSLHate , a prompt-enhanced neural framework for few-shot hate speech detection implemented on the MindSpore deep learning platform. The model integrates learnable prompt embeddings, a CNN-BiLSTM backbone with attention pooling, and synonym-based adversarial data augmentation to improve generalization. Experimental results on two benchmark datasets—HateXplain and HSOL—demonstrate that our approach outperforms competitive baselines in precision, recall, and F1-score. Additionally, the framework shows high efficiency and scalability, suggesting its suitability for deployment in resource-constrained environments. These findings highlight the potential of combining prompt-based learning with adversarial augmentation for robust and adaptable hate speech detection in few-shot scenarios. K eywords MindSpore Framework \cdot Adversarial Data Augmentation \cdot Prompt-based Models \cdot Hate Speech Detection \cdot Few-shot Learning 1 Introduction In recent years, the proliferation of hate speech on social media platforms has emerged as a critical societal concern. The ease of information dissemination via platforms such as Twitter, Facebook, and Gab has unfortunately enabled the rapid spread of discriminatory, offensive, and hateful content targeting individuals and communities based on race, gender, religion, and other attributes. The prevalence of such content not only threatens online safety and civil discourse but also contributes to offline violence, psychological harm, and the marginalization of vulnerable groups. In response, automatic hate speech detection has become an urgent and highly active area of research within natural language processing (NLP). Traditional approaches to hate speech detection typically rely on rule-based systems or classical machine learning algorithms such as support vector machines (SVM) and logistic regression. More recently, deep learning-based methods, including convolutional neural networks (CNNs), recurrent neural networks (RNNs), and transformer-based models, have shown substantial promise due to their ability to learn contextual and semantic features from text. Despite their success, these models often assume access to large-scale annotated datasets and may suffer from poor generalization when applied to real-world scenarios with limited or imbalanced data. Moreover, hate speech is highly contextual and subtle, often requiring nuanced understanding and domain-specific cues, which further complicates model development. One of the most pressing challenges in building reliable hate speech detection systems is the scarcity of high-quality annotated data. Manual labeling is labor-intensive, time-consuming, and ethically sensitive, making large-scale dataset construction difficult, particularly for emerging or under-resourced languages and domains. Additionally, hateful content frequently exhibits long-tail distributions, where truly harmful instances are rare and diverse, exacerbating the class imbalance problem. These constraints highlight the need for methods that are effective in few-shot learning scenarios—where only a small number of labeled examples are available for training. To address these limitations, we propose a novel framework for few-shot hate speech detection based on prompt-enhanced deep learning, implemented using the MindSpore platform. MindSpore is an open-source deep learning framework developed in China that offers efficient graph-mode execution, strong hardware adaptability, and high modularity for model customization. These properties make it particularly suitable for rapid prototyping and experimentation in research settings with limited computational resources. Our method introduces a learnable prompt embedding mechanism that prepends task-specific virtual tokens to input sequences, enabling the model to better encode semantic priors even under data-scarce conditions. In addition, we employ adversarial data augmentation via synonym replacement, which increases lexical diversity while preserving semantic consistency. This strategy enhances the model’s robustness to variations in phrasing and vocabulary, which are common in user-generated content. Comprehensive experiments are conducted on two publicly available benchmark datasets—HateXplain and the Hate Speech and Offensive Language Dataset (HSOL)—to demonstrate the effectiveness of the proposed approach. The main contributions of this paper are as follows: • We propose a novel prompt-based neural architecture for few-shot hate speech detection, built upon the MindSpore framework to leverage its efficient graph-based execution and flexibility. • We introduce an adversarial data augmentation strategy based on synonym replacement to improve model generalization under limited supervision. • We conduct extensive experiments on two benchmark datasets, showing that our method outperforms existing baselines across multiple evaluation metrics in few-shot settings. 2 Related Work Automated hate speech detection has received growing attention due to the increasing volume of offensive and abusive content on social media platforms. Early approaches primarily relied on rule-based systems or traditional machine learning classifiers such as support vector machines (SVMs) and logistic regression [ 1 ] , often supported by handcrafted features or keyword lists. While these methods were computationally efficient, they typically suffered from poor generalization and high false positive rates, particularly when dealing with implicit hate, sarcasm, or code-switching. The advent of deep learning led to substantial improvements in detection performance, with convolutional neural networks (CNNs), recurrent neural networks (RNNs), and more recently, transformer-based models such as BERT and RoBERTa demonstrating strong capabilities in capturing contextual semantics [ 2 , 3 , 4 ] . Complementary enhancements have included attention-based pooling [ 5 ] , multi-task learning [ 6 ] , and multimodal architectures that integrate user metadata or visual content [ 7 ] . However, the majority of these methods assume access to large-scale annotated datasets and tend to degrade when applied to domain-shifted or data-scarce scenarios. To alleviate the reliance on large labeled corpora, few-shot learning (FSL) has been actively explored as a data-efficient alternative. Meta-learning approaches such as Prototypical Networks, Matching Networks [ 8 ] , and MAML [ 9 ] have shown success in NLP tasks including intent classification and relation extraction [ 10 ] . Nevertheless, applying FSL to hate speech detection remains a largely underexplored direction due to challenges such as class imbalance, semantic ambiguity, and the subtle nature of toxic language. Moreover, conventional fine-tuning of large-scale pre-trained models often leads to overfitting when only a few training samples are available [ 11 ] . Recent studies have introduced task-adaptive pretraining, prototype-based regularization, and contrastive learning [ 12 , 13 ] to improve few-shot generalization, yet these strategies have not been systematically applied to socially sensitive tasks like hate speech detection. Parallel to these developments, prompt-based learning has emerged as a powerful paradigm for adapting large language models to downstream tasks with minimal supervision. By reformatting classification problems into cloze-style or masked language modeling templates, prompt tuning leverages the pre-trained knowledge embedded within large models [ 14 ] . Early methods focused on manually designed prompts, which were later superseded by learnable alternatives such as soft prompt tuning [ 15 ] , prefix tuning [ 16 ] , and instruction tuning [ 17 ] . These techniques have achieved competitive performance in various few-shot tasks, including sentiment classification and question answering. However, their application to hate speech detection remains limited. Some recent efforts have considered prompt-based toxicity classification [ 18 ] , but these studies rarely address challenges related to robustness, fairness, or linguistic diversity, particularly in low-resource settings. Building on these prior directions, our work proposes a prompt-enhanced neural architecture specifically designed for few-shot hate speech detection. It integrates learnable task-adaptive prompts with a lightweight CNN-BiLSTM backbone and

Read the complete text