Model training method and device, electronic device and computer-readable storage medium

By optimizing the gradient update process in model training and using the target weight to optimize and update the gradient, the problem of long model training time is solved, training efficiency and accuracy are improved, and it is especially suitable for large-scale models.

CN117725979BActive Publication Date: 2024-09-20XINGIN INFORMATION TECH (SHANGHAI) CO LTD
View PDF 8 Cites 0 Cited by

Patent Information

Application Number
CN202311266738.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-09-27
Publication Date
2024-09-20
Estimated Expiration
2043-09-27

AI Technical Summary

Technical Problem

Existing model training methods take a long time, resulting in low training efficiency. How to shorten the training time and improve training efficiency is of great significance.

Method used

By obtaining training data, the target gradient of the model to be trained is determined, and the gradient is optimized and updated based on the preset target weight, and the model parameters are updated to accelerate the model training process.

Benefits of technology

By optimizing the gradient update process, the model training time is significantly shortened, the model training efficiency and the accuracy of the output results are improved, especially suitable for large-scale models.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117725979B
    Figure CN117725979B
Patent Text Reader

Abstract

The present application discloses a model training method and device, an electronic device and a computer-readable storage medium. The method includes: obtaining training data, the training data is used to update the parameters of the model to be trained; processing the training data by the model to be trained to determine the target gradient of the first layer of the model to be trained; obtaining the update gradient of the first layer based on the preset target weight and the target gradient, the target weight characterizing the degree of improvement of the accuracy of the result output of the model to be trained by the output of the first layer; in the process of updating the parameters of the model to be trained based on the training data, updating the parameters of the first layer based on the update gradient to obtain the target model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a model training method and device, an electronic device, and a computer-readable storage medium. Background Art

[0002] By training the model, the model can be equipped with the ability to process data. In order to improve the training effect, the model usually needs to be fully trained, but sufficient training takes a long time, which leads to long training time and low training efficiency. Therefore, how to shorten the training time and improve the training efficiency is of great significance. Summary of the invention

[0003] The present application provides a model training method and device, an electronic device, and a computer-readable storage medium.

[0004] In a first aspect, a model training method is provided, the method comprising:

[0005] Acquire training data, where the training data is used to update parameters of the model to be trained;

[0006] Processing the training data by the model to be trained to determine the target gradient of the first layer of the model to be trained;

[0007] Based on a preset target weight and the target gradient, an update gradient of the first layer is obtained, wherein the target weight represents the degree to which the output of the first layer improves the accuracy of the result output by the model to be trained;

[0008] In the process of updating the parameters of the model to be trained based on the training data, the parameters of the first layer are updated based on the updated gradient to obtain a target model.

[0009] In combination with any implementation manner of the present application, in the process of updating the parameters of the model to be trained based on the training data, updating the parameters of the first layer based on the updated gradient to obtain the target model includes:

[0010] In the process of updating the parameters of the model to be trained based on the training data, the parameters of the first layer and the target weight are updated based on the updated gradient to obtain a target model.

[0011] In combination with any embodiment of the present application, the model to be trained includes a second layer, and the output of the second layer is the result output by the model to be trained;

[0012] The step of processing the training data by using the model to be trained to determine the target gradient of the first layer includes:

[0013] The training data is processed by the model to be trained, the first layer outputs a first result, and the second layer outputs a second result;

[0014] splicing the first result and the second result to obtain a splicing result;

[0015] The target gradient is determined based on a difference between the concatenation result and the label of the training data.

[0016] In combination with any implementation manner of the present application, the step of splicing the first result and the second result to obtain a spliced ​​result includes:

[0017] Concatenate the first result and the second result to obtain an intermediate result;

[0018] The product of the intermediate result and the target weight is determined as the splicing result.

[0019] In combination with any implementation manner of the present application, the step of concatenating the first result and the second result to obtain an intermediate result includes:

[0020] Encoding the first result to obtain an encoded first result, wherein a dimension of the encoded first result is the same as a dimension of the second result;

[0021] The encoded first result and the second result are concatenated to obtain the intermediate result.

[0022] In combination with any embodiment of the present application, the determining the target gradient based on the difference between the splicing result and the label of the training data includes:

[0023] Determine the loss of the first layer based on the difference between the concatenation result and the label of the training data;

[0024] The target gradient is determined based on the loss of the first layer.

[0025] In combination with any implementation manner of the present application, determining the target gradient based on the loss of the first layer includes:

[0026] The target gradient is obtained by calculating the partial derivative of the loss of the first layer and the parameters in the first layer

[0027] In combination with any implementation manner of the present application, obtaining the update gradient of the first layer based on the preset target weight and target gradient includes:

[0028] The product of the target weight and the target gradient is determined as the update gradient.

[0029] In combination with any implementation manner of the present application, the training data is training text including a mask, and the result output by the model to be trained includes a prediction result of the mask.

[0030] In a second aspect, a model training device is provided, the device comprising:

[0031] An acquisition unit, used to acquire training data, wherein the training data is used to update the parameters of the model to be trained;

[0032] A determination unit, configured to process the training data through the model to be trained to determine a target gradient of a first layer of the model to be trained;

[0033] A processing unit, configured to obtain an update gradient of the first layer based on a preset target weight and the target gradient, wherein the target weight represents a degree of improvement of the accuracy of a result output by the output of the first layer on the output of the model to be trained;

[0034] An updating unit is used to update the parameters of the first layer based on the update gradient in the process of updating the parameters of the model to be trained based on the training data to obtain a target model.

[0035] In combination with any implementation manner of the present application, the updating unit is used to:

[0036] In the process of updating the parameters of the model to be trained based on the training data, the parameters of the first layer and the target weight are updated based on the updated gradient to obtain a target model.

[0037] In combination with any embodiment of the present application, the model to be trained includes a second layer, and the output of the second layer is the result output by the model to be trained;

[0038] The determining unit is used for:

[0039] The training data is processed by the model to be trained, the first layer outputs a first result, and the second layer outputs a second result;

[0040] splicing the first result and the second result to obtain a splicing result;

[0041] The target gradient is determined based on a difference between the concatenation result and the label of the training data.

[0042] In combination with any implementation manner of the present application, the determining unit is used to:

[0043] Concatenate the first result and the second result to obtain an intermediate result;

[0044] The product of the intermediate result and the target weight is determined as the splicing result.

[0045] In combination with any implementation manner of the present application, the determining unit is used to:

