Text classification method, system, device and storage medium based on neural network

By using the parameters of the pre-trained model itself for text classification and directly performing the classification operation, it solves the problems of increased training time and reduced efficiency caused by additional construction of neural network layers in the existing technology, and achieves efficient text classification.

CN113688244BActive Publication Date: 2024-09-17CHINA PING AN LIFE INSURANCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111015077.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-08-31
Publication Date
2024-09-17
Estimated Expiration
2041-08-31

AI Technical Summary

Technical Problem

When the existing technology uses a pre-trained model for text classification, it is necessary to construct an additional fully connected layer for training, which results in the inability to fully utilize the capabilities of the pre-trained model, increases training time, and reduces real-time performance and usage efficiency.

Method used

By using the parameters of the pre-trained model itself instead of additionally constructed neural network layers, text classification can be performed directly to avoid re-training, thus improving efficiency.

Benefits of technology

It saves training time, improves the efficiency of the method, and can be effectively used without training samples or small sample data, and has a wide range of application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113688244B
    Figure CN113688244B
Patent Text Reader

Abstract

The present invention relates to artificial intelligence technology, and proposes a text classification method, system, device and storage medium based on a neural network. The method includes: predicting the word vector of each preset category according to the text to be classified and the target pre-training model, and the text to be classified conforms to the text format corresponding to the preset template; obtaining the probability of each preset category according to the word vector of each preset category and the parameters in the target pre-training model; and determining the final category of the text to be classified according to the probability of each preset category. The present invention utilizes the characteristics of the pre-training model itself, and utilizes the parameters of the pre-training model itself to replace a layer of neural network constructed outside the pre-training model in the traditional method, so that there is no need to reuse a large amount of sample data for training, thereby saving training time and improving the efficiency of the method; and it can also be used in the case of no training sample data or small sample data, and has a relatively wide range of application scenarios.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a text classification method, system, device and storage medium based on a neural network. Background Art

[0002] In the existing problem classification methods, discriminative deep learning models are usually used for processing. With the development of training technology, by inputting the problem into the pre-trained model, obtaining its representation, and then adding an additional layer of fully connected network after the pre-trained model, the problem can be classified.

[0003] Pre-training is to train the model on a large number of general corpora to learn general language knowledge, and then conduct transfer training for the task in a targeted manner. The pre-trained model is an application of transfer learning. It uses almost unlimited text to learn the contextual relationship representation of each member of the input sentence and learn general grammatical and semantic knowledge. It can also transfer knowledge learned from open fields to downstream tasks to improve low-resource tasks, which is also very beneficial for low-resource language processing. In addition, the pre-trained model has achieved the best results in almost all natural language processing (NLP) tasks.

[0004] However, since a fully connected layer is added after the pre-trained model, and the fully connected layer has not been pre-trained, the network structure parameters of this layer are not suitable for the existing classification function. Therefore, a large number of samples need to be reused to retrain the entire pre-trained model and the fully connected layer. This results in the inability to fully utilize the capabilities of the pre-trained model. Instead, a large number of samples are required for retraining, which loses the ability to learn with small samples, thereby increasing the training time and reducing the real-time and usage efficiency of the method. Summary of the invention

[0005] The present invention provides a text classification method, system, device and storage medium based on a neural network, the main purpose of which is to utilize the characteristics of the pre-trained language model itself to avoid constructing an additional layer of neural network, thereby effectively improving the efficiency of the method.

[0006] In a first aspect, an embodiment of the present invention provides a text classification method based on a neural network, comprising:

[0007] Predicting a word vector for each preset category based on the text to be classified and the target pre-trained model, wherein the text to be classified conforms to the text format corresponding to the preset template;

[0008] Obtaining the probability of each preset category according to the word vector of each preset category and the parameters in the target pre-trained model;

[0009] According to the probability of each preset category, the final category of the text to be classified is determined.

[0010] Preferably, obtaining the probability of each preset category according to the word vector of each preset category and the parameters in the target pre-trained model includes:

[0011] Obtaining a representation vector for each preset category according to the word vector for each preset category and the conversion matrix in the target pre-trained model;

[0012] According to the representation vector of each preset category, the probability of each preset category is obtained.

[0013] Preferably, the target pre-trained model is obtained by training the pre-trained model using preset text data and preset text labels, wherein:

[0014] In each round of training, the preset text data is input into the pre-training model, and the pre-training model is controlled to process the preset text data to obtain the classification result corresponding to each text in the preset text data;

[0015] Calculating the loss function of the pre-trained model according to the preset text label and the classification result;

[0016] The gradient corresponding to each functional layer in the pre-trained model is calculated according to the loss function;

[0017] The pre-trained model is updated by using the gradient and learning rate of each functional layer in the pre-trained model to update each functional layer;

[0018] After each round of training, the final updated pre-trained model is used as the target pre-trained model.

[0019] Preferably, the target pre-trained model is obtained by training the pre-trained model using preset text data and preset text labels, and is specifically obtained by the following steps:

[0020] Performing sampling with replacement on the preset text data, and merging identical sampling samples to obtain a merged sampling sample;

[0021] Taking the combined sampling samples and the preset text labels corresponding to the combined sampling samples as a training set;

[0022] The remaining sampled samples and the preset text labels corresponding to the remaining sampled samples are used as a test set, wherein the remaining sampled samples are obtained by removing the merged sampled samples from the preset text data;

[0023] The pre-training model is trained according to the training set and the test set.

[0024] Preferably, the target pre-trained model is obtained by training a preset pre-trained neural network model with a preset corpus. During the training process of the preset pre-trained neural network model, the learning rate of each functional layer of the preset pre-trained neural network model decreases from the output layer to the input layer.

[0025] Preferably, the target pre-training model is a fine-tuning pre-training model, which is obtained by the following steps:

[0026] Using preset text data and preset text labels to train a preset pre-trained neural network model to obtain a reference pre-trained model;

[0027] The reference pre-trained model is combined with a preset corpus to obtain the fine-tuned pre-trained model.

[0028] Preferably, the pre-trained model includes BERT, ALBERT, and XLNET.

[0029] Preferably, the calculation formula of the loss function is as follows:

[0030] FL(pt)=(-a)×(1-pt)γ×log(pt),

[0031] Among them, pt represents the probability value, a represents the balance weight, FL(pt) represents the loss value, and γ represents the focusing parameter.

[0032] In a second aspect, an embodiment of the present invention provides a text classification system based on a neural network, comprising:

[0033] A vector model, used to predict a word vector of each preset category based on a text to be classified and a target pre-trained model, wherein the text to be classified conforms to a text format corresponding to a preset template;

[0034] A probability model, used to obtain the probability of each preset category based on the word vector of each preset category and the parameters in the target pre-trained model;

[0035] The classification model is used to determine the final category of the text to be classified according to the probability of each preset category.

[0036] In a third aspect, an embodiment of the present invention provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned neural network-based text classification method when executing the computer program.

[0037] In a fourth aspect, an embodiment of the present invention provides a computer storage medium, wherein the computer storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above-mentioned neural network-based text classification method are implemented.

[0038] The present invention proposes a neural network-based text classification method, system, device and storage medium. The method utilizes the characteristics of the pre-trained model itself and utilizes the parameters of the pre-trained model itself to replace a layer of neural network constructed outside the pre-trained model in the traditional method, thereby eliminating the need to reuse a large amount of sample data for training, thereby saving training time and improving the efficiency of the method. The method can also be used in the absence of training sample data or small sample data, and has a relatively wide range of application scenarios. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] Figure 1 An application scenario diagram of a text classification method based on a neural network provided by an embodiment of the present invention;

[0040] Figure 2 A flowchart of a text classification method based on a neural network provided by an embodiment of the present invention;

[0041] Figure 3 A schematic diagram of the structure of a text classification system based on a neural network provided by an embodiment of the present invention;

[0042] Figure 4 A schematic diagram of the structure of a computer device provided in an embodiment of the present invention.

[0043] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0044] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.

[0045] Figure 1 An application scenario diagram of a text classification method based on a neural network provided by an embodiment of the present invention, such as Figure 1 As shown, firstly, the text to be classified and the target pre-trained model are determined in the client, and the text to be classified and the target pre-trained model are sent to the server. After the server receives the text to be classified and the target pre-trained model, the neural network-based text classification method is executed to obtain the final category of the text to be classified.

[0046] It should be noted that the server can be implemented by an independent server or a server cluster composed of multiple servers. The client can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc., but is not limited thereto. The client and the server can be connected via Bluetooth, USB (Universal Serial Bus) or other communication connection methods, which is not limited in the embodiments of the present invention.

[0047] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.

[0048] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.

[0049] Figure 2 A flowchart of a text classification method based on a neural network provided by an embodiment of the present invention is shown in FIG. Figure 2 As shown, the method includes:

[0050] S210, predicting a word vector of each preset category according to the text to be classified and the target pre-trained model, wherein the text to be classified conforms to a text format corresponding to a preset template;

[0051] A text to be classified is obtained, the format of which conforms to a preset template. For example, if the classification method is to classify questions, that is, to determine whether a sentence is correct or wrong.

[0052] The fitting goal of the pre-trained model is to determine whether an input sentence conforms to a normal language sequence. For example, if there is a sentence: Today the weather is nice, I went out. At this time, the first half of the sentence: Today the weather is nice, is input into the pre-trained model, hoping that the model can accurately predict the second half of the sentence: I went out through generation.

[0053] Based on this principle, in order to apply the pre-trained model to classification, it is necessary to construct the general input text so that the input text meets the requirements of the pre-trained model. If there is a sentence: Today the weather is nice, the rain wets my shoes, and the sentence is input into the pre-trained model, the sentence obviously does not conform to the normal speaking logic, and the pre-trained model accurately predicts the judgment content of the sentence: wrong. Therefore, in order to apply the pre-trained model to the classification problem, it is necessary to construct the original "Today the weather is nice, the rain wets my shoes" into a new sentence "Today the weather is nice, the rain wets my shoes, wrong".

