A method, device and storage medium for detecting bad short text on the Internet based on BERT

Through the network bad short text detection method based on BERT, using the two-stage classification of hidden states and attention weights, the problem of low short text detection performance in the existing technology is solved, and more accurate bad short text detection is achieved.

CN112131453BInactive Publication Date: 2024-10-11JIANGHAN UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010871788.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-08-26
Publication Date
2024-10-11
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

In the existing technology, the detection performance of bad short texts on the Internet is low, mainly due to the characteristics of short texts such as high noise, short length, and sparse information, which makes traditional classification methods ineffective and difficult to extract high-quality topic features.

Method used

The BERT-based network bad short text detection method is used to collect and label short texts, divide them into test data sets and training data sets, train the BERT model, and use the semantic representation of hidden states and attention weights to conduct a two-stage classification, including Discrimination of coarse-grained and fine-grained labels, combined with additional information for detection.

Benefits of technology

It improves the performance of bad short text detection, can more accurately identify and classify different types of bad short texts, and improves the accuracy and recall rate of detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112131453B_ABST
    Figure CN112131453B_ABST
Patent Text Reader

Abstract

The present invention relates to a method, device and computer-readable storage medium for detecting bad short texts on a network based on BERT. A method for detecting bad short texts on a network based on BERT comprises the following steps: collecting short texts and annotating them, dividing the annotated short texts into a test data set and a training data set, training a BERT model according to the test data set and the training data set, and obtaining a BERT model based on bad short text detection; inputting the short text to be detected and its corresponding additional information into the BERT model based on bad short text detection, obtaining the corresponding hidden state semantic representation, and obtaining the bad short text label according to the hidden state semantic representation; inputting the bad short text label, the short text to be detected and its corresponding additional information into the BERT model based on bad short text detection, obtaining the corresponding hidden state semantic representation, and distinguishing the type of the bad short text according to the hidden state semantic representation. The method improves the performance of bad short text detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of bad text information detection, and in particular to a BERT-based method, device and computer-readable storage medium for detecting bad short text on the Internet. Background Art

[0002] With the rapid development of mobile Internet and information technology, the extensive use of various social media platforms has brought great changes to people's lives and behaviors; for example, Internet applications such as Weibo, forums and WeChat have gradually become the main battlefield for people to share and discuss hot online events. However, some netizens with bad intentions take advantage of the virtuality, anonymity and convenience of the Internet to spread a large number of bad short texts on the Internet, such as pornography, violence, terrorism and advertising information. These bad short texts on the Internet can spread quickly to every corner of the Internet, not only seriously polluting the network environment, but also affecting the physical and mental health of young people. Therefore, automatically detecting bad short text information posted by netizens on social media platforms through information technology can greatly reduce the workload of manual review, help create a harmonious network environment, and improve the efficiency of netizens' information retrieval.

[0003] The task of detecting bad short texts on the Internet is to divide short text information on the Internet into two categories: normal short texts and bad short texts. However, due to the characteristics of short texts such as high noise, short length, and sparse information, traditional classification methods have poor effects on short texts. Many researchers use topic information to enrich the semantic features of short texts to improve classification performance, but the short text information posted by netizens on social platforms often has non-standard terms, lacks word co-occurrence information, and has very broad topics.

[0004] It is very difficult for traditional topic models to extract high-quality topic features from short texts, resulting in low performance in bad short text detection. Summary of the invention

[0005] In view of this, it is necessary to provide a BERT-based method, device and computer-readable storage medium for detecting bad short text on the network, so as to solve the technical problem of low performance of bad short text detection on the network in the prior art.

[0006] The present invention provides a method for detecting bad short text on a network based on BERT, comprising the following steps:

[0007] Collecting short texts, annotating the short texts, dividing the annotated short texts into a test data set and a training data set, training a BERT model according to the test data set and the training data set, and obtaining a BERT model based on bad short text detection;

[0008] Inputting the short text to be detected and its corresponding additional information into the BERT model based on bad short text detection, obtaining the semantic representation of the corresponding hidden state, and obtaining the bad short text label according to the semantic representation of the hidden state;

[0009] The bad short text label, the short text to be detected and the corresponding additional information are input into the BERT model based on bad short text detection to obtain the corresponding hidden state semantic representation, and the type of the bad short text is determined according to the hidden state semantic representation.

[0010] Furthermore, the short texts are annotated, and the annotated short texts are divided into a test data set and a training data set, and a BERT model is trained according to the test data set and the training data set, specifically including annotating the short texts as bad short texts or normal short texts, annotating the bad short texts as different types of bad short texts, dividing the annotated short texts into a test data set and a training data set, and training the BERT model using the test data set, the training data set and additional information of the short texts.