[0046] Encoding the first result to obtain an encoded first result, wherein a dimension of the encoded first result is the same as a dimension of the second result;

[0047] The encoded first result and the second result are concatenated to obtain the intermediate result.

[0048] In combination with any implementation manner of the present application, the determining unit is used to:

[0049] Determine the loss of the first layer based on the difference between the concatenation result and the label of the training data;

[0050] The target gradient is determined based on the loss of the first layer.

[0051] In combination with any implementation manner of the present application, the determining unit is used to:

[0052] The target gradient is obtained by calculating the partial derivative of the loss of the first layer and the parameters in the first layer.

[0053] In combination with any embodiment of the present application, the processing unit is used to:

[0054] The product of the target weight and the target gradient is determined as the update gradient.

[0055] In combination with any implementation manner of the present application, the training data is training text including a mask, and the result output by the model to be trained includes a prediction result of the mask.

[0056] In a third aspect, an electronic device is provided, comprising: a processor and a memory, the memory being used to store computer program code, the computer program code comprising computer instructions, and when the processor executes the computer instructions, the electronic device executes the method as described in the first aspect above and any possible implementation thereof.

[0057] In a fourth aspect, another electronic device is provided, comprising: a processor, a sending device, an input device, an output device and a memory, wherein the memory is used to store computer program code, and the computer program code includes computer instructions. When the processor executes the computer instructions, the electronic device executes the first aspect and any one of its embodiments.

[0058] In a fifth aspect, a computer-readable storage medium is provided, in which a computer program is stored. The computer program includes program instructions. When the program instructions are executed by a processor, the processor is caused to execute the first aspect and any one of its embodiments.

[0059] In a sixth aspect, a computer program product is provided, wherein the computer program product comprises a computer program or instructions, and when the computer program or instructions are run on a computer, the computer is enabled to execute the above-mentioned first aspect and any embodiment thereof.

[0060] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application.

[0061] In the present application, after acquiring the training data, the model training device uses the model to be trained to process the training data to determine the target gradient of the first layer in the model to be trained. Since the preset target weight of the first layer represents the degree of improvement of the accuracy of the output of the first layer to the output of the model to be trained, the model training device optimizes the target gradient based on the target weight to obtain the updated gradient of the first layer, and then in the process of updating the parameters of the model to be trained, the parameters of the first layer are updated based on the updated gradient to obtain the target model, which can enable the model to be trained to complete the training faster and improve the accuracy of the results output by the target model, thereby improving the training efficiency and training effect of the model to be trained.

[0062] Since the embodiment of the present application can optimize the gradient of each layer in the model to be trained, the optimization direction of updating the parameters of each layer based on the gradient of each layer can be made more accurate, and thus the time consumed for updating the parameters of each layer based on the gradient of each layer can be shortened, thereby shortening the time consumed for the model to be trained to converge. Specifically, the model to be trained is trained based on the method of the embodiment of the present application, and the amount of time consumed for the convergence of the model to be trained is shortened by the sum of the time consumed by the parameters of each layer. Large-scale models have many layers, or large-scale models have many parameters. Therefore, in the case of a large-scale model, the time consumed for the convergence of the model to be trained can be significantly shortened, thereby improving training efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0063] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the background technology, the drawings required for use in the embodiments of the present application or the background technology will be described below.

[0064] The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present application and are used together with the specification to illustrate the technical solution of the present application.

[0065] Figure 1A flowchart of a model training method provided in an embodiment of the present application;

[0066] Figure 2 A schematic diagram of the structure of a model to be trained provided in an embodiment of the present application;

[0067] Figure 3 A schematic diagram of the structure of a model training device provided in an embodiment of the present application;

[0068] Figure 4 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0069] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0070] The terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices.

[0071] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0072] By training the model, the model can learn the ability to perform tasks, and then the model can be used to perform tasks. For example, the task is to determine the content corresponding to the mask in the document, or to determine the relevance between documents, or to determine the relevance between search terms and documents, or to classify images. The ability of the model to perform tasks depends on the training effect of the model. In other words, if the training effect of the model is good, the trained model will have a strong ability to perform tasks.

[0073] In order to improve the training effect, it is usually necessary to fully train the model, but sufficient training takes a long time, which leads to long training time and low training efficiency. Therefore, how to shorten the training time and improve the training efficiency is of great significance.

[0074] The execution subject of the embodiment of the present application is a model training device, wherein the model training device can be any electronic device that can execute the technical solution disclosed in the embodiment of the method of the present application. Optionally, the model training device can be one of the following: a computer, a server.

[0075] It should be understood that the method embodiment of the present application can also be implemented by a processor executing a computer program code. The following describes the embodiment of the present application in conjunction with the drawings in the embodiment of the present application. Figure 1 , Figure 1 It is a flowchart of a model training method provided in an embodiment of the present application.

[0076] 101. Obtain training data.

[0077] In an embodiment of the present application, the training data is data used to train the model to be trained. In one possible implementation, the model to be trained is a large-scale model, wherein the large-scale model satisfies at least one of the following conditions: the number of parameters exceeds the parameter threshold, and the number of modules exceeds the module threshold. For example, if the parameter threshold is 1 million, then the model with the number of parameters exceeding 1 million is a large-scale model. For another example, if the module threshold is 10,000, then the model with the number of modules exceeding 10,000 is a large-scale model. For another example, if the parameter threshold is 1 million and the module threshold is 10,000, then when the number of parameters of the model exceeds 1 million and the number of models exceeds 10,000, the model is a large-scale model.

[0078] The module includes layers and neurons in a neural network. For example, the neural network includes a convolution layer, a pooling layer, a normalization layer, a linearization layer, a fully connected layer, and an activation layer. Then, when the total number of convolution layers, pooling layers, normalization layers, linearization layers, fully connected layers, and activation layers exceeds 10,000, the neural network is a large-scale model. For another example, the neural network includes neurons. Then, when the total number of neurons exceeds 10,000, the neural network is a large-scale model. Optionally, the model to be trained is one of the following: a chat generative pre-trained transformer (ChatGPT), a residual network (ResNet), a graph convolutional neural network (graph convolutional network, GCN), a graph neural network (graphneural networks, GNN), a large language model (large language model, LLM), a sentence to sentence model (sequence to sequence, seq2seq), a recurrent neural network (recurrent neural network, RNN), and a generative adversarial network (generative adversarial nets, GAN).