[0054] Specifically, if the classification problem is a binary classification problem, and the purpose is to determine whether the input sentence is correct or incorrect, the input text is constructed according to the preset template. In the embodiment of the present invention, the sentence format is "This is a problem" + input text, and the corresponding preset category is "correct" or "incorrect". If there is an input text: "The weather is nice today, I went out", in order to determine whether this input text is correct or incorrect, the input text is constructed according to the preset template to obtain the text to be classified: "This is a problem: The weather is nice today, I went out"; if there is an input text "It rained today, I went out and my shoes got wet", it is constructed according to the preset template to obtain the text to be classified "This is a problem: It rained today, I went out and my shoes got wet", that is, the preset template in this case is the original input text plus "This is a problem".

[0055] The above is a two-category problem, it can also be a three-category, four-category, etc., and the text to be classified is constructed according to the corresponding preset template, but at this time the preset categories are three or four categories.

[0056] It should be noted that the formats under the same preset template are the same, and the formats of different preset templates are different. The process of constructing a sentence can be constructed manually or by using other calculation methods.

[0057] Input the text to be classified into the target pre-trained model to obtain the word vector corresponding to each category. Taking question classification as an example, the word vector of each category is the word vector corresponding to the correct category and the word vector corresponding to the wrong category. The word vector is a set of parameter arrays obtained through the training of the language model. There are many ways to train the language model. For example, by predicting whether the two sentences are continuous, the model updates the parameter array through onehot (unique hot encoding), fully connected parameter array w, and softmax function. Finally, the parameter array will bear the task of representing the word vector.

[0058] It should be noted that the current pre-trained models for text classification are usually customized for specific business scenarios. The establishment process includes multiple links such as word segmentation, word embedding, model data training, and online service deployment. Among them, the word embedding link refers to the process of converting the text to be classified into word vectors. Because in the field of natural language processing technology, in order to hand over natural language to the algorithms in machine learning for processing, it is first necessary to mathematically represent natural language. Word vectors are a way to mathematically represent natural language.

[0059] In addition, the early methods of mathematizing natural language were mainly based on shallow machine learning and statistics, and used one-hot (also called one-of-V, where V is the size of the dictionary) or distributive methods (such as combining word frequency, co-occurrence information, TF-IDF or entropy bags of words) to give a mathematical representation of a sentence. The main disadvantage of this representation method is that it cannot express the semantics of the language units (such as characters, words or phrase n-grams) in the sentence and the relationship between them (for example, the inner product of the vectors of any two different words is 0), and it is prone to high-dimensional sparsity problems. Therefore, word embedding is usually used, that is, the mathematical representation of words is trained through neural networks.

[0060] The main idea of ​​word embedding is to map a word into a continuous d-dimensional real vector with semantic information. Existing research has shown that word embedding can better characterize the grammatical and semantic information of text, and can be combined with deep neural networks to further improve the accuracy of model classification.

[0061] S220, obtaining the probability of each preset category according to the word vector of each preset category and the parameters in the target pre-trained model;

[0062] Then, based on the word vector of the preset category and the parameters of the target pre-trained model, the probability of each preset category is obtained.

[0063] In the prior art, the word vector of each preset category is input into the fully connected layer network to obtain the probability of each preset category. However, in the embodiments of the present invention, it is found through research that the parameters in the pre-trained model itself can replace the function of the fully connected layer in the prior art. In this way, there is no need to connect the fully connected layer after the pre-trained model, and no additional external network is required. In this way, there is no need to retrain the pre-trained model, or there is no need to retrain the pre-trained model using a large amount of sample data, thereby reducing the training time and improving the efficiency of the method.

[0064] S230, determining the final category of the text to be classified according to the probability of each preset category.

[0065] According to the probability of each preset category, for example, comparing the probability of the correct category with the probability of the wrong category, the category with a larger probability is taken as the final category of the text to be classified. If the probability of the correct category is greater than the probability of the wrong category, the text to be classified is correct. If the probability of the correct category is less than the probability of the wrong category, the text to be classified is wrong.

[0066] The embodiment of the present invention provides a text classification method based on a neural network. The method utilizes the characteristics of a pre-trained model itself and utilizes the parameters of the pre-trained model itself to replace the role of a layer of neural network constructed outside the pre-trained model in the traditional method to determine the final category of the text to be classified. Since the pre-trained model in the embodiment of the present invention can be used directly without reusing a large amount of sample data for training, the embodiment of the present invention omits the training process of the neural network model, thereby saving training time and improving the use efficiency of the method.

[0067] Based on the above embodiment, preferably, obtaining the probability of each preset category according to the word vector of each preset category and the parameters in the target pre-trained model includes:

[0068] Obtaining a representation vector for each preset category according to the word vector for each preset category and the conversion matrix in the target pre-trained model;

