RB_BG_MHA: A RoBERTa-Based Model with Bi-GRU and Multi-Head Attention for Chinese Offensive Language Detection in Social Media

: Offensive language in social media affects the social experience of individuals and groups and hurts social harmony and moral values. Therefore, in recent years, the problem of offensive language detection has attracted the attention of many researchers. However, the primary research currently focuses on detecting English offensive language, while few studies on the Chinese language exist. In this paper, we propose an innovative approach to detect Chinese offensive language. First, unlike previous approaches, we utilized both RoBERTa’s sentence-level and word-level embedding, combining the sentence embedding and word embedding of RoBERTa’s model, bidirectional GRU, and multi-head self-attention mechanism. This feature fusion allows the model to consider sentence-level and word-level semantic information at the same time so as to capture the semantic information of Chinese text more comprehensively. Second, by concatenating the output results of multi-head attention with RoBERTa’s sentence embedding, we achieved an efﬁcient fusion of local and global information and improved the representation ability of the model. The experiments showed that the proposed model achieved 82.931% accuracy and 82.842% F1-score in Chinese offensive language detection tasks, delivering high performance and broad application potential.


Introduction
In recent years, with the widespread popularity of social media platforms such as Twitter, Facebook, and microblogging, the scope and scale of the online discussions people engage in has expanded.Social networks provide people around the world with the opportunity to express and share their thoughts instantly and widely.Unfortunately, a few users abuse the anonymity provided by online social media as an advantage and engage in social behavior that would not be acceptable in the real world, resulting in the constant emergence of offensive language.The reasons for the proliferation of offensive language may be: (1) due to the accessibility and anonymity of the platform [1].Social media provides a relatively anonymous and virtual platform allowing people to express their opinions without revealing their identities.This anonymity may make some users more prone to adopting offensive language because they do not have to bear the social consequences they might face when communicating face-to-face.(2) Social media has emphasized freedom of speech, allowing people to express their views more freely, even extreme or offensive ones, which raises questions about the balance between free speech and offensive speech.(3) There may be some commercial motives.These reasons provide a fertile environment for the spread of offensive and harmful content.Due to the lack of a well-developed legal system regarding offensive language, the difficulty of setting limits for the evolving cyberspace, the increased need for individuals to express their views and opponents to fight back, and the delay in manual checks by Internet operators, the spread of offensive language online has gained new momentum.It continues to challenge policymakers and the research community [2].
Appl.Sci.2023, 13, 11000 2 of 18 Offensive language often involves racism, sexism, and negative stereotypes about countries, religious entities, individuals, or minorities [1].This language can easily cause adverse effects, such as spreading hate and harassment.In addition, offensive language encourages inappropriate online behavior, such as personal attacks, cyberbullying [3], and hate speech, which seriously undermines the harmony of the online environment [4].In order to solve the above problems, many social media platforms check users' comments for offensive language and other violations through manual review mechanisms.Still, compared to the scale of people's online discussions, the manual review can only cover a small part of online interactions and is particularly costly in human resources [5].Automatic identification of offensive language allows the platform to detect offensive language and remove it faster and more efficiently than manual filtering, which is very time-consuming.Therefore, the task of automatic offensive language detection [6,7] has been widely discussed by researchers.
Currently, there are several methods for detecting offensive language and inappropriate content.These methods include rule-based, machine learning, deep learning, integrated, and pre-training methods in deep learning.The rule-based approach uses predefined rules and patterns to detect offensive language.For example, you can create rules to detect common offensive words, threatening phrases, or abusive speech.While these methods are relatively simple, they often require a lot of manual rule design and updating.Machine learning methods that can grasp diverse connections between text fragments and predict specific outputs for specific inputs using pre-labeled data as training material is widely favored in the scholarly exploration of detecting offensive language.Common machine learning algorithms include support vector machine (SVM), decision tree, random forest, etc.With the continuous improvement of machine learning models and the dramatic improvement in the performance of modern models trained for language tasks, AI-based offensive language detection has become a reality.Deep learning methods have made remarkable progress in the detection of offensive language.These methods use deep neural networks such as recurrent neural networks (RNN), short and long-term memory networks (LSTM), and Transformer to capture complex patterns in text.These models often require large amounts of labeled data to train, but they can achieve high performance in many cases.An integrated approach combines several different models or detectors to improve detection performance.Integrated approaches can include voting methods, stacking, or meta-learning techniques.Pre-trained deep learning models, such as BERT, GPT, and RoBERTa, have recently been used for offensive language detection.These models are pre-trained on large-scale text data and can be fine-tuned to suit specific detection tasks.They often perform excellently because they can understand the context.
Over the past few years, task performance in natural language processing has exploded.On the one hand, thanks to improvements in natural language algorithms, such as Text3D [8] (a 3D convolutional neural network for text classification), text classification research on low-resource language Tigrinya [9], optimization of LSTM model by adding an attention layer based on dropout layer and bidirectional recursion layer [10], and only using questions-answers archive automatically creates chatbots [11].On the other hand, this is mainly due to the development of the Transformer architecture.BERT, a Transformerbased model developed by Google, is the first deeply bidirectional, unsupervised language representation model by co-adjusting the left and right context in all layers [12].It has shown overwhelming performance and has been used as a central part of many studies in offensive language detection.RoBERTa is an improved model based on BERT, which further optimizes the structure of BERT by adjusting training hyperparameters and expanding training data sets, thereby improving its performance for natural language processing tasks [13].Compared to BERT, RoBERTa uses a longer training time and a larger corpus, allowing RoBERTa to understand semantics and context in natural language better.Techniques such as Bidirectional Gated Recurrent Unit and Multi-head attention have also been gradually applied in offensive language detection.Bidirectional GRU is based on recurrent neural network technology.It enables the extraction of long-term dependencies in the text by considering both forward and reverse information of the input sequence [14], thus capturing text fragments containing offensive category features.Multi-head attention can automatically calculate the weighted sum of different position vectors to realize the attention and memory of different positions in the text sequence and to capture rich information in different aspects of the text.Applying these techniques can supplement and enhance the feature representation and performance of the model from different angles.Integrating RoBERTa with bidirectional GRU and Multi-head attention may have great application prospects for enhancing the text perception ability of the model and the accuracy of offensive language detection.
Unfortunately, most of the work in offensive language detection has been carried out on English datasets, and most existing models focus on detecting offensive language in English.Although other languages such as Arabic, Turkish, Greek, Danish, and Urdu [15] are also increasing in proportion in this field [2], it is worth noting that Chinese, as a language with a large number of global speakers, has little research in the field of offensive language detection.Due to the lack of labeled data sets and reliable detectors, the problem of Chinese offensive language detection has yet to be well studied [16].
Therefore, the RB_BG_MHA model is proposed in this paper to detect offensive Chinese language in social media.First, we use the RoBERTa model to extract semantic information at the sentence and word levels and use the pre-trained language model to learn.Secondly, We leverage the bidirectional GRU model to further process word embedding for a richer context-dependent representation.We then integrate the information of the input sequence through the multi-head self-attention mechanism to extract global relationships and important features.Finally, we concatenate the output of multi-head attention with RoBERTa's sentence embedding to enable the model to take advantage of both local and global information.
The contributions of this work are as follows: (1) Addressing research gap: This study fills the Chinese language research gap in the field of offensive language detection.Although there has been a lot of research on the detection of English offensive language, the research on Chinese is relatively insufficient, especially considering the complexity of Chinese text; (2) Multi-level information fusion: Our proposed approach uses a multi-level information fusion strategy, combining RoBERTa's sentence-level and word-level embedding, bidirectional GRU model, and multi-head self-attention mechanism.This strategy enables the model to consider different levels of semantic information more comprehensively and helps to understand better and deal with the complexity of Chinese text; (3) Fine-grained detection of offensive language: Our research further expands the detection scope of offensive language, paying particular attention to the specific classification of offensive language, including race, gender, and region.This fine-grained exploration provides deeper insights to help us better understand and address the complexity of Chinese offensive language; (4) We conducted experiments on real data sets, and in various established indicators, the proposed model outperforms the existing baseline model and can effectively detect Chinese offensive language.
In the next section, we review related work on offensive language detection.Section 3 provides an overview of the relevant theory required and details our proposed approach.In Section 4, we present and discuss the experimental results in depth.Finally, Section 5 summarizes the main conclusions of this study and provides prospects for future work.