[0079] In one possible implementation, when the model to be trained is a text model, the training data includes text data with labels. For example, when the task to be performed by the model to be trained includes predicting whether a user is interested in a document, the training data includes documents with labels, wherein the labels include whether the user is interested in the document or not interested in it.

[0080] In another possible implementation, when the model to be trained is an image model, the training data includes image data with labels. For example, when the task to be trained includes classifying images, the training data includes images with labels, wherein the labels include the categories of the images.

[0081] In another possible implementation, when the model to be trained is an audio model, the training data includes audio data with labels. For example, when the task to be trained includes classifying audio, the training data includes audio with labels, wherein the labels include the categories of the audio.

[0082] In one implementation of acquiring training data, a model training device receives training data input by a user through an input component to acquire training data. The input component includes: a keyboard, a mouse, a touch screen, a touch pad, and an audio input device.

[0083] In another implementation of obtaining training data, the model training device receives training data sent by the terminal to obtain the training data. Optionally, the terminal can be any of the following: a mobile phone, a computer, a tablet computer, a server, and a wearable device.

[0084] 102. Process the training data by using the model to be trained to determine a target gradient of a first layer of the model to be trained.

[0085] In the embodiment of the present application, the model to be trained can be any model that needs to be trained. In one possible implementation, the model to be trained is a text model. In another possible implementation, the model to be trained is an image model. In yet another possible implementation, the model to be trained is an audio model.

[0086] In an embodiment of the present application, the model to be trained includes a first layer, wherein the first layer is a model structure in the model to be trained. In one possible implementation, the model to be trained is a neural network, and the first layer is a network layer (such as a convolutional layer) in the neural network. It should be understood that when the model to be trained includes at least one layer, the first layer is any layer in the model to be trained.

[0087] The training process of the model to be trained includes forward propagation and back propagation. The forward propagation can determine the output of the model to be trained. In the back propagation process, the gradient of each layer in the model to be trained can be obtained by reverse gradient calculation based on the output of the model to be trained and the label of the training data. The gradient of each layer is the basis for updating the parameters of each layer in the back propagation process. The target gradient is the gradient of the first layer in the back propagation process of the model to be trained.

[0088] In one possible implementation, when the model training device uses the training data to train the model to be trained, the model to be trained can obtain the output result of the model to be trained by processing the training data, and then the loss of the model to be trained can be determined based on the output result of the model to be trained and the label of the training data, and then the gradient of the first layer (that is, the target gradient) can be determined based on the loss.

[0089] 103. Based on the preset target weight and the target gradient, an update gradient of the first layer is obtained.

[0090] In the embodiment of the present application, the target weight is pre-set. The target weight represents the degree to which the output of the first layer improves the accuracy of the output of the training model. Specifically, the larger the target weight, the greater the improvement of the accuracy of the output of the first layer to the output of the training model. In other words, the first layer is more important in the training model.

[0091] It should be understood that in the process of the model to be trained processing the input data and outputting the results, each layer in the model to be trained will participate in the process, that is, the output of each layer in the model to be trained will affect the results of the output of the model to be trained, and the outputs of different layers in the model to be trained have different effects on the results of the output of the model to be trained. In other words, the outputs of different layers have different degrees of improvement in the accuracy of the results of the output of the model to be trained, that is, in terms of improving the accuracy of the results of the output of the model to be trained, the importance of different layers in the model to be trained is different.

[0092] In one possible implementation, the model to be trained includes a second layer that is different from the first layer, and the weight of the second layer represents the degree to which the output of the second layer improves the accuracy of the results of the output of the model to be trained. Then, when the target weight is greater than the weight of the second layer, the output of the first layer improves the accuracy of the results of the output of the model to be trained more than the output of the second layer, that is, the first layer is more important than the second layer.

[0093] In the training process of the model to be trained, the parameters of a layer can be updated based on the target gradient, and the update of the parameters of the first layer will cause the change of the output of the first layer, and the output of the first layer will affect the accuracy of the output result of the model to be trained. Therefore, the gradient of the first layer can be optimized according to the importance of the first layer, so that the output of the first layer can improve the output result of the model to be trained. Since the target weight represents the importance of the first layer, the model training device optimizes the target gradient based on the target weight and the target gradient to obtain the updated gradient of the first layer.

[0094] In one possible implementation, the model training device calculates the product of the target weight and the target gradient to obtain the update gradient of the first layer.

[0095] In another possible implementation, the model training device calculates the product of the target weight and the target gradient to obtain an intermediate value, and uses the sum of the intermediate value and the preset value as the update gradient of the first layer.

[0096] In another possible implementation, the model training device calculates the product of the square of the target weight and the target gradient to obtain the update gradient of the first layer.

[0097] 104. In the process of updating the parameters of the model to be trained based on the training data, the parameters of the first layer are updated based on the updated gradient to obtain a target model.

[0098] The training data is used to update the parameters of the model to be trained. Therefore, the parameters of the model to be trained can be updated by training the model to be trained with the training data. Specifically, the training data is input into the model to be trained, and the model to be trained processes the training data and outputs the processing result. The loss of the model to be trained is determined based on the difference between the output processing result and the label of the training data. The model to be trained is back-propagated based on the loss of the model to be trained. In the process of back-propagation of the model to be trained, the parameters of the model structure in the model to be trained are updated based on the gradient of back-propagation.

[0099] As described in step 102, in the process of back propagation, after the gradient of each layer in the model to be trained is calculated, the parameters of each layer can be updated based on the gradient of each layer. Therefore, in the process of updating the parameters of the model to be trained based on the training data, the model training device updates the parameters of the first layer based on the updated gradient, so that the parameters of the first layer can be updated in the direction of improving the accuracy of the result output by the model to be trained. It should be understood that in the process of updating the parameters of the model to be trained, the model structure in the model to be trained will update the parameters based on the gradient, but because the gradients of different model structures are different, the update of the parameters of different model structures is also different.

[0100] In one possible implementation, the training data is a training text including a mask. The training text may be a text describing any content, for example, the content of the target text is a red car, or another example, the content of the target text is a basketball game. The training text includes a mask, wherein the mask may include: masking, replacing, and extracting. For example, the training text is: a basketball game held at a school. A mask may be generated in the training text by masking the word "basketball" in the training text, a mask may be generated in the training text by replacing the word "basketball" in the training text corpus with a predetermined character, and a mask may be generated in the training text by extracting "basketball" from the training text.