[0069] According to the representation vector of each preset category, the probability of each preset category is obtained.

[0070] Specifically, in the embodiment of the present invention, the parameters of the target pre-trained model itself are the conversion matrix in the target pre-trained model. By multiplying the word vector of each preset category by the conversion matrix in the target pre-trained model, the representation vector of each preset category can be obtained, and then the probability of each preset category is obtained based on the representation vector of each preset category. The representation vector of each preset category is input into the softmax function to obtain the probability of each preset category.

[0071] In the embodiment of the present invention, BERT is taken as an example of the target pre-training model. If the vocabulary size of BERT is vocab_size=32000, then each word can be represented as a 32000-dimensional one-hot word vector. The maximum length of BERT is max_length=512, which is the length of the maximum input sentence that can be received. Then the position information of each word can be represented as a 512-dimensional one-hot word vector. The training data of BERT receives sentence pairs, so two different sentences can be represented by a 2-dimensional one-hot vector.

[0072] The specific process of using BERT for text classification is as follows: segment the input text to be classified to obtain individual words; encode each word to obtain a word vector; through multi-head attention, the word vector is divided into multiple heads, representing the query input, key input, and value input respectively, and multiplied by their respective transformation matrices to obtain the query matrix, key matrix, and value matrix; then all query matrices, key matrices, and value matrices are concatenated and multiplied by all transformation matrices to finally obtain the final category.

[0073] Specifically, in the multi-head attention input query input, key input and value input need to go through three transformation matrices W Q , W K , W V To generate the query matrix Q, key matrix K, and value matrix V, you need to determine the dimensions of the three W matrices, where:

[0074] X×W Q =Q,

[0075] X×W K =K,

[0076] X×W V =V.

[0077] W=[W Q , W K , W V ], which is the conversion matrix referred to in the embodiment of the present invention.

[0078] It should be noted that if the dimension of the word vector of each preset category is d, then the dimension of the conversion matrix is ​​d*N, where N is the size of the target pre-trained model's self-dictionary, that is, the number of all preset categories that the target pre-trained model can produce.

[0079] Perform matrix multiplication on the word vector and the transformation matrix to obtain a representation vector for each preset category. The dimension of the representation vector is N, that is, each preset category in the dictionary corresponds to a value in the representation vector.

[0080] The representation vector is passed through the softmax function, S = exp(N) / Sum(exp(N)), to obtain the probability corresponding to each preset category, and the dimension of the probability is N.

[0081] On the basis of the above embodiment, preferably, the target pre-trained model is obtained by training the pre-trained model using preset text data and preset text labels, wherein:

[0082] In each round of training, the preset text data is input into the pre-training model, and the pre-training model is controlled to process the preset text data to obtain the classification result corresponding to each text in the preset text data;

[0083] Calculating the loss function of the pre-trained model according to the preset text label and the classification result;

[0084] The gradient corresponding to each functional layer in the pre-trained model is calculated according to the loss function;

[0085] The pre-trained model is updated by using the gradient and learning rate of each functional layer in the pre-trained model to update each functional layer;

[0086] After each round of training, the final updated pre-trained model is used as the target pre-trained model.

[0087] Specifically, in the embodiment of the present invention, the target pre-trained model can be obtained by re-training the pre-trained model using preset text data and preset text labels, and the pre-trained model is already trained in advance by using a preset corpus to train a preset neural network model.

[0088] The pre-trained model can be a model created to solve similar classification or recognition problems. The pre-trained model may correspond to the text classification application, but it is not 100% compatible with the text classification scenario in the embodiment of the present invention. However, it can save a lot of time for model training.

[0089] Preset text data and preset text labels can be data collected and labeled for specific applications, but the amount of data is relatively limited. Since the pre-trained model is a model that has been trained with a large amount of other similarly constructed data, retraining the pre-trained model and performing adaptive local parameter optimization does not require massive training data like training a new model. Using useful preset text data that matches the specific application and slightly adjusting the pre-trained model can enable the model to be applied to new fields and solve new classification problems.

[0090] Therefore, in order to make the weight parameters of each layer of the neural network in the target pre-trained model more in line with the classification scenario in the embodiment of the present invention, the pre-trained model can be re-trained, and a small amount of sample data can be used as the training sample data, and there is no need to use a large amount of sample data. After the pre-trained model is re-trained, the target pre-trained model is more in line with the actual usage scenario, thereby improving the prediction accuracy of the subsequent target pre-trained model.

[0091] Specifically, in each round of training, the preset text data is input into the pre-training model, and the pre-training model is controlled to process the preset text data to obtain the classification results corresponding to each text in the preset text data;

[0092] Furthermore, the pre-trained model can be trained for multiple rounds. In each round of training, the preset text data is input into the pre-trained model, and the pre-trained model is controlled to process the preset text data to obtain the classification results corresponding to each text in the preset text data. It should be noted that the basis of each round of training is the pre-trained model after the previous round of training.