Research Methods of Offensive Language Detection
Offensive language refers to hurtful language, including hate speech, derogatory language, and profanity [2].Offensive language detection plays a vital role in maintaining the harmony of social platforms and promoting civilized communication.In recent years, many researchers have made efforts and proposed many methods for automatically detecting offensive language work.These techniques can be classified into two categories: conventional machine learning methodologies and deep learning approaches.Traditional machine learning methods build feature engineering for models, manually extracting meaningful features that can be used to train machine learning models such as naive Bayes, logistic regression, and support vector machines.Deep learning approaches employ multi-layer neural networks to automatically extract valuable features from input raw data.

Machine Learning Methods
Chen et al. [17] proposed the lexical-syntactic feature (LSF) structure to detect offensive content and potentially aggressive social media users.Based on the lexical and syntactic features of sentences, the offending value of sentences is obtained, and the traditional learning method is improved by using style, structure, and context features to predict potential aggressive users in social media.Nevertheless, the LSF framework is exclusively designed for English and disregards all other prominent languages, such as Chinese.Shylaja et al. [18] used Doc2Vec to generate document embedding as a feature of several supervised machine-learning methods to detect aggressive comments.Experimental results found that the method combined with Doc2Vec embedding and SVM classifier achieved the best detection results in a series of models.Bohra et al. [19] first attempted to detect hate speech in social media text with mixed Hindi-English code, proposing a supervised classification method that uses various character levels, word levels, and dictionary-based features to identify hate speech in mixed code text.Akhter et al. [20] developed an offensive language dataset of Urdu to detect the offensive language of Urdu, a resource-poor language.The n-grams technique extracted the features, and the offensive languages in Urdu and Roman Urdu data sets were detected and compared using multiple machine learning classifiers.

