Multi-text feature-based aggressive speech detection method

By combining the BERT model and the TextCNN model, using multiple text features to perform aggressive language detection on Twitter comment data, it solves the problem that it is difficult to effectively detect aggressive speech in the existing technology, and realizes efficient aggressive speech detection and effectively responds to cyberbullying.

CN120067855APending Publication Date: 2025-05-30CENTRAL SOUTH UNIVERSITY OF FORESTRY AND TECHNOLOGY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510129595.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-05
Publication Date
2025-05-30

AI Technical Summary

Technical Problem

The existing technology is difficult to effectively detect and manage offensive speech on social network platforms, resulting in frequent cyberbullying, affecting user experience and having adverse effects on society.

Method used

Aggressive speech detection method based on multi-text features is adopted, and a BERT model and TextCNN model are used to combine multiple text features to conduct aggressive language detection on Twitter comment data. Specific steps include text word embedding layer, semantic feature extraction layer and classification output layer, and identify aggressive features in text through multi-angle feature extraction and fusion.

Benefits of technology

Aggressive text detection of Twitter text has been achieved, excellent results have been achieved, the accuracy and efficiency of aggressive speech detection have been improved, and the problem of cyberbullying has been effectively dealt with.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120067855A_ABST
    Figure CN120067855A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of malicious speech detection, in particular to an aggressive speech detection method based on multi-text features, comprising: acquiring to-be-detected text data; the to-be-detected text data is input into a preset BTCNN-CHW model, an aggressive speech detection result of the to-be-detected text data is output, the BTCNN-CHW model is obtained based on training of a training set, the training set comprises a plurality of aggressive text data, and the aggressive speech detection result of the to-be-detected text data is obtained based on the aggressive speech detection result of the to-be-detected text data. The BTCNN-CHW model is used for identifying aggressive features hidden by the text data to be detected by using multi-angle features. According to the method and the device, aggressive text detection of the Twitter text can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of malicious speech detection, and in particular to an offensive speech detection method based on multi-text features. Background Art

[0002] With the rapid development of information technology, social networking platforms continue to emerge. Online platforms such as blogs, forums, and chat software have gradually entered people's lives and become an indispensable part. There are hundreds of millions of daily active users on social networking platforms such as Weibo, Facebook, and Twitter. When so many users are exchanging information, the network is virtual and deceptive to a certain extent, and the threshold requirements are low, which reduces the constraints on people. It is inevitable that some network platform users will make some offensive remarks, which will lead to large-scale cyberbullying. Therefore, offensive remarks appear more and more frequently in network platform exchanges. Offensive remarks refer to offensive, violent or offensive remarks directed at specific groups or individuals, which are common abuse problems on online social media. Nowadays, with the development of network platforms, some network platform users use or abuse social media to publish and promote offensive and hateful remarks. Some abnormal network users can easily publish various discriminatory or even insulting remarks through social platforms, which also makes social networking platforms become the outbreak of offensive remarks. This will not only seriously affect the experience of the majority of users, but also have adverse effects on the entire society, and even have serious consequences. Although the administrators of these network platforms have tried to formulate some rules and penalties to manage users who make offensive remarks, this approach has achieved little success due to the complexity of detecting offensive remarks in texts. At the same time, the massive amount of data brought by the Internet has also brought challenges to the supervision of social network platforms, so the detection of offensive remarks has become an urgent problem to be solved.

[0003] With the advent of the artificial intelligence era, especially the rapid development of natural language processing related technologies, we can try to use machine learning and deep learning methods to deal with this problem, so as to successfully make effective and accurate judgments on text information. The research on offensive speech detection has received widespread attention in recent years. Summary of the invention

[0004] The purpose of the present invention is to provide an offensive speech detection method based on multiple text features, which adopts the BERT model and TextCNN, and combines multiple text features to perform offensive language detection on Twitter comment data.

[0005] To achieve the above object, the present invention provides the following solutions:

[0006] An offensive speech detection method based on multi-text features, including:

[0007] Obtain the text data to be detected;

[0008] Input the text data to be detected into a preset BTCNN-CHW model, and output the offensive speech detection result of the text data to be detected. Among them, the BTCNN-CHW model is obtained by training based on a training set, the training set includes a number of offensive text data, and the BTCNN-CHW model is used to identify the offensive features hidden in the text data to be detected by using multi-angle features.