[0093] According to the classification labels and classification results corresponding to each text in the preset text data, the loss function of the pre-trained model is calculated. Specifically, the loss function of the pre-trained model is as follows:

[0094] FL(pt)=(-a)×(1-pt)γ×log(pt),

[0095] Among them, pt represents the probability value, a represents the balance weight, FL(pt) represents the loss value, and γ represents the focusing parameter.

[0096] The gradients corresponding to each functional layer in the pre-trained model are calculated based on the loss function. If the pre-trained model includes other parts, such as a subsequent task model, the gradients corresponding to the subsequent task model are calculated based on the loss function. Specifically, the gradients corresponding to each functional layer refer to the gradients corresponding to each parameter in each functional layer, and the gradients corresponding to the subsequent task model are also the gradients corresponding to each parameter in the subsequent task model.

[0097] The gradient and learning rate of each functional layer in the pre-trained model are used to update each functional layer accordingly. That is, for each functional layer, the gradient and learning rate of the functional layer are used to update the parameters of the functional layer. Similarly, the gradient and learning rate of the subsequent task model can be used to update the parameters of the subsequent task model. Specifically, the method of updating the parameters by updating the gradient and learning rate of the parameters can refer to the parameter updating method of the existing machine learning model, which will not be described in detail here. After updating the model parameters of each part in the pre-trained model, one round of training is completed.

[0098] After multiple rounds of training for the pre-trained model, the final updated pre-trained model is used as the target pre-trained model. The stop condition of the iterative training can be preset, for example, the training can be stopped when the number of training rounds reaches a preset maximum number of rounds, or when the loss function of the pre-trained model is detected to converge, or when the training time reaches a preset maximum training time.

[0099] It should be noted that the target pre-training model is a type of neural network. The training process of the target pre-training model can be divided into three steps: defining the structure of the target pre-training model and the output results of the forward propagation; defining the loss function and the back-propagation optimization algorithm; and finally generating a session and repeatedly running the back-propagation optimization algorithm on the training data.

[0100] Among them, neurons are the smallest units that constitute neural networks. A neuron can have multiple inputs and one output. The input of each neuron can be the output of other neurons or the input of the entire neural network. The output of the neural network is the weighted sum of the inputs of all neurons. The weights of different inputs are the neuron parameters. The optimization process of the neural network is the process of optimizing the values ​​of neuron parameters.

[0101] The effect of the neural network and the optimization goal are defined by the loss function, which gives the calculation formula for the difference between the output of the neural network and the true label. Supervised learning is a way of training neural networks. The idea is that the results given by the neural network should be as close to the true answer (i.e., label) as possible on the labeled data set with known answers. The training data is fitted by adjusting the parameters in the neural network, so that the neural network can provide prediction capabilities for unknown samples.

[0102] The back propagation algorithm implements an iterative process. At the beginning of each iteration, a portion of the training data is first taken and the prediction result of the neural network is obtained through the forward propagation algorithm. Because the training data has the correct answer, the gap between the predicted result and the correct answer can be calculated. Based on this gap, the back propagation algorithm will update the value of the neural network parameters accordingly to make it closer to the real answer.

[0103] It should be noted that after retraining, the weight parameters between the neurons in the target pre-trained model will definitely change compared with the original pre-trained model. Therefore, in this case, the target pre-trained model's own parameters are the pre-trained model's own parameters after retraining, that is, the transformation matrix of the target pre-trained model is the transformation matrix of the pre-trained model after retraining.

[0104] Based on the above embodiment, preferably, the target pre-trained model is obtained by training the pre-trained model using preset text data and preset text labels, and is specifically obtained by the following steps:

[0105] Performing sampling with replacement on the preset text data, and merging identical sampling samples to obtain a merged sampling sample;

[0106] Taking the combined sampling samples and the preset text labels corresponding to the combined sampling samples as a training set;

[0107] The remaining sampled samples and the preset text labels corresponding to the remaining sampled samples are used as a test set, wherein the remaining sampled samples are obtained by removing the merged sampled samples from the preset text data;

[0108] The pre-training model is trained according to the training set and the test set.

[0109] Specifically, in addition to the above-mentioned method of training a pre-trained model using preset text data and preset text labels, an embodiment of the present invention also provides another method for training a pre-trained model.

[0110] First, the preset text data is used as a data set, and the data in the data set is sampled with replacement. Sampling with replacement is one of the operation methods of simple random sampling. For the sampled samples in the data set, each sample is put back into the data set after it is drawn. For any sampling, since the overall capacity remains unchanged, each sample has an equal chance of being selected.

[0111] The extracted sampling samples are merged. Merging means recording the repeated sampling samples as 1 and removing the others to obtain the merged sampling samples. Then the merged sampling samples and the preset text labels corresponding to the merged sampling samples are used as the training set, and the data after removing the merged sampling samples from the data set are used as the remaining sampling samples, and the remaining sampling samples and the preset text labels corresponding to the remaining sampling samples are used as the test set.

[0112] The pre-trained model is trained using the training set, and the target pre-trained model is tested using the test set to obtain the test results.

