Text classification method and system based on deep learning
Through the deep learning method, the convolutional neural network and the bidirectional GRU neural network of the ALBERT and attention mechanism are used to extract text features, which solves the problem of insufficient text classification feature extraction in the existing technology and improves the accuracy and stability of text classification.
Patent Information
- Application Number
- CN202111535167.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-15
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2041-12-15
AI Technical Summary
Existing text classification methods based on statistical models consume a lot of manpower and material resources in extracting features and cannot learn sentence structure and semantic information, resulting in insufficient classification accuracy and stability.
Using a method based on deep learning, ALBERT is used for text pre-training, the convolutional neural network combined with the attention mechanism and the bidirectional GRU neural network are used to extract text features, the text classification model is established through the Cross Entropy Loss function and the Softmax algorithm, and the Adam optimization algorithm is used Optimizing parameters solves the problem of lack of global features in text word vectors.
The classification effect of the text classification model is improved, the connection between the generated word vectors is closer, the model pays more attention to important feature samples, and the accuracy and stability of text classification are improved.
Smart Images

Figure CN114428853B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of natural language processing, and in particular to a text classification method and system based on deep learning. Background Art
[0002] With the advancement of science and technology and the rapid development of the Internet, all kinds of digital information have penetrated into all walks of life. However, the growing number of digital resources has also brought us all kinds of troubles in information retrieval. Among them, text information is the most widely distributed and largest information carrier. How to effectively organize or manage this data is an urgent problem to be solved. At the same time, text classification is also one of the most important and basic tasks in natural language processing.
[0003] Text classification is a significant and necessary task in the downstream tasks of natural language processing (NLP), such as sentiment analysis, topic tagging, automatic question answering, etc. In the era of information explosion, it is very difficult to manually process and classify massive amounts of text data. In addition, the accuracy of manual classification is easily affected by human subjective factors, so letting the machine automatically learn text features automates the process of text classification and produces more reliable results. In addition, by locating key information from the text, it can be used to help improve information retrieval efficiency and alleviate the problem of information overload.
[0004] Between 1960 and 2010, statistical-based models dominated text classification, such as Naive J. Compared with the early rule-based methods, these methods have advantages in accuracy and stability. However, these methods still require a lot of manpower and material resources to extract features. Moreover, this method cannot learn the structure and context information between sentences and does not have the ability to obtain semantic information between words. Summary of the invention
[0005] The present invention aims to solve one of the technical problems in the related art at least to a certain extent.
[0006] To this end, an object of the present invention is to propose a text classification method based on deep learning, which solves the problem that text word vectors lack global features.
[0007] Another object of the present invention is to propose a text classification system based on deep learning.
[0008] To achieve the above-mentioned purpose, an embodiment of the present invention proposes a text classification method based on deep learning, comprising the following steps: step S1, obtaining and preprocessing a text data set, and dividing the preprocessed text data set into a training set and a test set according to a preset ratio; step S2, converting the training set into a text feature word vector using the ALBERT technology; step S3, extracting features from the text feature word vector using an improved deep learning algorithm to obtain an optimal feature vector, wherein the improved deep learning model includes a convolutional neural network with an attention mechanism and a bidirectional GRU neural network; step S4, improving the classification function of the Softmax algorithm using the Cross Entropy Loss function to establish a text classification model, training the text classification model using the data set to obtain a text classification prediction model; step S5, optimizing the parameters of the text classification prediction model using the parameter optimization algorithm Adam to obtain an optimal text classification prediction model; step S6, inputting the test set into the optimal text classification prediction model to obtain a classification prediction result.
[0009] The deep learning-based text classification method of the embodiment of the present invention uses ALBERT to pre-train the text. ALBERT randomly masks out 15% of the words each time and allows the language model to predict the word. This forces the model not to rely too much on the current word when encoding the current moment, but to consider its context, and even to perform "error correction" based on the context. It can learn some relationships between sentences from a large-scale corpus, so that the relationship between the generated word vectors is closer. It also extracts the features of the text by fusing the convolutional neural network and the bidirectional GRU neural network, and introduces the Attention mechanism to calculate the importance of the features extracted by the above two networks of the text, so that the model pays more attention to the feature samples that are more important for the text classification task, solves the problem of the lack of global features in the text word vector, and further improves the classification effect of the model.
[0010] In addition, the text classification method based on deep learning according to the above embodiment of the present invention may also have the following additional technical features:
[0011] Furthermore, in one embodiment of the present invention, the step S1 is specifically as follows: step S101, obtaining the text data set from network resources according to preset requirements; step S102, using regular expressions to remove special marking symbols in the text data set, performing word segmentation processing, and establishing a dictionary using the text content after word segmentation; step S103, unifying the length of the sentences after word segmentation to a preset fixed length, if the sentence length is less than the preset fixed length, padding with PAD, if the sentence length is greater than the preset fixed length, truncating the sentence; step S104, using the dictionary to serialize the fixed-length sentences generated in the step S103 to obtain a fixed-length sequence.
[0012] Furthermore, in one embodiment of the present invention, the step S3 specifically includes: step S301, using the mini-batch gradient descent method to input the text feature word vector into the improved deep learning model to respectively extract the local features and global features of the text feature word vector; step S302, using the Attention mechanism to respectively calculate the weight scores of the local features and the global features, and fusing and splicing the various weight scores to obtain the optimal feature vector.
[0013] Furthermore, in one embodiment of the present invention, the step S301 specifically includes: step S3011, using the mini-batch gradient descent method to input the text feature word vector into a convolutional neural network, the convolution layer extracts multiple different feature expressions of feature words through convolution kernels of different sizes, and the pooling layer compresses and reduces the dimension of the output features of the convolution layer to obtain the local features; step S3012, using the mini-batch gradient descent method to input the text feature word vector into a bidirectional GRU neural network to obtain the global features.
[0014] Furthermore, in one embodiment of the present invention, the calculation formula of step 3011 is:
[0015] o i =w·A[i:i+h-1],i=1,2,...,s-h+1
[0016] c i =f(o i +b)
[0017] Y i =max_pool(c i )
[0018] Among them, iis the output of the convolution kernel, w is the convolution kernel, s is the length of the sentence in the word vector, the convolution kernel is a matrix with a width of d and a height of h, A[i:i+h-1] is the text feature word vector from the i-th row to the i+h-1th row, f is the activation function, b is the bias, c i is the output of the convolutional neural network, max_pool is the pooling operation, Y i is the output of the pooling layer.
[0019] Furthermore, in one embodiment of the present invention, the calculation formula of step 3012 is:
[0020]
[0021]
[0022]
[0023]
[0024] Among them, z t is the update gate, σ is the activation function, x t is the input of the tth layer, h t-1 is the state at the previous moment, W h is the weight assigned to the unit by the output at the previous moment, b is the bias, W x is the weight assigned to the input vector, z is the output of the update gate, r t is the reset gate, r is the output of the reset gate, h t is the output of the GRU unit.
[0025] Furthermore, in one embodiment of the present invention, the calculation process of the Attention mechanism in step S302 is:
[0026] X i =tanh(W s h i +b s )
[0027]
[0028]
[0029] Among them, h i is the output word vector of the bidirectional GRU neural network, X i is the word vector of the text after being processed by the activation function tanh, W s is the initialization weight for nonlinear operations on text vectors, b s is the vector bias, W uis a random initialization vector, e is a natural exponent, is the transpose of the vector, α i is the text feature word vector h i In the sequence vector s=(h1,h2,...,h n ) is the attention weight, u i It is the word vector representation obtained by weighted averaging of text feature word vectors.
[0030] To achieve the above-mentioned purpose, another embodiment of the present invention proposes a text classification system based on deep learning, including: a preprocessing module, used to obtain and preprocess a text data set, and divide the preprocessed text data set into a training set and a test set according to a preset ratio; a conversion module, used to convert the training set into a text feature word vector using the ALBERT technology; a feature extraction module, used to extract features from the text feature word vector using an improved deep learning algorithm to obtain an optimal feature vector; a training module, used to improve the classification function of the Softmax algorithm using the Cross Entropy Loss function to establish a text classification model, and train the text classification model using the data set to obtain a text classification prediction model; an optimization module, used to optimize the parameters of the text classification prediction model using the parameter optimization algorithm Adam to obtain an optimal text classification prediction model; and a testing module, used to input the test set into the optimal text classification prediction model to obtain a classification prediction result.
[0031] The deep learning-based text classification system of the embodiment of the present invention uses ALBERT to pre-train the text. ALBERT randomly masks out 15% of the words each time and allows the language model to predict the word. This forces the model not to rely too much on the current word when encoding the current moment, but to consider its context, and even to perform "error correction" based on the context. It can learn some relationships between sentences from a large-scale corpus, so that the relationship between the generated word vectors is closer. It also extracts the features of the text by fusing the convolutional neural network and the bidirectional GRU neural network, and introduces the Attention mechanism to calculate the importance of the features extracted by the above two networks of the text, so that the model pays more attention to the feature samples that are more important for the text classification task, solves the problem of the lack of global features in the text word vector, and further improves the classification effect of the model.
[0032] In addition, the text classification system based on deep learning according to the above embodiment of the present invention may also have the following additional technical features:
[0033] Furthermore, in one embodiment of the present invention, the feature extraction module specifically includes: an extraction unit, used to input the text feature word vector into the improved deep learning model using a mini-batch gradient descent method to respectively extract local features and global features of the text feature word vector; a fusion and splicing unit, used to respectively calculate the weight scores of the local features and the global features using an Attention mechanism, and fuse and splice the various weight scores to obtain the optimal feature vector.
[0034] Furthermore, in one embodiment of the present invention, the extraction unit is specifically used to: use the mini-batch gradient descent method to input the text feature word vector into a convolutional neural network, the convolution layer extracts multiple different feature expressions of feature words through convolution kernels of different sizes, and the pooling layer compresses and reduces the dimension of the output features of the convolution layer to obtain the local features; use the mini-batch gradient descent method to input the text feature word vector into a bidirectional GRU neural network to obtain the global features.
[0035] Additional aspects and advantages of the present invention will be given in part in the following description and in part will be obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] The above and / or additional aspects and advantages of the present invention will become apparent and easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:
[0037] Figure 1 is a flowchart of a text classification method based on deep learning according to an embodiment of the present invention;
[0038] Figure 2 It is a specific execution diagram of a text classification method based on deep learning according to an embodiment of the present invention;
[0039] Figure 3 It is a schematic diagram of executing a method of extracting text features using a convolutional neural network according to an embodiment of the present invention;
[0040] Figure 4 It is a schematic diagram of executing a method of extracting text features using a bidirectional GRU network according to an embodiment of the present invention;
[0041] Figure 5 is a performance comparison chart of the embodiment of the present invention and other text classification methods on the THUCNews dataset;
[0042] Figure 6 is a performance comparison diagram of the embodiment of the present invention and other text classification methods on the IMDB movie review dataset;
[0043] Figure 7is a performance comparison diagram of the embodiment of the present invention and other text classification methods on the Fudan University Chinese dataset;
[0044] Figure 8 It is a structural diagram of a text classification system based on deep learning according to an embodiment of the present invention. DETAILED DESCRIPTION
[0045] Embodiments of the present invention are described in detail below, examples of which 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 invention, and should not be construed as limiting the present invention.
[0046] The following describes a text classification method and system based on deep learning proposed according to an embodiment of the present invention with reference to the accompanying drawings. First, the text classification method based on deep learning proposed according to an embodiment of the present invention will be described with reference to the accompanying drawings.
[0047] Figure 1 It is a flowchart of a text classification method based on deep learning according to an embodiment of the present invention.
[0048] like Figure 1 and 2 As shown, the text classification method based on deep learning includes the following steps:
[0049] In step S1, a text data set is obtained and preprocessed, and the preprocessed text data set is divided into a training set and a test set according to a preset ratio.
[0050] Furthermore, in one embodiment of the present invention, step S1 is specifically:
[0051] Step S101, obtaining a text data set from network resources according to preset requirements;
[0052] Step S102, using regular expressions to remove special marking symbols in the text data set, then performing word segmentation, and using the text content after word segmentation to build a dictionary;
[0053] Step S103, unifying the length of the sentence after word segmentation to a preset fixed length, if the sentence length is less than the preset fixed length, padding with PAD, if the sentence length is greater than the preset fixed length, truncating the sentence;
[0054] Step S104, using a dictionary to serialize the fixed-length sentences generated in step S103 to obtain a fixed-length sequence.
[0055] For example, three public datasets are downloaded from the Internet, namely, the IMDB English movie review dataset, the Fudan University Chinese dataset, and the THUCNews dataset. The IMDB English dataset is a binary classification dataset, which is divided into positive and negative reviews, with 1 representing positive reviews and 0 representing negative reviews. The Fudan University Chinese dataset is mainly composed of literature content, with a total of 20 classification categories, including art, literature, education, philosophy, history, etc. The text is long and has many noise features. 1, 2, 3, ..., 20 are used to represent the 20 classification categories. The THUCNews dataset was launched by Tsinghua University. It is based on the historical data of Sina News and is divided into 14 categories, including finance, lottery, news, etc. The average length of the document is short and the noise features are few. Due to the large number of samples in the dataset, this paper randomly selects 50,000 samples for experiments, and 1, 2, 3, ..., 14 are used to represent the 14 classification categories.
[0056] Then, the above data sets are processed by removing stop words, punctuation marks and special characters respectively. The Chinese data set needs to be segmented using jieba, and the words after segmentation are used to make a dictionary; the text after segmentation is then unified, and the sentence length of the text is agreed to be a fixed length. If the sentence length is not enough, PAD is used to fill it. If the sentence is too long, the sentence is truncated; the generated dictionary is then used to serialize the generated fixed-length sentences, convert the text into a fixed-length sequence, and the processed data is divided into a training set and a test set in a ratio of 7:3.
[0057] In step S2, the training set is converted into text feature word vectors using ALBERT technology.
[0058] Specifically, ALBERT is used to randomly mask out 15% of the words each time, and the language model is asked to predict the word. Among the randomly masked words, 80% are replaced with [MASK], 10% are replaced with a random word, and 10% are replaced with the word itself. This pre-training method forces the model to not rely too much on the current word when encoding the current moment, but to consider its context, and even "correct errors" based on the context. In this way, some relationships between sentences can be learned from a large-scale corpus, making the connection between the generated word vectors closer.
[0059] Among them, the formula for the importance of the text word feature vector in the sentence is:
[0060]
[0061] Among them, Q, K, V are vectors generated according to each word, d k is the dimension of vector K.
[0062] In step S3, an improved deep learning algorithm is used to extract features from the text feature word vector to obtain an optimal feature vector, wherein the improved deep learning model includes a convolutional neural network with an attention mechanism and a bidirectional GRU neural network.
[0063] That is to say, the local feature vector and global feature vector of the text are extracted using the convolutional neural network and the bidirectional GRU network respectively, and finally the feature vectors of the two are fused to output the optimal feature vector. The specific process is:
[0064] like Figure 3 As shown in the figure, the text feature word vector is input into the improved deep learning model using the mini-batch gradient descent method. The convolution layer extracts multiple different feature expressions of feature words through convolution kernels of different sizes. The pooling layer compresses and reduces the dimension of the output features of the convolution layer, retaining the main features of the feature words. Finally, the pooling layer outputs the extracted features to the fully connected layer to obtain local features. The specific processing formula is:
[0065] o i =w·A[i:i+h-1],i=1,2,...,s-h+1
[0066] c i =f(o i +b)
[0067] Y i =max_pool(c i )
[0068] Among them, i is the output of the convolution kernel, w is the convolution kernel, s is the length of the sentence in the word vector, the convolution kernel width is d, the height is h, A[i:i+h-1] is the text feature word vector from row i to row i+h-1, f is the activation function, b is the bias, c is the i is the output of the convolutional neural network, max_pool is the pooling operation, Y i is the output of the pooling layer.
[0069] like Figure 4 As shown, the text feature word vector is also input into the bidirectional GRU neural network using the mini-batch gradient descent method to obtain the global features, specifically:
[0070]
[0071]
[0072]
[0073]
[0074] Among them, z t is the update gate, σ is the activation function, x t is the input of the tth layer, h t-1 is the state at the previous moment, W h is the weight assigned to the unit by the output at the previous moment, b is the bias, W x The weight assigned to the input vector, r t is the reset gate, z is the output of the update gate, r is the output of the reset gate, h t is the output of the GRU unit.
[0075] Finally, the output of the above convolutional neural network and the output of the bidirectional GRU neural network are used, and the Attention mechanism is used to calculate the weight scores of local features and global features respectively, and each weight score is fused and spliced to obtain the optimal feature vector. The calculation process of the Attention mechanism is:
[0076] X i =tanh(W s h i +b s )
[0077]
[0078]
[0079] Among them, h i is the output word vector of the bidirectional GRU neural network, X i is the word vector of the text after being processed by the activation function tanh, W s is the initialization weight for nonlinear operations on text vectors, b s is the vector bias, W u is a random initialization vector, e is a natural exponent, is the transpose of the vector, α i is the text feature word vector h i In the sequence vector s=(h1,h2,...,h n ) is the attention weight, u i It is the word vector representation obtained by weighted averaging of text feature word vectors.
[0080] In step S4, the classification function of the Softmax algorithm is improved by using the Cross Entropy Loss function to establish a text classification model, and the text classification model of the data set is used for training to obtain a text classification prediction model.
[0081] It should be noted that the Softmax function is a very important tool for machine learning. It can be used independently as a machine learning model for modeling training, and can also be used as an excitation function for a deep model. Simply put, the function of the Softmax function is to calculate the proportion of each value in a set of values. The formula is generally described as:
[0082]
[0083] Among them, parameter i is used to represent a category in j, j∈[1,n], n represents the number of categories, and parameter y i The value used to represent this category.
[0084] The Cross Entropy Loss function is introduced into the Softmax function, so that the layer can be classified and back-propagated according to the loss value between the predicted value and the true value, regardless of the optimization adjustment parameters. The formula of the Cross Entropy Loss function is generally described as follows:
[0085]
[0086] In the formula, p i is the true value of category i, q i is the predicted value of category i, and c represents the number of categories.
[0087] In step S5, the parameters of the text classification prediction model are optimized by using the parameter optimization algorithm Adam to obtain the best text classification prediction model.
[0088] It should be noted that the Adam optimizer is one of the most popular optimizers in deep learning. It is applicable to many problems, including models with sparse or noisy gradients. Its easy fine-tuning feature enables it to quickly obtain good results. In fact, the default parameter configuration can usually achieve good results. The Adam optimizer combines the advantages of AdaGrad and RMSProp. Adam uses the same learning rate for each parameter and adapts independently as learning proceeds. The embodiment of the present invention utilizes these features of Adam and gradually obtains the best prediction model for text classification by continuously optimizing the parameters.
[0089] In step S6, the test set is input into the best text classification prediction model to obtain the classification prediction result.
[0090] It should be noted that the test set can also verify the model classification performance and evaluate the prediction effect of the model based on precision (pre), recall (rec), and F1 value.
[0091] The text classification method based on deep learning proposed in the embodiment of the present invention is further illustrated below through a specific example.
[0092] Based on the same text dataset, a comparative analysis is conducted with other deep learning-based text classification algorithm models.
[0093] First, the data set is preprocessed and divided into a training set and a test set in a ratio of 7:3. The training set data is pre-trained, and then the text vector is pre-trained using the ALBERT pre-training model method. Finally, the model is trained in combination with the improved deep model learning algorithm proposed in the present invention, and the model parameters are optimized by the Adam algorithm. The prediction results of the model are evaluated using the test set. The precision, recall and F1 value curves of each model on the THUCNews dataset, IMDB film review dataset, and Fudan University Chinese dataset are shown in the figure below. Figure 5-7 As shown. Figure 5-7 It can be seen from the results that when the classification models are the same, the text classification model proposed in the present invention has better prediction effect than the three text classification methods of prior art, namely CLA, LCA and CNN+LSTM.
[0094] According to the deep learning-based text classification method proposed in an embodiment of the present invention, ALBERT is used to pre-train the text. ALBERT randomly masks out 15% of the words each time and allows the language model to predict the word. This forces the model not to rely too much on the current word when encoding the current moment, but to consider its context, and even to perform "error correction" based on the context. Some relationships between sentences can be learned from a large-scale corpus, so that the connection between the generated word vectors is closer. The convolutional neural network and the bidirectional GRU neural network are also integrated to extract the features of the text. At the same time, the Attention mechanism is introduced to calculate the importance of the features extracted by the above two networks of the text, so that the model pays more attention to the feature samples that are more important for the text classification task, solves the problem of the lack of global features in the text word vector, and further improves the classification effect of the model.
[0095] Next, a text classification system based on deep learning proposed according to an embodiment of the present invention is described with reference to the accompanying drawings.
[0096] Figure 8 It is a structural diagram of a text classification system based on deep learning according to an embodiment of the present invention.
[0097] like Figure 8 As shown, the system 10 includes: a preprocessing module 100, a conversion module 200, a feature extraction module 300, a training module 400, an optimization module 500 and a testing module 600.
[0098] Among them, the preprocessing module 100 is used to obtain and preprocess the text data set, and divide the preprocessed text data set into a training set and a test set according to a preset ratio. The conversion module 200 is used to convert the training set into a text feature word vector using the ALBERT technology. The feature extraction module 300 is used to extract features from the text feature word vector using an improved deep learning algorithm to obtain the optimal feature vector. The training module 400 is used to improve the classification function of the Softmax algorithm using the Cross Entropy Loss function to establish a text classification model, and train using the data set text classification model to obtain a text classification prediction model. The optimization module 500 is used to optimize the parameters of the text classification prediction model through the parameter optimization algorithm Adam to obtain the optimal text classification prediction model. The test module 600 is used to input the test set into the optimal text classification prediction model to obtain the classification prediction result.
[0099] Furthermore, in one embodiment of the present invention, the feature extraction module 300 specifically includes:
[0100] An extraction unit, used for inputting the text feature word vector into the improved deep learning model by using a mini-batch gradient descent method, so as to respectively extract local features and global features of the text feature word vector;
[0101] The fusion and splicing unit is used to use the Attention mechanism to calculate the weight scores of local features and global features respectively, and fuse and splice each weight score to obtain the optimal feature vector.
[0102] Further, in one embodiment of the present invention, the extraction unit is specifically used for:
[0103] The text feature word vector is input into the convolutional neural network using the mini-batch gradient descent method. The convolution layer extracts multiple different feature expressions of feature words through convolution kernels of different sizes. The pooling layer compresses and reduces the dimension of the output features of the convolution layer to obtain local features.
[0104] The text feature word vector is input into the bidirectional GRU neural network using the mini-batch gradient descent method to obtain the global feature.
[0105] It should be noted that the aforementioned explanation of the embodiment of the text classification method based on deep learning is also applicable to the system of this embodiment and will not be repeated here.
[0106] According to the deep learning-based text classification system proposed in the embodiment of the present invention, ALBERT is used to pre-train the text. ALBERT randomly masks out 15% of the words each time and allows the language model to predict the word. This forces the model not to rely too much on the current word when encoding the current moment, but to consider its context, and even to perform "error correction" based on the context. Some relationships between sentences can be learned from a large-scale corpus, so that the connection between the generated word vectors is closer. The convolutional neural network and the bidirectional GRU neural network are also integrated to extract the features of the text. At the same time, the Attention mechanism is introduced to calculate the importance of the features extracted by the above two networks of the text, so that the model pays more attention to the feature samples that are more important for the text classification task, solves the problem of the lack of global features in the text word vector, and further improves the classification effect of the model.
[0107] 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 the present invention, the meaning of "plurality" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined.
[0108] 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 invention. 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.
[0109] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations of the present invention. A person skilled in the art may change, modify, replace and vary the above embodiments within the scope of the present invention.
Claims
1. A text classification method based on deep learning, characterized in that: The following steps are involved: Step S1, obtaining and preprocessing a text data set, and dividing the preprocessed text data set into a training set and a test set according to a preset ratio; Step S2, converting the training set into text feature word vectors using ALBERT technology; Step S3, using an improved deep learning algorithm to perform feature extraction on the text feature word vector to obtain an optimal feature vector, wherein the improved deep learning model includes a convolutional neural network with an attention mechanism and a bidirectional GRU neural network; Step S4, using the Cross Entropy Loss function to improve the classification function of the Softmax algorithm to establish a text classification model, and using the text classification model of the data set for training to obtain a text classification prediction model; Step S5, optimizing the parameters of the text classification prediction model by using the parameter optimization algorithm Adam to obtain the best text classification prediction model; Step S6, inputting the test set into the optimal text classification prediction model to obtain a classification prediction result; The step S3 specifically includes: Step S301, inputting the text feature word vector into the improved deep learning model using a mini-batch gradient descent method to respectively extract local features and global features of the text feature word vector; Step S302, using the Attention mechanism to calculate the weight scores of the local features and the global features respectively, and fusing and splicing the weight scores to obtain the optimal feature vector; The step S301 specifically includes: Step S3011, using the mini-batch gradient descent method to input the text feature word vector into the convolutional neural network, the convolution layer extracts multiple different feature expressions of the feature word through convolution kernels of different sizes, and the pooling layer compresses and reduces the dimension of the output features of the convolution layer to obtain the local features; Step S3012, using the mini-batch gradient descent method to input the text feature word vector into the bidirectional GRU neural network to obtain the global feature.
2. The text classification method based on deep learning according to claim 1, characterized in that: The step S1 is specifically as follows: Step S101, acquiring the text data set from network resources according to preset requirements; Step S102, using regular expressions to remove special marking symbols in the text data set, then performing word segmentation processing, and using the text content after word segmentation to establish a dictionary; Step S103, unifying the length of the sentence after word segmentation to a preset fixed length, and if the sentence length is less than the preset fixed length, padding it with PAD, and if the sentence length is greater than the preset fixed length, truncating the sentence; Step S104, using the dictionary to serialize the fixed-length sentences generated in step S103 to obtain a fixed-length sequence.
3. The text classification method based on deep learning according to claim 1, characterized in that: The calculation formula of step 3011 is: in, is the output of the convolution kernel, is the convolution kernel, is the length of the sentence in the word vector, and the width of the convolution kernel is , the height is The matrix of For the Go to The text feature word vector of the row, is the activation function, is the bias, is the output of the convolutional neural network, For the pooling operation, is the output of the pooling layer.
4. The text classification method based on deep learning according to claim 1, characterized in that: The calculation formula of step 3012 is: in, To update the gate, is the activation function, For the The input of the layer, is the state at the previous moment, is the weight assigned to the unit by the output at the previous moment, is the bias, The weight assigned to the input vector, is the output of the update gate, To reset the gate, is the output of the reset gate, is the output of the GRU unit.
5. The text classification method based on deep learning according to claim 1, characterized in that: The calculation process of the Attention mechanism in step S302 is: in, is the output word vector of the bidirectional GRU neural network, is the word vector of the text after being processed by the activation function tanh, To initialize the weights for nonlinear operations on text vectors, is the bias of the vector, is a random initialization vector, is the natural index, For vector The transpose of is the text feature word vector In the sequence vector The attention weight, It is the word vector representation obtained by weighted averaging of text feature word vectors.
6. A text classification system based on deep learning, characterized in that: include: A preprocessing module is used to obtain and preprocess a text data set, and divide the preprocessed text data set into a training set and a test set according to a preset ratio; A conversion module, used to convert the training set into a text feature word vector using ALBERT technology; A feature extraction module, used to extract features from the text feature word vector using an improved deep learning algorithm to obtain an optimal feature vector; A training module, used to improve the classification function of the Softmax algorithm by using the Cross Entropy Loss function to establish a text classification model, and to train the text classification model using the data set to obtain a text classification prediction model; An optimization module is used to optimize the parameters of the text classification prediction model by using the parameter optimization algorithm Adam to obtain the best text classification prediction model; A testing module, used for inputting the test set into the optimal text classification prediction model to obtain a classification prediction result; The feature extraction module specifically includes: An extraction unit, used for inputting the text feature word vector into the improved deep learning model by using a mini-batch gradient descent method, so as to respectively extract local features and global features of the text feature word vector; A fusion and splicing unit, used to respectively calculate the weight scores of the local features and the global features by using the Attention mechanism, and to fuse and splice the weight scores to obtain the optimal feature vector; The extraction unit is specifically used for: The text feature word vector is input into the convolutional neural network using the mini-batch gradient descent method. The convolution layer extracts multiple different feature expressions of the feature word through convolution kernels of different sizes. The pooling layer compresses and reduces the dimension of the output features of the convolution layer to obtain the local features. The text feature word vector is input into a bidirectional GRU neural network using a mini-batch gradient descent method to obtain the global feature.
Citation Information
Patent Citations
A method for sentiment analysis of film reviews based on deep learning and natural language processing
AU2020100710A4
Text emotion classification method based on the joint deep learning model
CN106599933A
Hybrid neural network text classification method capable of blending abstract with main characteristics
CN108595632A
Text classification algorithm based on a circulating neural network variant and a convolution neural network
CN109376242A
Text classification method and system fusing self-attention mechanism and deep learning
CN112926322A