[0011] Furthermore, the BERT model is trained using the test data set, the training data set, and the additional information of the short text, specifically including using the test data set, the training data set, and the additional information of the short text, using Gelu as the activation function, using the Adam optimizer, and using the cross entropy loss function to train the BERT model, wherein the cross entropy loss function is

[0012]

[0013] Among them, y represents the true label of the short text dataset, p represents the label predicted by the model, m represents the number of labels, and n represents the number of short text datasets.

[0014] Furthermore, the short text to be detected and its corresponding additional information are input into the BERT model based on bad short text detection to obtain the semantic representation of the corresponding hidden state, and the bad short text label is obtained according to the semantic representation of the hidden state, specifically including: vectorizing the short text to be detected and its corresponding additional information to obtain an input vector, inputting the input vector into the BERT model for bad short text detection, encoding the input vector into a hidden state, obtaining the attention weight of the hidden state, obtaining the semantic representation of the hidden state according to the hidden state and its attention weight, and obtaining the bad short text label according to the semantic representation of the hidden state.

[0015] Furthermore, based on the semantic representation of the hidden state, bad short texts are identified, specifically including connecting the short text represented by [CLS] with the semantic representation of all hidden states to form a vector R for classification, inputting the vector R into a fully connected layer, and obtaining a bad short text label.

[0016] Further, obtaining the attention weight of the hidden state specifically includes obtaining the attention weight of the hidden state using the attention weight calculation formula, wherein the attention weight calculation formula is:

[0017]

[0018] f represents the relationship scoring function, f(H i ,T)=tanh(W[H i :T]+b), tanh represents the hyperbolic tangent activation function, W and b represent the parameters of the model, H i , T are hidden states and topic features respectively, A i is the attention weight.

[0019] Further, according to the hidden state and its attention weight, a semantic representation of the hidden state is obtained, specifically including obtaining the semantic representation of the hidden state using a semantic representation formula, wherein the semantic representation formula is

[0020] Furthermore, the bad short text label, the short text to be detected and the corresponding additional information are input into the BERT model based on bad short text detection to obtain the corresponding hidden state semantic representation, and the type of the bad short text is determined according to the semantic representation of the hidden state. Specifically, the bad short text label, the short text to be detected and the corresponding additional information are vectorized to obtain an input vector, the input vector is input into the BERT model for bad short text detection, the input vector is encoded into a hidden state, the attention weight of the hidden state is obtained, the semantic representation of the hidden state is obtained according to the hidden state and its attention weight, and the bad short text is determined according to the semantic representation of the hidden state.

[0021] The present invention also provides a device for detecting bad short network text based on BERT, comprising a processor and a memory, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, a method for detecting bad short network text based on BERT as described in any of the above technical solutions is implemented.

[0022] The present invention also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the BERT-based network bad short text detection method as described in any of the above technical solutions is implemented.

[0023] Compared with the prior art, the beneficial effects of the present invention include: by collecting short texts, annotating the short texts, dividing the annotated short texts into a test data set and a training data set, training a BERT model according to the test data set and the training data set, and obtaining a BERT model based on bad short text detection; inputting the short text to be detected and its corresponding additional information into the BERT model based on bad short text detection, obtaining the corresponding semantic representation of the hidden state, and obtaining the bad short text label according to the semantic representation of the hidden state; inputting the bad short text label, the short text to be detected and its corresponding additional information into the BERT model based on bad short text detection, obtaining the corresponding semantic representation of the hidden state, and distinguishing the type of the bad short text according to the semantic representation of the hidden state; improving the performance of bad short text detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] Figure 1 A schematic diagram of a flow chart of a method for detecting bad short text on a network based on BERT provided in Example 1 of the present invention;

[0025] Figure 2 A schematic diagram of the structure of a BERT model based on bad short text detection provided by Example 1 of the present invention;

[0026] Figure 3 Performance comparison experimental results of the TBERT model provided in Example 1 of the present invention and the benchmark model. DETAILED DESCRIPTION

[0027] The preferred embodiments of the present invention are described in detail below in conjunction with the accompanying drawings, wherein the accompanying drawings constitute a part of this application and are used together with the embodiments of the present invention to illustrate the principles of the present invention, but are not used to limit the scope of the present invention.

[0028] Example 1

[0029] The embodiment of the present invention provides a method for detecting bad short text on the Internet based on BERT, and its flow chart is as follows: Figure 1 As shown, the method comprises the following steps:

[0030] Step S1, collecting short texts, annotating the short texts, dividing the annotated short texts into a test data set and a training data set, training a BERT model according to the test data set and the training data set, and obtaining a BERT model based on bad short text detection;

[0031] S2, inputting the short text to be detected and its corresponding additional information into the BERT model based on bad short text detection, obtaining the semantic representation of the corresponding hidden state, and obtaining the bad short text label according to the semantic representation of the hidden state;

[0032] S3. Input the bad short text label, the short text to be detected and the corresponding additional information into the BERT model based on bad short text detection, obtain the corresponding hidden state semantic representation, and identify the type of the bad short text according to the hidden state semantic representation.

[0033] In a specific embodiment, the BERT-based network bad short text detection method includes a short text representation generation process of TBERT, an additional information fusion process of TBERT, and a two-stage classification process of TBERT;

[0034] The generation process of short text representation is completed by the BERT model as an encoder. In the BERT model structure, Transformer is used to encode the input.

[0035] Assume that the input short text is represented by X = (character 1, character 2, ..., character N), and the length of the short text is represented by N; the segment vector, character vector and position vector jointly represent the input short text X; the segment vector is used to distinguish two different text segments, the character vector is used to represent each character in the short text, and the position vector is used to provide position information for the model; after vectorization, the input of the model is the vector E = (E1, E2, ..., E N ); In the BERT model, self-attention and multi-head attention mechanisms are used to encode the vector E into hidden states H = (H1, H2, ..., H N ); the self-attention mechanism refers to the mapping of a query to a series of key-value pairs; let Q, K and V represent query, key and value respectively, and the self-attention weight can be calculated by the following formula;

[0036]

[0037] Multi-head attention allows the model to learn relevant information in different representation subspaces. Specifically, the parameters of each linear transformation of Q, K, and V are different. Then the multiple attention results are concatenated and the value obtained by performing a linear transformation is used as the result of multi-head attention, as shown in the following formula:

[0038] MultiHead(Q,K,V)=Concat(head1,head2,...,head h )W O

[0039]

[0040] Among them, Concat represents the connection operation. represents the parameter matrix;

[0041] In a specific embodiment, the number of multi-head attention layers h = 12, d k =d v =d modeL / h=64. Due to the reduced dimensionality of each multi-head layer, the total computational cost is similar to that of the full-dimensional single-head attention. In the original BERT model, [CLS] is added to the character sequence as the first character, and its hidden state H c The short text representation R used for classification tasks c ,In the embodiment of the present invention, all hidden states are merged into a short text vector representation for classification, and additional information is integrated;

[0042] Preferably, the short texts are annotated, the annotated short texts are divided into a test data set and a training data set, and a BERT model is trained according to the test data set and the training data set, specifically including annotating the short texts as bad short texts or normal short texts, annotating the bad short texts as different types of bad short texts, dividing the annotated short texts into a test data set and a training data set, and training the BERT model using the test data set, the training data set and additional information of the short texts;

[0043] Preferably, the BERT model is trained using the test data set, the training data set, and the additional information of the short text, specifically including using the test data set, the training data set, and the additional information of the short text, and using Gelu as the activation function, using the Adam optimizer, and using the cross entropy loss function to train the BERT model, wherein the cross entropy loss function is

[0044]

[0045] Among them, y represents the true label of the short text dataset, p represents the label predicted by the model, m represents the number of labels, and n represents the number of short text datasets;

[0046] Preferably, the short text to be detected and the corresponding additional information are input into the BERT model based on bad short text detection, the semantic representation of the corresponding hidden state is obtained, and the bad short text label is obtained according to the semantic representation of the hidden state, which specifically includes: vectorizing the short text to be detected and the corresponding additional information to obtain an input vector, inputting the input vector into the BERT model for bad short text detection, encoding the input vector into a hidden state, obtaining the attention weight of the hidden state, obtaining the semantic representation of the hidden state according to the hidden state and its attention weight, and obtaining the bad short text label according to the semantic representation of the hidden state;

[0047] In a specific embodiment, a schematic diagram of the structure of a BERT model based on bad short text detection is shown in FIG. Figure 2 As shown, Figure 2 In the example, the coarse-grained label is the bad short text label, and the fine-grained label is the bad short text type. L is the vector generated by the coarse-grained label, [SEP] is the character in the BERT model. The BERT model based on bad short text detection integrates additional information in two ways. The first is to add part of the additional information directly to the head of the short text to form a longer short text representation with richer semantic features to alleviate the sparsity problem; the second is to use the topic features to calculate the attention, which determines the weight of all hidden states in the output short text representation. The hidden state with stronger relevance to the short text topic will have a greater weight in the short text representation;