Deep Learning Methods
In recent years, many studies have used deep learning to solve the problem of offensive language detection with excellent performance, and some studies have confirmed the superiority of deep learning models over machine learning models.Roy et al. [21] created an automated system for hate speech detection on Twitter, employing deep convolutional neural networks (DCNN) to address the issue of identifying hate speech.The authors use GloVe embedding to represent the vector of the tweet text, capturing the semantics of the tweet with the help of convolution operations.Lu et al. [22] introduced a model for detecting cyberbullying involving a Character-Level Convolutional Neural Network with Shortcuts (Char-CNNS).Characters represent the most basic learning elements, enabling the model to tackle the issue of text misspelling on social media platforms.Learn mixed bullying signals with Shortcuts to stitch together different levels of features.Zhou et al. [12] used popular deep learning methods such as BERT, ELMo, and CNN to detect hate speech.They amalgamated the outcomes from diverse classifiers to enhance the classification performance.The classification results of CNN, ELMo, and BERT were combined to validate the practicality of the fusion technique in identifying hate speech.Djandji et al. [23] combined a pre-trained Arabic model (AraBERT) with multi-task learning to accurately enhance the AraBERT model to detect offensive language on Arabic social platforms.The experimental results show that the proposed multi-task AraBERT model is superior to single-task and multi-label AraBERT.

Other Methods
In addition to offensive language detection methods based on machine learning and deep learning, there are other approaches.For example, Gémes et al. [24] proposed a Bert-based offensive language detection method that performed well regarding F1 scores.In addition, they used the custom framework to build a high-precision rule-based offensive language detection method that can be used either as a standalone high-precision classifier or as a supplement to improve recall rates for Bert-based methods.Pradeep et al. [25] proposed a Dravidian hate speech and offensive language detection method based on a deep integration framework, which proposed some integration models mainly composed of DNN, BERT, and xlm-RoBERTa models.The distilBERT, DNN, and xlm-RoBERTa integrated models and BERT, DNN, and MuRIL integrated models performed best on two real datasets, respectively.Segun et al. [26] evaluated the intermediate pre-training of the offensive language recognition task.They used the pre-trained language model for the Twitter field to solve the offensive language detection task in Spanish and Mexican Spanish.They also found that further training in multilingual sentiment analysis benefited this task.

Correlation Data Sets
Due to the lack of a reliable Chinese data set for offensive language detection, Deng et al. [16] proposed a benchmark-COLD, which includes a Chinese data set for offensive language and a baseline detector trained on the data set.To the extent of the authors' awareness, this represents the initial openly accessible Chinese dataset for offensive language, comprising 37,480 comments annotated with binary labels covering diverse topics such as region, race, and gender.Chung et al. [1] proposed a Chinese abusive language dataset, TOCAB, which contained 121,344 comments from social media sites.The authors used several baseline systems of machine learning and deep learning to test this benchmark, and experimental results indicated that the deep learning model exhibited superior performance compared to the machine learning model.Lu et al. [27] proposed TOXICN, a fine-grained dataset containing indirect toxicity samples, which promotes fine-grained Chinese toxic language detection.It also constructs insult words containing implied profanity.It proposes the Toxic Knowledge Enhancement (TKE) benchmark to introduce lexical features to detect toxic language and verifies the effectiveness of TKE through experiments.On the other hand, Zhou et al. [28] used the offensive language detection data of Korean and English, two different cultural backgrounds, to explore the influence of transfer learning on identifying offensive language in the Chinese context.Their findings demonstrate the promise of non-English offensive language detection in resource-limited Settings, emphasizing the significance of cross-cultural transfer learning in enhancing the performance of offensive language detection.