[0101] In the case where the training data is a training text including a mask, the result output by the model to be trained includes a prediction result of the mask, wherein the prediction result is the content of the mask determined by the model to be trained, that is, by training the model to be trained using the training data, the model to be trained can acquire the ability to predict the content of the mask in the text. In the process of updating the parameters of the model to be trained, the parameters of the first layer are updated based on the update gradient to obtain the target model, which can improve the training effect of the model to be trained, that is, improve the prediction accuracy of the target model for the content of the mask in the text.

[0102] In another possible implementation, the training data is a training image with a label, wherein the label includes the category of the training image. For example, if the training image includes an apple, then the label of the training image may be an apple. For another example, if the training image includes a car, then the label of the training image may be a car. Using the training image to train the model to be trained can enable the model to be trained to have the ability to classify images. Specifically, after the training image is input into the model to be trained, the model to be trained processes the training image and outputs a prediction result of the category of the training image. Based on the difference between the prediction result and the label of the training image, the loss of the model to be trained is determined. Then, through the back propagation algorithm, the partial derivative of the loss of the model to be trained and each parameter in the model to be trained is calculated to obtain the back propagation gradient of each layer in the model to be trained. Then, based on the back propagation gradient of each layer in the model to be trained, the parameters of each layer are updated, wherein the back propagation gradient of the first layer is the update gradient, and therefore the parameters of the first layer are updated based on the update gradient. Until the loss of the model to be trained converges, the training of the model to be trained is completed to obtain the target model, so that the target model has the ability to classify images.

[0103] In another possible implementation, the training data is a training word pair with a label, wherein the training word pair includes two words, and the label includes the matching degree of the two words in the training word pair. Using the training words to train the model to be trained can enable the model to be trained to have the ability to determine the matching degree of the two words. Specifically, after the training word pair is input into the model to be trained, the training word pair is processed by the model to be trained to extract the word features of the two words in the training word pair, respectively, wherein the word features carry the semantic information of the words. Then, based on the word features of the two words, the semantic relevance of the two words is determined, and the matching degree of the two words is determined based on the semantic relevance, wherein the matching degree is positively correlated with the semantic relevance. The model to be trained finally outputs the prediction result of the matching degree of the two words in the training word pair. Based on the difference between the prediction result and the label of the training word pair, the loss of the model to be trained is determined. Then, through the back propagation algorithm, the partial derivative of the loss of the model to be trained and each parameter in the model to be trained is calculated to obtain the back propagation gradient of each layer in the model to be trained. Then, based on the back propagation gradient of each layer in the model to be trained, the parameters of each layer are updated. The back propagation gradient of the first layer is the update gradient, so the parameters of the first layer are updated based on the update gradient. This process is repeated until the loss of the model to be trained converges. The training of the model to be trained is completed and the target model is obtained, so that the target model has the ability to determine the matching degree of two words.

[0104] In the embodiment of the present application, after acquiring the training data, the model training device processes the training data using the model to be trained to determine the target gradient of the first layer in the model to be trained. Since the preset target weight of the first layer represents the degree of improvement of the accuracy of the output of the first layer to the output of the model to be trained, the model training device optimizes the target gradient based on the target weight to obtain the updated gradient of the first layer, and then in the process of updating the parameters of the model to be trained, the parameters of the first layer are updated based on the updated gradient to obtain the target model, which can enable the model to be trained to complete the training faster and improve the accuracy of the results output by the target model, thereby improving the training efficiency and training effect of the model to be trained.

[0105] It should be understood that the first layer and the target weight in the embodiment of the present application are the description objects determined by the concise description technical solution, and should not be understood as the model to be trained includes only one layer, nor should it be understood as only one layer having a weight. In practical applications, the model to be trained may include at least one layer, and each layer has a corresponding weight, and the weight of each layer is used to optimize the gradient of each layer. In the process of updating the parameters of the model to be trained, the parameters of each layer can be updated based on the optimized gradients of all layers. In this way, the gradients of each layer can be optimized according to the importance of each layer in the model to be trained to obtain the updated gradients of each layer, and then the parameters of each layer can be updated based on the updated gradients of each layer. Compared with directly updating the parameters of each layer based on the gradients of each layer after determining the gradients of each layer according to the loss of the model to be trained, the parameters of each layer can be updated faster to meet the requirements, wherein meeting the requirements refers to the convergence of the loss of the model to be trained. This can shorten the training time of the model to be trained, thereby improving the training efficiency of the model to be trained, and can improve the training effect of the model to be trained.

[0106] Since the embodiment of the present application can optimize the gradient of each layer in the model to be trained, the optimization direction of updating the parameters of each layer based on the gradient of each layer can be made more accurate, and thus the time consumed for updating the parameters of each layer based on the gradient of each layer can be shortened, thereby shortening the time consumed for the model to be trained to converge. Specifically, the model to be trained is trained based on the method of the embodiment of the present application, and the amount of time consumed for the convergence of the model to be trained is shortened by the sum of the time consumed by the parameters of each layer. Large-scale models have many layers, or large-scale models have many parameters. Therefore, in the case of a large-scale model, the time consumed for the convergence of the model to be trained can be significantly shortened, thereby improving training efficiency.

[0107] In a possible application scenario, the training data is training text, and the first layer of the model to be trained is a feature extraction layer. After the training text is input into the model to be trained, the first layer extracts features from the training text to obtain text features of the training text. The model to be trained obtains a processing result of the training text based on the text features as the result output by the model to be trained. For example, when the training text includes a mask, the content corresponding to the mask in the training text is predicted to obtain the processing result. Based on the difference between the processing result and the label of the mask, the loss of the model to be trained is determined, wherein the label of the mask is the true value (ground truth, GT). Based on the loss, the target gradient of the first layer is determined, and then based on the target weight and the target gradient, the update gradient of the first layer is obtained. In this way, in the process of updating the parameters of the model to be trained, the parameters of the first layer are updated based on the update gradient to obtain the target model.

[0108] In this application scenario, after determining the loss of the model to be trained, the target gradient of the first layer is first determined based on the loss, and then the target gradient is optimized based on the target weight to obtain the updated gradient of the first layer. In this way, the parameters of the first layer are updated based on the updated gradient, so that the result output by the first layer can be optimized in the direction of improving the accuracy of the processing result of the training text output by the model to be trained, and the result output by the first layer can also make the processing result of the training text output by the model to be trained more accurate, thereby improving the training efficiency and training effect of the model to be trained.