[0009] Optionally, the BTCNN-CHW model includes: a text word embedding layer, a semantic feature extraction layer, and a classification output layer. Among them, the text word embedding layer is used to extract the text word embedding features of the text data to be detected; the semantic feature extraction layer is used to extract multiple semantic features based on the text word embedding features; the classification output layer is used to perform fusion analysis on multiple semantic features and output a text classification result.

[0010] Optionally, the text word embedding layer extracts the text word embedding features of the text data to be detected by using a first BERT module, including:

[0011] Construct the text data to be detected into a text vector, and the text vector includes a word vector, a sentence embedding, and a position vector;

[0012] Input the text vector into the first BERT module, and after several Transformer modules in the first BERT module, obtain the text state semantic representation, that is, the text word embedding features.

[0013] Optionally, the semantic feature extraction layer extracts multiple semantic features based on the text word embedding features by using a TextCNN module, a second BERT module, a Character Encoder module, and a HOF Encoder module. Among them, the TextCNN module is used to extract local features of multi-level short texts based on the text word embedding features; the second BERT module is used to extract context features based on the text word embedding features; the Character Encoder module is used to extract character set features based on the text word embedding features; the HOF Encoder module is used to extract word-level features based on the text word embedding features.

[0014] Optionally, the TextCNN module includes an input layer, a convolutional layer, a pooling layer, a first fully connected layer, and a first output layer connected in sequence. Among them, the convolutional layer processes text data by using a number of convolutional kernels of different sizes to obtain local features of different scales.

[0015] Optionally, the calculation method of the convolution kernel is as follows:

[0016] c i = f(W · X i:i+h-1 + b);

[0017] where X i:i+h-1 is the word vector at each position in the text content, c i is the i-th feature generated from the window of X i:i+h-1 , W is the weight, b is the bias parameter, h is the number of convolution kernels, and f is the activation function.

[0018] Optionally, the classification output layer includes a second fully connected layer and a second output layer connected in sequence, where the second fully connected layer is used to calculate the weights of the fused multiple semantic features, and the second output layer is used to classify the output of the second fully connected layer to obtain the probability value of the text information tendency type.

[0019] Optionally, the second fully connected layer calculates the weights of the fused multiple semantic features as follows:

[0020] M = ReLU(W d · out + b d );

[0021] where W d is the second fully connected weight matrix, b d is the bias of the second fully connected layer, out is the fused multiple semantic features, and M is the output of the second fully connected layer.

[0022] Optionally, the second output layer classifies the output of the second fully connected layer to obtain the probability value of the text information tendency type as follows:

[0023] y = Softmax(W s + b);

[0024] where W s is the weight matrix corresponding to the second output layer, b is the bias of the second output layer, and y is the probability value of the output text information tendency type.

[0025] The beneficial effects of the present invention are as follows:

[0026] The present invention proposes an offensive speech detection method based on multi-text features, and constructs a BTCNN-CHW model. The BTCNN-CHW model uses the BERT model to complete the word embedding work of the input text, and then uses four models, namely TextCNN, BERT, CharEncoder, and HOF Encoder, to extract global information, local information at different levels in the text, and the dependency relationship between positive and negative bidirectional sentences. After that, the text features extracted separately are fused and then input into a classifier for classification. The BTCNN-CHW model can achieve the detection of offensive text in Twitter text and achieve excellent results in the offensive speech detection task. Brief Description of the Drawings

[0027] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required in the embodiments. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.

[0028] Figure 1 Schematic structural diagram of the BTCNN-CHW model for the embodiment of the present invention;

[0029] Figure 2 Flow chart of the BERT word embedding processing for the embodiment of the present invention;

[0030] Figure 3 Schematic structural diagram of the BERT for the embodiment of the present invention;

[0031] Figure 4 Schematic structural diagram of the TextCNN for the embodiment of the present invention. Detailed Description of the Embodiments

[0032] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, rather than all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the scope of protection of the present invention.

[0033] In order to make the above objects, features, and advantages of the present invention more obvious and understandable, the present invention will be further described in detail below in conjunction with the drawings and specific embodiments.

[0034] Offensive speech detection is an important research direction in the field of natural language processing, aiming to identify and classify texts containing offensive, malicious, or offensive content.