[0113] Using the data in the training set, the pre-trained model can be locally optimized and trained, and the parameters of certain intermediate layers of the pre-trained model can be adjusted to make the target pre-trained model suitable for the data type in the constructed data set, and then the target pre-trained model can be applied to tasks such as classification or recognition of the corresponding data type.

[0114] Then, the target pre-trained model is evaluated based on the test results to determine whether the test results meet the preset application requirements. When the test results meet the preset application requirements, the target pre-trained model is directly output; when the test results do not meet the preset application requirements, the preset text data in the data set is re-sampled and replaced, and the sampled samples are merged to obtain a new training set, and the pre-trained model is re-trained using the new training set. This process is repeated until the test results of the target pre-trained model finally meet the preset application requirements.

[0115] In a specific embodiment, the test result can be the classification accuracy of the target pre-trained model after training the training set on the test set. When the classification accuracy is greater than or equal to the preset threshold, that is, the test result meets the preset application requirements, it can be considered that the local optimization of the pre-trained model has achieved the expected purpose, and the model can be reliably applied to tasks such as classification or recognition of corresponding data types.

[0116] When the classification accuracy is less than the preset threshold, that is, the test result does not meet the preset application requirements, it means that the pre-trained model still needs to continue to be optimized and trained. By repeatedly executing the above steps, it is possible to achieve repeated training and testing of the pre-trained model with different training sets and their test sets, thereby continuously optimizing the local parameters of the pre-trained model, and ultimately making the test results meet the preset application requirements, thereby ensuring that the pre-trained model finally output by the embodiment of the present invention can be reliably applied to the classification or recognition tasks of the corresponding data types.

[0117] A data set with limited data volume is divided into a training set and a test set by sampling. Since the samples obtained in each sampling are different, multiple different training sets and corresponding test sets can be obtained on a data set with limited data volume through sampling, thereby realizing model optimization training based on limited data.

[0118] On the basis of the above embodiments, preferably, the target pre-trained model is obtained by training a preset pre-trained neural network model with a preset corpus, and during the training process of the preset pre-trained neural network model, the learning rate of each functional layer of the preset pre-trained neural network model decreases from the output layer to the input layer.

[0119] Specifically, the overall learning rate of the preset pre-trained neural network model is obtained, and the learning rate of each functional layer in the preset pre-trained neural network model is determined according to the overall learning rate, and the steps are: the overall learning rate is used as the learning rate of the functional layer of the preset pre-trained neural network model that is closest to the output layer. Based on the learning rate of the functional layer closest to the output layer, the output layer direction is taken as the upper direction, and the input layer direction is taken as the lower direction, and the learning rate of the upper functional layer corresponding to each functional layer is divided by the preset value, and the result is used as the learning rate of each functional layer, wherein the preset value is greater than one.

[0120] The preset pre-trained neural network model is trained according to the learning rate of each functional layer of the preset pre-trained neural network model to obtain a target pre-trained model.

[0121] Since the pre-trained model has been trained with a large amount of other similarly constructed data, although the weight parameters in its network are not 100% applicable to the new classification scenario, it can still complete the classification task if used directly, but the classification accuracy is not as high as the target pre-trained model after retraining. It can be used to complete some relatively simple text classification tasks.

[0122] Therefore, the target pre-trained model can also be obtained by directly training the pre-trained neural network model with a preset corpus. Generally, when the target pre-trained model is needed, it can be used directly. In this case, the parameters of the target pre-trained model itself are the parameters of the pre-trained model after training with the preset corpus.

[0123] In the embodiment of the present invention, even in the absence of sample data, the parameters of the pre-trained model itself can be used to complete the classification task. Even in the absence of sample data, it can be applied and has strong practicality.

[0124] Based on the above embodiment, preferably, the target pre-training model is a fine-tuning pre-training model, which is obtained by the following steps:

[0125] Using preset text data and preset text labels to train a preset pre-trained neural network model to obtain a reference pre-trained model;

[0126] The reference pre-trained model is combined with a preset corpus to obtain the fine-tuned pre-trained model.

[0127] The target pre-trained model may be a model obtained by retraining the pre-trained model in the above-mentioned embodiment, or may be an original pre-trained model, or may be a pre-trained model after fine-tuning in the embodiment of the present invention.

[0128] Specifically, the pre-trained neural network model is first trained using the training samples to obtain a reference pre-trained model. The preset corpus is a special dictionary or recognition rules. When the fine-tuning pre-trained model combining the reference pre-trained model and the preset corpus is subsequently used, the marked text data can be input into the preset corpus, which will be matched with the special dictionary of the preset corpus and generate the corresponding feature vector according to the recognition rules.

[0129] It is understandable that the preset corpus can be specially customized according to the business requirements of the scenario type to which the labeled text data belongs, that is, each scenario type corresponds to a fine-tuned pre-trained model, and these fine-tuned pre-trained models contain different preset corpora, but the same pre-trained models.

