Harmonic-containing malicious comment identification method

By adopting the multi-head attention mechanism and three-channel input method in the neural network model, the accuracy and efficiency of identifying homophone malicious content in network comments in the prior art is solved, and more efficient identification and processing effects are achieved.

CN119513311APending Publication Date: 2025-02-25HUBEI UNIV OF ECONOMICS
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411412702.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-11
Publication Date
2025-02-25

AI Technical Summary

Technical Problem

The prior art has problems such as low recognition accuracy, frequent update of vocabulary lists, and a lot of manpower when identifying and processing homophone malicious content in online comments.

Method used

Using a multi-head attention mechanism and a three-channel input neural network model, the information of each channel is extracted by fusing the original text, pinyin text and pinyin first letter text, and finally the recognition result is obtained.

Benefits of technology

It improves the ability to capture the relationship between the front and back of long texts, enhances the computing efficiency, avoids the problem of gradient vanishing, and effectively recognizes and deals with homophone malicious content in online comments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119513311A_ABST
    Figure CN119513311A_ABST
Patent Text Reader

Abstract

The invention discloses a harmonic-containing malicious comment recognition method, which comprises the following steps of S1, collecting text data, classifying the text data into malicious comments and non-malicious comments, and constructing a text data set which comprises Chinese character texts and corresponding pinyin; s2, training a neural network model by using the text data set, in the neural network model, dividing input text data into three channels, namely an original text, a pinyin text and a pinyin initial text, extracting information of each channel from the text data through a multi-head attention mechanism, fusing the three channels, and further extracting information, and finally obtaining an identification result. S3, verifying the recognition accuracy of the neural network model; and S4, during actual comment recognition, collecting comment texts, inputting the comment texts into the neural network model, and judging whether the comment texts belong to malicious comments or not.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of comment recognition, and in particular to a method for recognizing malicious comments containing homophones. Background Art

[0002] With the rapid development of Internet technology and the vigorous growth of Internet culture, Internet users are exposed to more and more diverse online life, and the bizarre information leads to a lack of thinking. Perhaps at some point, some deliberately guided malicious opinions, after unthinkingly agreeing with them, will bring devastating harm to an individual. Especially for the endless large and small cyberbullying incidents nowadays, the fuse behind them is often a blurted out bad words.

[0003] At present, different platforms have adopted the construction of malicious keyword lists and manual reporting and supervision mechanisms to deal with malicious comments. The defect of building a word list is that only a word in a comment can be identified if it appears in the word list, and the appearance of the word is irrelevant to the context. Due to the continuous development of the Internet, such a mechanism needs to constantly update the word list and is prone to misjudgment. The manual reporting and supervision mechanism requires users to actively maintain the platform environment, and the back-end staff needs to quickly review and resolve the report. Although this method improves the accuracy of identifying malicious comments, it consumes a huge amount of manpower. Summary of the invention

[0004] In order to solve the problems raised in the above background technology, the technical solution adopted by the present invention is:

[0005] A method for identifying malicious comments containing homophones comprises the following steps:

[0006] S1. Collect text data, classify the text data into malicious comments and non-malicious comments, and construct a text data set, which contains Chinese text and corresponding pinyin;

[0007] S2. Use the text data set to train a neural network model. In the neural network model, the input text data is divided into three channels: original text, pinyin text, and pinyin initials text. The multi-head attention mechanism is used to extract information from each channel in the text data, and then the three channels are fused to further extract information, and finally the recognition result is obtained;

[0008] S3, verify the recognition accuracy of the neural network model;

[0009] S4. When actually performing comment recognition, collect the comment text and input it into the neural network model to determine whether it is a malicious comment.

[0010] Furthermore, in step S1, when constructing the text dataset, a large amount of text data of online comments is obtained from the network platform through web crawler technology, the text data is classified into malicious comments and non-malicious comments through manual classification, and Chinese characters are automatically converted into pinyin through pypinyin, and homophonic replacement is performed on the text data.

[0011] Further, in step S2, the neural network model includes a preprocessing layer, an encoder and a decoder;

[0012] In the preprocessing layer:

[0013] S21a, for input text data, whose type is list List, List contains text of type string str, represented as List[str], and the length of List is batch_size, the input text data is divided into three channels: original text, pinyin text, and pinyin initials text, and each word in the original text is meta-ized;