[0035] There is no unified definition of offensive speech. Even though the characteristics of the research content may be similar, the different focuses have also led to differences in the use of professional terms. The international definition of offensive speech mainly refers to the description of the United Nations. In 2019, the United Nations defined offensive language as any speech, writing, or behavioral communication that attacks individuals or groups or uses derogatory or discriminatory language against them because of their personal or group identity (i.e., their religion, ethnicity, nationality, race, color, descent, gender, or other identity factors). The spread of offensive speech is a potential threat to social peace and stability and may exacerbate discrimination, stigmatization, dehumanization, and marginalization. Offensive language intensifies the opposition and contradictions between different groups through insults, discrimination, and hate speech. Such language not only harms the dignity and feelings of the attacked but may also trigger hostility and conflicts between groups, destroying the harmonious atmosphere of society. For example, offensive speech based on race, religion, or gender may lead to social dissatisfaction and protests and even result in violent incidents.

[0036] In 2013, Mikolov et al. proposed a model now known as Word2Vec, which essentially consists of two models with opposite ideas, namely the Continuous Bag-of-Words (CBOW) model and the Skip-gram model. Through these models, high-quality word representations can be quickly learned. In 2014, Pennington et al. proposed the GloVe model based on statistical methods. This model not only utilizes the local features extracted from the local context window but also pays attention to the global information obtained through global matrix factorization, making more effective use of statistical data and integrating global information into the word representation.

[0037] In 2017, Davidson et al. obtained random tweets from Twitter and had them manually classified by staff. The tweets were divided into three categories: hateful, offensive, and neutral. In the experiment, for the use of features, n-gram features, part-of-speech features, sentiment score features, etc. were adopted, and these features were respectively applied to various classifiers for comparison. The classifiers included LR, Naive Bayesian, decision tree, and linear SVM.

[0038] Chatzakou et al. collected more data on Twitter and combined various features in the experiment: features based on user attributes such as user and account attributes, features based on text such as hate vocabulary and emotion classification, and features based on social networks such as attention and influence. After testing various tree algorithms, a random forest composed of 10 decision trees was finally selected as the classifier. The experimental results performed well on the dataset, which also shows that combining multiple features can improve the final classification results.

[0039] In 2018, Devlin et al. proposed the BERT model, which became a representative of context-related text representation. BERT is a pre-trained language model based on Transformer that captures rich context information of text through bidirectional training. BERT uses two tasks, Masked Language Model and Next Sentence Prediction, for unsupervised learning to form deep language representations. As a pre-trained model for large-scale unsupervised multilingual corpora, the BERT model has demonstrated good performance and achieved excellent results in many natural language processing tasks.

[0040] Van Hee et al. collected data containing English and Dutch from social networking sites and refined the label categories, including threats, curses, insults, slander, pornography, etc. In the classification experiment, a support vector machine was used as the classifier, and the features used included character-based and word-based N-gram features, lexical features, topic features, etc. The experimental results showed that the classification effect could reach an optimal level after combining multiple features.

[0041] This embodiment provides an offensive speech detection method based on multi-text features, including:

[0042] Obtain the text data to be detected;

[0043] Input the text data to be detected into a preset BTCNN-CHW model, and output the offensive speech detection result of the text data to be detected. Among them, the BTCNN-CHW model is obtained by training based on a training set, the training set includes several offensive text data, and the BTCNN-CHW model is used to identify the offensive features hidden in the text data to be detected using multi-angle features.

[0044] Furthermore, the BTCNN-CHW model includes: a text word embedding layer, a semantic feature extraction layer, and a classification output layer. Among them, the text word embedding layer is used to extract the text word embedding features of the text data to be detected; the semantic feature extraction layer is used to extract multiple semantic features based on the text word embedding features; the classification output layer is used to perform fusion analysis on multiple semantic features and output the text classification result.

[0045] Furthermore, the text word embedding layer extracts the text word embedding features of the text data to be detected using a first BERT module, including:

[0046] Construct the text data to be detected into a text vector, and the text vector includes word vectors, sentence embeddings, and position vectors;

[0047] Input the text vector into the first BERT module. After passing through several Transformer modules in the first BERT module, obtain the text-state semantic representation, that is, the text word embedding features.