[0130] Based on the above embodiments, preferably, the pre-trained model includes BERT, ALBERT, and XLNET.

[0131] It should be noted that the model architecture of BERT (Bidirectional Encoder Representation from Transformers) and ERT is based on multi-layer bidirectional transformation decoding. Because the decoder cannot obtain the information to be predicted, the main innovations of the model are in the pre-training method, that is, the MaskedLM and Next Sentence Prediction methods are used to capture the performance at the word and sentence levels respectively.

[0132] The "bidirectional" means that when the model processes a certain word, it can use the information of both the previous word and the following word at the same time. The source of this "bidirectional" is that BERT is different from the traditional language model. It does not predict the most likely current word based on all the previous words, but randomly masks some words and uses all the unmasked words for prediction.

[0133] ALBERT is a lightweight BERT model, which has 18 times smaller parameters than the BERT model and outperforms BERT.

[0134] Xlnet is another major breakthrough in natural language processing (NLP) since the creation of the BERT pre-training-fine-tuning model. Xlnet integrates language model features such as autoregression (AR, unidirectional language model) and autoencoding (AE, bidirectional language model), uses the most advanced transformer feature extractor (transformer-xl, using the segmentation cycle mechanism and relative position encoding for high concurrency-very long text processing), and pioneered the permutation language model (Permutation Language Modeling).

[0135] In summary, the embodiment of the present invention provides a text classification method based on a neural network. The method utilizes the characteristics of the pre-trained model itself and utilizes the parameters of the pre-trained model itself to replace the role of a layer of neural network constructed outside the pre-trained model in the traditional method to determine the final category of the text to be classified. Since the pre-trained model in the embodiment of the present invention can be used directly without reusing a large amount of sample data for training, the embodiment of the present invention omits the training process of the neural network model, thereby saving training time and improving the efficiency of the method.

[0136] Moreover, since the pre-trained model has been trained with a large amount of other similarly constructed data, retraining the pre-trained model for adaptive local parameter optimization does not require a large amount of training data like training a new model. Using useful preset text data that fits the specific situation and slightly adjusting the pre-trained model can enable the model to be applied to a completely new field and solve new classification problems. Even if re-training is required, it is not necessary to use a large amount of sample data, so the training time will not be too long, and the classification accuracy of the text to be classified can be improved.

[0137] Finally, even in the absence of sample data, the parameters of the pre-trained model itself can be used to complete the classification task. It can be applied even in the absence of sample data and has strong practicality.

[0138] Figure 3 A structural diagram of a neural network-based text classification system provided by an embodiment of the present invention is shown in FIG. Figure 3 As shown, the system includes: a vector model 310, a probability model 320 and a classification model 330, wherein:

[0139] The vector model 310 is used to predict the word vector of each preset category according to the text to be classified and the target pre-trained model, wherein the text to be classified conforms to the text format corresponding to the preset template;

[0140] The probability model 320 is used to obtain the probability of each preset category according to the word vector of each preset category and the parameters in the target pre-trained model;

[0141] The classification model 330 is used to determine the final category of the text to be classified according to the probability of each preset category.

[0142] Based on the above embodiment, preferably, the probability module includes a conversion unit and a calculation unit, wherein:

[0143] The conversion unit is used to obtain a representation vector of each preset category according to the word vector of each preset category and the conversion matrix in the target pre-trained model;

[0144] The calculation unit is used to obtain the probability of each preset category according to the representation vector of each preset category.

[0145] On the basis of the above embodiment, preferably, it further includes a first training module, wherein the first training module is used to train the pre-training model using preset text data and preset text labels to obtain the target pre-training model.

[0146] Based on the above embodiment, preferably, the first training module includes a sampling unit, a training set unit, a test set unit and a training unit, wherein:

[0147] The sampling unit is used to perform sampling with replacement on the preset text data, and merge the same sampling samples to obtain a merged sampling sample;

[0148] The training set unit is used to use the combined sampling samples and the preset text labels corresponding to the combined sampling samples as the training set;

[0149] The test set unit is used to use the remaining sampled samples and the preset text labels corresponding to the remaining sampled samples as the test set, wherein the remaining sampled samples are obtained by removing the merged sampled samples from the preset text data;

[0150] The training unit is used to train the pre-trained model according to the training set and the test set.

[0151] On the basis of the above embodiment, preferably, it further includes a second training module, wherein the second training module is used to train a preset pre-trained neural network model through a preset corpus to obtain the target pre-trained model.

[0152] On the basis of the above embodiment, preferably, a third training module is further included, and the third training module includes a pre-training unit and a fine-tuning unit, wherein:

[0153] The pre-training unit is used to train a preset pre-trained neural network model using preset text data and preset text labels to obtain a target pre-trained model;

[0154] The fine-tuning unit is used to combine the target pre-training model with a preset corpus to obtain the fine-tuning pre-training model.

[0155] This embodiment is a system embodiment corresponding to the above method embodiment, and its specific execution process is the same as that of the above method embodiment. For details, please refer to the above method embodiment, and this system embodiment will not be repeated here.