[0109] In another possible application scenario, the training data is a training image, and the first layer of the model to be trained is a feature extraction layer. After the training image is input into the model to be trained, the first layer extracts features from the training image to obtain image features of the training image. The model to be trained obtains a prediction result for the category of the training image based on the image features. Based on the difference between the processing result and the label of the training image, the loss of the model to be trained is determined, wherein the label of the training image is GT. Based on the loss, the target gradient of the first layer is determined, and then based on the target weight and the target gradient, the updated gradient of the first layer is obtained. In this way, in the process of updating the parameters of the model to be trained, the parameters of the first layer are updated based on the updated gradient to obtain the target model.

[0110] In this application scenario, after determining the loss of the model to be trained, the target gradient of the first layer is first determined based on the loss of the model to be trained, and then the target gradient is optimized based on the target weight to obtain the updated gradient of the first layer. In this way, the parameters of the first layer are updated based on the updated gradient, so that the image features extracted by the first layer can be optimized in the direction of improving the accuracy of the prediction results output by the model to be trained, thereby improving the training efficiency and training effect of the model to be trained.

[0111] As an optional implementation, the model training device performs the following steps during the execution of step 104:

[0112] 201. In the process of updating the parameters of the model to be trained based on the training data, the parameters of the first layer and the target weight are updated based on the updated gradient to obtain a target model.

[0113] As mentioned above, the training data is used to update the parameters of the model to be trained. Therefore, the parameters of the model to be trained can be updated by training the model to be trained with the training data. In the process of updating the parameters of the model to be trained, the parameters of the first layer will also be updated. In this embodiment, in the process of updating the parameters of the model to be trained based on the training data, the model training device not only updates the parameters of the first layer based on the updated gradient, but also updates the target weight based on the updated gradient, thereby improving the accuracy of the representation of the importance of the target weight to the first layer.

[0114] As an optional implementation, the model to be trained includes a second layer, wherein the output of the second layer is the result of the output of the model to be trained, that is, the second layer is the last layer in the model to be trained. It should be understood that the output of the first layer can be the input of the second layer, for example, the first layer is the input layer of the model to be trained, that is, the input of the model to be trained is the input of the first layer, the output of the first layer is the input of the second layer, and the output of the second layer is the result of the output of the model to be trained. There may also be other layers between the first and second layers, that is, the output of the first layer is not the input of the second layer, for example, the first layer is the input layer of the model to be trained, that is, the input of the model to be trained is the input of the first layer, the output of the first layer is the input of the third layer, the output of the third layer is the input of the second layer, and the output of the second layer is the result of the output of the model to be trained.

[0115] In this embodiment, the model training device performs the following steps during the execution of step 102:

[0116] 301. The training data is processed by the model to be trained, the first layer outputs a first result, and the second layer outputs a second result.

[0117] In the process of the model to be trained processing the training data, each layer in the model to be trained will process the input and output the result, wherein the result output by the first layer is the first result, and the result output by the second layer is the second result. For example, the first layer is the input layer of the model to be trained, the output of the first layer is the input of the second layer, and the output of the second layer is the result output by the model to be trained. The input of the model to be trained is data a, and the first layer processes data a and outputs data b, that is, data b is the first result, and the second layer processes data b and outputs data c, that is, the second result is data c.

[0118] 302. Concatenate the first result and the second result to obtain a concatenated result.

[0119] 303. Determine the target gradient based on the difference between the splicing result and the label of the training data.

[0120] In the embodiment of the present application, the label of the training data is GT, and the accuracy of the output result can be determined by supervising the output result with the label of the training data. Since the splicing result includes the first result and the second result, the accuracy of the splicing result can be determined by supervising the splicing result with the label of the training data. In other words, the degree to which the first result output by the first layer improves the accuracy of the result output by the model to be trained can be determined. Therefore, the model training device determines the target gradient of the first layer based on the difference between the label of the splicing result and the label of the training data.

[0121] In one possible implementation, the model training device determines the loss of the first layer based on the difference between the splicing result and the label of the training data. Optionally, the model training device determines the loss of the model to be trained based on the difference between the splicing result and the trained label, wherein the loss of the model to be trained is positively correlated with the difference. The model training device then determines the loss of the first layer based on the loss of the model to be trained. After determining the loss of the first layer, the model training device can determine the target gradient based on the loss of the first layer. Optionally, the model training device obtains the target gradient by calculating the partial derivative of the loss of the first layer and the parameters in the first layer. Optionally, the model training device calculates the partial derivative of the loss of the first layer and the parameters in the first layer according to the back propagation (BP) algorithm to obtain the target gradient.

[0122] In this embodiment, the model training device processes the training data by using the model to be trained, so that the first layer outputs the first result, and the second layer outputs the second result. Since the output of the second layer is the result output by the model to be trained, the second result is the result output by the model to be trained. Therefore, by splicing the first result and the second result to obtain the splicing result, the result output by the first layer can be added to the result output by the model to be trained. In this way, the splicing result can be supervised by the label of the training data to determine the degree of improvement of the accuracy of the first result output by the first layer to the result output by the model to be trained. Therefore, the model training device determines the target gradient based on the difference between the splicing result and the label of the training data, which can improve the accuracy of the target gradient.

[0123] It should be understood that in practical applications, the model training device processes the training data through the model to be trained to determine the results of all non-output layer outputs in the model to be trained, wherein the non-output layer is a layer other than the second layer. The superposition results of each non-output layer are obtained by splicing the results of each non-output layer output with the second result of the second layer output. Then, based on the difference between the superposition results of each non-output layer and the label of the training data, the back propagation gradient of each non-output layer is determined. Optionally, the model training device determines the loss of each non-output layer based on the difference between the superposition results of each non-output layer and the label of the training data. The back propagation gradient of each non-output layer is obtained by calculating the partial derivative of the loss of each non-output layer and the parameters in each non-output layer. Optionally, the model training device calculates the partial derivative of the loss of each non-output layer and the parameters in each non-output layer according to the BP algorithm to obtain the back propagation gradient of each non-output layer.

[0124] As an optional implementation, the model training device performs the following steps in the step of executing step 302:

[0125] 401. Concatenate the first result and the second result to obtain an intermediate result.

[0126] It should be understood that in step 302, what is obtained by splicing the first result and the second result is a spliced ​​result, but in this step, what is obtained by the model splicing the first result and the second result is not a spliced ​​result but an intermediate result.

