A text classification method, device, storage medium and electronic device
By using the traditional cross-entropy loss function and the improved Focal loss function in text classification, combined with text semantic clustering, and dynamically adjusting the weights of the loss function, a target text classification model is generated. This solves the problems of low training efficiency and inaccurate classification caused by the imbalance of dataset label distribution, and achieves higher text classification accuracy and efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-18
- Publication Date
- 2026-03-24
AI Technical Summary
Existing text classification methods suffer from low training efficiency and difficulty in accurate classification when the dataset labels are imbalanced. Traditional data augmentation and weight adjustment methods have failed to effectively improve model performance.
The traditional cross-entropy loss function is used for initial training. Combined with the improved Focal loss function, the target text classification model is generated by text semantic clustering and dynamic adjustment of loss function weights, forcing the model to learn labels with uneven data distribution.
It improves the accuracy and efficiency of text classification, effectively enhances the model's classification ability under uneven data distribution, and reduces overfitting and local optima problems for certain labels.
Smart Images

Figure CN116467451B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of finance, artificial intelligence and finance, in particular to a text classification method and device, a storage medium and an electronic equipment. BACKGROUND
[0002] In actual production work, many tasks encountered are not balanced in terms of data set label distribution, that is, a certain class of label accounts for a high proportion in the data set. This will cause low training efficiency, because most samples are simple targets, and these samples provide little useful information to the model during training; and the great advantage of the number of simple samples will also cause the training to fail, causing the model performance to degrade. At present, the common methods to solve these problems are to perform some form of difficult sample mining, the implementation is to select difficult samples during training or use more complex sampling, and re-weight the samples. For specific text classification problems, more content can be generated for sample-deficient data to supplement the deficiencies of the original data during data augmentation. The traditional focal loss is to give different weights to different classes of labels during the training process when calculating the loss, so that the data with low proportion can obtain higher loss weight, so as to make the model focus on learning this part. However, in actual use, simply augmenting data cannot improve the performance of the model, because the generated data is based on a small amount of seed data and will not change much; and simply based on the proportion of data distribution based on different weights cannot guarantee that the model will focus on the correct label, so that the text classification is not accurate enough. SUMMARY
[0003] Therefore, the present application provides a text classification method, device, storage medium and electronic equipment, which mainly aims to solve the problem of inaccurate text classification.
[0004] To solve the above problems, the present application provides a text classification method, comprising:
[0005] Obtain a plurality of training sample data;
[0006] Train a preset model based on each of the training sample data and a preset first loss function, to generate an initial text classification model;
[0007] Train the initial text classification model based on each of the training sample data and a preset second loss function, to generate a target text classification model;
[0008] Classify the text to be classified based on the target text classification model to obtain a target text category corresponding to the text to be classified.
[0009] Optionally, the preset model is trained based on the test sample data and a preset first loss function to generate an initial text classification model, specifically including:
[0010] The preset model is used to process data based on the training sample data to obtain first prediction label data corresponding to each of the training sample data.
[0011] The preset model is trained based on the initial label data carried by each of the training sample data, the first prediction label data, and a first preset loss function to generate the initial text classification model.
[0012] Optionally, the preset model is trained based on the initial label data carried by each of the test sample data, the prediction label data, and a first preset loss function to generate the initial text classification model, specifically including:
[0013] The first accuracy rate and the first loss value of the current model are obtained by performing calculation and processing based on the initial label data and the prediction label data corresponding to each of the initial label data.
[0014] When the first accuracy rate exceeds a first preset threshold and / or the first loss value is less than a second preset threshold, the initial text classification model is obtained.
[0015] Optionally, the initial text classification model is trained based on the training sample data and a preset second loss function to generate a target text classification model, specifically including:
[0016] Second accuracy rates corresponding to each of the preset categories are obtained based on the training sample data and the initial text classification model.
[0017] An initial weight value corresponding to a target preset category is obtained based on the average dispersion degree corresponding to the target preset category and the second accuracy rate.
[0018] A second loss value corresponding to the initial text classification model is obtained by performing loss value calculation and processing based on the second accuracy rates and the initial weight values using a preset second loss function.
[0019] The second loss value is judged based on the second loss value.
[0020] The target text classification model is obtained based on the judgment result.
[0021] Optionally, before the initial text classification model is trained based on the training sample data and a preset second loss function to generate a target text classification model, the method further includes:
[0022] performing text semantic clustering processing on each of the training sample data to obtain a dispersion degree corresponding to each of the training sample data;
[0023] calculating an average dispersion degree of the training samples of the same label category based on each of the dispersion degrees to obtain an average dispersion degree corresponding to each of the preset categories.
[0024] Optionally, the obtaining of the second accuracy rate corresponding to each of the preset categories based on the training sample data and the initial text classification model includes:
[0025] randomly obtaining a plurality of first target training sample data from each of the training sample data;
[0026] performing data processing on each of the first target training sample data by using the initial text classification model to generate second prediction label data corresponding to each of the target training sample data;
[0027] performing calculation processing based on each of the target training sample data and each of the second prediction label data to obtain a second accuracy rate corresponding to each of the preset categories.
[0028] Optionally, the obtaining of the target text classification model based on the judgment result includes:
[0029] when the judgment result is that the second loss value is greater than the second preset loss value threshold, performing parameter adjustment on the initial text classification model by using a preset model back propagation algorithm based on the second loss value to obtain a current text classification model;
[0030] randomly obtaining a plurality of second target training sample data from each of the training sample data;
[0031] updating the current text classification model by using a second preset loss function based on each of the second target training sample data in a loop until the current loss value is less than or equal to the second preset loss value threshold to obtain the target text classification model;
[0032] when the judgment result is that the second loss value is less than or equal to the second preset loss value threshold, obtaining the target text classification model based on the initial text classification model.
[0033] To solve the above problems, the present application provides a text classification device, which comprises:
[0034] an obtaining module configured to obtain a plurality of training sample data;
[0035] an initial text classification model training module configured to train a preset model based on each of the training sample data and a preset first loss function to generate an initial text classification model;
[0036] The target text classification model training module is configured to train the initial text classification model based on the training sample data and a preset second loss function, and generate a target text classification model.
[0037] The data processing module is configured to perform data processing on the text to be classified by using the target text classification model, and obtain a target text category corresponding to the text to be classified.
[0038] To solve the above problems, the present application provides a storage medium, which stores a computer program. When the computer program is executed by a processor, the steps of the above-mentioned text classification method are implemented.
[0039] To solve the above problems, the present application provides an electronic device, which at least includes a memory and a processor. The memory stores a computer program. When the processor executes the computer program stored in the memory, the steps of the above-mentioned text classification method are implemented.
[0040] The present application obtains a plurality of training sample data, trains a preset model based on the training sample data and a preset first loss function to generate an initial text classification model, trains the initial text classification model based on the training sample data and a preset second loss function to generate a target text classification model, and performs data processing on the text to be classified by using the target text classification model to obtain a target text category corresponding to the text to be classified. The preset model is initially trained by using a traditional cross-entropy loss function to generate an initial text classification model, and the initial text classification model is trained by using an improved second loss function to generate a target text classification model. The text to be classified is classified based on the target text classification model to obtain a target text category corresponding to the text to be classified. The text classification method of the present application can improve the accuracy and efficiency of text classification.
[0041] The above description is only a summary of the technical solutions of the present application. In order to more clearly understand the technical means of the present application, the content of the specification can be implemented, and in order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific embodiments of the present application are described below. BRIEF DESCRIPTION OF DRAWINGS
[0042] By reading the detailed description of the preferred embodiments below, various other advantages and benefits will become clear to those of ordinary skill in the art. The drawings are only for the purpose of illustrating the preferred embodiments and are not considered as limiting the present application. Moreover, the same reference symbols are used throughout the drawings to represent the same components. In the drawings:
[0043] Figure 1A flow chart of a text classification method provided for an embodiment of the present application;
[0044] Figure 2 A flow chart of a text classification method provided for another embodiment of the present application;
[0045] Figure 3 A structure block diagram of a text classification apparatus provided for another embodiment of the present application. DETAILED DESCRIPTION
[0046] Various aspects and features of the present application are described herein with reference to the drawings.
[0047] It is to be understood that various modifications can be made to the embodiments described herein. Thus, the description is not to be considered as limiting, but merely as a description of exemplary embodiments. Other modifications of the application will occur to those skilled in the art upon reading the present disclosure.
[0048] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments of the present application and, together with the general description of the application given above, and the detailed description of the embodiments given below, serve to explain the principles of the present application.
[0049] These and other characteristics of the present application will become apparent upon consideration of the following detailed description taken in conjunction with the accompanying drawings.
[0050] It should also be understood that, although the present application has been described in relation to certain specific examples, many other equivalents and modifications are possible.
[0051] The above and other aspects, features, and advantages of the present application will become more apparent upon consideration of the following detailed description taken in conjunction with the accompanying drawings, in which:
[0052] Specific embodiments of the present application are described hereinafter, with reference to the accompanying drawings; however, it will be understood that the application is not limited to the specific examples described, but encompasses many other embodiments. Well-known and / or repeated functions and structures are not described in detail to avoid obscuring the application in unnecessary or redundant detail. Therefore, specific structural and functional details disclosed herein are not intended to limit the scope of the application, but merely to illustrate representative embodiments of the application.
[0053] The specification can use phrases such as "in one embodiment", "in another embodiment", "in yet another embodiment", or "in other embodiments", which can refer to one or more of the same or different embodiments of the application.
[0054] The embodiment of the application provides a text classification method, as shown in the method, comprising the following steps: Figure 1
[0055] Step S101: acquiring a plurality of training sample data;
[0056] In the application process, in the insurance agent application scenario of an insurance company, there are text categories such as a willingness to quote, value-added services, and a quote cashback. In the process of a call, a user often speaks in a long speech, and an artificial person labels a tag category for each speech by analyzing each speech. The text classification method of the application can be applied to any scenario that needs to classify text, and the application does not limit the application scenario.
[0057] Step S102: training a preset model based on each of the training sample data and a preset first loss function, and generating an initial text classification model;
[0058] In the application process, the preset model is used for data processing based on each of the training sample data, and first prediction label data corresponding to each of the training sample data is obtained. The preset model is trained based on initial label data carried by each of the training sample data, each of the first prediction label data, and a first preset loss function, and the initial text classification model is generated. The first preset loss function can use a traditional cross-entropy loss function to calculate a first loss value. The first accuracy and the first loss value of the current model are obtained by calculating and processing the initial label data and the prediction label data corresponding to each of the initial label data. When the first accuracy exceeds a first preset value and / or the first loss value is less than a second preset value, the initial text classification model is obtained. When the first accuracy is less than or equal to the first preset threshold and / or the first loss value is greater than or equal to the second preset threshold, the parameters of the preset model are updated based on the first loss value using a back propagation algorithm until the loss value of the updated preset model satisfies the first preset value, and the initial text classification model is obtained.
[0059] Step S103: training the initial text classification model based on each of the training sample data and a preset second loss function, and generating a target text classification model;
[0060] In the implementation process of the step, first: the text semantic clustering processing is performed on each training sample data to obtain the dispersion of each training sample in each preset category distribution; and the average dispersion corresponding to each preset category is obtained based on the dispersion. The average dispersion is used to calculate the weight value of the second loss function in the subsequent calculation. Then: based on the training sample data and the initial text classification model, the second accuracy corresponding to each preset category is obtained, and the second accuracy is used to calculate the weight value of the second loss function. The parameter data of the initial text classification model is updated based on the second loss value using the back propagation algorithm, and the model is updated through cyclic iteration until the obtained second loss value is less than or equal to the second loss value threshold, and the obtained model is the target text classification model.
[0061] Step S104: classifying the text to be classified based on the target text classification model to obtain a target text category corresponding to the text to be classified.
[0062] In the implementation process of the step, the text to be classified is input into the trained target text classification model to obtain a target text category corresponding to the text to be classified. The text classification method of the application effectively improves the problem that the model only learns some specific types of labels when the data distribution is uneven. By dynamically adjusting the weight of the loss function of the model in different categories during the learning process, the problem of uneven data classification can be effectively improved, and the model is forced to learn some labels with small quantities.
[0063] The application obtains a plurality of training sample data, trains a preset model based on the training sample data and a preset first loss function to generate an initial text classification model, trains the initial text classification model based on the training sample data and a preset second loss function to generate a target text classification model, and processes data of the text to be classified using the target text classification model to obtain a target text category corresponding to the text to be classified. The initial text classification model is generated by preliminarily training the preset model using a traditional cross-entropy loss function, and the target text classification model is generated by training the initial text classification model using an improved second loss function. The text to be classified is classified based on the target text classification model to obtain a target text category corresponding to the text to be classified. The text classification method of the application can improve the accuracy and efficiency of text classification.
[0064] Another embodiment of the application provides another text classification method, as shown in Figure 2 The method comprises the following steps:
[0065] Step S201: obtaining a plurality of training sample data;
[0066] In the implementation process of the present step, the training sample data can be obtained by manually labeling a plurality of texts, and the training sample data carries a class label. For example, when the preset classes include three classes A, B and C, the training sample of class A can be labeled as [1, 0, 0], indicating that the sample is class A with a probability of 100%, class B with a probability of 0%, and class C with a probability of 0%; the training sample of class B can be labeled as [0, 1, 0], indicating that the sample is class B with a probability of 100%, class A with a probability of 0%, and class C with a probability of 0%; and the training sample of class C can be labeled as [0, 0, 1], indicating that the sample is class C with a probability of 100%, class B with a probability of 0%, and class A with a probability of 0%. In the insurance company insurance seat application scenario, there are text categories such as willingness to quote, value-added services, and quote cashback. During the conversation, the user often speaks in a long sentence. By using the text classification method of the present application, various speeches can be classified to determine the category of user demand, so as to provide targeted services for the user and improve service efficiency and service quality. In the auxiliary diagnosis and treatment application scenario, during the preliminary inquiry process, the patient's symptoms and current medication can be analyzed according to the long speech of the inquirer, and the user information can be sorted. By using the text classification method of the present application, the text category of the patient can be determined, which can be a text category such as consulting symptoms, consulting drug reactions, and consulting departments. The user can be better guided to provide services and improve service efficiency. The text classification method of the present application can be applied to any scenario that needs to classify texts, and the application scenario of the present application is not limited.
[0067] Step S202: training the preset model based on each of the training sample data and a preset first loss function, to generate an initial text classification model;
[0068] In the implementation process of the present application, the preset model is used to process the data based on each training sample data, and first prediction label data corresponding to each training sample data is obtained; for example, inputting the sample with the category label [1, 0, 0] as described above into the preset model, the output label may be [0.6, 0.3, 0.1], at this time, it is indicated that the probability that the first prediction label data generated after the preset model data processing is of category A is 0.6, the probability that the first prediction label data is of category B is 0.3, and the probability that the first prediction label data is of category C is 0.1. The initial text classification model is generated by training the preset model based on the initial label data carried by each training sample data, each first prediction label data, and a first preset loss function. The first preset loss function can use a traditional cross-entropy loss function to calculate the first loss value. Initially, all samples in the initial 1 to 2 training sets in the training process can be calculated using the cross-entropy loss function, so that the model can first learn preliminarily. The first accuracy and the first loss value of the current model are obtained by calculating and processing the initial label data and the prediction label data corresponding to each initial label data. Specifically, each initial label data and the prediction label data corresponding to each initial label data are substituted into the cross-entropy loss function for calculation, and the first loss value is calculated. The first accuracy of the current model is obtained by calculating and processing the initial label data and the prediction label data corresponding to each initial label data. The specific calculation process is that the larger probability value in the prediction label data is selected as the prediction category of the current prediction label data, and then it is judged whether the prediction category is the same as the category of the initial label data corresponding to the current test label data, so as to obtain the first accuracy. When the first accuracy exceeds the first preset value and / or the first loss value is less than the second preset value, the initial text classification model is obtained. When the first accuracy is less than or equal to the first preset threshold and / or the first loss value is greater than or equal to the second preset threshold, the parameters of the preset model are updated based on the first loss value using the back propagation algorithm until the loss value of the updated preset model satisfies the first preset value, and the initial text classification model is obtained.
[0069] Step S203: performing text semantic clustering processing on each training sample data to obtain a dispersion corresponding to each training sample;
[0070] In the specific implementation process of this step, the training sample data is clustered in an unsupervised manner, and the dispersion degree of each training sample in the corresponding category can be obtained. It can be considered that the data in the first region is simple content for the model, the first region is the most central 10% data, and the model does not spend too much effort on it to obtain better results. The second region is the core region of the model clustering result, and the second region can be a region composed of data in the range of 10%-80%. The annotation of this part of data is probably correct, and it is not a special value and has good generalization. It is the content that the model needs to focus on learning. The third region may be a special case such as annotation error or data extreme value. The third region can be the outermost 10% training data. For example, most of the training data of a certain category in the current iter are concentrated in the range of 10%-80%, so a higher loss weight is assigned to the model to focus on learning. If the middle 10% or the outermost 10% data is more, a lower weight is assigned to avoid overfitting of the model or to weaken the influence of extreme points on the model. After the text semantic clustering processing of each training sample data is performed, the dispersion degree of each training sample data in the preset category can be obtained.
[0071] Step S204: Based on the dispersion degree calculation, the average dispersion degree of the training sample of the same label category is obtained, and the average dispersion degree corresponding to each preset category is obtained.
[0072] In the specific implementation process of this step, based on the dispersion degree calculation, the average dispersion degree corresponding to each preset category is obtained. Specifically, the average dispersion degree can be calculated by using the inverse ratio of the sum of the dispersion degrees of the training sample data and the sum of the dispersion degrees of the same category label data in each training sample data. The average dispersion degree corresponding to each preset category is calculated respectively. In the calculation of the loss weight, the dispersion degree of the sample data is considered. In the case where the data quality is not very high, the problems of annotation error, data extreme value and the like are effectively improved, the generalization of the model is effectively improved, and the overall performance of the model is improved.
[0073] Step S205: Based on each training sample data and the initial text classification model, a second accuracy rate corresponding to each preset category is obtained.
[0074] In the specific implementation process of this step, a plurality of target training sample data are randomly obtained from each training sample data. The initial text classification model is used for data processing based on each target training sample data, and second prediction label data corresponding to each target training sample data is generated. Based on each target training sample data and each second prediction label data, a second accuracy rate corresponding to each preset category is obtained.
[0075] Step S206: obtaining an initial weight value corresponding to the target preset category based on the average dispersion degree corresponding to the target preset category and the second accuracy rate;
[0076] In the specific implementation process, the initial weight value corresponding to the target preset category is obtained based on the average dispersion degree corresponding to the target preset category and the second accuracy rate, which can be represented by the formula: 1-target preset category average dispersion degree*target preset category second accuracy rate, so as to obtain the initial weight value corresponding to each preset category. Through this improved loss function weight calculation method, the problem that the model only learns some specific categories of labels when the data distribution is uneven is effectively improved. By dynamically adjusting the weight of the loss function of the model on different categories during the learning process, the problem of uneven data classification can be effectively improved.
[0077] Step S207: based on each initial weight value, each target training sample data and each second prediction label data, a preset second loss function is used for loss value calculation processing to obtain a second loss value corresponding to the initial text classification model;
[0078] In the specific implementation process of the present application, the second loss function can use the Focalloss loss function. The present application improves the calculation method of the weight value of the Focalloss loss function, so that the problem that the model only learns some specific categories of labels when the data distribution is uneven is effectively improved in the classification process. By dynamically adjusting the weight of the loss function of the model on different categories during the learning process, the problem of uneven data classification can be effectively improved, and the model is forced to learn some labels with small quantities. Referring to the dynamic learning rate of the model, the problem of the model falling into local optimum can also be avoided by the dynamic loss function. At the same time, the dispersion degree of the data is also considered when the weight is allocated, which effectively improves the problems of labeling errors, data extreme values and the like in the case of not particularly high data quality, effectively improves the generalization of the model and improves the overall performance of the model. Specifically, each initial weight value, each target training sample data and each second prediction label data are substituted into the second loss function for calculation processing to obtain the second loss value.
[0079] Step S208: judging based on the second loss value; obtaining the target text classification model based on the judgment result;
[0080] In the specific implementation process of this step, when the judgment result is that the second loss value is greater than the second preset loss value threshold, the initial text classification model is adjusted in parameters based on the second loss value using a preset model back propagation algorithm to obtain a current text classification model; a plurality of second target training sample data in each of the training sample data is randomly obtained; the current text classification model is updated iteratively using a second preset loss function based on each of the second target training sample data until the current loss value is less than or equal to the second preset loss value threshold, and the target text classification model is obtained; when the judgment result is that the second loss value is less than or equal to the second preset loss value threshold, the target text classification model is obtained based on the initial text classification model.
[0081] Step S209: classifying the text to be classified based on the target text classification model to obtain a target text category corresponding to the text to be classified.
[0082] In the specific implementation process of this step, the target text category corresponding to the text to be classified can be obtained by inputting the text to be classified into the trained target text classification model.
[0083] The application obtains a plurality of training sample data, trains a preset model based on the training sample data and a preset first loss function to generate an initial text classification model, and uses a traditional cross-entropy loss function to calculate a loss value to enable the model to learn preliminarily. The training sample data is subjected to text semantic clustering processing to obtain an average dispersion degree corresponding to each preset category, obtains a second accuracy rate corresponding to each preset category based on the training sample data and the initial text classification model, calculates an initial weight value corresponding to a target preset category based on the average dispersion degree and the second accuracy rate, uses a preset second loss function to calculate a loss value based on the initial weight value, each target training sample data and each second prediction label data to obtain a second loss value corresponding to the initial text classification model, trains the initial text classification model based on the training sample data and the preset second loss function to generate a target text classification model, and the second loss function in the application is improved based on the calculation of the weight of the traditional Focalloss loss function. Through the improved focalloss, the problem that the model only learns some specific categories of labels when the data distribution is uneven is effectively improved, the weight of the loss function of the model on different categories is dynamically adjusted during learning, and the problem of uneven data classification is effectively improved. The second loss value is used for judgment, the target text classification model is obtained based on the judgment result, the target text classification model is used for data processing of the text to be classified to obtain a target text category corresponding to the text to be classified. The text classification method can improve the accuracy and efficiency of text classification.
[0084] Another embodiment of the application provides a text classification device, as shown in the accompanying drawings, comprising: Figure 3
[0085] The acquisition module 1 is configured to obtain a plurality of training sample data.
[0086] The initial text classification model training module 2 is configured to train a preset model based on the training sample data and a preset first loss function to generate an initial text classification model.
[0087] The target text classification model training module 3 is configured to train the initial text classification model based on the training sample data and a preset second loss function to generate a target text classification model.
[0088] The classification module 4 is configured to classify the text to be classified based on the target text classification model to obtain a target text category corresponding to the text to be classified.
[0089] In the implementation process, the initial text classification model training module 2 is specifically configured to: perform data processing on each training sample data based on the preset model, to obtain first predicted label data corresponding to each training sample data; train the preset model based on initial label data carried by each training sample data, each first predicted label data, and a first preset loss function, to generate the initial text classification model.
[0090] In the implementation process, the initial text classification model training module 2 is further configured to: perform calculation processing on the initial label data and predicted label data corresponding to each initial label data, to obtain a first accuracy rate and a first loss value of a current model; and obtain the initial text classification model when the first accuracy rate exceeds a first preset threshold and / or the first loss value is less than a second preset threshold.
[0091] In the implementation process, the target text classification model training module 3 is specifically configured to: obtain a second accuracy rate corresponding to each preset category based on each training sample data and the initial text classification model; obtain an initial weight value corresponding to a target preset category based on an average dispersion degree corresponding to the target preset category and the second accuracy rate; perform loss value calculation processing based on each second accuracy rate and each initial weight value by using a preset second loss function, to obtain a second loss value corresponding to the initial text classification model; perform judgment based on the second loss value; and obtain the target text classification model based on the judgment result.
[0092] In the implementation process, the text classification apparatus further includes a semantic clustering module, which is specifically configured to: perform text semantic clustering processing on each training sample data, to obtain a dispersion degree corresponding to each training sample; and obtain an average dispersion degree of training samples of a same label category based on each dispersion degree, to obtain an average dispersion degree corresponding to each preset category.
[0093] In the implementation process, the target text classification model training module 3 is further configured to: randomly obtain a plurality of first target training sample data from each training sample data; perform data processing on each first target training sample data based on the initial text classification model, to generate second predicted label data corresponding to each target training sample data; and perform calculation processing based on each target training sample data and each second predicted label data, to obtain a second accuracy rate corresponding to each preset category.
[0094] In the implementation process, the target text classification model training module 3 is further configured to: when the judgment result is that the second loss value is greater than the second preset loss value threshold, adjust parameters of the initial text classification model based on the second loss value using a preset model back propagation algorithm to obtain a current text classification model; randomly obtain a plurality of second target training sample data from the training sample data; and update the current text classification model based on the second target training sample data using a second preset loss function in a loop until the current loss value is less than or equal to the second preset loss value threshold, to obtain the target text classification model; and when the judgment result is that the second loss value is less than or equal to the second preset loss value threshold, obtain the target text classification model based on the initial text classification model.
[0095] The application obtains a plurality of training sample data, trains a preset model based on the training sample data and a preset first loss function to generate an initial text classification model, trains the initial text classification model based on the training sample data and a preset second loss function to generate a target text classification model, and processes data of a text to be classified using the target text classification model to obtain a target text category corresponding to the text to be classified. The application trains a preset model using a traditional cross-entropy loss function to generate an initial text classification model, trains the initial text classification model using an improved second loss function to generate a target text classification model, and classifies a text to be classified based on the target text classification model to obtain a target text category corresponding to the text to be classified. The text classification method can improve the accuracy and efficiency of text classification.
[0096] Another embodiment of the application provides a storage medium storing a computer program, which, when executed by a processor, implements the following method steps:
[0097] Step one, obtaining a plurality of training sample data;
[0098] Step two, training a preset model based on the training sample data and a preset first loss function to generate an initial text classification model;
[0099] Step three, training the initial text classification model based on the training sample data and a preset second loss function to generate a target text classification model;
[0100] Step four, classifying a text to be classified based on the target text classification model to obtain a target text category corresponding to the text to be classified.
[0101] The specific implementation process of the above method steps can be referred to the embodiment of any of the above text classification methods, which will not be repeated here.
[0102] The application obtains a plurality of training sample data, trains a preset model based on each of the training sample data and a preset first loss function to generate an initial text classification model, trains the initial text classification model based on each of the training sample data and a preset second loss function to generate a target text classification model, and processes data of a text to be classified using the target text classification model to obtain a target text category corresponding to the text to be classified. The initial text classification model is generated by training the preset model using a traditional cross-entropy loss function, and the target text classification model is generated by training the initial text classification model using an improved second loss function. The text to be classified is classified based on the target text classification model to obtain the target text category corresponding to the text to be classified. The text classification method of the application can improve the accuracy and efficiency of text classification.
[0103] Another embodiment of the application provides an electronic device comprising at least a memory and a processor, wherein the memory stores a computer program, and the processor implements the following method steps when executing the computer program on the memory:
[0104] Step one, obtaining a plurality of training sample data;
[0105] Step two, training a preset model based on each of the training sample data and a preset first loss function to generate an initial text classification model;
[0106] Step three, training the initial text classification model based on each of the training sample data and a preset second loss function to generate a target text classification model;
[0107] Step four, classifying a text to be classified based on the target text classification model to obtain a target text category corresponding to the text to be classified.
[0108] The specific implementation process of the above method steps can be referred to the embodiment of any of the above text classification methods, which will not be repeated here.
[0109] The application obtains a plurality of training sample data, trains a preset model based on each of the training sample data and a preset first loss function to generate an initial text classification model, trains the initial text classification model based on each of the training sample data and a preset second loss function to generate a target text classification model, and processes data of a text to be classified by using the target text classification model to obtain a target text category corresponding to the text to be classified. The initial text classification model is generated by using a traditional cross-entropy loss function to preliminarily train the preset model, and the target text classification model is generated by using an improved second loss function to train the initial text classification model, so as to classify the text to be classified based on the target text classification model to obtain the target text category corresponding to the text to be classified. The text classification method can improve the accuracy and efficiency of text classification.
[0110] The above examples are only exemplary embodiments of the application and are not used to limit the application, and the protection scope of the application is defined by the claims. Those skilled in the art can make various modifications or equivalent replacements to the application within the spirit and protection scope of the application, and such modifications or equivalent replacements are also regarded as falling within the protection scope of the application.
Claims
1. A text classification method, characterized in that, include: Obtain several training sample data; The preset model is trained based on the training sample data and the preset first loss function to generate an initial text classification model; The initial text classification model is trained based on the training sample data and the preset second loss function to generate the target text classification model; Based on the target text classification model, the text to be classified is classified to obtain the target text category corresponding to the text to be classified. The step of training the initial text classification model based on the training sample data and a preset second loss function to generate the target text classification model specifically includes: Based on the training sample data and the initial text classification model, a second accuracy corresponding to the target preset category is obtained; An initial weight value corresponding to the target preset category is calculated based on the average dispersion corresponding to the target preset category and the second accuracy; the average dispersion is calculated based on the dispersion obtained after performing text semantic clustering processing on each of the training sample data; The mathematical formula for calculating the initial weight values is: Initial weight value = 1 - average dispersion of target preset category × second accuracy of target preset category; Based on the second accuracy and the initial weight value, a preset second loss function is used to calculate the loss value to obtain the second loss value corresponding to the initial text classification model. The judgment is made based on the second loss value; The target text classification model is obtained based on the judgment result; The step of obtaining a second accuracy corresponding to the target preset category based on the training sample data and the initial text classification model specifically includes: Randomly select several first target training samples from each of the training sample data; Based on the training sample data of each first target, the initial text classification model is used to process the data to generate second predicted label data corresponding to each training sample data of the target. The second accuracy corresponding to the preset category of the target is obtained by performing calculations based on the training sample data of each target and the second predicted label data of each target. The process of obtaining the target text classification model based on the judgment result specifically includes: When the judgment result is that the second loss value is greater than the second preset loss value threshold, the parameters of the initial text classification model are adjusted based on the second loss value using the preset model backpropagation algorithm to obtain the current text classification model. Randomly obtain several second target training sample data from each of the training sample data; Based on the training sample data of each second target, the current text classification model is iteratively updated using a second preset loss function until the current loss value is less than or equal to the second preset loss value threshold, thus obtaining the target text classification model. When the judgment result is that the second loss value is less than or equal to the second preset loss value threshold, the target text classification model is obtained based on the initial text classification model.
2. The method as described in claim 1, characterized in that, The step of training the preset model based on the training sample data and the preset first loss function to generate an initial text classification model specifically includes: Based on the training sample data, the preset model is used to process the data to obtain the first predicted label data corresponding to each training sample data. The preset model is trained based on the initial label data carried by each training sample data, the first predicted label data, and the first preset loss function to generate the initial text classification model.
3. The method as described in claim 2, characterized in that, The process of training the preset model based on the initial label data carried by each of the training sample data, each of the first predicted label data, and the first preset loss function to generate the initial text classification model specifically includes: Based on the initial label data and the predicted label data corresponding to each of the initial label data, the first accuracy and the first loss value of the current model are calculated and processed to obtain the first accuracy and the first loss value of the current model. When the first accuracy exceeds the first preset threshold and / or the first loss value is less than the second preset threshold, the initial text classification model is obtained.
4. The method as described in claim 1, characterized in that, Before training the initial text classification model based on the training sample data and a preset second loss function to generate the target text classification model, the method further includes: Perform text semantic clustering on each of the training sample data to obtain the discreteness corresponding to each of the training samples; The average dispersion of training samples of the same label category is calculated based on the dispersion of each of the aforementioned dispersion values, and the average dispersion of each preset category is obtained.
5. A text classification apparatus for implementing any one of the text classification methods as claimed in claims 1 to 4, characterized in that, include: Acquisition module: Used to acquire several training sample data; Initial text classification model training module: Based on the training sample data and the preset first loss function, the preset model is trained to generate the initial text classification model; Target text classification model training module: used to train the initial text classification model based on the training sample data and a preset second loss function to generate the target text classification model; Classification module: Used to classify the text to be classified based on the target text classification model, and obtain the target text category corresponding to the text to be classified.
6. A storage medium, characterized in that, The storage medium stores a computer program, which, when executed by a processor, implements the steps of the text classification method according to any one of claims 1-4.
7. An electronic device, characterized in that, It includes at least a memory and a processor, wherein the memory stores a computer program, and the processor, when executing the computer program in the memory, implements the steps of the text classification method according to any one of claims 1-4.
Citation Information
Patent Citations
Big-data asset assessment method
CN106845846A
Method and system for training classification model
CN110704627A
Text statement classification method and device, electronic equipment and storage medium
CN115510232A