[0048] Preferably, bad short texts are identified based on the semantic representation of the hidden state, specifically including connecting the short text represented by [CLS] with the semantic representation of all hidden states to form a vector R for classification, inputting the vector R into a fully connected layer, and obtaining a bad short text label.

[0049] Preferably, obtaining the attention weight of the hidden state specifically includes obtaining the attention weight of the hidden state using an attention weight calculation formula, wherein the attention weight calculation formula is:

[0050]

[0051] f represents the relationship scoring function, f(H i ,T)=tanh(W[H i :T]+b), tanh represents the hyperbolic tangent activation function, W and b represent the parameters of the model, H i , T are hidden states and topic features respectively, A i is the attention weight.

[0052] In a specific embodiment, the GPU-DMM topic model is used to extract the topic features of the short text, and the relationship between the hidden state H and the topic features T is used to calculate the attention weight;

[0053] Preferably, according to the hidden state and its attention weight, obtaining the semantic representation of the hidden state specifically includes obtaining the semantic representation of the hidden state using a semantic representation formula, wherein the semantic representation formula is

[0054] In a specific implementation, the short text represented by [CLS] is represented by R c And the semantic representation R of all hidden states HConnect them to form a vector representation R for classification, R = Concat(R c ,R H )

[0055] Preferably, the bad short text label, the short text to be detected and the corresponding additional information are input into the BERT model based on bad short text detection to obtain the semantic representation of the corresponding hidden state, and the type of the bad short text is determined according to the semantic representation of the hidden state. Specifically, the bad short text label, the short text to be detected and the corresponding additional information are vectorized to obtain an input vector, the input vector is input into the BERT model for bad short text detection, the input vector is encoded into a hidden state, the attention weight of the hidden state is obtained, the semantic representation of the hidden state is obtained according to the hidden state and its attention weight, and the bad short text is determined according to the semantic representation of the hidden state.

[0056] It should be noted that in the task of detecting bad short texts on the Internet, it is difficult to clearly define the labels of certain short texts. This is because these short texts are deliberately fabricated by netizens with bad intentions. In order to make them misleading and confusing, these short texts contain both ordinary content and bad information. Therefore, the detection of bad short texts on the Internet should not be regarded as a simple text binary classification task. Bad short texts should also be subdivided into categories such as violence and terrorism, politics, advertising, and pornography.

[0057] Classifying short texts into "normal" and "bad" is not applicable to all cases of bad short texts on the Internet. More categories should be used to classify short texts. However, fine-grained multi-classification models are usually more difficult to train and model than two-class classification models. The BERT model based on bad short text detection provided by the embodiment of the present invention can be used to distinguish labels of different granularities. The two stages of the model can promote each other.

[0058] like Figure 2 As shown in the figure, the BERT model based on bad short text detection is similar in two stages. TBERT first divides online short texts into two categories, namely "normal" and "bad", according to coarse-grained labels; then, the model divides the short texts into multiple categories according to fine-grained labels, and the number of categories is determined by the characteristics of the data set; in the second stage, the model uses the coarse-grained labels (i.e., bad short text labels) obtained in the first stage as part of the input of the second stage, and follows the same modeling method to perform fine-grained classification on all inputs, that is, to identify the type of bad short text.

[0059] In another specific implementation, the existing support vector machine, random forest and BERT models are used as benchmark modules and the BERT model based on bad short text detection described in the embodiment of the present invention, and the commonly used performance evaluation indicators for bad short text detection on the network, namely, accuracy, recall and F1 value, are used to analyze the experimental results;

[0060] 4236 short texts were collected and annotated, of which 2118 were bad short texts, including sensitive short texts, spam short texts, advertising short texts and pornographic short texts; 400 bad short texts and 400 normal short texts were randomly selected as test data sets, and the remaining short texts were used as training data sets; for the additional information in the first part, the number of comments, number of Weibo posts, number of author fans, and number of likes were discretized and directly used as part of the model input sequence; for the additional information in the second part, the 10 words with the highest probability in the corresponding topic of the short text constituted the topic features of the short text, which were used to calculate the attention weight; the TBERT model (BERT model based on bad short text detection) used the pre-trained BERT BASE (Chinese) model, using Gelu as the activation function, using Adam optimizer, setting the learning rate to 5e-5, and setting the Dropout probability to 0.1; the performance comparison experimental results of the TBERT model and the baseline model, as shown in Figure 3 As shown, the BERT model based on bad short text detection described in the embodiment of the present invention is better than the three benchmark models in three evaluation indicators.

[0061] Example 2