[0014] S21b, define a time step steps. If the length of the text data exceeds steps, the excess part is truncated. If the length of the text data is less than steps, the missing part is filled. After processing, three Lists with shapes of (batch_size, steps) corresponding to the three channels are obtained;

[0015] S21c, through the preset word table, map each word unit to the corresponding number and construct it as a variable of Tensor type, link the three Tensors corresponding to the three channels together in the dimensions between batch_size and steps, construct a Tensor with a shape of (batch_size, num_channels, steps), and output it to the encoder.

[0016] Furthermore, in the encoder:

[0017] S22a. For the Tensor input by the preprocessing layer, an embedding layer is used to vectorize the numbers corresponding to the Tensor. After each word is vectorized, the output embedding vector shape is (batch_size, num_channels, steps, hidden_size), where hidden_size is the length of the vector.

[0018] S22b, using periodic function injection position coding, the position coding of the 2×jth feature of the ith word element of each sentence is:

[0019]

[0020] The position encoding of the 2×j+1th feature of the i-th word is:

[0021]

[0022] S22c. Extract the information of each channel in the text data through a multi-head attention mechanism. Specifically, the query, key, and value of the attention mechanism are all of Tensor type, where key and value correspond one to one, the query shape is (batch_size, num_query, query_size), the key shape is (batch_size, num_key_value, key_size), and the value shape is (batch_size, num_key_value, value_size);

[0023] For each query, calculate its correlation with key i score i =α(query, key i ), the attention score function is:

[0024]

[0025] sotfmax represents the normalized exponential function;

[0026] The output is the weighted sum of each query and value, that is,

[0027]

[0028] When using a multi-head attention mechanism, h different attention mechanisms are used to learn different patterns. For the i-th head in the multi-head attention:

[0029] h i =f(W iq ×query,W ik ×keys,W iv ×value)

[0030] Finally, the learned h patterns are fused together as output:

[0031] output=W o ×[h1…,h h ]

[0032] Among them (W iq , W ik , W iv ) represents the feature matrix of linear transformation of (query, key, value), W oRepresents the feature matrix that projects the multi-head merge matrix into the category space;

[0033] After extraction by the multi-head attention mechanism, the output shapes of the three channels remain unchanged, all of which are (batch_size, steps, hidden_size). The outputs of the three channels are fused in the steps dimension to obtain a Tensor with a shape of (batch_size, steps*3, hidden_size);

[0034] S22d. When scoring attention, for each input text data, the steps dimension represents the num_key_value dimension. After the three channels are fused in the steps dimension, each small batch of key-value pairs contains information from three channels: original text, pinyin text, and pinyin initials text. The output of the original text channel is used as the query, and the fused information is used as the key-value to perform a layer of multi-head attention mechanism to extract key information. The final shape of the encoder output is (batch_size, steps, hidden_size).

[0035] Furthermore, in the decoder:

[0036] S23a, the input of the decoder comes from the output of the encoder. In the Transformer network of the decoder, the query of the next layer of the network comes from the output of the current network, and the key-value of the next layer of the network comes from the output of the current network and the result of linking the key-value of the current network in the steps dimension, so that the key-value of each layer is the result of linking the key-value of each historical layer in steps, that is, the key-value of each layer retains the information of the key-value of each historical layer;

[0037] S23b, after receiving the output of the Transformer that records the history, stretch each small batch of its output into one dimension and enter a feedforward network to fuse the information of each step. The output format is (batch_size, 1, hidden_size), which means that each small batch has a query, and the query contains the information of the entire text;

[0038] S23c. After obtaining the query from the full text, an attention mechanism is performed on it and the Transformer that records the history. By paying attention to all information from the full text, the information contained in each small batch can be obtained. Finally, a linear layer is used to map the information contained in each small batch to the category space to complete the semantic recognition of each small batch.

[0039] Furthermore, in step S3, the k-fold cross-validation method is used to verify the training accuracy of the neural network model, and the confusion matrix is ​​used to verify the recognition accuracy of the neural network model; if the recognition accuracy is lower than the preset threshold, return to step S2, adjust the model parameters and re-train until its classification accuracy reaches the preset threshold.

[0040] Compared with the prior art, the present invention has the following beneficial effects:

