Classification model processing, intent recognition method, device and computer equipment
By acquiring a training sample set, extracting features and calculating loss using trained and untrained classification models, and adjusting model parameters, the problem of low accuracy in identifying new categories in existing classification models is solved, achieving high-accuracy category identification.
Patent Information
- Application Number
- CN202211000438.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-19
- Publication Date
- 2026-02-13
- Estimated Expiration
- 2042-08-19
AI Technical Summary
Existing classification models have low accuracy during continuous learning and struggle to effectively identify new categories.
By acquiring a training sample set, the first sample features are extracted using the trained classification model, and the second sample features are extracted using the classification model to be trained. The classification loss, the first target loss, and the second target loss are calculated. The model parameters are adjusted to form a target classification model, ensuring that the model has high accuracy in recognizing both identified categories and newly added categories.
The target classification model not only retains the knowledge of the trained model, but also improves the generalization between new and old categories, significantly enhancing the accuracy of category recognition.
Smart Images

Figure CN115456043B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a classification model processing method and device, computer equipment, storage medium and computer program product, and an intent recognition method and device, computer equipment, storage medium and computer program product. BACKGROUND
[0002] With the development of computer technology, machine learning technology appears, through which a classification model for classification can be trained, the classification model can extract features corresponding to content, and then can classify the content based on the extracted features to identify the category to which the content belongs.
[0003] In the traditional technology, the classification model can identify the already learned categories, however, as new categories continuously appear, continuous learning is needed, however, in the continuous learning process, there is often the problem of low recognition accuracy of the classification model obtained by training. SUMMARY
[0004] Therefore, it is necessary to provide a classification model processing method, device, computer equipment, computer readable storage medium and computer program product with high recognition accuracy.
[0005] In one aspect, the present application provides a classification model processing method. The method comprises: obtaining a training sample set; the training sample set comprises training samples belonging to an already recognized category corresponding to an already trained classification model and training samples belonging to a new category; extracting respective first sample features of each training sample in the training sample set by the already trained classification model; extracting respective second sample features of each training sample by a to-be-trained classification model, and classifying based on the respective second sample features, and determining a classification loss based on the obtained respective first classification results; performing loss calculation based on the first sample features and the second sample features of the same training sample to obtain a first target loss, and performing loss calculation based on the respective second sample features of each pair of training samples belonging to different categories to obtain a second target loss; adjusting parameters of the to-be-trained classification model based on the first target loss, the second target loss and the classification loss and continuing training, and when a training stop condition is met, obtaining a target classification model, the target classification model being used for identifying the already recognized category and the new category.
[0006] In another aspect, the present application also provides a classification model processing device. The device comprises: a training sample acquisition module configured to acquire a training sample set; the training sample set comprises training samples belonging to an identified category corresponding to a trained classification model and training samples belonging to a new category; a feature extraction module configured to extract first sample features of each training sample in the training sample set respectively by the trained classification model; a classification loss determination module configured to extract second sample features of each training sample respectively by a to-be-trained classification model, perform classification based on the second sample features, and determine a classification loss based on obtained first classification results; a target loss calculation module configured to calculate a first target loss based on the first sample features and the second sample features of the same training sample, and calculate a second target loss based on the second sample features of each pair of training samples belonging to different categories; and a parameter adjustment module configured to adjust parameters of the to-be-trained classification model based on the first target loss, the second target loss, and the classification loss, and continue training, and obtain a target classification model when a training stop condition is met, wherein the target classification model is used to identify the identified category and the new category.
[0007] In another aspect, the present application also provides a computer device. The computer device comprises a memory and a processor, the memory stores a computer program, and the processor implements the steps of the above classification model processing method when executing the computer program.
[0008] In another aspect, the present application also provides a computer readable storage medium. The computer readable storage medium stores a computer program, and the computer program implements the steps of the above classification model processing method when executed by a processor.
[0009] In another aspect, the present application also provides a computer program product. The computer program product comprises a computer program, and the computer program implements the steps of the above classification model processing method when executed by a processor.
[0010] The classification model processing method, device, computer device, storage medium, and computer program product obtain a training sample set. The training sample set includes training samples belonging to recognized categories corresponding to a trained classification model and training samples belonging to new categories. First sample features of each training sample in the training sample set are extracted by the trained classification model, second sample features of each training sample are extracted by a to-be-trained classification model, and classification is performed based on the second sample features. Classification loss is determined based on obtained first classification results. Loss calculation is performed based on the first sample features and the second sample features of the same training sample to obtain a first target loss. Loss calculation is performed based on the second sample features of each pair of training samples belonging to different categories to obtain a second target loss. The parameters of the to-be-trained classification model are adjusted based on the first target loss, the second target loss, and the classification loss, and the to-be-trained classification model is continuously trained. When a training stop condition is met, a target classification model is obtained. The target classification model not only effectively retains knowledge learned by the trained classification model, but also improves the generalization between new and old categories, thereby greatly improving the accuracy of class recognition by the target classification model.
[0011] In another aspect, the present application also provides an intent recognition method, device, computer device, computer readable storage medium, and computer program product. Wherein:
[0012] An intent recognition method. The method comprises: obtaining an input text; inputting the input text into a target intent classification model, and performing intent classification on the input text by the target intent classification model; wherein the target intent classification model is obtained by adjusting model parameters of a to-be-trained classification model based on a first target loss, a second target loss, and a classification loss, the first target loss is obtained by loss calculation based on first sample features and second sample features of the same training sample, the second target loss is obtained by loss calculation based on second sample features of each pair of training samples belonging to different categories, the first sample features of the training sample are obtained by extracting the trained classification model, the second sample features of the training sample are obtained by extracting the to-be-trained classification model, the classification loss is obtained based on classification results output by the to-be-trained classification model based on the second sample features of the training sample, the training sample belongs to a training sample set, the training sample set includes training samples belonging to recognized categories corresponding to the trained classification model and training samples belonging to new categories; obtaining an intent recognition result corresponding to the input text output by the target intent classification model.
[0013] An intent recognition device. The device comprises: an input text acquisition module, configured to acquire input text; an intent classification module, configured to input the input text into a target intent classification model, and perform intent classification on the input text by the target intent classification model; wherein the target intent classification model is obtained by adjusting model parameters of a to-be-trained classification model based on a first target loss, a second target loss, and a classification loss, the first target loss is obtained by loss calculation based on first sample features and second sample features of a same training sample, the second target loss is obtained by loss calculation based on respective second sample features of two training samples belonging to different categories, the first sample features of a training sample are extracted by a trained classification model, the first sample features of a training sample are extracted by the to-be-trained classification model, the classification loss is obtained based on a classification result output by the to-be-trained classification model on the second sample features of a training sample, a training sample belongs to a training sample set, and the training sample set comprises training samples belonging to an already-recognized category corresponding to the trained classification model and training samples belonging to a new category; and an intent recognition result acquisition module, configured to acquire an intent recognition result corresponding to the input text output by the target intent classification model.
[0014] A computer device. The computer device comprises a memory and a processor, the memory stores a computer program, and the processor implements the steps of the above-mentioned intent recognition method when executing the computer program.
[0015] A computer-readable storage medium. The computer-readable storage medium stores a computer program, and the computer program implements the steps of the above-mentioned intent recognition method when executed by a processor.
[0016] A computer program product. The computer program product comprises a computer program, and the computer program implements the steps of the above-mentioned intent recognition method when executed by a processor.
[0017] The above-mentioned intent recognition method, device, computer device, storage medium, and computer program product, since the target intent recognition model is obtained through continuous learning, and in the process of continuous learning, the target intent classification model not only effectively retains the knowledge learned by the trained classification model, but also improves the generalization between new and old categories, so that when the target intent classification model is used for intent recognition, the accuracy is greatly improved. BRIEF DESCRIPTION OF DRAWINGS
[0018] Figure 1 An application environment diagram of the classification model processing method and the intent recognition method in one embodiment;
[0019] Figure 2A flowchart of a classification model processing method in one embodiment;
[0020] Figure 3 A schematic diagram of loss calculation in one embodiment;
[0021] Figure 4 A flowchart of a classification model processing method in another embodiment;
[0022] Figure 5 A schematic diagram of sample distribution in a feature space in one embodiment;
[0023] Figure 6 A flowchart of an intent recognition method in one embodiment;
[0024] Figure 7 A schematic diagram of a training process of a classification model processing method in one embodiment;
[0025] Figure 8 A comparative schematic diagram of test accuracy in one embodiment;
[0026] Figure 9 A block diagram of a classification model processing apparatus in one embodiment;
[0027] Figure 10 A block diagram of an intent recognition apparatus in one embodiment;
[0028] Figure 11 An internal structure diagram of a computer device in one embodiment;
[0029] Figure 12 An internal structure diagram of a computer device in one embodiment. DETAILED DESCRIPTION
[0030] In order to make the purposes, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and should not be used to limit the present application.
[0031] The content processing method provided by the embodiments of the present application relates to natural speech processing, machine learning and other technologies of artificial intelligence, wherein:
[0032] Artificial Intelligence (AI) is the theory, method, technology and application system that use digital computer or digital computer controlled machine to simulate, extend and expand human intelligence, perceive environment, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology of computer science, which attempts to understand the essence of intelligence, and produces a new intelligent machine that can react 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.
[0033] Artificial intelligence technology is a comprehensive discipline, involving a wide range of fields, both hardware and software level technology. Artificial intelligence basic technology generally includes such as sensors, special artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction system, mechatronics and other technologies. Artificial intelligence software technology mainly includes computer vision technology, speech processing technology, natural language processing technology and machine learning / deep learning and other several directions.
[0034] Nature Language processing (NLP) 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, the research in this field will involve natural language, i.e. the language used in daily life, so it has a close relationship with the study of linguistics. Natural language processing technology usually includes text processing, semantic understanding, machine translation, robot question and answer, knowledge graph and other technologies.
[0035] Machine Learning (ML) is a multi-disciplinary subject, involving probability theory, statistics, approximation theory, convex analysis, algorithm complexity theory and other disciplines. It is a branch of computer science that studies how computers simulate or implement human learning behavior to acquire new knowledge or skills, and reorganize existing knowledge structure to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental approach to making computers intelligent, and its applications are widespread in various fields of artificial intelligence. Machine learning and deep learning usually include artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and rule-based learning.
[0036] With the research and progress of artificial intelligence technology, artificial intelligence technology is researched and applied in many fields, such as common smart home, smart wearable device, virtual assistant, smart speaker, smart marketing, unmanned driving, automatic driving, unmanned aerial vehicle, robot, smart medical treatment, smart customer service, etc. It is believed that with the development of technology, artificial intelligence technology will be applied in more fields and play an increasingly important value.
[0037] The present application relates to natural language processing, machine learning and other technologies, which are specifically illustrated by the following embodiments:
[0038] The classification model processing method provided by the embodiments of the present application can be applied in an application environment as shown in the figure. Figure 1 The terminal 102 communicates with the server 104 through a network, which can be a wired network or a wireless network. The wireless network can be any one of a local area network, a metropolitan area network and a wide area network. The data storage system can store data required by the server 104 for processing. The data storage system can be integrated on the server 104, or placed on the cloud or other servers, and can be used to store training sample data and trained classification models. The terminal 102 can be one of a smartphone, a tablet computer, a notebook computer, a desktop computer, a smart speaker, a smart watch, a smart television or a wearable device, but is not limited thereto. The server 104 can be a standalone physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDNs, and basic cloud computing services such as big data and artificial intelligence platforms.
[0039] The terminal 102 and the server 104 can be used alone to perform the classification model processing method provided in the embodiments of the present application. The terminal 102 and the server 104 can also be used cooperatively to perform the classification model processing method provided in the embodiments of the present application. In one embodiment, the server 104 can obtain a training sample set, the training sample set including training samples belonging to an identified category corresponding to a trained classification model and training samples belonging to a new category, extract first sample features of each training sample through the trained classification model, extract second sample features of each training sample through a to-be-trained classification model, perform classification based on the second sample features, determine a classification loss based on each first classification result obtained, perform loss calculation based on the first sample features and the second sample features of the same training sample to obtain a first target loss, perform loss calculation based on the second sample features of each pair of training samples belonging to different categories to obtain a second target loss, adjust parameters of the to-be-trained classification model based on the first target loss, the second target loss, and the classification loss and continue training, obtain a target classification model when a training stop condition is met, and the server 104 can send the classification model to the terminal 102. The terminal 102 performs classification on content in a business scenario by deploying the classification model, implements corresponding business processing, for example, the terminal can perform intent recognition through the classification model, thereby implementing intelligent dialogue.
[0040] In one embodiment, as shown in Figure 2 , a classification model processing method is provided. The method is executed by a computer device, which can be the terminal 102 as shown in Figure 1 , the server 104, or a system composed of the terminal 102 and the server 104, and is implemented through interaction between the terminal 102 and the server 104. In this embodiment, the classification model processing includes the following steps:
[0041] Step 202, obtaining a training sample set; the training sample set including training samples belonging to an identified category corresponding to a trained classification model and training samples belonging to a new category.
[0042] The training sample set includes multiple training samples, and the training sample refers to a content sample used for training the classification model. The content can be any one of text, audio, or image. For classification models under different business requirements, different types of training samples need to be obtained. For example, if the classification model is used for classifying images, the training samples in the obtained training sample set are image type samples, and if the classification model is used for classifying text, the training samples in the obtained training sample set are text type samples. The training samples in the training sample set belong to multiple different categories. These categories can be divided into two types: one is the identified category corresponding to the trained classification model, and the other is a new category. The trained classification model refers to a classification model that has been trained in the historical stage. The identified category corresponding to the trained classification model refers to a category that can be recognized by the trained classification model. The identified category corresponding to the trained classification model refers to a category that can be recognized by the trained classification model. The trained classification model can learn all categories that can be observed in the historical stage during the training process.
[0043] The new category is a new category that appears after the training of the trained classification model is completed. It is a new category added relative to the identified category. As an example, in the scenario of a user interacting with an intelligent dialogue system, a classification model for intent recognition is trained for various problems that may occur in the dialogue scenario. With the emergence of new events or new functions, the user may ask the dialogue system various questions related to the new events or new functions, and a model capable of recognizing the intent of the questions related to the new events or new functions needs to be trained. The new category refers to the intent category corresponding to the questions related to the new events or new functions.
[0044] The identified category and the new category can each include one or more. Multiple refers to at least two. The identified category is a category observed in the historical stage, and the new category is a new category that appears after the training of the trained classification model is completed. Therefore, the identified category can also be referred to as an old category, and the new category can also be referred to as a new category. Accordingly, the trained classification model can be referred to as an old model, and the classification model to be trained can be referred to as a new model.
[0045] Specifically, the computer device can obtain the training sample set from a local or from another computer device. In other embodiments, the computer device can also download the training sample set from a cloud through a network. The training sample set includes training samples belonging to the identified categories corresponding to the trained classification model and training samples belonging to the new categories. The computer device can train the to-be-trained classification model based on the training sample set, so that the to-be-trained classification model continuously learns on the basis of the trained classification model to obtain a classification model that can identify the identified categories and the new categories.
[0046] In step 204, the first sample features of each training sample in the training sample set are respectively extracted by the trained classification model.
[0047] Specifically, the computer device can input each training sample in the training sample set into the trained classification model. The trained classification model can include a feature extraction network that can extract features of each training sample to obtain the first sample features of each training sample.
[0048] In one embodiment, the training sample is a text type sample, the feature extraction network includes an encoding layer and a feature extraction layer, and the computer device inputs the training sample into the trained classification model. First, the training sample is encoded by the encoding layer, and then the feature vector is extracted by the feature extraction layer.
[0049] In step 206, the second sample features of each training sample are respectively extracted by the to-be-trained classification model, and classification is performed based on the second sample features. The classification loss is determined based on the obtained first classification results.
[0050] The to-be-trained classification model refers to a classification model that needs to be trained. The model structure of the to-be-trained classification model and the trained classification model can be the same or different. The to-be-trained classification model can inherit the model parameters of the trained classification model, that is, the initial parameters of the to-be-trained classification model can be consistent with the model parameters of the trained classification model. Of course, the initial parameters of the to-be-trained classification model can also be obtained by random initialization. Classification refers to classifying training samples based on sample features to determine the specific category to which the training sample belongs.
[0051] The classification result is class information used to represent the specific class to which the training sample belongs. In one embodiment, the classification result can be a class identifier used to represent the class to which the training sample belongs. For example, assuming that there are N classes in total, including the identified classes and the new classes, the classification result can be an N-dimensional vector containing the class identifier, such as (1, 0, 0, 0, …, 0), indicating that the training sample belongs to the first class, or (0, 1, 0, 0, …, 0), indicating that the training sample belongs to the second class, and so on. In another embodiment, the classification result can be a probability used to represent the class to which the training sample belongs. For example, assuming that there are N classes in total, including the identified classes and the new classes, the classification result can be an N-dimensional probability vector, where the probability of each dimension is used to represent the likelihood of the training sample belonging to the class.
[0052] The classification loss can be used to represent the difference between the classification result and the class label, and the classification loss is positively correlated with the difference, that is, the larger the difference, the larger the classification loss.
[0053] Specifically, the computer device inputs each training sample into the classification model to be trained, and the classification model first extracts each training sample to obtain the second sample feature of each training sample. Then, the classification model can perform classification processing on each training sample based on the second sample feature of each training sample to obtain the classification result corresponding to each training sample. Based on the classification result corresponding to each training sample and the class label corresponding to each training sample, loss calculation is performed to obtain the classification loss.
[0054] In one specific embodiment, the computer device can calculate the cross-entropy by referring to the following formula (1) when performing loss calculation to obtain the classification loss:
[0055]
[0056] where L represents the calculated classification loss, y represents the class label, p represents the classification result, and N represents the training sample set. CE n n
[0057] Step 208: performing loss calculation based on the first sample feature and the second sample feature of the same training sample to obtain a first target loss, and performing loss calculation based on the second sample feature of each pair of training samples belonging to different classes to obtain a second target loss.
[0058] The first objective loss is related to the difference or similarity between the first and second sample features of the same training sample. This aims to achieve knowledge distillation, encouraging the features extracted by the classification model to be trained to be similar to those extracted by the already trained classification model, thus effectively preserving the knowledge learned by the already trained model. Considering that training using only the first objective loss might weaken the generalization between new and old categories, this embodiment further calculates a second objective loss. The second objective loss is related to the difference or similarity between the second sample features of each pair of training samples belonging to different categories. The second objective loss aims to achieve contrastive learning, ensuring that each extracted feature has a certain degree of distinguishability from features of other categories.
[0059] Specifically, in the aforementioned steps, for each training sample, a first sample feature and a second sample feature are obtained. Therefore, for each input training sample, the computer device can perform loss calculation based on the first and second sample features corresponding to that training sample to obtain a sub-loss. Then, by statistically analyzing the sub-losses corresponding to each training sample, a first target loss is obtained. Simultaneously, the computer device performs loss calculation based on the second sample features of every two training samples belonging to different categories to obtain sub-losses corresponding to every two training samples belonging to different categories. Then, by statistically analyzing these sub-losses, a second target loss is obtained.
[0060] For example, such as Figure 3 As shown, assuming the training sample set includes three training samples, namely training sample 1, training sample 2, and training sample 3, where training sample 1 and training sample 2 belong to the same identified category, while training sample 3 belongs to a newly added category, the computer device extracts the first sample features A1, A2, and A3 respectively from the trained classification model for these three samples, and extracts the second sample features B1, B2, and B3 respectively from the classification model to be trained. Then, the computer device can calculate the sub-loss X1 of training sample 1 based on A1 and B1, the sub-loss X2 of training sample 2 based on A2 and B2, and the sub-loss X3 of training sample 3 based on A3 and B3. By statistically analyzing X1, X2, and X3, the first target loss is obtained. The sub-loss Y1 corresponding to the first and third training samples is calculated based on B1 and B3, and the sub-loss Y2 corresponding to the second and third training samples is calculated based on B2 and B3. By statistically analyzing Y1 and Y2, the second target loss is obtained.
[0061] In one embodiment, when calculating the second target loss, the computer device can determine pairs of training samples belonging to different categories based on the labels of the training samples, and for each pair of training samples, the computer device can perform loss calculation based on the second sample features corresponding to the pair of training samples to obtain a sub-loss corresponding to the pair of training samples.
[0062] In one embodiment, considering that the trained classification model has only learned the old categories, when calculating the first target loss, the computer device can only calculate for the training samples corresponding to the old categories. Of course, since the classification model to be trained mainly learns the new categories through continuous learning, the proportion of the old categories in the training sample set is low, and the first target loss is used to encourage the features extracted by the new model to be close to the features extracted by the old model, in the specific implementation process, the computer device can calculate for the training samples corresponding to the old categories and the training samples corresponding to the new categories when calculating the first target loss.
[0063] In step 210, the parameters of the classification model to be trained are adjusted based on the first target loss, the second target loss, and the classification loss, and the training is continued. When the training stop condition is met, a target classification model is obtained, which is used to identify the identified categories and the new categories.
[0064] Specifically, the computer device can calculate the first target loss, the second target loss, and the classification loss to obtain a statistical loss, and then propagate the obtained statistical loss in reverse to adjust the model parameters of the classification model to be trained. Then, the adjusted classification model is taken as the classification model to be trained, and the above training steps are repeated for iterative training until the training stop condition is met, and a trained target classification model is obtained. The statistics can be one of weighted summation, average, or median.
[0065] In the training process, the model parameters of the classification model can be adjusted using a stochastic gradient descent algorithm, an Adagrad (Adaptive Gradient) algorithm, an Adadelta algorithm (an improvement of the AdaGrad algorithm), an RMSprop algorithm (an improvement of the AdaGrad algorithm), an Adam (Adaptive Moment Estimation) algorithm, etc. The training stop condition can be that the model parameters no longer change, or that the statistical loss reaches a minimum value, or that the number of training reaches a maximum number of iterations, etc.
[0066] The target classification model obtained by training learns the training samples of the identified categories and the training samples of the new categories in the training process, and can be used to identify the identified categories and the new categories.
[0067] In the classification model processing method, a training sample set is obtained, the training sample set includes training samples belonging to an identified category corresponding to a trained classification model and training samples belonging to a new category, first sample features of each training sample in the training sample set are extracted by the trained classification model, second sample features of each training sample are extracted by a to-be-trained classification model, and classification is performed based on the second sample features. The classification loss is determined based on each first classification result, the loss is calculated based on the first sample features and the second sample features of the same training sample to obtain a first target loss, the loss is calculated based on the second sample features of each training sample pair belonging to different categories to obtain a second target loss, the parameters of the to-be-trained classification model are adjusted based on the first target loss, the second target loss, and the classification loss, and the to-be-trained classification model is continuously trained, when a training stop condition is met, a target classification model is obtained. The target classification model not only effectively retains the knowledge learned by the trained classification model, but also improves the generalization between new and old categories, so that the accuracy is greatly improved when the target classification model is used for category identification.
[0068] In one embodiment, the loss calculation based on the second sample features of each training sample pair belonging to different categories to obtain the second target loss includes: forming a training sample pair by each training sample and each training sample in the training sample set to obtain a plurality of training sample pairs; calculating the similarity based on the second sample features corresponding to each training sample pair respectively, and determining the sub-loss corresponding to each training sample pair based on the calculated similarity; and obtaining the second target loss by counting the sub-loss corresponding to the target training sample pair, the target training sample pair being a training sample pair containing training samples of different categories.
[0069] Specifically, the computer device can traverse each training sample in the training sample set, and form a training sample pair with the traversed training sample and each training sample in the training sample set, so that a plurality of training sample pairs can be obtained. For each training sample pair, the computer device can perform similarity calculation based on the respective second training sample features of the two training samples in the training sample pair, and determine a sub-loss corresponding to the training sample pair based on the calculated similarity. It can be understood that here, the sub-loss corresponding to the training sample pair is in a positive correlation with the calculated similarity, where the positive correlation means that, under the condition that other conditions remain unchanged, the variation directions of two variables are the same, and when one variable changes from large to small, the other variable also changes from large to small. It can be understood that the positive correlation here means that the variation directions are consistent, but it is not required that when one variable changes a little, the other variable must also change. For example, it can be set that when the variable a is 10-20, the variable b is 100, and when the variable a is 20-30, the variable b is 120. In this way, the variation directions of a and b are both that when a becomes larger, b also becomes larger. However, within the range of a being 10-20, b can not change.
[0070] Further, since the second target loss aims to achieve contrast learning and ensure that each feature extracted has a certain degree of discrimination from the features of other classes, after the respective sub-losses of each training sample pair are calculated, the computer device can only count the sub-losses of the target sample pairs containing training samples of different classes, and take the counted statistical loss as the second target loss.
[0071] In a specific embodiment, for each training sample pair, the computer device can perform cosine similarity calculation based on the respective second training sample features of the two training samples in the training sample pair to obtain the similarity corresponding to the training sample pair.
[0072] In the above embodiment, the sub-loss is obtained by performing similarity calculation, and then the second target loss is obtained by counting the sub-losses corresponding to the target sample pairs. The obtained second target loss can better reflect the discrimination between training samples of different classes.
[0073] In an embodiment, determining the respective sub-losses of each training sample pair based on the calculated similarity includes: for the similarity corresponding to each training sample pair, subtracting a preset similarity from the similarity to obtain a target difference value; in the case that the similarity is less than the preset similarity, determining a minimum loss value as the sub-loss corresponding to the training sample pair; and in the case that the similarity is greater than or equal to the preset similarity, determining the target difference value as the sub-loss corresponding to the training sample pair.
[0074] Specifically, in the embodiment, a preset similarity can be set as the maximum similarity between different categories of training samples, and the model parameters of the to-be-trained classification model can be adjusted in a direction that the similarity between different categories of training samples is less than the maximum similarity. For the similarity corresponding to each training sample pair, the computer device subtracts the preset similarity from the similarity to obtain a target difference value. In a case where the similarity is less than the preset similarity, the minimum loss value is determined as the sub-loss corresponding to the training sample pair. In a case where the similarity is greater than or equal to the preset similarity, the target difference value is determined as the sub-loss corresponding to the training sample pair. It can be understood that, in the training process, the model parameters of the to-be-trained classification model are adjusted in a direction that the loss is reduced, i.e., in a direction that the minimum loss value is determined as the sub-loss corresponding to the training sample pair, so that the similarity between different categories of training samples is less than the preset similarity, and a certain degree of distinction is ensured between each extracted feature and features of other categories.
[0075] Based on this, in a specific embodiment, the sub-loss corresponding to the training sample pair can be determined by max(<f(x n ),f(x t )>-α,0), where 0 represents the minimum loss value, f(x n ) and f(x t ) are the second sample features of two training samples in the training sample pair, and <f(x n ),f(x t )> represents the cosine similarity of the two sample features.
[0076] In the above embodiment, when calculating the sub-loss, in a case where the similarity is less than the preset similarity, the minimum loss value is determined as the sub-loss corresponding to the training sample pair, and in a case where the similarity is greater than or equal to the preset similarity, the target difference value is determined as the sub-loss corresponding to the training sample pair, which can better ensure the distinction between the features extracted by the target classification model obtained through training and different categories of samples, and improve the generalization performance of the model.
[0077] In an embodiment, the computer device trains the target loss function by: obtaining, for each training sample pair, a category label corresponding to the training sample pair, and calculating an indicator function value corresponding to the training sample pair based on the category label; wherein the indicator function value is calculated by an indicator function, and the indicator function value calculated by the indicator function is a first value when the category labels corresponding to the training samples in the training sample pair are consistent, and the indicator function value calculated by the indicator function is a second value when the category labels corresponding to the training samples in the training sample pair are inconsistent; when the calculated indicator function value is the first value, performing a reservation process on the sub-loss corresponding to the training sample pair to obtain a target sub-loss corresponding to the training sample pair, and when the calculated indicator function value is the second value, performing a masking process on the sub-loss corresponding to the training sample pair to obtain a target sub-loss corresponding to the training sample pair; and calculating the second target loss by summing up the target sub-losses corresponding to the respective training sample pairs.
[0078] The category label is used to identify the category of the training sample. For example, if the training sample is an image, the category label corresponding to the training sample can be an animal species such as a dog, a cat, or a fish, a plant species such as a coral, a pine tree, or a osmanthus, or an object category such as a magnifying glass, a cabinet, or a water bottle. The category label corresponding to the training sample can be used as supervision information for the feature extraction model to be trained.
[0079] Specifically, the indicator function outputs an indicator function value that is either the first value or the second value, and the first value and the second value are different values. Therefore, by outputting the indicator function value, it can be determined whether the category labels corresponding to the training samples in the training sample pair are consistent. When the calculated indicator function value is the first value, it indicates that the category labels corresponding to the training samples in the training sample pair are consistent. Then, the computer device can perform a reservation process on the sub-loss corresponding to the training sample pair, which means that the sub-loss can be reserved as part of the second target loss. When the calculated indicator function value is the second value, it indicates that the category labels corresponding to the training samples in the training sample pair are inconsistent. Then, the computer device can perform a masking process on the sub-loss corresponding to the training sample pair, which means that the sub-loss will not affect the second target loss.
[0080] In a specific embodiment, the first value of the indicator function output is 1 and the second value is 0. The computer device can multiply the corresponding sub-loss of the training sample pair and the indicator function value corresponding to the training sample. When the indicator function value is the first value, the sub-loss is taken as the target sub-loss of the training sample by multiplying the first value. When the indicator function value is the second value, the target sub-loss of the training sample is 0 by multiplying the second value. Therefore, the second target loss finally obtained only contains the sub-loss corresponding to the target training sample pair, where the target training sample pair is a training sample pair containing training samples of different categories.
[0081] In the above embodiment, by calculating the indicator function value, the sub-loss of the training sample pair containing the same category training sample can be shielded, so that the second target loss obtained is more accurate, and the classification accuracy of the target classification model is further improved.
[0082] In an embodiment, as shown in Figure 4 , a classification model processing method is provided. The method is executed by a computer device. It can be understood that the computer device can be a terminal 102 as shown in Figure 1 , a server 104, or a system composed of the terminal 102 and the server 104, and is realized through interaction between the terminal 102 and the server 104. In this embodiment, the classification model processing includes the following steps:
[0083] Step 402, obtaining a training sample set; the training sample set includes training samples belonging to an identified category corresponding to a trained classification model and training samples belonging to a new category.
[0084] Step 404, extracting respective first sample features of each training sample in the training sample set by the trained classification model.
[0085] Step 406, extracting respective second sample features of each training sample by the to-be-trained classification model, and classifying based on the respective second sample features, and determining a classification loss based on the obtained respective first classification results.
[0086] Step 408, performing loss calculation based on the first sample feature and the second sample feature of the same training sample to obtain a first target loss, and performing loss calculation based on the respective second sample features of each pair of training samples belonging to different categories to obtain a second target loss.
[0087] Step 410, performing loss calculation based on the first sample feature and the second sample feature corresponding to each pair of training samples belonging to different categories to obtain a third target loss.
[0088] Specifically, the computer device performs loss calculations based on the first sample features and the second sample features corresponding to each pair of training samples belonging to different categories, to obtain the sub-loss corresponding to each pair of training samples belonging to different categories, and then obtains the third target loss by statistically analyzing these sub-losses.
[0089] In one embodiment, assuming a training sample pair contains two training samples, training sample A and training sample B, the first and second sample features corresponding to the training sample pair can be the first sample feature corresponding to training sample A and the second sample feature corresponding to training sample B. The computer device can perform loss calculations based on the first sample feature corresponding to training sample A and the second sample feature corresponding to training sample B to obtain the sub-loss of the training sample pair. In another embodiment, the first and second sample features corresponding to the training sample pair can be the second sample feature corresponding to training sample A and the first sample feature corresponding to training sample B. The computer device can perform loss calculations based on the second sample feature corresponding to training sample A and the second sample feature corresponding to training sample B to obtain the sub-loss of the training sample pair. A sub-loss is obtained by calculating the loss of a training sample pair using a sample feature. In other embodiments, the computer device may use the first sample feature and the second sample feature corresponding to the training sample pair to include the first sample feature corresponding to training sample A and the second sample feature corresponding to training sample B, as well as the second sample feature corresponding to training sample A and the first sample feature corresponding to training sample B. Thus, the computer device may calculate a sub-loss based on the first sample feature corresponding to training sample A and the second sample feature corresponding to training sample B, and calculate a sub-loss based on the second sample feature corresponding to training sample A and the first sample feature corresponding to training sample B. Finally, the two sub-losses are statistically analyzed to obtain the sub-loss of the training sample pair.
[0090] In one embodiment, when performing loss calculation, for each set of one sample feature and two sample features used for loss calculation, the computer device can calculate the similarity between the two sample features and determine the corresponding sub-loss based on the calculated similarity.
[0091] In one embodiment, for each calculated similarity, the computer device can subtract a preset similarity to obtain a target difference; if the similarity is less than the preset similarity, the minimum loss value is determined as the corresponding sub-loss; if the similarity is greater than or equal to the preset similarity, the target difference is determined as the corresponding sub-loss.
[0092] In a specific implementation, the sub-loss here can be achieved by max( <f(x n ), g(x t The similarity is determined by f(x) > -α, 0), where α is the preset similarity, 0 represents the minimum loss value, and f(x) > -α, 0.n ) and f(x t ) are the first sample feature and the second sample feature corresponding to the training sample pair respectively, <f(x n ), f(x t )> represents the cosine similarity of the two sample features.
[0093] In step 412, the first target loss, the second target loss, the third target loss and the classification loss are counted to obtain a statistical loss, and the parameters of the to-be-trained classification model are adjusted based on the statistical loss and the training is continued.
[0094] In a specific embodiment, in the counting process, the second target loss and the third target loss can be counted by referring to the following formula (2):
[0095]
[0096] Wherein, L MGN is the loss obtained by counting the second target loss and the third target loss, is an indicator function, when the labels of two training samples are the same, the indicator function value output by the indicator function is 0, and when the labels of two training samples are different, the indicator function value output by the indicator function is 1.
[0097] In the above embodiment, since the first sample feature is the feature extracted by the old model, and the second sample feature is the feature extracted by the new model, by calculating the third target loss, it can be ensured that there is a certain degree of distinction between the features extracted by the new model and the old model for different categories, so that the new model can better distinguish between new and old categories, and further improve the generalization performance of the model.
[0098] In an embodiment, the first target loss is obtained by calculating the loss based on the first sample feature and the second sample feature of the same training sample, including: calculating the similarity based on the first sample feature and the second sample feature of each training sample, and determining the sub-loss of each training sample based on the calculated similarity; the sub-loss of the training sample and the similarity corresponding to the training sample are negatively correlated; and the sub-loss of each training sample is counted to obtain the first target loss.
[0099] Specifically, the computer device can calculate the first target loss by referring to the following formula (3):
[0100]
[0101] Wherein, L SIM is the first target loss, N represents the training sample set, f(x n ) is the second sample feature extracted by the to-be-trained classification model, and g(x n) the first sample feature extracted for the trained classification model, <f(x n ), g(x n ) represents the similarity between the first sample feature and the second sample feature.
[0102] In one embodiment, the identified categories include a plurality of categories, and the generating step of the training sample set includes: obtaining an initial sample set from the memory; wherein the initial sample set includes representative training samples corresponding to the identified categories, and the distribution of the representative training samples corresponding to the identified categories in the feature space corresponding to the identified categories matches the distribution of the original sample set corresponding to the identified categories in the feature space.
[0103] The original sample set corresponding to the identified category refers to the training sample set belonging to the identified category used when training the trained classification model. The feature space corresponding to the identified category refers to the feature space formed by the sample features corresponding to each sample in the original sample set corresponding to the identified category. The distribution of the representative training samples corresponding to the identified category in the feature space corresponding to the identified category matches the distribution of the original sample set corresponding to the identified category in the feature space, i.e. the positions of the representative training samples in the feature space are near the center positions of each region in the feature space. The position of the representative training sample in the feature space is the position of the sample feature of the representative training sample in the feature space. For example, as shown in Figure 5 , the original sample set corresponding to the identified category A has a distribution in the feature space corresponding to the identified category A as shown in Figure 5 (a) of FIG. 1, the distribution of the representative training samples corresponding to the identified category A in the feature space can be as shown in Figure 5 (b) of FIG. 1, which can be seen from Figure 5 It can be seen that the distribution of the representative training samples corresponding to the identified category A in the feature space is relatively uniform, and representative training samples are distributed at each sample aggregation place. The representative training samples corresponding to each identified category constitute the initial sample set in the memory.
[0104] Considering that there are usually different sample expressions for the same category, for example, the same intent category can have multiple expressions. Taking a practical example, during the outbreak of X disease, the expression of “how to protect yourself?” can be as follows: “how to avoid infection with X disease?” “is there an effective drug to avoid infection with X disease?” “can wearing gloves avoid infection with X disease?” “which anti-virus mask is better?”
[0105] Based on this, in the embodiment, a small amount of representative training samples can be stored in the memory for each identified category, and the representative training samples are selected according to the spatial structure of the feature space corresponding to the identified category. The diversified and information-rich data in the original sample set can be retained. In the subsequent continuous learning process, the computer device obtains the representative training samples from the memory, and after obtaining the new sample set corresponding to the new category, the new sample set and the representative training samples in the initial sample set are combined into a training category set for continuous learning.
[0106] In the above embodiment, since the representative training samples of the identified category are stored in the memory, and the distribution of the representative training samples in the feature space corresponding to the identified category matches the distribution of the original sample set corresponding to the identified category in the feature space, for each identified category, more diversified samples can be obtained. By training the to-be-trained category model with these diversified samples, the model can better learn the sample features of the identified category, thereby maintaining the recognition performance of the model on the old category.
[0107] In one embodiment, before obtaining the initial sample set from the memory, the method further includes: obtaining a respective original sample set corresponding to each identified category; the original sample set includes an identified training sample corresponding to the trained classification model; for each original sample set corresponding to an identified category, clustering the sample features of each identified training sample in the original sample set to obtain a plurality of clustering clusters corresponding to the identified category; and selecting sample features from each clustering cluster that satisfy a distance condition with the clustering center of the respective clustering cluster, and taking the identified training sample to which the selected sample features belong as the representative training sample corresponding to the identified category.
[0108] For example, the distance condition can be that the feature distance between the sample feature and the clustering center of the clustering cluster in which the sample feature is located is less than a preset threshold, or the feature distance between the sample feature and the clustering center of the clustering cluster in which the sample feature is located is ranked before a ranking threshold. The identified training sample corresponding to the trained classification model refers to the training sample used in the process of training the model. The original sample set corresponding to the identified category refers to the training sample belonging to the identified category used in the process of training the trained classification model.
[0109] Specifically, for each identified category corresponding to the original sample set, the computer device can extract the sample features of each identified training sample in the original sample set through the trained classification model, cluster the sample features, and obtain multiple clustering clusters after clustering the original sample set corresponding to each identified category. The computer device can select one or more sample features from each clustering cluster that satisfy the distance condition with the respective clustering center, and the selected sample features represent the identified training sample belonging to, so as to take the identified training sample to which the selected sample features belong as the representative training sample of the identified category to which the identified training sample belongs. The clustering can be implemented by using any clustering algorithm in the prior art, for example, a k-means clustering algorithm.
[0110] In a specific embodiment, the distance condition can be that the feature distance between the clustering center of the clustering cluster and the sample feature is ranked before the ranking threshold. For each clustering cluster, the computer device can arrange the sample features in the clustering cluster in ascending order according to the feature distance between the clustering center of the clustering cluster and the sample features, and determine the sample features ranked before the ranking threshold as the sample features satisfying the distance condition. For example, assuming that the ranking threshold is 2, the first ranked sample feature is the sample feature satisfying the distance condition, that is, the sample feature closest to the clustering center is determined as the sample feature satisfying the distance condition.
[0111] In the above embodiment, by clustering, the sample features satisfying the distance condition with the respective clustering center are selected from each clustering cluster, and the identified training sample to which the selected sample features belong is taken as the representative training sample of the identified category. These selected samples belong to different categories after clustering, which are often very diverse and have approximately the same distribution as the original old training samples, and can better retain the characteristics of the old samples.
[0112] In an embodiment, the sample features of each identified training sample in the original sample set are clustered to obtain multiple clustering clusters corresponding to the identified category, including: determining a first category number corresponding to the identified category, determining a target category number in the clustering process based on the first category number and the storage capacity of the memory; and clustering the sample features of each identified training sample in the original sample set according to the target category number to obtain multiple clustering clusters corresponding to the identified category and matching the target category number.
[0113] The storage capacity of the memory is used to represent the maximum number of samples that the memory can store. For example, assuming that the memory can store up to 1000 samples, the storage capacity of the memory is 1000.
[0114] Specifically, assuming that the storage capacity of the memory is |M| and the first category number corresponding to the identified category is K, for each identified category, the target category number in the clustering process is |M| / K, where |M| and K are positive integers greater than 0. After determining the target category number, for each original sample set, the computer device can cluster the sample features of each identified training sample in the original sample set according to the target category number, and the number of the final clustering clusters is consistent with the target category number.
[0115] In the above embodiments, by determining the first category number corresponding to the identified category, determining the target category number in the clustering process based on the first category number and the storage capacity of the memory, and clustering the sample features of each identified training sample in the original sample set according to the target category number, the representative training samples of each identified category can be uniformly and as many as possible saved in the memory.
[0116] In one embodiment, the new categories include multiple categories, and after obtaining the target classification model, the method further includes: determining a second category number corresponding to the new categories, deleting multiple representative training samples in the initial sample set from the memory based on the second category number; determining representative training samples corresponding to the new categories from the new sample set corresponding to the new categories; and storing the representative training samples corresponding to the new categories into the memory.
[0117] The new sample set corresponding to the new category refers to the training samples belonging to the new category used in the process of training the target classification model. The distribution of the representative training samples of the new category in the feature space matches the distribution of the new sample set corresponding to the new category in the feature space. It can be understood that the determination of the representative training samples of the new category can refer to the related description of the determination of the representative training samples of the identified category in the above embodiments, which will not be described herein.
[0118] After obtaining the target classification model, the sample data of the new categories involved in the model training process need to be stored in the memory for subsequent continuous learning process. However, due to the limited storage capacity of the memory, part of the stored data needs to be removed to allocate space for the sample data of the new categories. Specifically, the computer device can determine a second category number of the new categories, delete multiple representative training samples in the initial sample set from the memory based on the second category number, and the more the second category number, the more the number of samples to be deleted. For each new category, the computer device can determine the representative training samples from the new sample set corresponding to the new category, and finally store the representative training samples corresponding to each new category into the memory to update the memory.
[0119] In one specific embodiment, for each identified category, the computer device can delete |M| / K-|M| / B representative training samples, where K is the first category number corresponding to the identified category, and B is the number of all categories observed so far, which is obtained by adding the first category number corresponding to the identified category and the second category number corresponding to the new category.
[0120] In the above embodiment, based on the second category number, the computer device deletes a plurality of representative training samples in the initial sample set from the memory, determines the representative training sample corresponding to the new category from the new sample set corresponding to the new category, and stores the representative training sample corresponding to the new category into the memory, so that the sample requirement in the continuous learning process can be maintained by the data stored in the memory with limited storage capacity.
[0121] In one embodiment, based on the second category number, the computer device deletes a plurality of representative training samples in the initial sample set from the memory, including: based on the second category number, determining the target sample number of the to-be-deleted samples corresponding to each identified category; for each identified category, determining the center point feature of the feature space corresponding to the identified category based on the identified training sample corresponding to the identified category; respectively calculating the feature distance between the sample feature of each representative training sample and the center point feature; based on the feature distance corresponding to each representative training sample, deleting the representative sample features matching the target sample number from the representative sample features corresponding to the identified category.
[0122] Specifically, the computer device first determines the target sample number of the to-be-deleted samples corresponding to each identified category based on the second category number, and then for each identified category, the computer device can calculate the average sample feature according to the sample features of the identified training samples corresponding to the identified category, take the average sample feature as the center point feature of the feature space corresponding to the identified category, respectively calculate the feature distance between the sample feature of each representative training sample corresponding to the identified category and the center point feature, sort the representative training samples corresponding to the identified category in ascending order based on the feature distance corresponding to each representative training sample, delete the representative training samples with lower rankings based on the sorting result, and the number of deleted representative training samples is consistent with the target sample number. In the specific implementation process, the computer device can average the sample features of all identified training samples corresponding to the identified category to obtain the average sample feature; or the computer device can average the sample features of all representative training samples corresponding to the identified category to obtain the average sample feature.
[0123] For example, assuming that the number of target samples is 5 and the number of representative training samples corresponding to a certain identified category is 10, the computer device first averages the sample features of the 10 representative training samples to calculate the center point feature of the feature space corresponding to the identified category, calculates the feature distance between the 10 representative training samples and the center point feature respectively, sorts the representative training samples in ascending order of feature distance, and then deletes the 5 representative training samples ranked from 6 to 10.
[0124] In the above embodiment, by determining the center point feature of the feature space corresponding to the identified category, calculating the feature distance between the sample feature of each representative training sample and the center point feature respectively, and deleting the samples based on the feature distance corresponding to each representative training sample, the remaining samples are the samples closest to the center point feature, thereby the data distribution characteristics of the feature space can be maximally preserved.
[0125] In one embodiment, the first classification result includes a first prediction probability corresponding to the identified category; before adjusting the parameters of the to-be-trained classification model based on the first target loss, the second target loss and the classification loss and continuing training, the method further includes: classifying each training sample based on the first sample feature of the training sample by the trained classification model to obtain a second classification result of each training sample; the second classification result includes a second prediction probability corresponding to the identified category; for each training sample, the first prediction probability and the second prediction probability of the training sample are normalized at the same distillation temperature to obtain a first target probability corresponding to the first prediction probability and a second target probability corresponding to the second prediction probability; the distillation loss is calculated based on the first target probability and the second target probability to obtain the distillation loss of the training sample; the distillation loss of each training sample is counted to obtain a target distillation loss; the parameters of the to-be-trained classification model are adjusted based on the first target loss, the second target loss and the classification loss and the training is continued, including: counting the first target loss, the second target loss, the target distillation loss and the classification loss to obtain a statistical loss; and adjusting the parameters of the to-be-trained classification model based on the statistical loss and continuing the training.
[0126] Wherein, the specific process of the computer device to calculate the target distillation loss can refer to the following formula (4) and formula (5):
[0127]
[0128]
[0129] Wherein, L PKD represents the target distillation loss, T refers to the distillation temperature, and |C 0| represents a set of identified categories, N represents a set of training samples, u represents a first prediction probability, and v represents a second prediction probability.
[0130] After the target distillation loss is calculated, the computer device can calculate the first target loss, the second target loss, the target distillation loss, and the classification loss to obtain a statistical loss, and then adjust the parameters of the to-be-trained classification model based on the statistical loss.
[0131] In the above embodiments, the target distillation loss is calculated, which can encourage the to-be-trained classification model to maintain the probability distribution characteristics output by the trained model in the learning process, thereby further improving the generalization performance of the model.
[0132] The present application also provides an intent recognition method, which can be applied to the application environment as shown in Figure 1 The terminal 102 and the server 104 can be used alone to execute the intent recognition method provided in the embodiments of the present application. The terminal 102 and the server 104 can also be used cooperatively to execute the intent recognition method provided in the embodiments of the present application.
[0133] In one embodiment, as Figure 6 , an intent recognition method is provided, which is taken as an example to be executed by a computer device. It can be understood that the computer device can be the terminal 102 as shown in Figure 1 , or the server 104, or a system composed of the terminal 102 and the server 104, and is realized through the interaction between the terminal 102 and the server 104. In this embodiment, the intent recognition method includes the following steps:
[0134] Step 602, obtaining an input text.
[0135] The input text refers to a sentence that needs to generate a dialogue reply sentence, which can be a declarative sentence, an interrogative sentence, an imperative sentence, and an exclamatory sentence. For example, the input text can be "How is the weather today?". The input text can be a starting dialogue sentence in a dialogue, or a dialogue sentence at an intermediate stage.
[0136] Specifically, the computer device obtains the input text, which can be an input text input by a user in real time, or a user voice converted into an input text in real time. The computer device can also directly obtain the input text from a local database or a third-party database. The third party can be a service party that stores dialogue sentences.
[0137] Step 604, inputting the input text into a target intent classification model, and classifying the input text by the target intent classification model.
[0138] The target intent classification model is obtained by adjusting model parameters of a to-be-trained classification model based on a first target loss, a second target loss, and a classification loss. The first target loss is obtained by loss calculation based on the first sample feature and the second sample feature of the same training sample. The second target loss is obtained by loss calculation based on the respective second sample features of two training samples belonging to different categories. The first sample feature of the training sample is extracted by the trained classification model. The second sample feature of the training sample is extracted by the to-be-trained classification model. The classification loss is obtained based on a classification result output by the to-be-trained classification model based on the second sample feature of the training sample. The training sample belongs to a training sample set. The training sample set includes training samples belonging to an already-recognized category corresponding to the trained classification model and training samples belonging to a new category. It can be understood that the intent classification model herein is the classification model described above, and the training process thereof can refer to the description in the above embodiments. The intent classification model trained in this embodiment is used for intent recognition of an input text, that is, to recognize the intent category to which the input text belongs. Therefore, the training samples in the training sample set used in the training process are also texts, and these texts as training samples are labeled. The labels are used to represent the intent category to which the text belongs.
[0139] Specifically, since the intent recognition model of the present application continuously learns as new intent categories appear, in the process of intent recognition, the computer device can perform intent recognition by using the target intent recognition model obtained by the latest training, input the input text into the target intent classification model, and perform intent classification on the input text by using the intent classification model.
[0140] In step 606, an intent recognition result corresponding to the input text output by the target intent classification model is obtained.
[0141] Specifically, the computer device can obtain the intent recognition result corresponding to the input text output by the target intent classification model. The intent recognition result is used to represent the intent category to which the input text belongs.
[0142] The above intent recognition method, since the target intent recognition model is obtained by continuous learning, and in the process of continuous learning, the target intent classification model not only effectively retains the knowledge learned by the trained classification model, but also improves the generalization between new and old categories, so that when the target intent classification model is used for intent recognition, the accuracy is greatly improved.
[0143] In a specific embodiment, the classification model processing method provided by the embodiments of the present application can be applied to the intent detection task in the field of natural language processing. In existing businesses, the classification model can usually only process predefined categories. However, new categories will continue to appear over time, and the model that has been deployed online often cannot process these new categories. By continuously learning new categories from new data, the performance of the existing model can be enhanced, and at the same time, serious performance degradation on old data can be avoided.
[0144] In related technologies, when the continuous learning method is applied to the intent detection task, the following problems often exist: sample diversity and category imbalance. Among them: (1) sample diversity: in the intent detection task, there are multiple expression ways for the same intent category. However, in related technologies, similar training samples are usually retained, which only involve a few expression ways, which is not conducive to maintaining the performance of the model on old categories. (2) Category imbalance: generally, the newly arrived data is relatively large, however, due to the limited memory capacity, only a small amount of old data is usually saved in related technologies, resulting in an imbalance between new and old intent categories. In this case, related technologies will obviously be biased towards learning new data, causing performance degradation on old data.
[0145] Based on this, the present application provides a classification model processing method, which adopts Structure Consolidation Networks (SCN) for continuous learning, specifically including two core parts: (1) In order to deal with the sample diversity problem, the present application proposes structure-based sample review, which selects and retains diversified and information-rich old data according to the spatial structure of the features; (2) In order to cope with the category imbalance problem, the present application proposes contrastive knowledge distillation, which migrates the knowledge in the old model to the new model through knowledge distillation and contrastive learning technology, reduces the impact of the category imbalance problem, effectively preserves the knowledge in the old model, and improves the generalization between new and old intent categories. The following is a specific description taking execution on a computer device as an example:
[0146] I. Structure-based sample review
[0147] The continuous learning of the present application aims to continuously train an intent classification model trained on old training samples belonging to old categories on a training sample set obtained by combining new and old data, which includes two parts of data: (1) training samples of new categories; and (2) data stored in a limited memory, which retains a small number of representative training samples belonging to old categories to maintain the performance of the model on old categories. For example, in a business, given a classification model that has learned two categories of "paragraph missing" and "paragraph splicing", the present application can continuously train on a new category "translated paragraph". Only by learning the newly added training samples corresponding to "translated paragraph" and a small amount of stored old data (representative training samples corresponding to "paragraph missing" and "paragraph splicing"), a model that performs well on three categories can be obtained.
[0148] In order to select and store representative samples from diverse old training samples, the present application proposes structure-based sample review, which specifically includes two operations: (1) structure-based sample selection: selecting and storing diverse training samples according to the spatial structure of feature vectors; and (2) structure-preserved sample deletion: deleting some stored old samples when new samples arrive to maintain the total capacity of the memory unchanged. In this way, diverse old data enters the subsequent training process to maintain the performance of the model on old categories. Specifically as follows:
[0149] 1. Structure-based sample selection
[0150] After each model training is completed, |M| / K samples are selected for each identified category involved in the training process, where |M| is the capacity of the memory and K is the number of all categories. For each identified category, all its training samples are converted into feature vectors by the trained model. Then, K-means algorithm is applied on these feature vectors for feature clustering, where the number of clusters is |M| / K. In each cluster after clustering, the sample closest to the center point is selected as the representative training sample and saved in the memory. These selected representative training samples belong to different clusters after clustering, which are often very diverse and approximately the same as the distribution of the original old training samples, and can better retain the characteristics of old samples.
[0151] 2. Structure-preserved sample deletion
[0152] Due to the limited memory capacity, when new data comes, the application also needs to remove part of the stored data to allocate space for the newly arrived samples. Specifically, for each old class, delete |M| / K-|M| / B training samples, where K is the number of old classes and B is the number of all classes observed so far. In the process of deleting training samples, for each old class, first extract a feature vector for all its training samples, and then average these feature vectors as the center point feature vector of the entire feature space. For the training samples to be retained, they are sorted in ascending order according to their distance from the center point feature vector. In the subsequent continuous learning process, the training samples at the lower end of the ranking are gradually removed to reserve space for the newly arrived samples.
[0153] The following will be illustrated in conjunction with Figure 7 For example, referring to Figure 7 , in the first training process, learn the intent set A, and after the training is completed, select representative training samples from the training sample set corresponding to the intent set A for storage to obtain the "memory after learning the intent set A", and when learning the intent set B, combine the representative training samples in the "memory after learning the intent set A" and the newly added training samples corresponding to the intent set B (i.e. Figure 7 "new data of set B" in the embodiment) to form a training sample set, train the training sample set, and after the training is completed, for each intent category in the intent set A, sort the representative training samples corresponding to the intent category in the memory according to the distance from the center point feature vector of the feature space corresponding to the intent category, remove the representative training samples far from the center point feature vector according to the sorting result, extract feature vectors from the newly added training samples corresponding to the intent set B through the new model obtained by training, and then select representative training samples from the newly added training samples corresponding to the intent set B, and then add the representative training samples to the memory to update the memory to obtain the "memory after learning the intent set B".
[0154] II. Comparative knowledge distillation
[0155] Due to the limited memory capacity, the number of old training samples retained is relatively small, while the number of newly arrived training samples is usually large. Such a problem of data imbalance makes the model tend to learn the newly arrived training samples, which affects the performance on the old data. In contrast, the old model in the previous step is trained on the old data, and it performs well on the old classes. Therefore, in order to alleviate the influence of class imbalance, the application learns the knowledge in the model in the previous step through comparative knowledge distillation. For each training sample x n in the training sample set, the feature vectors extracted by the current model (the intent classification model to be trained) and the model in the previous step (the trained intent classification model) are represented as f(x n ) and g(x n). Then the following loss can be calculated by comparing the knowledge distillation:
[0156] 1. The similarity loss function L is calculated by the above formula (3) SIM to obtain the first target loss.
[0157] 2. The residual loss function L is calculated by the above formula (2) MGN to obtain the statistical loss of the second target loss and the third target loss.
[0158] 3. The distillation loss is calculated by the above formula (4) and formula (5).
[0159] III. Model training
[0160] The classification loss obtained by the above formula (1) is combined, and each loss is counted by the following formula (6) to obtain the final statistical loss:
[0161] L = L CE + γ1L SIM + γ2L MGN + γ3L PKD Formula (6)
[0162] Wherein, L is the statistical loss, L SIM is the first target loss calculated by the similarity loss function, L MGN is the statistical loss of the second target loss and the third target loss calculated by the residual loss function, L PKD is the target distillation loss, L CE is the classification loss, and γ1, γ2 and γ3 are adjustable coefficients for controlling the proportion of different losses.
[0163] The model parameters of the new model (i.e. the to-be-trained intent classification model) are adjusted in the reverse direction by the statistical loss and the training is continued. When the training stop condition is met, the target intent classification model is obtained, and the obtained target intent classification model has good performance in identifying old intents and new intents.
[0164] With reference to Figure 7 , in the embodiment, the intent classification model can adopt the model structure as shown in Figure 7 , wherein the old model (i.e. the trained intent classification model) and the new model (i.e. the to-be-trained intent classification model) have the same model structure, including an encoder, a feature extraction layer, a linear layer and a probability output layer, wherein the encoder can be implemented by a BERT encoder.
[0165] The classification model processing method provided by the embodiment can be trained from the dynamically added data set, so as to continuously learn new intent categories flexibly and efficiently. The method can be applied in the following real scenarios:
[0166] 1. A scenario in which new intent categories continuously appear. For example, as new events occur or new functions are added, users may ask the dialog system various questions related to the new events or new functions, thereby bringing many new dialog intents.
[0167] 2. A scenario in which the iteration speed of the model is required to be high. When the model is iterated, retraining the model from scratch using all data often requires a large amount of time. For example, the time for training a model using all data of the CLINC benchmark data set is about 9.7 times longer than the time for training the same model using only new data. In actual business, a large number of services and a large amount of data make the time cost of continuous retraining very large.
[0168] 3. A scenario in which the computing power and storage capacity are limited. For example, the present application can be flexibly and scalably applied on an embedded device such as a smart phone with limited computing power and storage capacity to learn new categories defined by users.
[0169] The present application is verified on the continuous intent detection task, and the experimental results on three benchmark data sets prove the effectiveness of SCN, which is significantly better than the continuous learning methods in other related technologies in terms of performance on the three benchmark data sets; at the same time, compared with training using all data, SCN significantly reduces the training time and reduces the training cost. Specifically:
[0170] The present application constructs the intent detection benchmark dataset according to the following method: for each benchmark dataset, the present application arranges the categories of one or more original datasets in a random order. Each class has its own training / validation / testing data. In an incremental manner by category, the continual learning method continuously trains the intent detection model on new data. Based on this, the present application constructs three benchmark datasets: (1) the CLINC benchmark dataset is constructed based on the CLINC150 dataset, which contains all 150 categories of the CLINC150 dataset. At each step of continual learning, the model learns 15 new categories; (2) the Banking-ML benchmark dataset is constructed based on three datasets, including the Banking dataset, the M-CID-EN dataset and the Liu57 dataset. The Banking dataset and the M-CID-EN dataset provide 77 and 16 categories, respectively. The data segmentation of these categories follows the official dataset segmentation. Since there is a serious long-tail data distribution problem in the categories of the Liu57 dataset, the present application only uses the first 57 frequently occurring categories. Finally, the Banking-ML benchmark dataset contains 150 categories. At each step of continual learning, the model learns 15 new categories; (3) the Stack-SHA benchmark dataset is constructed based on four datasets, including the StackOverflow dataset, the SNIPS dataset, the HINT3 dataset and the ATIS dataset. The present application uses all 20 and 7 categories provided by the StackOverflow dataset and the SNIPS dataset, and the official data segmentation. Due to the long-tail distribution of data, the present application uses the first 8 and the first 15 frequent categories of the ATIS dataset and the HINT3 dataset. Similar to the Liu57 dataset, the data of each category of the HINT3 and ATIS datasets is divided into training, validation and testing sets in a ratio of 3:1:1. The total number of categories of the Stack-SHA benchmark dataset is 50. In each step, the model needs to learn 5 new categories.
[0171] The present application completes one model training in each incremental step, and after each incremental step, the present application evaluates the model on the test data of all current categories. After the last step, the present application reports the average accuracy of all steps and the overall accuracy on the test data of all categories.
[0172] To provide a comprehensive comparison, the SCN is compared with related continual learning methods. LwF model utilizes the original knowledge distillation method to preserve the probability distribution of the old model. EWC preserves the parameters important to the old classes by regularization. iCaRL selects representative samples according to the prototype vectors of classes and trains the model by the original knowledge distillation method. EEIL fine-tunes the model with the data in the memory to deal with the class imbalance problem. EMAR selects samples using the K-means algorithm and consolidates the model by the class prototype vectors. RP-CRE utilizes the class prototype vectors as external features and selects samples by the K-means algorithm. FineTune directly fine-tunes the model trained on old data on new data. UpperBound trains the model using the training data of all current classes, and its recognition accuracy is considered as the upper bound. Reference Figure 8 The test accuracy of various continual learning methods on the above datasets can be plotted into a curve. From Figure 8 It can be seen that, when tested on three different benchmark datasets, the accuracy of the SCN provided by the present application is the highest among all methods except UpperBound, and the training time of the SCN provided by the present application is greatly reduced compared with UpperBound.
[0173] Table 1 shows the average accuracy and overall accuracy after the last step. From the results, it can be seen that: (1) the SCN provided by the present application achieves the most advanced performance on all benchmark datasets. Compared with the RP-CRE model, the SCN obtains an overall accuracy improvement of 5.98%, 3.65% and 3.23% on the CLINC, Banking-ML and Stack-SHA benchmark datasets, respectively. The results verify the effectiveness of the present application on the task of continual intent detection. (2) There is a significant performance gap between RP-CRE and the present application at each step of the whole process. The reason is that RP-CRE ignores the sample diversity and class imbalance problem in the task of continual intent detection, which eventually leads to performance degradation.
[0174] Table 1
[0175]
[0176]
[0177] To verify the effectiveness of the structure-based sample review and contrastive knowledge distillation proposed by the present application, the present application conducts an ablation experiment. The ablation experiment results of the structure-based sample review are shown in Table 2. We can see that: (1) The “-SBSS” model removes the structure-based sample selection module, which randomly adds samples to the memory. The “-SPSR” model randomly removes samples without using the structure-preserved sample removal proposed by the present application. The “-SBR” variant adopts a random strategy in both sample selection and sample removal. Compared with these benchmark models, the present application has better performance. This shows that the structure-based sample review is very effective in selecting and storing representative samples. (2) The “+CPBR” model calculates a prototype vector for each class and selects samples according to the prototype vector. This model is even worse than the random strategy “-SBR”, because it usually selects similar samples. In contrast, the present application can effectively select diverse and informative samples by utilizing the spatial structure of features.
[0178] Table 2
[0179]
[0180] The present application further verifies the effectiveness of the proposed contrastive knowledge distillation through experiments, and the relevant experimental results are shown in Table 3. From the results, we can see that: (1) Removing any part of the contrastive knowledge distillation, i.e. the similarity loss (“-SIM”) or the margin loss (“-MGN”), will result in a significant performance drop. When removing the entire contrastive knowledge distillation (“-CKD”) module, the performance will further decrease. This shows that the contrastive knowledge distillation can effectively improve the performance by preserving the knowledge of the old model. In addition, the results show that the present application can improve the generalization between new and old categories by using contrastive learning.
[0181] Table 3
[0182]
[0183] In a specific embodiment, the classification model processing method provided by the present application can also be applied to low-quality ecological business. Low-quality article producers often bypass the review system through various means, which will cause new low-quality categories to continue to appear. For example, in the washing business, different washing methods are constantly emerging. The present application can enable the classification model to continuously and quickly learn new low-quality categories, while shortening the model training time and enhancing the model's ability to handle new low-quality categories. Ultimately, after the appearance of new low-quality categories, we can quickly put the corresponding classification model online to reduce the impact of new low-quality categories on the article ecology.
[0184] It should be understood that although the steps in the flowcharts of the above embodiments are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the above embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0185] Based on the same inventive concept, this application also provides a classification model processing apparatus for implementing the classification model processing method and an intent recognition method as described above. The solution provided by this apparatus is similar to the implementation scheme described in the above method. Therefore, the specific limitations of one or more classification model processing apparatuses and intent recognition apparatus embodiments provided below can be found in the limitations of the classification model processing method and intent recognition method described above, and will not be repeated here.
[0186] In one embodiment, such as Figure 9 As shown, a classification model processing device 900 is provided, comprising:
[0187] The training sample acquisition module 902 is used to acquire a training sample set; the training sample set includes training samples belonging to the identified categories corresponding to the trained classification model and training samples belonging to the newly added categories;
[0188] The feature extraction module 904 is used to extract the first sample features of each training sample in the training sample set through the trained classification model.
[0189] The classification loss determination module 906 is used to extract the second sample features of each training sample through the classification model to be trained, classify based on each second sample feature, and determine the classification loss based on the obtained first classification results.
[0190] The target loss calculation module 908 is used to calculate the loss based on the first sample feature and the second sample feature of the same training sample to obtain the first target loss, and to calculate the loss based on the second sample feature of each pair of training samples belonging to different categories to obtain the second target loss.
[0191] The parameter adjustment module 910 is configured to adjust the parameters of the to-be-trained classification model based on the first target loss, the second target loss, and the classification loss, and continue training, and when a training stop condition is met, obtain a target classification model, which is used for identifying the identified categories and the new categories.
[0192] The classification model processing apparatus described above obtains a training sample set, which includes training samples belonging to the identified categories corresponding to the trained classification model and training samples belonging to the new categories, extracts respective first sample features of each training sample in the training sample set by using the trained classification model, extracts respective second sample features of each training sample by using the to-be-trained classification model, performs classification based on the second sample features, determines a classification loss based on the obtained respective first classification results, performs loss calculation based on the first sample features and the second sample features of the same training sample to obtain a first target loss, performs loss calculation based on the respective second sample features of each pair of training samples belonging to different categories to obtain a second target loss, adjusts the parameters of the to-be-trained classification model based on the first target loss, the second target loss, and the classification loss, and continues training, and when a training stop condition is met, obtains a target classification model. The target classification model not only effectively retains the knowledge learned by the trained classification model, but also improves the generalization between the new and old categories, so that the accuracy is greatly improved when the target classification model is used for category identification.
[0193] In one embodiment, the target loss calculation module is further configured to: form each training sample and each training sample in the training sample set into a training sample pair respectively to obtain a plurality of training sample pairs; perform similarity calculation based on the respective second sample features of each training sample pair respectively, and determine a respective sub-loss of each training sample pair based on the calculated similarity; and count the sub-loss corresponding to the target training sample pair to obtain the second target loss, the target training sample pair being a training sample pair containing training samples of different categories.
[0194] In one embodiment, the target loss calculation module is further configured to: for the similarity corresponding to each training sample pair, subtract a preset similarity from the similarity to obtain a target difference value; in a case where the similarity is less than the preset similarity, determine a minimum loss value as the sub-loss corresponding to the training sample pair; and in a case where the similarity is greater than or equal to the preset similarity, determine the target difference value as the sub-loss corresponding to the training sample pair.
[0195] In an embodiment, the target loss calculation module is further configured to: for each training sample pair, obtain a category label corresponding to the training sample pair included in the training sample pair, and calculate an indicator function value corresponding to the training sample pair based on the category label; the indicator function value is calculated by an indicator function, and the indicator function value calculated by the indicator function is a first numerical value when the category labels corresponding to the training samples included in the training sample pair are consistent, and the indicator function value calculated by the indicator function is a second numerical value when the category labels corresponding to the training samples included in the training sample pair are inconsistent; when the calculated indicator function value is the first numerical value, the sub-loss corresponding to the training sample pair is retained to obtain a target sub-loss corresponding to the training sample pair, and when the calculated indicator function value is the second numerical value, the sub-loss corresponding to the training sample pair is shielded to obtain a target sub-loss corresponding to the training sample pair; and the target sub-loss corresponding to each training sample pair is counted to obtain a second target loss.
[0196] In an embodiment, the target loss calculation module is further configured to: perform loss calculation based on the first sample features and the second sample features corresponding to each pair of training samples belonging to different categories to obtain a third target loss; the parameter adjustment module is further configured to: count the first target loss, the second target loss, the third target loss, and the classification loss to obtain a statistical loss; and adjust the parameters of the to-be-trained classification model based on the statistical loss and continue training.
[0197] In an embodiment, the target loss calculation module is further configured to: perform similarity calculation based on the first sample features and the second sample features of each training sample, and determine the sub-loss of each training sample based on the calculated similarity; the sub-loss of the training sample and the similarity corresponding to the training sample are negatively correlated; and the sub-loss of each training sample is counted to obtain the first target loss.
[0198] In an embodiment, the identified categories include a plurality of categories, and the apparatus further includes a training sample set generation module configured to: obtain an initial sample set from the memory; the initial sample set includes a representative training sample corresponding to each identified category, and the distribution of the representative training sample corresponding to each identified category in a feature space matches the distribution of an original sample set corresponding to the identified category in the feature space; obtain a new sample set corresponding to a new category, and generate the training sample set based on the new sample set and the initial sample set.
[0199] In an embodiment, the training sample set generation module is further configured to: obtain a plurality of original sample sets respectively corresponding to the identified categories; each of the original sample sets comprises the identified training samples corresponding to the trained classification model; for each of the original sample sets corresponding to the identified categories, perform clustering on the sample features of each of the identified training samples in the original sample set to obtain a plurality of clustering clusters corresponding to the identified category; and select, from each of the clustering clusters, sample features satisfying a distance condition with a clustering center of the clustering cluster, and take the identified training samples to which the selected sample features belong as representative training samples corresponding to the identified category.
[0200] In an embodiment, the training sample set generation module is configured to: determine a first category number corresponding to the identified categories, determine a target category number in the clustering process based on the first category number and a storage capacity of the memory, and perform clustering on the sample features of each of the identified training samples in the original sample set according to the target category number to obtain a plurality of clustering clusters corresponding to the identified categories and matching the target category number.
[0201] In an embodiment, the apparatus further comprises an updating module configured to: determine a second category number corresponding to the new category, delete a plurality of representative training samples in the initial sample set from the memory based on the second category number, determine representative training samples corresponding to the new category from a new sample set corresponding to the new category, and store the representative training samples corresponding to the new category into the memory.
[0202] In an embodiment, the updating module is further configured to: determine a target sample number of samples to be deleted corresponding to each of the identified categories based on the second category number; for each of the identified categories, determine a center point feature of a feature space corresponding to the identified category based on the identified training samples corresponding to the identified category; calculate a feature distance between the sample feature of each of the representative training samples and the center point feature respectively; and delete, from the representative sample features corresponding to the identified category, representative sample features matching the target sample number based on the feature distances respectively corresponding to the representative training samples.
[0203] In an embodiment, the first classification result includes a first prediction probability corresponding to the identified class; the apparatus further includes a distillation loss calculation module configured to: perform classification on each training sample based on the first sample feature of the training sample by using the trained classification model to obtain a second classification result of the training sample; the second classification result includes a second prediction probability corresponding to the identified class; for each training sample, normalize the first prediction probability and the second prediction probability of the training sample at the same distillation temperature to obtain a first target probability corresponding to the first prediction probability and a second target probability corresponding to the second prediction probability; calculate a distillation loss based on the first target probability and the second target probability to obtain the distillation loss of the training sample; and calculate a target distillation loss by summing up the distillation losses of all training samples; the parameter adjustment module is further configured to calculate a statistical loss by summing up the first target loss, the second target loss, the target distillation loss, and the classification loss, and adjust the model parameters of the to-be-trained classification model based on the statistical loss and continue training.
[0204] In an embodiment, as shown in FIG. 10, an intent recognition apparatus 1000 is provided, which includes: Figure 10
[0205] An input text acquisition module 1002 configured to acquire an input text;
[0206] An intent classification module 1004 configured to input the input text into a target intent classification model, and perform intent classification on the input text by using the target intent classification model; wherein the target intent classification model is obtained by adjusting the model parameters of a to-be-trained classification model based on a first target loss, a second target loss, and a classification loss, the first target loss is obtained by calculating a loss based on the first sample feature and the second sample feature of the same training sample, the second target loss is obtained by calculating a loss based on the second sample feature of each of two training samples belonging to different classes, the first sample feature of the training sample is obtained by using a trained classification model, the second sample feature of the training sample is obtained by using a to-be-trained classification model, the classification loss is obtained based on a classification result output by the to-be-trained classification model by performing classification on the second sample feature of the training sample, the training sample belongs to a training sample set, and the training sample set includes training samples belonging to an identified class of the trained classification model and training samples belonging to a new class;
[0207] An intent recognition result acquisition module 1006 configured to acquire an intent recognition result corresponding to the input text output by the target intent classification model.
[0208] The above intention recognition device, since the target intention recognition model is obtained through continuous learning, and in the process of continuous learning, the target intention classification model can not only effectively retain the knowledge learned by the trained classification model, but also improve the generalization between new and old classes, so that when the target intention classification model is used for intention recognition, the accuracy is greatly improved.
[0209] The modules in the above classification model processing device and intention recognition device can be all or part realized by software, hardware and combination thereof. The above modules can be embedded in or independent of the processor in the computer device in hardware form, or can be stored in the memory in the computer device in software form, so as to be called and executed by the processor to perform the operations corresponding to the above modules.
[0210] In one embodiment, a computer device is provided, which can be a server, and an internal structure diagram thereof can be as shown in Figure 11 The computer device includes a processor, a memory, an input / output interface (I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operating system and the computer program in the non-volatile storage medium to run. The database of the computer device is used to store training sample data. The input / output interface of the computer device is used to exchange information between the processor and external devices. The communication interface of the computer device is used to communicate with external terminals through network connection. The computer program is executed by the processor to implement a classification model processing method or an intention recognition method.
[0211] In one embodiment, a computer device is provided, which can be a terminal, and an internal structure diagram thereof can be as shown in Figure 12As shown, the computer device includes a processor, memory, input / output interfaces, a communication interface, a display unit, and an input device. The processor, memory, and input / output interfaces are connected via a system bus, and the communication interface, display unit, and input device are also connected to the system bus via the input / output interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The input / output interfaces are used for exchanging information between the processor and external devices. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, NFC (Near Field Communication), or other technologies. When the computer program is executed by the processor, it implements a classification model processing method or an intent recognition method. The display unit of the computer device is used to form a visually visible image. It can be a display screen, a projection device, or a virtual reality imaging device. The display screen can be an LCD screen or an e-ink screen. The input device of the computer device can be a touch layer covering the display screen, or buttons, trackballs, or touchpads set on the casing of the computer device, or external keyboards, touchpads, or mice, etc.
[0212] Those skilled in the art will understand that Figure 11 , Figure 12 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0213] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the above-described classification model processing method or intent recognition method.
[0214] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, which, when executed by a processor, implements the steps of the above-described classification model processing method or intent recognition method.
[0215] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps of the above-described classification model processing method or intent recognition method.
[0216] It should be noted that the user information (including but not limited to user equipment information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the present application are all information and data authorized by the user or authorized by all parties, and the collection, use and processing of related data need to comply with relevant laws, regulations and standards of the country and region.
[0217] It can be understood by those skilled in the art that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing related hardware through a computer program, and the computer program can be stored in a non-volatile computer readable storage medium. When the computer program is executed, it can include the processes of the above-mentioned embodiments of each method. In the embodiments provided in the present application, any reference to memory, database or other medium can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (Read-Only Memory, ROM), magnetic tape, floppy disk, flash memory, optical storage, high-density embedded non-volatile memory, resistive memory (ReRAM), magnetic variable memory (Magnetoresistive Random Access Memory, MRAM), ferroelectric memory (Ferroelectric Random Access Memory, FRAM), phase change memory (Phase Change Memory, PCM), graphene memory, etc. Volatile memory can include random access memory (Random Access Memory, RAM) or external cache memory, etc. As an illustration but not limitation, RAM can be in various forms, such as static random access memory (Static Random Access Memory, SRAM) or dynamic random access memory (Dynamic Random Access Memory, DRAM), etc. The database involved in the embodiments provided in the present application can include at least one of a relational database and a non-relational database. The non-relational database can include a distributed database based on a block chain, etc., without being limited thereto. The processor involved in the embodiments provided in the present application can be a general-purpose processor, a central processing unit, a graphics processing unit, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., without being limited thereto.
[0218] The technical features of the above embodiments can be combined in any way. In order to make the description simple, not all possible combinations of technical features in the above embodiments are described, but as long as the combination of technical features does not exist contradictory, it should be considered as the scope of the present application.
[0219] The above-described embodiments are merely illustrative of several embodiments of the present application, and the description is relatively specific and detailed, but should not be understood as a limitation on the scope of the patent. It should be noted that for those skilled in the art, without departing from the concept of the present application, a number of modifications and improvements can be made, which are all within the scope of the present application. Therefore, the scope of protection of the present application should be subject to the appended claims.
Claims
1. A classification model processing method, characterized in that, The method comprises: obtaining a training sample set; the training sample set comprises training samples belonging to an identified category corresponding to a trained classification model and training samples belonging to a new category; the training samples are text, audio or image; extracting first sample features of each training sample in the training sample set respectively through the trained classification model; extracting second sample features of each training sample through a to-be-trained classification model, and performing classification based on the second sample features, and determining a classification loss based on each first classification result obtained; performing loss calculation based on the first sample features and the second sample features of the same training sample to obtain a first target loss, and performing loss calculation based on the second sample features of each pair of training samples belonging to different categories to obtain a second target loss; adjusting parameters of the to-be-trained classification model based on the first target loss, the second target loss and the classification loss and continuing training, and obtaining a target classification model when a training stop condition is met, wherein the target classification model is used for identifying the identified category and the new category.
2. The method of claim 1, wherein, The method comprises: forming a plurality of training sample pairs by respectively grouping each training sample with each training sample in the training sample set; performing similarity calculation based on the second sample features corresponding to each training sample pair respectively, and determining a sub-loss corresponding to each training sample pair based on the calculated similarity; statistically obtaining a second target loss corresponding to a target training sample pair, wherein the target training sample pair is a training sample pair containing training samples belonging to different categories.
3. The method of claim 2, wherein, The method comprises: for the similarity corresponding to each training sample pair, obtaining a target difference value by subtracting a preset similarity from the similarity; in a case where the similarity is less than the preset similarity, determining a minimum loss value as the sub-loss corresponding to the training sample pair; in a case where the similarity is greater than or equal to the preset similarity, determining the target difference value as the sub-loss corresponding to the training sample pair.
4. The method of claim 2, wherein, The method comprises: for each training sample pair, obtaining a category label corresponding to the training samples contained in the training sample pair, and calculating an indicator function value corresponding to the training sample pair based on the category label; wherein the indicator function value is calculated by an indicator function, and the indicator function value calculated by the indicator function is a first value when the category labels corresponding to the training samples contained in the training sample pair are consistent, and the indicator function value calculated by the indicator function is a second value when the category labels corresponding to the training samples contained in the training sample pair are inconsistent. When the calculated indicator function value is the first numerical value, the corresponding sub-loss of the training sample pair is reserved to obtain a target sub-loss corresponding to the training sample pair, and when the calculated indicator function value is the second numerical value, the corresponding sub-loss of the training sample pair is shielded to obtain the target sub-loss corresponding to the training sample pair. The target sub-loss corresponding to each training sample is counted to obtain a second target loss.
5. The method according to any one of claims 1 to 4, characterized in that, Before the parameters of the to-be-trained classification model are adjusted based on the first target loss, the second target loss, and the classification loss and the training is continued, the method further includes: Loss calculation is performed based on the first sample feature and the second sample feature corresponding to each pair of training samples belonging to different categories to obtain a third target loss. The parameters of the to-be-trained classification model are adjusted based on the first target loss, the second target loss, and the classification loss and the training is continued, including: The first target loss, the second target loss, the third target loss, and the classification loss are counted to obtain a statistical loss. The parameters of the to-be-trained classification model are adjusted based on the statistical loss and the training is continued.
6. The method of claim 1, wherein, The first target loss is obtained by performing loss calculation based on the first sample feature and the second sample feature of the same training sample, including: Similarity calculation is performed based on the first sample feature and the second sample feature of each training sample, and the sub-loss of each training sample is determined based on the calculated similarity; the sub-loss of the training sample and the similarity corresponding to the training sample are negatively correlated; The sub-loss of each training sample is counted to obtain the first target loss.
7. The method of claim 1, wherein, The identified categories include a plurality of categories, and the generating of the training sample set includes: An initial sample set is obtained from the memory; The initial sample set includes representative training samples corresponding to the identified categories, and the distribution of the representative training samples corresponding to the identified categories in a feature space corresponding to the identified categories matches the distribution of an original sample set corresponding to the identified categories in the feature space; An additional sample set corresponding to an additional category is obtained, and a training sample set is formed based on the additional sample set and the initial sample set.
8. The method of claim 7, wherein, Before the initial sample set is obtained from the memory, the method further includes: An original sample set corresponding to each identified category is obtained; the original sample set includes identified training samples corresponding to the trained classification model; For each original sample set corresponding to an identified category, the sample features of each identified training sample in the original sample set are clustered to obtain a plurality of clustering clusters corresponding to the identified category; Sample features whose feature distances from the respective clustering centers satisfy a distance condition are selected from each clustering cluster, and the identified training samples to which the selected sample features belong are taken as representative training samples corresponding to the identified category.
9. The method of claim 8, wherein, The clustering of the sample features of each identified training sample in the original sample set to obtain a plurality of clustering clusters corresponding to the identified category includes: determining a first category number corresponding to the identified category, determining a target category number in a clustering process based on the first category number and a storage capacity of the memory; clustering sample features of each identified training sample in the original sample set according to the target category number to obtain a plurality of clustering clusters corresponding to the identified category and matching the target category number.
10. The method of claim 7, wherein, The method further comprises, after obtaining the target classification model, determining a second category number corresponding to the new category, deleting a plurality of representative training samples in the initial sample set from the memory based on the second category number; determining representative training samples corresponding to the new category from a new sample set corresponding to the new category; storing the representative training samples corresponding to the new category into the memory. The method further comprises, after obtaining the target classification model, determining a second category number corresponding to the new category, deleting a plurality of representative training samples in the initial sample set from the memory based on the second category number; 11. The method of claim 10, wherein, determining a target sample number of samples to be deleted corresponding to each identified category based on the second category number; determining a center point feature of a feature space corresponding to each identified category based on identified training samples corresponding to the identified category; calculating a feature distance between sample features of each representative training sample and the center point feature respectively; deleting representative sample features matching the target sample number from representative sample features corresponding to the identified category based on the feature distance corresponding to each representative training sample. The first classification result includes a first prediction probability corresponding to the identified category; before adjusting parameters of the to-be-trained classification model based on the first target loss, the second target loss, and the classification loss and continuing training, the method further comprises:
12. The method according to any one of claims 1 to 4 or 6 to 11, characterized in that, classifying each training sample based on its first sample feature by using the trained classification model to obtain a second classification result of each training sample; the second classification result includes a second prediction probability corresponding to the identified category; for each training sample, normalizing the first prediction probability and the second prediction probability of the training sample at the same distillation temperature to obtain a first target probability corresponding to the first prediction probability and a second target probability corresponding to the second prediction probability; performing distillation loss calculation based on the first target probability and the second target probability to obtain a distillation loss of the training sample; statistically obtaining a target distillation loss based on the distillation loss of each training sample; adjusting parameters of the to-be-trained classification model based on the statistical loss and continuing training. The method comprises: obtaining an input text; 13. An intention recognition method characterized by, input the input text into a target intent classification model, and perform intent classification on the input text by using the target intent classification model; the target intent classification model is obtained by adjusting model parameters of a to-be-trained classification model based on a first target loss, a second target loss, and a classification loss; the first target loss is obtained by performing loss calculation based on first sample features and second sample features of a same training sample; the second target loss is obtained by performing loss calculation based on second sample features of two training samples belonging to different categories; the first sample features of the training sample are extracted by using a trained classification model; the second sample features of the training sample are extracted by using the to-be-trained classification model; the classification loss is obtained based on a classification result output by the to-be-trained classification model based on the second sample features of the training sample; the training sample belongs to a training sample set, and the training sample set includes training samples belonging to an identified category corresponding to the trained classification model and training samples belonging to a new category; obtain an intent recognition result corresponding to the input text output by the target intent classification model.
14. A classification model processing apparatus characterized by comprising: The apparatus comprises: a training sample acquisition module configured to acquire a training sample set; the training sample set includes training samples belonging to an identified category corresponding to a trained classification model and training samples belonging to a new category; the training sample is a text, an audio, or an image; a feature extraction module configured to extract first sample features of each training sample in the training sample set by using the trained classification model; a classification loss determination module configured to extract second sample features of each training sample by using a to-be-trained classification model, perform classification based on the second sample features, and determine a classification loss based on obtained first classification results; a target loss calculation module configured to perform loss calculation based on first sample features and second sample features of a same training sample to obtain a first target loss, and perform loss calculation based on second sample features of two training samples belonging to different categories to obtain a second target loss; a parameter adjustment module configured to adjust parameters of the to-be-trained classification model based on the first target loss, the second target loss, and the classification loss, and continue training; when a training stop condition is met, a target classification model is obtained, and the target classification model is used to identify the identified category and the new category.
15. The classification model processing apparatus according to claim 14, characterized by, The target loss calculation module is further configured to group each training sample and each training sample in the training sample set into a training sample pair to obtain a plurality of training sample pairs, perform similarity calculation based on second sample features corresponding to each training sample pair, and determine a sub-loss corresponding to each training sample pair based on a calculated similarity; statistically determine a sub-loss corresponding to a target training sample pair to obtain the second target loss, the target training sample pair being a training sample pair containing training samples of different categories.
16. The classification model processing apparatus according to claim 15, characterized by, The target loss calculation module is further configured to subtract a preset similarity from the similarity corresponding to each training sample pair to obtain a target difference value; in a case where the similarity is less than the preset similarity, determine a minimum loss value as the sub-loss corresponding to the training sample pair; in a case where the similarity is greater than or equal to the preset similarity, determine the target difference value as the sub-loss corresponding to the training sample pair.
17. The classification model processing apparatus of claim 15, wherein, The target loss calculation module is further configured to, for each training sample pair, obtain the category labels corresponding to the training samples included in the training sample pair, and calculate an indicator function value corresponding to the training sample pair based on the category labels; the indicator function value is calculated by an indicator function, and the indicator function value calculated by the indicator function is a first value when the category labels corresponding to the training samples included in the training sample pair are consistent, and the indicator function value calculated by the indicator function is a second value when the category labels corresponding to the training samples included in the training sample pair are inconsistent; when the calculated indicator function value is the first value, the sub-loss corresponding to the training sample pair is retained to obtain a target sub-loss corresponding to the training sample pair; when the calculated indicator function value is the second value, the sub-loss corresponding to the training sample pair is shielded to obtain a target sub-loss corresponding to the training sample pair; and the target sub-loss corresponding to each training sample pair is counted to obtain a second target loss.
18. The classification model processing apparatus according to any one of claims 14 to 17, characterized by, The target loss calculation module is further configured to perform loss calculation based on the first sample features and the second sample features corresponding to each pair of training samples belonging to different categories to obtain a third target loss; the parameter adjustment module is further configured to count the first target loss, the second target loss, the third target loss, and the classification loss to obtain a statistical loss; and the parameters of the to-be-trained classification model are adjusted based on the statistical loss and the training is continued.
19. The classification model processing apparatus of claim 14, wherein, The target loss calculation module is further configured to perform similarity calculation based on the first sample features and the second sample features of each training sample, and determine the sub-loss of each training sample based on the calculated similarity; the sub-loss of the training sample and the similarity corresponding to the training sample are negatively correlated; and the sub-loss of each training sample is counted to obtain a first target loss.
20. The classification model processing apparatus of claim 14, wherein, The identified categories include a plurality of categories, and the apparatus further includes a training sample set generation module configured to obtain an initial sample set from a memory; the initial sample set includes representative training samples corresponding to the identified categories, and the distribution of the representative training samples corresponding to the identified categories in a feature space corresponding to the identified categories matches the distribution of an original sample set corresponding to the identified categories in the feature space; obtain a new sample set corresponding to a new category, and generate a training sample set based on the new sample set and the initial sample set.
21. The classification model processing apparatus of claim 20, wherein, The training sample set generation module is further configured to obtain a respective original sample set corresponding to each identified category, wherein the original sample set includes the identified training sample corresponding to the trained classification model; for the original sample set corresponding to each identified category, cluster the sample features of each identified training sample in the original sample set to obtain a plurality of clustering clusters corresponding to the identified category; and select sample features from each clustering cluster that satisfy a distance condition with a respective clustering center, and take the identified training sample to which the selected sample features belong as a representative training sample corresponding to the identified category.
22. The classification model processing apparatus according to claim 21, wherein The training sample set generation module is further configured to determine a first category number corresponding to the identified category, determine a target category number in the clustering process based on the first category number and a storage capacity of the memory, and cluster the sample features of each identified training sample in the original sample set according to the target category number to obtain a plurality of clustering clusters corresponding to the identified category and matching the target category number.
23. The classification model processing apparatus of claim 20, wherein, The new categories include a plurality of new categories, and the device further includes an updating module configured to determine a second category number corresponding to the new categories, delete a plurality of representative training samples in the initial sample set from the memory based on the second category number, determine representative training samples corresponding to the new categories from the new sample set corresponding to the new categories, and store the representative training samples corresponding to the new categories into the memory.
24. The classification model processing apparatus according to claim 23, characterized by, The updating module is further configured to determine a target sample number of samples to be deleted corresponding to each identified category based on the second category number, determine a center point feature of a feature space corresponding to each identified category based on the identified training sample corresponding to the identified category, calculate a feature distance between the sample feature of each representative training sample and the center point feature, and delete representative sample features matching the target sample number from the representative sample features corresponding to the identified category based on the feature distance corresponding to each representative training sample. The updating module is further configured to determine a target sample number of samples to be deleted corresponding to each identified category based on the second category number, determine a center point feature of a feature space corresponding to each identified category based on the identified training sample corresponding to the identified category, calculate a feature distance between the sample feature of each representative training sample and the center point feature, and delete representative sample features matching the target sample number from the representative sample features corresponding to the identified category based on the feature distance corresponding to each representative training sample.
25. The classification model processing apparatus according to any one of claims 14 to 17 or 19 to 24, characterized by, The first classification result includes a first prediction probability corresponding to the identified class; the device further comprises a distillation loss calculation module configured to: perform classification on each training sample based on the first sample feature of the training sample by using the trained classification model, to obtain a second classification result of the training sample; the second classification result includes a second prediction probability corresponding to the identified class; for each training sample, normalize the first prediction probability and the second prediction probability of the training sample at the same distillation temperature, to obtain a first target probability corresponding to the first prediction probability and a second target probability corresponding to the second prediction probability; calculate a distillation loss based on the first target probability and the second target probability, to obtain the distillation loss of the training sample; and calculate a target distillation loss by summing up the distillation losses of all training samples; and the parameter adjustment module is further configured to calculate a statistical loss by summing up the first target loss, the second target loss, the target distillation loss, and the classification loss, and adjust the parameters of the to-be-trained classification model based on the statistical loss and continue training.
26. An intention recognition apparatus characterized by comprising: The device comprises: an input text acquisition module configured to acquire an input text; an intent classification module configured to input the input text into a target intent classification model, and perform intent classification on the input text by using the target intent classification model; wherein the target intent classification model is obtained by adjusting model parameters of a to-be-trained classification model based on a first target loss, a second target loss, and a classification loss, the first target loss is obtained by calculating a loss based on a first sample feature and a second sample feature of a same training sample, the second target loss is obtained by calculating a loss based on the second sample features of two training samples belonging to different classes, the first sample feature of a training sample is extracted by using a trained classification model, the second sample feature of the training sample is extracted by using the to-be-trained classification model, the classification loss is obtained based on a classification result output by the to-be-trained classification model when classifying the second sample feature of the training sample, and the training sample belongs to a training sample set, the training sample set includes training samples belonging to an identified class corresponding to the trained classification model and training samples belonging to a new class; an intent recognition result acquisition module configured to acquire an intent recognition result corresponding to the input text output by the target intent classification model. 27.A computer device, comprising a memory and a processor, wherein the memory stores a computer program. The processor executes the computer program to implement the method in any one of claims 1 to 13.
28. A computer readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the method in any one of claims 1 to 13.
29. A computer program product comprising a computer program, characterised in that, The computer program is executed by the processor to implement the method in any one of claims 1 to 13. The computer program is executed by the processor to implement the method in any one of claims 1 to 13.