[0062] An embodiment of the present invention provides a device for detecting bad short network text based on BERT, including a processor and a memory, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the method for detecting bad short network text based on BERT as described in Example 1 is implemented.

[0063] Example 3

[0064] An embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the BERT-based network bad short text detection method as described in Example 1 is implemented.

[0065] The present invention discloses a method, device and computer-readable storage medium for detecting bad short texts on a network based on BERT. The method comprises the following steps: collecting short texts, annotating the short texts, dividing the annotated short texts into a test data set and a training data set, training a BERT model according to the test data set and the training data set, and obtaining a BERT model based on bad short text detection; inputting the short text to be detected and its corresponding additional information into the BERT model based on bad short text detection, obtaining a semantic representation of the corresponding hidden state, and obtaining a bad short text label according to the semantic representation of the hidden state; inputting the bad short text label, the short text to be detected and its corresponding additional information into the BERT model based on bad short text detection, obtaining a semantic representation of the corresponding hidden state, and distinguishing the type of the bad short text according to the semantic representation of the hidden state; and improving the performance of bad short text detection.

[0066] The technical solution of the present invention learns a more robust short text representation, thereby extracting text features suitable for detecting bad short texts on the Internet; fully considers the association between different types of bad short texts on the Internet, divides the detection process into two stages, and uses additional information to enrich the semantics of short texts, and also uses all hidden state features for classification, thereby alleviating the problem of sparse short text information; and also promotes each other through coarse-grained classification and fine-grained classification, thereby improving the accuracy of bad short text detection.

[0067] The above description is only a preferred specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily conceived by any technician familiar with the technical field within the technical scope disclosed by the present invention should be covered within the protection scope of the present invention.

Claims

1. A BERT-based network bad short text detection method, characterized in that: The following steps are involved: Collecting short texts, annotating the short texts, dividing the annotated short texts into a test data set and a training data set, training a BERT model according to the test data set and the training data set, and obtaining a BERT model based on bad short text detection; Vectorize the short text to be detected and its corresponding additional information to obtain an input vector, input the input vector into the BERT model based on bad short text detection, encode the input vector into a hidden state, obtain the attention weight of the hidden state, obtain the semantic representation of the corresponding hidden state according to the hidden state and its attention weight, and obtain the bad short text label according to the semantic representation of the hidden state; Vectorize the bad short text label, the short text to be detected and the corresponding additional information to obtain an input vector, input the input vector into the BERT model based on bad short text detection, encode the input vector into a hidden state, obtain the attention weight of the hidden state, obtain the corresponding semantic representation of the hidden state according to the hidden state and its attention weight, and identify the type of the bad short text according to the semantic representation of the hidden state; The method of obtaining the attention weight of the hidden state includes obtaining the attention weight of the hidden state using the attention weight calculation formula, wherein the attention weight calculation formula is: represents the relationship scoring function, , represents the hyperbolic tangent activation function, and represents the parameters of the model, , are hidden states and topic features respectively, is the attention weight; According to the hidden state and its attention weight, a semantic representation of the hidden state is obtained, specifically including obtaining the semantic representation of the hidden state using a semantic representation formula, wherein the semantic representation formula is .

2. The BERT-based network bad short text detection method according to claim 1, characterized in that: The short texts are annotated, and the annotated short texts are divided into a test data set and a training data set. The BERT model is trained according to the test data set and the training data set, specifically including annotating the short texts as bad short texts or normal short texts, annotating the bad short texts as different types of bad short texts, dividing the annotated short texts into a test data set and a training data set, and training the BERT model using the test data set, the training data set and additional information of the short texts.

3. The BERT-based network bad short text detection method according to claim 1, characterized in that: The BERT model is trained using the test data set, the training data set, and the additional information of the short text. Specifically, the BERT model is trained using the test data set, the training data set, and the additional information of the short text, using Gelu as the activation function, using the Adam optimizer, and using the cross entropy loss function. The cross entropy loss function is in, represents the true label of the short text dataset, represents the label predicted by the model, Indicates the number of tags, Represents the number of short text datasets.

4. The BERT-based network bad short text detection method according to claim 1, characterized in that: According to the semantic representation of the hidden state, the bad short text is identified, specifically including: connecting the short text represented by [CLS] with the semantic representation of all hidden states to form a vector R for classification, inputting the vector R into a fully connected layer, and obtaining the bad short text label.

5. A BERT-based network bad short text detection device, characterized in that: The method comprises a processor and a memory, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the method for detecting bad short text on the network based on BERT as described in any one of claims 1 to 4 is implemented.

6. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by the processor, the BERT-based network bad short text detection method as described in any one of claims 1 to 4 is implemented.