Literature Review: Summary and Evaluation
Most traditional machine learning methods rely on manually designed features, which can have limitations when dealing with data diversity and a changing network context.However, deep learning can overcome some limitations of traditional methods in offensive language detection, avoid cumbersome manual feature engineering, and improve the adaptability and generalization ability of the model.Other methods, such as rule-based approaches, are suitable for simple tasks and specific contexts but perform poorly in complex and diverse offensive language detection.An integration-based approach can improve performance but requires more computing resources and data.Pretraining-based methods perform well in modern offensive language detection because of their strong representation and adaptability, but they also need more computational resources and data support.
There is a significant research gap in the field of offensive language detection, that is, the focus tends to be on English, while the research on offensive language detection of other languages is relatively insufficient, which leads to an urgent need to focus on other languages.In terms of Chinese offensive language detection, the complexity of Chinese text increases the difficulty of this task.Chinese has a rich grammatical structure, which may require more complex natural language processing techniques to cope with, but also may present researchers with more challenges.Therefore, we chose to focus our research on Chinese, which, despite its large number of speakers, has relatively few studies on offensive detection.
Our proposed approach fills this research gap by employing multi-level information fusion strategies, including RoBERTa's sentence-level and word-level embedding, bidirec-tional GRU model, and multi-head self-attention mechanism, which enable the model to consider different levels of semantic information at the same time and contribute to a better understanding of the complexity of Chinese text.In addition, by concatenating the output of multi-head attention with RoBERTa's sentence embedding, the model makes use of local and global information simultaneously, improving the model's representation ability and helping to better deal with the complex context in Chinese text.
Another research gap is that most studies still need to address the issue of finegrained offensive language detection.In our study, we further expanded the scope of detection of offensive language, paying special attention to the specific classification of offensive language, including race, gender, and region.This fine-grained exploration provides deeper insights to help us better understand and address the complexity of Chinese offensive language.

RoBERTa Layer
RoBERTa aims to learn a common language representation by pre-training largescale unlabeled text data for fine-tuning and application on various downstream natural language processing tasks.Figure 1 is an architecture diagram of RoBERTa's model.fensive detection.
Our proposed approach fills this research gap by employing multi-level infor fusion strategies, including RoBERTa's sentence-level and word-level embedding, b tional GRU model, and multi-head self-attention mechanism, which enable the m consider different levels of semantic information at the same time and contribute t ter understanding of the complexity of Chinese text.In addition, by concatenat output of multi-head attention with RoBERTa's sentence embedding, the model use of local and global information simultaneously, improving the model's represe ability and helping to better deal with the complex context in Chinese text.
Another research gap is that most studies still need to address the issue o grained offensive language detection.In our study, we further expanded the scope tection of offensive language, paying special attention to the specific classification fensive language, including race, gender, and region.This fine-grained exploratio vides deeper insights to help us better understand and address the complexity of C offensive language.

RoBERTa Layer
RoBERTa aims to learn a common language representation by pre-training scale unlabeled text data for fine-tuning and application on various downstream language processing tasks.Figure 1  In the MLM task, the model needs to predict the obscured words based on the context.For a given input text T = {W 1 , W 2 , . . . ,W n }, RoBERTa first masks some random words and replaces them with the special MASK token "[MASK]" to obtain the mask text M = {m 1 , m 2 , . . . ,m n }.
Then, RoBERTa encodes through the Transformer model to obtain the output H = {h 1 , h 2 , . . . ,h n } of the encoder layer.For a mask position m i , RoBERTa maps d model to a dimensional vector z = W out h i by linear transformation and obtains the final predicted distribution P(z|T) by softmax operation.
In the NSP task, the model needs to determine whether two sentences are continuous.
For a pair of input sentences S = (s 1 , s 2 ), RoBERTa represents them as a special sequence [CLS]s 1 [SEP]s 2 [SEP].RoBERTa then passes this composite sequence into the Transformer model for encoding, yielding the output H = {h 1 , h 2 , . . . ,h n }.Here, h 1 repre- sents the output of the composite sequence's first token "[CLS]".RoBERTa then takes the vector h 1 representing the entire sequence as input and runs it through a binary classifier to determine whether the two sentences occur in succession.

Bidirectional GRU Layer
A Bidirectional Gated Recurrent Unit is a recurrent neural network (RNN) variant that considers past and future contextual information in time series data.GRU is a gated loop unit that models long-term dependencies in sequence data.In a traditional one-way RNN, information flows in only one direction, from the past to the future.The bidirectional GRU incorporates an additional reverse layer, enabling information propagation in both the forward and backward directions, thus enhancing the capture of contextual information within sequence data.

Forward GRU
The internal cell structure of a forward GRU is shown in Figure 2.
In the NSP task, the model needs to determine whether two sentences are con For a pair of input sentences  = ( 1 ,  2 ), RoBERTa represents them as a sp quence [CLS] s 1 [SEP] s 2 [SEP] .RoBERTa then passes this composite sequence Transformer model for encoding, yielding the output  = {ℎ 1 , ℎ 2 , ⋯ , ℎ  }.Here, h sents the output of the composite sequence's first token "[CLS]".RoBERTa then t vector h 1 representing the entire sequence as input and runs it through a binary c to determine whether the two sentences occur in succession.pre-training process, including random removal and dynamic masking helped the model better adapt to various natural language processing tasks.

Bidirectional GRU Layer
A Bidirectional Gated Recurrent Unit is a recurrent neural network (RNN) that considers past and future contextual information in time series data.GRU is loop unit that models long-term dependencies in sequence data.In a traditional o RNN, information flows in only one direction, from the past to the future.The tional GRU incorporates an additional reverse layer, enabling information propag both the forward and backward directions, thus enhancing the capture of contex formation within sequence data.

