A multi-task model training method, system, medium and electronic terminal
By adding a new classification layer to the original multi-task model and performing freeze and thaw training, the problem of low model training efficiency in the existing technology is solved, and new knowledge can be learned quickly while retaining old knowledge, thereby improving the training efficiency and accuracy of the multi-task model.
Patent Information
- Application Number
- CN202111522799.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-13
- Publication Date
- 2025-12-05
- Estimated Expiration
- 2041-12-13
AI Technical Summary
When new tasks arise, existing technologies require the integration of new and old knowledge to retrain multi-task models, resulting in low training efficiency and an inability to quickly learn new knowledge while retaining old knowledge.
A new classification layer is added to the original multi-task model, the parameter layer and the original classification layer are frozen, a prediction and training are performed once, and after unfreezing, a second prediction and joint training are performed to obtain the final multi-task model.
It enables rapid learning of new knowledge while retaining old knowledge, improving the training and iteration efficiency of multi-task models and reducing model training costs.
Smart Images

Figure CN114186684B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence technology, and in particular to a multi-task model training method, system, medium, and electronic terminal. Background Technology
[0002] With the development of natural language processing technology, multi-task models have been increasingly widely used. However, over time, many new tasks in new domains often emerge. Currently, when a new task appears, it is usually necessary to discard the old model, integrate new and old knowledge, and retrain a multi-task model. This results in low model training efficiency, an inability to support rapid model iteration, and an inability to continue learning new knowledge while retaining old knowledge.
[0003] For example, in life insurance quality inspection tasks, it is often necessary to identify irregular dialogue by humans or machines. This involves identifying whether agents use any irregular dialogue when communicating with customers over the phone. These irregular dialogues may involve multiple areas, and new irregular dialogues will emerge over time. We need to judge the newly emerging irregular dialogues. However, existing technologies require integrating new and old knowledge and retraining a multi-task model to meet the needs of identifying new irregular dialogues, resulting in low model iteration efficiency. Summary of the Invention
[0004] This invention provides a multi-task model training method, system, medium, and electronic terminal to solve the problem in the prior art that when a new task appears, it is not possible to continue learning new knowledge while retaining old knowledge. Instead, it is necessary to integrate new and old knowledge and retrain a multi-task model, resulting in low model training efficiency and iteration efficiency.
[0005] The multi-task model training method provided by this invention includes:
[0006] Obtain the new task, and add a new classification layer to the original multi-task model based on the new task to obtain an intermediate model. The intermediate model includes a parameter layer, an original classification layer, and a new classification layer.
[0007] The parameter layer and the original classification layer are frozen;
[0008] The newly added training statement in the new task is input into the intermediate model for a prediction, and the first prediction result output by the new classification layer and the second prediction result output by the original classification layer are obtained.
[0009] Based on the first prediction result and the corresponding true classification result in the new task, the new classification layer is trained once.
[0010] Unfreeze the parameter layer and the original classification layer, input the newly added training statement into the intermediate model for secondary prediction, and obtain the third prediction result output by the original classification layer;
[0011] Based on the second and third prediction results, all layers in the intermediate model are jointly trained to obtain the final multi-task model.
[0012] Optionally, the step of freezing the parameter layer and the original classification layer includes:
[0013] Based on the pre-set frozen attributes, the parameter attributes of the trainable variables in the parameter layer and the original classification layer are updated once.
[0014] Add a parameter filter to the optimizer of the intermediate model;
[0015] After iterating through the parameter attributes of the trainable variables in the parameter layer and the original classification layer after one update, determine whether the parameter attributes of the trainable variables in the parameter layer and the original classification layer are both frozen attributes, and obtain the first judgment result.
[0016] Based on the first judgment result, the parameter layer and the original classification layer are frozen.
[0017] Optionally, the step of training the new classification layer based on the first prediction result and the corresponding true classification result in the new task includes:
[0018] Based on the first prediction result, the corresponding true classification result in the new task, and the preset first loss function, the new classification layer is trained. The mathematical expression of the first loss function is as follows:
[0019]
[0020] in, For the first loss function, The prediction result output by the newly added classification layer, y n This represents the actual classification result corresponding to the prediction result output by the newly added classification layer.
[0021] Optionally, after the step of adding a parameter filter to the optimizer of the intermediate model, the following steps are included:
[0022] When training a new classification layer, the control parameter filter filters the trainable variables in the parameter layer and the original classification layer according to the preset filtering rules, and then trains the new classification layer.
[0023] The filtering rules include: determining whether the parameter attribute of the trainable variable is a frozen attribute; if the parameter attribute of the trainable variable is a frozen attribute, then filtering the corresponding trainable variable and keeping the corresponding trainable variable unchanged.
[0024] Optionally, the step of unfreezing the parameter layer and the original classification layer includes:
[0025] According to the pre-set unfreezing rules, the parameter attributes of trainable variables in the parameter layer and the original classification layer are updated a second time.
[0026] The parameter attributes of the trainable variables in the parameter layer and the original classification layer after the second update are traversed. It is determined whether the parameter attributes of the trainable variables in the parameter layer and the original classification layer are all unfrozen attributes. A second determination result is obtained, and then the unfreezing of the parameter layer and the original classification layer is completed.
[0027] Optionally, the step of jointly training all layers in the intermediate model based on the second and third prediction results includes:
[0028] Obtain the fourth prediction result output by the newly added classification layer during the secondary prediction process. Based on the fourth prediction result, the corresponding true classification result, and the preset first loss function, obtain the first loss and perform secondary training on the newly added classification layer to obtain the newly added classification layer after secondary training.
[0029] Based on the second prediction result, the third prediction result, and the preset second loss function, the original classification layer is distilled to obtain the second loss, and the original classification layer is trained once to obtain the original classification layer after one training.
[0030] Based on the first loss and the second loss, the parameter layer, the newly added classification layer after secondary training, and the original classification layer after primary training in the intermediate model are jointly trained.
[0031] The mathematical expression for the second loss function is:
[0032]
[0033] in, Let y′ be the second loss function. o This is the second prediction result from the original classification layer, frozen during a prediction process. This represents the third prediction result output by the original classification layer after thawing during the secondary prediction process, where l is the prediction number of the original classification layer after thawing.
[0034] Optionally, the step of jointly training the parameter layer, the newly added classification layer after secondary training, and the original classification layer after primary training in the intermediate model based on the first loss and the second loss includes:
[0035] Based on the first and second losses, a preset third loss function is used to jointly train the parameter layer, the newly added classification layer after secondary training, and the original classification layer after primary training in the intermediate model. The mathematical expression of the third loss function is as follows:
[0036]
[0037] in, For the third loss function, θ s θ is the parameter layer, θ0 is the original classification layer, θ n To add a new classification layer, argmin represents the value of the variable that minimizes the subsequent expression, λ0 is the preset first weight, and λ1 is the preset second weight. The second loss is the loss of the original sorting layer during the distillation process. The first loss is the loss of the newly added classification layer during the secondary prediction process.
[0038] The present invention also provides a multi-task model training system, comprising:
[0039] A new task module is used to obtain new tasks. Based on the new tasks, a new classification layer is added to the original multi-task model to obtain an intermediate model. The intermediate model includes a parameter layer, an original classification layer, and a new classification layer.
[0040] The first training module is used to freeze the parameter layer and the original classification layer; input the new training statement in the new task into the intermediate model to make a prediction, and obtain the first prediction result output by the new classification layer and the second prediction result output by the original classification layer; and train the new classification layer based on the first prediction result and the corresponding true classification result in the new task.
[0041] The second training module is used to unfreeze the parameter layer and the original classification layer, input the newly added training statement into the intermediate model for secondary prediction, and obtain the third prediction result output by the original classification layer; based on the second prediction result and the third prediction result, the module performs joint training on all layers in the intermediate model to obtain the final multi-task model.
[0042] The newly added task module, the first training module, and the second training module are connected.
[0043] The present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method as described in any of the preceding claims.
[0044] The present invention also provides an electronic terminal, including: a processor and a memory;
[0045] The memory is used to store computer programs, and the processor is used to execute the computer programs stored in the memory to cause the terminal to perform the method described in any of the preceding descriptions.
[0046] The beneficial effects of this invention are as follows: The multi-task model training method, system, medium, and electronic terminal of this invention acquire a new task, add a new classification layer corresponding to the new task to the original multi-task model, and then obtain an intermediate model. The intermediate model includes a parameter layer, an original classification layer, and a new classification layer. Then, the parameter layer and the original classification layer are frozen, and the new training statement from the new task is input into the intermediate model for a prediction. A first prediction result from the new classification layer and a second prediction result from the original classification layer are obtained. Based on the first prediction result and the corresponding true classification result in the new task, the new classification layer is trained once. Then, the parameter layer and the original classification layer are unfrozen, and the new training statement is input into the intermediate model for a second prediction. A third prediction result from the original classification layer is obtained. Based on the second and third prediction results, all layers in the intermediate model are jointly trained to obtain the final multi-task model. This achieves the ability to learn new knowledge while retaining old knowledge, completing the iteration of the original multi-task model. The model has high training and iteration efficiency and high accuracy. It is understood that "new knowledge" refers to the new task, and "old knowledge" refers to the original task of the original multi-task model. Attached Figure Description
[0047] Figure 1 This is a flowchart illustrating the multi-task model training method in an embodiment of the present invention.
[0048] Figure 2 This is a schematic diagram illustrating the process of freezing the parameter layer and the original classification layer in the multi-task model training method of this invention.
[0049] Figure 3 This is a schematic diagram of the process of training a newly added classification layer in the multi-task model training method in this embodiment of the invention.
[0050] Figure 4 This is a schematic diagram of the process of unfreezing the parameter layer and the original classification layer in the multi-task model training method of this invention.
[0051] Figure 5This is a schematic diagram of the process of jointly training all layers of the intermediate model in the multi-task model training method of this invention.
[0052] Figure 6 This is a schematic diagram of the structure of the multi-task model training system in an embodiment of the present invention.
[0053] Figure 7 This is a schematic diagram of the structure of the electronic terminal for multi-task model training in an embodiment of the present invention. Detailed Implementation
[0054] The following specific examples illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that, unless otherwise specified, the following embodiments and features described therein can be combined with each other.
[0055] It should be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of the present invention. Therefore, the drawings only show the components related to the present invention and are not drawn according to the actual number, shape and size of the components in the actual implementation. In the actual implementation, the form, quantity and proportion of each component can be arbitrarily changed, and the layout of the components may also be more complex.
[0056] like Figure 1 As shown, the multi-task model training method in this embodiment includes:
[0057] S11: Obtain the new task. Based on the new task, add a new classification layer to the original multi-task model to obtain an intermediate model. The intermediate model includes a parameter layer, an original classification layer, and a new classification layer. The new task refers to a newly emerging task, including a new training statement and the corresponding real classification result. The original multi-task model is the original model used to predict multiple tasks. The original multi-task model includes a parameter layer and an original classification layer. The original classification layer is the original classification layer in the original multi-task model, and the parameter layer is the other layers in the original multi-task model besides the original classification layer. The new task corresponds to the new classification layer. When the new classification layer is added to the original multi-task model, an intermediate model is formed. The intermediate model includes a parameter layer, an original classification layer, and a new classification layer. By obtaining the new task and adding a new classification layer corresponding to the new task to the original multi-task model, it is convenient to continue learning new knowledge, i.e., continuing to learn new tasks, based on the original multi-task model, thereby improving the iteration and update efficiency of the multi-task model. For example, if the original task in the original multi-task model is "confusing financial products", and a new task is obtained, assuming the new task is "misleading insurance without spending money", then a classification layer corresponding to the new task "misleading insurance without spending money" is added to the original multi-task model to obtain an intermediate model. The intermediate model includes: a parameter layer, an original classification layer corresponding to the original task, and a new classification layer corresponding to the new task "misleading insurance without spending money". Based on this, the multi-task model is trained and iterated to improve the iteration efficiency of the multi-task model.
[0058] Understandably, a multi-task model refers to a model that learns multiple tasks simultaneously. The structure of a multi-task model typically includes a parameter layer of a transformer structure and N classification layers corresponding to the tasks. The transformer is an encoder-decoder structure based on an attention mechanism. Multi-task models are the opposite of single-task models. As time progresses, new tasks emerge. When new tasks in a new domain appear, existing technologies usually require integrating old and new knowledge to retrain a multi-task model. This undoubtedly incurs huge training costs and takes a long time. Therefore, the multi-task model training method in this embodiment adds a new classification layer corresponding to the new task to the original multi-task model to obtain an intermediate model. This effectively achieves the addition of new tasks based on the original multi-task model, saving training time and costs.
[0059] S12: Freeze the parameter layer and the original classification layer; specifically, freezing the parameter layer and the original classification layer in the intermediate model means that in subsequent training processes, the trainable variables of the parameter layer and the original classification layer in the intermediate model are not updated, that is, they only participate in the forward loss calculation and not in the backpropagation. By freezing the parameter layer and the original classification layer in the intermediate model, it is convenient to train the newly added task layer separately in subsequent training processes, thereby improving the accuracy of the newly added classification layer.
[0060] S13: Input the newly added training statement from the new task into the intermediate model for one prediction, and obtain the first prediction result output by the new classification layer and the second prediction result output by the original classification layer; that is, input the newly added training statement from the new task into the intermediate model, and use the new classification layer and the original classification layer to predict the newly added training statement once, and obtain the first prediction result output by the new classification layer and the second classification result output by the original classification layer. By obtaining the first prediction result output by the new classification layer, it is convenient to train the new classification layer separately based on the first prediction result, thereby improving the classification accuracy of the new classification layer. Since the original classification layer is a pre-trained classification layer, it is understood that the second prediction result output by the original classification layer is a good prediction. Therefore, by using the second prediction result output by the original classification layer, it is convenient to perform knowledge distillation on the original classification layer after unfreezing, thereby improving the accuracy of the original classification layer.
[0061] S14: Based on the first prediction result and the corresponding true classification result in the new task, train the new classification layer once; that is, by obtaining the difference between the first prediction result and the corresponding true classification result in the new task, iteratively train the new classification layer to achieve separate training of the new classification layer and improve the accuracy of the new classification layer.
[0062] S15: Unfreeze the parameter layer and the original classification layer, input the newly added training statement into the intermediate model for secondary prediction, and obtain the third prediction result output by the original classification layer; that is, after one training is completed, unfreeze the parameter layer and the original classification layer in the intermediate model so that the trainable variables in the parameter layer and the original classification layer can participate in the update and backpropagation in the subsequent training process, and input the newly added training statement into the intermediate model for secondary prediction to obtain the third prediction result output by the original classification layer.
[0063] S16: Based on the second and third prediction results, jointly train all layers in the intermediate model to obtain the final multi-task model. By obtaining the difference between the second and third prediction results, knowledge distillation is performed on the unfrozen original classification layer to improve the accuracy of the original classification layer. This allows the model to learn new knowledge while retaining the ability to recognize old knowledge. Furthermore, based on the difference between the second and third prediction results, jointly train all layers in the intermediate model, namely the parameter layer, the original classification layer, and the newly added classification layer, to obtain a better final multi-task model. This achieves the learning of new knowledge while retaining old knowledge, effectively improving the training and iteration efficiency of the multi-task model. The model has high accuracy and greatly reduces the model training cost. It also avoids the need to integrate new and old knowledge when a new task appears and then retrain a multi-task model using the integrated knowledge.
[0064] In some embodiments, the number of newly added tasks can be one or more. When there are multiple newly added tasks, the multiple newly added tasks are sorted and marked. The above steps S11, S12, S13, S14, S15, and S16 are repeated according to the order of the newly added tasks to complete the iteration and update of the multi-task model. This effectively improves the iteration efficiency and training efficiency of the multi-task model, greatly saves the cost of model training, and the model has high accuracy and strong feasibility.
[0065] In some embodiments, when a new task appears again, the steps S11, S12, S13, S14, S15, and S16 above are repeated to complete the iteration and update of the multi-task model. The model has high accuracy, is easy to implement, and has low cost.
[0066] like Figure 2 As shown, in order to better achieve the freezing of the parameter layer and the original classification layer, and to ensure that the parameter layer and the original classification layer do not participate in parameter updates and iterations in subsequent training processes, the inventors propose that the steps for freezing the parameter layer and the original classification layer include:
[0067] S121: Update the parameter attributes of the trainable variables in the parameter layer and the original classification layer according to the preset frozen attributes; that is, change the parameter attributes of the trainable variables in the parameter layer and the original classification layer to the preset frozen attributes, for example: set the parameter attribute (requires-grad) of the trainable variables in the parameter layer and the original classification layer to False.
[0068] S122: Add a parameter filter to the optimizer of the intermediate model;
[0069] S123: Traverse the parameter attributes of the trainable variables in the parameter layer and the original classification layer after one update, determine whether the parameter attributes of the trainable variables in the parameter layer and the original classification layer are all frozen attributes, and obtain the first judgment result;
[0070] S124: Based on the first judgment result, the freezing of the parameter layer and the original classification layer is completed. Specifically, to further ensure that the trainable variables of both the parameter layer and the original classification layer are frozen, the parameter attributes of the trainable variables in both layers are iterated. It is determined whether the parameter attributes of both layers are frozen (False). If both layers are frozen (False), the freezing of the trainable variables is completed. If the parameter attributes of the trainable variables in the parameter layer and / or the original classification layer are not frozen (False), the corresponding trainable variable's parameter attributes are updated to frozen attributes. Once all the parameter attributes of the trainable variables in both layers are frozen, the freezing of the trainable variables in both layers is completed. This ensures that the trainable variables in the parameter layer and the original classification layer will not participate in backpropagation and updates in subsequent training processes, i.e., in the separate training of the newly added classification layer, thereby improving the accuracy of model training.
[0071] like Figure 3 As shown, in some embodiments, the step of training the new classification layer based on the first prediction result and the corresponding true classification result in the new task includes:
[0072] S141: Based on the first prediction result, the corresponding true classification result in the new task, and the preset first loss function, the new classification layer is trained. The mathematical expression of the first loss function is:
[0073]
[0074] in, For the first loss function, The prediction result output by the newly added classification layer, y n This refers to the true classification result corresponding to the predicted result output by the newly added classification layer. In other words, during a single training cycle, the newly added classification layer is iteratively trained using a pre-defined first loss function, effectively improving the prediction accuracy of the new classification layer.
[0075] In some embodiments, when the newly added classification layer is trained once, the control parameter filter filters the trainable variables in the parameter layer and the original classification layer according to the preset filtering rules, and then trains the newly added classification layer once.
[0076] The filtering rules include: determining whether the parameter attribute of a trainable variable is a frozen attribute; if the parameter attribute of the trainable variable is a frozen attribute, then filtering the corresponding trainable variable and keeping the corresponding trainable variable unchanged. For example, determining whether the parameter attribute of a trainable variable in an intermediate model is a frozen attribute False; if the parameter attribute of the trainable variable is False, then filtering the trainable variable and keeping the value of the trainable variable unchanged, thereby freezing the trainable variables of the parameter layer and the original classification layer during a training process, avoiding the trainable variables of the parameter layer and the original classification layer from participating in parameter updates and iterations during a training process, realizing separate training for the newly added classification layer, and thus realizing learning new knowledge based on existing knowledge, i.e., old knowledge, improving the efficiency of model training and iteration.
[0077] like Figure 4 As shown, in order to improve the thawing efficiency of the parameter layer and the original classification layer, and to avoid errors during the thawing process, the inventors propose that the steps for thawing the parameter layer and the original classification layer include:
[0078] S151: According to the pre-set unfreezing rules, perform a secondary update on the parameter attributes of trainable variables in the parameter layer and the original classification layer; that is, change the parameter attributes of trainable variables in the parameter layer and the original classification layer to the preset unfreezing attributes, for example: change the parameter attribute (requires-grad) of trainable variables in the parameter layer and the original classification layer to True, and complete the secondary update of trainable variables in the parameter layer and the original classification layer.
[0079] S152: Traverse the parameter attributes of the trainable variables in the parameter layer and the original classification layer after the second update, determine whether the parameter attributes of the trainable variables in the parameter layer and the original classification layer are all unfrozen attributes, obtain the second judgment result, and then complete the unfreezing of the parameter layer and the original classification layer. To further ensure that the trainable variables in both the parameter layer and the original classification layer are unfrozen, the parameter attributes of the trainable variables in both layers are iterated. It is determined whether all parameter attributes of the trainable variables in both layers are "True" (unfrozen). If all parameter attributes are "True", the unfreezing of the trainable variables in both layers is complete. If the parameter attributes of the trainable variables in the parameter layer and / or the original classification layer are not "True", the corresponding parameter attributes are updated to "True". Once all parameter attributes of the trainable variables in both layers are "True", the unfreezing of the trainable variables in both layers is complete. This ensures that the trainable variables in the parameter layer and the original classification layer participate in backpropagation and parameter updates during subsequent joint training, enabling the learning of new knowledge based on existing knowledge.
[0080] Preferably, during the secondary training process, parameter filters in the intermediate model can be deleted or removed to reduce the model's workload and improve its efficiency.
[0081] In some embodiments, the step of jointly training all layers in the intermediate model based on the second prediction result and the third prediction result includes:
[0082] By obtaining the difference between the second and third prediction results, all layers of the intermediate model are jointly trained to obtain the final multi-task model.
[0083] To further improve the accuracy of the final multi-task model, the inventors proposed that during joint training, in addition to obtaining the difference between the second and third prediction results, a loss for the newly added classification layer should be added. Then, using the loss from the newly added classification layer and the distillation loss from the original classification layer, all layers of the intermediate model are jointly trained. Figure 5 As shown, the steps for jointly training all layers of the intermediate model using the loss of the newly added classification layer and the distillation loss of the original classification layer include:
[0084] S161: Obtain the fourth prediction result output by the newly added classification layer during the secondary prediction process. Based on the fourth prediction result, the corresponding true classification result, and the preset first loss function, obtain the first loss, and perform secondary training on the newly added classification layer to obtain the newly added classification layer after secondary training. That is, using the preset first loss function, obtain the difference between the fourth prediction result and the corresponding true classification result, obtain the first loss, and perform secondary training on the newly added classification layer based on the first loss to improve the prediction accuracy of the newly added classification layer. The degree of secondary training on the newly added classification layer can be set according to the actual situation, which will not be elaborated here.
[0085] S162: Based on the second prediction result, the third prediction result, and the preset second loss function, the original classification layer is distilled to obtain the second loss, and the original classification layer is trained once to obtain the original classification layer after one training; that is, using the second loss function, the difference between the second prediction result and the third prediction result is obtained to obtain the second loss, and the original classification layer is distilled based on the second loss to realize the one training of the original classification layer. The degree of one training of the original classification layer can be set according to the actual situation, which will not be elaborated here.
[0086] S163: Based on the first loss and the second loss, the parameter layer, the newly added classification layer after secondary training, and the original classification layer after primary training in the intermediate model are jointly trained; that is, by combining the first loss and the second loss, all layers of the intermediate model are jointly trained to obtain a final multi-task model with high accuracy.
[0087] The mathematical expression for the second loss function is:
[0088]
[0089] in, Let y′ be the second loss function. o This is the second prediction result from the original classification layer, frozen during a prediction process. The third prediction result is the output of the original classification layer after thawing during the secondary prediction process, where l represents the number of predictions made by the original classification layer after thawing. By employing the aforementioned second loss function to distill the original classification layer, the prediction accuracy of the original classification layer can be effectively improved, and the distillation efficiency is good.
[0090] In some embodiments, the step of jointly training the parameter layer, the newly added classification layer after secondary training, and the original classification layer after primary training in the intermediate model based on the first loss and the second loss includes:
[0091] S1631: Based on the first loss and the second loss, and using a preset third loss function, the parameter layer, the newly added classification layer after secondary training, and the original classification layer after primary training in the intermediate model are jointly trained. The mathematical expression of the third loss function is as follows:
[0092]
[0093] in, For the third loss function, θ s Let θ0 be the parameter layer, θ0 be the original classification layer, θ1 be the newly added classification layer, argmin represent the value of the variable that minimizes the following expression, λ0 be the preset first weight, and λ1 be the preset second weight. The second loss is the loss of the original sorting layer during the distillation process. The first loss is the loss of the newly added classification layer during the secondary prediction process. By adopting the aforementioned third loss function, joint training and iterative updates are performed on all layers of the intermediate model, which significantly improves the accuracy and precision of the final multi-task model, greatly enhances the training efficiency of the multi-task model, eliminates the need to retrain a new model, and enables the learning of new knowledge based on existing knowledge.
[0094] Example 1:
[0095] In life insurance quality inspection applications, it is often necessary to determine whether non-compliant statements are involved during interactions with customers. Over time, new non-compliant statements often emerge. If the original multi-task model is used for judgment, it often cannot accurately identify the corresponding non-compliant statements. Existing technologies usually require integrating new knowledge corresponding to the new task (newly added training statements and their corresponding real classification results) and old knowledge corresponding to the old task (the training data used by the original multi-task model, including the original training samples and their corresponding real prediction results) to retrain a new multi-task model. This process is difficult, computationally complex, time-consuming, and costly, resulting in low model training efficiency. Therefore, this embodiment obtains an intermediate model by adding a new classification layer corresponding to the new task to the original multi-task model. The intermediate model includes a parameter layer, an original classification layer, and a new classification layer. The parameter layer and the original classification layer in the intermediate model are frozen. The new training statement in the new task is input into the intermediate model for prediction, and the first prediction result output by the new classification layer and the second prediction result output by the original classification layer are obtained. Based on the first prediction result and the corresponding true classification result in the new task, the new classification layer is trained once. After the first training is completed, the parameter layer and the original classification layer are unfrozen, and the new training statement is input into the intermediate model for prediction a second time, and the third prediction result output by the original classification layer and the fourth classification result output by the new classification layer are obtained. Based on the second prediction result, the third prediction result, the fourth prediction result, and the true classification result corresponding to the fourth prediction result, all layers in the intermediate model are jointly trained to obtain the final multi-task model. This realizes iterative training and updating of the original multi-task model without integrating new and old knowledge and retraining a multi-task model. The model training and iteration efficiency is high, the accuracy is high, and the model training cost is greatly saved and the model training time is shortened. For example, when the new task is to determine the violation statement "misleading insurance companies to pay less," then according to the new task, a corresponding new classification layer θ1 is added to the original multi-task model to obtain an intermediate model. This intermediate model includes: the new classification layer θ1 and the parameter layer θ1. s And the original classification layer θ0, freeze the parameter layer θ s And the original classification layer θ0, so that the parameter layer θ s In a subsequent training iteration of the newly added classification layer, the original classification layer θ0 no longer participates in backpropagation and iteration. Instead, the newly added training statement corresponding to the new task is input into the intermediate model for prediction. The first prediction result output by the new classification layer θ1 and the second prediction result output by the original classification layer θ0 are obtained. Based on the first prediction result and the corresponding true classification result, the new classification layer is trained once. During this process, the parameter layer θ... sThe original classification layer θ0 has been frozen, therefore, the parameter layer θ s The original classification layer θ0 does not participate in parameter updates. Only after the newly added classification layer θ1 has been trained separately are the parameter layers θ updated. s The original classification layer θ0 is unfrozen, and the newly added training statement for the new task is input into the intermediate model for secondary prediction. The third prediction result output by the original classification layer θ0 and the fourth prediction result output by the newly added classification layer θ1 are obtained. Based on the difference between the second and third prediction results and the difference between the fourth prediction result and the corresponding true classification result, all layers in the original multi-task model are jointly trained to obtain a better final multi-task model. This effectively achieves the training of new tasks based on the original multi-task model, further learning new knowledge based on old knowledge, with high training efficiency, high accuracy, and good model prediction effect.
[0096] Example 2:
[0097] In intelligent call answering or public opinion assessment applications, when a task requires judging newly emerging inappropriate or target language, an intermediate model is obtained by adding a new classification layer corresponding to the new task to the original multi-task model. This intermediate model includes a parameter layer, an original classification layer, and a new classification layer. The parameter layer and the original classification layer in the intermediate model are then frozen. The new training statement for the new task is input into the intermediate model for prediction. The first prediction result output by the new classification layer and the second prediction result output by the original classification layer are obtained. By obtaining the difference between the first prediction result and the corresponding true classification result, the new classification layer is trained. After the individual training of the new classification layer is completed, then... The parameter layer and the original classification layer are unfrozen, allowing them to participate in parameter updates and iterations during subsequent training. New training statements are input into the intermediate model for secondary prediction, yielding the third prediction result from the original classification layer and the fourth prediction result from the newly added classification layer. Based on the second, third, and fourth prediction results, as well as the corresponding true classification result, all layers in the intermediate model are jointly trained to obtain the final multi-task model with high accuracy. This allows the model to retain the old knowledge of the original multi-task model while training on the new knowledge corresponding to the new task, effectively improving the training efficiency of the multi-task model.
[0098] like Figure 6 As shown, this embodiment also provides a multi-task model training system, including:
[0099] A new task module is used to obtain new tasks. Based on the new tasks, a new classification layer is added to the original multi-task model to obtain an intermediate model. The intermediate model includes a parameter layer, an original classification layer, and a new classification layer.
[0100] The first training module is used to freeze the parameter layer and the original classification layer; input the new training statement in the new task into the intermediate model to make a prediction, and obtain the first prediction result output by the new classification layer and the second prediction result output by the original classification layer; and train the new classification layer based on the first prediction result and the corresponding true classification result in the new task.
[0101] The second training module is used to unfreeze the parameter layer and the original classification layer, input the newly added training statement into the intermediate model for secondary prediction, and obtain the third prediction result output by the original classification layer; based on the second prediction result and the third prediction result, the module performs joint training on all layers in the intermediate model to obtain the final multi-task model.
[0102] The newly added task module, the first training module, and the second training module are connected. In this embodiment, the multi-task model training system acquires a new task, adds a new classification layer corresponding to the new task to the original multi-task model, and then obtains an intermediate model. The intermediate model includes a parameter layer, an original classification layer, and a newly added classification layer. Then, the parameter layer and the original classification layer are frozen, and the new training statement from the new task is input into the intermediate model for a prediction. The first prediction result output by the newly added classification layer and the second prediction result output by the original classification layer are obtained. Based on the first prediction result and the corresponding true classification result in the new task, the newly added classification layer is trained once. Then, the parameter layer and the original classification layer are unfrozen, and the new training statement is input into the intermediate model for a second prediction. The third prediction result output by the original classification layer is obtained. Based on the second and third prediction results, all layers in the intermediate model are jointly trained to obtain the final multi-task model. This system achieves the ability to learn new knowledge while retaining old knowledge, completing the iteration of the original multi-task model. The model has high training and iteration efficiency, high accuracy, low cost, and strong feasibility.
[0103] In some embodiments, the step of freezing the parameter layer and the original classification layer includes:
[0104] Based on the pre-set frozen attributes, the parameter attributes of the trainable variables in the parameter layer and the original classification layer are updated once.
[0105] Add a parameter filter to the optimizer of the intermediate model;
[0106] After iterating through the parameter attributes of the trainable variables in the parameter layer and the original classification layer after one update, determine whether the parameter attributes of the trainable variables in the parameter layer and the original classification layer are both frozen attributes, and obtain the first judgment result.
[0107] Based on the first judgment result, the parameter layer and the original classification layer are frozen.
[0108] In some embodiments, the step of training the new classification layer once based on the first prediction result and the corresponding true classification result in the new task includes:
[0109] Based on the first prediction result, the corresponding true classification result in the new task, and the preset first loss function, the new classification layer is trained. The mathematical expression of the first loss function is as follows:
[0110]
[0111] in, For the first loss function, The prediction result output by the newly added classification layer, y n This represents the actual classification result corresponding to the prediction result output by the newly added classification layer.
[0112] In some embodiments, the step of adding a parameter filter to the optimizer of the intermediate model includes:
[0113] When training a new classification layer, the control parameter filter filters the trainable variables in the parameter layer and the original classification layer according to the preset filtering rules, and then trains the new classification layer.
[0114] The filtering rules include: determining whether the parameter attribute of the trainable variable is a frozen attribute; if the parameter attribute of the trainable variable is a frozen attribute, then filtering the corresponding trainable variable and keeping the corresponding trainable variable unchanged.
[0115] In some embodiments, the step of unfreezing the parameter layer and the original classification layer includes:
[0116] According to the pre-set unfreezing rules, the parameter attributes of trainable variables in the parameter layer and the original classification layer are updated a second time.
[0117] The parameter attributes of the trainable variables in the parameter layer and the original classification layer after the second update are traversed. It is determined whether the parameter attributes of the trainable variables in the parameter layer and the original classification layer are all unfrozen attributes. A second determination result is obtained, and then the unfreezing of the parameter layer and the original classification layer is completed.
[0118] In some embodiments, the step of jointly training all layers in the intermediate model based on the second prediction result and the third prediction result includes:
[0119] Obtain the fourth prediction result output by the newly added classification layer during the secondary prediction process. Based on the fourth prediction result, the corresponding true classification result, and the preset first loss function, obtain the first loss and perform secondary training on the newly added classification layer to obtain the newly added classification layer after secondary training.
[0120] Based on the second prediction result, the third prediction result, and the preset second loss function, the original classification layer is distilled to obtain the second loss, and the original classification layer is trained once to obtain the original classification layer after one training.
[0121] Based on the first loss and the second loss, the parameter layer, the newly added classification layer after secondary training, and the original classification layer after primary training in the intermediate model are jointly trained.
[0122] The mathematical expression for the second loss function is:
[0123]
[0124] in, Let y′ be the second loss function. o This is the second prediction result from the original classification layer, frozen during a prediction process. This represents the third prediction result output by the original classification layer after thawing during the secondary prediction process, where l is the prediction number of the original classification layer after thawing.
[0125] In some embodiments, the step of jointly training the parameter layer, the newly added classification layer after secondary training, and the original classification layer after primary training in the intermediate model based on the first loss and the second loss includes:
[0126] Based on the first and second losses, a preset third loss function is used to jointly train the parameter layer, the newly added classification layer after secondary training, and the original classification layer after primary training in the intermediate model. The mathematical expression of the third loss function is as follows:
[0127]
[0128] in, For the third loss function, θ s θ is the parameter layer, θ0 is the original classification layer, θ n To add a new classification layer, argmin represents the value of the variable that minimizes the subsequent expression, λ0 is the preset first weight, and λ1 is the preset second weight. The second loss is the loss of the original sorting layer during the distillation process. The first loss is the loss of the newly added classification layer during the secondary prediction process.
[0129] This embodiment also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the methods in this embodiment.
[0130] This embodiment also provides an electronic terminal, including: a processor and a memory;
[0131] The memory is used to store computer programs, and the processor is used to execute the computer programs stored in the memory to cause the terminal to perform any of the methods in this embodiment.
[0132] like Figure 7 The diagram illustrates the structure of an electronic terminal according to an embodiment of the present invention. The electronic terminal provided in this example includes: a processor 71, a memory 72, a communicator 73, a communication interface 74, and a system bus 75. The memory 72 and the communication interface 74 are connected to the processor 71 and the communicator 73 via the system bus 75 and communicate with each other. The memory 72 stores computer programs, the communication interface 74 communicates with other devices, and the processor 71 and the communicator 73 run the computer programs, enabling the electronic terminal to execute the various steps of the multi-task model distillation method described above.
[0133] The system bus 75 mentioned above can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This system bus can be divided into address bus, data bus, control bus, etc. For ease of representation, it is represented by only one thick line in the figure, but this does not indicate that there is only one bus or one type of bus. The communication interface is used to enable communication between the database access device and other devices (e.g., clients, read-write libraries, and read-only libraries). Memory may include Random Access Memory (RAM) and may also include non-volatile memory, such as at least one disk storage device.
[0134] In this embodiment, the memory may include random access memory (RAM) and may also include non-volatile memory, such as at least one disk storage device.
[0135] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0136] The computer-readable storage medium in this embodiment is understood by those skilled in the art to be capable of implementing all or part of the steps of the above method embodiments by computer program-related hardware. The aforementioned computer program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above method embodiments; and the aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disk, or optical disk. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to wireless, wired, optical fiber, RF, etc., or any suitable combination thereof. The program code for performing the operations of this invention can be written in any combination of one or more programming languages, including object-oriented programming languages—such as Java, C++, etc.—and conventional procedural programming languages—such as the "C" language or similar programming languages. The program code can be executed entirely on a user computing device, partially on a user device, as a standalone software package, partially on a user computing device and partially on a remote computing device, or entirely on a remote computing device or server. A server can be a standalone server or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms. In cases involving remote computing devices, these devices can connect to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or they can connect to external computing devices, such as through an internet service provider via the internet.
[0137] This application's embodiments can acquire and process relevant data based on artificial intelligence (AI) technology. AI is the theory, methods, technology, and application system that uses digital computers or computers-controlled machines to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to obtain optimal results. Basic AI technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operating / interactive systems, and mechatronics. AI software technologies mainly include computer vision, robotics, biometrics, speech processing, natural language processing, and machine learning / deep learning.
[0138] In summary, the multi-task model training method, system, medium, and electronic terminal in this embodiment acquire a new task, add a new classification layer corresponding to the new task to the original multi-task model, and obtain an intermediate model. The intermediate model includes a parameter layer, an original classification layer, and a new classification layer. Then, the parameter layer and the original classification layer are frozen, and the new training statement from the new task is input into the intermediate model for a prediction. The first prediction result output by the new classification layer and the second prediction result output by the original classification layer are obtained. Based on the first prediction result and the corresponding true classification result in the new task, the new classification layer is trained once. Then, the parameter layer and the original classification layer are unfrozen, and the new training statement is input into the intermediate model for a second prediction. The third prediction result output by the original classification layer is obtained. Based on the second and third prediction results, all layers in the intermediate model are jointly trained to obtain the final multi-task model. This achieves the ability to continue learning new knowledge while retaining old knowledge, completing the iteration of the original multi-task model. The model has high training and iteration efficiency, high accuracy, and effectively reduces the iteration cost of the multi-task model.
[0139] Furthermore, the above figures are merely illustrative of the processes included in the method according to exemplary embodiments of the present invention, and are not intended to be limiting. It is readily understood that the processes shown in the above figures do not indicate or limit the temporal order of these processes. Additionally, it is readily understood that these processes may be executed synchronously or asynchronously, for example, in multiple modules.
[0140] The above embodiments are merely illustrative of the principles and effects of the present invention and are not intended to limit the invention. Any person skilled in the art can modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by those skilled in the art without departing from the spirit and technical concept disclosed in the present invention should still be covered by the claims of the present invention.
Claims
1. A multi-task model training method, characterized in that, include: Obtain a new task, and based on the new task, add a new classification layer to the original multi-task model to obtain an intermediate model. The intermediate model includes a parameter layer, an original classification layer, and a new classification layer. The parameter layer is the other layers in the original multi-task model except for the original classification layer. The new task is a new task for judging illegal speech. The parameter layer and the original classification layer are frozen; The newly added training statement in the new task is input into the intermediate model for a prediction, and the first prediction result output by the new classification layer and the second prediction result output by the original classification layer are obtained. The newly added training statement is a new violation statement. Based on the first prediction result and the corresponding true classification result in the new task, the new classification layer is trained once. Unfreeze the parameter layer and the original classification layer, input the newly added training statement into the intermediate model for secondary prediction, and obtain the third prediction result output by the original classification layer; Based on the second and third prediction results, all layers in the intermediate model are jointly trained to obtain the final multi-task model, which is used to judge illegal speech. The steps for jointly training all layers in the intermediate model based on the second and third prediction results include: Obtain the fourth prediction result output by the newly added classification layer during the secondary prediction process. Based on the fourth prediction result, the corresponding true classification result, and the preset first loss function, obtain the first loss and perform secondary training on the newly added classification layer to obtain the newly added classification layer after secondary training. Based on the second prediction result, the third prediction result, and the preset second loss function, the original classification layer is distilled to obtain the second loss, and the original classification layer is trained once to obtain the original classification layer after one training. Based on the first loss and the second loss, the parameter layer, the newly added classification layer after secondary training, and the original classification layer after primary training in the intermediate model are jointly trained.
2. The multi-task model training method according to claim 1, characterized in that, The steps for freezing the parameter layer and the original classification layer include: Based on the pre-set frozen attributes, the parameter attributes of the trainable variables in the parameter layer and the original classification layer are updated once. Add a parameter filter to the optimizer of the intermediate model; After iterating through the parameter attributes of the trainable variables in the parameter layer and the original classification layer after one update, determine whether the parameter attributes of the trainable variables in the parameter layer and the original classification layer are both frozen attributes, and obtain the first judgment result. Based on the first judgment result, the parameter layer and the original classification layer are frozen.
3. The multi-task model training method according to claim 1, characterized in that, The steps for training the new classification layer based on the first prediction result and the corresponding true classification result in the new task include: Based on the first prediction result, the corresponding true classification result in the new task, and the preset first loss function, the new classification layer is trained. The mathematical expression of the first loss function is as follows: in, For the first loss function, The prediction result output by the newly added classification layer, y n This represents the actual classification result corresponding to the prediction result output by the newly added classification layer.
4. The multi-task model training method according to claim 2, characterized in that, The step of adding a parameter filter to the optimizer of the intermediate model includes: When training a new classification layer, the control parameter filter filters the trainable variables in the parameter layer and the original classification layer according to the preset filtering rules, and then trains the new classification layer. The filtering rules include: determining whether the parameter attribute of the trainable variable is a frozen attribute; if the parameter attribute of the trainable variable is a frozen attribute, then filtering the corresponding trainable variable and keeping the corresponding trainable variable unchanged.
5. The multi-task model training method according to claim 1, characterized in that, The steps for unfreezing the parameter layer and the original classification layer include: According to the pre-set unfreezing rules, the parameter attributes of trainable variables in the parameter layer and the original classification layer are updated a second time. The parameter attributes of the trainable variables in the parameter layer and the original classification layer after the second update are traversed. It is determined whether the parameter attributes of the trainable variables in the parameter layer and the original classification layer are all unfrozen attributes. A second determination result is obtained, and then the unfreezing of the parameter layer and the original classification layer is completed.
6. The multi-task model training method according to claim 1, characterized in that, The mathematical expression for the second loss function is: in, For the second loss function, y ′ o This is the second prediction result from the original classification layer, frozen during a prediction process. This represents the third prediction result output by the original classification layer after thawing during the secondary prediction process, where l is the prediction number of the original classification layer after thawing.
7. The multi-task model training method according to claim 6, characterized in that, The steps for jointly training the parameter layer, the newly added classification layer after secondary training, and the original classification layer after primary training in the intermediate model based on the first loss and the second loss include: Based on the first and second losses, a preset third loss function is used to jointly train the parameter layer, the newly added classification layer after secondary training, and the original classification layer after primary training in the intermediate model. The mathematical expression of the third loss function is as follows: in, For the third loss function, θ s θ is the parameter layer, θ0 is the original classification layer, θ n To add a new classification layer, argmin represents the value of the variable that minimizes the subsequent expression, λ0 is the preset first weight, and λ1 is the preset second weight. The second loss is the loss of the original sorting layer during the distillation process. The first loss is the loss of the newly added classification layer during the secondary prediction process.
8. A multi-task model training system, characterized in that, include: A new task module is used to obtain new tasks. Based on the new tasks, a new classification layer is added to the original multi-task model to obtain an intermediate model. The intermediate model includes a parameter layer, an original classification layer, and a new classification layer. The parameter layer is the other layers in the original multi-task model except for the original classification layer. The new task is a new task for judging illegal speech. The first training module is used to freeze the parameter layer and the original classification layer; input the newly added training statement in the new task into the intermediate model for prediction, obtain the first prediction result output by the new classification layer and the second prediction result output by the original classification layer, wherein the newly added training statement is a new violation statement; and train the new classification layer once based on the first prediction result and the corresponding real classification result in the new task. The second training module is used to unfreeze the parameter layer and the original classification layer, input the newly added training statement into the intermediate model for secondary prediction, and obtain the third prediction result output by the original classification layer; based on the second prediction result and the third prediction result, all layers in the intermediate model are jointly trained to obtain the final multi-task model, which is used to judge illegal speech. The newly added task module, the first training module, and the second training module are connected; The steps for jointly training all layers in the intermediate model based on the second and third prediction results include: Obtain the fourth prediction result output by the newly added classification layer during the secondary prediction process. Based on the fourth prediction result, the corresponding true classification result, and the preset first loss function, obtain the first loss and perform secondary training on the newly added classification layer to obtain the newly added classification layer after secondary training. Based on the second prediction result, the third prediction result, and the preset second loss function, the original classification layer is distilled to obtain the second loss, and the original classification layer is trained once to obtain the original classification layer after one training. Based on the first loss and the second loss, the parameter layer, the newly added classification layer after secondary training, and the original classification layer after primary training in the intermediate model are jointly trained.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, it implements the method as described in any one of claims 1 to 7.
10. An electronic terminal, characterized in that, include: Processor and memory; The memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory to cause the terminal to perform the method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Training method and device for generating generative model of adversarial text
CN111241287A
Method, device, equipment, medium and program for generating multi-task model
CN112527383A
Multi-task model distillation method and system, medium and electronic terminal
CN113706347A