Model training method, intention classification method, device, equipment, medium and product
By generating and using target adversarial samples in the intent classification model training, the problem of insufficient number of certain intent training samples in the intent classification model is solved, and the classification accuracy and robustness of the model are improved.
Patent Information
- Application Number
- CN202510022170.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-07
- Publication Date
- 2025-04-15
AI Technical Summary
When training the existing intent classification model, the number of training samples for a certain intent is small, resulting in poor classification accuracy.
By obtaining multiple initial samples, the target adversarial samples are generated, ensuring that their semantic similarity to the initial sample is greater than the preset threshold and the intention is different, and the initial sample and the target adversarial samples are added to the dataset as training samples respectively, the initial model is trained, and the number of training samples for each intention in each round of training is dynamically adjusted.
The classification accuracy of the intention classification model is improved, the proportion of different intention training samples is balanced, the model's ability to identify adversarial samples is enhanced, and the classification is improved.
Smart Images

Figure CN119830016A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of artificial intelligence technology, and in particular relates to a model training method, intent classification method, device, equipment, medium and product. Background Art
[0002] Intent recognition technology plays an important role in applications such as intelligent assistants, customer service systems, and information retrieval. With the continuous advancement of natural language processing technology, the performance of intent classification models has been significantly improved. However, in the face of diverse and complex user input, there are still some problems that need to be solved in intent classification models. For example, when training the model, the training samples used to train the intent classification model are randomly selected, which may result in a small number of training samples for a certain type of intent in the training. In this case, the intent classification model may have poor classification accuracy when classifying texts of this type of intent. Summary of the invention
[0003] The embodiments of the present application provide a model training method, intent classification method, device, equipment, medium and product, which can improve the classification accuracy of the intent classification model.
[0004] In a first aspect, an embodiment of the present application provides a model training method, the method comprising:
[0005] Obtain multiple initial samples;
[0006] For each of the initial samples, executing: generating a target adversarial sample according to the initial sample, wherein the semantic similarity between the target adversarial sample and the initial sample is greater than a preset threshold and the intentions are different;
[0007] Add each of the initial samples and the generated target adversarial samples to the data set as training samples respectively;
[0008] The initial model is trained using the training samples in the data set to obtain an intent classification model, wherein, in the process of training the initial model, the number of training samples corresponding to each intent used in each round of training is determined according to the intent classification results output by the initial model in the previous round of training.
[0009] In a second aspect, an embodiment of the present application provides an intent classification method, the method comprising:
[0010] Get the text to be classified;
[0011] The text to be classified is classified according to the intention classification model to obtain the intention classification result of the text to be classified. The intention classification model is obtained by adopting the model training method described in the first aspect.
[0012] In a third aspect, an embodiment of the present application provides a model training device, the device comprising:
[0013] A first acquisition module, used for acquiring a plurality of initial samples;
[0014] A generating module, configured to execute, for each of the initial samples: generating a target adversarial sample according to the initial sample, wherein the semantic similarity between the target adversarial sample and the initial sample is greater than a preset threshold and the intentions are different;
[0015] A second acquisition module, used to add each of the initial samples and the generated target adversarial samples as training samples to the data set;
[0016] A training module is used to train the initial model using the training samples in the data set to obtain an intent classification model, wherein, in the process of training the initial model, the number of training samples corresponding to each intent used in each round of training is determined according to the intent classification results output by the initial model in the previous round of training.
[0017] In a fourth aspect, an embodiment of the present application provides an intent classification device, the device comprising:
[0018] An acquisition module is used to obtain the text to be classified;
[0019] A classification module is used to classify the text to be classified according to an intention classification model to obtain an intention classification result of the text to be classified. The intention classification model is obtained by adopting the model training method described in the first aspect.
[0020] In a fifth aspect, an embodiment of the present application provides an electronic device, including: a processor and a memory storing computer program instructions;
[0021] When the processor executes the computer program instructions, it implements the model training method as described in the first aspect, or implements the intent classification method as described in the second aspect.
[0022] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the model training method as described in the first aspect is implemented, or the intent classification method as described in the second aspect is implemented.
[0023] In the seventh aspect, an embodiment of the present application provides a computer program product. When the instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes the model training method as described in the first aspect, or implements the intent classification method as described in the second aspect.
[0024] In this embodiment, during the training of the initial model, the training samples for each round are determined dynamically. That is, according to the classification effect of the initial model in the previous round of training, the number of training samples corresponding to each intent in this round of training is dynamically adjusted. This can balance the proportion of training samples for different intents and improve the classification accuracy of the intent classification model. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the technical solution of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0026] Figure 1 It is a flow chart of the model training method provided in the embodiment of the present application;
[0027] Figure 2 It is another flowchart of the model training method provided in the embodiment of the present application;
[0028] Figure 3 It is a flow chart of the intent classification method provided in the embodiment of the present application;
[0029] Figure 4 It is a structural schematic diagram of a model training device provided in an embodiment of the present application;
[0030] Figure 5 is a schematic diagram of the structure of the intent classification device provided in an embodiment of the present application;
[0031] Figure 6 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0032] The features and exemplary embodiments of various aspects of the present application will be described in detail below. In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain the present application, rather than to limit the present application. For those skilled in the art, the present application can be implemented without the need for some of these specific details. The following description of the embodiments is only to provide a better understanding of the present application by illustrating the examples of the present application.
[0033] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "include..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0034] In each specific implementation of the present application, when it comes to the need to perform relevant processing based on data related to user identity or characteristics such as user information, user behavior data, user historical data, and user location information, the user's permission or consent will be obtained first, and the collection, use, and processing of these data will comply with relevant laws, regulations, and standards. In addition, when the embodiment of the present application needs to obtain the user's sensitive personal information, the user's separate permission or consent will be obtained through a pop-up window or by jumping to a confirmation page. After clearly obtaining the user's separate permission or consent, the necessary user-related data for the normal operation of the disclosed embodiment will be obtained.
[0035] In order to solve the problems of the prior art, the embodiments of the present application provide a model training method, an intent classification method, an apparatus, a device, a medium and a product. The model training method provided by the embodiments of the present application is first introduced below.
[0036] Figure 1 FIG. 1 is a flow chart of a model training method provided by an embodiment of the present application. Figure 1 As shown, the model training method provided in the embodiment of the present application is applied to an electronic device and includes the following steps 101 to 103, wherein:
[0037] Step 101, obtaining a plurality of initial samples.
[0038] The initial sample may be a text obtained after preprocessing the original text such as word segmentation, part-of-speech tagging and syntactic analysis. The preprocessing is used to identify key intent words (words can also be called phrases) and phrases in the initial sample.
[0039] Step 102, for each of the initial samples, executing: generating a target adversarial sample according to the initial sample, wherein the semantic similarity between the target adversarial sample and the initial sample is greater than a preset threshold and the intentions are different.
[0040] Perform at least one of the following processing on the initial sample to obtain the target adversarial sample:
[0041] Synonym replacement, intent perturbation, sentence reconstruction, intent insertion and / or deletion, and inputting the initial sample into a pre-trained preset model. Among them, synonym replacement refers to replacing the keywords in the initial sample with a synonym dictionary; intent perturbation refers to changing the key intent words or phrases in the initial sample; sentence reconstruction refers to changing the structure or component order of the sentence in the initial sample; intent insertion and / or deletion refers to changing the intent of the initial sample by inserting and / or deleting some words or phrases in the initial sample; inputting the initial sample into a preset model refers to using the preset model to generate adversarial samples that are similar to the initial sample but have different intents.
[0042] Based on the initial sample, one or more target adversarial samples can be obtained. When multiple target adversarial samples are obtained, the intentions of any two target adversarial samples can be the same or different, which is not limited here. The semantic similarity between the target adversarial sample and the initial sample is greater than a preset threshold, and the intentions are different. The preset threshold can be set according to the actual situation, such as 0.8 or 0.9, etc., which is not limited here.
[0043] Step 103: Add each of the initial samples and the generated target adversarial samples to the data set as training samples.
[0044] Each initial sample is used as a training sample, and the generated target adversarial sample is used as a training sample and added to the dataset. For example, if there are 100 initial samples, each initial sample is used as a training sample, so 100 training samples are added to the dataset; similarly, if there are 1000 target adversarial samples, each target adversarial sample is used as a training sample, so 1000 training samples are added to the dataset. The dataset is used for subsequent model training.
[0045] Step 104, use the training samples in the data set to train the initial model to obtain an intent classification model, wherein, in the process of training the initial model, the number of training samples corresponding to each intent used in each round of training is determined according to the intent classification results output by the initial model in the previous round of training.
[0046] Specifically, in the process of training the initial model using the training samples in the data set, the number of training samples corresponding to each intent used in each round of training is determined according to the intent classification results output by the initial model in the previous round of training. That is, in the process of training the initial model, the training samples in each round are dynamically determined and are related to the intent classification results output by the initial model in the previous round of training. The initial model can be a neural network model, which is not limited here.
[0047] It should be noted that when the initial model is trained for the first time, the number of training samples corresponding to each intent is the same.
[0048] In this embodiment, multiple initial samples are obtained; for each of the initial samples, the following steps are performed: based on the initial samples, a target adversarial sample is generated, wherein the semantic similarity between the target adversarial sample and the initial sample is greater than a preset threshold, and the intentions are different; each of the initial samples and the generated target adversarial sample are added to the data set as training samples; the initial model is trained using the training samples in the data set to obtain an intention classification model, wherein, in the process of training the initial model, the number of training samples corresponding to each intention used in each round of training is determined according to the intention classification result output by the initial model in the previous round of training. In the above manner, in the process of training the initial model, the training samples of each round are dynamically determined, that is, according to the classification effect of the initial model in the previous round of training, the number of training samples corresponding to each intention in the current round of training is dynamically adjusted to balance the proportion of training samples of different intentions and improve the classification accuracy of the intention classification model. In addition, adding the generated target adversarial sample to the data set together with the initial sample for model training can enhance the model's recognition ability for adversarial samples, thereby improving the robustness of the classification of the intention classification model.
[0049] In another embodiment of the present application, generating a target adversarial sample according to the initial sample includes:
[0050] Generate N candidate adversarial samples according to the initial sample, where N is a positive integer;
[0051] For each candidate adversarial sample, the following preset processing is performed:
[0052] If the semantic similarity between the initial sample and the candidate adversarial sample is greater than a preset threshold and the intentions are different, the candidate adversarial sample is used as the target adversarial sample;
[0053] If the semantic similarity between the initial sample and the candidate adversarial sample is less than or equal to the preset threshold, and / or the intentions are different, a new adversarial sample is generated based on the initial sample, and the new adversarial sample is used as a candidate adversarial sample to perform the preset processing.
[0054] In the above, the initial sample can be processed by at least one of the following processes to obtain a candidate adversarial sample:
[0055] Synonym replacement, intent perturbation, sentence reconstruction, intent insertion and / or deletion, inputting the initial sample into a pre-trained preset model. Among them, synonym replacement refers to replacing the keywords in the initial sample with a synonym dictionary; intent perturbation refers to changing the key intent words or phrases in the initial sample; sentence reconstruction refers to changing the structure or component order of the sentence in the initial sample; intent insertion and / or deletion refers to changing the intent of the initial sample by inserting and / or deleting some words or phrases in the initial sample; inputting the initial sample into a preset model refers to using the preset model to generate candidate adversarial samples that are similar to the initial sample but have different intents. Other ways of generating adversarial samples for the initial sample can also be used, which are not limited here.
[0056] After generating candidate adversarial samples based on the initial samples, preset processing is performed on each candidate adversarial sample (the preset processing can also be understood as verification processing) to verify whether the candidate adversarial sample meets the preset conditions. If the candidate adversarial sample meets the preset conditions, the candidate adversarial sample is used as the target adversarial sample; if the candidate adversarial sample does not meet the preset conditions, a new adversarial sample is generated again based on the initial sample, and the new adversarial sample is used as the candidate adversarial sample to perform preset processing. It should be noted that if the newly generated adversarial sample does not meet the preset conditions, the preset processing will be performed until the newly generated adversarial sample meets the preset conditions. In this case, the new adversarial sample will be used as the target adversarial sample. The preset condition is that the semantic similarity between the initial sample and the candidate adversarial sample is greater than the preset threshold, and the intentions are different.
[0057] In this embodiment, N candidate adversarial samples are generated based on the initial sample, and each candidate adversarial sample is verified. When the semantic similarity between the candidate adversarial sample and the initial sample is greater than a preset threshold and the intention is different, the candidate adversarial sample is used as the target adversarial sample. Otherwise, a new adversarial sample is generated and verified until the semantic similarity between the generated new adversarial sample and the initial sample is greater than a preset threshold and the intention is different, and the new adversarial sample is used as the target adversarial sample. Through the above process, it can be ensured that the semantic similarity between the target adversarial sample and the initial sample is greater than the preset threshold and the intention is different, providing training samples for subsequent model training, thereby improving the classification accuracy of the intent classification model when processing texts with similar semantics but different intentions, and reducing misjudgments and confusion.
[0058] In another embodiment of the present application, generating N candidate adversarial samples according to the initial sample includes:
[0059] Generate N candidate adversarial samples according to the initial sample and a preset first algorithm;
[0060] If the semantic similarity between the initial sample and the candidate adversarial sample is less than or equal to the preset threshold, and / or the intentions are different, generating a new adversarial sample according to the initial sample, including:
[0061] If the semantic similarity between the initial sample and the candidate adversarial sample is less than or equal to the preset threshold, generating a new adversarial sample according to the initial sample and the first algorithm;
[0062] If the initial sample and the candidate adversarial sample have the same intention, the perturbation degree of the first algorithm is adjusted to obtain a second algorithm, and a new adversarial sample is generated based on the initial sample and the second algorithm, wherein the perturbation degree of the second algorithm on the intention of the initial sample when generating a new adversarial sample is greater than the perturbation degree of the first algorithm on the intention of the initial sample when generating a candidate adversarial sample.
[0063] In the above, the first algorithm includes at least one of the following: a synonym replacement algorithm, an intention perturbation algorithm, a sentence reconstruction algorithm, an intention insertion and / or deletion algorithm, and an algorithm corresponding to a preset model, wherein the synonym replacement algorithm refers to using a synonym dictionary to replace the keywords in the initial sample to obtain a candidate adversarial sample; the intention perturbation algorithm refers to changing the key intention words or phrases in the initial sample to obtain a candidate adversarial sample; the sentence reconstruction algorithm refers to changing the structure or component order of the sentence in the initial sample to obtain a candidate adversarial sample; the intention insertion and / or deletion algorithm refers to inserting and / or deleting some words or phrases in the initial sample to change the intention of the initial sample to obtain a candidate adversarial sample; the algorithm corresponding to the preset model refers to using the preset model to generate a candidate adversarial sample that is similar to the initial sample but has a different intention. The first algorithm can also be other algorithms for generating adversarial samples, which are not limited here.
[0064] If the semantic similarity between the initial sample and the candidate adversarial sample is less than or equal to the preset threshold, a new adversarial sample is generated again in the previous manner, that is, a new adversarial sample is generated according to the initial sample and the first algorithm.
[0065] If the initial sample and the candidate adversarial sample have the same intention, the perturbation parameter of the first algorithm is adjusted to increase the perturbation degree of the first algorithm to obtain the second algorithm, and then a new adversarial sample is generated according to the second algorithm and the initial sample.
[0066] For example, the initial sample is: "Please help me book a flight to New York tomorrow."
[0067] The generated candidate adversarial example is: "Please help me book a flight to New York tomorrow.",
[0068] The intent has not changed: the intent is still "book a flight."
[0069] (1) When the first algorithm is a synonym replacement algorithm, the first algorithm is adjusted in the following manner:
[0070] Adjusting the disturbance parameters of the first algorithm includes: enhancing the replacement strength and relaxing the vocabulary category restrictions.
[0071] Adjust logic: Relax restrictions on synonyms and select synonyms with greater semantic distance for replacement;
[0072] Increase the types of replaceable words.
[0073] Augmented adversarial example: “Please help me arrange a flight to New York tomorrow.”
[0074] Replace "booking" with "arrangement" and "ticket" with "flight" to ensure similar semantics but different intent.
[0075] (2) When the first algorithm is an intention disturbance algorithm, the first algorithm is adjusted in the following manner:
[0076] Adjusting the disturbance parameters of the first algorithm includes: increasing the disturbance frequency and the disturbance depth.
[0077] Adjust the logic: Increase the frequency of the perturbed intent keywords, for example, perturb "booking" and "air tickets" at the same time;
[0078] Increase the depth of perturbation and use words that more significantly change intent.
[0079] Augmented adversarial example: “Please cancel my flight to New York tomorrow.”
[0080] By changing “book” to “cancel,” a more significant change in intent is created.
[0081] (3) When the first algorithm is a sentence reconstruction algorithm, the first algorithm is adjusted in the following manner:
[0082] Adjusting the disturbance parameters of the first algorithm includes: increasing the word order change frequency and sentence complexity.
[0083] Adjust the logic: increase the degree of variation in sentence structure, such as adding subordinate clauses or changing the order of subject, predicate, and object.
[0084] Augmented adversarial example: "I would like you to help me book a flight to New York tomorrow."
[0085] By making more drastic changes to the word order and sentence structure, the sentence becomes more complex and the intent deviates.
[0086] (4) In the case where the first algorithm is an intended insertion and / or deletion algorithm, the first algorithm is adjusted in the following manner:
[0087] Adjusting the disturbance parameters of the first algorithm includes: increasing the number of keywords inserted and / or deleted, and extending the insertion position.
[0088] Adjust logic: increase the number of keywords inserted or deleted, such as inserting noise words like "I'll talk about it later" in a sentence;
[0089] Choose words that impact your intention and change the core of your intention directly.
[0090] Augmented adversarial example: “Please help me decide later on booking a flight to New York tomorrow.”
[0091] By inserting “I’ll decide later,” an uncertainty of intent is introduced, affecting the clarity of the original intent.
[0092] (5) When the first algorithm is an algorithm corresponding to a preset model (which may be a large language model obtained by pre-training), the first algorithm is adjusted in the following manner:
[0093] Adjusting the disturbance parameters of the first algorithm includes: increasing the number of generation and the generation temperature, wherein the higher the temperature, the greater the randomness.
[0094] Adjust the logic: increase the number of generated samples and select the samples that best meet the requirement of “semantically similar but different intents”.
[0095] Increase the generation temperature to make the generated text more diverse and random.
[0096] Example: Input: "Please book me a flight to New York tomorrow."
[0097] Generate multiple samples: Sample 1: "Can you help arrange transportation to New York tomorrow?"
[0098] Sample 2: "Can I get help with my trip to New York tomorrow?"
[0099] Sample 3: "I would like to know the transportation ticket information to New York."
[0100] By increasing the number and diversity of generation, samples that meet the requirements of “deviant intent but similar semantics” are selected.
[0101] In this embodiment, different methods are selected to generate new adversarial samples according to different situations that the initial sample and the candidate adversarial sample meet. For example, if the semantic similarity between the initial sample and the candidate adversarial sample is less than or equal to the preset threshold, a new adversarial sample is generated according to the initial sample and the first algorithm; if the initial sample and the candidate adversarial sample have the same intention, the perturbation degree of the first algorithm is increased to obtain a second algorithm, and a new adversarial sample is generated according to the initial sample and the second algorithm. In the above manner, new adversarial samples can be regenerated for different situations, which can improve the availability of new adversarial samples.
[0102] In another embodiment of the present application, the initial model is trained using the training samples in the data set to obtain the intent classification model, including:
[0103] Obtaining weights corresponding to M intents in this round of training, wherein the training samples in the data set include M intents, and M is an integer greater than 1;
[0104] Determine the number of samples corresponding to each of the M intentions in the current round of training according to the weights corresponding to each of the M intentions in the current round of training, wherein the weights corresponding to each of the M intentions are determined according to the intention classification results output by the initial model in the previous round of training;
[0105] According to the number of samples corresponding to the M intentions in the current round of training, respectively, obtaining training samples corresponding to the M intentions in the current round of training from the data set;
[0106] The initial model is trained using the training samples corresponding to the M intents in this round of training, and the step of obtaining the weights corresponding to the M intents in this round of training is repeated until the preset training termination condition is met to obtain the intent classification model.
[0107] In the above, in the process of training the initial model, the weights corresponding to the M intents in each round of training are determined by the intent classification results output by the initial model in the previous round of training. It should be noted that in each round of training, the model parameters of the initial model will be updated, and the initial model for each round of training is the model obtained after the previous round of training. For the sake of ease of description, the model for each round of training is called the initial model, and the model that meets the training termination conditions is called the intent classification model.
[0108] In the above, the weight corresponding to each of the M types of intent is determined according to the intent classification result output by the initial model in the previous round of training. Specifically, the following adjustment strategy can be adopted: for intent types with poor classification effect (for example, the classification accuracy is lower than the first preset threshold, the first preset threshold is set according to the actual situation, and is not limited here. The first preset threshold can also be the average classification accuracy obtained according to the classification accuracy of each intent), increase its sampling ratio (that is, increase the weight), thereby increasing the number of training samples for the intent; for intent types with good classification effect (for example, the classification accuracy is higher than the first preset threshold), reduce its sampling ratio (that is, reduce the weight), thereby reducing the number of training samples for the intent, so as to strengthen the training of the intent with poor classification effect of the initial model, thereby improving the classification accuracy of the intent classification model.
[0109] The training termination condition can be set according to the actual situation. For example, the training termination condition may be that the number of training times reaches a preset number, or that the intent classification result output by the initial model meets expectations, for example, the classification accuracy is greater than 0.95, etc., which is not limited here.
[0110] It should be noted that the sum of the weights corresponding to each of the M intents is 1. If the number of training samples required for each round of training is 100, the weight corresponding to the first intent is 0.2, and the number of training samples corresponding to this intent is 20; the weight corresponding to the second intent is 0.3, and the number of training samples corresponding to this intent is 30; the weight corresponding to the third intent is 0.5, and the number of training samples corresponding to this intent is 50.
[0111] The training samples in the data set include M kinds of intents. The training samples in the data set can be classified in advance according to the intents. For example, there are 1000 training samples, and these 1000 training samples include 3 intents. There are 300 training samples in the first intent, 300 training samples in the second intent, and 400 training samples in the third intent. After determining the number of training samples corresponding to each intent, the required number of training samples can be randomly selected from the multiple training samples corresponding to each intent.
[0112] In this embodiment, the weights corresponding to each of the M intents are determined based on the intent classification results output by the initial model in the previous round of training. According to the weights corresponding to the M intents in this round of training, the number of samples corresponding to each of the M intents in this round of training is determined, thereby determining the training samples for this round. By dynamically adjusting the number of training samples corresponding to each intent in each round, the proportion of training samples for different intents can be balanced, thereby improving the classification accuracy of the intent classification model.
[0113] In an embodiment of the present application, obtaining the weights corresponding to the M intentions in the current round of training includes:
[0114] If the current round of training is the first round of training, the weights corresponding to the M intentions in the current round of training are set to be the same;
[0115] If the current round of training is not the first round of training, the classification accuracy of each intent of the initial model in the previous round of training is obtained according to the intent classification results of the training samples corresponding to each of the M intents by the initial model in the previous round of training;
[0116] According to the classification accuracy of each intention in the previous round of training, the weight corresponding to each intention in the previous round of training is adjusted to obtain the intermediate weight corresponding to each of the M intentions in the current round of training;
[0117] The intermediate weights corresponding to the M intentions in the current round of training are normalized to obtain the weights corresponding to the M intentions in the current round of training.
[0118] For example, the training samples in the last round of training include three intents, and the number of training samples corresponding to each intent is 20, 30, and 50 respectively. In the intent classification results of the initial model for the training samples of each intent, the number of training samples correctly classified for these three intents is 10, 20, and 45 respectively. Then, the classification accuracy of the initial model for these three intents in the last round of training is 0.5, 0.67, and 0.9 respectively, where the classification accuracy of the intent is the number of samples accurately classified corresponding to the intent divided by the total number of samples corresponding to the intent in this round of training.
[0119] According to the classification accuracy of each intent, the weight corresponding to each intent is adjusted. Specifically, according to the classification accuracy of each intent in the previous round of training, the weight corresponding to each intent in the previous round of training is adjusted to obtain the intermediate weights corresponding to the M intents in the current round of training, including:
[0120] According to the classification accuracy of each intent in the previous round of training, the average classification accuracy is calculated;
[0121] For any first intent among the M intents, perform the following processing:
[0122] If the classification accuracy of the first intent is less than the average classification accuracy, the weight of the first intent in the previous round of training is increased and adjusted to obtain an intermediate weight corresponding to the first intent in the current round of training;
[0123] If the classification accuracy of the first intent is greater than the average classification accuracy, the weight of the first intent in the previous round of training is reduced and adjusted to obtain an intermediate weight corresponding to the first intent in the current round of training;
[0124] If the classification accuracy of the first intent is equal to the average classification accuracy, the weight of the first intent in the previous round of training is used as the intermediate weight corresponding to the first intent in the current round of training.
[0125] In the above, the weight can be adjusted according to the following formula (1):
[0126] w i '=w i ×(1-λ×(ACC i -ACC - )) (1)
[0127] Among them, w i is the weight of the i-th intention in the previous round of training, ACC i is the classification accuracy of the initial model for the i-th intent in the previous round of training, w i ' is the intermediate weight of the i-th intention in this round of training, ACC - is the average classification accuracy of each intent in the previous round of training, λ is the preset adjustment coefficient, λ is a positive number, and the value of λ can be set according to the actual situation.
[0128] Through the above method, for intents with classification accuracy lower than the average classification accuracy, the corresponding intermediate weight is increased (that is, the corresponding weight obtained after normalization is increased), thereby increasing the number of training samples corresponding to the intent; for intents with classification accuracy higher than the average classification accuracy, the corresponding intermediate weight is reduced (that is, the corresponding weight obtained after normalization is reduced), thereby reducing the number of training samples corresponding to the intent, so as to strengthen the training of the initial model for intents with low classification accuracy, thereby improving the classification accuracy of the intent classification model.
[0129] After adjusting the weights corresponding to the intents, what is obtained is not the final weight of the intents, but the intermediate weights. It is also necessary to normalize the intermediate weights corresponding to the M intents to obtain the weights corresponding to the M intents in this round of training. This ensures that the sum of the weights corresponding to the M intents is 1.
[0130] Specifically, the following formula (2) can be used for normalization processing so that the sum of the weights corresponding to each intent is 1.
[0131]
[0132] w i ” is the weight of the i-th intention in this round of training after normalization, w i ' is the intermediate weight of the i-th intention in this round of training, M is the number of types of intentions, and w j is the intermediate weight of the jth intent in this round of training.
[0133] In this embodiment, the weight corresponding to each intent in the previous round of training is adjusted according to the classification accuracy of each intent by the initial model in the previous round of training, so as to obtain the weights corresponding to the M intents in this round of training, thereby dynamically adjusting the number of training samples corresponding to each intent in this round of training, balancing the proportion of training samples of different intents, and improving the classification accuracy of the intent classification model.
[0134] The following is an example of the model training method provided in the embodiments of the present application.
[0135] The model training method can include the following modules:
[0136] Data preprocessing module:
[0137] Input: original text.
[0138] Output: Text data after word segmentation, part-of-speech tagging, and syntactic analysis, i.e., the initial sample.
[0139] Function: Perform word segmentation, part-of-speech tagging and syntactic analysis on the original text to identify key intent words and phrases.
[0140] Synonym replacement submodule:
[0141] Input: preprocessed text data (i.e. initial sample).
[0142] Output: Adversarial examples after synonym replacement.
[0143] Function: Use a synonym dictionary to replace keywords in the text and generate adversarial samples.
[0144] Intention perturbation submodule:
[0145] Input: preprocessed text data.
[0146] Output: Adversarial example after intention perturbation.
[0147] Function: Change the key intent words or phrases in the text to generate adversarial samples with different intents.
[0148] Sentence reconstruction submodule:
[0149] Input: preprocessed text data.
[0150] Output: Reconstructed adversarial example.
[0151] Functionality: Change the structure or order of components of a sentence to generate adversarial examples with different intent.
[0152] Intentionally inserting and removing submodules:
[0153] Input: preprocessed text data.
[0154] Output: adversarial examples after vocabulary insertion or deletion.
[0155] Function: Insert or delete some words or phrases in the text to change the intention.
[0156] Automatically generate adversarial text submodule:
[0157] Input: preprocessed text data.
[0158] Output: Adversarial examples generated by the pre-trained large model (i.e., large language model).
[0159] Function: Use a pre-trained large model to generate adversarial samples with similar vocabulary to the original text but different intent.
[0160] Sample verification module:
[0161] Input: Generated adversarial examples.
[0162] Output: Verified adversarial examples (i.e., target adversarial examples).
[0163] Functionality: Verify the generated adversarial examples to ensure that their vocabulary and semantics are similar to the original text but with different intent.
[0164] Dataset building blocks:
[0165] Input: initial sample and adversarial sample that passed verification.
[0166] Output: Dataset.
[0167] Function: Merge the verified adversarial samples with the initial samples to construct a dataset and balance the data distribution through a dynamic ratio adjustment strategy.
[0168] Model training module:
[0169] Input: Dataset.
[0170] Output: trained intent classification model.
[0171] Function: Use the dataset to conduct adversarial training on the intent classification model to improve the classification accuracy and robustness of the model.
[0172] During the training of the initial model, the sample sampling ratios of different intents in the next round of training are dynamically adjusted according to the intent classification results of the initial model in each round of training to balance the training data of various intents.
[0173] like Figure 2As shown, the model training method provided by the embodiment of the present application includes the following steps:
[0174] Step 201, preprocessing the original text to obtain an initial sample;
[0175] Step 202, generating candidate adversarial samples according to the initial sample and the first algorithm. The first algorithm may specifically use the above-mentioned synonym replacement submodule, intention perturbation submodule, sentence reconstruction submodule, intention insertion and / or deletion submodule, and automatic generation of adversarial text submodule to generate candidate adversarial samples;
[0176] Step 203, verify whether the candidate adversarial sample is passed, if yes, go to step 204 for execution, if no, go to step 204' for execution;
[0177] Step 204, constructing a data set based on the verified candidate adversarial samples (i.e., target adversarial samples) and the initial samples;
[0178] Step 204', determine whether to increase the disturbance level according to the reason for the verification failure, if yes, go to step 206 for execution, if no, go to step 202 for execution;
[0179] Step 205, selecting training samples from the data set, training the initial model, and obtaining an intent classification model;
[0180] Step 206, performing disturbance enhancement on the first algorithm to obtain a second algorithm;
[0181] Step 207: Generate candidate adversarial samples based on the initial sample and the second algorithm.
[0182] Through the above process, data is enriched and enhanced to improve the model's generalization and intent understanding capabilities. For example, the sentence "I want to eat hot pot" belongs to the "food" intent, but after passing through the adversarial data generation module, it is generalized into "I want to learn about hot pot" and "I want to eat, but I need a pot", which correspond to "networking intent" and "chatting intent" respectively. It is necessary to construct such similar but different intent data for model learning to improve the model's intent judgment ability.
[0183] Exemplarily, step 203 may be implemented in the following manner:
[0184] After candidate adversarial samples are generated, they need to be verified to ensure that they are semantically similar to the original samples but have different intentions. The logic of verification is as follows:
[0185] Semantic similarity verification:
[0186] Use a pre-trained language model (such as BERT) or other similarity calculation tools to calculate the semantic similarity score between the original sample and the adversarial sample. When the similarity score is higher than a certain threshold (such as 0.8), it is considered semantically similar.
[0187] If the semantic similarity score is lower than the threshold, the candidate adversarial sample is marked as failed verification.
[0188] Intent difference verification:
[0189] Use the model to classify the original sample and the adversarial sample respectively to ensure that the classification results of the adversarial sample are different from the original sample. If the classification results are the same, it is considered that the intention has not changed and the verification fails.
[0190] A large language model (LLM) (such as GPT or other pre-trained large models) can be used to verify candidate adversarial samples and determine whether to enhance the adversarial perturbation.
[0191] The specific process is as follows:
[0192] 1. Input data:
[0193] The original sample and the candidate adversarial sample are provided as input to LLM for analysis. The input includes:
[0194] Initial sample;
[0195] Generated adversarial examples;
[0196] Semantic similarity scores between the initial sample and the adversarial sample;
[0197] Classification results of initial samples and adversarial samples.
[0198] 2. LLM output (developing system prompts for large models specifically designed to verify expectations and enhance judgment):
[0199] LLM analyzes and outputs the reasons why adversarial sample verification fails. The output results include:
[0200] Semantic difference analysis: Analyze the reasons for the lack of semantic similarity, for example, which words or phrases cause the semantics to deviate from the original text;
[0201] Causes of intent confusion: Analyze the reasons why intent classification has not changed, such as if the key intent words in the adversarial sample have not been perturbed or the perturbation is not significant enough.
[0202] According to the analysis results of LLM, determine whether to perform perturbation enhancement on the adversarial sample. The specific logic is as follows:
[0203] 1. Insufficient semantic similarity:
[0204] If the LLM analysis results indicate that the semantics of the adversarial sample is significantly different from the original sample (for example, the choice of vocabulary or the change of sentence structure leads to a significant deviation in semantics), the perturbation is not enhanced and a new adversarial sample is directly regenerated.
[0205] 2. Confusion of intent:
[0206] If the LLM analysis results indicate that the intent of the adversarial sample has not been effectively changed (for example, the core keywords of the intent are not sufficiently perturbed or the intent is unclear), perturbation enhancement is required.
[0207] When it is determined that disturbance enhancement is necessary, stronger disturbance can be achieved through the following strategies:
[0208] 1. Enhanced synonym replacement:
[0209] For the more critical intent words in the initial sample, synonyms are replaced to increase the depth of replacement. For example, for key verbs, nouns, etc., synonyms that are more different from the original intent are selected.
[0210] 2. Increase intention disturbance:
[0211] In the intent perturbation submodule, the perturbation degree of the intent words or phrases is increased by introducing more perturbation operations, such as directly changing the intent-related phrases or introducing more reverse expressions.
[0212] 3. Further adjustment of sentence structure:
[0213] In the sentence reconstruction submodule, the perturbations to the sentence structure are added, such as replacing more critical sentence components or reconstructing the relationship between the subject and the object, so that the intention is changed more clearly.
[0214] 4. Automatically generate diverse adversarial samples:
[0215] Use LLM to generate more diverse adversarial samples, combine the context of the initial sample, and generate multiple sentence expressions to ensure that the generated adversarial samples are semantically similar but have significantly changed intentions.
[0216] In the above, step 205 specifically includes the following process:
[0217] 1. Initialization:
[0218] Set the initial sampling ratio to make the sample sampling ratio of all intents equal.
[0219] Initialize the weights corresponding to each intent, and the initial weights are equal.
[0220] 2. Training process:
[0221] After each training cycle, the classification effect of the initial model on each intent is evaluated, that is, the classification accuracy of each category (that is, each intent) is calculated.
[0222] 3. Dynamic adjustment:
[0223] Adjust the sampling ratio according to the classification accuracy. For categories with poor classification results, increase their sampling ratio; for categories with good classification results, reduce their sampling ratio.
[0224] The weight corresponding to each intent is updated in the manner shown in the above formula (1).
[0225] 4. Normalized weights:
[0226] Normalize the weight of each intent so that it sums to 1:
[0227] 5. Resampling:
[0228] According to the updated weights, the training samples are resampled for the next round of training.
[0229] Repeat the above process until the training is completed.
[0230] In the above process, five submodules are introduced: synonym replacement, intent perturbation, sentence reconstruction, intent insertion and deletion, and automatic generation of adversarial text. Adversarial samples with similar vocabulary but different intents are generated. Using these samples to train the initial model can improve the model's ability to handle subtle intent differences, thereby improving the model's classification accuracy and reducing misjudgments. Through a dynamic ratio adjustment strategy, the number of training samples corresponding to each intent is balanced, and the model's classification accuracy for minority intents is improved. Through adversarial training, the model's ability to recognize adversarial samples is improved, and the robustness and security of the model are enhanced.
[0231] Figure 3 A schematic diagram of the process of the intent classification method provided in the embodiment of the present application is shown as follows: Figure 3 As shown, the intent classification method provided in the embodiment of the present application includes steps 301 to 302, wherein:
[0232] Step 301, obtaining the text to be classified.
[0233] Step 302, classify the text to be classified according to the intention classification model to obtain the intention classification result of the text to be classified, and the intention classification model is obtained by adopting the model training method in the above embodiment.
[0234] In this embodiment, since the training samples for each round are dynamically determined during the training of the intent classification model, that is, the number of training samples corresponding to each intent in this round of training is dynamically adjusted according to the classification effect of the initial model in the previous round of training, the proportion of training samples for different intents can be balanced. This can improve the classification accuracy of the intent classification model, so that the intent classification model can classify the text to be classified more accurately.
[0235] Figure 4 The structure diagram of the model training device provided in the embodiment of the present application is shown. Figure 4 As shown, the model training device 400 includes:
[0236] A first acquisition module 401 is used to acquire a plurality of initial samples;
[0237] The generating module 402 is configured to execute, for each of the initial samples, the following steps: generating a target adversarial sample according to the initial sample, wherein the semantic similarity between the target adversarial sample and the initial sample is greater than a preset threshold and the intentions are different;
[0238] A second acquisition module 403 is used to add each of the initial samples and the generated target adversarial samples as training samples to the data set;
[0239] The training module 404 is used to train the initial model using the training samples in the data set to obtain an intent classification model, wherein, in the process of training the initial model, the number of training samples corresponding to each intent used in each round of training is determined according to the intent classification results output by the initial model in the previous round of training.
[0240] In an embodiment of the present application, the generating module 402 includes:
[0241] A first generation submodule, configured to generate N candidate adversarial samples according to the initial sample, where N is a positive integer;
[0242] The processing module is used to perform the following preset processing for each candidate adversarial sample:
[0243] If the semantic similarity between the initial sample and the candidate adversarial sample is greater than the preset threshold and the intentions are different, the candidate adversarial sample is used as the target adversarial sample;
[0244] If the semantic similarity between the initial sample and the candidate adversarial sample is less than or equal to the preset threshold, and / or the intentions are different, a new adversarial sample is generated based on the initial sample, and the new adversarial sample is used as a candidate adversarial sample to perform the preset processing.
[0245] In an embodiment of the present application, the first generating submodule specifically includes:
[0246] Generate N candidate adversarial samples according to the initial sample and a preset first algorithm;
[0247] The processing module is further configured to generate a new adversarial sample according to the initial sample and the first algorithm if the semantic similarity between the initial sample and the candidate adversarial sample is less than or equal to the preset threshold;
[0248] If the initial sample and the candidate adversarial sample have the same intention, the perturbation degree of the first algorithm is adjusted to obtain a second algorithm, and a new adversarial sample is generated based on the initial sample and the second algorithm, wherein the perturbation degree of the second algorithm on the intention of the initial sample when generating a new adversarial sample is greater than the perturbation degree of the first algorithm on the intention of the initial sample when generating a candidate adversarial sample.
[0249] In one embodiment of the present application, the training module 404 includes:
[0250] A first acquisition submodule is used to obtain weights corresponding to M intents in this round of training, wherein the training samples in the data set include M intents, and M is an integer greater than 1;
[0251] A first determination submodule is used to determine the number of samples corresponding to each of the M intentions in the current round of training according to the weights corresponding to each of the M intentions in the current round of training, wherein the weights corresponding to each of the M intentions are determined according to the intention classification results output by the initial model in the previous round of training;
[0252] A second acquisition submodule is used to acquire, from the data set, training samples corresponding to the M intentions in the current round of training according to the number of samples corresponding to the M intentions in the current round of training;
[0253] The training submodule is used to train the initial model using the training samples corresponding to the M intentions in this round of training, and repeatedly execute the step of obtaining the weights corresponding to the M intentions in this round of training until the preset training termination conditions are met to obtain the intent classification model.
[0254] In an embodiment of the present application, the first acquisition submodule includes:
[0255] A setting unit, configured to set the weights corresponding to the M intentions in the current round of training to be the same if the current round of training is the first round of training;
[0256] an acquisition unit, configured to obtain, if the current round of training is not the first round of training, the classification accuracy of each intent of the initial model in the previous round of training according to the intent classification results of the training samples corresponding to each of the M intents by the initial model in the previous round of training;
[0257] An adjustment unit, configured to adjust the weight corresponding to each intention in the previous round of training according to the classification accuracy of each intention in the previous round of training, so as to obtain the intermediate weight corresponding to each of the M intentions in the current round of training;
[0258] The normalization unit is used to normalize the intermediate weights corresponding to the M intentions in the current round of training to obtain the weights corresponding to the M intentions in the current round of training.
[0259] In one embodiment of the present application, the adjustment unit includes:
[0260] A calculation subunit, used to calculate an average classification accuracy rate according to the classification accuracy rate of each intent in the previous round of training;
[0261] The processing subunit is configured to perform the following processing for any first intent among the M intents:
[0262] If the classification accuracy of the first intent is less than the average classification accuracy, the weight of the first intent in the previous round of training is increased and adjusted to obtain an intermediate weight corresponding to the first intent in the current round of training;
[0263] If the classification accuracy of the first intent is greater than the average classification accuracy, the weight of the first intent in the previous round of training is reduced and adjusted to obtain an intermediate weight corresponding to the first intent in the current round of training;
[0264] If the classification accuracy of the first intent is equal to the average classification accuracy, the weight of the first intent in the previous round of training is used as the intermediate weight corresponding to the first intent in the current round of training.
[0265] The model training device 400 provided in the embodiment of the present application can implement the various processes implemented in the aforementioned model training method embodiment and achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0266] Figure 5 FIG. 1 shows a structural diagram of an intention classification device provided in an embodiment of the present application. Figure 5 As shown, the intention classification device 500 includes:
[0267] An acquisition module 501 is used to acquire the text to be classified;
[0268] The classification module 502 is used to classify the text to be classified according to the intention classification model to obtain the intention classification result of the text to be classified. The intention classification model is obtained by using the model training method described in the above embodiment.
[0269] The intent classification device 500 provided in the embodiment of the present application can implement the various processes implemented in the aforementioned intent classification method embodiment and achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0270] Figure 6 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application is shown.
[0271] The electronic device may include a processor 601 and a memory 602 storing computer program instructions.
[0272] Specifically, the processor 601 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.
[0273] The memory 602 may include a large capacity memory for data or instructions. By way of example and not limitation, the memory 602 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive or a combination of two or more of these. In appropriate cases, the memory 602 may include a removable or non-removable (or fixed) medium. In appropriate cases, the memory 602 may be inside or outside the integrated gateway disaster recovery device. In a specific embodiment, the memory 602 is a non-volatile solid-state memory.
[0274] The memory may include a read-only memory (ROM), a random access memory (RAM), a magnetic disk storage medium device, an optical storage medium device, a flash memory device, an electrical, optical or other physical / tangible memory storage device. Thus, typically, the memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., a memory device) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the method according to the first aspect or the second aspect of the present disclosure.
[0275] The processor 601 implements any one of the information auditing methods in the above embodiments by reading and executing computer program instructions stored in the memory 602 .
[0276] In one example, the electronic device may further include a communication interface 603 and a bus 610. Figure 6 As shown, the processor 601, the memory 602, and the communication interface 603 are connected via a bus 610 and communicate with each other.
[0277] The communication interface 603 is mainly used to implement communication between various modules, devices, units and / or equipment in the embodiments of the present application.
[0278] Bus 610 includes hardware, software or both, and the parts of information audit method or verification equipment are coupled to each other. For example, but not limitation, bus may include accelerated graphics port (AGP) or other graphics bus, enhanced industrial standard architecture (EISA) bus, front side bus (FSB), hypertransport (HT) interconnection, industrial standard architecture (ISA) bus, infinite bandwidth interconnection, low pin count (LPC) bus, memory bus, micro channel architecture (MCA) bus, peripheral component interconnection (PCI) bus, PCI-Express (PCI-X) bus, serial advanced technology attachment (SATA) bus, video electronics standard association local (VLB) bus or other suitable bus or two or more of these combinations. In suitable cases, bus 610 may include one or more buses. Although the present application embodiment describes and shows a specific bus, the application considers any suitable bus or interconnection.
[0279] In addition, in combination with the model training method in the above embodiment, the embodiment of the present application can provide a computer storage medium for implementation. The computer storage medium stores computer program instructions; when the computer program instructions are executed by the processor, any one of the model training methods or intent classification methods in the above embodiment is implemented.
[0280] An embodiment of the present application may provide a computer program product. When the instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes any one of the model training methods or intent classification methods in the above embodiments.
[0281] An embodiment of the present application also provides a computer program product. When the instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes any one of the model training methods or intent classification methods in the above embodiments.
[0282] It should be clear that the present application is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiment, several specific steps are described as examples. However, the method process of the present application is not limited to the specific steps described, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present application.
[0283] The functional blocks shown in the above-described block diagram can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc. When implemented in software, the elements of the present application are programs or code segments that are used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or a communication link by a data signal carried in a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, optical fiber media, radio frequency (RF) links, etc. The code segment can be downloaded via a computer network such as the Internet, an intranet, etc.
[0284] It should also be noted that the exemplary embodiments mentioned in this application describe some methods or systems based on a series of steps or devices. However, this application is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiment, or in a different order from the embodiment, or several steps can be performed simultaneously.
[0285] Aspects of the present disclosure are described above with reference to the flowchart and / or block diagram of the method, device (system) according to the embodiment of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device to produce a machine so that these instructions executed by the processor of the computer or other programmable data processing device enable the implementation of the function / action specified in one or more boxes of the flowchart and / or block diagram. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor, or a field programmable logic circuit. It can also be understood that each box in the block diagram and / or flowchart and the combination of boxes in the block diagram and / or flowchart can also be implemented by dedicated hardware that performs a specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions.
[0286] The above is only a specific implementation of the present application. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the systems, modules and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. It should be understood that the protection scope of the present application is not limited to this. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in this application, and these modifications or replacements should be included in the protection scope of this application.
Claims
1. A model training method, characterized in that: The method comprises: Obtain multiple initial samples; For each of the initial samples, executing: generating a target adversarial sample according to the initial sample, wherein the semantic similarity between the target adversarial sample and the initial sample is greater than a preset threshold and the intentions are different; Add each of the initial samples and the generated target adversarial samples to the data set as training samples respectively; The initial model is trained using the training samples in the data set to obtain an intent classification model, wherein, in the process of training the initial model, the number of training samples corresponding to each intent used in each round of training is determined according to the intent classification results output by the initial model in the previous round of training.
2. The model training method according to claim 1, characterized in that: Generating a target adversarial sample according to the initial sample includes: Generate N candidate adversarial samples according to the initial sample, where N is a positive integer; For each candidate adversarial sample, the following preset processing is performed: If the semantic similarity between the initial sample and the candidate adversarial sample is greater than the preset threshold and the intentions are different, the candidate adversarial sample is used as the target adversarial sample; If the semantic similarity between the initial sample and the candidate adversarial sample is less than or equal to the preset threshold, and / or the intentions are different, a new adversarial sample is generated based on the initial sample, and the new adversarial sample is used as a candidate adversarial sample to perform the preset processing.
3. The model training method according to claim 2, characterized in that: The step of generating N candidate adversarial samples according to the initial sample includes: Generate N candidate adversarial samples according to the initial sample and a preset first algorithm; If the semantic similarity between the initial sample and the candidate adversarial sample is less than or equal to the preset threshold, and / or the intentions are different, generating a new adversarial sample according to the initial sample, including: If the semantic similarity between the initial sample and the candidate adversarial sample is less than or equal to the preset threshold, generating a new adversarial sample according to the initial sample and the first algorithm; If the initial sample and the candidate adversarial sample have the same intention, the perturbation degree of the first algorithm is adjusted to obtain a second algorithm, and a new adversarial sample is generated based on the initial sample and the second algorithm, wherein the perturbation degree of the second algorithm on the intention of the initial sample when generating a new adversarial sample is greater than the perturbation degree of the first algorithm on the intention of the initial sample when generating a candidate adversarial sample.
4. The model training method according to claim 1, characterized in that: The method of training the initial model using the training samples in the data set to obtain the intent classification model includes: Obtaining weights corresponding to M intents in this round of training, wherein the training samples in the data set include M intents, and M is an integer greater than 1; Determine the number of samples corresponding to each of the M intentions in the current round of training according to the weights corresponding to each of the M intentions in the current round of training, wherein the weights corresponding to each of the M intentions are determined according to the intention classification results output by the initial model in the previous round of training; According to the number of samples corresponding to the M intentions in the current round of training, respectively, obtaining training samples corresponding to the M intentions in the current round of training from the data set; The initial model is trained using the training samples corresponding to the M intents in this round of training, and the step of obtaining the weights corresponding to the M intents in this round of training is repeated until the preset training termination condition is met to obtain the intent classification model.
5. The model training method according to claim 4, characterized in that: The step of obtaining the weights corresponding to the M intentions in this round of training includes: If the current round of training is the first round of training, the weights corresponding to the M intentions in the current round of training are set to be the same; If the current round of training is not the first round of training, the classification accuracy of each intent of the initial model in the previous round of training is obtained according to the intent classification results of the training samples corresponding to each of the M intents by the initial model in the previous round of training; According to the classification accuracy of each intention in the previous round of training, the weight corresponding to each intention in the previous round of training is adjusted to obtain the intermediate weight corresponding to each of the M intentions in the current round of training; The intermediate weights corresponding to the M intentions in the current round of training are normalized to obtain the weights corresponding to the M intentions in the current round of training.
6. The model training method according to claim 5, characterized in that: According to the classification accuracy of each intent in the previous round of training, the weight corresponding to each intent in the previous round of training is adjusted to obtain the intermediate weights corresponding to each of the M intents in the current round of training, including: According to the classification accuracy of each intent in the previous round of training, the average classification accuracy is calculated; For any first intent among the M intents, perform the following processing: If the classification accuracy of the first intent is less than the average classification accuracy, the weight of the first intent in the previous round of training is increased and adjusted to obtain an intermediate weight corresponding to the first intent in the current round of training; If the classification accuracy of the first intent is greater than the average classification accuracy, the weight of the first intent in the previous round of training is reduced and adjusted to obtain an intermediate weight corresponding to the first intent in the current round of training; If the classification accuracy of the first intent is equal to the average classification accuracy, the weight of the first intent in the previous round of training is used as the intermediate weight corresponding to the first intent in the current round of training.
7. A method for classifying intent, characterized in that: The method comprises: Get the text to be classified; The text to be classified is classified according to the intention classification model to obtain the intention classification result of the text to be classified, and the intention classification model is obtained by adopting the model training method described in any one of claims 1-6.
8. A model training device, characterized in that: The device comprises: A first acquisition module, used for acquiring a plurality of initial samples; A generating module, configured to execute, for each of the initial samples: generating a target adversarial sample according to the initial sample, wherein the semantic similarity between the target adversarial sample and the initial sample is greater than a preset threshold and the intentions are different; A second acquisition module, used to add each of the initial samples and the generated target adversarial samples as training samples to the data set; A training module is used to train the initial model using the training samples in the data set to obtain an intent classification model, wherein, in the process of training the initial model, the number of training samples corresponding to each intent used in each round of training is determined according to the intent classification results output by the initial model in the previous round of training.
9. An intention classification device, characterized in that: The device comprises: An acquisition module is used to obtain the text to be classified; A classification module is used to classify the text to be classified according to an intention classification model to obtain an intention classification result of the text to be classified, and the intention classification model is obtained by using the model training method described in any one of claims 1-6.
10. An electronic device, characterized in that: include: a processor and a memory storing computer program instructions; When the processor executes the computer program instructions, it implements the model training method as described in any one of claims 1-6, or implements the intent classification method as described in claim 7.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer program instructions, which, when executed by a processor, implement the model training method as described in any one of claims 1 to 6, or implement the intent classification method as described in claim 7.
12. A computer program product, characterized in that When the instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes the model training method as described in any one of claims 1 to 6, or implements the intent classification method as described in claim 7.
Citation Information
Cited By
Text risk classification model training method, text risk classification method and equipment
CN121705749A