Text classification method and device based on CNN-BiLSTM / BiGRU hybrid combination model
Through the CNN-BiLSTM/BiGRU hybrid combination model and block processing technology, combined with convolution and attention mechanisms, the accuracy and speed problems in text classification are solved, and efficient classification of texts of different lengths is achieved, which is suitable for various industries. Fast classification of Chinese text messages.
Patent Information
- Application Number
- CN202011487891.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-16
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2040-12-16
AI Technical Summary
It is difficult for existing text classification models to achieve both high accuracy and fast training speed. Especially when processing text data of different lengths, there are problems with classification efficiency and accuracy.
A text classification method based on the CNN-BiLSTM/BiGRU hybrid combination model is adopted, and the text length value is obtained to determine whether to perform content segmentation processing, and the CNN-BiLSTM/BiGRU and CNN-BiLSTM/CNN hybrid models are used for classification respectively. Combining convolution processing and attention mechanism to extract local and global features.
It achieves accurate classification of texts of different lengths, improves the classification accuracy and speed of the model, is suitable for rapid classification of text information in various industries, and reduces the training time and resource consumption of the model.
Smart Images

Figure CN112487191B
Abstract
Description
Technical Field
[0001] The present application relates to the field of machine learning technology, and in particular to a text classification method and device based on a CNN-BiLSTM / BiGRU hybrid combination model. Background Art
[0002] Nowadays, with the development of information technology, the amount of text information data in various industries is growing rapidly. These data contain rich information and have great potential value, but there are still problems of disorder. How to mine accurate and applicable data from them has become an urgent problem to be solved in the research of industry big data. Text classification, as one of the key technologies to solve this problem, helps to better manage and mine text information by standardizing and classifying industry text data, thereby promoting the mining and utilization of industry information and promoting industry development. In recent years, researchers have made some progress in the study of text classification, but there are still problems with accuracy and classification speed.
[0003] After a large number of applications of related technologies, such as Naive Bayes, Support Vector Machine, K Nearest Neighbor, etc., in order to further improve the accuracy of text classification models, researchers began to try deep learning algorithms that have been very successful in many fields in recent years. Today, the use of neural networks for text classification research has gradually become a hot topic. Currently, the most commonly used neural networks include Convolution Neural Network (CNN) and Recurrent Neural Network (RNN).
[0004] However, in the related technologies, it is not possible to take into account both text classification accuracy and training speed at the same time. Therefore, how to achieve a high text classification accuracy while ensuring a high training speed has become a key task for researchers in text classification today. Summary of the invention
[0005] The present application aims to solve one of the technical problems in the related art at least to some extent.
[0006] To this end, the first purpose of this application is to propose a text classification method based on a CNN-BiLSTM / BiGRU hybrid combination model to achieve accurate and rapid classification of text information in various industries, further improving the classification accuracy of the model while increasing the classification speed.
[0007] The second purpose of this application is to propose a text classification device based on the CNN-BiLSTM / BiGRU hybrid combination model.
[0008] To achieve the above objectives, the first embodiment of the present application proposes a text classification method based on a CNN-BiLSTM / BiGRU hybrid combination model, including:
[0009] Obtaining the text to be processed, and obtaining the text length value of the text to be processed;
[0010] When the text length value is less than a preset text length threshold, classifying the text to be processed based on the CNN-BiLSTM / BiGRU hybrid combination model to obtain a first classification result;
[0011] When the text length value is greater than or equal to a preset text length threshold, the text to be processed is divided into content blocks and then input into the CNN-BiLSTM / BiGRU hybrid combination model and the (CNN-BiLSTM) / CNN hybrid text classification model for processing and comprehensive calculation to obtain a second classification result.
[0012] The text classification method based on the CNN-BiLSTM / BiGRU hybrid combination model of the embodiment of the present application obtains the text to be processed and obtains the text length value of the text to be processed; when the text length value is less than the preset text length threshold, the text to be processed is classified based on the CNN-BiLSTM / BiGRU hybrid combination model to obtain the first classification result; when the text length value is greater than or equal to the preset text length threshold, the text to be processed is processed into content blocks and then input into the CNN-BiLSTM / BiGRU hybrid combination model and the (CNN-BiLSTM) / CNN hybrid text classification model for processing and comprehensive calculation to obtain the second classification result. Thus, accurate and rapid classification of text information in various industries is achieved, and the classification speed is improved while further improving the classification accuracy of the model.
[0013] In one embodiment of the present application, the text classification of the to-be-processed text based on the CNN-BiLSTM / BiGRU hybrid combination model to obtain a first classification result includes:
[0014] Extracting a text feature vector of the text to be processed;
[0015] Performing convolution processing on the text feature vector to obtain multiple local feature vectors of the text to be processed;
[0016] Sampling the multiple local feature vectors to obtain multiple key feature vectors of the text to be processed;
[0017] After the multiple key feature vectors are pruned, they are concatenated and respectively input into the BiLSTM network layer and the BiGRU network layer for processing to obtain a first output feature vector and a second output feature vector;
[0018] The first output feature vector and the second output feature vector are fused to obtain a fused feature vector, which is input into a classifier for processing to obtain the first classification result.
[0019] In one embodiment of the present application, when performing convolution processing, convolution kernel sizes of different sizes are set to extract word features of different lengths to obtain the multiple local feature vectors.
[0020] In one embodiment of the present application, the (CNN-BiLSTM) / CNN hybrid text classification model processes part of the text to be processed after content segmentation, including:
[0021] Extracting a text feature vector of the portion of text to be processed;
[0022] Performing convolution processing on the text feature vector to obtain multiple local feature vectors of the part of the text to be processed;
[0023] Sampling the multiple local feature vectors to obtain multiple key feature vectors of the text to be processed;
[0024] After the plurality of key feature vectors are pruned, they are input into the BiLSTM network layer for processing to obtain output feature vectors;
[0025] The output feature vector and the feature vector after the multiple key features are deleted are fused, and the fused feature vector is obtained and input into the classifier for processing to obtain the second sub-classification result.
[0026] In one embodiment of the present application, the hybrid combination model includes a CNN network layer, a BiLSTM network layer and a BiGRU network layer;
[0027] The CNN network layer is connected to the BiLSTM network layer and the BiGRU network layer respectively, and the BiLSTM network layer and the BiGRU network are connected to the classifier respectively; or,
[0028] The CNN network layer is connected to the BiLSTM network layer, and the two as a whole are connected to the classifier respectively with the CNN network layer.
[0029] To achieve the above-mentioned purpose, the second embodiment of the present application proposes a text classification device based on a CNN-BiLSTM / BiGRU hybrid combination model, comprising:
[0030] An acquisition module, used for acquiring the text to be processed and acquiring the text length value of the text to be processed;
[0031] A first processing module is used to classify the text to be processed based on the CNN-BiLSTM / BiGRU hybrid combination model to obtain a first classification result when the text length value is less than a preset text length threshold;
[0032] A block division module, used for performing content block processing on the text to be processed to obtain a first sub-text to be processed and a second sub-text to be processed when the text length value is greater than or equal to a preset text length threshold;
[0033] A second processing module is used to input the second sub-text to be processed into a (CNN-BiLSTM) / CNN hybrid text classification model for processing to obtain a second classification sub-result;
[0034] The third processing module is used to input the first sub-text to be processed into the CNN-BiLSTM / BiGRU hybrid combination model to obtain a first classification sub-result, and perform comprehensive calculation on the first classification sub-result and the second classification sub-result to obtain a second classification result.
[0035] The text classification device based on the CNN-BiLSTM / BiGRU hybrid combination model of the embodiment of the present application obtains the text to be processed and obtains the text length value of the text to be processed; when the text length value is less than the preset text length threshold, the text to be processed is classified based on the CNN-BiLSTM / BiGRU hybrid combination model to obtain the first classification result; when the text length value is greater than or equal to the preset text length threshold, the text to be processed is processed into content blocks and then input into the CNN-BiLSTM / BiGRU hybrid combination model and the (CNN-BiLSTM) / CNN hybrid text classification model for processing and comprehensive calculation to obtain the second classification result. Thus, accurate and rapid classification of text information in various industries is achieved, and the classification speed is improved while further improving the classification accuracy of the model.
[0036] In one embodiment of the present application, the first processing module is specifically used to:
[0037] Extracting a text feature vector of the text to be processed;
[0038] Performing convolution processing on the text feature vector to obtain multiple local feature vectors of the text to be processed;
[0039] Sampling the multiple local feature vectors to obtain multiple key feature vectors of the text to be processed;
[0040] After the multiple key feature vectors are pruned, they are concatenated and respectively input into the BiLSTM network layer and the BiGRU network layer for processing to obtain a first output feature vector and a second output feature vector;
[0041] The first output feature vector and the second output feature vector are fused to obtain a fused feature vector, which is input into a classifier for processing to obtain the first classification result.
[0042] In one embodiment of the present application, when performing convolution processing, convolution kernel sizes of different sizes are set to extract word features of different lengths to obtain the multiple local feature vectors.
[0043] In one embodiment of the present application, the second processing module is specifically used to:
[0044] Extracting a text feature vector of the portion of text to be processed;
[0045] Performing convolution processing on the text feature vector to obtain multiple local feature vectors of the part of the text to be processed;
[0046] Sampling the multiple local feature vectors to obtain multiple key feature vectors of the text to be processed;
[0047] After the plurality of key feature vectors are pruned, they are input into the BiLSTM network layer for processing to obtain output feature vectors;
[0048] The output feature vector and the feature vector after the multiple key features are deleted are fused, and the fused feature vector is obtained and input into the classifier for processing to obtain the second sub-classification result.
[0049] In one embodiment of the present application, the hybrid combination model includes a CNN network layer, a BiLSTM network layer and a BiGRU network layer;
[0050] The CNN network layer is connected to the BiLSTM network layer and the BiGRU network layer respectively, and the BiLSTM network layer and the BiGRU network are connected to the classifier respectively; or,
[0051] The CNN network layer is connected to the BiLSTM network layer, and the two as a whole are connected to the classifier respectively with the CNN network layer.
[0052] Additional aspects and advantages of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:
[0054] Figure 1 A flowchart of a text classification method based on a CNN-BiLSTM / BiGRU hybrid combination model provided in Example 1 of the present application;
[0055] Figure 2 This is an example diagram of the LSTM model structure provided in the embodiment of the present application;
[0056] Figure 3 This is an example diagram of the GRU model structure provided in the embodiments of the present application;
[0057] Figure 4 A schematic diagram of the BiLSTM / BiGRU model structure provided in the embodiment of the present application;
[0058] Figure 5 The model structure of the convolutional neural network (CNN) provided in the embodiment of the present application when applied to text classification;
[0059] Figure 6 A schematic diagram of the CBLGA model structure provided in the embodiment of the present application;
[0060] Figure 7 A schematic diagram of the CBCA model structure provided in the embodiment of the present application;
[0061] Figure 8 A flowchart of the corresponding processing for texts of different lengths provided in the embodiment of the present application;
[0062] Fig. 9 An example diagram showing part of the data in the data set provided in the embodiments of the present application;
[0063] Fig.10 A structural schematic diagram of a text classification device based on a CNN-BiLSTM / BiGRU hybrid combination model provided in an embodiment of the present application. DETAILED DESCRIPTION
[0064] Embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present application, and should not be construed as limiting the present application.
[0065] The following describes a text classification method and device based on a CNN-BiLSTM / BiGRU hybrid combination model according to an embodiment of the present application with reference to the accompanying drawings.
[0066] Figure 1 A flowchart of a text classification method based on a CNN-BiLSTM / BiGRU hybrid combination model provided in Example 1 of the present application.
[0067] like Figure 1 As shown, the text classification method based on the CNN-BiLSTM / BiGRU hybrid combination model includes the following steps:
[0068] Step 101, obtaining the text to be processed, and obtaining the text length value of the text to be processed.
[0069] Step 102: When the text length value is less than a preset text length threshold, the text to be processed is classified based on the CNN-BiLSTM / BiGRU hybrid combination model to obtain a first classification result.
[0070] Step 103, when the text length value is greater than or equal to the preset text length threshold, the text to be processed is divided into content blocks and then input into the CNN-BiLSTM / BiGRU hybrid combination model and the (CNN-BiLSTM) / CNN hybrid text classification model for processing and comprehensive calculation to obtain a second classification result.
[0071] In an embodiment of the present application, the hybrid combination model includes a CNN network layer, a BiLSTM network layer and a BiGRU network layer; the CNN network layer is connected to the BiLSTM network layer and the BiGRU network layer, respectively, and the BiLSTM network layer and the BiGRU network are connected to the classifier, respectively; or, the CNN network layer and the BiLSTM network layer, and the CNN network layer and the BiLSTM network layer are connected to the classifier, respectively.
[0072] Specifically, the present application utilizes BiLSTM and BiGRU to replace traditional RNN and LSTM. BiLSTM and BiGRU solve the problem of gradient vanishing or gradient exploding in traditional RNN. At the same time, considering that the semantics of a word is related to its previous and subsequent information, BiLSTM and BiGRU can fully consider the meaning of the word in the context, overcoming the drawback that LSTM can only consider unidirectional information of the word.
[0073] Specifically, a CNN-BiLSTM / BiGRU hybrid text classification model based on Attention was constructed, referred to as the CBLGA model. That is, CNN networks with different convolution window sizes are first connected in parallel to extract local features of various text vectors, and then BiLSTM and BiGRU are used in parallel to ensure that the model can have a good operating effect when facing data sets of different sizes, and BiLSTM and BiGRU are combined to extract global features related to the text context. By fusing CNN and BiLSTM / BiGRU, the advantages of CNN in extracting local features can be utilized, while the advantages of BiLSTM / BiGRU in taking into account the global features of text sequences can be utilized.
[0074] Specifically, a (CNN-BiLSTM) / CNN hybrid text classification model based on Attention, referred to as the CBCA model, was constructed. That is, the CNN network is first used to extract the local features of the text vector, and then the output of the CNN is divided into two parts, one of which is input into the BiLSTM network to extract the global features related to the text context. The other part is directly fused with the output of the BiLSTM network, which not only retains the local features of the text extracted by the CNN, but also utilizes the global features of the text sequence extracted by the BiLSTM network.
[0075] That is to say, the preprocessing methods for the corresponding preprocessing and subsequent classification work are carried out for texts of different lengths. That is, for short texts, a hybrid model is used for classification processing. At this time, the selection of the model focuses on the accuracy of classification; according to the structural characteristics of the model described above, the CBLGA model can be used to achieve a high accuracy while ensuring the training speed. For longer texts, two hybrid models are used for classification processing in a "division of labor". At this time, considering the content distribution characteristics of long texts, in the key content part, the selection of the model focuses on the accuracy of classification, and the CBLGA model is used for this part; and in the detailed content part of the longer text, the selection of the model focuses on the speed of classification, and the CBCA model is used for this part. The combination of the two models can improve the accuracy while ensuring a certain degree of improvement in the training speed even in the face of long texts.
[0076] In order to make the above structure more clear to those skilled in the art, it is described in detail below with reference to the relevant drawings.
[0077] Specifically, the long short-term memory neural network (LSTM) is a time series convolutional neural network derived from the recurrent neural network. By introducing the gate function, it can mine the time series change regularity words such as relatively long intervals and delays in the time series. Its structure is as follows Figure 2 shown.
[0078] like Figure 2As shown, LSTM has a hidden state h at time t (t) and cell state C (t) Its gate control structure generally includes three types: input gate, forget gate and output gate. At this time, the process at each sequence index position is:
[0079] (1) The input gate processes the input of the current sequence position. It consists of two parts. The cell state is updated by multiplying the results of the two parts. The formula is:
[0080] i (t) =σ(W ih h (t-1) +W ix x (t) +b i ) (1)
[0081] a (t) =tanh(W ah h (t-1) +W ax x (t) +b a ) (2)
[0082] (2) The forget gate controls the probability of forgetting the hidden cell state of the previous layer. The formula is:
[0083] f (t) =σ(W fh h (t-1) +W fx x (t) +b f ) (3)
[0084] (3) Cell state C (t) Depending on the results of the previous forget gate and input gate, the formula is:
[0085] C (t) =C (t-1) f(t)+i (t) a (t) (4)
[0086] (4) Update the output of the output gate, the formula is:
[0087] o (t) =σ(W oh h (t-1) +W ox x (t) +b o ) (5)
[0088] h (t) =o (t) tanh(C (t) ) (6)
[0089] (5) Add a softmax layer (with weight Ws and bias bs) on top of LSTM to extract the final output. The formula is:
[0090] y (t) =softmax(W s h (t) +b s ) (7)
[0091] As an improvement of RNN, LSTM can effectively avoid the gradient vanishing problem, but its model structure is more complex, takes longer to run, and occupies more resources, especially for small data sets, the results are not ideal.
[0092] As a variant of LSTM, the gated recurrent unit (GRU) simplifies the input gate, output gate, and memory gate in LSTM into an update gate and a reset gate, such as Figure 3 As shown in the figure, while inheriting the natural language processing ability of LSTM, fewer parameters greatly reduce the amount of calculation.
[0093] The process of the GRU neural network at each sequence index position is:
[0094] (1) The input gate and the forget gate are combined into an update gate to control the state information of the previous moment to be substituted into the current state, thereby obtaining the long-term dependency relationship in the time series data. The formula is:
[0095] z (t) =σ(W zx x (t) +W zh h (t-1) +b z ) (8)
[0096] (2) Introducing a reset gate to control the information of the previous moment with a certain probability is conducive to obtaining the short-term dependency in the time series data. The formula is:
[0097] r (t) =σ(W rx x (t) +W rh h (t-1) +b r ) (9)
[0098] (3) The candidate hidden state uses a reset gate to control the hidden state, the formula is:
[0099]
[0100] (4) Implicit state h (t) Use the update gate z (t)To the previous hidden state h (t-1) and candidate hidden states To update, the formula is:
[0101]
[0102] (5) Add a softmax layer (with weight Ws and bias bs) on top of the GRU, with the formula:
[0103] y (t) =softmax(W s h (t) +b s ) (12)
[0104] In the unidirectional LSTM / GRU neural network structure, the state is always output from the front to the back. Although the LSTM / GRU network solves the problem of gradient vanishing or gradient exploding in RNN, they can only learn the information before the current word and cannot use the information after the current word. Since the semantics of a word is not only related to the previous historical information, but also closely related to the information after the current word, this application uses BiLSTM / BiGRU instead of LSTM / GRU. The main structure of the model is as follows: Figure 4 As shown in the figure (here a main structure is used to describe the BiLSTM / BiGRU model), this not only solves the problem of gradient vanishing or gradient exploding, but also fully considers the contextual semantic information of the current word. At each moment when the model processes the text, the input of the model will pass through two LSTM / GRU network structures in opposite directions at the same time, so the output of the model is jointly determined by these two unidirectional LSTM / GRU structures. Therefore, after the sentence matrix is learned and processed using the BiLSTM / BiGRU neural network model, the text features obtained are global and fully consider the contextual information of the word in the text.
[0105] In an embodiment of the present application, text classification is performed on the text to be processed based on the CNN-BiLSTM / BiGRU hybrid combination model to obtain a first classification result, including: extracting a text feature vector of the text to be processed; performing convolution processing on the text feature vector to obtain multiple local feature vectors of the text to be processed; sampling multiple local feature vectors to obtain multiple key feature vectors of the text to be processed; deleting multiple key feature vectors and then splicing them into the BiLSTM network layer and the BiGRU network layer for processing, respectively, to obtain a first output feature vector and a second output feature vector; fusing the first output feature vector and the second output feature vector to obtain a fused feature vector and input it into the classifier for processing to obtain a first classification result.
[0106] In the embodiment of the present application, when performing convolution processing, convolution kernel sizes of different sizes are set to extract word features of different lengths to obtain multiple local feature vectors.
[0107] Specifically, the hybrid text classification model constructed in this application is a CNN-BiLSTM / BiGRU (referred to as CBLGA model) based on Attention, that is, firstly, CNN networks with different convolution window sizes are connected in parallel to extract local features of various text vectors, and then BiLSTM and BiGRU are used in parallel to ensure that the model can have a good operating effect when facing data sets of different sizes, and the global features related to the text context are extracted by combining BiLSTM and BiGRU. By fusing CNN and BiLSTM / BiGRU, the advantages of CNN in extracting local features can be utilized, and the advantages of BiLSTM / BiGRU in taking into account the global features of text sequences can be utilized.
[0108] In practical applications, in industry text classification applications, due to the difference in the importance of features in short subsequences of long time sequences (important significant features often contain more information and have a greater impact on the trend of actual demand), in order to achieve efficient allocation of information processing resources, this application introduces an attention mechanism in the model. In the application of this application, the Attention mechanism is implemented by retaining the intermediate output results of the BiLSTM / BiGRU encoder input sequence, and then inputting it into a model for selective training and learning, and associating the output sequence with it when the model outputs. The generation probability of each item in the output sequence depends on which items are selected in the input sequence. Although this will increase the computational burden of the model, it will form a more targeted and better performing model. The basic concept of the attention mechanism relies on being able to access all parts of the input sentence when reaching the output. This allows the model to give different attention to different parts of the sentence, so that dependencies can be derived. Therefore, this application uses an attention mechanism to extract the salient features of the text sequence.
[0109] In addition, this application introduces a convolutional neural network (CNN) when constructing the CBLGA model. The convolutional neural network model is used in the structure of text classification. Figure 5As shown. That is, after the text is preprocessed by word segmentation, the word vector is obtained through training, and then mapped into a two-dimensional sentence matrix. Then, multiple convolution kernels of size 1*m, 3*m, and 5*m are used to convolve the sentence matrix to extract the feature vector. The next step is the downsampling operation, which can filter out strong features and reduce the number of parameters to prevent overfitting. After downsampling, the connection is performed to form a feature vector, and then the classifier outputs the binary classification result. In other words, CNN is a model constructed by combining the convolution layer, the pooling layer, and the fully connected output layer. With the advantages of the convolution operation, the supervised learning of the multi-layer network structure can be realized, which reduces the number of parameters of the entire neural network model, thereby improving the performance of model training.
[0110] The convolution performed on the input layer can be regarded as a local connection. Each local input area corresponds to its own output neuron. By designing a convolution kernel of appropriate size, the information in the receptive field is convolved to abstractly express the original data. When the input data X is used, the feature map C of the convolution layer can be expressed as follows:
[0111]
[0112] In the formula, is the convolution operation; W is the weight vector of the convolution kernel; b represents the offset; f() is the activation function, which is the Relu function in this application. In addition, sigmoid, tanh, etc. can also be used.
[0113] Finally, the first hybrid text classification model constructed in this application is as follows Figure 6As shown, the feature fusion model of the present application is composed of two combinations of convolutional neural network parallel combination and BiLSTM / BiGRU parallel combination, which can be called CNN-BiLSTM / BiGRU-Attention (abbreviated as CBLGA) hybrid model, in which the first layer of the convolutional neural network part is a word embedding layer, and the sentence matrix of the word embedding layer is used as input, and then enters the second layer for convolution operation to extract local features. When performing convolution operation, different sizes of convolution kernel sizes are set to realize the extraction of word features of different lengths. Here, the sizes of three convolution kernels are set to 1, 3, and 5, respectively, and the number is 256. The stride size is set to 2, and the padding is the same, that is, the input is padded so that the output has the same length as the original input. Convolution operation is performed with such a structure to extract local features of multiple feature word vectors in the text; the third layer performs downsampling operation, and the maximum sampling method is used here to extract key features, discard redundant features, and generate feature vectors of fixed dimensions at the same time. Next, we enter the fourth layer, which is the respective Dropout layer, and temporarily discard the neural network unit from the network with a probability of 20% to prevent overfitting. The features output by the three Dropout layers are concatenated as part of the input features of the BiLSTM / BiGRU parallel combination.
[0114] The first layer of the BiLSTM / BiGRU part is a word embedding layer, which takes the sentence matrix of the embedding layer as input, and the dimension of each word vector is set to 768 dimensions; the second and third layers are hidden layers, and the hidden layer size is 64. The current input is related to the previous and next sequences. The input sequence is input into the model from two directions respectively, and the historical information and future information of the two directions are saved through the hidden layer. Next, the features of the BiLSTM and BiGRU outputs are fused, and the fused features are saved in the output. The attention mechanism is introduced and then used as the input of the fully connected layer, and finally input into the softmax classifier to output the classification result.
[0115] In an embodiment of the present application, the (CNN-BiLSTM) / CNN hybrid text classification model processes part of the text to be processed after content segmentation, including: extracting text feature vectors of part of the text to be processed; performing convolution processing on the text feature vector to obtain multiple local feature vectors of the part of the text to be processed; sampling multiple local feature vectors to obtain multiple key feature vectors of the text to be processed; deleting multiple key feature vectors and inputting them into the BiLSTM network layer for processing to obtain an output feature vector; fusing the output feature vector with the feature vector after deleting multiple key features, obtaining the fused feature vector and inputting it into the classifier for processing to obtain a second sub-classification result.
[0116] Specifically, the hybrid text classification model of the embodiment of the present application is a (CNN-BiLSTM) / CNN hybrid text classification model based on Attention (CBCA model for short), and the model structure is as follows: Figure 7 As shown. The feature fusion model of the present application is composed of a convolutional neural network and a BiLSTM connected in series and then connected in parallel with a convolutional neural network, wherein the first layer of the convolutional neural network is a word embedding layer, which takes the sentence matrix of the word embedding layer as input, and then enters the second layer for convolution operation to extract local features. The size of the convolution kernel set here is 3, the number is 256, the stride size is set to 2, and the padding is same, that is, the input is padded so that the output has the same length as the original input. The convolution operation is performed with such a structure to extract the local features of various feature word vectors in the text; the third layer performs a downsampling operation, and the maximum sampling method is used here to extract key features, discard redundant features, and generate feature vectors of fixed dimensions. Next, enter the fourth layer, the Dropout layer, and temporarily discard the neural network unit from the network with a probability of 20%, which can improve the independence between feature maps and prevent overfitting. Next, the features output by the Dropout layer are copied into two copies, one of which is used as part of the input features of the BiLSTM network, and the other is directly fused with the output of the BiLSTM.
[0117] That is, firstly, the CNN network is used to extract the local features of the text vector, and then the output of the CNN is divided into two parts, one of which is input into the BiLSTM network to extract the global features related to the text context. The other part is directly fused with the output of the BiLSTM network, which not only retains the local features of the text extracted by the CNN, but also utilizes the global features of the text sequence extracted by the BiLSTM network. The text classification principle of CNN is as described above, so it will not be repeated here.
[0118] For example, this application has established a set of preprocessing methods for texts of different lengths and subsequent classification work. The main process structure is as follows: Figure 8 As shown in the figure, the text length of 300 is used as the dividing line. When the text length is less than 300, it is regarded as a short text. At this time, a hybrid model is used for classification processing, and the selection of the model focuses on the accuracy of classification. According to the structural characteristics of the model described in the previous article, the CBLGA model is selected at this time to achieve a very high accuracy while ensuring the training speed.
[0119] Specifically, when the length of a text is greater than 300, it is considered a long text. At this time, two hybrid models are used to perform classification processing by "division of labor". Taking into account the content distribution characteristics of long texts, that is, the key features of industry texts are often concentrated at the beginning and end of the text, while the text in the middle of the text mainly plays an auxiliary interpretation role. Therefore, in the feature mining process of industry text sequences, this application focuses on the starting and ending positions of the text sequence, and uses a model that pays more attention to accuracy to classify the above two areas; the processing process for the middle part can be relatively weakened. This part is longer and most of it is detailed content. If a model that pays attention to detailed structure and has high accuracy is used for long texts, the training time and classification speed of the model will be reduced, and the computer operation burden will be increased. Therefore, this solution uses a CBCA model that pays more attention to classification efficiency to classify the middle part of the text; the two models work together to improve the classification efficiency while grasping the key information and global features of the text.
[0120] This technical solution introduces CNN network for feature extraction in the industry text classification technology, and proposes two new hybrid neural network models - CNN-BiLSTM / BiGRU-Attention (referred to as CBLGA) and Attention-based (CNN-BiLSTM) / CNN hybrid text classification model (referred to as CBCA model). For short text data, compared with the LSTM and GRU classification models with simpler structures, the new model has obvious improvements in accuracy and loss rate without significantly increasing the iteration time; compared with the BiGRU classification model, the new model not only has obvious improvements in accuracy and loss rate, but also greatly shortens the iteration time; compared with the most widely used hybrid model of BiLSTM neural network and attention, the new model can reduce the loss rate while improving the accuracy, and significantly reduces the training time of the model. It shows that the model can not only use convolutional neural network to effectively extract local features of text, but also use BiLSTM / BiGRU to take into account the global features of texts of different lengths, fully consider the contextual semantic information of words, and ensure the training speed of the model while improving the classification accuracy.
[0121] For long text data, this technical solution proposes an adaptive processing method for long texts - integrating CBLGA and CBCA models to process different positions of long texts accordingly. The proposal of this solution not only greatly improves the efficiency of text classification, but also solves the problem of the classification model being allergic to the length of the input text when it is established, that is, the processable text length len(txt) needs to be given when the model is established. Under a single model structure, when len(txt) is too large, it undoubtedly increases the training and processing burden of the model, occupies too many resources, and easily causes resource waste; and when len(txt) is too small, it undoubtedly reduces the usable scope and processing capacity of the model. When facing long text input, although it can also be processed, due to the automatic limitation of the model, only part of the text enters the model, which can easily cause "half-understanding" and the classification result is no longer accurate. The adaptive processing method for long texts proposed in this technical solution solves this problem. It provides a valuable reference solution for various industries with data classification needs.
[0122] As an example of a scenario, in order to verify the application effect of the model in the industry, this application selected two types of industry data, "parallel mechanism" and "production line" as data sets on CNKI, and collected a total of 10,000 data. After data cleaning, some missing indicators such as no labels and no summaries were filtered out, and finally 9,814 data were left, including 4,983 "parallel mechanism" and 4,831 "production line". The order of the original data set was randomly shuffled, and 10 data items were randomly selected. Fig. 9 As shown in the figure, "cat" represents the text category, "review" represents the text introduction, and "cat_id" represents the category code. Then it is divided into training set, validation set and test set in a ratio of 8:1:1, which are used for model training, model validation and model testing respectively.
[0123] The experimental environment of this application is as follows: the operating system is Windows 10, the CPU is Intel Core i5-6300, the GPU is GeForce GTX1050Ti, the graphics card driver is Nvidia GeForce GTX 950M (2G), the memory size is 12GB, the Keras deep learning framework is used, the underlying layer is Tensor Flow1.14.0, it is implemented in Python language programming, and the development tool used is Jupyter-notebook.
[0124] The experiment sets the number of iterations to 5, and uses accuracy, loss rate, and iteration time as the evaluation criteria of the experiment. Assuming the total number of samples is N, and the number of correctly classified samples is n, the accuracy is:
[0125]
[0126] This experimental model can be regarded as a three-layer network structure, including a text vector input layer, a hidden layer, and a text classification layer. There are many hyperparameters in the model that need to be set and adjusted. This application has conducted multiple experiments. After each iteration, the hyperparameters are set and adjusted according to the accuracy and loss rate of the experiment. After multiple iterative experiments, the hyperparameters set by the model are shown in Table 1.
[0127] Table 1 Hyperparameters of each neural network
[0128]
[0129] 2) Experimental comparison and result analysis
[0130] The CNN-BiLSTM / BiGRU-Attention (CBLGA) model and the Attention-based (CNN-BiLSTM) / CNN hybrid text classification model (CBCA model) proposed in this paper are compared with the following three common models.
[0131] (1) GRU. It was mainly applied by Cho et al. and can be seen as a further improvement of LSTM. It has fewer parameters and theoretically has better convergence effect.
[0132] (2) BiGRU. It was mainly proposed by Xuan Zhenfeng and others. With the global feature acquisition capability of the bidirectional GRU network, it can quickly extract specific text information.
[0133] (3) CNN-BiLSTM-Attention. As a model of text classification using convolutional neural network and recurrent neural network models, many researchers have used CNN-BiLSTM-Attention for text classification. It uses CNN and BiLSTM to extract text features, then fuses them and introduces the attention mechanism, which has achieved good results.
[0134] (4) All the loss functions used in this experiment are "cross entropy" loss functions. When selecting the optimizer, SGD, AdaGrad, RMSProp and Adam optimizers are considered. Among them, the Adam optimizer combines the advantages of the two optimization algorithms, AdaGrad and RMSProp, and comprehensively considers the first moment estimation (First Moment Estimation, i.e. the mean of the gradient) and the second moment estimation (Second Moment Estimation, i.e. the uncentered variance of the gradient), and continuously iterates and updates the network parameters. It is very suitable for scenarios with large-scale data and parameters. Therefore, this scheme selects Adam as the optimization function for each model.
[0135] (5) In addition, the number of training "Epochs" for each model is 5, the activation function is the "Relu" function, and the downsampling method is the "Maxpooling" method. In the experiment, the highest accuracy on the test set during the 5 iterations is selected as the accuracy of the model, and the corresponding loss rate of the highest accuracy of the test set is the loss rate of the model. The average time of 5 iterations is taken as the iteration time of the model, recorded as time. The comparison of the results of each model and the new hybrid model proposed in this scheme is shown in Table 2.
[0136] Table 2 Comparison of the results of each model with the new hybrid model proposed in this paper
[0137]
[0138] As can be seen from Table 2, compared with the single GRU model, the BiGRU model not only has a higher classification accuracy, but also has a greatly reduced loss rate. However, due to the more complex model structure, its training time is longer. Furthermore, the CNN-BiGRU-Attention model that integrates the CNN model and the attention mechanism performs better in terms of accuracy, loss rate and training speed, which shows the effectiveness of the model. As for the new model CBLGA proposed in this technical solution, even compared with the CNN-BiGRU-Attention model that performs well in all aspects, the new model CBLGA still shows higher accuracy, lower loss rate and faster training speed. Except that the training time is slightly longer than that of the single-structure GRU, the new model CBLGA performs better than the other three typical text classification models in various indicators, which strongly illustrates the power of the new model CBLGA proposed in this solution, that is, it effectively improves the accuracy of text classification and reduces the loss rate while ensuring the training speed. In addition, it can be seen that although the accuracy and loss rate of the new model CBCA are slightly worse than those of the new model CBLGA, its training speed is greatly improved, and the performance of the new model CBCA in various indicators is better than the first three typical text classification models in the table, which strongly illustrates the power of the new model CBCA proposed in this scheme, that is, it effectively improves the accuracy of text classification and reduces the loss rate while ensuring the training speed.
[0139] In terms of the verification of the adaptive processing method for long texts, this scheme fused the CBLGA and CBCA models to process different positions of the long text accordingly. The results showed higher efficiency and accuracy, which shows that the proposed scheme is very effective in solving the problem of the classification model's allergy to the length of the input text when it is established.
[0140] The text classification method based on the CNN-BiLSTM / BiGRU hybrid combination model of the embodiment of the present application obtains the text to be processed and obtains the text length value of the text to be processed; when the text length value is less than the preset text length threshold, the text to be processed is classified based on the CNN-BiLSTM / BiGRU hybrid combination model to obtain the first classification result; when the text length value is greater than or equal to the preset text length threshold, the text to be processed is processed into content blocks and then input into the CNN-BiLSTM / BiGRU hybrid combination model and the CNN-BiLSTM) / CNN hybrid text classification model for processing and comprehensive calculation to obtain the second classification result. Thus, accurate and rapid classification of text information in various industries is achieved, and the classification speed is improved while further improving the classification accuracy of the model.
[0141] In order to implement the above embodiment, the present application also proposes a text classification device based on the CNN-BiLSTM / BiGRU hybrid combination model.
[0142] Fig.10 A structural schematic diagram of a text classification device based on a CNN-BiLSTM / BiGRU hybrid combination model provided in an embodiment of the present application.
[0143] like Fig.10 As shown, the text classification device based on the CNN-BiLSTM / BiGRU hybrid combination model includes: an acquisition module 210, a first processing module 220, a blocking module 230, a second processing module 240 and a third processing module 250.
[0144] The acquisition module 210 is used to acquire the text to be processed and acquire the text length value of the text to be processed.
[0145] The first processing module 220 is used to perform text classification on the text to be processed based on the CNN-BiLSTM / BiGRU hybrid combination model to obtain a first classification result when the text length value is less than a preset text length threshold.
[0146] The block division module 230 is used to perform content block processing on the text to be processed when the text length value is greater than or equal to a preset text length threshold, and obtain a first sub-text to be processed and a second sub-text to be processed.
[0147] The second processing module 240 is used to input the second sub-text to be processed into the CNN-BiLSTM) / CNN hybrid text classification model for processing to obtain a second classification sub-result.
[0148] The third processing module 250 is used to input the first sub-text to be processed into the CNN-BiLSTM / BiGRU hybrid combination model to obtain a first classification sub-result, and perform comprehensive calculation on the first classification sub-result and the second classification sub-result to obtain a second classification result.
[0149] In one embodiment of the present application, the first processing module is specifically used to:
[0150] Extracting a text feature vector of the text to be processed;
[0151] Performing convolution processing on the text feature vector to obtain multiple local feature vectors of the text to be processed;
[0152] Sampling the multiple local feature vectors to obtain multiple key feature vectors of the text to be processed;
[0153] After the multiple key feature vectors are pruned, they are concatenated and respectively input into the BiLSTM network layer and the BiGRU network layer for processing to obtain a first output feature vector and a second output feature vector;
[0154] The first output feature vector and the second output feature vector are fused to obtain a fused feature vector, which is input into a classifier for processing to obtain the first classification result.
[0155] In one embodiment of the present application, when performing convolution processing, convolution kernel sizes of different sizes are set to extract word features of different lengths to obtain the multiple local feature vectors.
[0156] In one embodiment of the present application, the second processing module is specifically used to:
[0157] Extracting a text feature vector of the portion of text to be processed;
[0158] Performing convolution processing on the text feature vector to obtain multiple local feature vectors of the part of the text to be processed;
[0159] Sampling the multiple local feature vectors to obtain multiple key feature vectors of the text to be processed;
[0160] After the plurality of key feature vectors are pruned, they are input into the BiLSTM network layer for processing to obtain output feature vectors;
[0161] The output feature vector and the feature vector after the multiple key features are deleted are fused, and the fused feature vector is obtained and input into the classifier for processing to obtain the second sub-classification result.
[0162] In one embodiment of the present application, the hybrid combination model includes a CNN network layer, a BiLSTM network layer and a BiGRU network layer;
[0163] The CNN network layer is connected to the BiLSTM network layer and the BiGRU network layer respectively, and the BiLSTM network layer and the BiGRU network are connected to the classifier respectively; or,
[0164] The CNN network layer is connected to the BiLSTM network layer, and the two as a whole are connected to the classifier respectively with the CNN network layer.
[0165] The text classification device based on the CNN-BiLSTM / BiGRU hybrid combination model of the embodiment of the present application obtains the text to be processed and obtains the text length value of the text to be processed; when the text length value is less than the preset text length threshold, the text to be processed is classified based on the CNN-BiLSTM / BiGRU hybrid combination model to obtain the first classification result; when the text length value is greater than or equal to the preset text length threshold, the text to be processed is processed into content blocks and then input into the CNN-BiLSTM / BiGRU hybrid combination model and the CNN-BiLSTM) / CNN hybrid text classification model for processing and comprehensive calculation to obtain the second classification result. Thus, accurate and fast classification of text information in various industries is achieved, and the classification speed is improved while further improving the classification accuracy of the model.
[0166] It should be noted that the aforementioned explanation of the text classification method embodiment based on the CNN-BiLSTM / BiGRU hybrid combination model is also applicable to the text classification device based on the CNN-BiLSTM / BiGRU hybrid combination model of this embodiment, and will not be repeated here.
[0167] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, without contradiction.
[0168] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In the description of this application, the meaning of "plurality" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined.
[0169] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, fragment or portion of code comprising one or more executable instructions for implementing the steps of a custom logical function or process, and the scope of the preferred embodiments of the present application includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by technicians in the technical field to which the embodiments of the present application belong.
[0170] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute the instructions), or in combination with these instruction execution systems, devices or apparatuses. For the purpose of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in combination with these instruction execution systems, devices or apparatuses. More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection with one or more wires (electronic device), a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), a fiber optic device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium and then editing, interpreting or processing in other suitable ways if necessary, and then stored in a computer memory.
[0171] It should be understood that the various parts of the present application can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0172] A person skilled in the art may understand that all or part of the steps in the method for implementing the above-mentioned embodiment may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, which, when executed, includes one or a combination of the steps of the method embodiment.
[0173] In addition, each functional unit in each embodiment of the present application may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.
[0174] The storage medium mentioned above may be a read-only memory, a magnetic disk or an optical disk, etc. Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limiting the present application. A person of ordinary skill in the art may change, modify, replace and modify the above embodiments within the scope of the present application.
Claims
1. A text classification method based on a CNN-BiLSTM / BiGRU hybrid combination model, characterized in that: include: Obtaining the text to be processed, and obtaining the text length value of the text to be processed; When the text length value is less than a preset text length threshold, classifying the text to be processed based on the CNN-BiLSTM / BiGRU hybrid combination model to obtain a first classification result; When the text length value is greater than or equal to the preset text length threshold, the text to be processed is divided into content blocks and then input into the CNN-BiLSTM / BiGRU hybrid combination model and the (CNN-BiLSTM) / CNN hybrid text classification model for processing and comprehensive calculation to obtain a second classification result; The (CNN-BiLSTM) / CNN hybrid text classification model processes part of the text to be processed after content segmentation, including: Extracting a text feature vector of the portion of text to be processed; Performing convolution processing on the text feature vector to obtain multiple local feature vectors of the part of the text to be processed; Sampling the multiple local feature vectors to obtain multiple key feature vectors of the text to be processed; After the plurality of key feature vectors are pruned, they are input into the BiLSTM network layer for processing to obtain output feature vectors; The output feature vector and the plurality of key feature vectors are subjected to pruning processing, and the feature vectors are fused, and the fused feature vector is obtained and input into a classifier for processing to obtain the second classification result.
2. The method according to claim 1, characterized in that The method of performing text classification on the text to be processed based on the CNN-BiLSTM / BiGRU hybrid combination model to obtain a first classification result includes: Extracting a text feature vector of the text to be processed; Performing convolution processing on the text feature vector to obtain multiple local feature vectors of the text to be processed; Sampling the multiple local feature vectors to obtain multiple key feature vectors of the text to be processed; After the multiple key feature vectors are pruned, they are concatenated and respectively input into the BiLSTM network layer and the BiGRU network layer for processing to obtain a first output feature vector and a second output feature vector; The first output feature vector and the second output feature vector are fused to obtain a fused feature vector, which is input into a classifier for processing to obtain the first classification result.
3. The method according to claim 2, characterized in that When performing the convolution process, convolution kernel sizes of different sizes are set to extract word features of different lengths to obtain the multiple local feature vectors.
4. The method according to any one of claims 1 to 3, characterized in that: The hybrid combination model includes a CNN network layer, a BiLSTM network layer and a BiGRU network layer; The CNN network layer is connected to the BiLSTM network layer and the BiGRU network layer respectively, and the BiLSTM network layer and the BiGRU network are connected to the classifier respectively; or, The CNN network layer is connected to the BiLSTM network layer, and the two as a whole are connected to the classifier respectively with the CNN network layer.
5. A text classification device based on a CNN-BiLSTM / BiGRU hybrid combination model, characterized in that: include: An acquisition module, used for acquiring the text to be processed and acquiring the text length value of the text to be processed; A first processing module is used to classify the text to be processed based on the CNN-BiLSTM / BiGRU hybrid combination model to obtain a first classification result when the text length value is less than a preset text length threshold; A block division module, used for performing content block processing on the text to be processed to obtain a first sub-text to be processed and a second sub-text to be processed when the text length value is greater than or equal to a preset text length threshold; A second processing module is used to input the second sub-text to be processed into a (CNN-BiLSTM) / CNN hybrid text classification model for processing to obtain a second classification sub-result; A third processing module is used to input the first sub-text to be processed into the CNN-BiLSTM / BiGRU hybrid combination model to obtain a first classification sub-result, and perform comprehensive calculation on the first classification sub-result and the second classification sub-result to obtain a second classification result; The second processing module is specifically used for: Extracting text feature vectors of part of the text to be processed; Performing convolution processing on the text feature vector to obtain multiple local feature vectors of the part of the text to be processed; Sampling the multiple local feature vectors to obtain multiple key feature vectors of the text to be processed; After the plurality of key feature vectors are pruned, they are input into the BiLSTM network layer for processing to obtain output feature vectors; The output feature vector and the plurality of key feature vectors are subjected to pruning processing, and the feature vectors are fused, and the fused feature vector is obtained and input into a classifier for processing to obtain the second classification result.
6. The device according to claim 5, characterized in that The first processing module is specifically used for: Extracting a text feature vector of the text to be processed; Performing convolution processing on the text feature vector to obtain multiple local feature vectors of the text to be processed; Sampling the multiple local feature vectors to obtain multiple key feature vectors of the text to be processed; After the multiple key feature vectors are pruned, they are concatenated and respectively input into the BiLSTM network layer and the BiGRU network layer for processing to obtain a first output feature vector and a second output feature vector; The first output feature vector and the second output feature vector are fused to obtain a fused feature vector, which is input into a classifier for processing to obtain the first classification result.
7. The device according to claim 6, characterized in that When performing the convolution process, convolution kernel sizes of different sizes are set to extract word features of different lengths to obtain the multiple local feature vectors.
8. The device according to any one of claims 5 to 7, characterized in that: The hybrid combination model includes a CNN network layer, a BiLSTM network layer and a BiGRU network layer; The CNN network layer is connected to the BiLSTM network layer and the BiGRU network layer respectively, and the BiLSTM network layer and the BiGRU network are connected to the classifier respectively; or, The CNN network layer is connected to the BiLSTM network layer, and the two as a whole are connected to the classifier respectively with the CNN network layer.