[0156] Each module in the above-mentioned neural network-based text classification system can be implemented in whole or in part by software, hardware, or a combination thereof. Each of the above-mentioned modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.

[0157] Figure 4 A schematic diagram of the structure of a computer device provided by an embodiment of the present invention is shown in FIG. Figure 4As shown, the computer device can be a server, and the computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a computer storage medium and an internal memory. The computer storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the computer storage medium. The database of the computer device is used to store data generated or obtained during the execution of the text classification method based on a neural network, such as a process node number and a target business node. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a text classification method based on a neural network is implemented.

[0158] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the neural network-based text classification method in the above embodiment when executing the computer program. Alternatively, the processor implements the functions of each module / unit in the embodiment of the neural network-based text classification system when executing the computer program.

[0159] In one embodiment, a computer storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the text classification method based on a neural network in the above embodiment are implemented. Alternatively, when the computer program is executed by a processor, the functions of each module / unit in the embodiment of the text classification system based on a neural network are implemented.

[0160] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0161] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.

[0162] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.

Claims

1. A text classification method based on neural network, characterized in that: include: Predicting a word vector for each preset category based on the text to be classified and the target pre-trained model, wherein the text to be classified conforms to the text format corresponding to the preset template; Obtaining the probability of each preset category according to the word vector of each preset category and the parameters in the target pre-trained model; Determining the final category of the text to be classified according to the probability of each preset category; The obtaining the probability of each preset category according to the word vector of each preset category and the parameters in the target pre-trained model includes: Obtaining a representation vector for each preset category according to the word vector for each preset category and the conversion matrix in the target pre-trained model; Obtaining the probability of each preset category according to the representation vector of each preset category; The target pre-training model is a fine-tuning pre-training model, which is obtained by the following steps: Using preset text data and preset text labels to train a preset pre-trained neural network model to obtain a reference pre-trained model; The reference pre-trained model is combined with a preset corpus to obtain the fine-tuned pre-trained model.

2. The neural network-based text classification method according to claim 1, characterized in that: The target pre-trained model is obtained by training the pre-trained model using preset text data and preset text labels, wherein: In each round of training, the preset text data is input into the pre-training model, and the pre-training model is controlled to process the preset text data to obtain the classification result corresponding to each text in the preset text data; Calculating the loss function of the pre-trained model according to the preset text label and the classification result; The gradient corresponding to each functional layer in the pre-trained model is calculated according to the loss function; The pre-trained model is updated by using the gradient and learning rate of each functional layer in the pre-trained model to update each functional layer; After each round of training, the final updated pre-trained model is used as the target pre-trained model.

3. The neural network-based text classification method according to claim 2, characterized in that: The target pre-trained model is obtained by training the pre-trained model using preset text data and preset text labels, and is specifically obtained through the following steps: Performing sampling with replacement on the preset text data, merging identical sampling samples, and obtaining a merged sampling sample; Taking the combined sampling samples and the preset text labels corresponding to the combined sampling samples as a training set; The remaining sampled samples and the preset text labels corresponding to the remaining sampled samples are used as a test set, wherein the remaining sampled samples are obtained by removing the merged sampled samples from the preset text data; The pre-training model is trained according to the training set and the test set.

4. The text classification method based on neural network according to claim 1, characterized in that: The target pre-trained model is obtained by training a preset pre-trained neural network model with a preset corpus. During the training process of the preset pre-trained neural network model, the learning rate of each functional layer of the preset pre-trained neural network model decreases from the output layer to the input layer.

5. The neural network-based text classification method according to claim 2, characterized in that: The calculation formula of the loss function is as follows: FL(pt)=(-a)×(1-pt)γ×log(pt), Among them, pt represents the probability value, a represents the balance weight, FL(pt) represents the loss value, and γ represents the focusing parameter.

6. A text classification system based on a neural network, characterized in that: include: A vector model, used to predict a word vector of each preset category based on a text to be classified and a target pre-trained model, wherein the text to be classified conforms to a text format corresponding to a preset template; A probability model, used to obtain the probability of each preset category based on the word vector of each preset category and the parameters in the target pre-trained model; A classification model, used to determine the final category of the text to be classified according to the probability of each preset category; The obtaining the probability of each preset category according to the word vector of each preset category and the parameters in the target pre-trained model includes: Obtaining a representation vector for each preset category according to the word vector for each preset category and the conversion matrix in the target pre-trained model; Obtaining the probability of each preset category according to the representation vector of each preset category; The target pre-training model is a fine-tuning pre-training model, which is obtained by the following steps: Using preset text data and preset text labels to train a preset pre-trained neural network model to obtain a reference pre-trained model; The reference pre-trained model is combined with a preset corpus to obtain the fine-tuned pre-trained model.

7. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the neural network-based text classification method according to any one of claims 1 to 5 are implemented.

8. A computer storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the neural network-based text classification method according to any one of claims 1 to 5 are implemented.