[0041] The method for identifying malicious comments containing homophones provided by the present invention can effectively identify and process malicious homophone content in online comments by adopting a multi-head attention mechanism and a three-channel input method; compared with the traditional recurrent neural network, the multi-head attention mechanism not only improves the computational efficiency, but also enhances the ability to capture the contextual relationship of long texts, while avoiding the gradient vanishing problem in deep network training. The present invention provides an effective technical support for the purification of the network environment, so as to promote the healthy development of the network environment, maintain the harmony and order of the network environment, and help make the network environment and even the entire society healthier and more harmonious. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 A schematic diagram of a flow chart of a method for identifying malicious comments containing homophones provided by the present invention;

[0043] Figure 2 It is a schematic diagram of the results of using a confusion matrix to verify the accuracy of a model in a specific embodiment. DETAILED DESCRIPTION

[0044] In order to make the technical means, creative features, objectives and effects achieved by the present invention easy to understand, the following further describes how the present invention is implemented in conjunction with the accompanying drawings and specific implementation methods.

[0045] In a specific embodiment, referring to Figure 1 As shown, the present invention provides a method for identifying malicious comments containing homophones, comprising the following steps:

[0046] S1. Collect text data, classify the text data into malicious comments and non-malicious comments, and construct a text data set, which contains Chinese text and corresponding pinyin;

[0047] S2. Use the text data set to train a neural network model. In the neural network model, the input text data is divided into three channels: original text, pinyin text, and pinyin initials text. The multi-head attention mechanism is used to extract information from each channel in the text data, and then the three channels are fused to further extract information, and finally the recognition result is obtained;

[0048] S3, verify the recognition accuracy of the neural network model;

[0049] S4. When actually performing comment recognition, collect the comment text and input it into the neural network model to determine whether it is a malicious comment.

[0050] In a specific embodiment, in step S1, when constructing a text data set, most of the text data can be obtained from a network platform through web crawler technology, and a small part of the text data can be collected from common online swear words to supplement the data set.

[0051] After the data is collected, all text data is in an unclassified state. After browsing each text data, it can be labeled as malicious or non-malicious through manual classification, so as to classify the text data into malicious comments and non-malicious comments. If there are homophonic characters replacing the original characters in the text data to avoid the malicious word list of the platform, the homophonic characters will be manually corrected during manual classification, and the text data will be replaced with homophonic characters, and the correction points will be marked. In addition, the pypinyin in the open source python library can be used to automatically convert Chinese characters to pinyin. In addition, in addition to homophonic character replacement, if necessary, synonym replacement or translation into different languages ​​and then translation back can be used to enhance the data set.

[0052] The present invention ensures the quality and accuracy of the data through manual classification; and enhances the data set by adopting strategies such as homophonic character replacement, thereby further improving the generalization ability and robustness of the model.

[0053] Furthermore, in step S2, the neural network model includes a preprocessing layer, an encoder and a decoder. In the preprocessing layer:

[0054] S21a. For input text data, its type is list List, and the text in List is of string type str, represented as List[str]. The length of List is batch_size. The input text data is divided into three channels: original text, pinyin text, and pinyin initials text, and each word in the original text is meta-ized.

[0055] After entering the preprocessing layer, the pinyin text and the pinyin initials text will be obtained through pypinyin. For example, input ["How are you?", "Hello"] to get [["ni", "hao", "ma"], ["ni", "hao"]] and [['n', 'h', 'm'], ['n', 'h']], then three channels are obtained, namely [original text, pinyin text, pinyin initials text].

[0056] Traditional lemma is to segment sentences, but this method strongly depends on the accuracy of the lemma. If the lemma does not segment the sentence well, the trained lemma will not be able to express the original meaning well. In the homophonic task, the lemma may make segmentation errors due to the use of homophonic characters in the sentence. And because the number of words is much greater than the number of characters, using lemma will result in a huge vocabulary, and the number of layers will be huge in the subsequent training.

[0057] Therefore, in the present invention, each word is lemmatized, which not only reduces the size of the vocabulary, but also makes the context prediction more accurate and powerful by judging the meaning of each word by the words near it. In the operation of channel augmentation, the pinyin text and the pinyin initials text have been lemmatized, so it is only necessary to lemmatize the original text. For example, the result after lemmatization of ["how are you", "hello"] is [["you", "good", "may"], ["you", "good"]].

[0058] S21b. Since small batch training is required, the length of each sentence in each small batch needs to be the same. A time step steps is defined. If the length of the text data exceeds steps, the excess part is truncated. If the length of the text data is less than steps, the missing part is filled. After processing, three Lists with a shape of (batch_size, steps) corresponding to the three channels are obtained.