Forward GRU
The internal cell structure of a forward GRU is shown in Figure 2.  The formula for the forward GRU is Appl.Sci.2023, 13, 11000

Backward GRU
The formula for the backward GRU is similar to that for the forward GRU, except that the forward input sequence is arranged in reverse order in the time dimension to obtain the reverse input sequence, and then the operation is performed on it.The internal cell structure of a backward GRU is shown in Figure 3.

Backward GRU
The formula for the backward GRU is similar to that for the forward GRU that the forward input sequence is arranged in reverse order in the time dime obtain the reverse input sequence, and then the operation is performed on it.The cell structure of a backward GRU is shown in Figure 3.The formula for the backward GRU is

Bidirectional GRU Output
After going through the forward and backward GRUs, we spliced their outputs to obtain the output of the bidirectional GRU: where Concat represents the concatenation of two vectors according to dimension.

Multi-Head Attention Layer
Multi-head attention is an extended attention mechanism based on the self-attention mechanism to deal with information interaction and representation learning in sequence data.It is a crucial component of the Transformer model and is widely used in natural language processing tasks.Here are the critical steps for Multi-head attention:

Linear Mapping
Given an input sequence X = R n×d model , we transform it into a sequence of queries, keys, and values via linear mapping: where i ∈ [1, h], d k , d v are dimensions that can be specified by hyperparameters, and W Q i , W K i , W V i are learnable weight matrices with shapes R d model ×d k , R d model ×d k , and R d model ×d v .

Self-Attention Matrix
For the query, key, and value of group i, we calculated the similarity through the dot product and then performed softmax to obtain the corresponding self-attention matrix A i ∈ R n×n : The dot product attention mechanism defines the similarity calculation of query and key as The result of matrix multiplication QK T is a matrix of size (n,n), where each element (i,j) represents a similar fraction of the ith element in the query sequence and the jth element in the key sequence.

Final Output
By concatenating the self-attention matrix A i and the corresponding value V i , we can obtain where Concat indicates splicing by dimension.
Finally, the concatenated ∼ V is converted to the corresponding output by linear mapping

Proposed Model
The proposed model gradually extracts the semantic information of the input sequence through representation learning at multiple levels, as shown in Figure 4. First, the RoBERTa model encoded each sentence to generate sentence embedding, while also generating word embedding for each word.These embedding vectors contain the semantic information of the text.We then passed the word embedding extracted by the RoBERTa model to the bidirectional GRU model, which processes the word embedding for each word, considering the contextual information of the word in the sequence.We then used a multi-head self-attention mechanism to integrate the output of the bidirectional GRU, which helps identify essential features in the text.Finally, the output results of the multihead attention mechanism were concatenated with the sentence embedding extracted by the RoBERTa model, which combines the global relational and context-dependent representation with the semantic information at the original sentence level to obtain a richer semantic representation.where  indicates splicing by dimension.Finally, the concatenated  ̃ is converted to the corresponding output by linear mapping   ∈ ℝ ℎ  ×  :  =  ̃ , (17)

Proposed Model
The proposed model gradually extracts the semantic information of the input sequence through representation learning at multiple levels, as shown in Figure 4. First, the RoBERTa model encoded each sentence to generate sentence embedding, while also generating word embedding for each word.These embedding vectors contain the semantic information of the text.We then passed the word embedding extracted by the RoBERTa model to the bidirectional GRU model, which processes the word embedding for each word, considering the contextual information of the word in the sequence.We then used a multi-head self-attention mechanism to integrate the output of the bidirectional GRU, which helps identify essential features in the text.Finally, the output results of the multihead attention mechanism were concatenated with the sentence embedding extracted by the RoBERTa model, which combines the global relational and context-dependent representation with the semantic information at the original sentence level to obtain a richer semantic representation.The model can take advantage of local and global information by concatenating the output of multi-head attention with RoBERTa's sentence embedding.This kind of model integration can provide more abundant feature representation, thus enhancing the expressiveness of the model.

Roberta
The process is as follows: Given an input sequence X ∈ R n×d x , where d x represents the dimensional size of the input sequence.
First, we used the RoBERTa model to extract the semantic representation of the input sequence to obtain the sentence embedding H R ∈ R d r , where d r Represents the sentence embedding dimension of the RoBERTa model.At the same time, the word embedding matrix H W ∈ R n×d w is obtained through the RoBERTa model, where each line represents the embedding vector of a word, representing the semantic information of each word in the input sequence, and d w is the dimension of word embedding.
Second, we use the bidirectional GRU model to further process the word embedding, yielding the output H G ∈ R n×d g of the GRU model, where d g represents the output dimension of the GRU model.
Then, we used the multi-head self-attention mechanism to further integrate the information from the input sequence and obtain the final representation H A ∈ R d a , where d a represents the output dimension of the attention mechanism.
Specifically, we first took the output H G of the GRU model as the input query, key, and value in the self-attention mechanism, respectively, and then used multiple attention heads to compute in parallel, concatenate the output of each head to obtain the feature representation of the multi-head attention computation, and, after that, we applied a linear layer to transform the output of the multi-head attention to obtain the output result H A ∈ R d a .Finally, H A and H R were concatenated, and then the concatenated result was fed into the fully connected layer for classification to obtain the final result.
To sum up, the formula of the entire model is expressed as follows: where RoBERTa(•) represents the RoBERTa model, BiGRU(•) represents the bidirectional GRU model, MultiHeadAttention(•) represents the multi-head self-attention mechanism, d r , d g , and d a represents the output dimensions of the RoBERTa model, bidirectional GRU model, and multi-head self-attention mechanism, respectively.

