A natural language understanding model training method and device
By introducing a perceptual loss network with a multi-layer sequence transformer structure in the training of natural language understanding models, the problem of parameter quantity and performance balance in the existing technology is solved, the accuracy and performance of the student model are improved, and it is suitable for sequential language tasks.
Patent Information
- Application Number
- CN202011165670.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-27
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2040-10-27
AI Technical Summary
Existing deep learning models in the field of natural language understanding are difficult to balance the number of parameters and performance during the compression model migration process, and the existing perceptual loss network methods are not suitable for sequential language input and cannot effectively improve the accuracy and performance of student models.
A perceptual loss network with a multi-layer sequence transformer structure is used to calculate the perceptual loss of the sentence vector through the training sentence and the cascaded teacher model and perceptual loss network, and adjust the student model parameters according to the loss to improve the accuracy and performance of the student model. .
While compressing the natural language understanding model, it improves the student model's learning of the teacher model knowledge, improves the accuracy and performance of the model, and adapts to serialized natural language understanding tasks.
Smart Images

Figure CN114490922B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a natural language understanding model training method and device. Background Art
[0002] Artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a branch of computer science that attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Artificial intelligence is also the study of the design principles and implementation methods of various intelligent machines, so that machines have the functions of perception, reasoning and decision-making. Research in the field of artificial intelligence includes robots, natural language understanding, computer vision, decision-making and reasoning, human-computer interaction, recommendation and search, basic AI theory, etc.
[0003] At present, in the field of natural language understanding, mainstream deep learning models that meet real-time requirements are all compressed fine-tuned models based on pre-trained models. This training process can be simply divided into three steps: 1. Load the pre-trained natural language understanding model and obtain a teacher model with a large number of parameters by fine-tuning the specified task training data; 2. Through methods such as knowledge distillation, transfer the knowledge learned by the teacher model to a student model with a small number of parameters; 3. Fine-tune the parameters of the student model by specifying task training data. At present, the main bottleneck of this training method is how to balance the relationship between the number of parameters and performance, that is, how to maintain an acceptable high accuracy on the smallest possible model, and how to make the student model learn as much knowledge of the teacher model as possible.
[0004] In the field of computer vision, deep learning models also face the above problems in order to meet the requirements of real-time performance. In response to these problems, some researchers have proposed using perceptual loss to improve the effect of knowledge distillation. Specifically, in the process of knowledge distillation, the output images of the teacher model and the student model are respectively input into a pre-trained network. This network is usually pre-trained on a large amount of image data and can capture the semantic features of the image. Subsequently, the perceptual loss is calculated between the two output results of this network to represent the semantic similarity between the teacher model and the student model under the perceptual network. However, when these methods are applied to the field of natural language understanding, there are the following problems: 1. The currently proposed perceptual loss networks are all based on convolutional neural networks (CNNs), and the inputs are all two-dimensional images, not natural language. The input and output of natural language understanding problems usually have sequential sentences, so the CNN structure is not applicable; 2. The input of the current perceptual loss network is the same as the input of the original network, that is, the input of the teacher network and the student network are both images, and the input of the perceptual loss network is also an image, and the value range of each pixel value is continuous. However, in the field of natural language understanding, the inputs of the teacher network and the student network are sentences composed of words, and the input of the perceptual loss network is sentence vectors. If the sentence vectors are converted into sentences, the value range will become a discontinuous space. Therefore, the current methods are not suitable for problems in this field.
[0005] Therefore, a training method suitable for natural language understanding models is needed so that the student model can learn as much knowledge as possible from the teacher model and achieve higher accuracy. Summary of the invention
[0006] The embodiments of the present application provide a natural language understanding model training method and device, which are used to improve the accuracy and performance of the model (student natural language understanding model) as much as possible while compressing the natural language understanding model (i.e., transferring the knowledge of the teacher's natural language understanding model to the student's natural language understanding model).
[0007] In a first aspect, an embodiment of the present application provides a natural language understanding model training method, comprising: training the perceptual loss network through training sentences and a cascaded teacher natural language understanding model and a perceptual loss network, wherein the input of the teacher natural language understanding model is the training sentence, and the output is a first sentence vector obtained by processing the training sentence, the input of the perceptual loss model is the first sentence vector, and the output is a second sentence vector obtained by processing the first sentence vector, the perceptual loss network is based on a first loss adjustment parameter of an understanding result mapped by the second sentence vector relative to the true value of the understanding result corresponding to the training sentence, and the perceptual loss network adopts a multi-layer sequence transformation transformer structure; the training sentence is input into the cascaded teacher natural language understanding model and the trained perceptual loss network for processing to obtain a third sentence vector, and the training sentence is input into the cascaded student natural language understanding model and the trained perceptual loss network for processing to obtain a fourth sentence vector; the perceptual loss of the fourth sentence vector relative to the third sentence vector is calculated; the parameters of the student natural language understanding model are adjusted according to the perceptual loss to obtain a trained student natural language understanding model.
[0008] By adopting the above method, when compressing the natural language understanding model, that is, when transferring the knowledge of the teacher's natural language understanding model to the student's natural language understanding model, the perceptual loss is introduced, which improves the degree to which the student's natural language understanding model learns the knowledge of the teacher's natural language understanding model, and improves the accuracy and performance of the student's natural language understanding model. At the same time, the structure of the perceptual loss network is changed from multi-layer CNN to multi-layer Transformer, which is more suitable for serialized natural language understanding tasks, further improving the accuracy and performance of the student's natural language understanding model.
[0009] In one possible design, the method also includes: inputting the training sentence into the teacher natural language understanding model for processing to obtain a fifth sentence vector; calculating a second loss of the understanding result mapped by the fifth sentence vector relative to the true value of the understanding result corresponding to the training sentence; and adjusting the parameters of the teacher natural language understanding model according to the second loss.
[0010] In the above design, the perceptual loss network can be trained while training or fine-tuning the teacher's natural language understanding model, which is beneficial to improving the efficiency of model training.
[0011] In one possible design, the method also includes: inputting the training sentence into the teacher natural language understanding model and the student natural language understanding model, obtaining a first feature of the hidden layer output of the teacher natural language understanding model and a second feature of the hidden layer output of the student natural language understanding model; calculating a third loss of the second feature relative to the first feature; and adjusting the parameters of the student natural language understanding model according to the third loss.
[0012] In the above design, by allowing the student's natural language comprehension model to output the hidden layer and learn the teacher's natural language comprehension model's hidden layer output, the student's natural language comprehension model can learn the knowledge of the teacher's natural language comprehension model at multiple scales, which is conducive to improving the accuracy and performance of the student's natural language comprehension model.
[0013] In a possible design, the calculating the perceptual loss of the fourth sentence vector relative to the third sentence vector includes: calculating the perceptual loss of an understanding result of the fourth sentence vector mapping relative to an understanding result of the third sentence vector mapping.
[0014] In the above design, the perceptual loss can be calculated from multiple scales to update the student's natural language understanding model, which is conducive to further ensuring the accuracy and performance of the student's natural language understanding model.
[0015] In a possible design, the understanding result includes the intention of the training sentence and key information of the intention.
[0016] In one possible design, the number of layers and / or parameters of the teacher's natural language understanding model are greater than those of the student's natural language understanding model.
[0017] In a second aspect, an embodiment of the present application provides a natural language understanding model training device, which has the function of implementing the above-mentioned first aspect or any possible design method of the first aspect. The function can be implemented by hardware, or the corresponding software can be implemented by hardware. The hardware or software includes one or more units (or modules) corresponding to the above-mentioned functions. For example, it includes a first training unit and a second training unit.
[0018] In one possible design, the device may be a chip or an integrated circuit.
[0019] In one possible design, the device includes a memory and a processor, the memory is used to store a program executed by the processor, and when the program is executed by the processor, the device can execute the method described in the above-mentioned first aspect or any possible design of the first aspect.
[0020] In one possible design, the device may be an electronic device.
[0021] In a third aspect, the present application provides a computer-readable storage medium, which stores a computer program or instructions. When the computer program or instructions are executed, the method described in the first aspect or any possible design of the first aspect can be implemented.
[0022] In a fourth aspect, the present application also provides a computer program product, including a computer program or instructions, which, when executed, can implement the method described in the above-mentioned first aspect or any possible design of the first aspect.
[0023] In a fifth aspect, an embodiment of the present application provides a chip, which is used to execute a computer program or instruction stored in a memory to implement a method as described in the first aspect or any possible design of the first aspect.
[0024] The technical effects that can be achieved in the second to fifth aspects mentioned above can refer to the technical effects that can be achieved in the first aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Figure 1 A schematic diagram of the network structure of knowledge distillation provided in an embodiment of the present application;
[0026] Figure 2 A schematic diagram of a perception loss network structure provided in an embodiment of the present application;
[0027] Figure 3 A schematic diagram of the system architecture provided for an embodiment of the present application;
[0028] Figure 4 A schematic diagram of a training sentence collection method provided in an embodiment of the present application;
[0029] Figure 5 A schematic diagram of the implementation of the training device provided in the embodiment of the present application;
[0030] Figure 6 A process diagram of a natural language understanding model training method provided in an embodiment of the present application;
[0031] Figure 7 A schematic diagram of a method for fine-tuning a teacher's natural language understanding model provided in an embodiment of the present application;
[0032] Figure 8 A schematic diagram of a method for training a perceptual loss network provided in an embodiment of the present application;
[0033] Fig. 9 A schematic diagram of a method for training a student natural language understanding model provided in an embodiment of the present application;
[0034] Fig.10A schematic diagram of the structure of a natural language understanding model training device provided in an embodiment of the present application;
[0035] Fig.11 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0036] At present, with the continuous development of artificial intelligence technology, the interaction between humans and machines through natural language is becoming more and more important. For humans and machines to interact through natural language, machines need to be able to understand the specific meaning of human natural language. This behavior of identifying the specific meaning of human natural language is called natural language understanding (NLU). NLU usually refers to identifying the user's intention and extracting key information about the user's intention. The machine's understanding of natural language mainly relies on the natural language understanding model. Therefore, how to train a natural language understanding model with few parameters and high precision is crucial to meet the real-time and accuracy requirements of human-computer interaction.
[0037] To facilitate understanding by those skilled in the art, some terms used in the embodiments of the present application are explained below.
[0038] 1) The intent of the sentence and the key information of the intent, where the intent refers to the purpose that the user wants to express through the sentence. For example, the user inputs the sentence "Plan a route to Beijing", and the user's intention is navigation; the user inputs the sentence "I want to listen to my dream", and the user's intention is to listen to music. The key information of the intent can also be understood as the slot corresponding to the intent. For example, when the user's intention is to navigate, the destination is the slot; when the user's intention is to listen to music, the song title is the slot. For the sentence "Plan a route to Beijing" entered by the user with the intention of navigation, the key information (or slot) of the intent is the destination: Beijing.
[0039] 2) Knowledge distillation. Knowledge distillation is widely used in model compression and transfer learning. The general approach is to first train a teacher model with a large number of parameters using training data and the labels of the training data (also known as the true value of the annotation). Then, use the output of the teacher model for the training data to train a student model with a small number of parameters. That is, the probability vector output by the large model (teacher model) for the training data is used as a soft label to let the output of the small model (student model) learn as much as possible. Through knowledge distillation, the model can be converted from a large model into a compressed small model, and the performance can be kept as close to that of the large model as possible. The knowledge learned by multiple models can also be transferred to one model, so that the performance of a single model is close to the results of integrated learning of multiple models.
[0040] Take the teacher model and the student model for intent recognition (or intent classification) as an example. Assume that there are 10,000 training data and 3 types of intent can be recognized. Among them, the label of training data 1 is [0 0 1], which means that training data 1 is intent Figure 3 The probability is 0, Figure 2 The probability is 0, Figure 1 The probability of training data 2 is 1; the label of training data 2 is [0 1 0], which means that training data 2 is Figure 3 The probability is 0, Figure 2 The probability is 1, Figure 1 The probability of training data 10000 is 0; ... The label of training data 10000 is [1 00], which means that training data 10000 is Figure 3 The probability is 1, Figure 2 The probability is 0, Figure 1 The probability of 0 is 0. The above 10,000 training data are input into the teacher model respectively, and the loss (also called error or gradient information) is calculated based on the difference between the output of the teacher model and the label of the training data. The parameters of the teacher model are continuously adjusted according to the loss, and the teacher model is trained. The output of the trained teacher model for each training data can be used as a soft label for the student model training. For example: the output of the teacher model for training data 1 is [0 0.1 0.9], which means that training data 1 is Figure 3 The probability is 0, Figure 2 The probability is 0.1, which is Figure 1 The probability of 0.9 is 0.9. The above 10,000 training data are input into the student model respectively, and the loss is calculated according to the difference between the output of the student model and the soft label of the training data. The parameters of the student model are continuously adjusted according to the loss, and the student model is trained to complete the learning of the teacher model by the student model, that is, to complete the transfer of the knowledge learned by the teacher model to the student model, and the student model can retain the performance as close as possible to the teacher model.
[0041] Later, some methods also tried to make the hidden layer output of the student model learn the hidden layer output of the teacher model, so as to perform knowledge distillation at multiple scales. Figure 1As shown in the figure, a typical network structure of knowledge distillation is shown. Loss function 1 (loss1) represents the loss function of calculating the output of the teacher model and the output of the student model, and loss2 represents the loss function of calculating the hidden layer output of the teacher model and the hidden layer output of the student model. These two loss functions can appear at the same time, or only one of them can be selected. In a typical natural language understanding model (or network) based on knowledge distillation, the input is usually a text, the teacher model is a network that has been pre-trained on a large amount of text data, and the student model is similar to the teacher model structure, but it has been compressed to reduce the number of parameters and / or layers. Loss1 is usually the loss of the teacher model and the student model on a specified task (such as a voice assistant task), and loss2 is the similarity loss between the feature representations of the same input text at different levels.
[0042] It is important to understand that the above Figure 1 The input of loss1 is the direct output of the teacher model and the student model, which cannot reflect the semantic differences in the specified task (such as the voice assistant task).
[0043] 3) Perceptual loss. Perceptual loss was first proposed and applied to the image super-resolution task in the field of computer vision. In this task, if the model only uses pixel loss as the optimization object, although a higher evaluation index can be obtained during testing, this pixel-by-pixel optimization method ignores the global similarity of the image, and the reconstructed image has poor visual effect. In order to solve this problem, perceptual loss was proposed to minimize the difference between high-resolution images and real high-definition images at the image semantic level. Later, this method was extended to generative adversarial networks and knowledge distillation. A pre-trained perceptual loss network can be used to calculate the perceptual loss between generated images and real images, or between teacher models and student models. These methods generally use a pre-trained 16-layer visual geometry group network (VGG-16) as a feature extractor for both to describe the feature distance at the semantic level.
[0044] like Figure 2As shown, a VGG-16 network can be pre-trained using data from the ImageNet database, for example. The output of each hidden layer in this network is the semantic features of the corresponding image at different scales. Then, during the training of the student model, the pre-trained VGG-16 network is loaded, and the parameters of the VGG-16 network are fixed. The outputs of the teacher model and the student model are then input into the pre-trained VGG-16 network, respectively, and the outputs of different hidden layers are taken out as the semantic features corresponding to the two images, thereby calculating the perceptual loss between them through the loss function (pre_loss). According to the perceptual loss, the parameters of the student model are adjusted to obtain better performance.
[0045] However, existing methods related to perceptual loss are all applied to tasks in the field of computer vision, so the pre-trained networks used to calculate perceptual features are all based on CNN structures, and their inputs are all images. These methods and network structures are not suitable for sequence labeling tasks such as natural language understanding.
[0046] This application aims to use a perceptual loss network to compress the natural language understanding model while (i.e., transfer the knowledge of the teacher's natural language understanding model to the student's natural language understanding model) and improve the accuracy and performance of the model (student natural language understanding model) on the specified task as much as possible. The following will describe the embodiments of this application in detail with reference to the accompanying drawings.
[0047] In addition, it should be understood that in the embodiments of the present application, at least one can also be described as one or more, and multiple can be two, three, four or more, which is not limited in the present application. In the embodiments of the present application, " / " can indicate that the objects associated before and after are in an "or" relationship, for example, A / B can indicate A or B; "and / or" can be used to describe that there are three relationships between the associated objects, for example, A and / or B can indicate: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. In order to facilitate the description of the technical solutions of the embodiments of the present application, in the embodiments of the present application, the words "first", "second" and the like can be used to distinguish between technical features with the same or similar functions. The words "first", "second" and the like do not limit the quantity and execution order, and the words "first", "second" and the like do not limit them to be necessarily different. In the embodiments of the present application, the words "exemplary" or "for example" are used to indicate examples, illustrations or descriptions, and any embodiment or design described as "exemplary" or "for example" should not be interpreted as being more preferred or more advantageous than other embodiments or design. The use of words such as “exemplary” or “for example” is intended to present the relevant concepts in a specific manner to facilitate understanding.
[0048] Reference Figure 3As shown, it is a schematic diagram of a system architecture provided in an embodiment of the present application, and the system architecture may include: a data acquisition device 310, a database 320, a training device 330, an execution device 340, etc.
[0049] The data collection device 310 is used to collect training sentences. After collecting the training sentences, the data collection device 310 can store these training sentences in the database 320.
[0050] Taking the voice assistant task as an example, for the collection of training sentences for the voice assistant task, such as Figure 4 As shown, the data acquisition device 310 can receive the voice of the user at a close distance in a quiet indoor environment, convert the voice of the user into sentences (text) as training sentences, and accept the user's annotations on the understanding results of the training sentences (such as intentions and key information of the intentions), and store the training sentences with the annotated understanding results in the database 320.
[0051] The training device 330 can use the training sentences maintained in the database 320 to adjust or train the teacher's natural language understanding model, and transfer the knowledge learned by the teacher's natural language understanding model to the student's natural language understanding model. It can also use the training sentences maintained in the database 320 to adjust or train the student's natural language understanding model to obtain a student's natural language understanding model that is specifically applied to a specified task.
[0052] It should be noted that in actual applications, the training sentences maintained in the database 320 may not all be collected by the data device, but may also be received from other devices; the training device 330 may not necessarily adjust or train the natural language understanding model entirely based on the training sentences maintained by the database 320. The embodiments of the present application only take the example of the data device collecting training sentences and the training device 330 adjusting or training the natural language understanding model based on the training sentences maintained by the database 320 for explanation.
[0053] The student natural language understanding model obtained by the training device 330 can be applied to different systems or devices, such as Figure 3 In the execution device 340.
[0054] like Figure 5As shown, the training device 330 can be a server or a virtual machine, etc., including one or more callable central processing units (CPU) and / or graphics processing units (GPU), which can be used for model training and calling, etc. The execution device 340 can be a terminal, such as a mobile phone, a tablet computer, a laptop computer, a vehicle terminal, etc., or a chip applied to the above devices, etc., and can also be a server or a cloud, etc.
[0055] It is worth noting that Figure 3 This is only a schematic diagram of a system architecture provided by an embodiment of the present application, and the positional relationship between the devices and components shown in the figure does not constitute any limitation. Figure 3 In the embodiment, a data storage system 350 may also be included, and the data storage system 350 is used to store data, codes, etc. output by the execution device 340. At this time, the data storage system 350 is an external memory relative to the execution device 340. In other cases, the data storage system 350 may also be placed inside the execution device 340.
[0056] like Figure 6 As shown, the training device executes the natural language understanding model training method, that is, the executor of the following process can be the above Figure 3 Training equipment in.
[0057] S601: The training device trains the perceptual loss network through training sentences and the cascaded teacher natural language understanding model and the perceptual loss network.
[0058] Among them, the input of the teacher's natural language understanding model is the training sentence, and the output is the first sentence vector obtained by processing the training sentence. The input of the perceptual loss model is the first sentence vector, and the output is the second sentence vector obtained by processing the first sentence vector. The perceptual loss network is based on the first loss adjustment parameter of the understanding result mapped by the second sentence vector relative to the true value of the understanding result corresponding to the training sentence.
[0059] In an embodiment of the present application, a pre-trained natural language understanding model with a large number of parameters can be directly used as the teacher's natural language understanding model, and the teacher's natural language understanding model can be fine-tuned according to the training sentences of the specified task in the database. Of course, the training device can also directly train a new natural language understanding model with a large number of parameters as the teacher's natural language understanding model according to the training sentences of the specified task maintained in the database. Among them, the process of training a new teacher's natural language understanding model and fine-tuning the teacher's natural language understanding model is similar to the training device. The following is an example of fine-tuning the teacher's natural language understanding model.
[0060] Take the voice assistant task as an example. Figure 7 As shown, the training device can input the training sentences for the voice assistant task maintained in the database into the teacher's natural language understanding model, and obtain the sentence vectors output by the teacher's natural language understanding model for processing the training sentences, wherein the sentence vectors can be composed of multiple word vectors obtained by the teacher's natural language understanding model for processing multiple words in the input training sentences, and the obtained sentence vectors are input into the downstream task network (here, the voice assistant task network corresponding to the voice assistant task), and the sentence vectors output by the teacher's natural language understanding model are mapped to the understanding results of the training sentences, such as mapping to the intention of the training sentences, etc. Among them, the downstream task network can be one layer, two layers, etc., which can be understood as the understanding result output layer, which is used to convert the sentence vectors obtained by the teacher's natural language understanding model into recognizable understanding results. Taking the understanding result as the intention as an example, the recognizable intentions are 3 categories, and the converted understanding result is the intention. Figure 1 ,meaning Figure 2 Harmony Figure 3 For example, [0 0.1 0.9] means that the training data is Figure 3 The probability is 0, Figure 2 The probability is 0.1, which is Figure 1 The probability is 0.9.
[0061] The training device calculates the loss of the understanding result output by the teacher's natural language understanding model relative to the true value of the understanding result of the training sentence (i.e., the labeled understanding result) through the task loss function (loss_task1). The loss can also be called gradient information. In the gradient feedback stage, the gradient information calculated by loss_task1 will be fed back to each layer of the teacher's natural language understanding model to update the parameters of each layer and complete the adjustment of the teacher's natural language understanding model. Optionally, the gradient information calculated by loss_task1 can also be fed back to each layer of the teacher's natural language understanding model and the downstream task network to update their parameters.
[0062] In a possible implementation, during the stage of fine-tuning the teacher's natural language understanding model, the training device can simultaneously train the perceptual loss network. In order to adapt to sequence labeling tasks such as natural language understanding, in an embodiment of the present application, the perceptual loss network can be stacked with a multi-layer sequence transformer structure to adapt to serialized natural language understanding tasks.
[0063] like Figure 8As shown, two identical loss functions loss_task1 and loss_task2 can be used in the stage of fine-tuning the teacher's natural language understanding model. After obtaining the sentence vector 1 (i.e., the first sentence vector) output by the teacher's natural language understanding model for processing the training sentence, the sentence vector 1 output by the teacher's natural language understanding model can be mapped to the understanding result 1 of the training sentence through the downstream task network 1, and then the loss of the understanding result 1 relative to the true value of the understanding result of the training sentence is calculated according to loss_task1. At the same time, the sentence vector 1 output by the teacher's natural language understanding model will be used as the input of the perceptual loss network. The perceptual loss network processes the sentence vector 1 output by the natural language understanding model to obtain sentence vector 2 (i.e., the second sentence vector). Through the downstream task network 2, the sentence vector 2 output by the perceptual loss network can be mapped to the understanding result 2 of the training sentence, and then the loss of the understanding result 2 relative to the true value of the understanding result of the training sentence is calculated according to loss_task2 (i.e., the first loss). In the gradient feedback stage, the gradient information (loss) calculated by loss_task1 will be passed back to each layer of the teacher's natural language understanding model to update the parameters of each layer. The gradient information calculated by loss_task2 will only be passed back to each layer of the perceptual loss network to update the parameters of each layer of the perceptual loss network, and will not be passed back to any layer of the teacher's natural language understanding model.
[0064] In the process of fine-tuning the teacher's natural language understanding model and training the perceptual loss network, for loss_task1 and loss_task2, a sequential training and updating strategy is adopted, that is, in each iteration, an inference is first performed, and the parameters of the teacher's natural language understanding model are updated through loss_task1, and then these parameters are fixed for an inference, and the parameters in the perceptual loss network are updated through loss_task2. With this strategy, the perceptual loss network can be trained while fine-tuning the teacher's natural language understanding model. In this way, unlike the perceptual loss layer in the field of computer vision, where the input is an image, in this network, the input of the perceptual loss layer can be a sentence vector expressed by the natural language understanding model. In addition, it should be understood that the structures of the downstream task network 1 and the downstream task network 2 are the same, but the parameters can be different.
[0065] S602: The training device inputs the training sentence into the cascaded teacher natural language understanding model and the trained perceptual loss network for processing to obtain a third sentence vector, and inputs the training sentence into the cascaded student natural language understanding model and the trained perceptual loss network for processing to obtain a fourth sentence vector.
[0066] S603: The training device calculates the perceptual loss of the fourth sentence vector relative to the third sentence vector.
[0067] S604: The training device adjusts the parameters of the student natural language understanding model according to the perceptual loss to obtain a trained student natural language understanding model.
[0068] like Fig. 9 As shown, in the knowledge distillation stage, the training device will load the fine-tuned teacher natural language understanding model and the trained perceptual loss network, and fix the parameters of their layers. Then, for the training sentences, the training device will input them into the teacher natural language understanding model and the student natural language understanding model respectively, and obtain the sentence vectors output by the teacher natural language understanding model and the student natural language understanding model respectively. Then, the sentence vectors output by the teacher natural language understanding model and the student natural language understanding model are respectively input into the perceptual loss network. According to the perceptual loss network, the sentence vector input to the teacher natural language understanding model is processed to obtain the difference between the sentence vector 3 (i.e., the third sentence vector) and the sentence vector input to the student natural language understanding model is processed to obtain the sentence vector 4 (i.e., the fourth sentence vector). The perceptual loss is calculated through the loss function (loss_pre). In the gradient feedback stage, the gradient information (perceptual loss) calculated by loss_pre will be fed back to each layer of the student natural language understanding model, and the parameters of each layer of the student natural language understanding model will be updated to train the student natural language understanding model.
[0069] In a possible implementation, the training device can also map the obtained sentence vector 3 to the understanding result 3 of the training sentence through the above-mentioned downstream task network 2, and map the obtained sentence vector 4 to the understanding result 4 of the training sentence. According to the difference between the understanding result 3 and the understanding result 4, the perceptual loss is calculated through the loss function (loss_pre) to adjust the parameters of the student's natural language understanding model and train the student's natural language understanding model.
[0070] In another possible implementation, the training device can also calculate the loss through the loss function (loss_pres) based on the characteristics of a hidden layer corresponding to the teacher's natural language understanding model and the student's natural language understanding model, adjust the parameters of the student's natural language understanding model, and train the student's natural language understanding model.
[0071] For the trained student natural language understanding model, the training device can also fine-tune the student natural language understanding model according to the training sentences of the specified task in the database. For example, the student natural language understanding model is fine-tuned according to the training sentences for the voice assistant task maintained in the database. The process of the training device fine-tuning the student natural language understanding model can refer to the process of the training device fine-tuning the teacher's natural language understanding model, and the repeated parts will not be repeated.
[0072] The natural language understanding model training method provided in this application can be applied to business scenarios such as cloud side and terminal side, such as mobile phone voice assistant, smart screen, smart speaker, etc. Taking the mobile phone voice assistant as an example, after the student natural language understanding model is obtained based on the training sentence training of the mobile phone voice assistant task, the obtained student natural language understanding model and the corresponding downstream task network (such as the above-mentioned downstream task network 1) are cascaded to obtain a natural language understanding model suitable for the voice assistant in the mobile phone. It is used to identify and execute the navigation, dialing and other intentions of the user's issued sentences.
[0073] As an example, when a user needs navigation service, he can wake up the mobile phone voice assistant application in the mobile phone through the wake-up word "Xiaoyi Xiaoyi". After waking up the mobile phone voice assistant application, the user can input the voice "Plan a route to Beijing". The mobile phone voice assistant converts the user's input voice into a text sentence "Plan a route to Beijing", and then inputs the sentence "Plan a route to Beijing" into the cascaded student natural language understanding model and downstream task network 1. The sentence "Plan a route to Beijing" is processed by the cascaded student natural language understanding model and downstream task network 1. The mobile phone voice assistant recognizes that the user's intention is navigation, and the key information (or slot) of the intention is the destination: Beijing. The mobile phone voice assistant opens the navigation application in the mobile phone for the user, and enters the destination: Beijing, and starts navigation to Beijing for the user.
[0074] The above mainly introduces the solution provided by the present application from the perspective of the method flow. It is understandable that in order to achieve the above functions, the device may include hardware structures and / or software modules corresponding to the execution of each function. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present application.
[0075] In the case of an integrated unit, Fig.10 A possible exemplary block diagram of a natural language understanding model training device involved in an embodiment of the present application is shown. The natural language understanding model training device 1000 may exist in the form of software. The natural language understanding model training device 1000 may include: a first training unit 1001 and a second training unit 1002.
[0076] The natural language understanding model training device 1000 can be the above Figure 6 The training device may be a semiconductor chip arranged in the execution device.
[0077] Specifically, in one embodiment, the first training unit 1001 is used to train the perceptual loss network through training sentences and the cascaded teacher natural language understanding model and the perceptual loss network, wherein the input of the teacher natural language understanding model is the training sentence, and the output is the first sentence vector obtained by processing the training sentence, the input of the perceptual loss model is the first sentence vector, and the output is the second sentence vector obtained by processing the first sentence vector, the perceptual loss network is based on the first loss adjustment parameter of the understanding result mapped by the second sentence vector relative to the true value of the understanding result corresponding to the training sentence, and the perceptual loss network adopts a multi-layer sequence transformation transformer structure;
[0078] The second training unit 1002 is used to input the training sentence into the cascaded teacher natural language understanding model and the trained perceptual loss network for processing to obtain a third sentence vector, and input the training sentence into the cascaded student natural language understanding model and the trained perceptual loss network for processing to obtain a fourth sentence vector; calculate the perceptual loss of the fourth sentence vector relative to the third sentence vector; and adjust the parameters of the student natural language understanding model according to the perceptual loss to obtain a trained student natural language understanding model.
[0079] In a possible design, the first training unit 1001 is also used to input the training sentence into the teacher natural language understanding model for processing to obtain a fifth sentence vector; calculate the second loss of the understanding result mapped by the fifth sentence vector relative to the true value of the understanding result corresponding to the training sentence; and adjust the parameters of the teacher natural language understanding model according to the second loss.
[0080] In one possible design, the second training unit 1002 is also used to input the training sentence into the teacher natural language understanding model and the student natural language understanding model, obtain the first feature of the hidden layer output of the teacher natural language understanding model and the second feature of the hidden layer output of the student natural language understanding model; calculate the third loss of the second feature relative to the first feature; and adjust the parameters of the student natural language understanding model according to the third loss.
[0081] In a possible design, when the second training unit 1002 calculates the perceptual loss of the fourth sentence vector relative to the third sentence vector, it is specifically used to calculate the perceptual loss of the understanding result of the fourth sentence vector mapping relative to the understanding result of the third sentence vector mapping.
[0082] In a possible design, the understanding result includes the intention of the training sentence and key information of the intention.
[0083] In one possible design, the number of layers and / or parameters of the teacher's natural language understanding model are greater than those of the student's natural language understanding model.
[0084] It should be understood that the division of units in the embodiments of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation. Each functional unit in the embodiments of the present application may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0085] Based on the above embodiments, the present application also provides an electronic device (such as a training device), referring to Fig.11 As shown, the electronic device 1100 includes a memory 1101 and a processor 1102. The memory 1101 and the processor 1102 are connected via a bus. The memory 1101 is used to store computer-executable instructions. When the electronic device 1100 is running, the processor 1102 executes the computer-executable instructions stored in the memory 1101 so that the electronic device 1100 implements any of the above-mentioned natural language understanding model training methods. The specific natural language understanding model training method can refer to the relevant description above and its accompanying drawings, which will not be repeated here.
[0086] As another form of this embodiment, a computer-readable storage medium is provided, on which instructions are stored, and when the instructions are executed, the natural language understanding model training method applicable to the training device in the above method embodiment can be executed.
[0087] As another form of this embodiment, a computer program product containing instructions is provided. The computer program product includes instructions, and when the instructions are executed, the natural language understanding model training method applicable to the training device in the above method embodiment can be executed.
[0088] As another form of this embodiment, a chip is provided. When the chip is running, it can execute the natural language understanding model training method applicable to the training device in the above method embodiment.
[0089] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0090] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes 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, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0091] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0092] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0093] Although the preferred embodiments of the present application have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.
[0094] Obviously, those skilled in the art can make various changes and modifications to the embodiments of the present application without departing from the spirit and scope of the embodiments of the present application. Thus, if these modifications and variations of the embodiments of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A natural language understanding model training method, It is characterized in that include: The perceptual loss network is trained by training sentences and the cascaded teacher natural language understanding model and perceptual loss network, wherein the input of the teacher natural language understanding model is the training sentence and the output is the first sentence vector obtained by processing the training sentence, the input of the perceptual loss model is the first sentence vector and the output is the second sentence vector obtained by processing the first sentence vector, the perceptual loss network is based on the first loss adjustment parameter of the understanding result mapped by the second sentence vector relative to the true value of the understanding result corresponding to the training sentence, and the perceptual loss network adopts a multi-layer sequence transformation transformer structure; Input the training sentence into the cascaded teacher natural language understanding model and the trained perceptual loss network for processing to obtain a third sentence vector, and input the training sentence into the cascaded student natural language understanding model and the trained perceptual loss network for processing to obtain a fourth sentence vector; Calculating the perceptual loss of the fourth sentence vector relative to the third sentence vector; The parameters of the student natural language understanding model are adjusted according to the perceptual loss to obtain a trained student natural language understanding model.
2. The method according to claim 1, It is characterized in that The method further comprises: Inputting the training sentence into the teacher natural language understanding model for processing to obtain a fifth sentence vector; Calculating a second loss of the understanding result of the fifth sentence vector mapping relative to the true value of the understanding result corresponding to the training sentence; Adjust parameters of the teacher natural language understanding model according to the second loss.
3. The method according to claim 1, It is characterized in that The method further comprises: Input the training sentence into the teacher natural language understanding model and the student natural language understanding model, and obtain a first feature of the hidden layer output of the teacher natural language understanding model and a second feature of the hidden layer output of the student natural language understanding model; calculating a third loss of the second feature relative to the first feature; Parameters of the student natural language understanding model are adjusted according to the third loss.
4. The method according to claim 1, It is characterized in that The calculating the perceptual loss of the fourth sentence vector relative to the third sentence vector includes: Calculate the perceptual loss of the understanding result of the fourth sentence vector mapping relative to the understanding result of the third sentence vector mapping.
5. The method according to any one of claims 1 to 4, It is characterized in that The understanding result includes the intention of the training sentence and key information of the intention.
6. The method according to any one of claims 1 to 4, It is characterized in that The number of layers and / or parameters of the teacher's natural language understanding model are greater than those of the student's natural language understanding model.
7. A natural language understanding model training device, It is characterized in that include: A first training unit is used to train the perceptual loss network through training sentences and a cascaded teacher natural language understanding model and a perceptual loss network, wherein the input of the teacher natural language understanding model is the training sentence and the output is a first sentence vector obtained by processing the training sentence, the input of the perceptual loss model is the first sentence vector and the output is a second sentence vector obtained by processing the first sentence vector, the perceptual loss network is based on a first loss adjustment parameter of an understanding result mapped based on the second sentence vector relative to a true value of an understanding result corresponding to the training sentence, and the perceptual loss network adopts a multi-layer sequence transformation transformer structure; The second training unit is used to input the training sentence into the cascaded teacher natural language understanding model and the trained perceptual loss network for processing to obtain a third sentence vector, and input the training sentence into the cascaded student natural language understanding model and the trained perceptual loss network for processing to obtain a fourth sentence vector; calculate the perceptual loss of the fourth sentence vector relative to the third sentence vector; and adjust the parameters of the student natural language understanding model according to the perceptual loss to obtain a trained student natural language understanding model.
8. The device according to claim 7, It is characterized in that The first training unit is further used to input the training sentence into the teacher natural language understanding model for processing to obtain a fifth sentence vector; calculate a second loss of the understanding result mapped by the fifth sentence vector relative to the true value of the understanding result corresponding to the training sentence; And adjusting parameters of the teacher natural language understanding model according to the second loss.
9. The device according to claim 7, It is characterized in that The second training unit is also used to input the training sentence into the teacher natural language understanding model and the student natural language understanding model, obtain the first feature of the hidden layer output of the teacher natural language understanding model and the second feature of the hidden layer output of the student natural language understanding model; calculate the third loss of the second feature relative to the first feature; and adjust the parameters of the student natural language understanding model according to the third loss.
10. The device according to claim 7, It is characterized in that When the second training unit calculates the perceptual loss of the fourth sentence vector relative to the third sentence vector, it is specifically used to calculate the perceptual loss of the understanding result of the fourth sentence vector mapping relative to the understanding result of the third sentence vector mapping.
11. The device according to any one of claims 7 to 10, It is characterized in that The understanding result includes the intention of the training sentence and key information of the intention.
12. The device according to any one of claims 7 to 10, It is characterized in that The number of layers and / or parameters of the teacher's natural language understanding model are greater than those of the student's natural language understanding model.
13. An electronic device, It is characterized in that including a processor and a memory; The memory stores a computer program; The processor is configured to call the computer program stored in the memory to execute the method according to any one of claims 1 to 6.
14. A computer storage medium, It is characterized in that The computer-readable storage medium includes a computer program or an instruction. When the computer program or the instruction is executed on an electronic device, the electronic device executes the method according to any one of claims 1 to 6.
15. A chip, It is characterized in that The chip is used to execute a computer program or instruction stored in a memory to implement the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Natural language processing model training method, task execution method, equipment and system
CN111079406A
Training method and training device of style migration model, and video style migration method and device
CN111667399A
