A training method, device and electronic device for a neural network model realizing continuous learning
By binarizing the historical floating-point weights of the neural network model and performing error calculation, the catastrophic forgetting problem of traditional neural networks is solved, and continuous learning and low-power neural network training are achieved.
Patent Information
- Application Number
- CN202110686037.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-21
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2041-06-21
AI Technical Summary
Traditional artificial neural networks will produce catastrophic forgetting when learning new knowledge and cannot achieve continuous learning. In addition, existing algorithms have high requirements for data accuracy, resulting in high energy consumption.
By obtaining the historical floating-point weights of the neural network model and performing binarization processing, the historical binary weights are determined, the historical binary weights are used to process the training samples to obtain the error, and the current actual floating-point weights are determined based on the error between the historical floating-point weights and the binary weights, and the floating-point weights of the neural network model are adjusted.
The neural network model is enabled to remember previously learned knowledge when learning new knowledge, reducing the risk of catastrophic forgetting and reducing power consumption during data processing.
Smart Images

Figure CN115511042B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of machine learning and artificial intelligence, and in particular to a training method, device and electronic equipment for a neural network model that implements continuous learning. Background Art
[0002] With the development of machine learning and artificial intelligence, research on deep neural networks that can achieve continuous learning has become increasingly in-depth. Continuous learning is an important deep learning function that refers to the ability to retain previously learned knowledge while learning new knowledge.
[0003] The human brain achieves continuous learning through complex biological systems such as the Hebbian rule and complementary learning systems. However, traditional artificial neural networks experience catastrophic forgetting when learning new knowledge. This occurs when the neural network parameters are overwritten and previously learned parameters are not retained, making continuous learning impossible.
[0004] Currently, there are a variety of algorithms that can avoid catastrophic forgetting and achieve continuous learning in data streams, but these algorithms have high requirements on data accuracy and need to use floating-point data.
[0005] However, implementing this continuous learning algorithm using traditional complementary metal oxide semiconductor (CMOS) circuit hardware requires complex circuit design and structure, resulting in high energy consumption. Furthermore, implementing it using new in-memory computing devices can hardly meet the required accuracy. These new in-memory computing devices have non-ideal characteristics and can currently only achieve 8-bit fixed-point accuracy, but cannot meet the required 32-bit floating-point accuracy. Furthermore, high-precision data processing requires high power consumption. Summary of the Invention
[0006] The purpose of the present invention is to provide a training method, device and electronic device for a neural network model that realizes continuous learning, so as to solve the problems of high storage capacity requirements and high data accuracy requirements of existing continuous learning algorithms.
[0007] In a first aspect, the present invention provides a training method for a neural network model for implementing continuous learning, comprising:
[0008] Get the historical floating-point weights of the neural network model;
[0009] Binarizing the historical floating-point weights to determine historical binary weights;
[0010] Processing training samples using the historical binary weights of the neural network model to obtain errors in the historical binary weights;
[0011] Determining a current actual floating-point weight based on an error between the historical floating-point weight and the historical binary weight;
[0012] The floating-point weights of the neural network model are adjusted according to the current actual floating-point weights.
[0013] Under the above technical solution, the training method of the neural network model for realizing continuous learning provided by the present invention can obtain the historical floating-point weights of the neural network model; binarize the historical floating-point weights to determine the historical binary weights; use the historical binary weights of the neural network model to process the training samples to obtain the error of the historical binary weights; determine the current actual floating-point weights based on the historical floating-point weights and the error of the historical binary weights; and adjust the floating-point weights of the neural network model according to the current actual floating-point weights. It can be seen that the method provided by the present invention introduces a mixed precision training method for binary neural networks, so that the neural network model can not only accurately identify the current task, but also remember the tasks learned before, thereby reducing the problem of catastrophic forgetting in the continuous learning process. Moreover, by adopting the method of the present invention, continuous learning of binary neural networks can be realized without circuit design, which can improve the robustness of the neural network model and reduce power consumption in the data processing process.
[0014] In a possible implementation, processing training samples using the historical binary weights of the neural network model to obtain errors of the historical binary weights includes:
[0015] Processing the training samples using the historical binary weights of the neural network model to obtain sample loss;
[0016] An error of the historical binary weight is determined according to the sample loss.
[0017] In a possible implementation, determining the current actual floating-point weight based on the error between the historical floating-point weight and the historical binary weight includes:
[0018] In a case where the error of the historical binary weight has the same sign as the historical binary weight, the sum of the historical floating-point weight and the error of the historical binary weight is determined as the current actual floating-point weight.
[0019] In a possible implementation, determining the current actual floating-point weight based on the error between the historical floating-point weight and the historical binary weight includes:
[0020] When the error of the historical binary weight and the historical binary weight have opposite signs and the error of the historical binary weight is less than a weight error threshold, the sum of the historical floating-point weight and the error of the historical binary weight is determined to be the current actual floating-point weight.
[0021] In a possible implementation, determining the current actual floating-point weight based on the error between the historical floating-point weight and the historical binary weight includes:
[0022] When the error of the historical binary weight and the historical binary weight have opposite signs and the binarized weight is greater than a weight error threshold, obtaining an error weight preset value corresponding to the error of the historical binary weight;
[0023] The sum of the historical floating-point weight and the error weight preset value is determined as the current actual floating-point weight.
[0024] In one possible implementation, if the loss function of the neural network model converges, adjusting the floating-point weights of the neural network model according to the current actual floating-point weights includes:
[0025] The floating-point weights of the neural network model are the current actual floating-point weights.
[0026] In one possible implementation, if the loss function of the neural network model has not converged, adjusting the floating-point weights of the neural network model according to the current actual floating-point weights includes:
[0027] The initial floating-point weights of the neural network model are updated according to the current actual floating-point weights.
[0028] In a second aspect, the present invention further provides a training device for a neural network model that implements continuous learning, the device comprising:
[0029] The acquisition module is used to obtain the historical floating-point weights of the neural network model;
[0030] A first determining module is used to perform binarization processing on the historical floating-point weights to determine the historical binary weights;
[0031] An acquisition module, configured to process training samples using the historical binary weights of the neural network model to obtain an error of the historical binary weights;
[0032] A second determining module is configured to determine a current actual floating-point weight based on an error between the historical floating-point weight and the historical binary weight;
[0033] An adjustment module is used to adjust the floating-point weights of the neural network model according to the current actual floating-point weights.
[0034] In a possible implementation, the obtaining module includes:
[0035] An acquisition submodule, configured to process training samples using the historical binary weights of the neural network model to obtain sample loss;
[0036] The first determination submodule is configured to determine an error of the historical binary weight according to the sample loss.
[0037] In a possible implementation, the second determining module includes:
[0038] The second determining submodule is configured to determine, when the error of the historical binary weight and the historical binary weight have the same sign, that the sum of the error of the historical floating-point weight and the historical binary weight is the current actual floating-point weight.
[0039] In a possible implementation, the second determining module includes:
[0040] The third determination submodule is used to determine that the sum of the errors of the historical floating-point weight and the historical binary weight is the current actual floating-point weight when the errors of the historical binary weight and the historical binary weight have opposite signs and the errors of the historical binary weight are less than the weight error threshold.
[0041] In a possible implementation, the second determining module includes:
[0042] an acquisition submodule, configured to acquire an error weight preset value corresponding to the error of the historical binary weight when the error of the historical binary weight and the historical binary weight have opposite signs and the error of the historical binary weight is greater than a weight error threshold;
[0043] The fourth determining submodule is configured to determine the sum of the historical floating-point weight and the preset error weight as the current actual floating-point weight.
[0044] In one possible implementation, if the loss function of the neural network model converges, the adjustment module includes:
[0045] A fifth determination submodule, wherein the floating-point weights for the neural network model are the current actual floating-point weights.
[0046] In one possible implementation, if the loss function of the neural network model does not converge, the adjustment module includes:
[0047] An updating submodule is used to update the initial floating-point weights of the neural network model according to the current actual floating-point weights.
[0048] The beneficial effects of the training device for a neural network model that implements continuous learning provided by the second aspect are the same as the beneficial effects of the training method for a neural network model that implements continuous learning described in the first aspect or any possible implementation of the first aspect, and are not repeated here.
[0049] In a third aspect, the present invention also provides an electronic device comprising: one or more processors; and one or more machine-readable media having instructions stored thereon, which, when executed by the one or more processors, enables the device to execute the training device for a neural network model that implements continuous learning as described in any possible implementation method of the second aspect.
[0050] The beneficial effects of the electronic device provided in the third aspect are the same as the beneficial effects of the training device for the neural network model for continuous learning described in the second aspect or any possible implementation of the second aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0052] Figure 1 A schematic diagram of the structure of an artificial intelligence processing device provided in an embodiment of the present application is shown;
[0053] Figure 2 A flow chart of a training method for a neural network model for continuous learning provided in an embodiment of the present application is shown;
[0054] Figure 3 A flow chart of another method for training a neural network model for continuous learning provided by an embodiment of the present application is shown;
[0055] Figure 4 A schematic diagram of data set segmentation provided in an embodiment of the present application is shown;
[0056] Figure 5 A structural flow chart of a training device for a neural network model that implements continuous learning, provided in an embodiment of the present application, is shown;
[0057] Figure 6 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present invention;
[0058] Figure 7 A schematic diagram of the structure of a chip provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0059] To facilitate a clear description of the technical solutions of the embodiments of the present invention, the words "first" and "second" are used in the embodiments of the present invention to distinguish between identical or similar items with substantially the same functions and effects. For example, the first threshold and the second threshold are merely used to distinguish between different thresholds and do not limit their order. Those skilled in the art will understand that the words "first" and "second" do not limit the quantity or execution order, and the words "first" and "second" do not necessarily mean different.
[0060] It should be noted that, in the present invention, words such as "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design described as "exemplary" or "for example" in the present invention should not be construed as being preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplary" or "for example" is intended to present the relevant concepts in a concrete manner.
[0061] In the present invention, "at least one" refers to one or more, and "more" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: the existence of A alone, the existence of A and B at the same time, and the existence of B alone, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following items" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b or c can represent: a, b, c, the combination of a and b, the combination of a and c, the combination of b and c, or the combination of a, b and c, where a, b, c can be single or multiple.
[0062] An embodiment of the present invention provides an artificial intelligence processing device, Figure 1 A schematic diagram of the structure of an artificial intelligence processing device provided in an embodiment of the present application is shown. Figure 1 As shown: the artificial intelligence processing device 01 includes an artificial intelligence processor 01A and a storage unit 01B communicatively connected to the artificial intelligence processor 01A, and also includes an interface component 01C communicatively connected to the artificial intelligence processor 01A and the storage unit 01B respectively, wherein the storage unit 01B stores an instruction set, and the artificial intelligence processor 01A can implement a learning process of the instruction set based on the instruction set and the control of the interface component 01C.
[0063] Among the built-in data types of the instruction set architecture (ISA), floating-point numbers are in binary format. Floating-point numbers represent real numbers, and their numerical range is determined by the exponent, resulting in a very wide value range. The closer the value is to zero, the more accurate it is.
[0064] Figure 2 A flow chart of a training method for a neural network model for continuous learning provided in an embodiment of the present application is shown. Figure 2 As shown, the training method of the neural network model includes:
[0065] Step 101: Obtain historical floating-point weights of the neural network model.
[0066] In the present application, the neural network model can be a convolutional neural network, a fully connected neural network, or other types of neural networks, which are not specifically limited in the embodiments of the present application. The architecture of the neural network model is diverse and can be based on the ResNet network architecture, the VGG network architecture, the YOLO architecture, etc. Of course, it can also be an architecture designed according to actual conditions. For example: the neural network model includes a task input layer, a fully connected layer, and a prediction output layer that are sequentially connected in communication. The neural network model can be trained by continuous learning to achieve correct recognition of the re-input task.
[0067] In the present application, the fully connected layer includes a first fully connected layer, a second fully connected layer and a third fully connected layer, wherein the task input and output layer includes 784 neurons, the first fully connected layer and the second fully connected layer each include 256 neurons, the prediction output layer includes 10 neurons, and each fully connected layer adopts the method of the present invention.
[0068] Step 102: Binarize the historical floating-point weights to determine the historical binary weights.
[0069] In the process of forward propagation of neural networks, a sign function is usually used as the weight binarization function.
[0070] W b =sign(W h ).
[0071] Among them, x and W h Represents historical floating point weights, y and W b represents the historical binary weight, and sign(·) is the binary sign function.
[0072] After obtaining the historical binary weights, the historical binary weights can be used as weights for the forward propagation of the neural network model. In this application, the activation function uses a symbolic function, and the training data corresponding to the current task can be forward propagated through the fully connected layer, normalization layer, and activation function layer in sequence. The output of the last fully connected layer passes through the output function.
[0073] The output function may be: y = Softmax(x);
[0074] Where y represents the output value, and x represents the net activity value of the last fully connected layer corresponding to the current task. In other words, the value of the i-th output neuron can be:
[0075]
[0076] Among them, y i represents the output value of the i-th output neuron, x i Represents the net activity value of the i-th neuron corresponding to the current task.
[0077] Step 103: Process the training samples using the historical binary weights of the neural network model to obtain the error of the historical binary weights.
[0078] Among them, the training data can be forward propagated on the neural network with historical binary weights, the error can be calculated through the cross entropy function, and the update amount of the binary weights can be obtained. In other words, the historical binary weights of the neural network model can be used to process the training samples to obtain the error of the historical binary weights. After the training data corresponding to the current task completes a forward and backward propagation, the cross entropy function can be used to calculate the error of the historical binary weights (ΔW h ). Specifically, the specific implementation process of the above step 103 may include the following sub-steps:
[0079] Sub-step S1: Initialize the neural network model weights as floating-point weights to obtain initial floating-point weights, and binarize the initial floating-point weights to obtain historical binary weights.
[0080] Sub-step S2: Use the forward propagation of the neural network with historical binary weights to calculate the error, and calculate the update amount of the historical binary weights based on the loss. You can use y = Hardtanh (x) as the activation function to derive the data. Where, x represents input data and y represents output data.
[0081] Step 104: Determine the current actual floating-point weight based on the error between the historical floating-point weight and the historical binary weight.
[0082] In an optional embodiment provided by the present invention, when the error of the historical binary weight and the historical binary weight have the same sign, the sum of the historical floating-point weight and the error of the historical binary weight is determined to be the current actual floating-point weight.
[0083] In another embodiment provided by the embodiments of the present invention, when the error of the historical binary weight and the historical binary weight have opposite signs and the error of the historical binary weight is less than the weight error threshold, the sum of the errors of the historical floating-point weight and the historical binary weight is determined to be the current actual floating-point weight.
[0084] Among them, the weight error threshold can be: Where ΔW hmax It means W h The maximum update amount, m represents the memory coefficient, and ε represents the minimum value, which prevents the denominator from being 0.
[0085] In another embodiment provided by the embodiment of the present invention, when the error of the historical binary weight and the historical binary weight have opposite signs and the historical binary weight is greater than the weight error threshold, the error weight preset value corresponding to the error of the historical binary weight is obtained;
[0086] The sum of the historical floating point weight and the error weight preset value is determined to be the current actual floating point weight.
[0087] Step 105: Adjust the floating-point weights of the neural network model according to the current actual floating-point weights.
[0088] In an optional embodiment provided by an embodiment of the present invention, the loss function of the neural network model converges, and the floating-point weights of the neural network model are determined to be the current actual floating-point weights.
[0089] In another optional embodiment provided by the embodiment of the present invention, if the loss function of the neural network model has not converged, the historical floating-point weights of the neural network model are updated according to the current actual floating-point weights.
[0090] After learning the current task, continue to learn the next task. At this time, there is no need to re-initialize the floating-point weights of the neural network model. The current task is updated to the historical floating-point weights after learning. Then the above method steps are looped. When the next task arrives, the actual floating-point weights are determined based on the historical floating-point weights. That is, accurate recognition of the current task can be achieved, and the previously learned tasks can be remembered, so that continuous learning of the binary neural network can be achieved, the robustness of the neural network can be improved, and the power consumption during data processing can be reduced.
[0091] The training method of the neural network model for realizing continuous learning provided by the embodiment of the present invention can obtain the historical floating-point weights of the neural network model; binarize the historical floating-point weights to determine the historical binary weights; use the historical binary weights of the neural network model to process the training samples to obtain the error of the historical binary weights; determine the current actual floating-point weights based on the historical floating-point weights and the error of the historical binary weights; and adjust the floating-point weights of the neural network model according to the current actual floating-point weights. It can be seen that the method provided by the present invention introduces a training method of mixed precision of binary neural networks, so that the neural network model can not only accurately identify the current task, but also remember the tasks learned before, thereby avoiding the problem of catastrophic forgetting in the continuous learning process. In addition, the method of the present invention can realize continuous learning of binary neural networks without circuit design, improve the robustness of the neural network model, and reduce power consumption in the data processing process.
[0092] Optional, Figure 3 A flow chart showing another method for training a neural network model for continuous learning provided by an embodiment of the present application is shown. Figure 3 , the training method of the neural network model for realizing continuous learning includes:
[0093] Step 201: Obtain historical floating-point weights of the neural network model.
[0094] In the present application, the neural network model can be a convolutional neural network, a fully connected neural network, or other types of neural networks, and the embodiments of the present application do not specifically limit this.
[0095] The neural network model includes a task input layer, a first fully connected layer, a second fully connected layer, a third fully connected layer and a prediction output layer that are sequentially connected. The neural network model can be trained through continuous learning to achieve correct recognition of re-input tasks.
[0096] In the present application, the fully connected layer includes a first fully connected layer, a second fully connected layer and a third fully connected layer, wherein the task input and output layer includes 784 neurons, the first fully connected layer and the second fully connected layer each include 256 neurons, the prediction output layer includes 10 neurons, and each fully connected layer adopts the method of the present invention.
[0097] Among the built-in data types of the instruction set architecture (ISA), floating-point numbers are in binary format. Floating-point numbers represent real numbers, and their numerical range is determined by the exponent, resulting in a very wide value range. The closer the value is to zero, the more accurate it is.
[0098] In this application, historical floating-point weights refer to the floating-point weights corresponding to the neural network model's recognition of the previous input task.
[0099] When the current task arrives, the historical floating-point weights of the initial neural network model can be obtained. If the current task is the first task, the floating-point weights of the neural network model can be initialized first, and the initialized floating-point weights are used as the historical floating-point weights.
[0100] When the current task is not the first task, the floating-point weight of the previous task of the neural network model can be obtained as the historical floating-point weight.
[0101] The input data set can be divided into multiple tasks in a segmentation manner. For example, when the input data set is the MNIST data set, it can be divided into 5 tasks in sequence.
[0102] It should be noted that, in the present application, the input data set may be voice data, image data, text data, etc., and the embodiments of the present application do not make specific limitations on this.
[0103] Step 202: Binarize the historical floating-point weights to determine the historical binary weights.
[0104] In the process of forward propagation of neural networks, a sign function is usually used as the weight binarization function.
[0105]
[0106] W b =sign(W h );
[0107] Among them, x and W h Both represent historical floating point weights, y and W b Both represent historical binary weights.
[0108] After obtaining the historical binary weights, the historical binary weights can be used as weights for the forward propagation of the neural network model. In this application, the activation function uses a symbolic function, and the training data corresponding to the current task can be forward propagated through the fully connected layer, normalization layer, and activation function layer in sequence. The output of the last fully connected layer passes through the output function.
[0109] Among them, the output function can be:
[0110] y = Softmax(x);
[0111] Among them, y represents the output value, and x represents the net activity value of the last fully connected layer of the current task.
[0112] That is, the value of the i-th output neuron can be:
[0113]
[0114] Among them, y i represents the output value of the i-th output neuron, x i Represents the net activity value of the i-th neuron corresponding to the current task.
[0115] Step 203: Process the training samples using the historical binary weights of the neural network model to obtain the sample loss.
[0116] In this application, the training data can be forward propagated on a neural network with historical binary weights, the error can be calculated by the cross entropy function, and the update amount of the binary weights can be obtained. In other words, the historical binary weights of the neural network model can be used to process the training samples to obtain the error of the historical binary weights. After the training data corresponding to the current task completes a forward and backward propagation, the cross entropy function can be used to calculate the error of the historical binary weights (ΔW h ).
[0117] In this application, the weights of the neural network model can be initialized as floating-point weights to obtain historical floating-point weights, and the historical floating-point weights can be binarized to obtain historical binary weights. The error can be calculated by forward propagation of the neural network with historical binary weights, and the update amount of the historical binary weights can be calculated based on the loss, that is, the error of the historical binary weights is calculated.
[0118] Step 204: Determine the error of the historical binary weights based on the sample loss.
[0119] After the training data corresponding to the current task completes a forward and backward propagation, the cross entropy function can be used to calculate the error of the historical binary weight (ΔW h ).
[0120] In the present application, in the process of calculating the error of the historical binary weight using the cross entropy function, y=Hardtanh(x) can be used as the activation function to derive the data.
[0121] in,
[0122] In the above formula, x represents input data and y represents output data.
[0123] Step 205: Determine the current actual floating-point weight based on the error between the historical floating-point weight and the historical binary weight.
[0124] In an optional embodiment provided by the present invention, when the error of the historical binary weight and the historical binary weight have the same sign, the sum of the historical floating-point weight and the error of the historical binary weight is determined to be the current actual floating-point weight.
[0125] In another embodiment provided by the embodiments of the present invention, when the error of the historical binary weight and the historical binary weight have opposite signs and the error of the historical binary weight is less than the weight error threshold, the sum of the errors of the historical floating-point weight and the historical binary weight is determined to be the current actual floating-point weight.
[0126] Among them, the weight error threshold can be: Where ΔW hmax It means W h The maximum update amount, m represents the memory coefficient, and ε represents the minimum value, which prevents the denominator from being 0.
[0127] In another embodiment provided by the embodiment of the present invention, when the error of the historical binary weight and the historical binary weight have opposite signs and the error of the historical binary weight is greater than the weight error threshold, a preset error weight value corresponding to the error of the historical binary weight is obtained;
[0128] The sum of the historical floating point weight and the error weight preset value is determined to be the current actual floating point weight.
[0129] Step 206: Adjust the floating-point weights of the neural network model according to the current actual floating-point weights.
[0130] In an optional embodiment provided by an embodiment of the present invention, the loss function of the neural network model converges, and the floating-point weights of the neural network model are determined to be the current actual floating-point weights.
[0131] In another optional embodiment provided by the embodiment of the present invention, if the loss function of the neural network model has not converged, the initial floating-point weights of the neural network model are updated according to the current actual floating-point weights.
[0132] The neural network model trained using the embodiment of the present application can accurately identify the current task and remember previously learned tasks, thereby realizing continuous learning of the binary neural network, improving the robustness of the neural network model, and reducing power consumption during data processing.
[0133] In this application, the historical floating-point weights may refer to the floating-point weights trained by the neural network model in the last input. Of course, they may also refer to the floating-point weights trained by any historical input of the neural network model.
[0134] When the current task is not the first task, the floating-point weight of the previous task of the neural network model can be obtained as the historical floating-point weight.
[0135] Among them, the input data set can be divided into multiple tasks by segmentation. Figure 4 A schematic diagram of data set segmentation provided in an embodiment of the present application is shown, Figure 4As shown, the MNIST dataset can be divided into five tasks X. The neural network model learns one task at a time. When learning the current task, only the training data corresponding to the current task is provided, and the training data of the historical tasks is not provided. This can reduce the requirements for storage capacity and reduce power consumption during training.
[0136] See also Figure 4 When processing a dataset divided into five tasks, the historical floating-point weights of the neural network model can be obtained when the current task arrives. If the current task is the first task, the floating-point weights of the neural network model can be initialized first and the initialized floating-point weights are used as the historical floating-point weights.
[0137] Furthermore, the training method of the present application is used to obtain the floating-point weight corresponding to the first task, and the floating-point weight corresponding to the first task is updated to the historical floating-point weight. When the second task arrives, the next task is continued to be learned. At this time, there is no need to re-initialize the floating-point weight of the neural network model. The current task is updated to the historical floating-point weight after learning, and the above method steps are looped until the fifth task is processed. In this process, when the next task arrives, the actual floating-point weight is determined based on the historical floating-point weight, that is, accurate recognition of the current task can be achieved, and the previously learned tasks can be memorized, realizing continuous learning of the binary neural network, improving the robustness of the neural network, and reducing power consumption during data processing.
[0138] The training method of the neural network model for realizing continuous learning provided by the embodiment of the present invention can obtain the historical floating-point weights of the neural network model; binarize the historical floating-point weights to determine the historical binary weights; use the historical binary weights of the neural network model to process the training samples to obtain the error of the historical binary weights; determine the current actual floating-point weights based on the historical floating-point weights and the error of the historical binary weights; and adjust the floating-point weights of the neural network model according to the current actual floating-point weights. It can be seen that the method provided by the present invention introduces a training method of mixed precision of binary neural networks, so that the neural network model can not only accurately identify the current task, but also remember the tasks learned before, thereby avoiding the problem of catastrophic forgetting in the continuous learning process. Moreover, by adopting the method of the present invention, continuous learning of binary neural networks can be realized without circuit design, which can improve the robustness of the neural network model and reduce power consumption in the data processing process.
[0139] Figure 5 A schematic diagram of the structure of a training device for a neural network model for continuous learning provided by an embodiment of the present application is shown. Figure 5 As shown, the training device 300 for the neural network model implementing continuous learning includes:
[0140] An acquisition module 301 is used to obtain historical floating-point weights of a neural network model;
[0141] A first determining module 302 is configured to perform binarization processing on the historical floating point weights to determine the historical binary weights;
[0142] An acquisition module 303 is used to process the training samples using the historical binary weights of the neural network model to obtain the error of the historical binary weights;
[0143] A second determination module 304 is configured to determine a current actual floating-point weight based on an error between the historical floating-point weight and the historical binary weight;
[0144] The adjustment module 305 is used to adjust the floating-point weights of the neural network model according to the current actual floating-point weights.
[0145] Optionally, the acquisition module includes:
[0146] The first acquisition submodule is used to process the training samples using the historical binary weights of the neural network model to obtain the sample loss;
[0147] The second acquisition submodule is used to determine the error of the historical binary weights based on the sample loss.
[0148] Optionally, the first obtaining submodule includes:
[0149] Optionally, modules are available including:
[0150] Obtain a submodule for processing training samples using the historical binary weights of the neural network model to obtain sample loss;
[0151] The first determination submodule is used to determine the error of the historical binary weight according to the sample loss.
[0152] In a possible implementation, the second determining module includes:
[0153] The second determination submodule is used to determine the sum of the historical floating-point weight and the error of the historical binary weight as the current actual floating-point weight when the error of the historical binary weight and the historical binary weight have the same sign.
[0154] Optionally, the second determining module includes:
[0155] The third determination submodule is used to determine that the sum of the errors of the historical floating-point weight and the historical binary weight is the current actual floating-point weight when the errors of the historical binary weight and the historical binary weight have opposite signs and the errors of the historical binary weight are less than the weight error threshold.
[0156] Optionally, the second determining module includes:
[0157] An acquisition submodule, configured to obtain a preset error weight value corresponding to the error of the historical binary weight when the error of the historical binary weight and the historical binary weight have opposite signs and the error of the historical binary weight is greater than a weight error threshold;
[0158] The fourth determining submodule is used to determine the sum of the historical floating-point weight and the error weight preset value as the current actual floating-point weight.
[0159] Optionally, if the loss function of the neural network model converges, the adjustment module includes:
[0160] The fifth determination submodule uses the floating-point weights of the neural network model as the current actual floating-point weights.
[0161] Optionally, if the loss function of the neural network model does not converge, the adjustment module includes:
[0162] The update submodule is used to update the initial floating-point weights of the neural network model according to the current actual floating-point weights.
[0163] After learning the current task, continue to learn the next task. At this time, there is no need to re-initialize the floating-point weights of the neural network model. The current task is updated to the historical floating-point weights after learning. Then the above method steps are looped. When the next task arrives, the actual floating-point weights are determined based on the historical floating-point weights. That is, accurate recognition of the current task can be achieved, and the previously learned tasks can be remembered, so that continuous learning of the binary neural network can be achieved, the robustness of the neural network can be improved, and the power consumption during data processing can be reduced.
[0164] The training device for a neural network model that implements continuous learning provided by an embodiment of the present invention can obtain the historical floating-point weights of the neural network model; binarize the historical floating-point weights to determine the historical binary weights; use the historical binary weights of the neural network model to process training samples to obtain the error of the historical binary weights; determine the current actual floating-point weights based on the historical floating-point weights and the error of the historical binary weights; and adjust the floating-point weights of the neural network model according to the current actual floating-point weights. It can be seen that the method provided by the present invention introduces a training method for binary neural networks with mixed precision, so that the neural network model can not only accurately identify the current task, but also remember previously learned tasks, thereby reducing the problem of catastrophic forgetting that occurs during continuous learning. Moreover, by adopting the method of the present invention, continuous learning of binary neural networks can be achieved without circuit design, which can improve the robustness of the neural network model and reduce power consumption during data processing.
[0165] The present invention provides a training device for a neural network model for realizing continuous learning, which is applied to a system including a controller and at least one detection circuit electrically connected to the controller. Figures 1 to 4To avoid repetition, the training method of any of the neural network models shown to implement continuous learning will not be described here.
[0166] The electronic device in the embodiments of the present invention may be a device, or a component, integrated circuit, or chip in a terminal. The device may be a mobile electronic device or a non-mobile electronic device. For example, the mobile electronic device may be a mobile phone, tablet computer, laptop computer, PDA, in-vehicle electronic device, wearable device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc. The non-mobile electronic device may be a server, network attached storage (NAS), personal computer (PC), television (TV), ATM, or self-service machine, etc., and the embodiments of the present invention do not specifically limit this.
[0167] The electronic device in the embodiment of the present invention may be a device having an operating system. The operating system may be an Android operating system, an iOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present invention.
[0168] Figure 6 FIG1 shows a hardware structure diagram of an electronic device provided by an embodiment of the present invention. Figure 5 As shown, the electronic device 400 includes a processor 410 .
[0169] like Figure 6 As shown, the processor 410 may be a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the present invention.
[0170] like Figure 6 As shown, the electronic device 400 may further include a communication line 440. The communication line 440 may include a path for transmitting information between the components.
[0171] Optional, such as Figure 6 As shown, the electronic device may further include a communication interface 420. There may be one or more communication interfaces 420. The communication interface 420 may use any transceiver or other device for communicating with other devices or a communication network.
[0172] Optional, such as Figure 6 As shown, the electronic device may further include a memory 430. The memory 430 is used to store computer-executable instructions for executing the solution of the present invention, and is controlled by the processor to execute the computer-executable instructions stored in the memory, thereby implementing the method provided by the embodiment of the present invention.
[0173] like Figure 6 As shown, the memory 430 can be a read-only memory (ROM) or other type of static storage device that can store static information and instructions, a random access memory (RAM) or other type of dynamic storage device that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, an optical disc storage (including a compact disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory 430 can exist independently and be connected to the processor 410 via a communication line 440. The memory 430 can also be integrated with the processor 410.
[0174] Optionally, the computer-executable instructions in the embodiment of the present invention may also be referred to as application program codes, which is not specifically limited in the embodiment of the present invention.
[0175] In a specific implementation, as an embodiment, Figure 6 As shown, the processor 410 may include one or more CPUs, such as Figure 6 CPU0 and CPU1 in.
[0176] In a specific implementation, as an embodiment, Figure 6 As shown, the terminal device may include multiple processors, such as Figure 6 The first processor 4101 and the second processor 4102 in the embodiment of the present invention are shown in FIG. Each of these processors can be a single-core processor or a multi-core processor.
[0177] Figure 7 FIG. 1 is a schematic diagram of the structure of the chip provided by an embodiment of the present invention. Figure 7 As shown, the chip 500 includes one or more (including two) processors 410 .
[0178] Optional, such as Figure 7 As shown, the chip also includes a communication interface 420 and a memory 430. The memory 430 may include a read-only memory and a random access memory, and provides operation instructions and data to the processor. A portion of the memory may also include a non-volatile random access memory (NVRAM).
[0179] In some embodiments, as Figure 7 As shown, the memory 430 stores the following elements, execution modules or data structures, or a subset thereof, or an extended set thereof.
[0180] In the embodiment of the present invention, Figure 7 As shown, corresponding operations are performed by calling an operation instruction stored in a memory (the operation instruction may be stored in an operating system).
[0181] like Figure 7 As shown, the processor 410 controls the processing operations of any one of the terminal devices. The processor 410 may also be referred to as a central processing unit (CPU).
[0182] like Figure 7 As shown, the memory 430 may include a read-only memory and a random access memory, and provides instructions and data to the processor. A portion of the memory 430 may also include NVRAM. For example, in an application, the memory, the communication interface, and the memory are coupled together through a bus system, wherein the bus system may include a power bus, a control bus, and a status signal bus in addition to a data bus. However, for the sake of clarity, the following are not used in the following text: Figure 7 Various buses are labeled as bus system 540 .
[0183] like Figure 7As shown, the methods disclosed in the above embodiments of the present invention can be applied to or implemented by a processor. The processor may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by hardware integrated logic circuits in the processor or by software instructions. The above processor may be a general-purpose processor, a digital signal processor (DSP), an ASIC, a field-programmable gate array (FPGA), or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component. The methods, steps, and logic block diagrams disclosed in the embodiments of the present invention can be implemented or executed. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of the present invention can be directly implemented and executed by a hardware decoding processor or by a combination of hardware and software modules in the decoding processor. The software modules can be located in a storage medium well-known in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. The storage medium is located in a memory, and the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above method.
[0184] On the one hand, a computer-readable storage medium is provided, in which instructions are stored. When the instructions are executed, the functions performed by the terminal device in the above embodiment are implemented.
[0185] On the one hand, a chip is provided, which is applied to a terminal device. The chip includes at least one processor and a communication interface. The communication interface is coupled to at least one processor, and the processor is used to run instructions to implement the functions performed by the training method of the neural network model for implementing continuous learning in the above embodiment.
[0186] In the above embodiments, all or part of the embodiments may be implemented using software, hardware, firmware, or any combination thereof. When implemented using software, all or part of the embodiments may be implemented in the form of a computer program product. The computer program product includes one or more computer programs or instructions. When the computer programs or instructions are loaded and executed on a computer, the processes or functions described in the embodiments of the present invention are performed in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, a terminal, a user device, or other programmable device. The computer program or instructions may be stored in a computer-readable storage medium or transferred from one computer-readable storage medium to another. For example, the computer program or instructions may be transferred from one website, computer, server, or data center to another website, computer, server, or data center via wired or wireless means. The computer-readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server or data center that integrates one or more available media. The available medium may be a magnetic medium, such as a floppy disk, hard disk, or magnetic tape; an optical medium, such as a digital video disc (DVD); or a semiconductor medium, such as a solid-state drive (SSD).
[0187] Although the present invention is described herein in conjunction with various embodiments, in the process of implementing the claimed invention, those skilled in the art can understand and implement other variations of the disclosed embodiments by reviewing the drawings, the disclosure, and the appended claims. In the claims, the word "comprising" does not exclude other components or steps, and "a" or "an" does not exclude multiple situations. A single processor or other unit can implement several functions listed in the claims. Certain measures are recorded in different dependent claims, but this does not mean that these measures cannot be combined to produce good results.
[0188] Although the present invention has been described with reference to specific features and embodiments thereof, it will be apparent that various modifications and combinations may be made thereto without departing from the spirit and scope of the invention. Accordingly, this specification and drawings are merely illustrative of the invention as defined by the appended claims and are deemed to cover any and all modifications, variations, combinations or equivalents within the scope of the invention. It will be apparent that various modifications and variations may be made to the present invention by those skilled in the art without departing from the spirit and scope of the invention. Thus, the present invention is intended to include such modifications and variations as fall within the scope of the claims of the present invention and their equivalents.
Claims
1. A training method for a neural network model for continuous learning, characterized in that: include: Obtaining historical floating-point weights of a neural network model, wherein an input data set of the neural network model is divided into training data of a plurality of input tasks; wherein the historical floating-point weights are floating-point weights corresponding to a previous input task recognized by the neural network model or initialized floating-point weights; and the input data set includes any one of speech data, image data, and text data; Binarizing the historical floating-point weights to determine historical binary weights; The binarization process is achieved by the following formula: , ; Among them, x and W h Represents historical floating point weights, y and W b represents the historical binary weight, sign(·) is the binary sign function; Forward propagating the training data on a neural network with historical binary weights, calculating the error using a cross entropy function, and obtaining the error of the historical binary weights; Determining a current actual floating-point weight based on an error between the historical floating-point weight and the historical binary weight; The floating-point weights of the neural network model are adjusted according to the current actual floating-point weights.
2. The method according to claim 1, characterized in that The determining of the current actual floating-point weight based on the error between the historical floating-point weight and the historical binary weight includes: In a case where the error of the historical binary weight has the same sign as the historical binary weight, the sum of the historical floating-point weight and the error of the historical binary weight is determined as the current actual floating-point weight.
3. The method according to claim 1, characterized in that The determining of the current actual floating-point weight based on the error between the historical floating-point weight and the historical binary weight includes: When the error of the historical binary weight and the historical binary weight have opposite signs and the error of the historical binary weight is less than a weight error threshold, the sum of the historical floating-point weight and the error of the historical binary weight is determined to be the current actual floating-point weight.
4. The method according to claim 1, wherein The determining of the current actual floating-point weight based on the error between the historical floating-point weight and the historical binary weight includes: When the error of the historical binary weight and the historical binary weight have opposite signs and the error of the historical binary weight is greater than the weight error threshold, obtaining a preset error weight value corresponding to the error of the historical binary weight; The sum of the historical floating-point weight and the error weight preset value is determined as the current actual floating-point weight.
5. The method according to claim 1, wherein If the loss function of the neural network model converges, adjusting the floating-point weights of the neural network model according to the current actual floating-point weights includes: Determine the floating-point weights of the neural network model as the current actual floating-point weights.
6. The method according to claim 1, characterized in that If the loss function of the neural network model has not converged, adjusting the floating-point weights of the neural network model according to the current actual floating-point weights includes: The initial floating-point weights of the neural network model are updated according to the current actual floating-point weights.
7. A training device for a neural network model that implements continuous learning, characterized in that: The device comprises: An acquisition module is configured to acquire historical floating-point weights of a neural network model, wherein an input data set of the neural network model is divided into training data of multiple input tasks; wherein the historical floating-point weights are floating-point weights corresponding to previous input tasks recognized by the neural network model or initialized floating-point weights; and the input data set includes any one of speech data, image data, and text data; A first determining module is used to perform binarization processing on the historical floating-point weights to determine the historical binary weights; An acquisition module is used to forward propagate the training data on a neural network with historical binary weights, calculate the error through a cross entropy function, and obtain the error of the historical binary weights; A second determining module is configured to determine a current actual floating-point weight based on an error between the historical floating-point weight and the historical binary weight; An adjustment module, configured to adjust the floating-point weights of the neural network model according to the current actual floating-point weights; The binarization process is implemented by the following formula: , ; Among them, x and W h Represents historical floating point weights, y and W b represents the historical binary weight, and sign(·) is the binarization sign function.
8. An electronic device, characterized in that: include: one or more processors; and one or more machine-readable media having instructions stored thereon, which, when executed by the one or more processors, execute the training method for a neural network model for implementing continuous learning as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Neural network model processing method, apparatus, equipment, and readable storage medium
CN109102017A
Neural network optimization method and related equipment
CN111950700A