Text classification data enhancement method, device, equipment and medium
By generating new enhanced text and labels through linear interpolation and weighted summation, the problem of poor data augmentation effect in text classification models is solved, and the accuracy of the model in smart healthcare and financial service scenarios is improved.
Patent Information
- Application Number
- CN202310912352.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-20
- Publication Date
- 2025-11-25
- Estimated Expiration
- 2043-07-20
AI Technical Summary
Existing text classification models perform poorly in data augmentation, making it difficult to optimize model performance by generating samples.
Initial weights are randomly generated, linear interpolation and weighted summation are performed, and a trained classifier is used for category prediction and loss calculation. The weights are then updated to generate the target enhanced text, and new enhanced text and labels are generated by linear fusion of historical texts.
This improves the effectiveness of data augmentation, making classification models trained on augmented text more accurate and enhancing their application accuracy in smart healthcare and financial services scenarios.
Smart Images

Figure CN116821689B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of data processing, and in particular to a data enhancement method and device for text classification, equipment and medium. BACKGROUND
[0002] With the rise of artificial intelligence technology, intelligent text classification tasks based on artificial intelligence models have been widely applied in various application scenarios, such as smart medical scenarios and financial service scenarios. In the smart medical scenario, it can support functions such as medical record information identification, patient management, medical record archiving, and medical record query. In the financial service scenario, it can support functions such as invoice identification, customer management, financial product recommendation, insurance policy archiving, and insurance policy query. Correspondingly, in the smart medical scenario, the input text of the text classification model can be medical record data and medical record data. In the financial service scenario, the input text of the text classification model can be insurance policy data, invoice data, and transaction record data.
[0003] However, a text classification model usually needs a large number of samples for training to ensure the accuracy and generalization ability of the model. A large number of samples means that a large amount of human resources is needed for sample labeling. Therefore, the existing method usually performs data enhancement based on known samples to obtain generated samples for model training. However, since the text classification model is sensitive to slight changes in input, the data enhancement effect is poor, and the generated samples are difficult to optimize the performance of the model. Therefore, how to improve the training effect of the data enhancement result on the model has become a problem to be solved. SUMMARY
[0004] Therefore, the embodiments of the present application provide a data enhancement method, device, equipment and medium for text classification to solve the problem of poor training effect of the data enhancement result on the model.
[0005] In a first aspect, the embodiments of the present application provide a data enhancement method for text classification, which comprises:
[0006] obtaining at least two historical texts and their category labels, and optionally taking two historical texts as first text information and second text information, respectively;
[0007] randomly generating a first initial weight, taking the difference between a preset value and the first initial weight as a second initial weight, and performing weighted summation on the first text information and the second text information and the category labels corresponding to the first text information and the second text information, respectively, according to the first initial weight and the second initial weight, to obtain an initial enhanced text and its corresponding initial enhanced label;
[0008] performing class prediction on the initial augmented text by using the trained classifier to obtain a predicted class, calculating a predicted loss according to the predicted class and the initial augmented label, and performing partial derivative calculation on the predicted loss according to the first initial weight to obtain a calculation result;
[0009] multiplying the calculation result and a preset coefficient to obtain a multiplication result, adding the multiplication result and the first initial weight to obtain a first updated weight, taking a difference between the preset value and the first updated weight as a second updated weight, and performing weighted summation on the first text information and the second text information according to the first updated weight and the second updated weight to obtain target augmented text, wherein the target augmented text is used for parameter updating of the trained classifier.
[0010] In a second aspect, an embodiment of the present application provides a data augmentation device for text classification, and the data augmentation device comprises:
[0011] a text acquisition module configured to acquire at least two historical texts and their class labels, and optionally take two historical texts as first text information and second text information respectively;
[0012] an initial augmentation module configured to randomly generate a first initial weight, take a difference between a preset value and the first initial weight as a second initial weight, and perform weighted summation on the first text information and the second text information and their corresponding class labels respectively according to the first initial weight and the second initial weight to obtain initial augmented text and its corresponding initial augmented label;
[0013] a class prediction module configured to perform class prediction on the initial augmented text by using the trained classifier to obtain a predicted class, calculate a predicted loss according to the predicted class and the initial augmented label, and perform partial derivative calculation on the predicted loss according to the first initial weight to obtain a calculation result;
[0014] a target augmentation module configured to multiply the calculation result and a preset coefficient to obtain a multiplication result, add the multiplication result and the first initial weight to obtain a first updated weight, take a difference between the preset value and the first updated weight as a second updated weight, and perform weighted summation on the first text information and the second text information according to the first updated weight and the second updated weight to obtain target augmented text, wherein the target augmented text is used for parameter updating of the trained classifier.
[0015] In a third aspect, an embodiment of the present application provides a computer device, comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, and the processor implements the data enhancement method according to the first aspect when executing the computer program.
[0016] In a fourth aspect, an embodiment of the present application provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the data enhancement method according to the first aspect.
[0017] Compared with the prior art, the embodiment of the present application has the following beneficial effects:
[0018] At least two historical texts and their category labels are obtained, optionally two historical texts are used as first text information and second text information respectively, a first initial weight is randomly generated, a difference between a preset value and the first initial weight is used as a second initial weight, the first initial weight and the second initial weight are used to respectively perform weighted summation on the first text information and the second text information and the category labels corresponding to the first text information and the second text information, to obtain an initial enhanced text and an initial enhanced label corresponding to the initial enhanced text, a trained classifier is used to perform category prediction on the initial enhanced text to obtain a predicted category, the predicted category and the initial enhanced label are used to calculate a prediction loss, the first initial weight is used to calculate a partial derivative of the prediction loss to obtain a calculation result, the calculation result is multiplied by a preset coefficient to obtain a multiplication result, the multiplication result and the first initial weight are added to obtain a first updated weight, a difference between a preset value and the first updated weight is used as a second updated weight, and the first updated weight and the second updated weight are used to perform weighted summation on the first text information and the second text information to obtain a target enhanced text, a new enhanced text and a label are obtained through linear fusion of the historical texts, so that a large amount of text data can be generated, the initial weight is updated according to the gradient, so that the target enhanced text generated based on the updated weight is more robust, the data enhancement effect is improved, the classification model trained based on the enhanced text is more accurate, the training result of the classification model is improved, and thus the application accuracy of the classification model in specific business scenarios such as smart medical scenarios and financial service scenarios is improved. BRIEF DESCRIPTION OF DRAWINGS
[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiments or the prior art description. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can also be obtained by those skilled in the art without creative labor.
[0020] Figure 1is an application environment schematic diagram of a text classification data enhancement method provided by an embodiment one of the present application;
[0021] Figure 2 is a flow schematic diagram of a text classification data enhancement method provided by an embodiment one of the present application;
[0022] Figure 3 is a structure schematic diagram of a text classification data enhancement device provided by an embodiment two of the present application;
[0023] Figure 4 is a structure schematic diagram of a computer device provided by an embodiment three of the present application. DETAILED DESCRIPTION
[0024] In the following description, for the purpose of explanation and not limitation, specific details are set forth, such as particular system configurations, techniques, etc., in order to provide a thorough understanding of the embodiments of the present application. However, it will be apparent to those skilled in the art that the present application can be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present application with unnecessary detail.
[0025] It should be understood that the term "comprises" when used in this specification and the appended claims indicates the presence of the described features, integers, steps, operations, elements, and / or components, but does not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.
[0026] It should also be understood that the term "and / or" when used in this specification and the appended claims, such as in the phrases "A and / or B" and "A and / or B and / or C", means any combination of one or more of the associated listed items, and includes one or more of the associated listed items alone, two or more of the associated listed items, and all possible combinations of one or more of the associated listed items.
[0027] As used in this specification and the appended claims, the term "if" can be construed to mean "when" or "upon" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [a described condition or event] is detected" can be construed to mean "upon determining" or "in response to determining" or "upon detecting [the described condition or event]" or "in response to detecting [the described condition or event] ", depending on the context.
[0028] In addition, in the description of the present application and the appended claims, the terms "first", "second", "third", etc. are used only to distinguish descriptions, and cannot be understood as indicating or implying relative importance.
[0029] Reference within the specification of this document to "one embodiment" or "some embodiments" means that a particular feature, structure, or characteristic described in connection with the embodiment is included in at least one embodiment of the application. The appearances of the phrase "in one embodiment" or "in some embodiments" in various places within specified
[0030] The embodiments of the present application can acquire and process related data based on artificial intelligence technology. The artificial intelligence (AI) is to use a digital computer or a machine controlled by a digital computer to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use the knowledge to obtain the best results.
[0031] The basic technology of artificial intelligence generally includes technologies such as sensors, special artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction system, mechatronics, etc. The software technology of artificial intelligence mainly includes computer vision technology, robot technology, biometric technology, speech processing technology, natural language processing technology, and machine learning / deep learning, etc.
[0032] It should be understood that the size of the serial number of each step in the following embodiments does not mean the order of execution, and the execution order of each process should be determined according to its function and inherent logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0033] In order to illustrate the technical solutions of the present application, the following will be explained by specific embodiments.
[0034] The text classification data enhancement method provided by the first embodiment of the present application can be applied to, for example Figure 1The application environment is shown in FIG. 1. The client communicates with the server. The client includes, but is not limited to, a palmtop computer, a desktop computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a cloud terminal device, a personal digital assistant (PDA), and the like computer device. The server can be a stand-alone server or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms, and the like basic cloud computing services.
[0035] The client and the server can be deployed in a specific business platform. The specific business platform can be a smart medical platform that has the functions of medical record information recognition, patient management, medical record archiving, and medical record query. The specific business platform can also be a financial service business platform that has the functions of purchasing insurance and / or financial products, policy query, policy archiving, target customer mining, customer management, and financial product recommendation.
[0036] Referring to FIG. 2, Figure 2 is a flowchart of a data augmentation method for text classification provided by an embodiment of the present application. The data augmentation method can be applied to a client in a specific business platform. The client corresponds to a computer device that connects to a server to obtain historical text and its category label from the server. The server has a storage function and can store historical text and its known category label in the specific business platform. Figure 1
[0037] As shown in FIG. 3, the data augmentation method can include the following steps: Figure 2
[0038] In step S201, at least two historical texts and their category labels are obtained. Optionally, the two historical texts are used as first text information and second text information, respectively.
[0039] The historical text can be a financial text that has been classified in the financial service business platform or a medical data text that has been classified in the smart medical platform. The historical text can be obtained within a preset historical time period. The category label can be the historical classification result corresponding to the historical text. The category label is trusted prior information. The first text information and the second text information can be the processing objects of a subsequent data augmentation task and are used to distinguish the two selected historical texts.
[0040] Specifically, the server can have a database for storing historical texts and their category labels, the client accesses the server, reads a number of historical texts from the database of the server, and the implementer can read by limiting the number of read texts, for example, reading N historical texts and their corresponding category labels from the database of the server, N can be an integer greater than one, in an embodiment, N can be 1000.
[0041] In an embodiment, the reading of historical texts can also be performed by limiting the preset historical time period, for example, setting the historical time period to the time range between one month before the current time and the current time, reading the historical texts in the preset historical time period from the database of the server to obtain N historical texts, at this time N should still satisfy the condition of being an integer greater than one.
[0042] All the obtained historical texts form a selectable text set, a historical text is randomly selected from the selectable text set as the first text information, the historical text is removed from the selectable text set, and another historical text is randomly selected from the selectable text set as the second text information.
[0043] The above steps of obtaining at least two historical texts and their category labels, and optionally two historical texts as the first text information and the second text information, provide basis information for subsequent data enhancement, so that the initial enhanced label has a certain credibility, reduces the number of updates in the data enhancement process, and improves the efficiency of the overall data enhancement process.
[0044] In step S202, a first initial weight is randomly generated, a difference between a preset value and the first initial weight is taken as a second initial weight, and the first text information and the second text information and the category labels corresponding to the first text information and the second text information are weighted and summed according to the first initial weight and the second initial weight, to obtain an initial enhanced text and its corresponding initial enhanced label.
[0045] The first initial weight can be randomly generated within a preset generation range, the first initial weight and the second initial weight can be the weights corresponding to the linear interpolation of the first text information and the second text information, the initial enhanced text can be the linear interpolation result of the two historical texts, the initial enhanced label can be the linear interpolation result of the category labels corresponding to the two historical texts, and the initial enhanced label and the initial enhanced text correspond one-to-one.
[0046] Specifically, in the embodiment, the generation range can be set as [0, 1], the preset value can be set as 1, for example, the first initial weight randomly generated is 0.6, the difference between the preset value and the first initial weight is 0.4, and the second initial weight is 0.4.
[0047] Optionally, the first text information and the second text information are weighted and summed according to the first initial weight and the second initial weight to obtain an initial enhanced text, including:
[0048] The trained embedding layer is used for feature embedding of the first text information and the second text information respectively to obtain a first embedding feature corresponding to the first text information and a second embedding feature corresponding to the second text information.
[0049] The first initial weight and the first embedding feature are multiplied to obtain a first multiplication result, the second initial weight and the second embedding feature are multiplied to obtain a second multiplication result, and the first multiplication result and the second multiplication result are added to determine an addition result as an initial embedding feature corresponding to the initial enhanced text.
[0050] Correspondingly, the trained classifier is used for category prediction of the initial enhanced text to obtain a predicted category, including:
[0051] The trained classifier is used for category prediction of the initial embedding feature to obtain a predicted category.
[0052] The trained embedding layer can perform feature vector embedding on the input text information, convert the text information into a vector form, the first embedding feature can be a feature vector representation of the first text information, the second embedding feature can be a feature vector representation of the second text information, the first multiplication result can be a weighted result of the first embedding feature, the weight corresponding to the first embedding feature is the first initial weight, the second multiplication result can be a weighted result of the second embedding feature, the weight corresponding to the second embedding feature is the second initial weight, and the initial embedding feature can be a linear interpolation calculation result of the first embedding feature and the second embedding feature.
[0053] Specifically, the embedding layer can adopt a word vector embedding layer structure of a Transformer model, at this time, the input text information is subjected to word segmentation processing to obtain a plurality of character strings, each character string is mapped to a character vector, and all character vectors form an embedding feature corresponding to the input text information.
[0054] In the embodiment, the first text information and the second text information are represented in the form of embedding features, so that the initial enhanced text based on the fusion of the first text information and the second text information can be directly calculated by linear interpolation of the embedding features, effectively improving the efficiency of data enhancement of the text information.
[0055] Optionally, the category label is a probability value sequence formed according to probabilities of the corresponding historical text belonging to at least two preset categories respectively;
[0056] According to the first initial weight and the second initial weight, the category labels corresponding to the first text information and the second text information are weighted and summed to obtain an initial enhanced label, including:
[0057] The category label corresponding to the first text information is determined as the first probability value sequence, and the category label corresponding to the second text information is determined as the second probability value sequence;
[0058] Each probability value in the first probability value sequence is multiplied by the first initial weight to obtain a first multiplication sequence;
[0059] Each probability value in the second probability value sequence is multiplied by the second initial weight to obtain a second multiplication sequence;
[0060] The first multiplication sequence and the second multiplication sequence are added to determine an addition result as an initial enhanced label of the initial enhanced text.
[0061] In the financial service scenario, the preset category can refer to a policy type category, which can include an annuity insurance category, a life insurance category, a double insurance category, a critical illness insurance category, a medical insurance category, an accident insurance category, etc. In the smart medical scenario, the preset category can refer to a patient department category, which can include a neurology department, a cardiovascular department, a respiratory department, a digestive department, a blood department, a surgery department, etc. The category label is soft label data, that is, the category label is not specific to a single preset category, but a probability value sequence representing the prediction result of the input text information by a trained classifier in the historical process. The probability value sequence can include at least two preset categories and their corresponding probability values.
[0062] Specifically, the first probability value sequence can represent the possibility of the first text information belonging to each preset category, the second probability value sequence can represent the possibility of the second text information belonging to each preset category, the first multiplication sequence can be a weighted result of the first probability value sequence, the first probability value sequence corresponds to the first initial weight, and the second multiplication sequence can be a weighted result of the second probability value sequence, the second probability value sequence corresponds to the second initial weight.
[0063] In this embodiment, the preset category can be determined according to the actual classification task. For example, if the classification task is insurance type classification, the above-mentioned policy type category is used as the preset category, and if the classification task is policy type classification, the preset category includes a policy application category, a temporary policy category, an insurance policy category, an insurance voucher category, and a batch policy category.
[0064] It should be noted that after obtaining the addition result of the first multiplication sequence and the second multiplication sequence, normalization processing can be performed on all addition values in the addition result, so that the addition result can still maintain the form of a probability sequence after the normalization processing, thereby serving as an initial enhanced label.
[0065] In this embodiment, the linear interpolation of the category label is performed in the form of a soft label, so that the interpolation result contains more information and can more effectively guide the model to train, thereby improving the accuracy of the model retraining, improving the convergence speed of the model training, and improving the training efficiency of the model.
[0066] The above-mentioned first initial weight is randomly generated, the difference between the preset value and the first initial weight is used as the second initial weight, and the first text information and the second text information and the category labels corresponding to the first text information and the second text information are respectively weighted and summed according to the first initial weight and the second initial weight, thereby obtaining the initial enhanced text and the initial enhanced label corresponding to the initial enhanced text. The data augmentation of the text is performed in a linear interpolation manner, a large number of relatively reliable enhanced texts can be generated with high efficiency, and the relevance of the enhanced text and the historical text is stronger than the data augmentation manner of the prior art through data perturbation, so that the enhanced sample is more reliable.
[0067] In step S203, the trained classifier is used to predict the category of the initial enhanced text to obtain a predicted category, and a predicted loss is calculated according to the predicted category and the initial enhanced label. The predicted loss is subjected to a partial derivative calculation according to the first initial weight to obtain a calculation result.
[0068] The trained classifier can be used to predict the possibility of the initial enhanced text belonging to each preset category, the predicted category can be the preset category to which the initial enhanced text is most likely to belong, the predicted loss can be used to guide the adjustment of the parameters, and in this embodiment, the parameters to be adjusted are the first initial weight, and the calculation result can be a gradient based on the first initial weight.
[0069] Specifically, the predicted loss can be calculated using a cross-entropy loss function, that is, if the predicted category and the initial enhanced label are inconsistent, the predicted loss is very large, and if the predicted category and the initial enhanced label are consistent, the negative of the logarithmic value of the predicted probability corresponding to the predicted category is taken as the predicted loss.
[0070] Optionally, the trained classifier is used to predict the category of the initial enhanced text to obtain a predicted category, and the predicted category comprises:
[0071] The trained classifier is used to predict the probability of the initial enhanced text belonging to each preset category to obtain a predicted probability corresponding to the preset category.
[0072] The preset category corresponding to the maximum of all prediction probabilities is determined as the prediction category.
[0073] The prediction probability can represent the possibility of the initial enhanced text belonging to the corresponding prediction category.
[0074] Specifically, the trained classifier outputs prediction values of the initial enhanced text belonging to each preset category respectively, and normalization processing is performed on all prediction values. The normalization processing can adopt an exponential normalization function, and the normalization processing result is determined as the prediction probability of the corresponding preset category.
[0075] Optionally, the prediction loss is calculated according to the prediction category and the initial enhanced label, and the prediction loss includes:
[0076] The prediction probability sequence is formed according to all prediction probabilities.
[0077] The prediction loss is calculated according to the prediction probability sequence, the initial enhanced label, and the preset prediction loss function.
[0078] The prediction probability sequence includes each preset category and the corresponding prediction probability, and the prediction loss function can adopt a distance measurement function such as Euclidean distance or cosine similarity.
[0079] Specifically, in this embodiment, Euclidean distance is used as the prediction loss function. For any preset category, the prediction probability corresponding to the preset category is subtracted from the probability value, and the squared calculation is performed on the subtraction result to obtain a squared value corresponding to the preset category. After adding all squared values, the square root calculation is performed to determine the square root calculation result as the Euclidean distance calculation result, that is, the prediction loss.
[0080] In this embodiment, the loss function is calculated by using the soft label, so that the prediction loss is more reliable, and the update gradient of the first initial weight calculated based on the prediction loss is more consistent with the real update gradient direction, thereby improving the update efficiency of the first initial weight.
[0081] Compared with the update of the input data in the conventional data enhancement manner, the weight of the linear interpolation is updated in this embodiment, which avoids the great change of the output result of the classifier caused by the slight change of the input data, so that the generated enhanced data is more robust.
[0082] Step S204, multiplying the calculation result and the preset coefficient to obtain a multiplication result, adding the multiplication result and the first initial weight to obtain a first updated weight, taking the difference between a preset value and the first updated weight as a second updated weight, and performing weighted summation on the first text information and the second text information according to the first updated weight and the second updated weight to obtain a target enhanced text, the target enhanced text being used for parameter updating of the trained classifier.
[0083] The preset coefficient can be used to constrain the update amount of the first initial weight, the multiplication result can be the update amount of the first initial weight, the first updated weight can be the updated first initial weight, the first updated weight corresponds to the first text information, the second updated weight corresponds to the second text information, and the target enhanced text can be used as sample data for model training.
[0084] Specifically, a plurality of historical texts and a plurality of target enhanced texts are used to form a training data set, and the trained classifier is parameter updated according to the training data set, so that the updated classifier can better perform a classification task in the insurance business field.
[0085] Optionally, after obtaining the target enhanced text, the method further includes:
[0086] Performing weighted summation on the category labels corresponding to the first text information and the second text information according to the first updated weight and the second updated weight to obtain a target enhanced label.
[0087] Performing category prediction on the target enhanced text using the trained classifier to obtain an updated category, calculating an updated loss according to the updated category and the target enhanced label, and performing partial derivative calculation on the updated loss according to the first updated weight to obtain an updated calculation result.
[0088] Multiplying the updated calculation result and the preset coefficient to obtain an updated multiplication result, adding the updated multiplication result and the first updated weight to obtain a third updated weight, taking the difference between a preset value and the third updated weight as a fourth updated weight, and performing weighted summation on the first text information and the second text information according to the third updated weight and the fourth updated weight to obtain a final enhanced text.
[0089] The updated category can be a category predicted by the trained classifier based on the target enhanced text, the updated loss can be a loss calculated based on the updated category, and the updated calculation result can be a gradient calculated based on the updated loss.
[0090] The updated multiplication result can be the update amount of the first updated weight, the third updated weight can be the updated result of the first updated weight, the third updated weight corresponds to the first text information, the fourth updated weight corresponds to the second text information, and the final enhanced text can be used as sample data for model training.
[0091] Specifically, the above-mentioned way of updating the target enhanced text again can be performed in an iterative manner, that is, the final enhanced text is obtained by updating the weight value multiple times. In each iteration process, the output enhanced text of the last iteration process is used for loss calculation, and the weight value updated in the last iteration process is updated again. The iteration process continues until the weight value converges.
[0092] In this embodiment, the weight value calculated by linear interpolation of the historical text is updated multiple times, so that the robustness of the weight value update is stronger.
[0093] The above-mentioned multiplication result is obtained by multiplying the calculation result and the preset coefficient, the first updated weight value is obtained by adding the multiplication result and the first initial weight value, the second updated weight value is obtained by taking the difference between the preset value and the first updated weight value, and the first text information and the second text information are weighted and summed according to the first updated weight value and the second updated weight value to obtain the target enhanced text. The step of using the target enhanced text to update the parameters of the trained classifier, updating the initial weight value according to the gradient, makes the target enhanced text generated based on the updated weight value more robust, improves the data enhancement effect, and makes the classification model trained based on the enhanced text more accurate.
[0094] In this embodiment, the new enhanced text and the label are obtained by linear interpolation of the historical text, so that a large amount of text data can be generated, the initial weight value is updated according to the gradient, the target enhanced text generated based on the updated weight value is more robust, the data enhancement effect is improved, the classification model trained based on the enhanced text is more accurate, the training result of the classification model is improved, and the application accuracy of the classification model in the insurance business scenario is improved.
[0095] The data enhancement method for text classification corresponding to the above embodiment, Figure 3 The structure block diagram of the data enhancement device for text classification provided by the second embodiment of the application is shown, and the above-mentioned data enhancement device is applied to a client. The computer device corresponding to the client is connected to a server to obtain historical texts and their category labels from the server. The server has a storage function, and the server can store historical texts and their known category labels in the above-mentioned specific business platform. For the convenience of description, only the parts related to the embodiments of the application are shown.
[0096] Referring to Figure 3 The data enhancement device comprises:
[0097] The text acquisition module 31 is configured to acquire at least two historical texts and their category labels, and optionally two historical texts are used as the first text information and the second text information respectively.
[0098] The initial enhancement module 32 is configured to randomly generate a first initial weight value, take a difference between a preset value and the first initial weight value as a second initial weight value, and perform weighted summation on the first text information and the second text information and the category labels corresponding to the first text information and the second text information, respectively, according to the first initial weight value and the second initial weight value, to obtain initial enhanced text and initial enhanced labels corresponding to the initial enhanced text.
[0099] The category prediction module 33 is configured to perform category prediction on the initial enhanced text by using the trained classifier to obtain a predicted category, calculate a predicted loss according to the predicted category and the initial enhanced labels, and perform partial derivation on the predicted loss according to the first initial weight value to obtain a calculation result.
[0100] The target enhancement module 34 is configured to multiply the calculation result and a preset coefficient to obtain a multiplication result, add the multiplication result and the first initial weight value to obtain a first updated weight value, take a difference between a preset value and the first updated weight value as a second updated weight value, and perform weighted summation on the first text information and the second text information according to the first updated weight value and the second updated weight value to obtain target enhanced text, where the target enhanced text is used for parameter updating of the trained classifier.
[0101] Optionally, the initial enhancement module 32 includes:
[0102] The feature embedding unit is configured to perform feature embedding on the first text information and the second text information, respectively, by using the trained embedding layer to obtain first embedding features corresponding to the first text information and second embedding features corresponding to the second text information.
[0103] The feature weighting unit is configured to multiply the first initial weight value and the first embedding features to obtain a first multiplication result, multiply the second initial weight value and the second embedding features to obtain a second multiplication result, and add the first multiplication result and the second multiplication result to determine an addition result as initial embedding features corresponding to the initial enhanced text.
[0104] Correspondingly, the category prediction module 33 includes:
[0105] The feature prediction unit is configured to perform category prediction on the initial embedding features by using the trained classifier to obtain a predicted category.
[0106] Optionally, the category labels are probability value sequences formed according to probabilities of the corresponding historical text belonging to at least two preset categories.
[0107] The initial enhancement module 32 includes:
[0108] The sequence determination unit is configured to determine that the category labels corresponding to the first text information are first probability value sequences and determine that the category labels corresponding to the second text information are second probability value sequences.
[0109] The first weighting unit is configured to multiply each probability value in the first probability value sequence by a first initial weight value to obtain a first multiplication sequence.
[0110] The second weighting unit is configured to multiply each probability value in the second probability value sequence by a second initial weight value to obtain a second multiplication sequence.
[0111] The label determination unit is configured to add the first multiplication sequence and the second multiplication sequence to determine an initial enhanced label corresponding to the initial enhanced text.
[0112] Optionally, the category prediction module 33 includes:
[0113] The probability prediction unit is configured to use the trained classifier to predict probabilities of the initial enhanced text belonging to each preset category respectively to obtain prediction probabilities corresponding to the preset categories.
[0114] The category determination unit is configured to determine that a preset category corresponding to a maximum value of all the prediction probabilities is a prediction category.
[0115] Optionally, the category prediction module 33 includes:
[0116] The sequence forming unit is configured to form a prediction probability sequence according to all the prediction probabilities.
[0117] The loss calculation unit is configured to calculate a prediction loss according to the prediction probability sequence, the initial enhanced label, and a preset prediction loss function.
[0118] Optionally, the data enhancement device further includes:
[0119] The target label calculation module is configured to perform weighted summation on category labels corresponding to the first text information and the second text information respectively according to the first updated weight value and the second updated weight value to obtain a target enhanced label.
[0120] The loss update module is configured to perform category prediction on the target enhanced text using the trained classifier to obtain an updated category, calculate an updated loss according to the updated category and the target enhanced label, perform partial derivation calculation on the updated loss according to the first updated weight value to obtain an updated calculation result.
[0121] The enhanced text update module is configured to multiply the updated calculation result and a preset coefficient to obtain an updated multiplication result, add the updated multiplication result and the first updated weight value to obtain a third updated weight value, use a difference between a preset value and the third updated weight value as a fourth updated weight value, and perform weighted summation on the first text information and the second text information according to the third updated weight value and the fourth updated weight value to obtain a final enhanced text.
[0122] It should be noted that the information interaction, execution process and the like between the above modules and units are based on the same concept as the method embodiments of the present application, and the specific functions and technical effects brought by the same can be referred to the method embodiments part, which will not be described here.
[0123] Figure 4 A structural schematic diagram of a computer device for the third embodiment of the present application is shown in FIG. 3. As shown in the figure, the computer device of this embodiment comprises at least one processor (only one processor is shown in the figure), a memory, and a computer program stored in the memory and executable on the at least one processor, and the processor implements the steps in any of the above data enhancement method embodiments when executing the computer program. Figure 4 Figure 4 The computer device can comprise, but is not limited to, a processor, a memory. Those skilled in the art can understand that the computer device is only an example of the computer device, and does not constitute a limitation to the computer device, and the computer device can comprise more or fewer components than those shown in the figure, or combine certain components, or different components, for example, it can also comprise a network interface, a display screen, an input device and the like.
[0124] The computer device can comprise, but is not limited to, a processor, a memory. Those skilled in the art can understand that the computer device is only an example of the computer device, and does not constitute a limitation to the computer device, and the computer device can comprise more or fewer components than those shown in the figure, or combine certain components, or different components, for example, it can also comprise a network interface, a display screen, an input device and the like. Figure 4 The processor can be a CPU, and the processor can also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor.
[0125]
[0126] The memory includes a readable storage medium, an internal memory, etc., wherein the internal memory can be a memory of the computer device, and the internal memory provides an environment for running of the operating system and the computer-readable instructions in the readable storage medium. The readable storage medium can be a hard disk of the computer device, and in other embodiments, can also be an external storage device of the computer device, for example, a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, etc. Further, the memory can include both an internal storage unit of the computer device and an external storage device. The memory is used to store an operating system, an application program, a BootLoader, data, and other programs, such as program codes of computer programs, etc. The memory can also be used to temporarily store data that has been output or will be output.
[0127] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the above-mentioned division of each functional unit and module is exemplified, and in actual application, the above-mentioned functions can be completed by different functional units and modules according to needs, that is, the internal structure of the device is divided into different functional units or modules to complete all or part of the functions described above. Each functional unit and module in the embodiment can be integrated in one processing unit, or each unit can be physically present separately, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of software functional unit. In addition, the specific names of each functional unit and module are only for easy distinction, and do not limit the protection scope of the present application. The specific working process of the unit and module in the above device can refer to the corresponding process in the foregoing method embodiment, which will not be repeated here. If the integrated unit is realized in the form of software functional unit and sold or used as an independent product, it can be stored in a computer readable storage medium. Based on this understanding, the present application realizes all or part of the processes in the above-mentioned embodiment methods, which can be completed by a computer program to instruct related hardware. The computer program can be stored in a computer readable storage medium, and when the processor executes the computer program, the steps of the above-mentioned method embodiment can be realized. The computer program includes computer program code, which can be in the form of source code, object code, executable file or some intermediate form, etc. The computer readable medium can at least include any entity or device capable of carrying computer program code, recording medium, computer memory, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), electrical carrier signal, telecommunication signal and software distribution medium. For example, U disk, mobile hard disk, magnetic disk or optical disk, etc. In some jurisdictions, according to legislation and patent practice, the computer readable medium cannot be an electrical carrier signal and a telecommunication signal.
[0128] The present application realizes all or part of the processes in the above-mentioned embodiment methods, which can also be completed by a computer program product. When the computer program product runs on the computer device, it makes the computer device execute the steps that can realize the above-mentioned method embodiments.
[0129] In the above embodiments, the description of each embodiment has its own emphasis, and the parts not described or recorded in detail in a certain embodiment can be referred to the related description of other embodiments.
[0130] Those skilled in the art can understand that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be realized in electronic hardware or a combination of computer software and electronic hardware. Whether the functions are realized in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.
[0131] In the embodiments provided by the present application, it should be understood that the disclosed apparatus / computer device and method can be implemented in other manners. For example, the described apparatus / computer device embodiments are merely schematic. For example, the division of the modules or units can be different, and each can include a plurality of sub-units. Some or all of the modules or units can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections can be indirect couplings or communication connections through some interfaces, devices or units, and can be in electrical, mechanical or other forms.
[0132] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, i.e. may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiments.
[0133] The above embodiments are only used to illustrate the technical solutions of the present application, but not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that the technical solutions recorded in the foregoing embodiments can be modified, or some technical features can be replaced by equivalents; and these modifications or replacements do not make the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application.
Claims
1. A data augmentation method for text classification, characterized in that, The data augmentation method includes: Obtain at least two historical texts and their category labels, and randomly select two historical texts as the first text information and the second text information, respectively. A first initial weight is randomly generated, and the difference between the preset value and the first initial weight is used as the second initial weight. Based on the first initial weight and the second initial weight, the first text information and the second text information, as well as the category labels corresponding to the first text information and the second text information, are weighted and summed respectively to obtain the initial enhanced text and its corresponding initial enhanced label. The trained classifier is used to predict the category of the initial enhanced text to obtain the predicted category. Based on the predicted category and the initial enhanced label, the prediction loss is calculated. The partial derivative of the prediction loss is calculated based on the first initial weight to obtain the calculation result. The calculation result is multiplied by a preset coefficient to obtain a multiplication result. The multiplication result is added to the first initial weight to obtain a first update weight. The difference between the preset value and the first update weight is used as a second update weight. The first text information and the second text information are weighted and summed according to the first update weight and the second update weight to obtain the target enhanced text. The target enhanced text is used to update the parameters of the trained classifier. Based on the first initial weight and the second initial weight, the first text information and the second text information are weighted and summed to obtain the initial enhanced text, including: The trained embedding layer is used to embed features into the first text information and the second text information respectively, to obtain the first embedding feature corresponding to the first text information and the second embedding feature corresponding to the second text information; Multiply the first initial weight and the first embedding feature to obtain a first multiplication result; multiply the second initial weight and the second embedding feature to obtain a second multiplication result; add the first multiplication result and the second multiplication result to determine the sum as the initial embedding feature corresponding to the initial enhanced text. The step of using a trained classifier to predict the category of the initial enhanced text to obtain the predicted category includes: Using the trained classifier, the probability of the initial enhanced text belonging to each of the preset categories is predicted to obtain the predicted probability of the corresponding preset category; The preset category corresponding to the maximum value of all predicted probabilities is determined as the predicted category.
2. The data augmentation method according to claim 1, characterized in that, The category label is a probability value sequence formed based on the probability values of the corresponding historical text belonging to at least two preset categories; The step of weighted summation of the category labels corresponding to the first text information and the second text information according to the first initial weight and the second initial weight to obtain the initial enhanced label includes: The category label corresponding to the first text information is determined as a first probability value sequence, and the category label corresponding to the second text information is determined as a second probability value sequence; Each probability value in the first probability value sequence is multiplied by the first initial weight to obtain the first multiplication sequence; Each probability value in the second probability value sequence is multiplied by the second initial weight to obtain the second multiplication sequence; The first multiplication sequence and the second multiplication sequence are added together, and the result of the addition is determined as the initial enhancement tag corresponding to the initial enhancement text.
3. The data augmentation method according to claim 1, characterized in that, The step of calculating the prediction loss based on the predicted category and the initial enhanced label includes: A sequence of predicted probabilities is formed based on all predicted probabilities; The prediction loss is calculated based on the predicted probability sequence, the initial enhanced label, and the preset prediction loss function.
4. The data augmentation method according to any one of claims 1 to 3, characterized in that, After obtaining the target enhanced text, the process also includes: Based on the first update weight and the second update weight, the category labels corresponding to the first text information and the second text information are weighted and summed to obtain the target enhancement label; The trained classifier is used to predict the category of the target augmented text to obtain the updated category. The update loss is calculated based on the updated category and the target augmented label. The partial derivative of the update loss is calculated based on the first update weight to obtain the update calculation result. The update calculation result is multiplied by the preset coefficient to obtain the update multiplication result. The update multiplication result is added to the first update weight to obtain the third update weight. The difference between the preset value and the third update weight is used as the fourth update weight. The first text information and the second text information are weighted and summed according to the third update weight and the fourth update weight to obtain the final enhanced text.
5. A data augmentation device for text classification, characterized in that, The data enhancement device includes: The text acquisition module is used to acquire at least two historical texts and their category labels, and randomly select two historical texts as the first text information and the second text information, respectively. The initial enhancement module is used to randomly generate a first initial weight, use the difference between a preset value and the first initial weight as a second initial weight, and perform weighted summation on the first text information and the second text information, as well as the category labels corresponding to the first text information and the second text information, respectively, based on the first initial weight and the second initial weight, to obtain the initial enhanced text and its corresponding initial enhanced label. The category prediction module is used to predict the category of the initial enhanced text using a trained classifier, obtain the predicted category, calculate the prediction loss based on the predicted category and the initial enhanced label, and calculate the partial derivative of the prediction loss based on the first initial weight to obtain the calculation result. The target enhancement module is used to multiply the calculation result with a preset coefficient to obtain a multiplication result, add the multiplication result to the first initial weight to obtain a first update weight, use the difference between the preset value and the first update weight as a second update weight, and perform a weighted summation on the first text information and the second text information according to the first update weight and the second update weight to obtain the target enhanced text. The target enhanced text is used to update the parameters of the trained classifier. The initial enhancement module includes: The feature embedding unit is used to embed features into the first text information and the second text information respectively using the trained embedding layer, so as to obtain the first embedded feature corresponding to the first text information and the second embedded feature corresponding to the second text information. The feature weighting unit is used to multiply the first initial weight and the first embedded feature to obtain the first multiplication result, multiply the second initial weight and the second embedded feature to obtain the second multiplication result, and add the first multiplication result and the second multiplication result to determine the added result as the initial embedded feature of the corresponding initial enhanced text; The category prediction module includes: The probability prediction unit is used to predict the probability of the initial enhanced text belonging to each preset category using a trained classifier, and obtain the predicted probability of the corresponding preset category. The category determination unit is used to determine the preset category corresponding to the maximum value of all predicted probabilities as the predicted category.
6. The data enhancement apparatus according to claim 5, characterized in that, The category label is a probability value sequence formed based on the probability values of the corresponding historical text belonging to at least two preset categories; The initial enhancement module includes: A sequence determination unit is used to determine that the category label corresponding to the first text information is a first probability value sequence, and to determine that the category label corresponding to the second text information is a second probability value sequence; The first weighting unit is used to multiply each probability value in the first probability value sequence by the first initial weight to obtain a first multiplication sequence; The second weighting unit is used to multiply each probability value in the second probability value sequence by the second initial weight to obtain a second multiplication sequence; The tag determination unit is used to add the first multiplication sequence and the second multiplication sequence to determine the addition result as the initial enhancement tag corresponding to the initial enhancement text.
7. A computer device, characterized in that, The computer device includes a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the data augmentation method as described in any one of claims 1 to 4.
8. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the data augmentation method as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Text classification method and apparatus, computer device and storage medium
WO2020140403A1
Text classification model training method, apparatus, and device and storage medium
WO2022062404A1