[0059] For example, if [["you","good","are"],["good"]] is filled and truncated with steps=2, the result is [["you","good"],[" <unk>″,″Good″]], it can be seen that truncation will lose some information, so the steps can be set larger to ensure that information is not lost as much as possible; if setps is too large, the sentence will be too long and the training time will increase. In this embodiment, steps=128.

[0060] S21c, through the preset word table, map each word unit to the corresponding number and construct it as a variable of Tensor type, link the three Tensors corresponding to the three channels together in the dimensions between batch_size and steps, construct a Tensor with a shape of (batch_size, num_channels, steps), and output it to the encoder.

[0061] Further, in the encoder: S22a, for the Tensor input to the preprocessing layer, an embedding layer is used to vectorize the numbers corresponding to the Tensor. After each word is vectorized, the output embedding vector shape is (batch_size, num_channels, steps, hidden_size), where hidden_size is the length of the vector. Embedding is a simple lookup table used to store embeddings of fixed dictionary and size. This module is usually used to store word embeddings and retrieve them using indexes. The input of the module is an index list, and the output is the corresponding word embedding vector.

[0062] S22b. When processing word-unit sequences, the recurrent neural network processes each word-unit in turn in a loop. The attention mechanism abandons sequential operations for parallel computing, which results in the attention mechanism not paying attention to the position of a word-unit and the distribution of its attached words. In order to retain the position information of the sequence, it is necessary to add position encoding to the input of the attention mechanism to inject relative or absolute position information. In order to ensure the relativity of the position, the present invention uses periodic functions sin and cos to inject position encoding. The position encoding of the 2×jth feature of the ith word-unit of each sentence is:

[0063]

[0064] The position encoding of the 2×j+1th feature of the i-th word is:

[0065]

[0066] S22c. Extract the information of each channel in the text data through a multi-head attention mechanism. Specifically, the query, key, and value of the attention mechanism are all of Tensor type, where key and value correspond one to one, the query shape is (batch_size, num_query, query_size), the key shape is (batch_size, num_key_value, key_size), and the value shape is (batch_size, num_key_value, value_size);

[0067] For each query, calculate its correlation with key i score i =α(query, key i ), the attention score function is:

[0068]

[0069] sotfmax represents the normalized exponential function;

[0070] The output is the weighted sum of each query and value, that is,

[0071]

[0072] When using a multi-head attention mechanism, h different attention mechanisms are used to learn different patterns. For the i-th head in the multi-head attention:

[0073] h i =f(W iq ×query,W ik ×keys,W iv ×value)

[0074] Finally, the learned h patterns are fused together as output:

[0075] output=W o ×[h1…,h h ]

[0076] Among them (W iq , W ik , W iv ) represents the feature matrix of linear transformation of (query, key, value), W o Represents the feature matrix that projects the multi-head merge matrix into the category space;

[0077] After extraction by the multi-head attention mechanism, the output shapes of the three channels remain unchanged, all of which are (batch_size, steps, hidden_size). The outputs of the three channels are fused in the steps dimension to obtain a Tensor with a shape of (batch_size, steps*3, hidden_size).

[0078] S22d. When scoring attention, for each input text data, the steps dimension represents the num_key_value dimension. After the three channels are fused in the steps dimension, each small batch of key-value pairs contains information from three channels: original text, pinyin text, and pinyin initials text. The output of the original text channel is used as the query, and the fused information is used as the key-value to perform a layer of multi-head attention mechanism to extract key information. The final shape of the encoder output is (batch_size, steps, hidden_size).

[0079] Furthermore, in the decoder: S23a, the input of the decoder comes from the output of the encoder. In the Transformer network of the decoder, the query of the next layer of the network comes from the output of the current network, and the key-value of the next layer of the network comes from the output of the current network and the result of linking the key-value of the current network in the steps dimension, so that the key-value of each layer is the result of connecting the key-value of each historical layer in steps, that is, the key-value of each layer retains the information of the key-value of each historical layer.

[0080] In this way, it can be ensured that even if the model training results are not good, due to the historical information, the model training results will not get worse.

[0081] S23b. In the previous multi-head attention mechanism, each query in each small batch represents a query for each word-meta information. For information that needs to be understood in a text, it is not advisable to judge the entire text only by one word-meta information, so all word-meta information of a text needs to be fused together. After receiving the output of the Transformer that records the history, each small batch of its output is stretched into one dimension and enters a feedforward network to fuse the information of each step. The output format is (batch_size, 1, hidden_size), which means that each small batch has one query and the query contains the information of the entire text.

[0082] S23c. After obtaining the query from the full text, an attention mechanism is performed on it and the Transformer that records the history. By paying attention to all information from the full text, the information contained in each small batch can be obtained. Finally, a linear layer is used to map the information contained in each small batch to the category space to complete the semantic recognition of each small batch.

[0083] It can be seen that the present invention can effectively identify and process homophonic malicious content in online comments by adopting a multi-head attention mechanism and a three-channel input method; compared with traditional recurrent neural networks, the use of a multi-head attention mechanism not only improves the computational efficiency, but also enhances the ability to capture the contextual relationship of long texts, while avoiding the gradient vanishing problem in deep network training.

[0084] Furthermore, in step S3, the k-fold cross-validation method is used to verify the training accuracy of the neural network model, and the confusion matrix is ​​used to verify the recognition accuracy of the neural network model; if the recognition accuracy is lower than a preset threshold (such as 80%), return to step S2, adjust the model parameters and re-train until its classification accuracy reaches the preset threshold.

[0085] Specifically, k-fold cross validation divides the dataset into k similar subsets, and then trains and validates the model k times on these k subsets. In each training, one of the subsets is used as a validation set, and the remaining k-1 subsets are used as training sets. In this way, the performance of the model on different datasets can be evaluated, thereby more objectively evaluating its generalization ability. Finally, the average of the k validation results is used as the training accuracy of the model. This method can effectively reduce the deviation caused by uneven data set division, and can better utilize the information in the dataset, thereby obtaining more reliable model evaluation results.

[0086] A confusion matrix is ​​a table used to evaluate the performance of a classification model. It compares the model's predictions with the true labels, providing detailed information about the model's classification capabilities. In a confusion matrix, rows represent true categories and columns represent categories predicted by the model. The value of each cell represents the number of times the model predicted a true category as a certain predicted category. Based on the confusion matrix, various performance metrics can be calculated, including accuracy, precision, recall, and F1 score.

[0087] In a specific embodiment, the confusion matrix is ​​used to verify the model accuracy result. Figure 2 As shown, from the confusion matrix we can see that 316 true positive samples are correctly classified as positive, 288 true negative samples are correctly classified as negative, 53 true positive samples are incorrectly classified as negative, and 70 true negative samples are incorrectly classified as positive. The calculation results of Accuracy, Precision, Recall and F1 score are as follows:

[0088]

[0089] Among them, TP, TN, FP and FN represent the number of true positives, true negatives, false positives and false negatives in the confusion matrix respectively.

[0090] It can be seen that in this embodiment, the k-fold cross validation and confusion matrix methods are used to comprehensively verify the performance of the model. The evaluation results show that the model has achieved satisfactory accuracy, precision, recall rate and F1 score in the malicious comment identification task, showing good application prospects.

[0091] In general, the method for identifying malicious comments containing homophones provided by the present invention provides an effective technical support for the purification of the network environment, so as to promote the healthy development of the network environment, maintain the harmony and order of the network environment, and help make the network environment and even the entire society healthier and more harmonious.

[0092] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the purpose and scope of the technical solution of the present invention, which should be included in the scope of the claims of the present invention.< / unk>

Claims

1. A method for identifying malicious comments containing homophones, characterized in that: The steps include: S1. Collect text data, classify the text data into malicious comments and non-malicious comments, and construct a text data set, which contains Chinese text and corresponding pinyin; S2. Use the text data set to train a neural network model. In the neural network model, the input text data is divided into three channels: original text, pinyin text, and pinyin initials text. The multi-head attention mechanism is used to extract information from each channel in the text data, and then the three channels are fused to further extract information, and finally the recognition result is obtained; S3, verify the recognition accuracy of the neural network model; S4. When actually performing comment recognition, collect the comment text and input it into the neural network model to determine whether it is a malicious comment.

2. The method for identifying malicious comments containing homophones according to claim 1, characterized in that: In step S1, when constructing a text dataset, a large amount of text data of online comments is obtained from the network platform through web crawler technology, and the text data is classified into malicious comments and non-malicious comments through manual classification. Pypinyin is used to automatically convert Chinese characters into pinyin, and homophonic replacement is performed on the text data.

3. The method for identifying malicious comments containing homophones according to claim 1, characterized in that: In step S2, the neural network model includes a preprocessing layer, an encoder and a decoder; In the preprocessing layer: S21a, for input text data, whose type is list List, List contains text of type string str, represented as List[str], and the length of List is batch_size, the input text data is divided into three channels: original text, pinyin text, and pinyin initials text, and each word in the original text is meta-ized; S21b, define a time step steps. If the length of the text data exceeds steps, the excess part is truncated. If the length of the text data is less than steps, the missing part is filled. After processing, three Lists with shapes of (batch_size, steps) corresponding to the three channels are obtained; S21c, through the preset word table, map each word unit to the corresponding number and construct it as a variable of Tensor type, link the three Tensors corresponding to the three channels together in the dimensions between batch_size and steps, construct a Tensor with a shape of (batch_size, num_channels, steps), and output it to the encoder.

4. The method for identifying malicious comments containing homophones according to claim 3, characterized in that: In the encoder: S22a. For the Tensor input by the preprocessing layer, an embedding layer is used to vectorize the numbers corresponding to the Tensor. After each word is vectorized, the output embedding vector shape is (batch_size, num_channels, steps, hidden_size), where hidden_size is the length of the vector. S22b, using periodic function injection position coding, the position coding of the 2×jth feature of the ith word element of each sentence is: The position encoding of the 2×j+1th feature of the i-th word is: S22c. Extract the information of each channel in the text data through a multi-head attention mechanism. Specifically, the query, key, and value of the attention mechanism are all of Tensor type, where key and value correspond one to one, the query shape is (batch_size, num_query, query_size), the key shape is (batch_size, num_key_value, key_size), and the value shape is (batch_size, num_key_value, value_size); For each query, calculate its correlation with key i score i =α(query, key i ), the attention score function is: sotfmax represents the normalized exponential function; The output is the weighted sum of each query and value, that is, When using a multi-head attention mechanism, h different attention mechanisms are used to learn different patterns. For the i-th head in the multi-head attention: h i =f(W iq ×query,W ik ×keys,W iv ×value) Finally, the learned h patterns are fused together as output: output=W o ×[h1…,h h ] Among them (W iq , W ik , W iv ) represents the feature matrix of linear transformation of (query, key, value), W o Represents the feature matrix that projects the multi-head merge matrix into the category space; After extraction by the multi-head attention mechanism, the output shapes of the three channels remain unchanged, all of which are (batch_size, steps, hidden_size). The outputs of the three channels are fused in the steps dimension to obtain a Tensor with a shape of (batch_size, steps*3, hidden_size); S22d. When scoring attention, for each input text data, the steps dimension represents the num_key_value dimension. After the three channels are fused in the steps dimension, each small batch of key-value pairs contains information from three channels: original text, pinyin text, and pinyin initials text. The output of the original text channel is used as the query, and the fused information is used as the key-value to perform a layer of multi-head attention mechanism to extract key information. The final shape of the encoder output is (batch_size, steps, hidden_size).

5. The method for identifying malicious comments containing homophones according to claim 4, characterized in that: In the decoder: S23a, the input of the decoder comes from the output of the encoder. In the Transformer network of the decoder, the query of the next layer of the network comes from the output of the current network, and the key-value of the next layer of the network comes from the output of the current network and the result of linking the key-value of the current network in the steps dimension, so that the key-value of each layer is the result of linking the key-value of each historical layer in steps, that is, the key-value of each layer retains the information of the key-value of each historical layer; S23b, after receiving the output of the Transformer that records the history, stretch each small batch of its output into one dimension and enter a feedforward network to fuse the information of each step. The output format is (batch_size, 1, hidden_size), which means that each small batch has a query, and the query contains the information of the entire text; S23c. After obtaining the query from the full text, an attention mechanism is performed on it and the Transformer that records the history. By paying attention to all information from the full text, the information contained in each small batch can be obtained. Finally, a linear layer is used to map the information contained in each small batch to the category space to complete the semantic recognition of each small batch.

6. The method for identifying malicious comments containing homophones according to claim 1, characterized in that: In step S3, the k-fold cross-validation method is used to verify the training accuracy of the neural network model, and the confusion matrix is ​​used to verify the recognition accuracy of the neural network model; if the recognition accuracy is lower than the preset threshold, return to step S2, adjust the model parameters and re-train until its classification accuracy reaches the preset threshold.