A Chinese hate speech detection method integrating multi-dimensional sentiment features
By integrating multi-dimensional emotional features into a Chinese hate speech detection method, and utilizing RoBERTa and BiLSTM networks, the adaptation problem of hate speech detection in Chinese social media was solved, achieving more efficient detection results.
Patent Information
- Application Number
- CN202411811817.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-10
- Publication Date
- 2025-10-28
- Estimated Expiration
- 2044-12-10
AI Technical Summary
Existing technologies lack methods for detecting hate speech on Chinese social media. Applying foreign language technologies cannot effectively adapt to the special grammar and context of Chinese, resulting in poor recognition results. Furthermore, existing research has not fully considered multidimensional emotional features, especially emotional intensity, negation words, and punctuation marks.
We employ a RoBERTa pre-trained model combined with a sentiment dictionary to extract word-level, sentence-level, and multi-dimensional sentiment features from the text. We then fuse local and global information using a BiLSTM network and optimize the model using a focus loss function to address the problem of imbalanced data categories.
It improves the accuracy and robustness of Chinese hate speech detection, enhances the ability to understand local and global information, and significantly improves the ability to identify subtle hate speech.
Smart Images

Figure CN119903224B_ABST
Abstract
Description
Technical Field
[0001] This invention pertains to the detection of Chinese hate speech in natural language processing, and specifically relates to a method for detecting Chinese hate speech that integrates multi-dimensional sentiment features. Background Technology
[0002] With the rapid development of social media, the way people communicate has changed. At the same time, the convenience and anonymity of online speech tempt people to act without regard for reality, leading to the rampant spread of hate speech and causing significant social instability. Therefore, developing an efficient and accurate method for detecting hate speech is of great importance.
[0003] Early hate speech detection methods primarily relied on manually extracted features combined with machine learning to classify hate speech. However, traditional machine learning methods could only uncover shallow features of hate speech, and their detection performance was overly dependent on feature selection. With the advent of deep learning technology, especially pre-trained models like BERT and RoBERTa, their superior text processing capabilities have led to their widespread application in hate speech detection. As internet pop culture has risen, various words have acquired new meanings, and some ordinary words can become tools for attacking and insulting others in specific contexts, posing a challenge to traditional detection methods.
[0004] Recent research indicates that hate speech often contains negative emotions towards specific groups, thus the introduction of sentiment analysis techniques provides a new perspective for detecting such subtle hate speech. Farha and Magdy constructed a multi-task learning model by combining CNN and BiLSTM and incorporating sentiment information, effectively improving the ability to identify hate speech in Arabic tweets; Rajamanickam et al. also introduced sentiment features into a multi-task learning model to obtain auxiliary knowledge to detect abusive language in English tweets. Although existing studies consider sentiment features, most only consider the single feature of sentiment polarity related to the sentiment analysis task, without considering other sentiment features such as sentiment intensity, negation words, and punctuation marks; moreover, most related tasks are for the English domain, and there is very little research on Chinese text, and Chinese differs greatly from languages such as English in expression; at the same time, most existing hate speech datasets suffer from imbalanced data category distribution. Therefore, it is necessary to propose a Chinese hate speech detection method that integrates multi-dimensional sentiment features to solve the above problems. Summary of the Invention
[0005] The technical problem to be solved by this invention is to provide a Chinese hate speech detection method that integrates multi-dimensional emotional features. It aims to solve the problem that existing technologies lack hate speech detection methods for Chinese social media, and that applying foreign language techniques cannot effectively adapt to the special grammar and context of Chinese, resulting in poor recognition results. It has the feature of enhancing the detection model's ability to understand local and global information by fusing the output of BiLSTM with RoBERTa sentence features.
[0006] To solve the above-mentioned technical problems, the technical solution adopted by the present invention is as follows:
[0007] A method for detecting hate speech in Chinese that integrates multi-dimensional emotional features, comprising the following steps:
[0008] S1, organize and construct the social media dataset;
[0009] S2, perform data preprocessing on the dataset from step S1 to obtain input data for the hate speech detection model;
[0010] S3 involves building, training, and validating a hate speech detection model. The network structure of the hate speech detection model includes a text encoding layer, a sentiment feature layer, a BiLSTM layer, and a classification layer.
[0011] S4 uses a hate speech detection model to test and identify comments on social media, including:
[0012] S401, a comparative experiment was conducted with existing Chinese hate speech detection models on a public dataset;
[0013] S402, Ablation experiment on hate speech detection model;
[0014] S403, Parameter analysis of the hate speech detection model.
[0015] Preferably, in step S1, the organization and construction of the social media dataset includes:
[0016] We used the publicly available TOXICN and COLDataset Chinese hate speech detection datasets, and randomly divided the training and test sets in an 8:2 ratio.
[0017] Preferably, the data preprocessing method in step S2 includes using Jieba segmentation to segment the text content to adapt to the extraction of the emotional features of hate speech.
[0018] Preferably, in step S3, the RoBERTa pre-trained model is used as a baseline module to build a hate speech detection model, the pre-processed hate speech text is used as the input of the sentiment feature module, and the original text is used as the input of the text encoding layer to train the hate speech detection model.
[0019] Preferably, step S4 includes inputting the content to be detected into a trained hate speech detection model to identify whether the input content is hate speech.
[0020] Preferably, in step S3, the text encoding layer is composed of RoBERTa. The text is input into RoBERTa and processed to obtain the word vectors and sentence embedding vectors of the text.
[0021] Preferably, step S3 includes:
[0022] For a given input text, extract sentiment words using a sentiment dictionary. Emotional intensity Emotional polarity Other auxiliary features The sentiment features of the text are obtained by concatenating the four types of features. .
[0023] Preferably, in step S3, the BiLSTM layer is composed of a bidirectional long short-term memory network (BiLSTM). The word vectors and sentiment features of the text are concatenated and input into the BiLSTM network. After processing, context-dependent features that integrate forward and backward directions are obtained.
[0024] Preferably, in step S3, the training of the hate speech detection model includes:
[0025] S301, Extracting textual features of hate speech:
[0026] For a given sentence S= , Let represent the i-th word in the text sequence, and n represent the number of words in the text sequence;
[0027] Determine by using n-grams and an insult dictionary Whether it is an insulting term, and if so, further categorize the target group of the attack;
[0028] Adding the toxicity embedding to the word embedding yields an enhanced representation of the word embedding. The enhancement is represented as ;
[0029] By combining segment embeddings and position embeddings of the text, the corresponding word vector matrix is obtained through training using the Transformer module in RoBERTa. V ;
[0030] Take the output of the Pooler layer of RoBERTa As a feature representation of the entire sentence;
[0031] S302, Extracting the emotional characteristics of hate speech:
[0032] For a given sentence S= , Let represent the i-th word in the text sequence, and n represent the number of words in the text sequence. We summarize the scores of each word in all sentiments and the entire text to obtain a rich representation.
[0033] According to the sentiment dictionary, its word-level score s( e), combining the sentiment intensity and sentiment polarity scores from the sentiment lexicon, the word-level scores are weighted and summed to obtain the sentiment vocabulary. Emotional intensity Emotional polarity ;
[0034] Other auxiliary features were obtained by statistically analyzing the frequency of punctuation marks, emoticons, emotion words, degree words, negation words, personal pronouns, and assertion words in the text using an emotion dictionary. The sentiment features of the text are obtained by concatenating the four types of features. ;
[0035] S303, Obtain deep context dependency features:
[0036] The word vector matrix output by RoBERTa V With emotional characteristics Concatenate to obtain a vector , then The input is fed into a BiLSTM network, where computation is performed in two different directions using Long Short-Term Memory (LSTM) networks. The results from the two different directions are then merged and output. The output at each time step is saved, and the results are concatenated to obtain the final output. H ;
[0037] After obtaining the output vector of the BiLSTM layer module, it is compared with the sentence features. The data is concatenated, then combined using an MLP layer, and the output vector is mapped to the sample label space. SoftMax is used for normalization to calculate the approximate probability value for each label. y .
[0038] The beneficial effects of this invention are as follows:
[0039] This invention provides a method for detecting Chinese hate speech by fusing multi-dimensional sentiment features. The model is trained using a publicly available Chinese hate speech dataset collected from social networks. A RoBERTa pre-trained model combined with a sentiment dictionary is used to extract word-level, sentence-level, and sentiment features from the text. By fusing the output of BiLSTM with RoBERTa sentence features, the model's ability to understand local and global information is enhanced. Furthermore, to address the problem of imbalanced data classes, the model employs a focus loss function for optimization. By reducing the weight of easily classified samples, the attention given to difficult-to-classify samples is increased, thereby improving the model's robustness. Attached Figure Description
[0040] Figure 1 This is a flowchart of the present invention;
[0041] Figure 2 This is a diagram of the model architecture of the present invention;
[0042] Figure 3 This is a diagram of the text encoding layer model architecture of the present invention;
[0043] Figure 4 This is a graph showing the experimental results of the TOXICN dataset parameter analysis in this invention;
[0044] Figure 5 This is a graph showing the experimental results of the COLDataset dataset parameter analysis in this invention. Detailed Implementation
[0045] Example 1:
[0046] like Figure 1 As shown, a method for detecting Chinese hate speech that integrates multi-dimensional emotional features includes the following steps:
[0047] S1, organize and construct the social media dataset;
[0048] S2, perform data preprocessing on the dataset from step S1 to obtain input data for the hate speech detection model;
[0049] S3 involves building, training, and validating a hate speech detection model. The network structure of the hate speech detection model includes a text encoding layer, a sentiment feature layer, a BiLSTM layer, and a classification layer.
[0050] S4 uses a hate speech detection model to test and identify comments on social media, including:
[0051] S401, a comparative experiment was conducted with existing Chinese hate speech detection models on a public dataset;
[0052] S402, Ablation experiment on hate speech detection model;
[0053] S403, Parameter analysis of the hate speech detection model.
[0054] Preferably, in step S1, the organization and construction of the social media dataset includes:
[0055] We used the publicly available TOXICN and COLDataset Chinese hate speech detection datasets, and randomly divided the training and test sets in an 8:2 ratio.
[0056] Preferably, the data preprocessing method in step S2 includes using Jieba segmentation to segment the text content to adapt to the extraction of the emotional features of hate speech.
[0057] Preferably, in step S3, the RoBERTa pre-trained model is used as a baseline module to build a hate speech detection model, the pre-processed hate speech text is used as the input of the sentiment feature module, and the original text is used as the input of the text encoding layer to train the hate speech detection model.
[0058] Preferably, step S4 includes inputting the content to be detected into a trained hate speech detection model to identify whether the input content is hate speech.
[0059] Preferably, in step S3, the text encoding layer is composed of RoBERTa. The text is input into RoBERTa and processed to obtain the word vectors and sentence embedding vectors of the text.
[0060] Preferably, step S3 includes:
[0061] For a given input text, extract sentiment words using a sentiment dictionary. Emotional intensity Emotional polarity Other auxiliary features The sentiment features of the text are obtained by concatenating the four types of features. .
[0062] Preferably, in step S3, the BiLSTM layer is composed of a bidirectional long short-term memory network (BiLSTM). The word vectors and sentiment features of the text are concatenated and input into the BiLSTM network. After processing, context-dependent features that integrate forward and backward directions are obtained.
[0063] Preferably, in step S3, the training of the hate speech detection model includes:
[0064] S301, Extracting textual features of hate speech:
[0065] For a given sentence S= , Let represent the i-th word in the text sequence, and n represent the number of words in the text sequence;
[0066] Adding "[CLS]" and "[SEP]" segmentation markers at the beginning and end of the text sequence respectively converts the text sequence into a specific format that the RoBERTa model can process. The embedding of each marker is as follows: ∈ It is a vector representation in k-dimensional space;
[0067] according to Figure 2 In the example above, the category representations for non-toxic terms and sexist terms are set as follows: and ; Determining through n-grams and an insult dictionary If the term is offensive, further segment the target group of the attack. Then, randomly initialize the category representation. C = ,in ∈ , This refers to non-toxic terms, where m is the number of categories in the insult dictionary. In the TOXICN dataset, m=5, and in the CLOD dataset, m=3. Toxicity embedding The calculation formula is:
[0068] ;
[0069] Secondly, the toxicity embedding is added to the word embedding to obtain the enhanced representation of the word embedding; The enhancement is represented as = + ,in [0 [1] is the weight coefficient controlling the embedding of toxic knowledge; furthermore, by combining the segment embedding and position embedding of the text, the corresponding word vector matrix is obtained through training the Transformer module in RoBERTa. V = ∈ ;
[0070] like Figure 3 As shown, finally, the output of the Robeta Pooler layer is taken. As a feature representation of the entire sentence;
[0071] S302, Extracting the emotional characteristics of hate speech:
[0072] For a given sentence S= , Let represent the i-th word in the text sequence, and n represent the number of words in the text sequence. We summarize the scores of each word in all sentiments and the entire text to obtain a rich representation.
[0073] For a specific emotion e, if the emotion word In the emotional dictionary In the context of emotion e, when calculating its word-level score s, When considering word frequency, not only should the word's frequency be taken into account, but also the degree values of degree words in the context of the word, as well as the relationship between degree words and sentiment words. The distance. Since the frequency of negative words can directly change the meaning of a sentence (e.g., double negatives indicate affirmation), the frequency of negative words within the window was also considered when extracting sentiment word features.
[0074] In practical applications, a sentiment lexicon ontology is used to match and calculate the values of sentiment lexical features. The formula for calculating e) is:
[0075] ;
[0076] ;
[0077] Where windows is the size of the context window, neg is the number of times the negation word appears, and deg is the deg number. )for The degree value within the emotion dictionary; Distance weights are used for distance-based weights. and The distance is calculated using the following formula:
[0078] ;
[0079] ;
[0080] The text-level score of a specific emotion e is calculated by summing the scores of each word in the text that belongs to emotion e, and is denoted as s( e), its calculation method is as follows:
[0081] ;
[0082] Finally, connect All scores for each emotion yield emotional vocabulary features. The calculation formula is as follows, where ⊕ is the concatenation operator, and ;
[0083] ;
[0084] To accurately quantify the intensity of emotions, we first obtain the emotion words according to the calculation process of emotion vocabulary features. Word-level score s( Secondly, a word-level score of emotional intensity is obtained by weighting the intensity scores in the emotional lexicon. Finally, by summing the word-level scores of the emotional intensity of each word belonging to emotion e in the text, a text-level score for the perceived intensity of a specific emotion e is calculated. The calculation formula is as follows:
[0085] ;
[0086] in Representing words Intensity score; if In the dictionary, you can find it by searching for an emotion dictionary. ,otherwise 0;
[0087] The emotional intensity feature of the text is obtained by concatenating the emotional intensity scores of all emotion words. The calculation formula is as follows:
[0088] ;
[0089] in, ;
[0090] In addition to the aforementioned sentiment-level features, a coarse-grained sentiment score was also considered. Typically, the sentiment score is positive or negative, representing the degree of positive or negative polarity of the entire text. Word-level scores s(…) are obtained through the calculation process of sentiment lexical features. After step e), the polarity scores are weighted according to the BosonNLP sentiment lexicon, and then the polarity scores of all sentiment words in the text are summed. Assume the dimension of the sentiment score is... Then, the emotional polarity characteristics can be obtained. The calculation formula is as follows:
[0091] ;
[0092] in, The sentiment polarity score of a word, if In the dictionary, one can obtain information from an emotion dictionary. ,otherwise 0.
[0093] Since the above features do not explicitly utilize information beyond sentiment words, a set of auxiliary features is used to capture the sentiment information implied by non-word elements. The Wikipedia emoji list is divided into five emotion categories: happy, angry, surprised, sad, and neutral. This list is used to statistically analyze the frequency of emoji usage. The HowNet sentiment dictionary is used to statistically analyze the frequency of sentiment words, degree words, negation words, personal pronouns, and assertion words. Assume there are... If there are one auxiliary feature, then other auxiliary features can be extracted. ;
[0094] Finally, by connecting the above four features, we obtain... The calculation formula is:
[0095] ;
[0096] in , ;
[0097] S303, Obtain deep context dependency features:
[0098] The word vector matrix output by RoBERTa V With emotional characteristics Concatenate to obtain a vector , then The input is fed into a BiLSTM network, where computation is performed in two different directions using Long Short-Term Memory (LSTM) networks. The results from the two different directions are then merged and output. The output at each time step is saved, and the results are concatenated to obtain the final output. H The calculation formula is as follows:
[0099] ;
[0100] ;
[0101] in, This represents the output of the forward LSTM. This indicates the output of the backward LSTM;
[0102] After obtaining the output vector of the BiLSTM layer module, it is compared with the sentence features. The data is concatenated, then combined using an MLP layer, and the output vector is mapped to the sample label space. SoftMax is used for normalization to calculate the approximate probability value for each label. y The calculation formula is:
[0103]
[0104] ;
[0105] in, For parameter matrices, It is the bias vector;
[0106] To address the class imbalance problem, focus loss is used as the loss function to measure the difference between the true and predicted values. The calculation method is as follows:
[0107] ;
[0108] in, It is a non-negative adjustable focusing parameter used to distinguish between simple and difficult samples; It is a weighting factor that balances the importance of positive and negative samples; t is the index of the non-zero element in the true label; Let be the predicted probability of category t.
[0109] Example 2:
[0110] In step S4, a hate speech detection model is used to test and identify comments on social media, as follows:
[0111] Step 4.1: Conduct comparative experiments with existing Chinese hate speech detection algorithms on public datasets, using precision, recall, and F1 score as evaluation metrics. The experimental results are shown in Tables 1 and 2.
[0112] Table 1: Results of each model on the TOXICN dataset (unit: %)
[0113]
[0114] Table 2: Results of each model on the COLDataset dataset (unit: %)
[0115]
[0116] Step 4.2: Conduct an ablation experiment on the Chinese hate speech detection model, as follows:
[0117] (1) w / o EMO: indicates the removal of the sentiment feature module from the model.
[0118] (2) w / o SE: indicates that the sentence embedding features of RoBERTa in the model are removed.
[0119] (3) w / o EMO+SE: This means that the sentence embedding and sentiment feature module of RoBERTa in the model are removed at the same time.
[0120] The experimental results are shown in Tables 3 and 4.
[0121] Table 3: Ablation experimental results on the TOXICN dataset (unit: %)
[0122]
[0123] Table 4: Ablation experiment results of COLDataset dataset (unit: %)
[0124]
[0125] As can be seen from Tables 1 to 4, the method of this invention integrates multi-dimensional sentiment features and considers both character and sentence features, thereby improving the model's ability to identify hate speech and using the focus loss function to alleviate the problem of data class imbalance, thus achieving better detection results.
[0126] Step 4.3: Perform parameter analysis on the hate speech detection model. The main parameters include the window size and Dropout value in the context extraction window of the perceptual feature module. Experimental results are as follows: Figure 4 and Figure 5 As shown in the figure, it can be seen that in the TOXICN and COLDataset datasets, the model detection performance reaches its best when the window is set to 2 and the Dropout values are 0.6 and 0.1 respectively.
[0127] In summary, this invention provides a Chinese hate speech detection method that integrates multi-dimensional sentiment features. This method uses RoBERTa to extract character and sentence features from the input text, and employs tools such as sentiment dictionaries to extract multi-dimensional sentiment features including sentiment vocabulary, sentiment polarity, emotional intensity, punctuation, and emoticons. Then, the character and sentiment features are concatenated and input into a BiLSTM network to learn deeper contextual semantic information. Finally, to obtain semantic information at different levels, the output of BiLSTM is connected to the sentence features of RoBERTa, achieving efficient fusion of local and global information, improving the model's representational ability, and helping to better handle complex sentiment and contextual relationships in Chinese text. Simultaneously, to address the problem of imbalanced data classes, the model employs a focus loss function for optimization, reducing the weight of easily classified samples to increase the attention of difficult-to-classify samples, thereby improving the model's robustness. This invention not only achieves an innovative application of pre-trained models and sentiment features in the field of Chinese hate speech detection, but also significantly improves the model's ability to identify subtle hate speech through the introduction of multi-dimensional sentiment features.
Claims
1. A method for detecting hate speech in Chinese that integrates multi-dimensional emotional features, characterized in that, Includes the following steps: S1, organize and construct the social media dataset; S2, perform data preprocessing on the dataset from step S1 to obtain input data for the hate speech detection model; S3 is used for building, training, and validating hate speech detection models. The network structure of the hate speech detection model includes a text encoding layer, a sentiment feature layer, a BiLSTM layer, and a classification layer. Training a hate speech detection model includes: S301, Extracting textual features of hate speech: For a given sentence S= , Let represent the i-th word in the text sequence, and n represent the number of words in the text sequence; Determine by using n-grams and an insult dictionary Whether it is an insulting term, and if so, further categorize the target group of the attack; Adding the toxicity embedding to the word embedding yields an enhanced representation of the word embedding. The enhancement is represented as ; By combining segment embeddings and position embeddings of the text, the corresponding word vector matrix is obtained through training using the Transformer module in RoBERTa. V ; Take the output of the Pooler layer of RoBERTa As a feature representation of the entire sentence; S302, Extracting the emotional characteristics of hate speech: For a given sentence S= , Let represent the i-th word in the text sequence, and n represent the number of words in the text sequence. We summarize the scores of each word in all sentiments and the entire text to obtain a rich representation. According to the sentiment dictionary, its word-level score s( e), combining the sentiment intensity and sentiment polarity scores from the sentiment lexicon, the word-level scores are weighted and summed to obtain the sentiment vocabulary. Emotional intensity Emotional polarity ; Other auxiliary features were obtained by statistically analyzing the frequency of punctuation marks, emoticons, emotion words, degree words, negation words, personal pronouns, and assertion words in the text using an emotion dictionary. The sentiment features of the text are obtained by concatenating the four types of features. ; S303, Obtain deep context dependency features: The word vector matrix output by RoBERTa V With emotional characteristics Concatenate to obtain a vector Then The input is fed into a BiLSTM network, where computation is performed in two different directions using Long Short-Term Memory (LSTM) networks. The results from the two different directions are then merged and output. The output at each time step is saved, and the results are concatenated to obtain the final output. H ; After obtaining the output vector of the BiLSTM layer module, it is compared with the sentence features. The data is concatenated, then combined using an MLP layer, and the output vector is mapped to the sample label space. SoftMax is used for normalization to calculate the approximate probability value for each label. y ; S4 uses a hate speech detection model to test and identify comments on social media, including: S401, a comparative experiment was conducted with existing Chinese hate speech detection models on a public dataset; S402, Ablation experiment on hate speech detection model; S403, Parameter analysis of the hate speech detection model.
2. The method for detecting Chinese hate speech by integrating multi-dimensional emotional features according to claim 1, characterized in that, Step S1 involves organizing and constructing the social media dataset, including: We used the publicly available TOXICN and COLDataset Chinese hate speech detection datasets, and randomly divided the training and test sets in an 8:2 ratio.
3. The method for detecting Chinese hate speech by integrating multi-dimensional emotional features according to claim 2, characterized in that, The data preprocessing method in step S2 includes using Jieba segmentation to segment the text content to adapt to the extraction of the sentiment features of hate speech.
4. The method for detecting Chinese hate speech by integrating multi-dimensional emotional features according to claim 3, characterized in that, In step S3, the RoBERTa pre-trained model is used as the baseline module to build the hate speech detection model. The pre-processed hate speech text is used as the input to the sentiment feature module, and the original text is used as the input to the text encoding layer to train the hate speech detection model.
5. The method for detecting Chinese hate speech by integrating multi-dimensional emotional features according to claim 4, characterized in that, Step S4 includes inputting the content to be detected into a trained hate speech detection model to identify whether the input content is hate speech.
6. The method for detecting Chinese hate speech by fusing multi-dimensional emotional features according to claim 1, characterized in that, In step S3, the text encoding layer consists of RoBERTa. The text is input into RoBERTa and processed to obtain word vectors and sentence embedding vectors.
7. The method for detecting Chinese hate speech by integrating multi-dimensional emotional features according to claim 1, characterized in that, Step S3 includes: For a given input text, extract sentiment words using a sentiment dictionary. Emotional intensity Emotional polarity Other auxiliary features The sentiment features of the text are obtained by concatenating the four types of features. .
8. The method for detecting Chinese hate speech by integrating multi-dimensional emotional features according to claim 1, characterized in that, In step S3, the BiLSTM layer is composed of a bidirectional long short-term memory network BiLSTM. The word vectors and sentiment features of the text are concatenated and input into the BiLSTM network. After processing, context-dependent features that integrate forward and backward directions are obtained.
Citation Information
Patent Citations
Voice emotion recognition method and device based on artificial intelligence, equipment and medium
CN116844573A
Hatred speech detection method and system based on semantic enhancement and storage medium
CN118520070A