Data Set Preparation
The experiment in this paper was conducted on the COLD Chinese offensive language dataset collected by Deng et al. [16], which was created using authentic data published on Chinese social media platforms (Zhihu and Weibo) and contained 37,480 comments with binary offensive labels covering various topics of race, gender, and region.The details are shown in Table 1.The partitioning of the data set is shown in Table 2.

Experimental Environment and Parameter Setting
This experiment was run on a 3090-24G GPU, PyTorch 1.13.1,Cuda 11.7.0, and the Python3.8 environment.Using AdamW as the optimizer, the learning rate was set to0.00001, the Weight Decay coefficient was set to0.00001, the Hidden Size was set to 768, the number of heads of the attention mechanism was set to 4, and the batch size was set to 64.The training process introduces the dropout technique, and the dropout rate was set to 0.1.This technique can randomly discard nodes in a particular proportion, thus effectively preventing overfitting.

Evaluation Index
The model effect was evaluated by accuracy, precision, recall, and F1-score.
where TP: true positive (positive category predicts correct outcome), TN: true negative (negative categories predict correct negative categories predict correct results), FP: false positive (positive categories predict incorrect outcome), FN: false negative (negative categories predict incorrect outcome).

Baseline Method
Baidu Text Censor: It is a text content review service provided by Baidu, designed to help enterprises and developers achieve automatic review and filtering of text content.The API can identify and filter harmful content, such as abuse, pornography, violence, terrorism, etc., to protect users from wrong information.
COLDET [16]: COLDET(COLDETECTOR) uses an architecture based on the transformer and pre-trained model BERT.The backbone of the model is the bert-base-chines model with 12 layers and 12 attention heads.
RoBERTa + TKE [27]: The model applies the TKE (Toxic Knowledge Enhancement) method to the RoBERTa model by means of an insult lexicon containing explicit profanity and implicit profanity, combined with lexical features to detect toxic language.XLM-Rlarge [29]: A cross-language pre-trained series of models based on Transformer architecture developed by the Facebook AI Research team XLM-R (Cross-lingual Language Model for Robust Pre-Training).XLM-Rlarge is the larger version of the XLM-R family, with a deeper model structure and more parameters than XLM-Rbase.

