Text classification method and related device
Through knowledge distillation and clustering processing, combined with fusion distribution probability calculation, the problem of poor text classification results caused by the complexity of the deep learning model and insufficient training data is solved, and the accuracy and effect of text classification are improved.
Patent Information
- Application Number
- CN202310312849.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-20
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2043-03-20
AI Technical Summary
Among existing text classification methods, when the complexity of the deep learning model is large, the model deployment requirements are high, and when the complexity is small, the classification accuracy is low, and the small number of training texts or imbalanced categories lead to weak classification capabilities, resulting in poor classification of the text to be classified. Less effective.
Through model training based on knowledge distillation, a more complex first classification model and a less complex second classification model are obtained. Combined with clustering processing and fusion distribution probability calculation, the classification accuracy of the text to be classified is improved.
On the basis of ensuring the classification accuracy, the model complexity is reduced, the classification effect of the text to be classified is improved, the problem of weak classification ability caused by the small number of training texts or the imbalance of categories is compensated, and the classification accuracy is improved.
Smart Images

Figure CN118673142A
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a text classification method and related devices. Background Art
[0002] With the rapid development of text processing technology, in some actual business application scenarios, it is necessary to first classify the text to be processed. If the text to be processed is easier to process based on the classification category, the text to be processed is regarded as the text to be classified.
[0003] Related technology can pre-train a deep learning model through training text with category label data to obtain a text classification model, input the text to be classified into the text classification model for category prediction, and obtain the predicted category to which the text to be classified belongs as the classification category to which the text to be classified belongs.
[0004] However, when the complexity of the deep learning model in the above method is large, the model deployment requirements of the text classification model are high, and when the complexity of the deep learning model is small, the classification accuracy of the text classification model is low; and the small total number of training texts or unbalanced categories can easily lead to weak classification capabilities of the text classification model; that is, the classification effect of the text to be classified in the above method is poor. Summary of the invention
[0005] In order to solve the above technical problems, the present application provides a text classification method and related devices, which can improve the classification accuracy of the text to be classified, thereby improving the classification effect of the text to be classified.
[0006] The embodiments of the present application disclose the following technical solutions:
[0007] On the one hand, an embodiment of the present application provides a text classification method, the method comprising:
[0008] A category prediction is performed on each of the multiple texts to be classified by a preset classification model to obtain a first distribution probability of the multiple preset categories to which each text to be classified belongs; the preset classification model is obtained by performing model training based on knowledge distillation on a first classification model and a second classification model according to multiple first training texts and category label data annotated with each first training text, and the model complexity of the first classification model is greater than the complexity of the second classification model;
[0009] Performing clustering processing on the multiple texts to be classified to obtain a second distribution probability that each of the texts to be classified belongs to the multiple preset categories;
[0010] For each of the texts to be classified, a first distribution probability of the plurality of preset categories to which the text to be classified belongs and a second distribution probability of the plurality of preset categories to which the text to be classified belongs are fused to obtain a fused distribution probability of the plurality of preset categories to which the text to be classified belongs;
[0011] The classification category to which the to-be-classified text belongs is determined according to the preset category corresponding to the maximum probability component in the fused distribution probability.
[0012] Optionally, the fusing of the first distribution probabilities of the multiple preset categories to which the text to be classified belongs and the second distribution probabilities of the multiple preset categories to which the text to be classified belongs to obtain the fused distribution probabilities of the multiple preset categories to which the text to be classified belongs, comprises:
[0013] Determine a first weight corresponding to the first distribution probability and a second weight corresponding to the second distribution probability; the sum of the first weight and the second weight is 1;
[0014] The first distribution probability of the multiple preset categories to which the text to be classified belongs, the first weight, the second distribution probability of the multiple preset categories to which the text to be classified belongs, and the second weight are weighted to obtain a fused distribution probability of the multiple preset categories to which the text to be classified belongs.
[0015] Optionally, the step of training the preset classification model includes:
[0016] For each of the first training texts, using the first pre-training model in the first classification model, a category prediction is performed on the first training text to obtain a third distribution probability of the plurality of preset categories to which the first training text belongs;
[0017] By using the normalization layer in the first classification model, the third distribution probability is normalized based on knowledge distillation to obtain target distribution probabilities of the plurality of preset categories to which the first training text belongs;
[0018] Using the second pre-trained model in the second classification model, a category prediction is performed on each first training text to obtain a fourth distribution probability of the plurality of preset categories to which the first training text belongs; the model complexity of the first pre-trained model is greater than the complexity of the second pre-trained model;
[0019] By using the first normalization layer in the second classification model, the fourth distribution probability is normalized based on knowledge distillation to obtain a first prediction probability that the first training text belongs to the plurality of preset categories;
[0020] Normalizing the fourth distribution probability through a second normalization layer in the second classification model to obtain second prediction probabilities that the first training text belongs to the plurality of preset categories;
[0021] Training model parameters of the second classification model until the model converges according to the first prediction probability, the target distribution probability, the second prediction probability, the category label data annotated by the first training text, and a preset loss function of the second classification model;
[0022] The second pre-trained model and the second normalization layer in the trained second classification model are determined as the preset classification model.
[0023] Optionally, the preset loss function includes a first loss function and a second loss function; and training the model parameters of the second classification model until the model converges according to the first prediction probability, the target distribution probability, the second prediction probability, the category label data annotated by the first training text, and the preset loss function of the second classification model, comprises:
[0024] Determining a first loss corresponding to the first training text according to the first prediction probability, the target distribution probability and the first loss function;
[0025] Determine a second loss corresponding to the first training text according to the second predicted probability, the category label data and the second loss function;
[0026] Performing weighted processing on the first loss, a third weight corresponding to the first loss, the second loss, and a fourth weight corresponding to the second loss to obtain a total loss corresponding to the first training text; the sum of the third weight and the fourth weight is 1;
[0027] The model parameters of the second classification model are trained according to the total loss until the model converges.
[0028] Optionally, the step of obtaining the plurality of first training texts is specifically as follows:
[0029] The collected multiple historical texts are randomly sampled to obtain the multiple first training texts; the total number of the multiple first training texts is greater than or equal to the first number.
[0030] Optionally, the step of obtaining the category label data of each first training text is specifically as follows:
[0031] In response to the first object performing a category labeling operation on each of the first training texts according to preset classification business requirements corresponding to the plurality of first training texts, category label data of each of the first training texts is obtained.
[0032] Optionally, before training the preset classification model, the method further includes:
[0033] Randomly sampling the plurality of first training texts to obtain a plurality of texts to be annotated; the total number of the plurality of texts to be annotated is greater than or equal to a second number, and the second number is less than the first number;
[0034] In response to the second object performing a category labeling operation on each text to be annotated according to the preset classification business requirement, obtaining annotation category data of each text to be annotated;
[0035] If the consistency between the multiple category label data corresponding to the multiple texts to be annotated and the multiple annotation category data corresponding to the multiple texts to be annotated is greater than or equal to the preset consistency, it is determined that the category label data of each first training text is correctly annotated;
[0036] If the consistency level is less than the preset consistency level, the category label data of each first training text is updated.
[0037] Optionally, before predicting the category of each of the multiple texts to be classified by using a preset classification model, the method further includes:
[0038] Performing category prediction on each of the multiple to-be-tested texts that are different from the multiple first training texts by using the preset classification model to obtain a third prediction probability that each of the to-be-tested texts belongs to the multiple preset categories;
[0039] According to the third prediction probabilities of the multiple preset categories to which each of the to-be-tested texts belongs, the category label data annotated by each of the to-be-tested texts, and the preset verification index, the preset classification model is model verified to obtain a model verification result of the preset classification model;
[0040] If the model verification result does not meet the preset verification condition, updating the multiple first training texts according to the multiple historical texts to obtain multiple second training texts;
[0041] According to the multiple second training texts and the category label data annotated by each second training text, the first classification model and the second classification model are trained based on knowledge distillation to update the preset classification model.
[0042] Optionally, the preset verification indicator includes any one of a confusion matrix, accuracy and recall rate.
[0043] Optionally, clustering the plurality of texts to be classified to obtain a second distribution probability that each text to be classified belongs to the plurality of preset categories includes:
[0044] Determining a plurality of initial center points corresponding to the plurality of preset categories;
[0045] Clustering the plurality of texts to be classified according to the distance between each text to be classified and each initial center point, and determining the preset category to which each text to be classified belongs;
[0046] Update each initial center point according to a plurality of to-be-classified texts clustered under a preset category corresponding to each initial center point;
[0047] Repeating the clustering process of the plurality of texts to be classified according to the distance between each text to be classified and each initial center point until the clustering converges;
[0048] According to the preset category to which each to-be-classified text belongs after clustering convergence, a second distribution probability of each to-be-classified text belonging to the plurality of preset categories is determined.
[0049] Optionally, when the text classification method is applied to a text classification reply scenario, the method further includes:
[0050] According to the classification category to which the text to be classified belongs, a text to be replied that meets the classification category is determined corresponding to the text to be classified.
[0051] On the other hand, an embodiment of the present application provides a text classification device, the device comprising: a prediction unit, a clustering unit, a fusion unit and a determination unit;
[0052] The prediction unit is used to predict the category of each of the multiple texts to be classified by using a preset classification model to obtain a first distribution probability of the multiple preset categories to which each of the texts to be classified belongs; the preset classification model is obtained by performing model training based on knowledge distillation on a first classification model and a second classification model according to multiple first training texts and category label data annotated by each first training text, and the model complexity of the first classification model is greater than the complexity of the second classification model;
[0053] The clustering unit is used to perform clustering processing on the multiple texts to be classified to obtain a second distribution probability that each text to be classified belongs to the multiple preset categories;
[0054] The fusion unit is used to fuse the first distribution probability of the multiple preset categories to which the text to be classified belongs and the second distribution probability of the multiple preset categories to which the text to be classified belongs, for each text to be classified, to obtain the fused distribution probability of the multiple preset categories to which the text to be classified belongs;
[0055] The determination unit is used to determine the classification category to which the to-be-classified text belongs according to the preset category corresponding to the maximum probability component in the fused distribution probability.
[0056] Optional, fusion unit, specifically used for:
[0057] Determine a first weight corresponding to the first distribution probability and a second weight corresponding to the second distribution probability; the sum of the first weight and the second weight is 1;
[0058] The first distribution probabilities and the first weight of the multiple preset categories to which the text to be classified belongs, the second distribution probabilities and the second weight of the multiple preset categories to which the text to be classified belongs are weighted to obtain the fused distribution probabilities of the multiple preset categories to which the text to be classified belongs.
[0059] Optionally, the device further comprises: a training unit;
[0060] The training unit is specifically configured to perform category prediction on each first training text by using a first pre-training model in a first classification model to obtain a third distribution probability of a plurality of preset categories to which the first training text belongs;
[0061] The third distribution probability is normalized based on knowledge distillation through a normalization layer in the first classification model to obtain target distribution probabilities of multiple preset categories to which the first training text belongs;
[0062] Using the second pre-trained model in the second classification model, each first training text is predicted to be a category, so as to obtain a fourth distribution probability of a plurality of preset categories to which the first training text belongs; the model complexity of the first pre-trained model is greater than the complexity of the second pre-trained model;
[0063] By using a first normalization layer in the second classification model, the fourth distribution probability is normalized based on knowledge distillation to obtain first prediction probabilities of multiple preset categories to which the first training text belongs;
[0064] The fourth distribution probability is normalized by a second normalization layer in the second classification model to obtain second prediction probabilities of the plurality of preset categories to which the first training text belongs;
[0065] Training model parameters of the second classification model until the model converges according to the first prediction probability, the target distribution probability, the second prediction probability, the category label data annotated by the first training text, and the preset loss function of the second classification model;
[0066] The second pre-trained model and the second normalization layer in the trained second classification model are determined as the preset classification model.
[0067] Optional, training unit, specifically used for:
[0068] Determine a first loss corresponding to the first training text according to the first prediction probability, the target distribution probability and the first loss function;
[0069] Determine a second loss corresponding to the first training text according to the second prediction probability, the category label data, and the second loss function;
[0070] The first loss, the third weight corresponding to the first loss, the second loss, and the fourth weight corresponding to the second loss are weighted to obtain a total loss corresponding to the first training text; the sum of the third weight and the fourth weight is 1;
[0071] The model parameters of the second classification model are trained according to the total loss until the model converges.
[0072] Optionally, the device further comprises: a sampling unit;
[0073] The sampling unit is used to randomly sample the collected multiple historical texts to obtain multiple first training texts; the total number of the multiple first training texts is greater than or equal to the first number.
[0074] Optionally, the device further comprises: a marking unit;
[0075] The labeling unit is used to obtain the category label data of each first training text in response to the first object labeling each first training text according to the preset classification business requirements corresponding to the plurality of first training texts.
[0076] Optionally, the device further includes: a first updating unit;
[0077] The sampling unit is further used to randomly sample the plurality of first training texts to obtain a plurality of texts to be annotated; the total number of the plurality of texts to be annotated is greater than or equal to a second number, and the second number is less than the first number;
[0078] The marking unit is further used to obtain the annotation category data of each text to be annotated in response to the second object's category marking operation on each text to be annotated according to the preset classification business requirements;
[0079] The determination unit is further configured to determine that the category label data of each first training text is correctly annotated if the consistency between the multiple category label data corresponding to the multiple texts to be annotated and the multiple annotation category data corresponding to the multiple texts to be annotated is greater than or equal to a preset consistency degree;
[0080] The first updating unit is used to update the category label data of each first training text if the consistency level is less than a preset consistency level.
[0081] Optionally, the device further comprises: a verification unit and a second updating unit;
[0082] The prediction unit is further used to perform category prediction on each of the multiple test texts that are different from the multiple first training texts through a preset classification model to obtain a third prediction probability that each test text belongs to the multiple preset categories;
[0083] A verification unit, used to perform model verification on a preset classification model according to the third prediction probabilities of the multiple preset categories to which each to-be-tested text belongs, the category label data annotated by each to-be-tested text, and a preset verification index, to obtain a model verification result of the preset classification model;
[0084] A second updating unit is used to update the plurality of first training texts according to the plurality of historical texts to obtain the plurality of second training texts if the model verification result does not meet the preset verification condition;
[0085] The second updating unit is further used to perform model training based on knowledge distillation on the first classification model and the second classification model according to the multiple second training texts and the category label data annotated by each second training text, and update the preset classification model.
[0086] Optionally, the preset verification indicator includes any one of a confusion matrix, precision, and recall.
[0087] Optional, clustering unit, specifically used for:
[0088] Determine a plurality of initial center points corresponding to a plurality of preset categories;
[0089] Clustering multiple texts to be classified is performed according to the distance between each text to be classified and each initial center point, so as to determine the preset category to which each text to be classified belongs;
[0090] Update each initial center point according to a plurality of to-be-classified texts clustered under a preset category corresponding to each initial center point;
[0091] Repeat the clustering process of multiple texts to be classified according to the distance between each text to be classified and each initial center point until the clustering converges;
[0092] According to the preset category to which each to-be-classified text belongs after clustering convergence, a second distribution probability of the plurality of preset categories to which each to-be-classified text belongs is determined.
[0093] Optionally, when the text classification method is applied to a text classification reply scenario, the determination unit is further used to determine a to-be-reply text that meets the classification category corresponding to the to-be-classified text according to the classification category to which the to-be-classified text belongs.
[0094] On the other hand, an embodiment of the present application provides a computer device, the computer device comprising a processor and a memory:
[0095] The memory is used to store a computer program and transmit the computer program to the processor;
[0096] The processor is configured to execute the method described in any one of the preceding aspects according to instructions in the computer program.
[0097] On the other hand, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium is used to store a computer program, and the computer program is used to execute the method described in any one of the aforementioned aspects.
[0098] On the other hand, an embodiment of the present application provides a computer program product, including a computer program, which, when executed on a computer device, enables the computer device to implement the method described in any of the above aspects.
[0099] It can be seen from the above technical scheme that, first, the first classification model and the second classification model are trained based on knowledge distillation through multiple first training texts and the category label data annotated by each first training text to obtain a preset classification model, wherein the model complexity of the first classification model is greater than the complexity of the second classification model, then each of the multiple texts to be classified is input into the preset classification model for category prediction, and a first distribution probability of each text to be classified belonging to multiple preset categories is output; since the model training method based on knowledge distillation enables the preset classification model to reduce the model complexity while minimizing the classification accuracy, the classification performance of the text to be classified can be guaranteed to a certain extent through the preset classification model; in addition, the multiple texts to be classified are clustered to obtain the second distribution probability of each text to be classified belonging to multiple preset categories; this clustering method can make up for the shortcomings of the weak classification ability of the preset classification model caused by the small total number of multiple first training texts or the imbalance of categories. Then, for each text to be classified, the first distribution probability of the multiple preset categories to which the text to be classified belongs and the second distribution probability of the multiple preset categories to which the text to be classified belongs are fused to obtain the fused distribution probability of the multiple preset categories to which the text to be classified belongs; this fusion method makes the fused distribution probability more accurate than the first distribution probability and the second distribution probability. Finally, the preset category corresponding to the maximum probability component in the fused distribution probability is used as the classification category to which the text to be classified belongs, which can improve the classification accuracy of the text to be classified, thereby improving the classification effect of the text to be classified. BRIEF DESCRIPTION OF THE DRAWINGS
[0100] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technical members in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0101] Figure 1 A schematic diagram of the system architecture of a text classification method provided in an embodiment of the present application;
[0102] Figure 2 A flowchart of a text classification method provided in an embodiment of the present application;
[0103] Figure 3 A schematic diagram of text classification based on LSTM provided in an embodiment of the present application;
[0104] Figure 4 A schematic diagram of text classification based on textCNN provided in an embodiment of the present application;
[0105] Figure 5 A BERT-based text classification diagram provided in an embodiment of the present application;
[0106] Figure 6 A schematic diagram of model training based on knowledge distillation for a first classification model and a second classification model provided in an embodiment of the present application;
[0107] Figure 7 A schematic diagram of a model architecture of a preset classification model provided in an embodiment of the present application;
[0108] Figure 8 A schematic diagram of a confusion matrix provided in an embodiment of the present application;
[0109] Fig. 9 A flowchart of a text classification method combined with an actual application scenario provided in an embodiment of the present application;
[0110] Fig.10 A structural diagram of a text classification device provided in an embodiment of the present application;
[0111] Fig.11 A structural diagram of a server provided in an embodiment of the present application;
[0112] Fig.12 A structural diagram of a terminal provided in an embodiment of the present application. DETAILED DESCRIPTION
[0113] The embodiments of the present application are described below in conjunction with the accompanying drawings.
[0114] At present, text classification for text to be classified means: pre-training a deep learning model with training text with category label data to obtain a text classification model, inputting the text to be classified into the text classification model for category prediction, and obtaining the predicted category to which the text to be classified belongs as the classification category to which the text to be classified belongs.
[0115] However, after research, it was found that when the complexity of the deep learning model in the above method is large, the model deployment requirements of the text classification model are high, and when the complexity of the deep learning model is small, the classification accuracy of the text classification model is low; and the small total number of training texts or unbalanced categories can easily lead to weak classification capabilities of the text classification model; that is, the classification effect of the text to be classified in the above method is poor.
[0116] The embodiment of the present application provides a text classification method and related devices, which preliminarily uses a plurality of first training texts and the category label data annotated by each first training text to perform model training based on knowledge distillation on a first classification model and a second classification model to obtain a preset classification model, wherein the model complexity of the first classification model is greater than the complexity of the second classification model, and then each of the plurality of texts to be classified is input into the preset classification model for category prediction, and a first distribution probability of each text to be classified belonging to a plurality of preset categories is output; since the model training method based on knowledge distillation enables the preset classification model to reduce the model complexity while minimizing the reduction of the classification accuracy, the classification performance of the text to be classified can be guaranteed to a certain extent by the preset classification model. In addition, the plurality of texts to be classified are clustered to obtain a second distribution probability of each text to be classified belonging to a plurality of preset categories; this clustering method can make up for the disadvantage of the weak classification ability of the preset classification model caused by the small total number of the plurality of first training texts or the imbalance of the categories. For each text to be classified, the first distribution probability of multiple preset categories to which the text to be classified belongs and the second distribution probability of multiple preset categories to which the text to be classified belongs are fused to obtain the fused distribution probability of multiple preset categories to which the text to be classified belongs; this fusion method makes the fused distribution probability more accurate than the first distribution probability and the second distribution probability. The preset category corresponding to the maximum probability component in the fused distribution probability is used as the classification category to which the text to be classified belongs, which can improve the classification accuracy of the text to be classified, thereby improving the classification effect of the text to be classified.
[0117] Next, the system architecture of the text classification method will be introduced. Figure 1 , Figure 1 A schematic diagram of a system architecture of a text classification method provided in an embodiment of the present application, wherein the system architecture includes a terminal 101 and a server 102, wherein the terminal 101 sends a text to be classified to the server 102, so that the server 102 performs text classification on the text to be classified.
[0118] Among them, terminal 101 includes but is not limited to smart phones, tablet computers, laptops, desktop computers, intelligent voice interaction devices, smart home appliances, vehicle-mounted terminals, aircraft, extended reality devices (augmented reality devices, virtual reality devices, mixed reality devices), etc., but is not limited to this. Server 102 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud computing services. Terminal 101 and server 102 can be directly or indirectly connected via wired or wireless communication, and this application is not limited here. For example, terminal 101 and server 102 can be connected via a network, which can be a wired or wireless network.
[0119] The terminal 101 collects multiple texts to be classified and sends the multiple texts to be classified to the server 102. The server 102 predicts the category of each text to be classified in the multiple texts to be classified through a preset classification model, and obtains the first distribution probability of each text to be classified belonging to multiple preset categories; wherein the preset classification model is obtained by the server 102 performing model training based on knowledge distillation on the first classification model and the second classification model according to multiple first training texts and the category label data annotated by each first training text, and the model complexity of the first classification model is greater than the complexity of the second classification model.
[0120] As an example, in a payment business complaint scenario, multiple first training texts include "historical complaint text 1", "historical complaint text 2", ... and "historical complaint text m", where m is a positive integer, m≥500; the first classification model is "Model A" with a larger model complexity, and the second classification model is "Model B" with a smaller model complexity; multiple texts to be classified include "current complaint text 1", "current complaint text 2", ... and "current complaint text n", where n is a positive integer, n>3; multiple preset categories include "consumer complaint category", "fee payer complaint category" and "payment fee complaint category". Server 102 pre-trains "Model A" and "Model B" based on knowledge distillation through "Historical Complaint Text 1", "Historical Complaint Text 2", ... and "Historical Complaint Text m" and their annotated category label data to obtain a preset classification model; Server 102 inputs "Current Complaint Text i" into the preset classification model for category prediction, and outputs the first distribution probability of "Current Complaint Text i" belonging to the "Consumer Complaint Category", "Toll Collector Complaint Category" and "Payment Fee Complaint Category" as "Distribution Probability 1i", where i is a positive integer, i=1, 2, ..., n.
[0121] The server 102 performs clustering processing on the multiple texts to be classified, and obtains the second distribution probability of each text to be classified belonging to the multiple preset categories. As an example, based on the above example, the server 102 performs clustering on "Current Complaint Text 1", "Current Complaint Text 2", ... and "Current Complaint Text n", and obtains the second distribution probability of "Current Complaint Text i" belonging to "Consumer Complaint Category", "Toll Collector Complaint Category" and "Payment Fee Complaint Category" as "Distribution Probability 2i".
[0122] For each text to be classified, the server 102 performs a fusion process on the first distribution probability of the multiple preset categories to which the text to be classified belongs and the second distribution probability of the multiple preset categories to which the text to be classified belongs, and obtains the fused distribution probability of the multiple preset categories to which the text to be classified belongs. As an example, based on the above example, for "current complaint text i", the "distribution probability 1i" and the "distribution probability 2i" are fused, and the fused distribution probability of the "consumer complaint category", "fee collector complaint category" and "payment fee complaint category" to which the "current complaint text i" belongs is obtained as "distribution probability i".
[0123] The server 102 determines the classification category to which the text to be classified belongs based on the preset category corresponding to the maximum probability component in the fusion distribution probability. As an example, based on the above example, the server 102 uses the preset category corresponding to the maximum probability component in the "distribution probability i" as the classification category to which the "current complaint text i" belongs; if the "distribution probability i" is specifically "[0.1, 0.1, 0.8]", since the preset category corresponding to the maximum probability component "0.8" is "payment fee complaint category", the classification category to which the "current complaint text i" belongs is "payment fee complaint category".
[0124] That is to say, the first classification model and the second classification model are trained based on knowledge distillation to obtain a preset classification model through multiple first training texts and the category label data annotated by each first training text, wherein the model complexity of the first classification model is greater than the complexity of the second classification model, then each of the multiple texts to be classified is input into the preset classification model for category prediction, and the first distribution probability of each text to be classified belonging to multiple preset categories is output; since the model training method based on knowledge distillation enables the preset classification model to reduce the model complexity on the basis of not reducing the classification accuracy as much as possible, the classification performance of the text to be classified can be guaranteed to a certain extent by the preset classification model. In addition, the multiple texts to be classified are clustered to obtain the second distribution probability of each text to be classified belonging to multiple preset categories; this clustering method can make up for the disadvantage of the weak classification ability of the preset classification model caused by the small total number of multiple first training texts or the imbalance of categories. For each text to be classified, the first distribution probability of the multiple preset categories to which the text to be classified belongs and the second distribution probability of the multiple preset categories to which the text to be classified belongs are fused to obtain the fused distribution probability of the multiple preset categories to which the text to be classified belongs; this fusion method makes the fused distribution probability more accurate than the first distribution probability and the second distribution probability. By taking the preset category corresponding to the maximum probability component in the fusion distribution probability as the classification category to which the text to be classified belongs, the classification accuracy of the text to be classified can be improved, thereby improving the classification effect of the text to be classified.
[0125] The text classification method provided in this application involves artificial intelligence (AI) technology. Among them, artificial intelligence is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology in computer science that attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Artificial intelligence is to study the design principles and implementation methods of various intelligent machines so that machines have the functions of perception, reasoning and decision-making.
[0126] Artificial intelligence technology is a comprehensive discipline that covers a wide range of fields, including both hardware-level and software-level technologies. The basic technologies of artificial intelligence generally include sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics and other technologies.
[0127] The text classification method provided in this application mainly involves the natural language processing (NLP) technology and machine learning (ML) / deep learning included in artificial intelligence technology. Among them, natural language processing is an important direction in the field of computer science and artificial intelligence. It studies various theories and methods that can realize effective communication between people and computers using natural language. Natural language processing is a science that integrates linguistics, computer science, and mathematics. Therefore, research in this field will involve natural language, that is, the language used by people in daily life, so it is closely related to the study of linguistics. Natural language processing technology usually includes technologies such as text processing, semantic understanding, machine translation, robot question answering, and knowledge graphs.
[0128] Machine learning is a multi-disciplinary subject that involves probability theory, statistics, approximation theory, convex analysis, algorithm complexity theory and other disciplines. It specializes in studying how computers simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental way to make computers intelligent. Its applications are spread across all areas of artificial intelligence. Machine learning and deep learning usually include technologies such as artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning and teaching learning.
[0129] The embodiments of the present application can be applied to various scenarios, including but not limited to cloud technology scenarios, artificial intelligence scenarios, smart transportation scenarios, assisted driving scenarios, map scenarios, and in-vehicle scenarios.
[0130] Next, the text classification method provided by the embodiment of the present application is described in detail with reference to the accompanying drawings. Figure 2 , Figure 2 A flowchart of a text classification method provided in an embodiment of the present application, the method comprising:
[0131] S201: Predicting the category of each text to be classified among multiple texts to be classified by using a preset classification model to obtain a first distribution probability of each text to be classified belonging to multiple preset categories; the preset classification model is obtained by performing model training based on knowledge distillation on a first classification model and a second classification model according to multiple first training texts and category label data annotated with each first training text, and the model complexity of the first classification model is greater than the complexity of the second classification model.
[0132] In the related art, a text classification model is obtained by pre-training a deep learning model with training texts with category label data, and the text to be classified is input into the text classification model for category prediction, and the predicted category to which the text to be classified belongs is obtained as the classification category to which the text to be classified belongs. When the complexity of the deep learning model is large, the model deployment requirements of the text classification model are high, and when the complexity of the deep learning model is small, the classification accuracy of the text classification model is low, that is, the large or small complexity of the deep learning model will lead to poor classification effect of the text to be classified.
[0133] Therefore, in the embodiment of the present application, in order to take into account both the model deployment performance and the model classification accuracy, the knowledge learned by the first classification model with a larger model complexity can be transferred to the second classification model with a smaller model complexity, so as to obtain a preset classification model that reduces the model complexity while minimizing the classification accuracy; that is, based on multiple first training texts and the category label data annotated by each first training text, the first classification model and the second classification model are trained based on knowledge distillation to obtain a preset classification model. Based on this, each of the multiple texts to be classified is input into the preset classification model for category prediction, and the probability distribution of the multiple preset categories to which each text to be classified belongs is output, which is recorded as the first distribution probability of the multiple preset categories to which each text to be classified belongs; this prediction method can guarantee the classification performance of the text to be classified to a certain extent.
[0134] Among them, before S201 is implemented, the specific training method of the preset classification model refers to: for each first training text, first, the first training text is input into the first pre-training model with a larger model complexity in the first classification model for category prediction, and the probability distribution of multiple preset categories to which the first training text belongs is obtained, which is recorded as the third distribution probability of the multiple preset categories to which each text to be classified belongs; next, instead of directly normalizing the third distribution probability, a distillation process is performed before the normalization process, that is, the third distribution probability is input into the normalization layer in the first classification model for normalization processing based on knowledge distillation, and the target distribution probability of the multiple preset categories to which the first training text belongs is obtained.
[0135] Secondly, the first training text is input into a second pre-trained model with smaller model complexity in the second classification model for category prediction, and the probability distribution of multiple preset categories to which the first training text belongs is obtained, which is recorded as the fourth distribution probability of the multiple preset categories to which each text to be classified belongs; next, on the one hand, a distillation process is performed before the fourth distribution probability is normalized, that is, the fourth distribution probability is input into the first normalization layer in the second classification model for normalization based on knowledge distillation, and the first prediction probability of the multiple preset categories to which the first training text belongs is obtained; on the other hand, the fourth distribution probability is directly normalized, that is, the fourth distribution probability is input into the second normalization layer in the second classification model for normalization, and the second prediction probability of the multiple preset categories to which the first training text belongs is obtained.
[0136] Then, considering the transfer of knowledge learned by the first classification model with a larger model complexity to the second classification model with a smaller model complexity, the target distribution probability of the multiple preset categories to which the first training text belongs is actually used to train the first prediction probability of the multiple preset categories to which the first training text belongs, and the category label data annotated by the first training text is actually used to train the second prediction probability of the multiple preset categories to which the first training text belongs; therefore, through the first prediction probability, target distribution probability, second prediction probability and category label data, combined with the preset loss function of the second classification model, the model parameters of the second classification model can be trained until the model converges.
[0137] Finally, by selecting only the second pre-trained model and the second normalization layer in the trained second classification model, a preset classification model can be obtained that minimizes the classification accuracy and reduces the model complexity. Therefore, the present application provides a possible implementation method, and the training steps of the preset classification model may include, for example, the following S1-S7:
[0138] S1: For each first training text, a first pre-training model in a first classification model is used to perform category prediction on the first training text to obtain third distribution probabilities of multiple preset categories to which the first training text belongs.
[0139] Common text classification models include Long short-term memory (LSTM), text convolutional neural networks (textCNN), and bidirectional encoder representations from transformer (BERT). Figure 3 , Figure 3A schematic diagram of text classification based on LSTM provided in an embodiment of the present application; wherein, multiple word segmentation vectors w of the text 1 、w 2 ,…,w n-1 and w n Input feature extraction layer to obtain multiple hidden layer vectors h 1 、h 2 ,…,h n-1 and h n , h 1 、h 2 ,…,h n-1 and h n Input the self-attention layer to get the text feature vector, and h 1 、h 2 ,…,h n-1 and h n And the category label data of the text [c 1 , c 2 , …, c k ] Input the label attention layer to obtain the category feature vector, input the text feature vector and the category feature vector into the adaptive fusion layer to obtain the fused feature vector, and use the Multi-Layer Perceptron (MLP) to predict the category of the fused feature vector to obtain the probability distribution of multiple categories to which the text belongs [p 1 , p 2 ,…,p k ].
[0140] See also Figure 4 , Figure 4 A schematic diagram of text classification based on textCNN is provided for an embodiment of the present application; wherein, a 6×5 text matrix of the text "The weather is very good today, let's go out and play" is convolved with two convolution sizes (3×5, 4×5), each convolution size has two convolution kernels, a total of four convolution kernels, and a feature map of each convolution size is obtained in combination with an activation function, each convolution size has two feature maps, a total of four feature maps; each feature map is subjected to maximum pooling to obtain four single vectors and concatenated into one one-dimensional vector, and the one-dimensional vector is normalized to obtain a probability distribution [1, -1] of multiple categories to which the text belongs.
[0141] See also Figure 5 , Figure 5 A BERT-based text classification schematic diagram is provided for an embodiment of the present application; wherein, [CLS] text [SEP] is input as input content into the pre-trained model BERT to obtain an encoding vector including the [CLS] encoding vector, and the category of the [CLS] encoding vector is predicted by a classifier to obtain the probability distribution of multiple categories to which the text belongs.
[0142] Based on the above description, the classification effect of BERT is tested on four commonly used standard text classification data sets. The classification effect of BERT can exceed the classification effect of LSTM or textCNN. Based on this, the first pre-trained model in the first classification model can be a BERT with a larger model complexity.
[0143] In addition, before S1 is implemented, it is necessary to pre-acquire multiple first training texts and the category label data of each first training text, wherein the multiple first training texts can be obtained by randomly sampling the multiple historical texts collected. Considering that the prerequisite for the preset classification model to learn the classification ability is that a certain number of training texts with category label data are required, the total number of the multiple first training texts needs to be greater than or equal to a certain number, for example, it can be a first number. The category label data of each first training text is obtained by the first object by classifying each first training text according to the preset classification business requirements corresponding to the multiple first training texts. Therefore, the present application provides a possible implementation method, and the step of obtaining multiple first training texts can be specifically, for example, as follows: randomly sampling the multiple historical texts collected to obtain multiple first training texts; the total number of multiple first training texts is greater than or equal to the first number. The step of obtaining the category label data of each first training text can be specifically, for example, as follows: in response to the first object's category labeling operation on each first training text according to the preset classification business requirements corresponding to the multiple first training texts, the category label data of each first training text is obtained.
[0144] As an example, in a payment business complaint scenario, multiple historical texts include "Historical Complaint Text 1", "Historical Complaint Text 2", ... and "Historical Complaint Text 10000", the first quantity is 500, the first object is "Object A", and the preset classification business demand is "Payment Business Complaint Demand". First, "Historical Complaint Text 1", "Historical Complaint Text 2", ... and "Historical Complaint Text 10000" are randomly sampled to obtain multiple first training texts including "Historical Complaint Text 1", "Historical Complaint Text 2", ... and "Historical Complaint Text m", where m is a positive integer, m≥500. Then, in response to the category labeling operation of "Historical Complaint Text j" by "Object A" according to the "Payment Business Complaint Demand", the category label data of "Historical Complaint Text j" is obtained, where j is a positive integer, j=1, 2, ..., m. When multiple preset categories include "consumer complaint category", "toll collector complaint category" and "payment fee complaint category", if "historical complaint text j" belongs to the "consumer complaint category", the category label data of "historical complaint text j" is "[1, 0, 0]"; if "historical complaint text j" belongs to the "toll collector complaint category", the category label data of "historical complaint text j" is "[0, 1, 0]"; if "historical complaint text j" belongs to the "payment fee complaint category", the category label data of "historical complaint text j" is "[0, 0, 1]".
[0145] S2: Performing normalization processing based on knowledge distillation on the third distribution probability through the normalization layer in the first classification model to obtain target distribution probabilities of multiple preset categories to which the first training text belongs.
[0146] Among them, performing normalization processing on the third distribution probability based on knowledge distillation means: first performing distillation processing on the third distribution probability, for example, the third distribution probability may be divided by T; and then performing normalization processing on the third distribution probability after distillation.
[0147] S3: Using the second pre-trained model in the second classification model, perform category prediction on each first training text to obtain a fourth distribution probability of multiple preset categories to which the first training text belongs; the model complexity of the first pre-trained model is greater than the complexity of the second pre-trained model.
[0148] Among them, considering that the classification effect of BERT can exceed the classification effect of LSTM or textCNN, the second pre-trained model in the second classification model can be BERT with smaller model complexity.
[0149] S4: Performing normalization processing based on knowledge distillation on the fourth distribution probability through the first normalization layer in the second classification model to obtain first prediction probabilities of multiple preset categories to which the first training text belongs.
[0150] Among them, performing normalization processing on the fourth distribution probability based on knowledge distillation means: first performing distillation processing on the fourth distribution probability, for example, the fourth distribution probability may be divided by T; and then performing normalization processing on the fourth distribution probability after distillation.
[0151] S5: Normalizing the fourth distribution probability through a second normalization layer in the second classification model to obtain second prediction probabilities of the plurality of preset categories to which the first training text belongs.
[0152] S6: According to the first prediction probability, the target distribution probability, the second prediction probability, the category label data annotated by the first training text, and the preset loss function of the second classification model, the model parameters of the second classification model are trained until the model converges.
[0153] In the specific implementation of S6, considering that the target distribution probabilities of the multiple preset categories to which the first training text belongs are actually used to train the first prediction probabilities of the multiple preset categories to which the first training text belongs, and the category label data annotated by the first training text are actually used to train the second prediction probabilities of the multiple preset categories to which the first training text belongs, the preset loss function of the second classification model is set to two loss functions, namely, a first loss function for calculating the loss between the first prediction probability and the target distribution probability, and a second loss function for calculating the loss between the second prediction probability and the category label data. Based on this, firstly, the first prediction probability and the target distribution probability are substituted into the first loss function to calculate the first loss corresponding to the first training text, and the second prediction probability and the category label data are substituted into the second loss function to calculate the second loss corresponding to the first training text; then, the third weight and the fourth weight are respectively assigned to adjust the ratio of the first loss and the second loss to obtain the total loss by weighting, wherein the sum of the third weight and the fourth weight is 1; finally, the model parameters of the second classification model are iteratively trained by the total loss until the model converges, and the model convergence is manifested as the total loss no longer decreasing or reaching the preset number of iterations. Therefore, the present application provides a possible implementation method, where the preset loss function includes a first loss function and a second loss function; S6 may include, for example, the following S61-S64:
[0154] S61: Determine a first loss corresponding to the first training text according to the first prediction probability, the target distribution probability and the first loss function.
[0155] S62: Determine a second loss corresponding to the first training text according to the second prediction probability, the category label data and the second loss function.
[0156] S63: Perform weighted processing on the first loss, the third weight corresponding to the first loss, the second loss, and the fourth weight corresponding to the second loss to obtain a total loss corresponding to the first training text; the sum of the third weight and the fourth weight is 1.
[0157] S64: Train the model parameters of the second classification model according to the total loss until the model converges.
[0158] As an example, see Figure 6 , Figure 6 A schematic diagram of model training based on knowledge distillation for a first classification model and a second classification model is provided for an embodiment of the present application; wherein the first classification model is "model A" with a larger model complexity, the second classification model is "model B" with a smaller model complexity, the first pre-trained model is "first BERT" with a larger model complexity, the second pre-trained model is "second BERT" with a larger model complexity, and multiple preset categories include "consumer complaint category", "fee payer complaint category" and "payment fee complaint category". Based on the above example, first, the multiple first training texts "Historical Complaint Text 1", "Historical Complaint Text 2", ... and "Historical Complaint Text m" are input into the "first BERT" in the "Model A" for category prediction, and the third distribution probability of "Consumer Complaint Class", "Toll Collector Complaint Class" and "Payment Fee Complaint Class" to which "Historical Complaint Text j" belongs is obtained; the third distribution probability is input into the normalization layer in the "Model A" and first distilled by dividing by T and then normalized, and the target distribution probability of "Consumer Complaint Class", "Toll Collector Complaint Class" and "Payment Fee Complaint Class" to which "Historical Complaint Text j" belongs is "[0.2, 0.2, 0.6]".
[0159] Secondly, the "historical complaint text j" is input into the "second BERT" in the "model B" for category prediction, and the fourth distribution probability of the "consumer complaint category", "toll collector complaint category" and "payment fee complaint category" to which the "historical complaint text j" belongs is obtained; not only is the fourth distribution probability input into the first normalization layer in the "model B" for distillation processing divided by T and then normalized, to obtain the first prediction probability of the "consumer complaint category", "toll collector complaint category" and "payment fee complaint category" to which the "historical complaint text j" belongs; but the fourth distribution probability is also input into the second normalization layer in the "model B" for direct normalization processing, to obtain the second prediction probability of the "consumer complaint category", "toll collector complaint category" and "payment fee complaint category" to which the "historical complaint text j" belongs.
[0160] Then, through the first predicted probability, "[0.2, 0.2, 0.6]", the second predicted probability and the category label data "[0, 0, 1]" of "historical complaint text j", combined with the first loss function and the second loss function of "Model B", the model parameters of "Model B" can be trained until the model converges; among them, the first loss function and the second loss function are both cross entropy loss functions.
[0161] S7: Determine the second pre-trained model and the second normalization layer in the trained second classification model as the preset classification model.
[0162] As an example, see Figure 7 , Figure 7 A schematic diagram of a model architecture of a preset classification model provided in an embodiment of the present application; wherein, based on the above example, the above Figure 6 The "second BERT" and the second normalization layer in "Model B" are used as the preset classification model; based on this, multiple texts to be classified include "current complaint text 1", "current complaint text 2", ... and "current complaint text n", where n is a positive integer. When n>3, the "current complaint text i" is input into the preset classification model for category prediction, and the first distribution probability of the "consumer complaint category", "fee collector complaint category" and "payment fee complaint category" to which the "current complaint text i" belongs is output as "distribution probability 1i", where i is a positive integer, i=1, 2, ..., n.
[0163] S202: Clustering is performed on the plurality of texts to be classified to obtain second distribution probabilities of the plurality of preset categories to which each text to be classified belongs.
[0164] In related technologies, when the total number of training texts is small or the categories are unbalanced, the classification ability of the text classification model is weak. Only using the text classification model to predict the category of the text to be classified can easily lead to low classification accuracy, resulting in poor classification effect of the text to be classified.
[0165] Therefore, in an embodiment of the present application, after executing S201 to predict the category of each text to be classified in a plurality of texts to be classified according to a preset classification model, and obtaining a first distribution probability of the plurality of preset categories to which each text to be classified belongs, in order to make up for the shortcoming of the weak classification ability of the preset classification model caused by the small total number of the plurality of first training texts or the imbalance of the categories, it is also necessary to cluster the plurality of texts to be classified to obtain the probability distribution of the plurality of preset categories to which each text to be classified belongs, which is recorded as the second distribution probability of the plurality of preset categories to which each text to be classified belongs.
[0166] In the specific implementation of S202, when multiple preset categories are determined, first, multiple initial center points equal to the number of the multiple preset categories are randomly selected; secondly, the distance between each text to be classified and each initial center point in the multiple texts to be classified is calculated, and each text to be classified is clustered to the initial center point closest to it, then the multiple texts to be classified clustered under the preset category corresponding to each initial center point represent a cluster cluster; then, after the multiple texts to be classified are clustered, each initial center point is recalculated according to the multiple texts to be classified clustered under its corresponding preset category to update the initial center point, and the above process is repeated until the clustering converges, and the clustering convergence refers to any one of no (or a minimum number of) texts to be classified being re-clustered to different initial center points, no (or a minimum number of) initial center points changing again, and the sum of squares of distance errors between the multiple texts to be classified clustered under the preset category corresponding to each initial center point and the initial center point being locally minimum; finally, according to the preset category to which each text to be classified belongs after clustering convergence, the second distribution probability of each text to be classified belonging to the multiple preset categories can be determined. Therefore, the present application provides a possible implementation method, where S202 may include, for example, the following S2021-S2025:
[0167] S2021: Determine multiple initial center points corresponding to multiple preset categories.
[0168] S2022: Clustering the multiple texts to be classified according to the distance between each text to be classified and each initial center point to determine the preset category to which each text to be classified belongs.
[0169] S2023: Update each initial center point according to the multiple texts to be classified that are clustered under the preset category corresponding to each initial center point.
[0170] S2024: Repeat the clustering process of the plurality of texts to be classified according to the distance between each text to be classified and each initial center point until the clustering converges.
[0171] S2025: Determine a second distribution probability of the plurality of preset categories to which each to-be-classified text belongs according to the preset category to which each to-be-classified text belongs after clustering convergence.
[0172] As an example, based on the above example, based on multiple texts to be classified "Current Complaint Text 1", "Current Complaint Text 2", ... and "Current Complaint Text n", three initial center points corresponding to multiple "Consumer Complaint Categories", "Toll Collector Complaint Categories" and "Payment Fee Complaint Categories" are determined; the distance between "Current Complaint Text i" and each initial center point is calculated, and "Current Complaint Text i" is clustered to the initial center point closest to it; after "Current Complaint Text 1", "Current Complaint Text 2", ... and "Current Complaint Text n" are clustered, each initial center point is recalculated according to the multiple texts to be classified clustered under its corresponding preset category to update the initial center point; the above process is repeated until the clustering converges, and according to the preset category to which the "Current Complaint Text i" belongs after clustering converges, the second distribution probability of the "Consumer Complaint Category", "Toll Collector Complaint Category" and "Payment Fee Complaint Category" to which the "Current Complaint Text i" belongs is determined as "Distribution Probability 2i".
[0173] S203: For each text to be classified, a first distribution probability of the multiple preset categories to which the text to be classified belongs and a second distribution probability of the multiple preset categories to which the text to be classified belongs are fused to obtain a fused distribution probability of the multiple preset categories to which the text to be classified belongs.
[0174] In an embodiment of the present application, after executing S201-S202 to obtain the first distribution probability of each text to be classified belonging to multiple preset categories predicted by the preset classification model, and the second distribution probability of each text to be classified belonging to multiple preset categories determined by clustering, in order to make the probability distribution of each text to be classified belonging to multiple preset categories more accurate, for each text to be classified, the first distribution probability and the second distribution probability are processed by a fusion method to obtain a fused distribution probability of the multiple preset categories to which the text to be classified belongs, and the fused distribution probability is more accurate than the first distribution probability and the second distribution probability.
[0175] In the specific implementation of S203, considering the different importance of the first distribution probability and the second distribution probability, a first weight and a second weight are respectively assigned to the first distribution probability and the second distribution probability, and the first weight and the second weight are used to adjust the ratio of the first distribution probability and the second distribution probability to obtain a weighted fusion distribution probability; wherein the sum of the first weight and the second weight is 1. Therefore, the present application provides a possible implementation method, and S203 may include, for example, the following S2031-S2032:
[0176] S2031: Determine a first weight corresponding to the first distribution probability and a second weight corresponding to the second distribution probability; the sum of the first weight and the second weight is 1;
[0177] S2032: Perform weighted processing on the first distribution probabilities and the first weight of the multiple preset categories to which the text to be classified belongs, and the second distribution probabilities and the second weight of the multiple preset categories to which the text to be classified belongs, to obtain a fusion distribution probability of the multiple preset categories to which the text to be classified belongs.
[0178] As an example, the first weight is α, the second weight is β, α+β=1. Based on the above example, for each text to be classified "current complaint text i", weighted "distribution probability 1i", α, "distribution probability 2i" and β, the fused distribution probability of the multiple preset categories of "consumer complaint category", "fee collector complaint category" and "payment fee complaint category" of "current complaint text i" is obtained as "distribution probability i", that is, "distribution probability i"=α×"distribution probability 1i"+β×"distribution probability 2i".
[0179] S204: Determine the classification category to which the to-be-classified text belongs according to the preset category corresponding to the maximum probability component in the fused distribution probability.
[0180] In an embodiment of the present application, after executing S203 to obtain the fused distribution probability of multiple preset categories to which the text to be classified belongs, on the basis that the fused distribution probability is more accurate than the first distribution probability and the second distribution probability, and considering that the fused distribution probability can more accurately represent the probability distribution of multiple preset categories to which the text to be classified belongs, the preset category corresponding to the maximum probability component in the fused distribution probability can be directly used as the classification category to which the text to be classified belongs, so as to improve the classification accuracy of the text to be classified, thereby improving the classification effect of the text to be classified.
[0181] As an example, based on the above example, when the fusion distribution probability of multiple preset categories of "consumer complaint category", "toll collector complaint category" and "payment fee complaint category" to which the text to be classified "current complaint text i" belongs is "distribution probability i", the preset category corresponding to the maximum probability component in "distribution probability i" is taken as the classification category to which the "current complaint text i" belongs. If the "distribution probability i" is specifically "[0.8, 0.1, 0.1]", since the preset category corresponding to the maximum probability component "0.8" is "Consumer complaint category", the classification category to which the "current complaint text i" belongs is "Consumer complaint category"; if the "distribution probability i" is specifically "[0.1, 0.8, 0.1]", since the preset category corresponding to the maximum probability component "0.8" is "Toll collector complaint category", the classification category to which the "current complaint text i" belongs is "Toll collector complaint category"; if the "distribution probability i" is specifically "[0.1, 0.1, 0.8]", since the preset category corresponding to the maximum probability component "0.8" is "Payment fee complaint category", the classification category to which the "current complaint text i" belongs is "Payment fee complaint category".
[0182] In addition, in the embodiment of the present application, after the category label data of each first training text is obtained as described above, before S1 is implemented, since the category label data of each first training text is obtained by category annotation of the first object according to preset classification business requirements, there may be a problem of low accuracy of the category label data of some first training texts; in order to solve this problem, firstly, a plurality of texts to be annotated whose total number is greater than or equal to a second number can be randomly sampled from the plurality of first training texts, and the second number is less than the aforementioned first number; then, each text to be annotated is category-annotated according to the preset classification business requirements by a second object different from the first object to obtain annotation category data of each text to be annotated; finally, it is determined whether the plurality of category label data corresponding to the plurality of texts to be annotated are the same as the plurality of category label data corresponding to the plurality of texts to be annotated. Whether the consistency degree among multiple annotation category data is greater than or equal to the preset consistency degree. If so, it means that different objects have consistent category annotations for each text to be annotated according to preset classification business requirements. In this case, it can be determined that the accuracy of the category label data of each first training text is high, that is, it is determined that the category label data of each first training text is correct. If not, it means that different objects have inconsistent category annotations for each text to be annotated according to preset classification business requirements. In this case, it can be determined that the annotation accuracy of the category label data of each first training text is low, and it is necessary to update the category label data of each first training text to improve the accuracy of the category label data of each first training text, so as to facilitate the subsequent execution of S6 based on the updated category label data of each first training text, thereby further improving the classification accuracy of the preset classification model.
[0183] Therefore, the present application provides a possible implementation method, and the method may also include the following steps: randomly sampling multiple first training texts to obtain multiple texts to be annotated; the total number of the multiple texts to be annotated is greater than or equal to a second number, and the second number is less than the first number; in response to the second object performing a category labeling operation on each text to be annotated according to preset classification business requirements, obtaining annotation category data of each text to be annotated; if the degree of consistency between the multiple category label data corresponding to the multiple texts to be annotated and the multiple annotation category data corresponding to the multiple texts to be annotated is greater than or equal to a preset consistency degree, determining that the category label data of each first training text is correctly labeled; if the degree of consistency is less than the preset consistency degree, updating the category label data of each first training text.
[0184] In addition, in an embodiment of the present application, after the aforementioned S1-S7 and before S201 is implemented, the classification accuracy of the preset classification model can also be verified. The specific implementation method is: based on multiple test texts different from the multiple first training texts and the category label data annotated by each test text, first, each test text is input into the preset classification model for category prediction, and the probability distribution of the multiple preset categories to which each test text belongs is output, which is recorded as the third predicted probability of the multiple preset categories to which each test text belongs; then, the third predicted probability of the multiple preset categories to which each test text belongs and the category label data annotated by each test text are substituted into the preset verification index to perform model verification on the preset classification model. Verify the model verification result of the preset classification model; finally, determine whether the model verification result meets the preset verification conditions. If so, it means that the classification accuracy of the preset classification model is high, and S201 can be directly executed. If not, it means that the classification accuracy of the preset classification model is low, and it is necessary to re-extract multiple second training texts from multiple historical texts to update multiple first training texts, and re-train the first classification model and the second classification model based on knowledge distillation on the basis of multiple second training texts and the category label data annotated by each second training text, so as to update the preset classification model and improve the classification accuracy of the updated preset classification model, so as to facilitate the subsequent execution of S201 according to the updated preset classification model. Therefore, the present application provides a possible implementation method, and the method may also include the following S8-S:
[0185] S8: Performing category prediction on each of the multiple test texts that are different from the multiple first training texts using a preset classification model to obtain a third prediction probability that each test text belongs to the multiple preset categories.
[0186] S9: According to the third prediction probabilities of the multiple preset categories to which each text to be tested belongs, the category label data annotated by each text to be tested, and the preset verification indicators, the preset classification model is verified to obtain the model verification result of the preset classification model.
[0187] Among them, the preset verification indicator can be any one of the common multi-classification model evaluation indicators such as confusion matrix, accuracy and recall rate. Therefore, the present application provides a possible implementation method, and the preset verification indicator includes any one of the confusion matrix, accuracy and recall rate.
[0188] As an example, see Figure 8 , Figure 8A schematic diagram of a confusion matrix provided for an embodiment of the present application; wherein the vertical markings of the confusion matrix represent the true categories corresponding to the category label data of multiple samples to be tested, which are "consumer complaint category", "toll collector complaint category" and "payment fee complaint category" from top to bottom; the horizontal markings of the confusion matrix represent the predicted categories corresponding to the third predicted probabilities of multiple samples to be tested, which are "consumer complaint category", "toll collector complaint category" and "payment fee complaint category" from left to right. Based on this, the first row and the first column of the confusion matrix represent the number of "consumer complaint category" to which the samples to be tested actually belong and are predicted to belong, which is "13", the first row and the second column represent the number of "consumer complaint category" to which the samples to be tested actually belong and are predicted to belong, which is "0", and so on, the third row and the third column represent the number of "payment fee complaint category" to which the samples to be tested actually belong and are predicted to belong, which is "9".
[0189] S10: If the model verification result does not meet the preset verification condition, update the multiple first training texts according to the multiple historical texts to obtain multiple second training texts.
[0190] S11: According to the plurality of second training texts and the category label data annotated by each second training text, the first classification model and the second classification model are trained based on knowledge distillation, and the preset classification model is updated.
[0191] In addition, in the embodiment of the present application, in the text classification reply scenario, the purpose of text classification of the text to be classified can be: to find a reply text that is more suitable for the classification category to which the text to be classified belongs in the future, and to use the reply text of the text to be classified as a reply text to more accurately reply to the text to be classified. Therefore, the present application provides a possible implementation method, when the text classification method is applied to the text classification reply scenario, the method can also include the following S12: according to the classification category to which the text to be classified belongs, the corresponding text to be classified determines the reply text that meets the classification category.
[0192] As an example, based on the above example, when the text classification method is applied to the text classification reply scenario, if the classification category of the text to be classified "current complaint text i" is "consumer complaint category", the corresponding "current complaint text i" determines that the reply text that meets the "consumer complaint category" is "reply text a"; if the classification category of the text to be classified "current complaint text i" is "fee payer complaint category", the corresponding "current complaint text i" determines that the reply text that meets the "fee payer complaint category" is "reply text b"; if the classification category of the text to be classified "current complaint text i" is "payment complaint category", the corresponding "current complaint text i" determines that the reply text that meets the "payment complaint category" is "reply text c".
[0193] It can be seen from the above technical solution that the first classification model and the second classification model are trained based on knowledge distillation through multiple first training texts and the category label data annotated by each first training text to obtain a preset classification model, wherein the model complexity of the first classification model is greater than the complexity of the second classification model, then each of the multiple texts to be classified is input into the preset classification model for category prediction, and the first distribution probability of each text to be classified belonging to multiple preset categories is output; since the model training method based on knowledge distillation enables the preset classification model to reduce the model complexity without reducing the classification accuracy as much as possible, the classification performance of the text to be classified can be guaranteed to a certain extent through the preset classification model. In addition, the multiple texts to be classified are clustered to obtain the second distribution probability of each text to be classified belonging to multiple preset categories; this clustering method can make up for the shortcomings of the weak classification ability of the preset classification model caused by the small total number of multiple first training texts or the imbalance of categories. For each text to be classified, the first distribution probability of multiple preset categories to which the text to be classified belongs and the second distribution probability of multiple preset categories to which the text to be classified belongs are fused to obtain the fused distribution probability of multiple preset categories to which the text to be classified belongs; this fusion method makes the fused distribution probability more accurate than the first distribution probability and the second distribution probability. The preset category corresponding to the maximum probability component in the fused distribution probability is used as the classification category to which the text to be classified belongs, which can improve the classification accuracy of the text to be classified, thereby improving the classification effect of the text to be classified.
[0194] Next, in the payment service complaint scenario, the text classification method provided by the embodiment of the present application is described in detail with reference to the accompanying drawings. Fig. 9 , Fig. 9 A flowchart of a text classification method combined with an actual application scenario provided in an embodiment of the present application, the method includes:
[0195] S901: A preset classification model is used to predict the category of each of the multiple current complaint texts to obtain a first distribution probability of the multiple payment complaint categories to which each current complaint text belongs; the preset classification model is obtained by training the first classification model and the second classification model based on knowledge distillation according to multiple historical complaint texts and the category label data annotated with each historical complaint text, and the model complexity of the first classification model is greater than the complexity of the second classification model.
[0196] S902: Clustering is performed on multiple current complaint texts to obtain a second distribution probability of multiple payment complaint categories to which each current complaint text belongs.
[0197] S903: Determine a first weight corresponding to the first distribution probability and a second weight corresponding to the second distribution probability; the sum of the first weight and the second weight is 1.
[0198] S904: For each current complaint text, weighted processing is performed on the first distribution probability and the first weight of the multiple payment complaint categories to which the current complaint text belongs, and the second distribution probability and the second weight of the multiple payment complaint categories to which the current complaint text belongs, to obtain the fused distribution probability of the multiple payment complaint categories to which the current complaint text belongs.
[0199] S905: Determine the classification category to which the current complaint text belongs based on the payment complaint category corresponding to the maximum probability component in the fused distribution probability.
[0200] S906: According to the classification category to which the current complaint text belongs, determine the text to be replied that meets the classification category corresponding to the current complaint text.
[0201] It can be seen from the above technical solutions that the model training method based on knowledge distillation allows the preset classification model to reduce the model complexity without reducing the classification accuracy as much as possible. Therefore, the classification performance of the current complaint text can be guaranteed to a certain extent through the preset classification model; in addition, the clustering method can make up for the shortcomings of the weak classification ability of the preset classification model caused by the small total number of multiple historical complaint texts or the imbalance of categories. The fusion method makes the fused distribution probability more accurate than the first distribution probability and the second distribution probability. The classification category to which the current complaint text belongs is determined based on the preset category corresponding to the maximum probability component in the fused distribution probability, so as to improve the classification accuracy of the current complaint text, so as to improve the classification effect of the current complaint text, thereby improving the accuracy of the text to be replied to the current complaint text.
[0202] It should be noted that, based on the implementation methods provided in the above aspects, this application can also be further combined to provide more implementation methods.
[0203] Next, based on Figure 2 Corresponding to the text classification method provided in the embodiment, the present application embodiment also provides a text classification device, see Fig.10 , Fig.10 This is a structural diagram of a text classification device provided in an embodiment of the present application. The text classification device 1000 includes: a prediction unit 1001, a clustering unit 1002, a fusion unit 1003 and a determination unit 1004;
[0204] The prediction unit 1001 is used to predict the category of each of the multiple texts to be classified by using a preset classification model to obtain a first distribution probability of each text to be classified belonging to multiple preset categories; the preset classification model is obtained by performing model training based on knowledge distillation on a first classification model and a second classification model according to multiple first training texts and category label data annotated by each first training text, and the model complexity of the first classification model is greater than the complexity of the second classification model;
[0205] A clustering unit 1002 is used to perform clustering processing on a plurality of to-be-classified texts to obtain a second distribution probability that each to-be-classified text belongs to a plurality of preset categories;
[0206] A fusion unit 1003 is used to fuse the first distribution probability of the multiple preset categories to which the text to be classified belongs and the second distribution probability of the multiple preset categories to which the text to be classified belongs for each text to be classified, so as to obtain a fused distribution probability of the multiple preset categories to which the text to be classified belongs;
[0207] The determination unit 1004 is used to determine the classification category to which the to-be-classified text belongs according to the preset category corresponding to the maximum probability component in the fused distribution probability.
[0208] In a possible implementation, the fusion unit 1003 is specifically configured to:
[0209] Determine a first weight corresponding to the first distribution probability and a second weight corresponding to the second distribution probability; the sum of the first weight and the second weight is 1;
[0210] The first distribution probabilities and the first weight of the multiple preset categories to which the text to be classified belongs, the second distribution probabilities and the second weight of the multiple preset categories to which the text to be classified belongs are weighted to obtain the fused distribution probabilities of the multiple preset categories to which the text to be classified belongs.
[0211] In a possible implementation, the apparatus further includes: a training unit;
[0212] The training unit is specifically configured to perform category prediction on each first training text by using a first pre-training model in a first classification model to obtain a third distribution probability of a plurality of preset categories to which the first training text belongs;
[0213] The third distribution probability is normalized based on knowledge distillation through a normalization layer in the first classification model to obtain target distribution probabilities of multiple preset categories to which the first training text belongs;
[0214] Using the second pre-trained model in the second classification model, each first training text is predicted to be a category, so as to obtain a fourth distribution probability of a plurality of preset categories to which the first training text belongs; the model complexity of the first pre-trained model is greater than the complexity of the second pre-trained model;
[0215] By using a first normalization layer in the second classification model, the fourth distribution probability is normalized based on knowledge distillation to obtain first prediction probabilities of multiple preset categories to which the first training text belongs;
[0216] The fourth distribution probability is normalized by a second normalization layer in the second classification model to obtain second prediction probabilities of the plurality of preset categories to which the first training text belongs;
[0217] Training model parameters of the second classification model until the model converges according to the first prediction probability, the target distribution probability, the second prediction probability, the category label data annotated by the first training text, and the preset loss function of the second classification model;
[0218] The second pre-trained model and the second normalization layer in the trained second classification model are determined as the preset classification model.
[0219] In a possible implementation, the training unit is specifically configured to:
[0220] Determine a first loss corresponding to the first training text according to the first prediction probability, the target distribution probability and the first loss function;
[0221] Determine a second loss corresponding to the first training text according to the second prediction probability, the category label data, and the second loss function;
[0222] The first loss, the third weight corresponding to the first loss, the second loss, and the fourth weight corresponding to the second loss are weighted to obtain a total loss corresponding to the first training text; the sum of the third weight and the fourth weight is 1;
[0223] The model parameters of the second classification model are trained according to the total loss until the model converges.
[0224] In a possible implementation, the device further includes: a sampling unit;
[0225] The sampling unit is used to randomly sample the collected multiple historical texts to obtain multiple first training texts; the total number of the multiple first training texts is greater than or equal to the first number.
[0226] In a possible implementation, the device further includes: a labeling unit;
[0227] The labeling unit is used to obtain the category label data of each first training text in response to the first object labeling each first training text according to the preset classification business requirements corresponding to the plurality of first training texts.
[0228] In a possible implementation, the apparatus further includes: a first updating unit;
[0229] The sampling unit is further used to randomly sample the plurality of first training texts to obtain a plurality of texts to be annotated; the total number of the plurality of texts to be annotated is greater than or equal to a second number, and the second number is less than the first number;
[0230] The marking unit is further used to obtain the annotation category data of each text to be annotated in response to the second object's category marking operation on each text to be annotated according to the preset classification business requirements;
[0231] The determination unit 1004 is further configured to determine that the category label data of each first training text is correctly annotated if the consistency between the multiple category label data corresponding to the multiple texts to be annotated and the multiple annotation category data corresponding to the multiple texts to be annotated is greater than or equal to a preset consistency degree;
[0232] The first updating unit is used to update the category label data of each first training text if the consistency level is less than a preset consistency level.
[0233] In a possible implementation, the apparatus further includes: a verification unit and a second updating unit;
[0234] The prediction unit 1001 is further configured to perform category prediction on each of the multiple test texts that are different from the multiple first training texts through a preset classification model to obtain a third prediction probability that each test text belongs to the multiple preset categories;
[0235] A verification unit, used to perform model verification on a preset classification model according to the third prediction probabilities of the multiple preset categories to which each to-be-tested text belongs, the category label data annotated by each to-be-tested text, and a preset verification index, to obtain a model verification result of the preset classification model;
[0236] A second updating unit is used to update the plurality of first training texts according to the plurality of historical texts to obtain the plurality of second training texts if the model verification result does not meet the preset verification condition;
[0237] The second updating unit is further used to perform model training based on knowledge distillation on the first classification model and the second classification model according to the multiple second training texts and the category label data annotated by each second training text, and update the preset classification model.
[0238] In a possible implementation, the preset verification indicator includes any one of a confusion matrix, a precision rate, and a recall rate.
[0239] In a possible implementation, the clustering unit 1002 is specifically configured to:
[0240] Determine a plurality of initial center points corresponding to a plurality of preset categories;
[0241] Clustering multiple texts to be classified is performed according to the distance between each text to be classified and each initial center point, so as to determine the preset category to which each text to be classified belongs;
[0242] Update each initial center point according to a plurality of to-be-classified texts clustered under a preset category corresponding to each initial center point;
[0243] Repeat the clustering process of multiple texts to be classified according to the distance between each text to be classified and each initial center point until the clustering converges;
[0244] According to the preset category to which each to-be-classified text belongs after clustering convergence, a second distribution probability of the plurality of preset categories to which each to-be-classified text belongs is determined.
[0245] In a possible implementation, when the text classification method is applied to a text classification reply scenario, the determination unit 1004 is further configured to determine, according to the classification category to which the text to be classified belongs, a text to be replied that meets the classification category corresponding to the text to be classified.
[0246] It can be seen from the above technical solution that the first classification model and the second classification model are trained based on knowledge distillation through multiple first training texts and the category label data annotated by each first training text to obtain a preset classification model, wherein the model complexity of the first classification model is greater than the complexity of the second classification model, then each of the multiple texts to be classified is input into the preset classification model for category prediction, and the first distribution probability of each text to be classified belonging to multiple preset categories is output; since the model training method based on knowledge distillation enables the preset classification model to reduce the model complexity without reducing the classification accuracy as much as possible, the classification performance of the text to be classified can be guaranteed to a certain extent through the preset classification model. In addition, the multiple texts to be classified are clustered to obtain the second distribution probability of each text to be classified belonging to multiple preset categories; this clustering method can make up for the shortcomings of the weak classification ability of the preset classification model caused by the small total number of multiple first training texts or the imbalance of categories. For each text to be classified, the first distribution probability of multiple preset categories to which the text to be classified belongs and the second distribution probability of multiple preset categories to which the text to be classified belongs are fused to obtain the fused distribution probability of multiple preset categories to which the text to be classified belongs; this fusion method makes the fused distribution probability more accurate than the first distribution probability and the second distribution probability. The preset category corresponding to the maximum probability component in the fused distribution probability is used as the classification category to which the text to be classified belongs, which can improve the classification accuracy of the text to be classified, thereby improving the classification effect of the text to be classified.
[0247] The present application also provides a computer device, which may be a server. Fig.11 , Fig.11A structural diagram of a server provided in an embodiment of the present application, the server 1100 may have relatively large differences due to different configurations or performances, and may include one or more processors, such as a central processing unit (CPU) 1122, and a memory 1132, one or more storage media 1130 (such as one or more mass storage devices) storing application programs 1142 or data 1144. Among them, the memory 1132 and the storage medium 1130 can be short-term storage or permanent storage. The program stored in the storage medium 1130 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the server. Furthermore, the central processing unit 1122 can be configured to communicate with the storage medium 1130 and execute a series of instruction operations in the storage medium 1130 on the server 1100.
[0248] The server 1100 may also include one or more power supplies 1126, one or more wired or wireless network interfaces 1150, one or more input and output interfaces 1158, and / or one or more operating systems 1141, such as Windows Server 2003. TM , Mac OS X TM , Unix TM ,Linux TM , FreeBSD TM etc.
[0249] In this embodiment, the central processor 1122 in the server 1100 may perform the following steps:
[0250] A preset classification model is used to predict the category of each of the multiple texts to be classified, and a first distribution probability of each text to be classified belonging to multiple preset categories is obtained; the preset classification model is obtained by training the first classification model and the second classification model based on knowledge distillation according to the multiple first training texts and the category label data annotated by each first training text, and the model complexity of the first classification model is greater than the complexity of the second classification model;
[0251] Performing clustering processing on the multiple texts to be classified to obtain second distribution probabilities of each text to be classified belonging to the multiple preset categories;
[0252] For each text to be classified, a first distribution probability of multiple preset categories to which the text to be classified belongs and a second distribution probability of multiple preset categories to which the text to be classified belongs are fused to obtain a fused distribution probability of multiple preset categories to which the text to be classified belongs;
[0253] According to the preset category corresponding to the maximum probability component in the fusion distribution probability, the classification category to which the text to be classified belongs is determined.
[0254] The computer device provided in the embodiment of the present application may also be a terminal. Fig.12 , Fig.12 A structural diagram of a terminal provided in an embodiment of the present application. Taking a smartphone as an example, the smartphone includes: a radio frequency (RF) circuit 1210, a memory 1220, an input unit 1230, a display unit 1240, a sensor 1250, an audio circuit 1260, a wireless fidelity (WiFi) module 1270, a processor 1280, and a power supply 1290 and other components. The input unit 1230 may include a touch panel 1231 and other input devices 1232, the display unit 1240 may include a display panel 1241, and the audio circuit 1260 may include a speaker 1261 and a microphone 1262. Those skilled in the art will understand that Fig.12 The structure of the smartphone shown in the figure does not constitute a limitation of the smartphone, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0255] The memory 1220 can be used to store software programs and modules. The processor 1280 executes various functional applications and data processing of the smartphone by running the software programs and modules stored in the memory 1220. The memory 1220 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the smartphone (such as audio data, a phone book, etc.), etc. In addition, the memory 1220 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0256] The processor 1280 is the control center of the smartphone, which uses various interfaces and lines to connect various parts of the entire smartphone, and executes various functions of the smartphone and processes data by running or executing software programs and / or modules stored in the memory 1220, and calling data stored in the memory 1220. Optionally, the processor 1280 may include one or more processing units; preferably, the processor 1280 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 1280.
[0257] In this embodiment, the processor 1280 in the smartphone may perform the following steps:
[0258] A preset classification model is used to predict the category of each of the multiple texts to be classified, and a first distribution probability of each text to be classified belonging to multiple preset categories is obtained; the preset classification model is obtained by training the first classification model and the second classification model based on knowledge distillation according to the multiple first training texts and the category label data annotated by each first training text, and the model complexity of the first classification model is greater than the complexity of the second classification model;
[0259] Performing clustering processing on the multiple texts to be classified to obtain second distribution probabilities of each text to be classified belonging to the multiple preset categories;
[0260] For each text to be classified, a first distribution probability of multiple preset categories to which the text to be classified belongs and a second distribution probability of multiple preset categories to which the text to be classified belongs are fused to obtain a fused distribution probability of multiple preset categories to which the text to be classified belongs;
[0261] According to the preset category corresponding to the maximum probability component in the fusion distribution probability, the classification category to which the text to be classified belongs is determined.
[0262] According to one aspect of the present application, a computer-readable storage medium is provided, wherein the computer-readable storage medium is used to store a computer program, and the computer program is used to implement the text classification method described in the above-mentioned embodiments.
[0263] According to one aspect of the present application, a computer program product is provided, the computer program product comprising a computer program, the computer program being stored in a computer-readable storage medium. A processor of a computer device reads the computer program from the computer-readable storage medium, and the processor executes the computer program, so that the computer device executes the method provided in various optional implementations of the above-mentioned embodiments.
[0264] The descriptions of the processes or structures corresponding to the above-mentioned figures have different emphases. For parts that are not described in detail in a certain process or structure, please refer to the relevant descriptions of other processes or structures.
[0265] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein, for example. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0266] In the specific implementation of this application, if relevant data such as preset objects, actual interaction data, etc. involve user information, when the above embodiments of this application are applied to specific products or technologies, the user's separate permission or consent is required, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of relevant countries and regions.
[0267] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0268] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0269] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0270] If the integrated unit is implemented in the form of a 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 technical solution of the present application, or the part that contributes to the prior art or all or part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc. Various media that can store computer programs.
[0271] As described above, the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, ordinary technical members in the art should understand that they can still modify the technical solutions recorded in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A text classification method, characterized in that: The method comprises: A category prediction is performed on each of the multiple texts to be classified by a preset classification model to obtain a first distribution probability of the multiple preset categories to which each text to be classified belongs; the preset classification model is obtained by performing model training based on knowledge distillation on a first classification model and a second classification model according to multiple first training texts and category label data annotated with each first training text, and the model complexity of the first classification model is greater than the complexity of the second classification model; Performing clustering processing on the multiple texts to be classified to obtain a second distribution probability that each of the texts to be classified belongs to the multiple preset categories; For each of the texts to be classified, a first distribution probability of the plurality of preset categories to which the text to be classified belongs and a second distribution probability of the plurality of preset categories to which the text to be classified belongs are fused to obtain a fused distribution probability of the plurality of preset categories to which the text to be classified belongs; The classification category to which the to-be-classified text belongs is determined according to the preset category corresponding to the maximum probability component in the fused distribution probability.
2. The method according to claim 1, characterized in that The step of fusing the first distribution probabilities of the plurality of preset categories to which the text to be classified belongs and the second distribution probabilities of the plurality of preset categories to which the text to be classified belongs to obtain the fused distribution probabilities of the plurality of preset categories to which the text to be classified belongs, comprises: Determine a first weight corresponding to the first distribution probability and a second weight corresponding to the second distribution probability; the sum of the first weight and the second weight is 1; The first distribution probability of the multiple preset categories to which the text to be classified belongs, the first weight, the second distribution probability of the multiple preset categories to which the text to be classified belongs, and the second weight are weighted to obtain a fused distribution probability of the multiple preset categories to which the text to be classified belongs.
3. The method according to claim 1, characterized in that: The training step of the preset classification model includes: For each of the first training texts, using the first pre-training model in the first classification model, a category prediction is performed on the first training text to obtain a third distribution probability of the plurality of preset categories to which the first training text belongs; By using the normalization layer in the first classification model, the third distribution probability is normalized based on knowledge distillation to obtain target distribution probabilities of the plurality of preset categories to which the first training text belongs; Using the second pre-trained model in the second classification model, a category prediction is performed on each first training text to obtain a fourth distribution probability of the plurality of preset categories to which the first training text belongs; the model complexity of the first pre-trained model is greater than the complexity of the second pre-trained model; By using the first normalization layer in the second classification model, the fourth distribution probability is normalized based on knowledge distillation to obtain a first prediction probability that the first training text belongs to the plurality of preset categories; Normalizing the fourth distribution probability through a second normalization layer in the second classification model to obtain second prediction probabilities that the first training text belongs to the plurality of preset categories; Training model parameters of the second classification model until the model converges according to the first prediction probability, the target distribution probability, the second prediction probability, the category label data annotated by the first training text, and a preset loss function of the second classification model; The second pre-trained model and the second normalization layer in the trained second classification model are determined as the preset classification model.
4. The method according to claim 3, characterized in that The preset loss function includes a first loss function and a second loss function; the training of the model parameters of the second classification model until the model converges according to the first prediction probability, the target distribution probability, the second prediction probability, the category label data annotated by the first training text, and the preset loss function of the second classification model includes: Determining a first loss corresponding to the first training text according to the first prediction probability, the target distribution probability and the first loss function; Determine a second loss corresponding to the first training text according to the second predicted probability, the category label data and the second loss function; Performing weighted processing on the first loss, a third weight corresponding to the first loss, the second loss, and a fourth weight corresponding to the second loss to obtain a total loss corresponding to the first training text; the sum of the third weight and the fourth weight is 1; The model parameters of the second classification model are trained according to the total loss until the model converges.
5. The method according to claim 1, characterized in that The step of obtaining the plurality of first training texts is specifically as follows: The collected multiple historical texts are randomly sampled to obtain the multiple first training texts; the total number of the multiple first training texts is greater than or equal to the first number.
6. The method according to claim 5, characterized in that The step of obtaining the category label data of each first training text is specifically as follows: In response to the first object performing a category labeling operation on each of the first training texts according to preset classification business requirements corresponding to the plurality of first training texts, category label data of each of the first training texts is obtained.
7. The method according to claim 6, characterized in that Before training the preset classification model, the method further includes: Randomly sampling the plurality of first training texts to obtain a plurality of texts to be annotated; the total number of the plurality of texts to be annotated is greater than or equal to a second number, and the second number is less than the first number; In response to the second object performing a category marking operation on each text to be annotated according to the preset classification business requirement, obtaining annotation category data of each text to be annotated; If the consistency between the multiple category label data corresponding to the multiple texts to be annotated and the multiple annotation category data corresponding to the multiple texts to be annotated is greater than or equal to the preset consistency, it is determined that the category label data of each first training text is correctly annotated; If the consistency level is less than the preset consistency level, the category label data of each first training text is updated.
8. The method according to claim 5, characterized in that Before predicting the category of each of the multiple texts to be classified by using the preset classification model, the method further includes: Performing category prediction on each of the multiple to-be-tested texts that are different from the multiple first training texts by using the preset classification model to obtain a third prediction probability that each of the to-be-tested texts belongs to the multiple preset categories; According to the third prediction probabilities of the multiple preset categories to which each of the to-be-tested texts belongs, the category label data annotated by each of the to-be-tested texts, and the preset verification index, the preset classification model is model verified to obtain a model verification result of the preset classification model; If the model verification result does not meet the preset verification condition, updating the multiple first training texts according to the multiple historical texts to obtain multiple second training texts; According to the multiple second training texts and the category label data annotated by each second training text, the first classification model and the second classification model are trained based on knowledge distillation to update the preset classification model.
9. The method according to claim 8, characterized in that The preset verification indicator includes any one of a confusion matrix, accuracy and recall rate.
10. The method according to claim 1, characterized in that The clustering process is performed on the plurality of texts to be classified to obtain a second distribution probability that each text to be classified belongs to the plurality of preset categories, including: Determining a plurality of initial center points corresponding to the plurality of preset categories; Clustering the plurality of texts to be classified according to the distance between each text to be classified and each initial center point, and determining the preset category to which each text to be classified belongs; Update each initial center point according to a plurality of to-be-classified texts clustered under a preset category corresponding to each initial center point; Repeating the clustering process of the plurality of texts to be classified according to the distance between each text to be classified and each initial center point until the clustering converges; According to the preset category to which each to-be-classified text belongs after clustering convergence, a second distribution probability of each to-be-classified text belonging to the plurality of preset categories is determined.
11. The method according to any one of claims 1 to 10, characterized in that: When the text classification method is applied to a text classification reply scenario, the method further includes: According to the classification category to which the text to be classified belongs, a text to be replied that meets the classification category is determined corresponding to the text to be classified.
12. A text classification device, characterized in that: The device comprises: a prediction unit, a clustering unit, a fusion unit and a determination unit; The prediction unit is used to predict the category of each of the multiple texts to be classified by using a preset classification model to obtain a first distribution probability of the multiple preset categories to which each of the texts to be classified belongs; the preset classification model is obtained by performing model training based on knowledge distillation on a first classification model and a second classification model according to multiple first training texts and category label data annotated by each first training text, and the model complexity of the first classification model is greater than the complexity of the second classification model; The clustering unit is used to perform clustering processing on the multiple texts to be classified to obtain a second distribution probability that each text to be classified belongs to the multiple preset categories; The fusion unit is used to fuse the first distribution probability of the multiple preset categories to which the text to be classified belongs and the second distribution probability of the multiple preset categories to which the text to be classified belongs, for each text to be classified, to obtain the fused distribution probability of the multiple preset categories to which the text to be classified belongs; The determination unit is used to determine the classification category to which the to-be-classified text belongs according to the preset category corresponding to the maximum probability component in the fused distribution probability.
13. A computer device, characterized in that: The computer device comprises a processor and a memory: The memory is used to store a computer program and transmit the computer program to the processor; The processor is configured to execute the method according to any one of claims 1 to 11 according to the instructions in the computer program.
14. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store a computer program, and the computer program is used to implement the method according to any one of claims 1 to 11.
15. A computer program product comprising a computer program, characterized in that When the method is executed on a computer device, the computer device is enabled to execute the method according to any one of claims 1 to 11.
Citation Information
Patent Citations
Data sample clustering method and device
CN104765776A
Integrated classification identification method fused with classification and clustering
CN107563401A
Text analysis method and terminal
CN109376240A
Neural network language model, text prediction method and device, and storage medium
CN110147444A
Knowledge distillation-based text classification method and system
CN114818902A