[0048] Specifically, for a piece of text data T = [x 1 , x 2 ,..., x n , construct the word vector, sentence embedding, and position vector of text T, and then use the sum E = [e 1 , e 2 ,..., e n of the three vectors as the input data of the semantic feature extraction layer. Among them, the word vector is the vector representation corresponding to the word after one-hot encoding; the sentence embedding is the vector used to segment multiple sentences; the position vector adds position information to the sequence and maintains the order after vector representation of the text data.

[0049] Pass the obtained text vector representation through multiple Transformer modules in BERT to obtain the dynamic semantic representation V = [v 1 ,, v 2 ,..., v 3 ∈ R n×d , where n is the length of the input vector and d is the dimension of the word vector, which is 768.

[0050] Furthermore, the semantic feature extraction layer extracts multiple semantic features based on the text word embedding features using the TextCNN module, the second BERT module, the Character Encoder module, and the HOF Encoder module. Among them, the TextCNN module is used to extract local features of multi-level short texts based on the text word embedding features; the second BERT module is used to extract context features based on the text word embedding features; the Character Encoder module is used to extract character set features based on the text word embedding features; the HOF Encoder module is used to extract word-level features based on the text word embedding features.

[0051] Specifically, take the output of the text word embedding layer as the input of TextCNN, BERT, Character Encoder, and HOF Encoder, learn the local information at different levels in the input text, the dependency relationship and syntactic features between forward and backward sentences, and fuse the extracted features to play a role in more comprehensive and deeper feature extraction of offensive texts.

[0052] Further, the TextCNN module includes an input layer, a convolutional layer, a pooling layer, a first fully-connected layer, and a first output layer connected in sequence. Among them, the convolutional layer processes text data using a number of convolutional kernels of different sizes to obtain local features of different scales.

[0053] Among them, the calculation method of the convolutional kernel is:

[0054] c i = f(W·X i:i+h-1 + b);

[0055] Among them, X i:i+h-1 is the word vector at each position in the text content, c i is the i-th feature generated from the window of X i:i+h-1 , W is the weight, b is the bias parameter, h is the number of convolutional kernels, and f is the activation function.

[0056] Further, the classification output layer includes a second fully-connected layer and a second output layer connected in sequence. Among them, the second fully-connected layer is used to calculate the weights of the fused multiple semantic features, and the second output layer is used to classify the output of the second fully-connected layer to obtain the probability value of the text information tendency type.

[0057] Specifically, the features extracted by TextCNN, BERT, Character Encoder, and OffensiveWord Encoder in the semantic feature extraction layer are fused and then input into the second fully-connected layer, which maps them to the label space to classify offensive language. The second fully-connected layer calculates the weights of the fused multiple semantic features as follows:

[0058] M = ReLU(W d ·out + b d );

[0059] Among them, W d is the second fully-connected weight matrix, b d is the bias of the second fully-connected layer, out is the fused multiple semantic features, and M is the output of the second fully-connected layer.

[0060] The second output layer uses the softmax function to classify the output of the second fully-connected layer to obtain the probability value of the text information tendency type, including:

[0061] y = Softmax(W s + b);

[0062] Among them, W s is the weight matrix corresponding to the second output layer, b is the bias of the second output layer, and y is the probability value of the output text information tendency type.

[0063] Specifically, this embodiment proposes an offensive speech detection method based on multi-text features, constructs a BTCNN-CHW model. The BTCNN-CHW model uses the BERT model to complete the word embedding work of the input text, and then uses four models, namely TextCNN, BERT, Char Encoder, and HOF Encoder, to extract global information, local information at different levels in the text, and the dependency relationship between positive and negative bidirectional sentences. After that, the text features extracted separately are subjected to feature fusion and then input into a classifier for classification. The BTCNN-CHW model can achieve the detection of offensive texts in Twitter texts and achieve excellent results in the offensive speech detection task.

[0064] The following combines body 1- Figure 4 Specifically describe the BTCNN-CHW model for classifying texts proposed in this embodiment. BTCNN-CHW mainly consists of three parts: a text word embedding layer, a semantic feature extraction layer, and a classification output layer.

[0065] First, use the pre-trained model BERT proposed by the Google team in 2018 to perform semantic feature learning on Twitter texts. However, since the first step only uses the BERT model for relatively simple word embedding work and does not extract the semantic features of Twitter texts, the obtained text word embedding features need to be input into the feature extractor again. BTCNN uses four feature extractors: TextCNN, BERT, Character Encoder, and HOF Encoder to extract Twitter text features. By combining the local features of multi-level short texts extracted by TextCNN, the context features extracted by BERT, the character set features extracted by Charr Encoder, and the word-level features extracted by HOF Encoder, the hidden offensive features in Tweets can be effectively extracted, further improving the performance of the offensive speech detection model. The structure of the BTCNN-CHW model is as Figure 1 shown.

[0066] (1) Text word embedding layer:

[0067] The role of the word embedding layer is to convert the input text information into a numerical input vector through a certain encoding method, enabling the computer to process text data that it could not directly understand originally.

[0068] The BERT pre-trained model uses the WordPiece algorithm for word embedding. WordPiece is a top-down word embedding method that splits each word into a series of sub-words, and then maps these sub-words to fixed-length vectors for representation. These vector representations are learned and optimized by minimizing the loss function of the prediction task objective (such as next word prediction or masked word prediction) during the training process. In this way, BERT can capture rich semantic information of the vocabulary.

[0069] For a text data T = [x 1 , x 2 ,..., x n , word vectors, sentence embeddings, and position vectors of text T are constructed, and then the sum E = [e 1 , e 2 ,..., e n of these three vectors is used as the input data of the semantic feature extraction layer. The word embedding processing flow of the text data is as Figure 2 shown.

[0070] Among them, the word vector is the vector representation corresponding to the word after one-hot encoding; the sentence embedding is the vector for splitting multiple sentences; the position vector adds position information to the sequence and maintains the order after vector representation of the text data.

[0071] The obtained text vector representation is trained through multiple Transformer modules in BERT to obtain the dynamic semantic representation V = [v 1 ,, v 2 ,..., v 3 ∈ R n×d , where n is the length of the input vector and d is the dimension of the word vector, which is 768. The BERT model structure is as Figure 3 shown, and the middle layer represents a 12-layer bidirectional Transformer extractor.

[0072] (2) Semantic Feature Extraction Layer:

[0073] Compared with the text word embedding layer that encodes the text speech in the previous layer, the role of the semantic feature extraction layer is to capture the semantic information features of the input text. The output of the text word embedding layer is used as the input of TextCNN, BERT, Character Encoder, and HOF Encoder to learn the local information at different levels, the dependency relationships and syntactic features between positive and negative bidirectional sentences in the input text, and fuse these extracted features, playing a role in more comprehensive and deeper feature extraction of offensive text.

[0074] TextCNN:

[0075] TextCNN is a convolutional neural network proposed by Yoon Kim in 2014 for extracting text features and then performing text classification. TextCNN extracts local features of the input text by defining several convolutional kernels of different sizes, making the obtained features more diverse and representative. The TextCNN network structure is simple and the training speed is fast, and it can capture the context information of words or phrases.

[0076] TextCNN consists of an input layer, a convolutional layer, a pooling layer, a fully connected layer and an output layer, and its network structure is as Figure 4 shown.

[0077] The convolutional layer of TextCNN processes text data with multiple convolutional kernels of different sizes to achieve the effect of extracting local features of different scales. Three convolutional kernels with sizes of 2, 3, and 4 are used, and the relevant parameters of the three convolutional kernels are optimized through the backpropagation algorithm. Generally, x i:i+h represents the concatenation of words in the text, and through the operation of the convolutional kernel, new features can be generated from h words, so that c i can be extracted from the sentence x i:i+h-1 , and the calculation is shown in the following formula:

[0078] c i = f(W·X i:i+h-1 + b);

[0079] In the above formula, X i:i+h-1 is the word vector at each position in the text content, the feature c i is the i-th feature generated from the window of X i:i+h-1 , W is the weight, b is the bias parameter, h is the number of convolutional kernels, and f is a non-linear activation function set to ensure the non-linear features of the model.

[0080] The convolutional layer in TextCNN uses a convolutional kernel with a fixed width that is the same as the sub-vector dimension, and the convolutional kernel slides in the order of the word window to obtain the feature vector c∈R n-h+1 , as shown in the following formula:

[0081] c = [c 1 , c 2 ,..., c n+h-1 ;

[0082] Then, the obtained feature vector is input into the pooling layer for max pooling operation to extract more important features. The feature map c obtained by the convolutional layer is pooled to obtain c′ = max{c}, and the pooled features are concatenated. By concatenating all the features obtained by the convolutional layer after pooling into a new feature c″, as shown in the following formula:

[0083] c″ = [c′ 1 , c′ 2 ,..., c′ k ;

[0084] In the above formula, k is the output dimension of TextCNN.

[0085] Finally, the feature vector obtained after processing is input into the classification layer to classify the text.

[0086] BERT:

[0087] The architecture of the BERT (Bidirectional Encoder Representation from Transformers) model is based on the Attention mechanism and is a multi-layer Transformer encoder. Each layer in BERT contains two sub-layers: the multi-head attention mechanism and the feed-forward neural network. The role of the multi-head attention mechanism is to capture the global information in the text sequence, and the feed-forward neural network can perform simple transformations and connections on the text sequences at all positions.

[0088] The pre-training of BERT is based on the Masked Language Model (MLM). The core idea of MLM is to randomly mask some words in the input text and then let the model predict these masked words during the training process. By masking words and predicting them, MLM enables the model to learn to understand the meaning of words based on the context without the need for external annotation information.

[0089] In the BERT pre-trained model, when performing word masking, 15% of the words in the input sequence are randomly selected, and 80% of these words are replaced with the [MASK] label, 10% of the words are replaced with random words, and finally 10% remain the original vocabulary. Using such an MLM strategy can effectively reduce the inconsistency brought by the [MASK] label during the pre-training and fine-tuning of the BERT model.

[0090] Character Encoder:

[0091] The Character Encoder takes a single character as the analysis unit, which can avoid the difficulties in feature extraction caused by polysemy of words, etc., and deeply explore the subtle structure and local features of the text. For example, by analyzing the combination rules of specific characters, it provides a basis for understanding the local semantics and grammar of the text. However, it is difficult to grasp the macro semantics and theme categories. The word-level encoder analyzes the word frequency distribution based on the dictionary, and the extracted features are standardized and highly interpretable. It is suitable for professional text processing and can accurately extract the features of high-frequency words related to the field. The combination of the two can complement each other's advantages. The Character Encoder helps the word-level encoder understand emerging words, and the word-level encoder provides the macro semantic background for the Character Encoder, so as to comprehensively and accurately extract text features and improve the processing effect.

[0092] HOF Encoder:

[0093] The HOF Encoder is another unique text feature extraction module. It mainly realizes the extraction of text features by deeply analyzing the frequency and distribution of words in the dictionary. The operation of the HOF Encoder is based on the existing dictionary resources. This dictionary-based operation mode endows the extracted text features with strong standardization and interpretability. Since the words in the dictionary have clear definitions and usage norms, when the HOF Encoder analyzes the word frequency and distribution based on the dictionary, the obtained features can correspond to the standard definitions in the dictionary, thus avoiding the situation where the feature meanings are ambiguous and difficult to understand. For example, when processing some highly professional texts, the HOF Encoder can accurately extract the features of high-frequency words related to the professional field according to the professional dictionary, and the meanings of these features can be directly interpreted with reference to the dictionary, providing a clear semantic basis for the further analysis of the text.

[0094] (3) Classification output layer:

[0095] Fuse the features extracted by TextCNN, BERT, Character Encoder, and Offensive Word Encoder in the semantic feature extraction layer and input them into the fully connected layer, map them to the label space, and classify offensive language. The input out of the semantic feature extraction layer is calculated with the weight matrix of the fully connected layer to output M, as shown in the following formula:

[0096] M = ReLU(W d ·out + b d );

[0097] Among them, W d is the fully connected weight matrix, and b d is the bias of the fully connected layer.

[0098] The output layer uses the softmax function to classify the output information M of the fully connected layer, obtaining the probability values of the text information tendency types. The calculation is as shown in the following formula:

[0099] y = Softmax(W s + b);

[0100] where W s is the weight matrix corresponding to the output layer, and b is the bias of the output layer. y represents the probability value of the category corresponding to the text classification by the model.

[0101] The following is the experimental verification and comparative analysis:

[0102] (1) Dataset HASOC:

[0103] HASOC (Hate Speech and Offensive Content) is a dataset focused on detecting hate speech and offensive content, and it plays an important role in the field of social media text analysis. The HASOC dataset is mainly collected from Twitter and is pre-classified by a machine learning system. The HASOC dataset contains the Tweet text of the input data and two target labels: offensive text (HOF) and non-offensive text (NOT). HASOC has three sub-datasets: HASOC-2019, HASOC-2020, and HASOC-2021. The offensive text (HOF) and non-offensive text (NOT) data are shown in Table 1.

[0104] Table 1

[0105]

[0106] As can be seen from the table, the distribution of offensive text (HOF) and non-offensive text (NOT) in the datasets HASOC-2019 and HASOC-2021 is not uniform. In this experiment, HASOC-2021 is mainly used as the experimental dataset. To eliminate the impact of uneven quantity on the training process, this experiment uses the oversampling method on the training split, randomly selecting the category with a smaller quantity from the data subset for replication to keep the data quantities close.

[0107] Since there is a large amount of irrelevant data in Twitter text, such as special characters, URLs, tags, etc., which will not help in detecting offensive language, it is necessary to process the text data before inputting it into the word embedding layer. An example of the processed dataset is shown in Table 2.

[0108] Table 2

[0109]

[0110] (2) Experimental parameter settings:

[0111] To obtain the optimal classification results on the offensive language dataset, it is necessary to conduct multiple comparative experiments by setting different hyperparameters and finally select the optimal values of the parameters. The hyperparameter settings for the experiment are shown in Table 3.

[0112] Table 3

[0113]

[0114] (3) Evaluation metrics:

[0115] To verify the performance of the BTCNN-CHW model in the offensive language detection task, it is necessary to conduct a comparative analysis with other offensive detection model methods. The most commonly used evaluation metrics include a series of criteria, including accuracy, precision, recall, and F1 score. These criteria evaluate the performance of the model from different perspectives. To accurately evaluate the performance of the constructed model, the corresponding calculation formulas were used to calculate and analyze the accuracy, precision, recall, and F1 score in detail.

[0116] The confusion matrix is a tabular tool used to evaluate the performance of a classification model in a classification task. It is mainly used to show the relationship between the model's prediction results and the true labels, and to intuitively present the classification situation of the model in each category, as shown in Table 4.

[0117] Table 4

[0118]

[0119] In Table 4, TP represents the number of samples where the model predicts the positive class and the actual label is also the positive class, FP represents the number of samples where the model predicts the positive class but the actual label is the negative class, FN represents the number of samples where the model predicts the negative class but the actual label is the positive class, and TN represents the number of samples where the model predicts the negative class and the actual label is also the negative class.

[0120] The corresponding calculation formulas for Accuracy, Precision, Recall, and F1 are as follows:

[0121]

[0122] (4) Experimental results:

[0123] To verify the effectiveness of this method in the offensive language detection task, the BTCNN-CHW model was tested on the dataset HASOC-2021 and compared with other model methods.

[0124] GaussianNB: GaussianNB is a classification algorithm based on Bayes' theorem and naive assumptions, and its features conform to the Gaussian distribution. It is used for text classification through a series of processes, including text preprocessing, model training, and prediction.

[0125] LogisticRegression: LogisticRegression is a commonly used statistical technique based on the principle of logistic regression. This method preprocesses the text data and uses appropriate feature representations, and then conducts model training to build a classifier. Subsequently, the text is classified according to the calculated probability values.

[0126] KNN: The KNN (K-Nearest Neighbor) method is a classification technique that determines the class to which an unknown text belongs by identifying the K nearest neighbor texts of the unknown text in the feature space. Subsequently, decision rules such as majority voting are applied based on the known classes of these adjacent texts.

[0127] LSTM: LSTM (Long Short-Term Memory Network) is a deep learning method that adopts a unique gating structure to effectively process the sequential data inherent in text information. It promotes the learning and training of text-specific features and then classifies the text according to the learned patterns.

[0128] LinerSVC: LinearSVC is a variant of Support Vector Classification (SVC) and is suitable for processing high-dimensional data, such as the bag-of-words model in text classification tasks.

[0129] RandomForestClassifie: RandomForestClassifier is an ensemble learning method that performs classification tasks by constructing multiple decision trees and making the final prediction through voting or averaging.

[0130] DistilBERT: DistilBERT provides performance similar to BERT but is smaller and faster, making it particularly suitable for text classification tasks in resource-constrained environments.

[0131] HateBert-CH-HW: Its core lies in the organic integration of the advanced HateBert model with diverse text features.

[0132] The results are shown in Table 5.

[0133] Table 5

[0134]

[0135] Comparing the results of the models in Table 5 on the HASOC-2021 dataset, it can be found that the BTCNN-CHW model has a better classification effect than other models. Compared with the best-performing model among other models, the BTCNN-CHW model has improved by 0.82%, 2.92%, 2.73%, and 0.93% respectively in terms of accuracy, precision, recall, and F1 value compared to the second-best model. For the LinerSVC model and RandomForestClassifier model in the above table, they do not extract the syntactic and semantic information of the text through multiple models, resulting in insufficient text features being extracted and poor performance on the test set.

[0136] (5) Ablation experiment:

[0137] To further explore the effectiveness of the BTCNN-CHW model, ablation experiments are also needed to study the independent factors affecting the experimental results. The results of the ablation experiment are shown in Table 6.

[0138] Table 6

[0139]

[0140] Comparing the effects of the four models in Table 6 on the HASOC-2021 dataset, it can be found that using only the baseline model BERT for text classification achieves the worst performance. The reason is that when BERT processes long texts, it needs to cut the text into shorter segments, which will lose some text context information. After adding other modules to the baseline model BERT, more text feature information can be extracted, and better classification effects can be achieved. Generally speaking, the BTCNN-CHW model can extract more text semantic information by combining multiple modules. Experiments show that the BTCNN-CHW model has improved by 0.82%, 2.92%, 2.73%, and 0.93% respectively in terms of accuracy, precision, recall, and F1 value compared to the second-best model. The results of the ablation experiment demonstrate the effectiveness of the BTCNN-CHW model.

[0141] The embodiments described above are only descriptions of the preferred embodiments of the present invention and do not limit the scope of the present invention. Without departing from the design spirit of the present invention, various deformations and improvements made by those of ordinary skill in the art to the technical solutions of the present invention shall fall within the protection scope determined by the claims of the present invention.

Claims

1. An offensive speech detection method based on multi-text features, characterized in that: include: Get the text data to be detected; The text data to be detected is input into a preset BTCNN-CHW model, and the offensive speech detection result of the text data to be detected is output, wherein the BTCNN-CHW model is obtained based on training of a training set, and the training set includes a number of offensive text data. The BTCNN-CHW model is used to identify the offensive features hidden in the text data to be detected by using multi-angle features.

2. The method for detecting offensive speech based on multiple text features according to claim 1, characterized in that: The BTCNN-CHW model includes: a text word embedding layer, a semantic feature extraction layer, and a classification output layer, wherein the text word embedding layer is used to extract the text word embedding features of the text data to be detected; the semantic feature extraction layer is used to extract multiple semantic features based on the text word embedding features; the classification output layer is used to perform fusion analysis on multiple semantic features and output text classification results.

3. The method for detecting offensive speech based on multiple text features according to claim 2, characterized in that: The text word embedding layer extracts the text word embedding features of the text data to be detected using a first BERT module, including: Constructing the text data to be detected into a text vector, wherein the text vector includes a word vector, a sentence embedding and a position vector; The text vector is input into the first BERT module, and passes through several Transformer modules in the first BERT module to obtain a text-state semantic representation, that is, the text word embedding feature.

4. The method for detecting offensive speech based on multiple text features according to claim 2, characterized in that: The semantic feature extraction layer extracts multiple semantic features based on the text word embedding features using a TextCNN module, a second BERT module, a Character Encoder module and a HOF Encoder module, wherein the TextCNN module is used to extract local features of multi-level short texts based on the text word embedding features; the second BERT module is used to extract context features based on the text word embedding features; the Character Encoder module is used to extract character set features based on the text word embedding features; and the HOF Encoder module is used to extract word-level features based on the text word embedding features.

5. The method for detecting offensive speech based on multiple text features according to claim 4, characterized in that: The TextCNN module includes an input layer, a convolution layer, a pooling layer, a first fully connected layer and a first output layer connected in sequence, wherein the convolution layer uses a number of convolution kernels of different sizes to process text data and obtain local features of different scales.

6. The method for detecting offensive speech based on multiple text features according to claim 5, characterized in that: The calculation method of the convolution kernel is: c i =f(W·X i:i+h-1 +b); Among them, X i:i+h-1 is the word vector at each position in the text content, c i From X i:i+h-1 The i-th feature generated in the window of , W is the weight, b is the bias parameter, h is the number of convolution kernels, and f is the activation function.

7. The method for detecting offensive speech based on multiple text features according to claim 2, characterized in that: The classification output layer includes a second fully connected layer and a second output layer connected in sequence, wherein the second fully connected layer is used to calculate the weights of the fused multiple semantic features, and the second output layer is used to classify the output of the second fully connected layer to obtain the probability value of the text information tendency type.

8. The method for detecting offensive speech based on multiple text features according to claim 7, characterized in that: The second fully connected layer performs weight calculation on the fused multiple semantic features including: M=ReLU(W d ·out+b d ); Among them, W d is the second fully connected weight matrix, b d is the bias of the second fully connected layer, out is the fused multiple semantic features, and M is the output of the second fully connected layer.

9. The method for detecting offensive speech based on multiple text features according to claim 8, characterized in that: The second output layer performs classification processing on the output of the second fully connected layer, and obtaining the probability value of the tendency type of the text information includes: y=Softmax(W s +b) Among them, W s is the weight matrix corresponding to the second output layer, b is the bias of the second output layer, and y is the probability value of the output text information tendency type.