Contrast Experiment
To verify the RB_BG_MHA model, a series of experiments were conducted and compared with other models.Simultaneously, the experimental results were analyzed in detail to showcase the efficacy of our model in identifying offensive language in the Chinese context.
According to the comparative experimental results in Table 3, the accuracy of the RB_BG_MHA model on the test set was 82.931%, the precision was 82.257%, the recall was 83.436%, and the F1-score was 82.842%.Compared with other models, our proposed model shows better results in accuracy, precision, recall, and F1-score.The RoBERTa + TKE model also showed good performance, while the XLM-Rlarge model achieved high results in accuracy but a relatively low F1-score.However, the Baidu Text Censor model performs poorly on the whole, with low accuracy, precision, and recall, the latter displaying a rate of only 27.005%.Compared with Baidu Text Censor, the method based on deep learning has achieved better performance.A plausible rationale is that the online API's filtering mechanism predominantly depends on keyword dictionaries.As a result, it cannot effectively detect sentences that contain indirect offensive language.In summary, compared with other models, our proposed model can provide more abundant feature representation and can understand and express the semantics of sentences more accurately, thus achieving better results.Although the current performance is only slightly optimized compared to the RoBERTa + TKE method, we will consider carrying out the following the future to improve the performance of our method: Introducing lexical features: For offensive language detection tasks, it is relatively easy to detect direct offensive samples, but it is challenging to detect indirect offensive instances (such as stereotypes and sarcasm).Therefore, our future work will construct a dictionary containing implied insult and offensive words to introduce indirect offensive word features and obtain a weighted enhanced representation of each word so that the obtained sentence embedding will include implied offensive word features to improve the performance of offensive language detection; Data enhancement and diversity: We plan to collect more data on the Chinese offensive language and ensure the variety of the data set, which will help the model to better generalize to situations of various offensive languages.
From Table 4 we can notice that the RB_BG_MHA model has a higher number of parameters and a longer running time with respect to the RoBERTa and RoBERTa + TKE models.This reflects the higher complexity of our model, which may lead to a waste of computational resources in some cases.However, we recognize this drawback and will further optimize and reduce our model complexity to reduce the running time without harming performance to meet the dual requirements of performance and computational efficiency.Previous studies failed to detect specific types of offensive content in detail, so we conducted further fine-grained detection of Chinese offensive language, focusing on specific categories of offensive language, including race, gender, region, etc.We also performed offensive language detection for each of the three types of social text.Through this research, we aim to more accurately identify and understand offensive language and provide more effective content filtering and monitoring mechanisms for social media.
Figure 5 shows the results of the specific classification of offensive language by race, gender, and region.Among these performance indicators, the highest was recall (81.3%), and the lowest is precision (80.3%), while accuracy and F1-score were around 80.8%.The experimental results of offensive language detection for different text types showed that the gender category performed best in offensive language detection, despite the small number of data.This phenomenon may be attributed to the inclusion of specific words (such as "male" and "female") in the offensive language of the gender category, which may be more easily captured by the model, thus improving the accuracy of the detection.In contrast, the offensive language in the race category presents a more complex text structure, which makes it difficult for the model to accurately capture hidden features, resulting in lower detection performance.
harming performance to meet the dual requirements of performance and computa efficiency.Previous studies failed to detect specific types of offensive content in detail, s conducted further fine-grained detection of Chinese offensive language, focusing on cific categories of offensive language, including race, gender, region, etc.We also formed offensive language detection for each of the three types of social text.Throug research, we aim to more accurately identify and understand offensive language and vide more effective content filtering and monitoring mechanisms for social media.
Figure 5 shows the results of the specific classification of offensive language by gender, and region.Among these performance indicators, the highest was recall (81 and the lowest is precision (80.3%), while accuracy and F1-score were around 80.8% experimental results of offensive language detection for different text types showed the gender category performed best in offensive language detection, despite the number of data.This phenomenon may be attributed to the inclusion of specific w (such as "male" and "female") in the offensive language of the gender category, w may be more easily captured by the model, thus improving the accuracy of the dete In contrast, the offensive language in the race category presents a more complex text ture, which makes it difficult for the model to accurately capture hidden features, r ing in lower detection performance.This phenomenon can also be explained by the fact that in the gender categor explicit gender-related words lead to clearer feature performance, which is conduc effective classification.In the race category, the offending language may be more s and varied, with greater changes in semantics and context, which increases the comp This phenomenon can also be explained by the fact that in the gender category, the explicit gender-related words lead to clearer feature performance, which is conducive to effective classification.In the race category, the offending language may be more subtle and varied, with greater changes in semantics and context, which increases the complexity of model identification.Therefore, differences in data characteristics and language complexity may be one of the key factors leading to performance differences.

Ablation Analysis
In order to verify the role of each component of the model and the integrity of the model, this paper strips each component from the model one by one and observes the degree of its impact on the model performance.If the model performance degrades after removing a component, it indicates that the component is indispensable and of independent importance.Otherwise, it is dispensable.If the model performance suffers when each component is removed, then the model is unified, and each component is indispensable.
We conducted the following ablation experiments to verify the integrity of the RB_BG_MHA model.We removed each component one by one and observed changes in model performance.If the model's performance decreased after removing a component, it indicated that the component plays an essential role in the model's performance.
Table 5 shows the ablation experiment results, which are visually represented as shown in Figure 6.The model was decomposed into three modules: sentence embedding, word embedding + BiGRU, and multi-head self-attention, and one module was removed one by one to evaluate its impact on the model performance. of model identification.Therefore, differences in data characteristics and language plexity may be one of the key factors leading to performance differences.

Ablation Analysis
In order to verify the role of each component of the model and the integrity o model, this paper strips each component from the model one by one and observe degree of its impact on the model performance.If the model performance degrades removing a component, it indicates that the component is indispensable and of indep ent importance.Otherwise, it is dispensable.If the model performance suffers when component is removed, then the model is unified, and each component is indispens We conducted the following ablation experiments to verify the integrity o RB_BG_MHA model.We removed each component one by one and observed chang model performance.If the model's performance decreased after removing a compo it indicated that the component plays an essential role in the model's performance.
Table 5 shows the ablation experiment results, which are visually represente shown in Figure 6.The model was decomposed into three modules: sentence embed word embedding + BiGRU, and multi-head self-attention, and one module was rem one by one to evaluate its impact on the model performance.When the sentence embedding module was removed, the RB_BG_MHA model using only word embedding was formed, and the model's accuracy decreased by about 1.1%.The precision, recall, and F1-score all decreased by about 1.0%.When the multi-head self-attention module was removed, the RB_BG model using both word embedding and sentence embedding was formed, and the accuracy of the model was reduced by about 1.9%, the precision by about 1.7%, and the recall by about 1.5%.The F1-score fell by about 1.6%.When the word embedding module was removed, the RB_MLP model using only sentence embedding was formed, and the accuracy of the model decreased by about 1.3%, the precision decreased by about 1.1%, the recall decreased by about 0.9%, and the F1-score decreased by about 1.0%.
Through the above experimental results, this paper can fully reveal the role of each component of the model and the integrity of the model, and it can be clearly observed that the performance of the RB-BG-MHA model depends on the joint action of each module, which is indispensable.

Conclusions
Although English offensive language detection has been extensively studied, Chinese offensive language detection needs to be more studied, especially considering the complexity of Chinese text.Our study fills the Chinese research gap in offensive language detection.Our approach adopts multi-level information fusion strategies, including RoBERTa's sentence-level and word-level embedding, a bidirectional GRU model, and a multi-head self-attention mechanism, which enables the model to consider different levels of semantic information simultaneously.It helps to understand the complexity of Chinese text better.In addition, by concatenating the output results of multi-head attention with RoBERTa's sentence embedding, the efficient fusion of local and global information was realized, and the representation ability of the model was improved, which helps to better deal with the complex context in Chinese text.Our study further expands the scope of detection of offensive language, focusing on specific categories of offensive language, including race, gender, and region.This fine-grained exploration provides deeper insights to help us better understand and address the complexity of Chinese offensive language.
The experimental results show that our proposed method effectively detects Chinese offensive language.In addition, the ablation experiment also confirmed that the performance of our model depends on the synergistic effect of each module, and each module is indispensable.We also developed a series of strategies to continue to improve.First, we plan to build a dictionary of implicit insult and offensive words to introduce implicit offensive word features, thereby improving the performance of the model.Secondly, we will actively collect more Chinese offensive language data to ensure better generalization performance of the model.In addition, our future work will focus on promoting research in the field of mixed-language offensive language detection to adapt to diverse language environments and application scenarios.Finally, we plan to delve deeper into the joint analysis of multimodal information to further improve the performance and applicability of our method.

Figure 1 .Figure 1 .
Figure 1.Schematic diagram of the structure of the RoBERTa model.

( 3 )
Training parameters: RoBERTa has improved some training hyperparameters.It uses larger batch sizes, longer training sequences, and more training steps to enhance the model's performance; (4) Dynamic mask: RoBERTa introduced the concept of dynamic mask.Each training instance randomly generates a mask during each training step.This can improve the model's generalization ability and reduce the dependence on location information; (5) Randomization during training: RoBERTa used more randomization methods in the pre-training process, including random removal and dynamic masking, which helped the model better adapt to various natural language processing tasks.

( 3 )
Training parameters: RoBERTa has improved some training hyperparameters larger batch sizes, longer training sequences, and more training steps to enh model's performance; (4) Dynamic mask: RoBERTa introduced the concept of dynamic mask.Each instance randomly generates a mask during each training step.This can imp model's generalization ability and reduce the dependence on location inform (5) Randomization during training: RoBERTa used more randomization method

Figure 2 .
Figure 2. Schematic diagram of the forward GRU model.

Figure 2 .
Figure 2. Schematic diagram of the forward GRU model.

where z f T
represents the update gate, r f T represents the reset gate, and represents the multiplication of element levels, h f T−1 is the hidden state of the previous time step, and h f T is the hidden state of the current time step.

T
where z b T represents the backward update gate, r b T represents the backward reset gate, and represents the multiplication of element levels, h b T is the hidden state of the current time step, h b T+1 is the hidden state of the latter time step.W b z , W b r , W b h are the weight matrices Appl.Sci.2023, , respectively.U b z is the weight matrix from h b T+1 to z b T , U b r is the weight matrix from h b T+1 to r b T , and U b h is the weight matrix dealing with r b T and h b T+1 .

Figure 4 .
Figure 4. Schematic diagram of the structure of the proposed RB_BG_MHA model.(The solid arrow represents the forward GRU and the dashed arrow represents the backward GRU.)

Figure 4 .
Figure 4. Schematic diagram of the structure of the proposed RB_BG_MHA model.(The solid arrow represents the forward GRU and the dashed arrow represents the backward GRU.)

Figure 5 .
Figure 5. Offensive language detection: category prediction and analysis of race, gender, and topics.

Figure 5 .
Figure 5. Offensive language detection: category prediction and analysis of race, gender, and region topics.

Table 1 .
Statistics of COLD dataset under each topic.List the number of offensive language samples and non-offensive language samples corresponding to the race, region, and gender topics.

Table 2 .
Distribution statistics of samples from different classes in the COLD dataset.

Table 3 .
Comparison of offensive language detection performance across different models on our test set.

Table 4 .
Experimental comparison of the number of parameters and running time in RoBERTa-based models.

Table 4 .
Experimental comparison of the number of parameters and running time in RoB based models.