[0127] 402. Determine the product of the intermediate result and the target weight as the concatenation result.

[0128] Since the intermediate result includes the first result output by the first layer, and the degree of improvement of the accuracy of the result output by the first layer to the model to be trained can be represented by the target weight, the intermediate result can be optimized based on the target weight. Specifically, the model training device uses the product of the intermediate result and the target weight as the splicing result.

[0129] In this embodiment, the model training device first obtains an intermediate result by splicing the first result and the second result, and then optimizes the intermediate result using the target weight to obtain a spliced ​​result to improve the accuracy of the spliced ​​result. Specifically, the model training device determines the product of the intermediate result and the target weight as the spliced ​​result, thereby improving the accuracy of the spliced ​​result as the result output by the model to be trained.

[0130] Optionally, in practical applications, the model training device can determine the superposition result of any non-output layer in the manner of determining the target gradient of the first layer in step 401 and step 402. Specifically, the model training device splices the results output by each non-output layer with the second result output by the second layer to obtain the splicing results of each non-output layer. Then, the product of the splicing results of each non-output layer and the weight of each non-output layer is determined respectively to obtain the superposition result of each non-output layer, wherein the weight of each non-output layer represents the degree of improvement of the accuracy of the output of each output layer on the output of the training model.

[0131] As an optional implementation, the model training device performs the following steps during the execution of step 401:

[0132] 501. Encode the first result to obtain an encoded first result.

[0133] In the embodiment of the present application, the dimension of the encoded first result is the same as the dimension of the second result, that is, the model training device encodes the first result so that the dimension of the first result is the same as the dimension of the second result. For example, if the dimension of the first result is 3 and the dimension of the second result is 6, then the dimension of the encoded first result obtained by encoding the first result is 6.

[0134] 502. Concatenate the encoded first result and the second result to obtain the intermediate result.

[0135] In this embodiment, the model training device first encodes the first result so that the dimension of the first result is the same as the dimension of the second result, thereby obtaining the encoded first result. In this way, when the dimension of the encoded first result is the same as the dimension of the second result, the encoded first result and the second result can be concatenated to obtain an intermediate result.

[0136] Optionally, in practical applications, the model training device may determine the splicing result of any non-output layer in the manner of determining the intermediate result of the first layer in step 501 and step 502. Specifically, the model training device encodes the results output by each non-output layer to obtain the encoding results of each non-output layer, wherein the dimension of the encoding result of each non-output layer is the same as the dimension of the second result. The encoding result of each non-output layer and the second result are spliced ​​respectively to obtain the splicing result of each non-output layer.

[0137] Based on the model training method provided in the embodiment of the present application, the embodiment of the present application also provides a model training implementation method. Figure 2 , Figure 2 FIG. 1 is a schematic diagram of a structure of a model to be trained provided in an embodiment of the present application. Figure 2As shown, in the process of using training data to train the model to be trained, the input of the model to be trained is the training data. Figure 2 The module in the dotted box is the structure of the model to be trained, such as Figure 2 As shown, the model to be trained includes one layer, two layers, ..., N layers. If the model to be trained is represented by M, then M = {layer1, layer2, ..., layer n}, n≥1, where layer1 represents the first layer, layer2 represents the second layer, ..., layer n represents N layers, and n represents the number of layers.

[0138] like Figure 2 As shown, the N layers in the model to be trained are connected in series, that is, the output of the first layer is the input of the second layer, the output of the second layer is the input of the third layer, ..., the output of the (N-1) layer is the input of the N layer. Among them, the first layer, the second layer, ..., the (N-1) layer are all non-output layers, the N layer is the output layer of the model to be trained, and the first layer is the input layer of the model to be trained, that is, after the training data is input to the model to be trained, it is first input to the first layer, and after being processed in sequence by each layer, the output of the model to be trained is output through the output of the N layer. .

[0139] Figure 2 Each layer in the model to be trained shown has weights, such as Figure 2 As shown, w1 is the weight of the first layer, w2 is the weight of the second layer, ..., w n is the weight of the N layer, where w1 represents the degree of improvement of the accuracy of the output of the first layer to the output of the training model, w2 represents the degree of improvement of the accuracy of the output of the second layer to the output of the training model, and w n It represents the degree to which the output of the N layer improves the accuracy of the output of the model to be trained. If the set of weights of each layer in the model to be trained is represented by W, then W = {w1,w2,…,w n}, n≥1, where w1 represents the weight of the first layer, w2 represents the weight of the second layer, ..., w n Represents the weight of N layers.

[0140] In the forward propagation process of the model to be trained, the model to be trained processes the training data through N layers to obtain the output results of each layer, where the output result of the first layer is out1, the output result of the second layer is out2, the output result of the third layer is out3, ..., the output result of the N layer is out n . Construct the output matrix out based on the output structure of each layer in the model to be trained w , specifically:

[0141] The output matrix is ​​encoded by the encoder module (Encoder) so that the dimension of the output matrix is ​​the same as outn The dimension is the same as that of the encoded output matrix. Then, the output result of the model to be trained is re-determined based on the encoded output matrix and the output of the N layer. Specifically, Among them, out represents the re-determined output result of the model to be trained (hereinafter referred to as the new result), out n Represents the output result of layer N, out E represents the output matrix after encoding, W represents the set of weights of each layer in the model to be trained, and matmul(A, B) represents A×B. The new result contains the superposition results of each layer in the model to be trained. Specifically, out E Including the output results of each layer in the model to be trained, so It means that the output results of each layer in the model to be trained are concatenated with the output results of the N layers of the model to be trained to obtain the spliced ​​results of each layer. It means that the product of the splicing result of each layer in the model to be trained and the weight of each layer is determined to obtain the superposition result of each layer. For example, when one layer in the model to be trained is the first layer mentioned above, the superposition result of one layer in the new result is the splicing result of the first layer.

