Composite text multi-classification method and system based on deep learning model
Through a composite deep learning model that combines CNN, LSTM and self-attention mechanisms, it solves the interpretability and computational complexity problems of existing text classification models, achieves high efficiency and accuracy improvement in multi-classification of text, and is suitable for natural language Text classification task in process.
Patent Information
- Application Number
- CN202110222535.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-27
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2041-02-27
AI Technical Summary
Existing text classification models have shortcomings in interpretability and feature importance evaluation. The CNN model is simple but the effect is difficult to explain. The Attention mechanism is computationally intensive, and the LSTM model processes sequence information but lacks intuitiveness.
Using a composite deep learning model, combined with CNN, LSTM and self-attention mechanism, text features are extracted through word embedding, convolution layer, self-attention layer and LSTM loop layer, softmax classifier is used for multi-class prediction, and word segmentation system and word frequency are used Perform statistical feature analysis to improve the interpretability and efficiency of the model.
It effectively evaluates the contribution of each feature vector to the classification results, solves the problems of poor interpretability and large computational load of CNN and LSTM, improves the efficiency and accuracy of text multi-classification, and maintains the text sequence order and positional relationship.
Smart Images

Figure CN113011163B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of natural language processing, and in particular relates to a composite text multi-classification method and system based on a deep learning model, which performs multi-classification prediction on text through a composite deep learning model of CNN, LSTM, and self-attention. Background Art
[0002] Text classification is one of the key and basic tasks in natural language processing. Common methods include traditional machine learning classification models such as Naive Bayes, support vector machine, logistic regression, etc., as well as a series of deep learning-based classification models, mainly including CNN, LSTM, attention, etc.
[0003] Text-CNN is simple to implement and supports parallelism. Its main features are local perception and weight sharing. Local perception allows the model to perceive only a small local area each time, reducing the number of parameters while improving the fitting ability. Weight sharing allows some basic features to be reused, improving the training effect of the neural network. The principle of the Attention mechanism is to filter and focus on more effective information from a large amount of information. The focusing process is reflected in the calculation of weight coefficients. LSTM recurrent neural network is a deep learning model that uses sequence data as input for modeling. Compared with other neural network models, LSTM can process sequence information more effectively and is a commonly used model in NLP. In the actual application of text classification, the CNN model is simple, fast to train, and has impressive results, but it is not very interpretable. When tuning the model, it is difficult to adjust specific features according to the training results, and it is not easy to evaluate the importance of each feature. The Attention mechanism can ignore the examples between words and directly calculate the dependency relationship. It can learn the internal structure of the sentence, and the implementation is simple and can be calculated in parallel. However, when calculating the weight, it is necessary to calculate the correlation between each feature vector. When there are many feature vectors, the amount of calculation is high. LSTM can effectively process sequence information, but it is not intuitive and lacks interpretability. Summary of the invention
[0004] To this end, the present invention provides a composite text multi-classification method and system based on a deep learning model, which adopts three deep learning models, CNN, LSTM, and attention, to form a composite learning model for solving the precise multi-classification of text, so as to meet the practical application of multi-classification prediction and recognition of natural language text.
[0005] According to the design scheme provided by the present invention, a composite text multi-classification method based on a deep learning model is provided, comprising:
[0006] Convert the composite text into a word-level text representation, preprocess the converted word-level text representation, and represent it as a word vector using a word embedding method;
[0007] The word vector is used as the input of the trained deep learning model, and the text features are extracted through the CNN convolution layer in the model. The convolved vector is selected, and the global partial sequence association information is retained. The self-attention layer in the model is used to add weights to the text feature vector and perform equal-length vector sequence splicing. The text feature vector is extracted using the LSTM recurrent layer in the model; the text feature vector is averaged through the model pooling layer, and the softmax classifier is used to obtain the input text category probability, and the text classification result is obtained based on the probability size.
[0008] As a composite text multi-classification method based on a deep learning model of the present invention, further, for composite texts, a dictionary is used as a basic segmentation method, and a word segmentation system is used to perform different levels of word segmentation according to the language features, word order features and structural features of the text.
[0009] As a composite text multi-classification method based on a deep learning model of the present invention, further, feature analysis is performed on the composite text, based on a word segmentation method based on dictionary matching, and combined with word frequency statistics and semantic understanding word segmentation to divide the composite text into word granularity levels.
[0010] As a composite text multi-classification method based on a deep learning model of the present invention, further, in the preprocessing, for the text representation at the word granularity level, stop words are removed by loading a stop word dictionary, high-frequency words in all categories are removed using TF-IDF word frequency statistics, and the Word2Vec word embedding method is used to represent them as multi-dimensional word vectors, wherein high-frequency words are words whose frequency is greater than a set value.
[0011] As a composite text multi-classification method based on a deep learning model of the present invention, further, in the CNN convolution layer, different convolution windows are used to perform convolution operations on the input word vectors to extract text features with different field of view widths.
[0012] As a composite text multi-classification method based on a deep learning model of the present invention, the model Top-K pooling layer is further used to select the first K representative feature vectors from the text feature vector extracted by the convolution operation, the ordering sequence is intercepted from the output of the convolution layer of variable length, and some sequence association information is retained.
[0013] As a composite text multi-classification method based on a deep learning model of the present invention, further, in the self-attention layer, for the input feature vector sequence, the contribution of the selected feature vector to the overall text representation is determined by calculating the correlation between the selected feature vector and the remaining feature vectors, and a weight is added to it, and the word vectors are spliced into a feature vector representing the text through a splicing operation.
[0014] As a composite text multi-classification method based on a deep learning model of the present invention, further, in the deep learning model, a single-layer LSTM recurrent layer is used to perform single-layer recurrent learning on the input feature vector matrix and output a text feature vector.
[0015] As a composite text multi-classification method based on a deep learning model of the present invention, further, the text feature vector after averaging processing is input into a softmax classifier to obtain the category distribution probability, and the category with the largest probability is selected as the final classification prediction result.
[0016] Furthermore, based on the above method, the present invention also provides a composite text multi-classification system based on a deep learning model, comprising: a data preprocessing module and a classification prediction module, wherein:
[0017] A data preprocessing module is used to convert the composite text into a text representation at the word granularity level, preprocess the converted text representation at the word granularity level, and represent it as a word vector through a word embedding method;
[0018] The classification prediction module is used to use the word vector as the input of the trained deep learning model, extract text features through the CNN convolution layer in the model, select the vector after convolution, and retain the global partial sequence association information. The self-attention layer in the model adds weights to the text feature vector and performs equal-length vector sequence splicing, and the LSTM recurrent layer in the model is used to extract the text feature vector; the text feature vector is averaged through the model pooling layer, and the softmax classifier is used to obtain the input text category probability, and the text classification result is obtained according to the probability size.
[0019] Beneficial effects of the present invention:
[0020] The present invention combines three models of CNN, Self-attention and LSTM, which can give play to each other's advantages and make up for each other's shortcomings: the problem of poor interpretability of CNN and LSTM can be solved through the self-attention mechanism, and the contribution of each feature vector to the classification result can be effectively evaluated; the mechanism of CNN convolution can make Self-attention focus on the dependency between local sequence features, and there is no need to calculate the correlation between each feature vector; through the advantage of LSTM in processing sequence information, the problem of CNN convolution and pooling operations losing the order and position relationship of text sequences can be solved. According to the text features, the word segmentation system is applied, the input layer is constructed, the word segmentation results are digitized using Word2Vec, the feature vector sequence is extracted through various types of convolution windows of the CNN convolution layer, the feature vector is weighted by the self-attention layer, the feature vector is nonlinearly transformed and mapped by the LSTM recurrent layer, and then mapped to the probability space by the softmax classifier to judge the text category, thereby improving the efficiency and accuracy of text multi-classification, and having good application prospects. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 This is a schematic diagram of the text preprocessing process in the embodiment;
[0022] Figure 2 This is a schematic diagram of the convolution operation process in the embodiment;
[0023] Figure 3 This is a schematic diagram of the weighting process in the embodiment;
[0024] Figure 4 The following is a schematic diagram of the classification output process in the embodiment. DETAILED DESCRIPTION
[0025] In order to make the purpose, technical solutions and advantages of the present invention clearer and more understandable, the present invention is further described in detail below in conjunction with the accompanying drawings and technical solutions.
[0026] In response to the situation of how to perform accurate multi-classification of text, an embodiment of the present invention provides a composite text multi-classification method based on a deep learning model, including: converting the composite text into a text representation at a word granularity level, preprocessing the converted text representation at the word granularity level, and expressing it as a word vector through a word embedding method; using the word vector as the input of a trained deep learning model, extracting text features through a CNN convolutional layer in the model, selecting the vector after convolution, and retaining global partial sequence association information, adding weights to the text feature vector through a self-attention layer in the model and performing equal-length vector sequence splicing, and using an LSTM recurrent layer in the model to extract the text feature vector; averaging the text feature vector through a model pooling layer, and using a softmax classifier to obtain the input text category probability, and obtaining the text classification result according to the probability size.
[0027] There are two main types of network layers in CNN, namely convolutional layers and pooling / sampling layers (Pooling). The function of the convolutional layer is to extract various features of the image. The model generally uses multiple convolution kernels of different sizes and the convolution kernel generally only slides in one dimension, that is, the width of the convolution kernel is the same as the dimension of the word vector, and the height of the convolution kernel is the length of the local word order used. The convolution window value is a hyperparameter that needs to be debugged in the task, and a value between 2-8 is generally selected. The pooling layer (Pooling) of the Text-CNN model is also called undersampling or downsampling. It is mainly used for feature dimensionality reduction, compressing the number of data and parameters, reducing overfitting, and improving the fault tolerance of the model. There are mainly maximum pooling (Max Pooling) and average pooling (AveragePooling). The Attention mechanism regards the original input information as a series of<Key,Value> The data pairs are composed, and then when a Query operation is given, the weight coefficient of the Value corresponding to each Key is obtained by calculating the similarity or correlation between the Query and each Key, so it can be divided into two processes: the first process is to calculate the weight coefficient based on the Query and Key, and the second process is to weighted sum the Value according to the weight coefficient. The first process can be further divided into two stages. The first stage calculates the similarity or correlation between the two based on the Query and Key. The similarity methods include point multiplication, weight, cosine similarity, etc. The second stage normalizes the original score of the first stage. Self-Attention is a special form of Attention. In the self-attention model, query, key and value are equal. Attention needs to be constructed within the sequence to find the connection within the sequence. For example, when a sentence is input, each word in the sentence must be calculated with all the words in the sentence for the purpose of learning the word dependency within the sentence and capturing the internal structure of the sentence. Multiple neural units are set in the LSTM recurrent layer. A neural recurrent unit stores the state of the previous input and combines it with the current input to maintain the relationship between the current input and the previous input, that is, the mutual dependency in the sequence. The recursive formula describing the current state can be defined as follows:
[0028] h t =f(h t-1 ,x t )
[0029] Among them, h t is the state at time t, h t-1 is the state at the previous moment, x tis the current input, and the state of the previous moment is the state of the input of the previous moment after the neuron conversion. This case combines the three models of CNN, Self-attention, and LSTM to give full play to each other's advantages and make up for each other's shortcomings: the self-attention mechanism can solve the problem of poor interpretability of CNN and LSTM, and effectively evaluate the contribution of each feature vector to the classification result; the CNN convolution mechanism can make Self-attention focus on the dependency between local sequence features, without calculating the correlation between each feature vector; through the advantage of LSTM in processing sequence information, the problem of CNN convolution and pooling operations losing the order and position relationship of text sequences can be solved; and the application of deep learning models in text classification and recognition can be improved.
[0030] As a compound text multi-classification method based on a deep learning model in an embodiment of the present invention, further, for the compound text, a dictionary is used as a basic segmentation method, and a word segmentation system is used to perform different levels of word segmentation according to the text language features, word order features and structural features.
[0031] See also Figure 1 As shown in the figure, for specific input text, the dictionary is used as the basic segmentation method, and JieBa, HanLP and other word segmentation systems are used to perform different levels of word segmentation according to the text language features, word order features, structural features and other information. The HanLP word segmentation system is suitable for long texts that need to extract abstracts and keywords, as well as texts that need pinyin, traditional and simplified conversion, and texts that need to be distinguished by named entity recognition; JieBa word segmentation is suitable for texts that accurately segment text vocabulary, or for texts that segment words at the minimum granularity level to understand the representation. By loading the stop word dictionary, stop words are removed for the segmented words. According to the TF-IDF word frequency statistics method, high-frequency words with high word frequencies in all categories can be removed.
[0032] The filtered words are input into the Word2Vec word embedding model in the form of one-hot encoding, and the output is represented as an n-dimensional dense, continuous real number vector [a1, a2, a3, ..., a n ] and map similar words to similar spatial locations.
[0033] As a composite text multi-classification method based on a deep learning model in an embodiment of the present invention, further, in the CNN convolution layer, different convolution windows are used to perform convolution operations on the input word vectors to extract text features with different field of view widths.
[0034] See also Figure 2As shown in the figure, we use different types of convolution kernels to convolve word vectors and obtain local related feature vector sequences. We use a convolution window with a width of word vector and a height of 2 and 3, each with a step size of 1, to perform a convolution operation with a step size of 2, and obtain the feature vector sequences as follows:
[0035] [[a1,a2],[a3,a4],...,[a n-1 ,a n ]]→[b1,b2,...,b n / 2 ]
[0036] [[a1,a2,a3],[a3,a4,a5],...,[a n-2 ,a n-1 ,a n ]]→[d1,d2,...,d n / 3 ]
[0037] Among them, each mapped and transformed feature vector maintains a certain sequence order and position relationship.
[0038] As a composite text multi-classification method based on a deep learning model in an embodiment of the present invention, further, the model Top-K pooling layer is used to select the first K representative feature vectors from the text feature vector extracted by the convolution operation, and the order sequence is intercepted from the variable-length convolution layer output, and some sequence association information is retained. Further, in the self-attention layer, for the input feature vector sequence, the contribution of the selected feature vector to the overall text representation is determined by calculating the correlation between the selected feature vector and the remaining feature vectors, and a weight is added to it, and the word vectors are spliced into a feature vector representing the text through a splicing operation.
[0039] See also Figure 3 As shown in the figure, the TOP-K pooling layer selects k convolutional feature vectors and retains the global partial sequence correlation information. Configure the TOP-2 pooling layer and select 2 maximum text correlation feature vectors for each type:
[0040] [b x ,b y ]; [d i ,d k ]
[0041] Among them, b x and b y The local sequence order and position relationship are maintained between them, d i ,d k The local sequence order and position relationship are also maintained.
[0042] The self-attention layer calculates and adds weights to the feature vectors in the partial sequence information.<Key,Value> And the query Query comes from the same input matrix:
[0043]
[0044] X*W K =K;X*W V =V;X*W Q =Q
[0045]
[0046] Among them, X is the input sequence of the self-attention layer, W K , W V , W Q It is the appropriate parameter to learn during model training. Softmax normalizes the result of matrix dot multiplication into a probability distribution. is the scale set to prevent the result from being too large, d k is the dimension of the Key and Query vectors, and C is the feature vector matrix after the self-attention layer outputs the additional weights.
[0047] As a composite text multi-classification method based on a deep learning model in an embodiment of the present invention, further, in the deep learning model, a single-layer LSTM loop layer is used to perform single-layer loop learning on the input feature vector matrix and output a text feature vector. Further, the averaged text feature vector is input into a softmax classifier to obtain the category distribution probability, and the category with the largest probability is selected as the final classification prediction result.
[0048] See also Figure 4 As shown in the figure, a single-layer LSTM recurrent layer inputs the C1 and C2 feature vector matrices, and after a single-layer recurrent learning, the output feature vector is obtained:
[0049]
[0050] Mean pooling layer performs an average operation on the text feature vector after cyclic learning:
[0051]
[0052] The feature vector processed by feature engineering transformation is input into the soft-max classifier to obtain a category distribution probability, and the category with the highest probability is taken as the final classification.
[0053] Furthermore, based on the above method, an embodiment of the present invention also provides a composite text multi-classification system based on a deep learning model, comprising: a data preprocessing module and a classification prediction module, wherein:
[0054] A data preprocessing module is used to convert the composite text into a text representation at the word granularity level, preprocess the converted text representation at the word granularity level, and represent it as a word vector through a word embedding method;
[0055] The classification prediction module is used to use the word vector as the input of the trained deep learning model, extract text features through the CNN convolution layer in the model, select the vector after convolution, and retain the global partial sequence association information. The self-attention layer in the model adds weights to the text feature vector and performs equal-length vector sequence splicing, and the LSTM recurrent layer in the model is used to extract the text feature vector; the text feature vector is averaged through the model pooling layer, and the softmax classifier is used to obtain the input text category probability, and the text classification result is obtained according to the probability size.
[0056] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0057] The units and method steps of each example described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. A person of ordinary skill in the art may use different methods to implement the described functions for each specific application, but such implementation is not considered to be beyond the scope of the present invention.
[0058] Those skilled in the art will appreciate that all or part of the steps in the above method can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable storage medium, such as a read-only memory, a disk or an optical disk. Optionally, all or part of the steps in the above embodiment can also be implemented using one or more integrated circuits, and accordingly, each module / unit in the above embodiment can be implemented in the form of hardware or in the form of software function modules. The present invention is not limited to any specific form of combination of hardware and software.
[0059] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A composite text multi-classification method based on a deep learning model, characterized in that: Include: For compound text, the dictionary is used as the basic segmentation method. According to the language features, word order features and structural features of the text, the word segmentation system is used to perform word segmentation at different levels, and the compound text is converted to a text representation at the word granularity level. The converted text representation at the word granularity level is preprocessed, and the preprocessed words are represented as multi-dimensional dense word vectors using the Word2Vec word embedding method, and similar words are mapped to similar spatial positions. The preprocessing includes: for the text representation at the word granularity level, stop words are removed by loading a stop word dictionary, and high-frequency words in all categories are removed using TF-IDF word frequency statistics, where high-frequency words are words with a word frequency greater than a set value; The word vector is used as the input of the CNN convolution layer in the trained deep learning model. The input word vector is convolved through the CNN convolution layer and different convolution windows are used to extract text features with different field of view widths, so that the local sequence order and position relationship are maintained between the mapped and transformed feature vectors; the text features extracted by the convolution operation are used as the input of the model Top-K pooling layer, and the model Top-K pooling layer is used to select the first K representative feature vectors from the text features to intercept the fixed-length sequence from the output of the CNN convolution layer with different convolution windows of variable length, and retain some sequence association information; the selected first K representative feature vectors are used as the input of the self-attention layer, and the self-attention layer is used to calculate the selected feature vector and its The contribution of the selected feature vector to the overall text representation and its additional weight are determined by the correlation of the residual feature vector, and the feature vectors with additional weights are spliced into a feature vector matrix representing the text through a splicing operation; the feature vector matrix is used as the input of a single-layer LSTM recurrent layer, and a single-layer LSTM recurrent layer is used to perform single-layer recurrent learning on the input feature vector matrix and output a text feature vector; the text feature vector is averaged through the model pooling layer, and the averaged text feature vector is input into the softmax classifier to obtain the category distribution probability, and the category with the largest probability is selected as the final classification prediction result, where the TOP-K pooling layer is configured as a TOP-2 pooling layer, and two feature vectors with the largest text correlation are selected for each type and expressed as [b x ,b y ]; [d i ,d k ], b x and b y The local sequence order and position relationship are maintained between them, d i and d k The local sequence order and position relationship are also maintained between them; the self-attention layer of the model calculates the weights of the feature vector and adds some sequence information. The calculation process is expressed as: X*W K =K;X*W V =V;X*W Q =Q, X is the input feature vector sequence of the self-attention layer, that is, in the calculation process, X is the input X1 or X2, W K , W V , W Q are the appropriate parameters learned during model training, and softmax is the result of matrix dot multiplication normalized to probability distribution. is the scale of the setting, d k is the dimension of the input data pair Key and Query vector, C is the feature vector after the self-attention layer outputs the additional weight, and the feature vectors C calculated by X1 and X2 are concatenated in sequence to obtain the feature vector matrix representing the text.
2. The composite text multi-classification method based on the deep learning model according to claim 1 is characterized in that: Feature analysis is performed on compound texts, based on the word segmentation method based on dictionary matching, and combined with word frequency statistics and semantic understanding word segmentation to divide the compound text into word granularity levels.
3. A composite text multi-classification system based on a deep learning model, characterized in that: The method according to claim 1 is implemented, comprising: a data preprocessing module and a classification prediction module, wherein: A data preprocessing module is used to convert the composite text into a text representation at the word granularity level, preprocess the converted text representation at the word granularity level, and represent it as a word vector through a word embedding method; The classification prediction module is used to use the word vector as the input of the trained deep learning model, extract text features through the CNN convolution layer in the model, select the vector after convolution, and retain the global partial sequence association information. The self-attention layer in the model adds weights to the text feature vector and performs equal-length vector sequence splicing, and the LSTM recurrent layer in the model is used to extract the text feature vector; the text feature vector is averaged through the model pooling layer, and the softmax classifier is used to obtain the input text category probability, and the text classification result is obtained according to the probability size.
Citation Information
Patent Citations
Emotion analysis method based on context word vectors and depth learning
CN108427670A
Method for generating a web page screenshot code based on a neural network and a self-attention mechanism
CN109522017A
