Model training method, equipment, storage medium and device
By automatically monitoring the exceptions of the loss function value during the model training process and skipping the abnormal training data, the problems of low training efficiency and waste of resources caused by manual intervention in the prior art are solved, and more efficient model training and cost reduction are achieved.
Patent Information
- Application Number
- CN202310969280.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-02
- Publication Date
- 2025-02-14
AI Technical Summary
The existing model training methods require manual intervention, resulting in inefficient training, waste of resources and increased costs.
During the model training process, the exception of the loss function value is automatically monitored, and the exception training data will be automatically skipped when an exception occurs, and the training will continue through the next training data.
Improve model training efficiency, avoid waste of training resources, and reduce model training costs.
Smart Images

Figure CN119441931A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a model training method, equipment, storage medium and device. Background Art
[0002] As the parameter scale of transformer-type language models continues to increase, the loss function value of the model is prone to abnormalities during training, resulting in training failure. Therefore, in order to solve the above problem, the existing method is to manually observe the model training process, and when an abnormality is observed in the model training process, manually pause the model training process, manually skip the abnormal training data that caused the model training abnormality, and then restart the model training.
[0003] However, the above method requires manual intervention in the model training process, which is time-consuming and labor-intensive, and reduces the efficiency of model training. In addition, the above method also requires pausing the model training process, resulting in a waste of training resources and increasing the cost of model training.
[0004] The above contents are only used to assist in understanding the technical solution of the present invention and do not constitute an admission that the above contents are prior art. Summary of the invention
[0005] The main purpose of the present invention is to provide a model training method, equipment, storage medium and device, aiming to solve the technical problems that the existing model training method requires manual intervention in the model training process, which is time-consuming and labor-intensive, reduces the efficiency of model training, and the existing model training method also requires pausing the model training process, thereby causing a waste of training resources and increasing the cost of model training.
[0006] To achieve the above object, the present invention provides a model training method, which comprises:
[0007] When training the preset model, monitoring whether the loss function value of the preset model is abnormal;
[0008] When the loss function value is abnormal, the abnormal training data is skipped, the abnormal training data is the training data that causes the loss function value to be abnormal, and the preset model is continuously trained through the next training data corresponding to the abnormal training data.
[0009] Optionally, when training the preset model, monitoring whether the loss function value of the preset model is abnormal includes:
[0010] When training a preset model, obtaining a forward propagation loss value and / or a backward propagation gradient value of the preset model;
[0011] Monitor whether the loss function value of the preset model is abnormal based on the forward propagation loss value and / or the backward propagation gradient value.
[0012] Optionally, monitoring whether the loss function value of the preset model is abnormal according to the forward propagation loss value and / or the backward propagation gradient value includes:
[0013] Determine whether the forward propagation loss value exceeds a preset loss function value to obtain a first determination result, and determine whether the backward propagation gradient value exceeds a preset gradient value to obtain a second determination result;
[0014] Monitor whether the loss function value of the preset model is abnormal based on the first judgment result and / or the second judgment result.
[0015] Optionally, monitoring whether the loss function value of the preset model is abnormal according to the forward propagation loss value and / or the backward propagation gradient value includes:
[0016] Calculate whether the fluctuation value of the forward propagation loss value exceeds a preset first ratio threshold value to obtain a first calculation result, and calculate whether the fluctuation value of the backward propagation gradient value exceeds a preset second ratio threshold value to obtain a second calculation result;
[0017] Monitor whether the loss function value of the preset model is abnormal based on the first calculation result and / or the second calculation result.
[0018] Optionally, the calculating whether the fluctuation value of the forward propagation loss value exceeds a preset first ratio threshold to obtain a first calculation result includes:
[0019] Calculate an average value of the forward propagation loss value, where the average value of the forward propagation loss value is a moving average value or a rolling average value of the forward propagation loss value;
[0020] Whether the fluctuation value of the forward propagation loss value exceeds a preset first ratio threshold is calculated according to the average value of the forward propagation loss value to obtain a first calculation result.
[0021] Optionally, calculating whether the fluctuation value of the backward propagation gradient value exceeds a preset second ratio threshold to obtain a second calculation result includes:
[0022] Calculating an average value of the backward propagation gradient value, wherein the average value of the backward propagation gradient value is a moving average value or a rolling average value of the backward propagation gradient value;
[0023] Whether the fluctuation value of the backward propagation gradient value exceeds a preset second ratio threshold is calculated according to the average value of the backward propagation gradient value to obtain a second calculation result.
[0024] Optionally, the preset model is a language model built based on the Transformer architecture.
[0025] Optionally, when the loss function value is abnormal, continuing to train the preset model through next training data corresponding to the abnormal training data includes:
[0026] When the loss function value is abnormal, selecting batch training data associated with the abnormal training data;
[0027] The batch training data is skipped, and the preset model is continuously trained through the next training data corresponding to the batch training data.
[0028] Optionally, the model training method further includes:
[0029] When the number of abnormalities of the loss function value is greater than a preset number, reacquiring the training data set;
[0030] The preset model is retrained using the reacquired training data set.
[0031] Optionally, the model training method further includes:
[0032] Generate training anomaly logs based on skipped abnormal training data;
[0033] The training exception log is sent to the management terminal corresponding to the preset model.
[0034] Optionally, the model training method further includes:
[0035] After the preset model training is completed, obtaining the text to be processed;
[0036] The text to be processed is input into the trained preset model to obtain the result text corresponding to the text to be processed.
[0037] In addition, to achieve the above-mentioned purpose, the present invention also proposes a model training device, which includes a memory, a processor, and a model training program stored in the memory and executable on the processor, and the model training program is configured to implement the model training method as described above.
[0038] In addition, to achieve the above-mentioned purpose, the present invention also proposes a storage medium, on which a model training program is stored, and when the model training program is executed by a processor, the model training method as described above is implemented.
[0039] In addition, to achieve the above object, the present invention also proposes a model training device, the model training device comprising:
[0040] A monitoring module, used to monitor whether the loss function value of the preset model is abnormal when the preset model is trained;
[0041] The skipping module is used to skip abnormal training data when the loss function value is abnormal, wherein the abnormal training data is the training data that causes the loss function value to be abnormal, and continue to train the preset model through the next training data corresponding to the abnormal training data.
[0042] Optionally, the monitoring module is further used to obtain a forward propagation loss value and / or a backward propagation gradient value of the preset model when training the preset model;
[0043] The monitoring module is also used to monitor whether the loss function value of the preset model is abnormal based on the forward propagation loss value and / or the backward propagation gradient value.
[0044] Optionally, the monitoring module is further used to determine whether the forward propagation loss value exceeds a preset loss function value to obtain a first judgment result, and to determine whether the backward propagation gradient value exceeds a preset gradient value to obtain a second judgment result;
[0045] The monitoring module is further used to monitor whether the loss function value of the preset model is abnormal based on the first judgment result and / or the second judgment result.
[0046] Optionally, the monitoring module is further used to calculate whether the fluctuation value of the forward propagation loss value exceeds a preset first ratio threshold value to obtain a first calculation result, and calculate whether the fluctuation value of the backward propagation gradient value exceeds a preset second ratio threshold value to obtain a second calculation result;
[0047] The monitoring module is further used to monitor whether the loss function value of the preset model is abnormal based on the first calculation result and / or the second calculation result.
[0048] Optionally, the monitoring module is further used to calculate an average value of the forward propagation loss value, where the average value of the forward propagation loss value is a moving average value or a rolling average value of the forward propagation loss value;
[0049] The monitoring module is further used to calculate whether the fluctuation value of the forward propagation loss value exceeds a preset first ratio threshold value based on the average value of the forward propagation loss value, so as to obtain a first calculation result.
[0050] Optionally, the monitoring module is further used to calculate an average value of the backward propagation gradient value, where the average value of the backward propagation gradient value is a moving average value or a rolling average value of the backward propagation gradient value;
[0051] The monitoring module is further used to calculate whether the fluctuation value of the backward propagation gradient value exceeds a preset second ratio threshold value according to the average value of the backward propagation gradient value, so as to obtain a second calculation result.
[0052] Optionally, the skip module is further used to select batch training data associated with the abnormal training data when the loss function value is abnormal;
[0053] The skip module is also used to skip the batch training data and continue to train the preset model through the next training data corresponding to the batch training data.
[0054] The present invention discloses that when training a preset model, whether the loss function value of the preset model is abnormal is monitored. When the loss function value is abnormal, the abnormal training data is skipped, and the abnormal training data is the training data that causes the loss function value to be abnormal, and the preset model is continuously trained through the next training data corresponding to the abnormal training data. Since the present invention automatically monitors the abnormality of the loss function value during the model training process and automatically skips the abnormal training data when the loss function value is abnormal, the model training process does not require manual intervention and suspension of training, thereby improving the model training efficiency, avoiding the waste of training resources, and reducing the model training cost. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] Figure 1 It is a structural diagram of a model training device in a hardware operating environment involved in an embodiment of the present invention;
[0056] Figure 2 This is a flow chart of the first embodiment of the model training method of the present invention;
[0057] Figure 3 This is a flow chart of the second embodiment of the model training method of the present invention;
[0058] Figure 4 This is a flow chart of a third embodiment of the model training method of the present invention;
[0059] Figure 5 This is a structural block diagram of the first embodiment of the model training device of the present invention.
[0060] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0061] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0062] Reference Figure 1 , Figure 1A schematic diagram of the structure of a model training device in a hardware operating environment according to an embodiment of the present invention.
[0063] like Figure 1 As shown, the model training device may include: a processor 1001, such as a central processing unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The wired interface of the user interface 1003 may be a USB interface in the present invention. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a wireless fidelity (Wireless-Fidelity, Wi-Fi) interface). The memory 1005 may be a high-speed random access memory (Random Access Memory, RAM) memory, or a stable memory (Non-volatile Memory, NVM), such as a disk memory. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0064] Those skilled in the art will understand that Figure 1 The structure shown in does not constitute a limitation on the model training device, and may include more or fewer components than shown in the figure, or a combination of certain components, or a different arrangement of components.
[0065] like Figure 1 As shown, the memory 1005 identified as a computer storage medium may include an operating system, a network communication module, a user interface module, and a model training program.
[0066] exist Figure 1 In the model training device shown, the network interface 1004 is mainly used to connect to the background server and communicate data with the background server; the user interface 1003 is mainly used to connect to the user device; the model training device calls the model training program stored in the memory 1005 through the processor 1001, and executes the model training method provided by the embodiment of the present invention.
[0067] Based on the above hardware structure, an embodiment of the model training method of the present invention is proposed.
[0068] Reference Figure 2 , Figure 2 The figure is a flow chart of the first embodiment of the model training method of the present invention, and the first embodiment of the model training method of the present invention is proposed.
[0069] It should be understood that as the parameter scale of transformer-type language models continues to increase, the stability challenge of pre-training from 0 to 1 is also increasing. Compared with small models (for example: BERT model, GPT-2 model, etc.), large models (above 10B scale) are more prone to training failure during the pre-training process. The specific phenomenon is that the training loss function value is abnormal (for example: the loss function value diverges and does not converge, the loss function value fluctuates greatly (such as loss spikes)). In order to solve the above problems, the existing method is to manually observe the model training process. When an abnormality is observed in the model training process, the model training process is manually paused, and the abnormal training data that causes the model training abnormality is manually skipped, and then the model training is restarted.
[0070] However, the above method requires manual intervention in the model training process, which is time-consuming and labor-intensive, and reduces the efficiency of model training. In addition, the above method also requires pausing the model training process, resulting in a waste of training resources and increasing the cost of model training.
[0071] In order to overcome the above-mentioned defects, this embodiment automatically monitors the abnormality of the loss function value during the model training process, and automatically skips the abnormal training data when the loss function value is abnormal, so that the model training process does not require manual intervention and suspension of training, thereby improving the model training efficiency, avoiding waste of training resources, and reducing the model training cost.
[0072] In a first embodiment, the model training method comprises the following steps:
[0073] Step S10: When training the preset model, monitor whether the loss function value of the preset model is abnormal.
[0074] It should be understood that the executor of the method of this embodiment can be a model training device with data processing, network communication and program running functions, for example, a terminal device such as a computer, or other electronic device that can achieve the same or similar functions, and this embodiment does not impose any restrictions on this.
[0075] It is understandable that in this embodiment, the preset model is trained by a training data set. The training data set can be obtained from the Internet (for example, a public corpus, literary works, conversation data, and specific field data are obtained from the Internet as a training data set), or can be pre-customized according to model training requirements, which is not limited in this embodiment.
[0076] It should be understood that an abnormality in the loss function value of the preset model will result in the model being unable to be effectively optimized and converged. Therefore, in order to ensure the model training effect, in this embodiment, the loss function value of the preset model is monitored during the training process to see if there is an abnormality. Among them, the abnormality in the loss function value can be the divergence and non-convergence of the loss function value or the large fluctuation of the loss function value. The divergence and non-convergence of the loss function value means that the loss function value cannot steadily decrease or the loss function value continues to increase during the model training process; the large fluctuation of the loss function value refers to the temporary peak or abnormal value of the loss function value during the model training process.
[0077] Furthermore, in order to be able to process the input text, in this embodiment, the preset model may be a language model. In a specific implementation, the preset model is a language model built based on the Transformer architecture.
[0078] It should be understood that the preset model is a language model built based on the Transformer architecture. The preset model can receive the user's input text, parse the input text into a computer-understandable data format, and then use a pre-trained neural network model to generate response text.
[0079] In the specific implementation, the preset model uses the neural network in deep learning technology and is trained through a large amount of corpus data, so that it can learn the structure, grammatical rules and semantic information of the language. After the user enters the text, the preset model will first segment and parse the text, convert it into a computer-readable vector form, and then send it to the pre-trained neural network model for inference. During the inference process, the preset model will predict the most likely next response based on the text entered by the user and the previous context. This prediction process is based on the model's learning of a large amount of corpus data, so it can largely restore the way humans express natural language and generate highly coherent and natural response text. Finally, the preset model returns the generated response text to the user to complete a conversation interaction. Throughout the process, the preset model will continue to learn and optimize to provide more accurate and user-friendly answers.
[0080] Step S20: when the loss function value is abnormal, skip abnormal training data, the abnormal training data being the training data that causes the loss function value to be abnormal, and continue training the preset model through the next training data corresponding to the abnormal training data.
[0081] It is understandable that when the loss function value is abnormal, it means that the model cannot be effectively optimized and converged when the model is trained with the current training data. Therefore, it is necessary to treat the current training data as abnormal training data and skip the abnormal training data. Among them, skipping the abnormal training data means skipping the step of optimizing the parameters of the preset model based on the loss function value corresponding to the abnormal training data, that is, the current training process does not update the parameters of the preset model.
[0082] It should be understood that in order to ensure the continuation of the model training process, in this embodiment, the preset model is further trained using the next training data corresponding to the abnormal training data, and the process returns to step S10 until the preset model training is completed.
[0083] Furthermore, the preset model after training can be applied to text processing scenarios, and the model training method also includes:
[0084] After the preset model training is completed, the text to be processed is obtained, and the text to be processed is input into the trained preset model to obtain the result text corresponding to the text to be processed.
[0085] The present invention discloses that when training a preset model, whether the loss function value of the preset model is abnormal is monitored. When the loss function value is abnormal, the abnormal training data is skipped, and the abnormal training data is the training data that causes the loss function value to be abnormal, and the preset model is continuously trained through the next training data corresponding to the abnormal training data. Since the present invention automatically monitors the abnormality of the loss function value during the model training process and automatically skips the abnormal training data when the loss function value is abnormal, the model training process does not require manual intervention and suspension of training, thereby improving the model training efficiency, avoiding the waste of training resources, and reducing the model training cost.
[0086] Reference Figure 3 , Figure 3 This is a flow chart of the second embodiment of the model training method of the present invention. Figure 2 The first embodiment shown proposes a second embodiment of the model training method of the present invention.
[0087] In the second embodiment, the step S10 includes:
[0088] Step S101: when training a preset model, obtaining a forward propagation loss value and / or a backward propagation gradient value of the preset model.
[0089] It should be understood that in order to accurately determine whether the loss function value of the preset model is abnormal, in this embodiment, the loss function value of the preset model is monitored according to the forward propagation loss value and / or the backward propagation gradient value in the preset model training process to determine whether the loss function value of the preset model is abnormal. Wherein, forward propagation refers to the process of obtaining the final output result by calculating through each layer of the neural network starting from the input training data. In the forward propagation, the loss value (Loss Value) is calculated based on the difference between the output result of the model and the true label, and the loss value is used to indicate the performance of the model. Backward propagation, which can also be called back propagation, is a process for calculating gradients (Gradient) and updating the parameters of the neural network. In the backward propagation, according to the loss value and the prediction result of the model, the gradient is transferred from the output layer to the input layer by the chain rule to update the weights and biases of each layer. The forward propagation loss value represents the difference between the output result of the model under the training data and the true label, and the backward propagation gradient value represents the derivative of the loss function to the model parameters to determine how to adjust the parameters to minimize the loss function.
[0090] Step S102: monitoring whether the loss function value of the preset model is abnormal according to the forward propagation loss value and / or the backward propagation gradient value.
[0091] It can be understood that monitoring whether the loss function value of the preset model is abnormal based on the forward propagation loss value and / or the backward propagation gradient value can be to determine whether the loss function value of the preset model is abnormal when the forward propagation loss value is abnormal; or to determine whether the loss function value of the preset model is abnormal when the backward propagation gradient value is abnormal; or to determine whether the loss function value of the preset model is abnormal when the forward propagation loss value is abnormal and the backward propagation gradient value is abnormal, and this embodiment is not limited to this.
[0092] This embodiment monitors whether the loss function value of the preset model is abnormal based on the forward propagation loss value and / or the backward propagation gradient value during the preset model training process, so as to accurately determine whether the loss function value of the preset model is abnormal.
[0093] In the second embodiment, the step S20 includes:
[0094] Step S201: when the loss function value is abnormal, selecting batch training data associated with the abnormal training data.
[0095] It should be understood that, considering that in practical applications, training data is generally batch data, therefore, when skipping abnormal training data, in order to further improve the training effect, in this embodiment, batch training data associated with the abnormal training data is selected and skipped.
[0096] It should be noted that the batch training data associated with the abnormal training data may be training data within a preset range before and after the abnormal training data, or may be training data from the same source as the abnormal training data, and this embodiment does not impose any limitation on this.
[0097] Step S202: skip the batch training data, and continue training the preset model through the next training data corresponding to the batch training data.
[0098] It can be understood that skipping batch training data means skipping the step of optimizing the parameters of the preset model based on the loss function value corresponding to the batch training data, that is, the current training process does not update the parameters of the preset model.
[0099] This embodiment selects batch training data associated with abnormal training data and skips batch training data, thereby further improving the training effect.
[0100] Reference Figure 4 , Figure 4 The flowchart of the third embodiment of the model training method of the present invention is shown in FIG. Based on the above embodiments, the third embodiment of the model training method of the present invention is proposed.
[0101] In the third embodiment, the step S102 includes:
[0102] Step S1021: Determine whether the forward propagation loss value exceeds the preset loss function value to obtain a first judgment result, and determine whether the backward propagation gradient value exceeds the preset gradient value to obtain a second judgment result.
[0103] It should be understood that in order to accurately determine whether an abnormality occurs in the loss function of the preset model, in this embodiment, the loss function value of the preset model can be monitored to determine whether an abnormality occurs based on whether the forward propagation loss value exceeds the preset loss function value and / or whether the backward propagation gradient value exceeds the preset gradient value. The preset loss function value and the preset gradient value can be preset according to the model training requirements.
[0104] Step S1022: monitor whether the loss function value of the preset model is abnormal based on the first judgment result and / or the second judgment result.
[0105] It can be understood that monitoring whether the loss function value of the preset model is abnormal according to the first judgment result and / or the second judgment result can be that when the forward propagation loss value exceeds the preset loss function value, it is determined that the loss function value of the preset model is abnormal; it can also be that when the backward propagation gradient value exceeds the preset gradient value, it is determined that the loss function value of the preset model is abnormal; it can also be that when the forward propagation loss value exceeds the preset loss function value and the backward propagation gradient value exceeds the preset gradient value, it is determined that the loss function value of the preset model is abnormal, and this embodiment does not limit this.
[0106] This embodiment monitors whether there is any abnormality in the loss function value of the preset model based on whether the forward propagation loss value exceeds the preset loss function value and / or whether the backward propagation gradient value exceeds the preset gradient value, thereby being able to accurately determine whether there is any abnormality in the loss function of the preset model.
[0107] In the third embodiment, the step S102 includes:
[0108] Step S1021': Calculate whether the fluctuation value of the forward propagation loss value exceeds a preset first ratio threshold to obtain a first calculation result, and calculate whether the fluctuation value of the backward propagation gradient value exceeds a preset second ratio threshold to obtain a second calculation result.
[0109] It should be understood that in order to accurately determine whether an abnormality occurs in the loss function of the preset model, in this embodiment, it is also possible to monitor whether an abnormality occurs in the loss function value of the preset model based on whether the fluctuation value of the forward propagation loss value exceeds the preset first ratio threshold and / or whether the fluctuation value of the backward propagation gradient value exceeds the preset second ratio threshold. The preset first ratio threshold and the preset second ratio threshold can be preset according to the model training requirements.
[0110] Further, in order to improve the accuracy of the first calculation result, in this embodiment, the fluctuation value of the forward propagation loss value is calculated based on the average value of the forward propagation loss value. The step S1021′ includes:
[0111] The average value of the forward propagation loss value is calculated, and the average value of the forward propagation loss value is the moving average value or the rolling average value of the forward propagation loss value. The fluctuation value of the forward propagation loss value is calculated based on the average value of the forward propagation loss value to determine whether it exceeds a preset first ratio threshold value, and a first calculation result is obtained.
[0112] It is understandable that the average value of the forward propagation loss value can be obtained by cumulatively smoothing the forward propagation loss values in the previous period. In a specific implementation, the average value of the forward propagation loss value can be a moving average or a rolling average value of the forward propagation loss value, wherein the moving average smoothes the loss curve by calculating the average value of the loss value in the previous period; the rolling average is based on the exponential weighted average method, giving a higher weight to the latest loss value.
[0113] Furthermore, the step S1021' further includes:
[0114] The average value of the backward propagation gradient value is calculated, and the average value of the backward propagation gradient value is a moving average value or a rolling average value of the backward propagation gradient value. Whether the fluctuation value of the backward propagation gradient value exceeds a preset second ratio threshold value is calculated based on the average value of the backward propagation gradient value to obtain a second calculation result.
[0115] It should be understood that the average value of the back-propagation gradient value can be obtained by cumulatively smoothing the back-propagation gradient values in the previous period. In a specific implementation, the average value of the back-propagation gradient value can be a moving average value or a rolling average value of the back-propagation gradient value, wherein the moving average value smoothes the loss curve by calculating the average value of the loss value in the previous period; the rolling average value is based on the exponential weighted average method, giving a higher weight to the latest loss value.
[0116] Step S1022': monitor whether the loss function value of the preset model is abnormal according to the first calculation result and / or the second calculation result.
[0117] It can be understood that monitoring whether the loss function value of the preset model is abnormal according to the first calculation result and / or the second calculation result can be that when the fluctuation value of the forward propagation loss value exceeds the preset first proportional threshold, it is determined that the loss function value of the preset model is abnormal; it can also be that when the fluctuation value of the backward propagation gradient value exceeds the preset second proportional threshold, it is determined that the loss function value of the preset model is abnormal; it can also be that when the fluctuation value of the forward propagation loss value exceeds the preset first proportional threshold, and the fluctuation value of the backward propagation gradient value exceeds the preset second proportional threshold, it is determined that the loss function value of the preset model is abnormal, and this embodiment does not limit this.
[0118] This embodiment monitors whether there is an abnormality in the loss function value of the preset model based on whether the fluctuation value of the forward propagation loss value exceeds a preset first proportional threshold and / or whether the fluctuation value of the backward propagation gradient value exceeds a preset second proportional threshold, thereby being able to accurately determine whether there is an abnormality in the loss function of the preset model.
[0119] Based on the above embodiments, a fourth embodiment of the model training method of the present invention is proposed.
[0120] In a fourth embodiment, the model training method further includes:
[0121] When the number of abnormalities of the loss function value is greater than a preset number, reacquiring the training data set;
[0122] The preset model is retrained using the reacquired training data set.
[0123] It should be understood that when the number of abnormalities of the loss function value is greater than the preset number, it indicates that the quality of the training data set currently used for the preset model training is low and the model training effect is poor. Therefore, in order to overcome the above defects and improve the training effect of the preset model, in this embodiment, the number of abnormalities of the loss function value is also counted, and when the number of abnormalities is greater than the preset number, the training data set is re-acquired to retrain the preset model. Among them, the preset number can be pre-set, and this implementation does not limit this.
[0124] In a fourth embodiment, the model training method further includes:
[0125] Generate training anomaly logs based on skipped abnormal training data;
[0126] The training exception log is sent to the management terminal corresponding to the preset model.
[0127] It is understandable that, in order to facilitate the management of the model training process, in this embodiment, a training exception log is also generated based on the skipped abnormal training data, and the training exception log is sent to the management terminal corresponding to the preset model. Among them, the management terminal corresponding to the preset model can be pre-set. Of course, in order to facilitate viewing, in this embodiment, the training exception log can also be displayed directly on the model training device, and this embodiment does not limit this.
[0128] In addition, an embodiment of the present invention further proposes a storage medium, on which a model training program is stored. When the model training program is executed by a processor, the model training method as described above is implemented.
[0129] In addition, refer to Figure 5 , an embodiment of the present invention also proposes a model training device.
[0130] It should be understood that as the parameter scale of transformer-type language models continues to increase, the stability challenge of pre-training from 0 to 1 is also increasing. Compared with small models (for example: BERT model, GPT-2 model, etc.), large models (above 10B scale) are more prone to training failure during the pre-training process. The specific phenomenon is that the training loss function value is abnormal (for example: the loss function value diverges and does not converge, the loss function value fluctuates greatly (such as loss spikes)). In order to solve the above problems, the existing method is to manually observe the model training process. When an abnormality is observed in the model training process, the model training process is manually paused, and the abnormal training data that causes the model training abnormality is manually skipped, and then the model training is restarted.
[0131] However, the above method requires manual intervention in the model training process, which is time-consuming and labor-intensive, and reduces the efficiency of model training. In addition, the above method also requires pausing the model training process, resulting in a waste of training resources and increasing the cost of model training.
[0132] In order to overcome the above-mentioned defects, this embodiment automatically monitors the abnormality of the loss function value during the model training process, and automatically skips the abnormal training data when the loss function value is abnormal, so that the model training process does not require manual intervention and suspension of training, thereby improving the model training efficiency, avoiding waste of training resources, and reducing the model training cost.
[0133] In this embodiment, the model training device includes: a monitoring module 10 and a skipping module 20;
[0134] The monitoring module 10 is used to monitor whether the loss function value of the preset model is abnormal when the preset model is trained.
[0135] It is understandable that in this embodiment, the preset model is trained by a training data set. The training data set can be obtained from the Internet (for example, a public corpus, literary works, conversation data, and specific field data are obtained from the Internet as a training data set), or can be pre-customized according to model training requirements, which is not limited in this embodiment.
[0136] It should be understood that an abnormality in the loss function value of the preset model will result in the model being unable to be effectively optimized and converged. Therefore, in order to ensure the model training effect, in this embodiment, the loss function value of the preset model is monitored during the training process to see if there is an abnormality. Among them, the abnormality in the loss function value can be the divergence and non-convergence of the loss function value or the large fluctuation of the loss function value. The divergence and non-convergence of the loss function value means that the loss function value cannot steadily decrease or the loss function value continues to increase during the model training process; the large fluctuation of the loss function value refers to the temporary peak or abnormal value of the loss function value during the model training process.
[0137] Furthermore, in order to be able to process the input text, in this embodiment, the preset model may be a language model. In a specific implementation, the preset model is a language model built based on the Transformer architecture.
[0138] It should be understood that the preset model is a language model built based on the Transformer architecture. The preset model can receive the user's input text, parse the input text into a computer-understandable data format, and then use a pre-trained neural network model to generate response text.
[0139] In the specific implementation, the preset model uses the neural network in deep learning technology and is trained through a large amount of corpus data, so that it can learn the structure, grammatical rules and semantic information of the language. After the user enters the text, the preset model will first segment and parse the text, convert it into a computer-readable vector form, and then send it to the pre-trained neural network model for inference. During the inference process, the preset model will predict the most likely next response based on the text entered by the user and the previous context. This prediction process is based on the model's learning of a large amount of corpus data, so it can largely restore the way humans express natural language and generate highly coherent and natural response text. Finally, the preset model returns the generated response text to the user to complete a conversation interaction. Throughout the process, the preset model will continue to learn and optimize to provide more accurate and user-friendly answers.
[0140] The skipping module 20 is used to skip abnormal training data when the loss function value is abnormal, the abnormal training data being the training data that causes the loss function value to be abnormal, and continue training the preset model through the next training data corresponding to the abnormal training data.
[0141] It is understandable that when the loss function value is abnormal, it means that the model cannot be effectively optimized and converged when the model is trained with the current training data. Therefore, it is necessary to treat the current training data as abnormal training data and skip the abnormal training data. Among them, skipping the abnormal training data means skipping the step of optimizing the parameters of the preset model based on the loss function value corresponding to the abnormal training data, that is, the current training process does not update the parameters of the preset model.
[0142] It should be understood that in order to ensure the continuation of the model training process, in this embodiment, the preset model is further trained using the next training data corresponding to the abnormal training data, and the process returns to step S10 until the preset model training is completed.
[0143] Furthermore, the preset model after training can be applied to text processing scenarios, and the model training method also includes:
[0144] After the preset model training is completed, the text to be processed is obtained, and the text to be processed is input into the trained preset model to obtain the result text corresponding to the text to be processed.
[0145] The present invention discloses that when training a preset model, whether the loss function value of the preset model is abnormal is monitored. When the loss function value is abnormal, the abnormal training data is skipped, and the abnormal training data is the training data that causes the loss function value to be abnormal, and the preset model is continuously trained through the next training data corresponding to the abnormal training data. Since the present invention automatically monitors the abnormality of the loss function value during the model training process and automatically skips the abnormal training data when the loss function value is abnormal, the model training process does not require manual intervention and suspension of training, thereby improving the model training efficiency, avoiding the waste of training resources, and reducing the model training cost.
[0146] Other embodiments or specific implementations of the model training device of the present invention can refer to the above-mentioned method embodiments and will not be described in detail here.
[0147] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0148] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0149] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as a read-only memory image (ROM) / random access memory (RAM), a magnetic disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0150] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
[0151] The present invention discloses A1, a model training method, the model training method comprising:
[0152] When training the preset model, monitoring whether the loss function value of the preset model is abnormal;
[0153] When the loss function value is abnormal, the abnormal training data is skipped, the abnormal training data is the training data that causes the loss function value to be abnormal, and the preset model is continuously trained through the next training data corresponding to the abnormal training data.
[0154] A2. The model training method as described in A1, wherein when training the preset model, monitoring whether the loss function value of the preset model is abnormal comprises:
[0155] When training a preset model, obtaining a forward propagation loss value and / or a backward propagation gradient value of the preset model;
[0156] Monitor whether the loss function value of the preset model is abnormal based on the forward propagation loss value and / or the backward propagation gradient value.
[0157] A3. The model training method as described in A2, wherein the step of monitoring whether the loss function value of the preset model is abnormal according to the forward propagation loss value and / or the backward propagation gradient value comprises:
[0158] Determine whether the forward propagation loss value exceeds a preset loss function value to obtain a first determination result, and determine whether the backward propagation gradient value exceeds a preset gradient value to obtain a second determination result;
[0159] Monitor whether the loss function value of the preset model is abnormal based on the first judgment result and / or the second judgment result.
[0160] A4. The model training method as described in A2, wherein the step of monitoring whether the loss function value of the preset model is abnormal based on the forward propagation loss value and / or the backward propagation gradient value comprises:
[0161] Calculate whether the fluctuation value of the forward propagation loss value exceeds a preset first ratio threshold value to obtain a first calculation result, and calculate whether the fluctuation value of the backward propagation gradient value exceeds a preset second ratio threshold value to obtain a second calculation result;
[0162] Monitor whether the loss function value of the preset model is abnormal based on the first calculation result and / or the second calculation result.
[0163] A5. The model training method as described in A4, wherein the calculating whether the fluctuation value of the forward propagation loss value exceeds a preset first ratio threshold value to obtain a first calculation result comprises:
[0164] Calculate an average value of the forward propagation loss value, where the average value of the forward propagation loss value is a moving average value or a rolling average value of the forward propagation loss value;
[0165] Whether the fluctuation value of the forward propagation loss value exceeds a preset first ratio threshold is calculated according to the average value of the forward propagation loss value to obtain a first calculation result.
[0166] A6. The model training method as described in A4, wherein the step of calculating whether the fluctuation value of the backward propagation gradient value exceeds a preset second ratio threshold value to obtain a second calculation result comprises:
[0167] Calculating an average value of the backward propagation gradient value, wherein the average value of the backward propagation gradient value is a moving average value or a rolling average value of the backward propagation gradient value;
[0168] Whether the fluctuation value of the backward propagation gradient value exceeds a preset second ratio threshold is calculated according to the average value of the backward propagation gradient value to obtain a second calculation result.
[0169] A7. A model training method as described in any one of A1 to A6, wherein the preset model is a language model built based on the Transformer architecture.
[0170] A8. The model training method as described in any one of A1 to A6, wherein when the loss function value is abnormal, the preset model is continuously trained using the next training data corresponding to the abnormal training data, including:
[0171] When the loss function value is abnormal, selecting batch training data associated with the abnormal training data;
[0172] The batch training data is skipped, and the preset model is continuously trained through the next training data corresponding to the batch training data.
[0173] A9. The model training method as described in any one of A1 to A6, wherein the model training method further comprises:
[0174] When the number of abnormalities of the loss function value is greater than a preset number, reacquiring the training data set;
[0175] The preset model is retrained using the reacquired training data set.
[0176] A10. The model training method as described in any one of A1 to A6, wherein the model training method further comprises:
[0177] Generate training anomaly logs based on skipped abnormal training data;
[0178] The training exception log is sent to the management terminal corresponding to the preset model.
[0179] A11. The model training method as described in any one of A1 to A6, wherein the model training method further comprises:
[0180] After the preset model training is completed, obtaining the text to be processed;
[0181] The text to be processed is input into the trained preset model to obtain the result text corresponding to the text to be processed.
[0182] The present invention also discloses B12, a model training device, which includes: a memory, a processor, and a model training program stored in the memory and executable on the processor, wherein the model training program implements the model training method described above when executed by the processor.
[0183] The present invention also discloses C13, a storage medium, on which a model training program is stored, and when the model training program is executed by a processor, the model training method as described above is implemented.
[0184] The present invention also discloses D14, a model training device, the model training device comprising:
[0185] A monitoring module, used to monitor whether the loss function value of the preset model is abnormal when the preset model is trained;
[0186] The skipping module is used to skip abnormal training data when the loss function value is abnormal, wherein the abnormal training data is the training data that causes the loss function value to be abnormal, and continue to train the preset model through the next training data corresponding to the abnormal training data.
[0187] D15. In the model training device as described in D14, the monitoring module is further used to obtain the forward propagation loss value and / or the backward propagation gradient value of the preset model when training the preset model;
[0188] The monitoring module is also used to monitor whether the loss function value of the preset model is abnormal based on the forward propagation loss value and / or the backward propagation gradient value.
[0189] D16. In the model training device as described in D15, the monitoring module is further used to determine whether the forward propagation loss value exceeds a preset loss function value to obtain a first judgment result, and to determine whether the backward propagation gradient value exceeds a preset gradient value to obtain a second judgment result;
[0190] The monitoring module is further used to monitor whether the loss function value of the preset model is abnormal based on the first judgment result and / or the second judgment result.
[0191] D17, as described in D16, the model training device, the monitoring module is further used to calculate whether the fluctuation value of the forward propagation loss value exceeds a preset first ratio threshold value to obtain a first calculation result, and calculate whether the fluctuation value of the backward propagation gradient value exceeds a preset second ratio threshold value to obtain a second calculation result;
[0192] The monitoring module is further used to monitor whether the loss function value of the preset model is abnormal based on the first calculation result and / or the second calculation result.
[0193] D18. In the model training device as described in D17, the monitoring module is further used to calculate the average value of the forward propagation loss value, and the average value of the forward propagation loss value is a moving average value or a rolling average value of the forward propagation loss value;
[0194] The monitoring module is further used to calculate whether the fluctuation value of the forward propagation loss value exceeds a preset first ratio threshold value based on the average value of the forward propagation loss value, so as to obtain a first calculation result.
[0195] D19, in the model training device as described in D17, the monitoring module is further used to calculate the average value of the backward propagation gradient value, and the average value of the backward propagation gradient value is a moving average value or a rolling average value of the backward propagation gradient value;
[0196] The monitoring module is further used to calculate whether the fluctuation value of the backward propagation gradient value exceeds a preset second ratio threshold value according to the average value of the backward propagation gradient value, so as to obtain a second calculation result.
[0197] D20. In the model training device as described in any one of D14 to D19, the skip module is further used to select batch training data associated with the abnormal training data when the loss function value is abnormal;
[0198] The skip module is also used to skip the batch training data and continue to train the preset model through the next training data corresponding to the batch training data.
Claims
1. A model training method, characterized in that: The model training method comprises: When training the preset model, monitoring whether the loss function value of the preset model is abnormal; When the loss function value is abnormal, the abnormal training data is skipped, the abnormal training data is the training data that causes the loss function value to be abnormal, and the preset model is continuously trained through the next training data corresponding to the abnormal training data.
2. The model training method according to claim 1, characterized in that: When training the preset model, monitoring whether the loss function value of the preset model is abnormal includes: When training a preset model, obtaining a forward propagation loss value and / or a backward propagation gradient value of the preset model; Monitor whether the loss function value of the preset model is abnormal based on the forward propagation loss value and / or the backward propagation gradient value.
3. The model training method according to claim 2, characterized in that: The step of monitoring whether the loss function value of the preset model is abnormal according to the forward propagation loss value and / or the backward propagation gradient value includes: Determine whether the forward propagation loss value exceeds a preset loss function value to obtain a first determination result, and determine whether the backward propagation gradient value exceeds a preset gradient value to obtain a second determination result; Monitor whether the loss function value of the preset model is abnormal based on the first judgment result and / or the second judgment result.
4. The model training method according to claim 2, characterized in that: The step of monitoring whether the loss function value of the preset model is abnormal according to the forward propagation loss value and / or the backward propagation gradient value includes: Calculate whether the fluctuation value of the forward propagation loss value exceeds a preset first ratio threshold value to obtain a first calculation result, and calculate whether the fluctuation value of the backward propagation gradient value exceeds a preset second ratio threshold value to obtain a second calculation result; Monitor whether the loss function value of the preset model is abnormal based on the first calculation result and / or the second calculation result.
5. The model training method according to claim 4, characterized in that: The calculating whether the fluctuation value of the forward propagation loss value exceeds a preset first ratio threshold value to obtain a first calculation result includes: Calculate an average value of the forward propagation loss value, where the average value of the forward propagation loss value is a moving average value or a rolling average value of the forward propagation loss value; Whether the fluctuation value of the forward propagation loss value exceeds a preset first ratio threshold is calculated according to the average value of the forward propagation loss value to obtain a first calculation result.
6. The model training method according to claim 4, characterized in that: The calculating whether the fluctuation value of the backward propagation gradient value exceeds a preset second ratio threshold value to obtain a second calculation result includes: Calculating an average value of the backward propagation gradient value, wherein the average value of the backward propagation gradient value is a moving average value or a rolling average value of the backward propagation gradient value; Whether the fluctuation value of the backward propagation gradient value exceeds a preset second ratio threshold is calculated according to the average value of the backward propagation gradient value to obtain a second calculation result.
7. The model training method according to any one of claims 1 to 6, characterized in that: The preset model is a language model built based on the Transformer architecture.
8. A model training device, characterized in that: The model training device includes: a memory, a processor, and a model training program stored in the memory and executable on the processor. When the model training program is executed by the processor, the model training method according to any one of claims 1 to 7 is implemented.
9. A storage medium, characterized in that: The storage medium stores a model training program, and when the model training program is executed by the processor, it implements the model training method as described in any one of claims 1 to 7.
10. A model training device, characterized in that: The model training device comprises: A monitoring module, used to monitor whether the loss function value of the preset model is abnormal when the preset model is trained; The skipping module is used to skip abnormal training data when the loss function value is abnormal, wherein the abnormal training data is the training data that causes the loss function value to be abnormal, and continue to train the preset model through the next training data corresponding to the abnormal training data.