[0142] During the back propagation process of the model to be trained, the back propagation gradient of each layer is determined by back gradient calculation. Specifically, the model training device first determines the loss of the model to be trained based on the difference between the output of the model to be trained and the label of the training data. The loss of the model to be trained is denoted as Loss, then Loss = F(out, label), where F(·) represents the loss function, out represents the output of the model to be trained, and label represents the label of the training data. Then the model training device calculates the partial derivative of the loss of the model to be trained and the parameters in each layer through the BP algorithm to obtain the back propagation gradient of each layer. The set of back propagation gradients of each layer in the model to be trained is denoted as G, then G = {g1, g2,…, g n}, n ≥ 1, where g1 represents the back propagation gradient of the first layer, g2 represents the back propagation gradient of the second layer, ..., g n represents the back propagation gradient of N layers. The model training device then updates the back propagation gradient of each layer based on the weight of each layer to obtain the updated gradient of each layer, and the set of updated gradients of each layer in the model to be trained is recorded as So Finally, the model training device updates the parameters and weights of each layer based on the updated gradient of each layer until the loss of the model to be trained converges, completing the training of the model to be trained and obtaining the target model.

[0143] Based on the model training method provided in the embodiment of the present application, the output results of each layer of the model to be trained can be spliced ​​with the output results of the model to be trained, and the output results of each layer can be added to the output results of the model to be trained respectively, so that the output results of each layer can be determined based on the output results of the model to be trained. The output results of the model to be trained are determined based on the weights of each layer, which can improve the accuracy of the output of the model to be trained. Therefore, after determining the back propagation gradient of each layer based on the output results of the model to be trained and the labels of the training data, the back propagation gradient of each layer is optimized based on the weights of each layer to obtain the updated gradient of each layer, which can improve the accuracy of the back propagation gradient of each layer. In this way, updating the parameters and weights of each layer based on the updated gradients of each layer can not only improve the optimization efficiency of each layer, so that the model to be trained converges quickly, but also improve the accuracy of the weights of each layer, thereby improving the training efficiency and training effect of the model to be trained.

[0144] Those skilled in the art will appreciate that, in the above method of specific implementation, the order in which the steps are written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of the steps should be determined by their functions and possible internal logic.

[0145] The method of the embodiment of the present application is described in detail above, and the device of the embodiment of the present application is provided below.

[0146] See also Figure 3 , Figure 3 A schematic diagram of the structure of a model training device provided in an embodiment of the present application, the model training device 1 includes: an acquisition unit 11, a determination unit 12, a processing unit 13, and an update unit 14, specifically:

[0147] An acquisition unit 11 is used to acquire training data, where the training data is used to update the parameters of the model to be trained;

[0148] A determination unit 12, configured to process the training data through the model to be trained to determine a target gradient of a first layer of the model to be trained;

[0149] A processing unit 13 is used to obtain an update gradient of the first layer based on a preset target weight and the target gradient, wherein the target weight represents a degree of improvement of the accuracy of the result output by the output of the first layer on the output of the model to be trained;

[0150] The updating unit 14 is used to update the parameters of the first layer based on the update gradient in the process of updating the parameters of the model to be trained to obtain a target model.

[0151] In combination with any implementation manner of the present application, the updating unit 14 is used to:

[0152] In the process of updating the parameters of the model to be trained based on the training data, the parameters of the first layer and the target weight are updated based on the updated gradient to obtain a target model.

[0153] In combination with any embodiment of the present application, the model to be trained includes a second layer, and the output of the second layer is the result output by the model to be trained;

[0154] The determining unit 12 is used to:

[0155] The training data is processed by the model to be trained, the first layer outputs a first result, and the second layer outputs a second result;

[0156] splicing the first result and the second result to obtain a splicing result;

[0157] The target gradient is determined based on a difference between the concatenation result and the label of the training data.

[0158] In combination with any implementation manner of the present application, the determining unit 12 is used to:

[0159] Concatenate the first result and the second result to obtain an intermediate result;

[0160] The product of the intermediate result and the target weight is determined as the splicing result.

[0161] In combination with any implementation manner of the present application, the determining unit 12 is used to:

[0162] Encoding the first result to obtain an encoded first result, wherein a dimension of the encoded first result is the same as a dimension of the second result;

[0163] The encoded first result and the second result are concatenated to obtain the intermediate result.

[0164] In combination with any implementation manner of the present application, the determining unit 12 is used to:

[0165] Determine the loss of the first layer based on the difference between the concatenation result and the label of the training data;

[0166] The target gradient is determined based on the loss of the first layer.

[0167] In combination with any implementation manner of the present application, the determining unit 12 is used to:

[0168] The target gradient is obtained by calculating the loss of the first layer and the partial derivative of the parameters in the first layer through a back-propagation algorithm.

[0169] In combination with any embodiment of the present application, the processing unit 13 is used to:

[0170] The product of the target weight and the target gradient is determined as the update gradient.

[0171] In combination with any implementation manner of the present application, the training data is training text including a mask, and the result output by the model to be trained includes a prediction result of the mask.

[0172] In the embodiment of the present application, after acquiring the training data, the model training device processes the training data using the model to be trained to determine the target gradient of the first layer in the model to be trained. Since the preset target weight of the first layer represents the degree of improvement of the accuracy of the output of the first layer to the output of the model to be trained, the model training device optimizes the target gradient based on the target weight to obtain the updated gradient of the first layer, and then in the process of updating the parameters of the model to be trained, the parameters of the first layer are updated based on the updated gradient to obtain the target model, which can enable the model to be trained to complete the training faster and improve the accuracy of the results output by the target model, thereby improving the training efficiency and training effect of the model to be trained.

[0173] Since the embodiment of the present application can optimize the gradient of each layer in the model to be trained, the optimization direction of updating the parameters of each layer based on the gradient of each layer can be made more accurate, and thus the time consumed for updating the parameters of each layer based on the gradient of each layer can be shortened, thereby shortening the time consumed for the model to be trained to converge. Specifically, the model to be trained is trained based on the method of the embodiment of the present application, and the amount of time consumed for the convergence of the model to be trained is shortened by the sum of the time consumed by the parameters of each layer. Large-scale models have many layers, or large-scale models have many parameters. Therefore, in the case of a large-scale model, the time consumed for the convergence of the model to be trained can be significantly shortened, thereby improving training efficiency.

[0174] In some embodiments, the functions or modules included in the device provided in the embodiments of the present application can be used to execute the method described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments. For the sake of brevity, it will not be repeated here.

[0175] Figure 4A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application. The electronic device 2 includes a processor 21 and a memory 22. Optionally, the electronic device 2 also includes an input device 23 and an output device 24. The processor 21, the memory 22, the input device 23 and the output device 24 are coupled via a connector, and the connector includes various interfaces, transmission lines or buses, etc., which are not limited in the embodiments of the present application. It should be understood that in each embodiment of the present application, coupling refers to mutual connection in a specific manner, including direct connection or indirect connection through other devices, for example, it can be connected through various interfaces, transmission lines, buses, etc.

[0176] The processor 21 may include one or more processors, for example, one or more central processing units (CPUs). When the processor is a CPU, the CPU may be a single-core CPU or a multi-core CPU. Optionally, the processor 21 may be a processor group consisting of multiple CPUs, and the multiple processors are coupled to each other via one or more buses. Optionally, the processor may also be other types of processors, etc., which are not limited in the embodiments of the present application.

[0177] The memory 22 can be used to store computer program instructions and various computer program codes including the program code for executing the program code of the present application. Optionally, the memory includes but is not limited to random access memory (RAM), read-only memory (ROM), erasable programmable read only memory (EPROM), or portable read only memory (CD-ROM), which is used for related instructions and data.

[0178] The input device 23 is used to input data and / or signals, and the output device 24 is used to output data and / or signals. The input device 23 and the output device 24 can be independent devices or an integrated device.

[0179] It can be understood that in the embodiment of the present application, the memory 22 can be used not only to store relevant instructions, but also to store relevant data. For example, the memory 22 can be used to store the model to be trained and the training data obtained through the input device 23, or the memory 22 can also be used to store the target model obtained by the processor 21, etc. The embodiment of the present application does not limit the specific data stored in the memory.

[0180] Understandably, Figure 4Only a simplified design of an electronic device is shown. In practical applications, the electronic device may also include other necessary components, including but not limited to any number of input / output devices, processors, memories, etc., and all electronic devices that can implement the embodiments of the present application are within the protection scope of the present application.

[0181] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software 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 this application.

[0182] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. Those skilled in the art can also clearly understand that the descriptions of the various embodiments of the present application have different focuses. For the convenience and brevity of description, the same or similar parts may not be repeated in different embodiments. Therefore, for parts not described or not described in detail in a certain embodiment, refer to the records of other embodiments.

[0183] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0184] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0185] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0186] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted through the computer-readable storage medium. The computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (digital subscriber line, DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium (eg, a floppy disk, a hard disk, a magnetic tape), an optical medium (eg, a digital versatile disc (DVD)), or a semiconductor medium (eg, a solid state disk (SSD)).

[0187] A person skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by a computer program to instruct the relevant hardware, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the above-mentioned method embodiments. The aforementioned storage medium includes: a read-only memory (ROM) or a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.

Claims

1. A model training method, characterized in that: The method comprises: Acquire training data, where the training data is used to update the parameters of the model to be trained, and the training data includes one of the following: labeled text data, labeled image data, and labeled audio data; Processing the training data by the model to be trained to determine the target gradient of the first layer of the model to be trained; Based on a preset target weight and the target gradient, an update gradient of the first layer is obtained, wherein the target weight represents the degree to which the output of the first layer improves the accuracy of the result output by the model to be trained; In the process of updating the parameters of the model to be trained based on the training data, the parameters of the first layer are updated based on the updated gradient to obtain a target model.

2. The method according to claim 1, characterized in that In the process of updating the parameters of the to-be-trained model based on the training data, updating the parameters of the first layer based on the updated gradient to obtain the target model includes: In the process of updating the parameters of the model to be trained based on the training data, the parameters of the first layer and the target weight are updated based on the updated gradient to obtain a target model.

3. The method according to claim 1 or 2, characterized in that: The model to be trained includes a second layer, and the output of the second layer is the result output by the model to be trained; The step of processing the training data by using the model to be trained to determine the target gradient of the first layer includes: The training data is processed by the model to be trained, the first layer outputs a first result, and the second layer outputs a second result; splicing the first result and the second result to obtain a splicing result; The target gradient is determined based on a difference between the concatenation result and the label of the training data.

4. The method according to claim 3, characterized in that The step of splicing the first result and the second result to obtain a splicing result includes: Concatenate the first result and the second result to obtain an intermediate result; The product of the intermediate result and the target weight is determined as the splicing result.

5. The method according to claim 4, characterized in that The step of combining the first result and the second result to obtain an intermediate result includes: Encoding the first result to obtain an encoded first result, wherein a dimension of the encoded first result is the same as a dimension of the second result; The encoded first result and the second result are concatenated to obtain the intermediate result.

6. The method according to claim 3, characterized in that The determining the target gradient based on the difference between the splicing result and the label of the training data includes: Determine the loss of the first layer based on the difference between the concatenation result and the label of the training data; The target gradient is determined based on the loss of the first layer.

7. The method according to claim 6, characterized in that The determining the target gradient based on the loss of the first layer includes: The target gradient is obtained by calculating the partial derivative of the loss of the first layer and the parameters in the first layer.

8. The method according to claim 1 or 2, characterized in that: The step of obtaining the update gradient of the first layer based on the preset target weight and target gradient includes: The product of the target weight and the target gradient is determined as the update gradient.

9. The method according to claim 1 or 2, characterized in that: The training data is training text including a mask, and the result output by the model to be trained includes a prediction result of the mask.

10. A model training device, characterized in that: The device comprises: An acquisition unit, configured to acquire training data, wherein the training data is used to update parameters of the model to be trained, and the training data includes one of the following: text data with labels, image data with labels, and audio data with labels; A determination unit, configured to process the training data through the model to be trained to determine a target gradient of a first layer of the model to be trained; A processing unit, configured to obtain an update gradient of the first layer based on a preset target weight and the target gradient, wherein the target weight represents a degree of improvement of the accuracy of a result output by the output of the first layer on the output of the model to be trained; An updating unit is used to update the parameters of the first layer based on the update gradient in the process of updating the parameters of the model to be trained based on the training data to obtain a target model.

11. An electronic device, characterized in that: include: A processor and a memory, wherein the memory is used to store computer program codes, wherein the computer program codes include computer instructions, and when the processor executes the computer instructions, the electronic device executes the method according to any one of claims 1 to 9.

12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions. When the program instructions are executed by a processor, the processor is caused to execute the method according to any one of claims 1 to 9.

Citation Information

Patent Citations

  • A data restoration method based on a time sequence

    CN109670580A

  • Neural network model training method, device and electronic equipment

    CN110991652A

  • A method and device for searching model structure

    CN111667056A

  • Neural network training method and device, equipment and computer readable storage medium

    CN113435520A

  • Model gradient updating method and device

    CN114492841A