Neural network model training, image classification, text translation methods, devices, and equipment
By using codewords instead of weight matrix in neural network model training, memory usage and computational volume are reduced, memory bottleneck problem is solved, and efficient training and accurate results are achieved under resource constraints.
Patent Information
- Application Number
- CN202010558711.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-18
- Publication Date
- 2025-09-02
- Estimated Expiration
- 2040-06-18
AI Technical Summary
During the training of existing neural network models, the large amount of weight matrix data leads to memory bottlenecks, especially in resource-constrained scenarios.
The codewords are obtained from memory instead of directly reading into the weight matrix, and the codewords are determined through clustering and average calculation, reducing memory usage, and using codewords to update the weight matrix, reducing the amount of intermediate parameters calculation.
Effectively overcome memory bottlenecks, realize smooth training of neural network models in resource-constrained scenarios, and improve the accuracy of training results.
Smart Images

Figure CN113822410B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a neural network model training method, an image classification method, a text translation method and apparatus, and equipment. Background Art
[0002] With the rapid development of artificial intelligence (AI), neural networks (NN), as a key technology leading the current development direction of AI, have made breakthrough progress and achieved high accuracy in many fields such as image processing, text classification, machine translation, and natural language processing.
[0003] At present, when using a neural network model to perform a preset task (for example, image classification or text translation), it is usually necessary to train the neural network model in advance to improve the accuracy of the model's output task results. A neural network can generally include multiple weight coefficient matrices. When using a neural network to perform a preset task operation, taking a classification task as an example, a data vector of an object to be classified can be input into the neural network so that the neural network can calculate based on the data vector and the vector of its own multiple weight coefficient matrices to obtain an output vector corresponding to the data vector, and then the neural network can classify the object to be classified based on the output vector. Usually, the weight coefficient matrix in the neural network in the initial state is unknown. In order to obtain a more accurate weight coefficient matrix so that the neural network can obtain more accurate calculation results, it is necessary to train the neural network in the initial state. During the training process, according to the difference between the output result of the neural network and the ideal output result, the weight coefficient matrix contained in each layer of the neural network is continuously updated and corrected until the neural network can obtain an output vector close to the ideal after processing any data vector based on the corrected weight coefficient matrix.
[0004] However, when training a neural network model, to ensure the accuracy of the model's output, the weight coefficients contained in each layer must be repeatedly updated and corrected using training data. Current neural networks typically contain many layers (more than 15), and the weight coefficient matrix contained in each layer is also quite large. Repeatedly reading in weight coefficient matrix data during training creates a memory bottleneck, making neural network training even difficult in resource-constrained scenarios. Summary of the Invention
[0005] The embodiments of the present application provide a neural network model training method, an image classification method, a text translation method and apparatus, and equipment, which can reduce the amount of data of the weight matrix in the neural network model training and the amount of intermediate parameter calculation in the weight matrix update process, thereby solving the memory bottleneck problem and achieving the expected effect when using the neural network model to perform preset tasks (for example, image classification or text translation, etc.).
[0006] In a first aspect, the present application provides a neural network model training method, which includes: first obtaining a codeword corresponding to a first weight matrix of the neural network model from a memory, then determining that the weight matrix of the neural network model is the first weight matrix based on the codeword, and training the first weight matrix using training data, and when a preset stop condition is not met, updating the codeword to obtain an updated codeword, and storing the updated codeword in the memory, then, using the updated codeword obtained in the memory to determine that the weight matrix of the neural network model is a second weight matrix, and training the second weight matrix using training data, and then stopping the training of the neural network model when the preset stop condition is met.
[0007] Compared with traditional technologies, the embodiment of the present application no longer directly reads the weight matrix from the memory when training the neural network model, but instead reads the codewords corresponding to the weight matrix to form the weight matrix for training. Since the memory space occupied by the codewords is much smaller than the memory space occupied by the weight matrix, the amount of data read from the memory can be greatly reduced, overcoming the memory bottleneck problem. In addition, since the present application no longer calculates the update amount of the weight matrix during the model training process, but calculates the update amount of the codewords to re-determine the new weight matrix for subsequent training, it can reduce the amount of intermediate parameter calculations during the update process, thereby enabling the smooth training of the neural network model in resource-constrained scenarios.
[0008] In a possible implementation, when the first weight matrix is an initial weight matrix, the method further includes:
[0009] The initial weight matrix is divided to determine the codewords corresponding to the initial weight matrix, so that the codewords can be stored in memory later to reduce memory usage.
[0010] In one possible implementation, the initial weight matrix is divided to determine the codeword corresponding to the initial weight matrix, including:
[0011] Divide the initial weight matrix into k sub-matrices of the same dimension; where k is a positive integer greater than 1;
[0012] Perform clustering on k sub-matrices of the same dimension to obtain n codewords corresponding to the k sub-matrices of the same dimension, where n is a positive integer greater than 0 and n≤k;
[0013] The n codewords are determined as the codewords corresponding to the initial weight matrix.
[0014] In this way, when training the neural network model, the codewords corresponding to the initial weight matrix of the neural network model can be obtained from the memory to perform model training without directly reading in the initial weight matrix for training. Since the data storage space occupied by the codewords is much smaller than the data storage space occupied by the weight matrix, the amount of data read from the memory can be greatly reduced, effectively overcoming the memory bottleneck problem.
[0015] In one possible implementation, k sub-matrices of the same dimension are clustered to obtain n codewords corresponding to the k sub-matrices of the same dimension, including:
[0016] Reduce the dimensions of k sub-matrices of the same dimension into one-dimensional vectors respectively, and obtain k one-dimensional vectors;
[0017] Divide k one-dimensional vectors into n vector groups, where each vector group contains at least one one-dimensional vector;
[0018] The element values of corresponding positions in all one-dimensional vectors belonging to the i-th vector group in the k one-dimensional vectors are averaged to obtain a codeword corresponding to all one-dimensional vectors in the i-th vector group; where i is an integer from 1 to n.
[0019] In this way, through clustering and averaging, we can obtain code words that can represent n, and each code word can simultaneously represent multiple sub-matrices. Then, these n code words can be used to quickly decode the weight matrix of the neural network.
[0020] In a possible implementation, the method further includes:
[0021] When the preset stopping condition is not met, the weight matrix of the neural network model is released in the memory. This can further save memory space and help overcome the memory bottleneck problem.
[0022] In one possible implementation, when a preset stop condition is not satisfied, updating the codeword to obtain an updated codeword includes:
[0023] When a preset stopping condition is not satisfied, determining a weight gradient of a first weight matrix of the neural network model;
[0024] A codeword gradient is determined according to the first weight gradient, and an updated codeword is determined according to the codeword gradient.
[0025] In this way, the codeword gradient can be determined based on the weight gradient to obtain a more accurate updated codeword for subsequent model training.
[0026] In one possible implementation, determining a codeword gradient based on a weight gradient, and determining an updated codeword based on the codeword gradient includes:
[0027] The weight gradient of the submatrix corresponding to the j-th codeword in the weight gradient is weighted and summed to obtain the codeword gradient corresponding to the j-th codeword; where j is an integer from 1 to n;
[0028] Optimize the codeword gradient corresponding to the j-th codeword to obtain the update amount of the j-th codeword;
[0029] The j-th code word is updated using the update amount of the j-th code word to obtain an updated j-th code word.
[0030] In this way, each codeword can be accurately determined to decode a new weight matrix for subsequent model training.
[0031] In a possible implementation, the method further includes:
[0032] Obtain an index, where the index is the correspondence between the codeword and the weight matrix of the neural network model, so that the weight matrix of the neural network model can be more accurately decoded using the codeword and the index.
[0033] In one possible implementation, the preset stop condition includes one or more of the following conditions:
[0034] The difference between the result label value corresponding to the training data and the output result of the neural network model for the training data is lower than the preset difference;
[0035] The rate of change of the difference between the result label value corresponding to the training data and the output result of the neural network model for the training data is lower than the preset change threshold;
[0036] The number of updates of the model parameters in the neural network model reaches the preset number of updates;
[0037] The output value of the loss function used by the neural network model reaches a preset threshold; wherein the loss function is used to measure the gap between the output result of the neural network model for the training data and the result label value corresponding to the training data.
[0038] In a second aspect, the present application also provides an image classification method, which includes: obtaining an image to be classified; inputting the image to be classified into a trained neural network model to obtain an image classification result output by the neural network model; wherein the training process of the neural network model includes: first obtaining a codeword corresponding to a first weight matrix of the neural network model from a memory, then determining the weight matrix of the neural network model as the first weight matrix based on the codeword, and training the first weight matrix using training data, wherein the training data includes a positive sample image and a negative sample image. When the neural network model outputs a probability value that the training data is a positive sample image, if a preset stop condition is not met, the codeword is updated to obtain an updated codeword, and the updated codeword is stored in the memory, then, the weight matrix of the neural network model is determined to be a second weight matrix using the updated codeword obtained in the memory, and the second weight matrix is trained using the training data, and then the training of the neural network model is stopped when the preset stop condition is met.
[0039] Compared with traditional technologies, the embodiment of the present application uses a pre-trained neural network model to classify images to be classified. Since the neural network model can reach global optimality, the classification results output by the neural network model are more accurate, thereby improving the accuracy of the classification results.
[0040] In a third aspect, the present application also provides a text translation method, which includes: obtaining a text to be translated; inputting the text to be translated into a trained neural network model to obtain a text translation result output by the neural network model; wherein the training process of the neural network model includes: first obtaining a codeword corresponding to a first weight matrix of the neural network model from a memory, then determining the weight matrix of the neural network model as a first weight matrix based on the codeword, and training the first weight matrix using training data, wherein the training data is a sample text. After the neural network model outputs the translation result of the sample text, if a preset stop condition is not met, the codeword is updated to obtain an updated codeword, and the updated codeword is stored in a memory, then, the weight matrix of the neural network model is determined to be a second weight matrix using the updated codeword obtained in the memory, and the second weight matrix is trained using the training data, and then the training of the neural network model is stopped when the preset stop condition is met.
[0041] Compared with traditional technologies, the embodiment of the present application uses a pre-trained neural network model to translate the text to be translated. Since the neural network model can reach global optimization, the translation results output by the neural network model are more accurate, thereby improving the accuracy of the translation results.
[0042] In a fourth aspect, the present application also provides a neural network model training device, which includes: a first acquisition unit for acquiring a codeword from a memory, wherein the codeword corresponds to a first weight matrix of the neural network model; a first training unit for determining that the weight matrix of the neural network model is a first weight matrix based on the codeword, and training the first weight matrix using training data; an update unit for updating the codeword to obtain an updated codeword when a preset stop condition is not met; a storage unit for storing the updated codeword in the memory; a second training unit for determining that the weight matrix of the neural network model is a second weight matrix using the updated codeword acquired in the memory, and training the second weight matrix using training data; a stop unit for stopping the training of the neural network model when the preset stop condition is met.
[0043] In a possible implementation, when the first weight matrix is an initial weight matrix, the apparatus further includes:
[0044] The partitioning unit is used to partition the initial weight matrix to determine the codeword corresponding to the initial weight matrix.
[0045] In one possible implementation, the division unit includes:
[0046] A first division subunit is configured to divide the initial weight matrix into k sub-matrices of the same dimension; k is a positive integer greater than 1;
[0047] a clustering subunit, configured to perform clustering processing on the k sub-matrices of the same dimension to obtain n codewords corresponding to the k sub-matrices of the same dimension, where n is a positive integer greater than 0, and n≤k;
[0048] The first determining subunit is configured to determine the n codewords as codewords corresponding to the initial weight matrix.
[0049] In one possible implementation, the clustering subunit includes:
[0050] The dimensionality reduction sub-unit is used to reduce the dimensions of k sub-matrices of the same dimension into one-dimensional vectors respectively, thereby obtaining k one-dimensional vectors;
[0051] A second division subunit is configured to divide the k one-dimensional vectors into n vector groups, wherein each vector group includes at least one one-dimensional vector;
[0052] The calculation subunit is used to average the element values of corresponding positions in all one-dimensional vectors belonging to the i-th vector group in the k one-dimensional vectors to obtain a codeword corresponding to all one-dimensional vectors in the i-th vector group; wherein i is an integer from 1 to n.
[0053] In one possible implementation, the device further includes: a releasing unit, configured to release the weight matrix of the neural network model in the memory when a preset stop condition is not met.
[0054] In one possible implementation, the updating unit includes:
[0055] A second determining subunit, configured to determine a weight gradient of a first weight matrix of the neural network model when a preset stop condition is not satisfied;
[0056] The third determining subunit is configured to determine a codeword gradient according to the first weight gradient and the index, and determine an updated codeword according to the codeword gradient.
[0057] In one possible implementation, the third determining subunit includes:
[0058] A first obtaining subunit is configured to perform weighted summation on the weight gradients of the submatrices corresponding to the index number of the j-th codeword in the weight gradient to obtain a codeword gradient corresponding to the j-th codeword; wherein j is an integer from 1 to n;
[0059] The second obtaining subunit is used to optimize the codeword gradient corresponding to the j-th codeword to obtain the update amount of the j-th codeword;
[0060] The third obtaining subunit is configured to update the j-th code word using the update amount of the j-th code word to obtain the updated j-th code word.
[0061] In one possible implementation, the device further includes:
[0062] The second acquisition unit is used to obtain an index, where the index is a correspondence between a codeword and a weight matrix of a neural network model.
[0063] In one possible implementation, the preset stop condition includes one or more of the following conditions:
[0064] The difference between the result label value corresponding to the training data and the output result of the neural network model for the training data is lower than the preset difference;
[0065] The rate of change of the difference between the result label value corresponding to the training data and the output result of the neural network model for the training data is lower than the preset change threshold;
[0066] The number of updates of the model parameters in the neural network model reaches the preset number of updates;
[0067] The output value of the loss function used by the neural network model reaches a preset threshold; among them, the loss function is used to measure the gap between the output result of the neural network model for the training data and the result label value corresponding to the training data.
[0068] In a fifth aspect, the present application further provides an image classification device, comprising: an image acquisition unit for acquiring an image to be classified; an image classification unit for inputting the image to be classified into a trained neural network model to obtain an image classification result output by the neural network model; and a neural network model training unit for training the neural network model.
[0069] Among them, the neural network model training unit includes:
[0070] A first acquiring unit is configured to acquire a codeword from a memory, wherein the codeword corresponds to a first weight matrix of a neural network model;
[0071] A first training unit is configured to determine a weight matrix of the neural network model as a first weight matrix according to the codeword, and train the first weight matrix using training data; wherein the training data includes positive sample images and negative sample images;
[0072] An updating unit, configured to update the codeword to obtain an updated codeword when the neural network model outputs a probability value that the training data is a positive sample image and a preset stop condition is not satisfied;
[0073] a storage unit, configured to store the updated codeword in a memory;
[0074] A second training unit is configured to determine a weight matrix of the neural network model as a second weight matrix using the updated codeword obtained in the memory, and to train the second weight matrix using the training data;
[0075] The stopping unit is used to stop the training of the neural network model when a preset stopping condition is met.
[0076] In a sixth aspect, the present application further provides a text translation device, comprising: a text acquisition unit for acquiring a text to be translated; a text translation unit for inputting the text to be translated into a trained neural network model to obtain a text translation result output by the neural network model; and a neural network model training unit for training the neural network model.
[0077] Among them, the neural network model training unit includes:
[0078] A first acquiring unit is configured to acquire a codeword from a memory, wherein the codeword corresponds to a first weight matrix of a neural network model;
[0079] A first training unit is configured to determine a weight matrix of a neural network model as a first weight matrix according to the codeword, and train the first weight matrix using training data; wherein the training data is sample text;
[0080] an updating unit, configured to update the codeword to obtain an updated codeword when the neural network model outputs the translation result of the sample text and a preset stop condition is not satisfied;
[0081] a storage unit, configured to store the updated codeword in a memory;
[0082] A second training unit is configured to determine a weight matrix of the neural network model as a second weight matrix using the updated codeword obtained in the memory, and to train the second weight matrix using the training data;
[0083] The stopping unit is used to stop the training of the neural network model when a preset stopping condition is met.
[0084] In a seventh aspect, the present application further provides a neural network model training device, the neural network model training device comprising: a memory, a processor;
[0085] A memory is used to store instructions; a processor is used to execute the instructions in the memory and perform the neural network model training method in the above-mentioned first aspect and any possible implementation thereof.
[0086] In an eighth aspect, the present application further provides an image classification device, the image classification device comprising: a memory, a processor;
[0087] The memory is used to store instructions; the processor is used to execute the instructions in the memory and perform the image classification method in the second aspect.
[0088] In a ninth aspect, the present application further provides a text translation device, the text translation device comprising: a memory, a processor;
[0089] The memory is used to store instructions; the processor is used to execute the instructions in the memory and perform the text translation method in the third aspect.
[0090] In the tenth aspect, the present application also provides a computer-readable storage medium comprising instructions, which, when executed on a computer, enables the computer to execute the neural network model training method in the above-mentioned first aspect and any possible implementation thereof, or execute the image classification method in the above-mentioned second aspect, or execute the text translation method in the above-mentioned third aspect.
[0091] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages:
[0092] In the embodiment of the present application, when training a neural network model, the codeword corresponding to the first weight matrix of the neural network model is first obtained from the memory, and then the weight matrix of the neural network model is determined to be the first weight matrix based on the codeword, and the first weight matrix is trained using the training data. When the preset stop condition is not met, the codeword is updated to obtain the updated codeword, and the updated codeword is stored in the memory. Then, the weight matrix of the neural network model is determined to be the second weight matrix using the updated codeword obtained in the memory, and the second weight matrix is trained using the training data. Then, when the preset stop condition is met, the training of the neural network model is stopped. It can be seen that when training the neural network model, the embodiment of the present application no longer directly reads the weight matrix from the memory, but reads the codeword corresponding to the weight matrix to form the weight matrix for training. Since the memory space occupied by the codeword is much smaller than the memory space occupied by the weight matrix, the amount of data read from the memory can be greatly reduced, overcoming the memory bottleneck problem. Moreover, since the present application no longer calculates the update amount of the weight matrix during the model training process, but calculates the update amount of the codeword to re-determine the new weight matrix for subsequent training, it can reduce the amount of intermediate parameter calculation in the update process, thereby enabling the smooth training of the neural network model in resource-constrained scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0093] Figure 1 A schematic diagram of the structure of the artificial intelligence main framework provided in the embodiment of the present application;
[0094] Figure 2 This is an example diagram of a system architecture used in an embodiment of the present application;
[0095] Figure 3 A flowchart of a neural network model training method provided in an embodiment of the present application;
[0096] Figure 4 A schematic diagram of determining a first weight matrix of a neural network model according to a codeword provided in an embodiment of the present application;
[0097] Figure 5 A schematic diagram of codeword update provided in an embodiment of the present application;
[0098] Figure 6 A flowchart of an image classification method provided in an embodiment of the present application;
[0099] Figure 7 A flowchart of a text translation method provided in an embodiment of the present application;
[0100] Figure 8 A structural block diagram of a neural network model training device provided in an embodiment of the present application;
[0101] Figure 9 A structural block diagram of an image classification device provided in an embodiment of the present application;
[0102] Figure 10 A structural block diagram of a text translation device provided in an embodiment of the present application;
[0103] Figure 11 A schematic diagram of the structure of a neural network model training device provided in an embodiment of the present application;
[0104] Figure 12 A schematic diagram of the structure of an image classification device provided in an embodiment of the present application;
[0105] Figure 13 A structural diagram of a text translation device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0106] The embodiments of the present application provide a neural network model training method, an image classification method, a text translation method and apparatus, and equipment, which can reduce the amount of data of the weight matrix in the neural network model training and the amount of intermediate parameter calculation in the weight matrix update process, so as to solve the memory bottleneck problem and achieve the expected training effect.
[0107] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art will appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0108] First, the overall workflow of the artificial intelligence system is described. Figure 1 , Figure 1 The following diagram illustrates a structural diagram of the AI framework. This framework is explained below from two perspectives: the "intelligent information chain" (horizontal axis) and the "IT value chain" (vertical axis). The "intelligent information chain" reflects the entire process from data acquisition to processing. For example, it encompasses the general process of intelligent information perception, intelligent information representation and formation, intelligent reasoning, intelligent decision-making, and intelligent execution and output. Throughout this process, data undergoes a condensed progression from "data-information-knowledge-wisdom." The "IT value chain," encompassing the entire process from the underlying infrastructure of human intelligence, information (provided and processed by technology), to the system's industrial ecosystem, reflects the value that AI brings to the information technology industry.
[0109] (1) Infrastructure
[0110] Infrastructure provides computing power for AI systems, enabling communication with the outside world and supporting this through a foundational platform. External communication occurs through sensors; computing power is provided by intelligent chips (CPUs, NPUs, GPUs, ASICs, FPGAs, and other hardware accelerators). The foundational platform includes a distributed computing framework and network-related platform guarantees and support, including cloud storage and computing, and interconnected networks. For example, sensors communicate with the outside world to acquire data, which is then fed into the intelligent chips within the distributed computing system provided by the foundational platform for computation.
[0111] (2) Data
[0112] Data above the infrastructure layer represents data sources for AI. This data includes graphics, images, voice, and text, as well as IoT data from traditional devices. This includes business data from existing systems and sensor data such as force, displacement, liquid level, temperature, and humidity.
[0113] (3) Data processing
[0114] Data processing generally includes data training, machine learning, deep learning, search, reasoning, decision-making, etc.
[0115] Among them, machine learning and deep learning can symbolize and formalize data for intelligent information modeling, extraction, preprocessing, and training.
[0116] Reasoning refers to the process of simulating human intelligent reasoning in computers or intelligent systems, using formalized information to perform machine thinking and solve problems based on reasoning control strategies. Typical functions are search and matching.
[0117] Decision-making refers to the process of making decisions after intelligent information is reasoned, and usually provides functions such as classification, sorting, and prediction.
[0118] (4) General ability
[0119] After the data has undergone the data processing mentioned above, some general capabilities can be further formed based on the results of the data processing, such as algorithms or a general system, for example, translation, text analysis, computer vision processing, speech recognition, image recognition, etc.
[0120] (5) Smart products and industry applications
[0121] Smart products and industry applications refer to the products and applications of artificial intelligence systems in various fields. They are the encapsulation of the overall artificial intelligence solution, which productizes intelligent information decision-making and realizes practical application. Its application areas mainly include: smart terminals, smart transportation, smart medical care, autonomous driving, safe cities, etc.
[0122] Since the embodiments of the present application involve the training process of a neural network model, for ease of understanding, the relevant terms and concepts of the neural network model that may be involved in the embodiments of the present application are first introduced below.
[0123] (1) Neural Network
[0124] A neural network can be composed of neural units. A neural unit can refer to an operation unit with xs and intercept 1 as input. The output of the operation unit can be:
[0125]
[0126] Where s = 1, 2, ..., n, where n is a natural number greater than 1, Ws is the weight of Xs, and b is the bias of the neural unit. f is the activation function of the neural unit, which is used to introduce nonlinear characteristics into the neural network to convert the input signal in the neural unit into the output signal. The output signal of the activation function can be used as the input of the next convolutional layer, and the activation function can be a sigmoid function. A neural network is a network formed by connecting multiple single neural units mentioned above, that is, the output of one neural unit can be the input of another neural unit. The input of each neural unit can be connected to the local receptive field of the previous layer to extract the features of the local receptive field. The local receptive field can be an area composed of several neural units.
[0127] (2) Loss Function
[0128] During neural network training, because we want the output of the neural network to be as close as possible to the desired predicted value, we can compare the current network's predicted value with the desired target value and then update the weight vector of each layer of the neural network based on the difference between the two. (Of course, there is usually an initialization process before the first update, which is to pre-configure the parameters for each layer in the deep neural network.) For example, if the network's predicted value is too high, the weight vector is adjusted to make it predict a lower value. This adjustment is continued until the deep neural network can predict the desired target value or a value very close to the desired target value. Therefore, it is necessary to predefine "how to compare the difference between the predicted value and the target value." This is the loss function (or objective function), which is an important equation used to measure the difference between the predicted value and the target value. For example, the loss function output value (loss) indicates a greater difference, so training a deep neural network becomes a process of minimizing this loss.
[0129] (3) Backpropagation algorithm
[0130] Neural networks can use the back propagation (BP) algorithm to correct the size of the parameters in the initial neural network model during training, reducing the reconstruction error loss of the neural network model. Specifically, the forward propagation of the input signal to the output generates error loss. This error loss information is then backpropagated to update the parameters in the initial neural network model, thereby converging the error loss. The BP algorithm is a backward propagation movement dominated by error loss, aiming to obtain the optimal parameters of the neural network model, such as the weight matrix.
[0131] This application can be applied in the field of artificial intelligence. The following will introduce a system structure of a neural network model training application in an embodiment of this application.
[0132] See also Figure 2 , which shows an example diagram of a system architecture applied in an embodiment of the present application, such as Figure 2 As shown, this scenario includes memory 201, processor 202, and AI hardware accelerator 203. Memory 201 is connected to processor 202, and processor 202 is connected to AI hardware accelerator 203. The above "connection" can be a direct connection or an indirect connection.
[0133] Among them, the memory 201 is one of the important components in the computer. It is a bridge for communication between the external memory and the processor 202. In addition, the operation of all programs in the computer is carried out in the memory.
[0134] The processor 202 may be a central processing unit (CPU), configured to assign acceleration tasks to the AI hardware accelerator 203 mounted thereon.
[0135] The AI hardware accelerator 203 can be a standalone chip or integrated into a system on chip (SoC) as a functional module. It mainly includes a matrix calculation unit (cube unit), a vector calculation unit (vector unit) and a buffer.
[0136] The matrix calculation unit is used to complete matrix-matrix calculations, such as gradient calculations in neural networks and matrix-matrix calculations corresponding to convolutional layers and fully connected layers. Specifically, when performing convolutional layer or fully connected layer operations, the matrix calculation unit reads the data corresponding to the data matrix from the data cache unit and the parameter cache unit. The parameter data read from the parameter cache unit is transferred to the parameter cache unit through the memory read-write controller. During the transfer process, the parameter data needs to be decompressed by the decompression engine before the matrix multiplication calculation can be performed on the matrix calculation unit to obtain the partial result or the final result of the matrix and save it in the accumulator.
[0137] The vector processing unit can further optimize the output results of the matrix calculation unit when necessary, such as vector multiplication, vector addition, exponential operation, logarithmic operation, size comparison, etc. It is mainly used for network calculations in layers other than non-convolutional layers and fully connected layers in neural networks, such as activation function (rectified linear unit, ReLU) layers and pooling layers.
[0138] The cache is used to store data loaded from memory into the AI hardware accelerator and intermediate data generated during the calculation process.
[0139] The neural network model training process applied to the AI hardware accelerator 203 in this application is as follows:
[0140] In an embodiment of the present application, the AI hardware accelerator 203 first obtains the codeword and index corresponding to the initial weight matrix of the neural network model from the memory 201 through the processor 202, and then determines the weight matrix of the neural network model based on the obtained codeword and index, and trains the weight matrix using the training data. When the preset stop condition is not met, the codeword is updated, and the updated codeword and the previously obtained index are used to redetermine the weight matrix for re-training the model. Similarly, as long as the preset stop condition is not met, the codeword is repeatedly updated, and the updated codeword is used to redetermine the weight matrix for re-training the model. Until the preset stop condition is met, in this way, by reducing the amount of data of the weight matrix in the neural network model training and the amount of intermediate parameter calculation in the weight matrix update process, not only the memory bottleneck problem is solved, but also the expected model training effect can be achieved.
[0141] It should be noted that the above application scenarios are only shown to facilitate understanding of the present application, and the embodiments of the present application are not limited in this respect. On the contrary, the embodiments of the present application can be applied to any applicable scenario.
[0142] Based on the above application scenarios, the embodiment of the present application provides a neural network model training method, which can be applied to the AI hardware accelerator 203, such as Figure 3 As shown, the method includes:
[0143] S301: Obtain a codeword from a memory, where the codeword corresponds to a first weight matrix of a neural network model.
[0144] In this embodiment, in order to overcome the memory bottleneck problem in the training of the neural network model, the weight matrix is no longer loaded repeatedly, but the codeword is obtained from the memory to perform model training, wherein the codeword corresponds to the first weight matrix of the neural network model. In addition, when the first weight matrix is the initial weight matrix, the initial weight matrix needs to be divided to determine the codeword corresponding to the initial weight matrix. That is, the initial weight matrix of the neural network model needs to be preprocessed in advance and split into corresponding codewords and corresponding indexes, wherein the codeword refers to the representation of each occurrence state in the dictionary, and each codeword in this application refers to a submatrix in the weight matrix, and the memory space occupied by the codeword is much smaller than the memory space occupied by the weight matrix. For details of the codeword, please refer to the relevant introduction in the subsequent step A2. The index represents the correspondence between the codeword and the weight matrix of the neural network model, and the weight means contained in each layer of the neural network model correspond to different codewords and indexes. In this way, when training the neural network model, the codewords corresponding to the initial weight matrix of the neural network model can be obtained from the memory to execute subsequent steps S302-S306 to complete the model training, without the need to directly read in the initial weight matrix for training. Since the data storage space occupied by the codewords is much smaller than the data storage space occupied by the weight matrix, the amount of data read from the memory can be greatly reduced, effectively overcoming the memory bottleneck problem.
[0145] In a possible implementation of this embodiment, the initial weight matrix of the neural network model is preprocessed in advance. The specific implementation process of splitting it into corresponding codewords and indexes may include the following steps A1-A3:
[0146] Step A1: Divide the initial weight matrix into k sub-matrices of the same dimension, and determine the index numbers corresponding to the k sub-matrices of the same dimension; where k is a positive integer greater than 1.
[0147] In this implementation, preprocessing the initial weight matrix of the neural network model refers to preprocessing the initial weight matrix contained in each layer of the neural network model in advance, so that the initial weights contained in each layer correspond to different codewords and indexes. It should be noted that in the subsequent content, this embodiment will take the initial weight matrix contained in a certain layer in the neural network model as the basis to introduce how to preprocess the initial weight matrix to obtain its corresponding codeword and index and perform subsequent processing on it, and the processing method of the initial weight matrix contained in other layers is similar and will not be repeated one by one.
[0148] Specifically, the application first divides the initial weights into k sub-matrices of the same dimension, and determines the index number corresponding to each sub-matrix. The two are in a one-to-one correspondence (i.e., one sub-matrix corresponds to one index number). For example, the index numbers corresponding to the k sub-matrices of the same dimension can be defined as i0, i1, ...i k-1 , to perform step A3. Wherein, k is a positive integer greater than 1.
[0149] Step A2: clustering k sub-matrices of the same dimension to obtain n codewords corresponding to the k sub-matrices of the same dimension, and determining index values corresponding to the n codewords, where n is a positive integer greater than 0, and n≤k.
[0150] In this implementation, after the initial weight matrix is divided into k sub-matrices of the same dimension through step A1, these k sub-matrices of the same dimension can be further clustered to obtain n category centers (i.e., n codewords), where n is a positive integer greater than 0 and n≤k. In this way, the sub-matrix (i.e., codeword) corresponding to each category center can be used to represent each sub-matrix in the category to which it belongs. In addition, the index values corresponding to each of the n codewords can be further determined, and the two are in a one-to-one correspondence (i.e., one codeword corresponds to one index value). For example, the index values corresponding to the n codewords can be defined as 1, 2, ...n, respectively, to execute step A3.
[0151] Specifically, an optional implementation method is that the specific implementation process of "clustering k sub-matrices of the same dimension to obtain n codewords corresponding to the k sub-matrices of the same dimension" in step A2 may include the following steps A21-A23:
[0152] Step A21: Reduce the dimensions of k sub-matrices of the same dimension into one-dimensional vectors respectively, to obtain k one-dimensional vectors.
[0153] In this implementation, in order to determine the n codewords corresponding to k sub-matrices of the same dimension, it is first necessary to reduce the dimensions of the k sub-matrices of the same dimension into one-dimensional vectors respectively, thereby obtaining k one-dimensional vectors.
[0154] For example: Assume that k sub-matrices of the same dimension contain a 2*3-order matrix: It can be reduced to a one-dimensional vector containing 6 elements [a1, a2, a3, a4, a5, a6].
[0155] Step A22: Divide the k one-dimensional vectors into n vector groups, where each vector group contains at least one one-dimensional vector.
[0156] In this implementation, after k sub-matrices of the same dimension are reduced into corresponding k one-dimensional vectors through step A21, these k one-dimensional vectors can be further grouped. For example, vectors with relatively close element values can be divided into a vector group, so that each vector group contains at least one one-dimensional vector.
[0157] Step A23: averaging the element values at corresponding positions in all one-dimensional vectors belonging to the i-th vector group among the k one-dimensional vectors to obtain a codeword corresponding to all one-dimensional vectors in the i-th vector group; where i is an integer from 1 to n.
[0158] In this implementation, after k one-dimensional vectors are divided into n vector groups through step A22, the center vector of each vector group can be further determined to determine the codeword corresponding to the vector group. Specifically, taking the i-th vector group as an example (i can be any integer from 1 to n), assuming that the i-th vector group contains 3 one-dimensional vectors, namely: [a1, a2, a3, a4, a5, a6], [b1, b2, b3, b4, b5, b6], [c1, c2, c3, c4, c5, c6], then the element values of the corresponding positions in these three vectors can be averaged to obtain a one-dimensional average vector:
[0159]
[0160] The one-dimensional vector is the codeword corresponding to the i-th vector group, and the length of the codeword is 6, that is, the number of elements contained in the one-dimensional vector.
[0161] It should be noted that when determining the codewords corresponding to all one-dimensional vectors in the i-th vector group, other data processing methods can also be used to process the element values of corresponding positions in all one-dimensional vectors in the i-th vector group, such as weighted averaging, etc. The specific processing method can be selected according to actual conditions, and the embodiments of the present application are not limited to this.
[0162] Step A3: Determine n codewords as codewords corresponding to the initial weight matrix, and use index values corresponding to the n codewords and index numbers corresponding to the index values to form an index corresponding to the initial weight matrix.
[0163] In this implementation, the initial weight matrix is divided into k sub-matrices of the same dimension through step A2, and the index numbers corresponding to the k sub-matrices of the same dimension are determined. After the n code words corresponding to the k sub-matrices of the same dimension and the index values corresponding to the n code words are determined through step A2, the n code words can be determined as the code words corresponding to the initial weights for storage, or the n code words can be formed into a dictionary for storage. At the same time, the index values corresponding to the n code words (for example, 1, 2, ... n) and the index numbers corresponding to the index values (such as i0, i1, ... i k-1 ) constitutes the index corresponding to the initial weight.
[0164] It should be noted that since the sub-matrix and the index number are in a one-to-one correspondence (i.e., one sub-matrix corresponds to one index number), and the codeword and the index value are in a one-to-one correspondence (i.e., one codeword corresponds to one index value), and the codeword is the central vector of a vector group (such as an average vector), where each vector in the vector group corresponds to a sub-matrix, so one codeword can represent multiple sub-matrices, and thus one index value may correspond to multiple index numbers.
[0165] Furthermore, after determining the codeword and index corresponding to the initial weight matrix, the codeword can be stored in memory. Compared with directly storing the initial weight matrix in memory, the storage space occupied by the codeword is much smaller. Alternatively, both the codeword and the index can be stored in memory. Compared with directly storing the initial weight matrix in memory, the storage space occupied by both is also much smaller, thereby significantly reducing the storage space occupied by the parameters in memory, and the compression rate can usually reach about 40 times. For example, for a 528MB weight matrix, after preprocessing it through the above process, its corresponding codeword and index can be obtained, totaling 14.45MB, of which the codeword is 1.16MB and the index is 13.29MB, with a compression rate close to 40 times.
[0166] It should be noted that after determining the codewords and indexes corresponding to the initial weight matrix, they can also be stored in an external memory (such as a hard disk) and then input into the internal memory from the external memory. The specific storage location is not limited in the embodiment of this application.
[0167] S302: Determine a weight matrix of the neural network model as a first weight matrix according to the codeword, and train the first weight matrix using training data.
[0168] In this embodiment, after the codeword corresponding to the initial weight matrix of the neural network model is obtained from the memory in step S301, a new weight matrix of the neural network model (here defined as the first weight matrix) can be further determined based on the obtained codeword. An optional implementation method is to further obtain an index representing the correspondence between the codeword and the weight matrix of the neural network model, and then the first weight matrix of the neural network model can be determined by using the correspondence between the obtained codeword, the index and the weight matrix.
[0169] Specifically, the one-to-one correspondence between codewords and index values, the one-to-many relationship between index values and index numbers, and the one-to-one correspondence between index numbers and submatrices can be used to decode the first weight matrix of the neural network model, and the training data can be used to train the first weight matrix of the neural network model. The specific calculation formula is as follows:
[0170] W=D mat ·Io h (2)
[0171] Among them, D mat Io represents the first weight matrix composed of code words, the dimension of the matrix is c×n, where c represents the length of the code word and n represents the number of code words; h Represents a one-hot matrix composed of indices. The dimension of the matrix is n×k. Based on the characteristics of the one-hot matrix, each row has a value of 1 only at the position corresponding to the index number, and the value of other positions is 0.
[0172] For example: Figure 4 As shown, the left figure shows a dictionary composed of n code words, namely: the first code word, the second code word, ..., the nth code word, and the middle figure shows the index values corresponding to the n code words (i.e. 1, 2, ..., n) and the index numbers corresponding to the index values (i.e. i0, i1, ...i k-1 ) constitutes an index. As indicated by the thick black arrow in the figure, the index value corresponding to the first codeword in the dictionary is "1", and this index value corresponds to two index numbers, namely the index number of the first row and first column and the index number of the second row and second column in the index diagram. These two index numbers correspond to two sub-matrices in the weight matrix of the neural network model, namely the sub-matrix represented by light gray squares in the first row and first column and the sub-matrix represented by light gray in the second row and second column in the weight matrix diagram on the right. Such a corresponding relationship can be used to decode the sub-matrix of the first row and first column and the sub-matrix of the second row and second column in the weight matrix according to the first codeword in the dictionary.
[0173] Similarly, if Figure 4The thin black arrow in the middle indicates that the index value corresponding to the second codeword is "2", and this index value corresponds to an index number, namely the index number in the third row and first column of the index diagram. This index number corresponds to a submatrix in the weight matrix of the neural network model, namely the submatrix represented by the dark gray square in the third row and first column of the weight matrix diagram on the right. This correspondence can be used to decode the submatrix in the third row and first column of the weight matrix according to the second codeword in the dictionary. Similarly, the entire weight matrix of the neural network model can be decoded by using the correspondence between each codeword in the dictionary and the codeword, index, and submatrix of the weight matrix. The weight matrix can then be trained using training data.
[0174] However, it should be noted that since the codeword is generated by clustering and averaging the sub-matrices corresponding to the initial matrix through the above steps A21-A23, the first weight matrix of the neural network model determined by the codeword and index is compared to the initial weight matrix. Although the data space occupied by the two is consistent, the weight elements contained in the two are not exactly the same, which leads to the fact that the weight values of the two are also not completely consistent, but the two are very close, that is, the weight matrix of the determined neural network model can be used instead of the initial weight matrix for model training.
[0175] S303: When the preset stop condition is not satisfied, the codeword is updated to obtain an updated codeword.
[0176] In this embodiment, after the first weight matrix of the neural network model is trained using the training data in step S302, it is further necessary to determine whether a preset stop condition is met, wherein the preset stop condition refers to a pre-set condition that needs to be met when stopping training. It can be that the difference between the result label value of the training data and the output result of the model for the training data is lower than a preset difference value; it can also be that the rate of change of the difference between the result label value of the training data and the output result of the model for the training data is lower than a preset change threshold; it can also be that the number of updates of the model parameters reaches a preset number of updates (such as 100 times); or it can also be that the output value (loss) of the loss function that characterizes the difference between the output result of the model and the target result value reaches a preset threshold (such as 0.1). When the preset stop condition is not met, it is necessary to update the codeword according to the result of the current training to obtain an updated codeword for retraining the model in the subsequent step S304.
[0177] In a possible implementation of this embodiment, the specific implementation process of step S303 may include the following steps B1-B2:
[0178] Step B1: When a preset stopping condition is not satisfied, determining a weight gradient of a first weight matrix of the neural network model.
[0179] In this implementation, after the first weight matrix of the neural network model is trained using the training data in step S302, if it is determined that the preset stop condition is not met, such as when the loss value does not reach the preset threshold, the weight gradient of the first weight matrix of the neural network model (here defined as g w ), to execute the subsequent step B2.
[0180] Step B2: Determine a codeword gradient according to the first weight gradient and the index, and determine an updated codeword according to the codeword gradient.
[0181] In this implementation, when the weight gradient g of the first weight matrix of the neural network model is determined by step B1, w After that, the codeword gradient can be further determined based on the correspondence between the codeword, index, and weight matrix. Specifically, the one-to-one correspondence between codewords and index values, the one-to-many relationship between index values and index numbers, and the one-to-one correspondence between index numbers and submatrices can be used to process the weight gradients in the submatrices corresponding to the index numbers belonging to the same codeword to obtain the codeword gradient corresponding to the codeword. The specific calculation formula is as follows:
[0182]
[0183] Among them, g D represents the codeword gradient; Represents the one-hot matrix Io composed of indices h The transpose of g w Represents the weight gradient of the first weight matrix of the neural network model.
[0184] Specifically, an optional implementation method is that the specific implementation process of this step B2 may include the following steps B21-B23:
[0185] Step B21: performing weighted summation on the weight gradients of the submatrices corresponding to the index numbers of the j-th codeword in the weight gradient to obtain the codeword gradient corresponding to the j-th codeword; wherein j is an integer from 1 to n.
[0186] In this implementation, to obtain the updated codeword, it is necessary to process the weight gradients in the submatrix corresponding to the index number belonging to the same codeword, and determine the updated value corresponding to the codeword based on the processing results. Specifically, taking the j-th codeword as an example (j can be any integer from 1 to n), there may be multiple index numbers corresponding to this codeword, and each index number corresponds to a submatrix. Then, the weight gradients of the submatrix corresponding to each index number can be weighted summed, and the result of the calculation can be used as the codeword gradient corresponding to the j-th codeword.
[0187] It should be noted that when determining the codeword gradient corresponding to the j-th codeword, other data processing methods can also be used to process the weight gradient of the submatrix corresponding to each index number belonging to the j-th codeword, such as direct accumulation and summation, etc. The specific processing method can be selected according to actual conditions, and the embodiment of the present application does not limit this.
[0188] Step B22: Optimize the codeword gradient corresponding to the j-th codeword to obtain an update amount for the j-th codeword.
[0189] In this implementation, after obtaining the codeword gradient corresponding to the jth codeword in step B21, the gradient can be further optimized to obtain the update amount of the jth codeword. For example, the widely used Adam optimizer can be used to optimize the codeword gradient corresponding to the jth codeword to obtain the update amount of the jth codeword. At the same time, four intermediate parameters will be generated during the optimization process, namely: first-order momentum m t , second-order momentum v t , first-order momentum correction value Second-order momentum correction It should be noted that the four intermediate parameters (i.e. m t 、v t 、 ) is consistent with the number of codeword gradients of the j-th codeword.
[0190] Step B23: Update the jth code word using the update amount of the jth code word to obtain an updated jth code word.
[0191] In this implementation, after obtaining the update amount of the j-th codeword through step B22, the j-th codeword can be further updated using the update amount. For example, the result of subtracting the update amount from the j-th codeword can be used, or the result of adding the j-th codeword to the update amount can be used as the updated j-th codeword to execute the subsequent step S305.
[0192] For example: Figure 5As shown, the right figure is the weight gradient of the weight matrix, and the middle figure is the index value corresponding to the n codewords (i.e. 1, 2, ..., n) and the index number corresponding to the index value (i.e. i0, i1, ...i k-1 ) constitutes an index. As indicated by the thick black arrow in the figure, the index value corresponding to the first codeword in the dictionary is "1", and this index value corresponds to two index numbers, namely the index number of the first row and first column and the index number of the second row and second column in the index map. These two index numbers correspond to the weight gradients of the two sub-matrices in the weight gradient of the weight matrix, namely the weight gradient in the first row and first column and the weight gradient in the second row and second column in the weight gradient map on the right. These two weight gradients can then be weighted and summed to obtain the codeword gradient corresponding to the first codeword.
[0193] Similarly, if Figure 5 The thin black arrow in the middle indicates that the index value corresponding to the second codeword is "2", and this index value corresponds to two index numbers, namely the index number in the third row and first column of the index map and the index number in the fourth row and third column. These two index numbers correspond to the weight gradients of the two sub-matrices in the weight gradient of the weight matrix, namely the weight gradient in the third row and first column and the weight gradient in the fourth row and third column of the weight gradient map on the right. These two weight gradients can then be weighted and summed to obtain the codeword gradient corresponding to the second codeword. Similarly, the codeword gradient corresponding to each codeword can be determined. The Adam optimizer can then be used to optimize each codeword gradient to obtain the update amount of each codeword. The update amount of each codeword is then used to update each codeword to obtain the updated codewords.
[0194] S304: Store the updated codeword in the memory.
[0195] In this embodiment, after obtaining each updated codeword in step S303, the updated codeword may be further stored in a memory for executing the subsequent step S305.
[0196] S305: Using the updated codeword obtained in the memory, determine that the weight matrix of the neural network model is a second weight matrix, and train the second weight matrix using the training data.
[0197] In this embodiment, after the updated codeword is stored in the memory in step S304, the updated codeword obtained in the memory can be further used to re-determine a new weight matrix for the neural network model by executing step S302 (here defined as a second weight matrix to replace the first weight matrix described in step S302). The training data is then used to perform the next round of model training on the second weight matrix of the neural network model. The specific implementation process can be found in the description of step S302 above and will not be repeated here.
[0198] It should be noted that after the second weight matrix of the neural network model is trained using the training data through step S302, when it is determined that the preset stop condition is still not met, in order to save memory space, the weight matrix of the current neural network model can be released in the memory, and then the weight matrix of the new neural network model can be re-determined through the above steps S303-S305 for the next round of model training.
[0199] S306: When a preset stopping condition is met, stop training the neural network model.
[0200] In this embodiment, after the next round of model training is performed on the second weight value (or the subsequent new weight matrix) of the neural network model using the training data in step S305, it is further necessary to determine whether the preset stop condition is met, for example, it is necessary to determine whether the loss value reaches the preset threshold, etc. When the preset stop condition is still not met, it is necessary to update the codeword again based on the result of one round of model training to obtain the updated codeword, which is used to retrain the model through the above step S305. By analogy, the codeword is updated when the preset stop condition is not met and the subsequent steps (i.e., steps S303 and S305) are repeated until the training of the neural network model is stopped when the preset stop condition is met.
[0201] In summary, the present embodiment provides a neural network model training method. When training the neural network model, first, a codeword corresponding to a first weight matrix of the neural network model is obtained from the memory. Then, the weight matrix of the neural network model is determined to be the first weight matrix based on the codeword, and the first weight matrix is trained using training data. When the preset stop condition is not met, the codeword is updated to obtain an updated codeword, and the updated codeword is stored in the memory. Then, the weight matrix of the neural network model is determined to be the second weight matrix using the updated codeword obtained in the memory, and the second weight matrix is trained using training data. When the preset stop condition is met, the training of the neural network model is stopped. It can be seen that when training the neural network model, the embodiment of the present application no longer directly reads the weight matrix from the memory, but reads the codeword and index corresponding to the weight matrix to form the weight matrix for training. Since the memory space occupied by the codeword is much smaller than the memory space occupied by the weight matrix, the amount of data read from the memory can be greatly reduced, overcoming the memory bottleneck problem. Moreover, since the present application no longer calculates the update amount of the weight matrix during the model training process, but calculates the update amount of the codeword to re-determine the new weight matrix for subsequent training, it can reduce the amount of intermediate parameter calculation in the update process, thereby enabling the smooth training of the neural network model in resource-constrained scenarios.
[0202] For example, when using the existing method to train the classification network VGG16, the amount of data read into the weight matrix is 528MB, the weight gradient generated is 528MB, and the four intermediate parameters (i.e., m t 、v t 、 ) also has a data size of 528MB for each parameter, so the total memory space required is 3.17GB. When the model training method provided by this application is used to train VGG16, the codewords and indices corresponding to the weight matrix are read in, totaling 14.45MB, of which the codewords are 1.16MB, the indices are 13.29MB, and the generated codeword gradients are 1.16MB. The four intermediate parameters (i.e., m t 、v t 、 ) also requires 1.16MB of data for each parameter, so the total memory space required is 20.25MB. Compared with 3.17GB, the amount of data to be calculated is greatly reduced.
[0203] When the existing method is used to train the translation network model transformer, the amount of data read into the weight matrix is 471MB, the weight gradient generated is 471MB, and the four intermediate parameters generated during the optimization (i.e., m t、v t 、 ) is also 471MB in size, so the total memory space required is 2.76GB. When the model training method provided by this application is used to train the transformer, the codewords and indices corresponding to the weight matrix are read in, which are 11.46MB in total. Among them, the codewords are 0.12MB, the indices are 11.34MB, and the generated codeword gradients are 0.12MB. The four intermediate parameters (i.e., m t 、v t 、 ) also requires 0.12MB of data for each parameter, so the total memory space required is 12.06MB. Compared with 2.76GB, the amount of data to be calculated is also greatly reduced.
[0204] In addition, the present application also provides an image classification method. Based on the neural network model training method provided in the above embodiment, the neural network model obtained according to the neural network model training method can be applied to image classification. Figure 6 , which is a flowchart of an image classification method provided in an embodiment of the present application, and the method may include:
[0205] S601: Obtain an image to be classified.
[0206] S602: Input the image to be classified into the trained neural network model to obtain the image classification result output by the neural network model.
[0207] In this embodiment, an image to be classified is first obtained and then input into a pre-trained neural network model to obtain an image classification result corresponding to the image to be classified. In a specific implementation, the neural network model can not only output the classification result corresponding to the image to be classified, but also output the probability value corresponding to each classification result, so that the user can directly understand the classification status of the image to be classified.
[0208] For example, taking a medical image as an example, the neural network model used is a model that can classify medical images. By inputting the medical image (or its corresponding feature map) into the neural network model, a specific classification result for the medical image can be obtained. For example, it can be identified whether the input medical image carries a certain feature or has a certain classification result, or whether it does not carry a certain feature or has no certain classification result.
[0209] The training process of the neural network model includes:
[0210] Retrieve a codeword from a memory, the codeword corresponding to a first weight matrix of a neural network model;
[0211] Determining, according to the codeword, a weight matrix of the neural network model as the first weight matrix, and training the first weight matrix using training data;
[0212] When the preset stop condition is not satisfied, updating the codeword to obtain an updated codeword;
[0213] Storing the updated codeword in the memory;
[0214] Determining a weight matrix of the neural network model as a second weight matrix using the updated codeword obtained in the memory, and training the second weight matrix using training data;
[0215] When the preset stopping condition is met, the training of the neural network model is stopped.
[0216] It should be noted that the training data in this embodiment may include positive sample images and negative sample images. A positive sample image refers to an image to be trained that has certain features or a certain classification result, and the result label value of a positive sample image may be 1. A negative sample image refers to an image to be trained that does not have certain features or a certain classification result, and the result label value of a negative sample image may be 0. The output of the current neural network model to be trained on the training data may be the probability value of the training data output by the current neural network model to be trained being a positive sample image when the training data is input into the current neural network model to be trained.
[0217] In an implementation of this embodiment, when the first weight matrix is an initial weight matrix, the method further includes:
[0218] The initial weight matrix is divided to determine the codeword corresponding to the initial weight matrix.
[0219] In an implementation of this embodiment, dividing the initial weight matrix to determine the codeword corresponding to the initial weight matrix includes:
[0220] Divide the initial weight matrix into k sub-matrices of the same dimension; k is a positive integer greater than 1;
[0221] Performing clustering processing on the k sub-matrices of the same dimension to obtain n codewords corresponding to the k sub-matrices of the same dimension, where n is a positive integer greater than 0, and n≤k;
[0222] The n codewords are determined as codewords corresponding to the initial weight matrix.
[0223] In one implementation of this embodiment, clustering the k sub-matrices of the same dimension to obtain n codewords corresponding to the k sub-matrices of the same dimension includes:
[0224] Reducing the k sub-matrices of the same dimension into one-dimensional vectors respectively to obtain k one-dimensional vectors;
[0225] Dividing the k one-dimensional vectors into n vector groups, wherein each vector group contains at least one one-dimensional vector;
[0226] The element values of corresponding positions in all one-dimensional vectors belonging to the i-th vector group in the k one-dimensional vectors are averaged to obtain a codeword corresponding to all one-dimensional vectors in the i-th vector group; wherein i is an integer from 1 to n.
[0227] In one implementation of this embodiment, the method further includes:
[0228] When the preset stop condition is not met, the weight matrix of the neural network model is released in the memory.
[0229] In an implementation of this embodiment, when the preset stop condition is not satisfied, updating the codeword to obtain an updated codeword includes:
[0230] When a preset stopping condition is not satisfied, determining a weight gradient of a first weight matrix of the neural network model;
[0231] A codeword gradient is determined according to the first weight gradient, and an updated codeword is determined according to the codeword gradient.
[0232] In one implementation of this embodiment, determining a codeword gradient according to the weight gradient, and determining an updated codeword according to the codeword gradient includes:
[0233] Performing weighted summation on the weight gradients of the submatrix corresponding to the j-th codeword in the weight gradient to obtain the codeword gradient corresponding to the j-th codeword; wherein j is an integer from 1 to n;
[0234] Optimizing the codeword gradient corresponding to the j-th codeword to obtain an update amount for the j-th codeword;
[0235] The j-th code word is updated using the update amount of the j-th code word to obtain an updated j-th code word.
[0236] In one implementation of this embodiment, the method further includes:
[0237] Obtain an index, where the index is a correspondence between the codeword and a weight matrix of the neural network model.
[0238] In one implementation of this embodiment, the preset stop condition includes one or more of the following conditions:
[0239] The difference between the result label value corresponding to the training data and the output result of the neural network model for the training data is lower than a preset difference value;
[0240] The change rate of the difference between the result label value corresponding to the training data and the output result of the neural network model for the training data is lower than a preset change threshold;
[0241] The number of updates of the model parameters in the neural network model reaches a preset number of updates;
[0242] The output value of the loss function used by the neural network model reaches a preset threshold; the loss function is used to measure the gap between the output result of the neural network model for the training data and the result label value corresponding to the training data.
[0243] It should also be noted that the specific training process of the neural network model in this embodiment can be found in Figure 3 The process of the method will not be described in detail in this embodiment.
[0244] The embodiment of the present application utilizes a pre-trained neural network model to classify the images to be classified. Since the neural network model can reach global optimality, the classification results output by the neural network model are more accurate, thereby improving the accuracy of the classification results.
[0245] In addition, the present application also provides a text translation method. Based on the neural network model training method provided in the above embodiment, the neural network model obtained according to the neural network model training method can be applied to text translation. Figure 7 , which is a flowchart of a text translation method provided in an embodiment of the present application, the method may include:
[0246] S701: Obtain the text to be translated.
[0247] S702: Input the text to be translated into the trained neural network model to obtain the text translation result output by the neural network model.
[0248] In this embodiment, a text to be translated is first obtained and then input into a pre-trained neural network model to obtain a text translation result corresponding to the text to be translated. For example, English text is translated into Chinese text and the pre-trained neural network model outputs the Chinese translation result, or Chinese text is translated into German text and the pre-trained neural network model outputs the German translation result, etc. This application does not limit the language of translation.
[0249] For example, let's say the text to be translated is English. The neural network model used is a model that can translate the text to be translated. By inputting the text to be translated (or its corresponding feature vector) into the neural network model, a specific translation result of the English text can be obtained. For example, the Chinese translation result or the German translation result of the input English text can be translated.
[0250] The training process of the neural network model includes:
[0251] Retrieve a codeword from a memory, the codeword corresponding to a first weight matrix of a neural network model;
[0252] Determining, according to the codeword, a weight matrix of the neural network model as the first weight matrix, and training the first weight matrix using training data;
[0253] When the preset stop condition is not satisfied, updating the codeword to obtain an updated codeword;
[0254] Storing the updated codeword in the memory;
[0255] Determining a weight matrix of the neural network model as a second weight matrix using the updated codeword obtained in the memory, and training the second weight matrix using training data;
[0256] When the preset stopping condition is met, the training of the neural network model is stopped.
[0257] In an implementation of this embodiment, when the first weight matrix is an initial weight matrix, the method further includes:
[0258] The initial weight matrix is divided to determine the codeword corresponding to the initial weight matrix.
[0259] In an implementation of this embodiment, dividing the initial weight matrix to determine the codeword corresponding to the initial weight matrix includes:
[0260] Divide the initial weight matrix into k sub-matrices of the same dimension; k is a positive integer greater than 1;
[0261] Performing clustering processing on the k sub-matrices of the same dimension to obtain n codewords corresponding to the k sub-matrices of the same dimension, where n is a positive integer greater than 0, and n≤k;
[0262] The n codewords are determined as codewords corresponding to the initial weight matrix.
[0263] In one implementation of this embodiment, clustering the k sub-matrices of the same dimension to obtain n codewords corresponding to the k sub-matrices of the same dimension includes:
[0264] Reducing the k sub-matrices of the same dimension into one-dimensional vectors respectively to obtain k one-dimensional vectors;
[0265] Dividing the k one-dimensional vectors into n vector groups, wherein each vector group contains at least one one-dimensional vector;
[0266] The element values of corresponding positions in all one-dimensional vectors belonging to the i-th vector group in the k one-dimensional vectors are averaged to obtain a codeword corresponding to all one-dimensional vectors in the i-th vector group; wherein i is an integer from 1 to n.
[0267] In one implementation of this embodiment, the method further includes:
[0268] When the preset stop condition is not met, the weight matrix of the neural network model is released in the memory.
[0269] In an implementation of this embodiment, when the preset stop condition is not satisfied, updating the codeword to obtain an updated codeword includes:
[0270] When a preset stopping condition is not satisfied, determining a weight gradient of a first weight matrix of the neural network model;
[0271] A codeword gradient is determined according to the first weight gradient, and an updated codeword is determined according to the codeword gradient.
[0272] In one implementation of this embodiment, determining a codeword gradient according to the weight gradient, and determining an updated codeword according to the codeword gradient includes:
[0273] Performing weighted summation on the weight gradients of the submatrix corresponding to the j-th codeword in the weight gradient to obtain the codeword gradient corresponding to the j-th codeword; wherein j is an integer from 1 to n;
[0274] Optimizing the codeword gradient corresponding to the j-th codeword to obtain an update amount for the j-th codeword;
[0275] The j-th code word is updated using the update amount of the j-th code word to obtain an updated j-th code word.
[0276] In one implementation of this embodiment, the method further includes:
[0277] Obtain an index, where the index is a correspondence between the codeword and a weight matrix of the neural network model.
[0278] In one implementation of this embodiment, the preset stop condition includes one or more of the following conditions:
[0279] The difference between the result label value corresponding to the training data and the output result of the neural network model for the training data is lower than a preset difference value;
[0280] The change rate of the difference between the result label value corresponding to the training data and the output result of the neural network model for the training data is lower than a preset change threshold;
[0281] The number of updates of the model parameters in the neural network model reaches a preset number of updates;
[0282] The output value of the loss function used by the neural network model reaches a preset threshold; the loss function is used to measure the gap between the output result of the neural network model for the training data and the result label value corresponding to the training data.
[0283] It should also be noted that the specific training process of the neural network model in this embodiment can be found in Figure 3 The process of the method will not be described in detail in this embodiment.
[0284] The embodiment of the present application uses a pre-trained neural network model to translate the text to be translated. Since the neural network model can reach global optimization, the translation result output by the neural network model is more accurate, thereby improving the accuracy of the translation result.
[0285] In order to better implement the above solution of the embodiment of the present application, the following also provides related devices for implementing the above solution. Figure 8 As shown, the embodiment of the present application provides a neural network model training device 800. The device 800 may include: a first acquisition unit 801, a first training unit 802, an update unit 803, a storage unit 804, a second training unit 805 and a stop unit 806. The first acquisition unit 801 is used to support the device 800 to perform Figure 3 In the embodiment shown in S301, the first training unit 802 is used to support the apparatus 800 to perform Figure 3 S302 in the embodiment shown. The updating unit 803 is used to support the device 800 to execute Figure 3 S303 in the embodiment shown. The storage unit 804 is used to support the device 800 to execute Figure 3 In the embodiment shown in S304, the second training unit 805 is used to support the apparatus 800 to perform Figure 3 In the embodiment shown in S305, the stopping unit 806 is used to support the apparatus 800 to execute Figure 3 S306 in the embodiment shown. Specifically,
[0286] A first acquiring unit 801 is configured to acquire a codeword from a memory, wherein the codeword corresponds to a first weight matrix of a neural network model;
[0287] A first training unit 802 is configured to determine a weight matrix of a neural network model as a first weight matrix according to the codeword, and train the first weight matrix using training data;
[0288] An updating unit 803, configured to update the codeword to obtain an updated codeword when a preset stop condition is not satisfied;
[0289] The storage unit 804 is used to store the updated codeword in the memory;
[0290] A second training unit 805 is configured to determine a weight matrix of the neural network model as a second weight matrix using the updated codeword obtained in the memory, and train the second weight matrix using the training data;
[0291] The stopping unit 806 is used to stop the training of the neural network model when a preset stopping condition is met.
[0292] In one implementation of this embodiment, when the first weight matrix is an initial weight matrix, the apparatus further includes:
[0293] The partitioning unit is used to partition the initial weight matrix to determine the codeword corresponding to the initial weight matrix.
[0294] In one implementation of this embodiment, the dividing unit includes:
[0295] A first division sub-unit is used to divide the initial weight matrix into k sub-matrices of the same dimension; wherein k is a positive integer greater than 1;
[0296] A clustering sub-unit, configured to cluster k sub-matrices of the same dimension to obtain n codewords corresponding to the k sub-matrices of the same dimension, where n is a positive integer greater than 0 and n≤k;
[0297] The first determining subunit is configured to determine n codewords as codewords corresponding to the initial weight matrix.
[0298] In one implementation of this embodiment, the clustering subunit includes:
[0299] The dimensionality reduction sub-unit is used to reduce the dimensions of k sub-matrices of the same dimension into one-dimensional vectors respectively, thereby obtaining k one-dimensional vectors;
[0300] A second division subunit is configured to divide the k one-dimensional vectors into n vector groups, wherein each vector group includes at least one one-dimensional vector;
[0301] A calculation subunit is used to average the element values of corresponding positions in all one-dimensional vectors belonging to the i-th vector group in the k one-dimensional vectors to obtain a codeword corresponding to all one-dimensional vectors in the i-th vector group; wherein i is an integer from 1 to n.
[0302] In one implementation of this embodiment, the device further includes:
[0303] The release unit is used to release the weight matrix of the neural network model in the memory when the preset stop condition is not met.
[0304] In one implementation of this embodiment, the updating unit 803 includes:
[0305] A second determining subunit, configured to determine a weight gradient of a first weight matrix of the neural network model when a preset stop condition is not satisfied;
[0306] The third determining subunit is configured to determine a codeword gradient according to the first weight gradient, and determine an updated codeword according to the codeword gradient.
[0307] In one implementation of this embodiment, the third determining subunit includes:
[0308] A first obtaining subunit is configured to perform weighted summation on the weight gradients of the submatrices corresponding to the index number of the j-th codeword in the weight gradient to obtain a codeword gradient corresponding to the j-th codeword; wherein j is an integer from 1 to n;
[0309] The second obtaining subunit is used to optimize the codeword gradient corresponding to the j-th codeword to obtain the update amount of the j-th codeword;
[0310] The third obtaining subunit is configured to update the j-th code word using the update amount of the j-th code word to obtain the updated j-th code word.
[0311] In one implementation of this embodiment, the device further includes:
[0312] The second acquisition unit is used to obtain an index, where the index is a correspondence between a codeword and a weight matrix of a neural network model.
[0313] In one implementation of this embodiment, the preset stop condition includes one or more of the following conditions:
[0314] The difference between the result label value corresponding to the training data and the output result of the neural network model for the training data is lower than the preset difference;
[0315] The rate of change of the difference between the result label value corresponding to the training data and the output result of the neural network model for the training data is lower than the preset change threshold;
[0316] The number of updates of the model parameters in the neural network model reaches the preset number of updates;
[0317] The output value of the loss function used by the neural network model reaches a preset threshold; wherein the loss function is used to measure the gap between the output result of the neural network model for the training data and the result label value corresponding to the training data.
[0318] In summary, the present embodiment provides a neural network model training device. When training a neural network model, the codeword corresponding to the first weight matrix of the neural network model is first obtained from the memory. Then, the weight matrix of the neural network model is determined to be the first weight matrix based on the codeword, and the first weight matrix is trained using training data. When the preset stop condition is not met, the codeword is updated to obtain the updated codeword, and the updated codeword is stored in the memory. Then, the weight matrix of the neural network model is determined to be the second weight matrix using the updated codeword obtained in the memory, and the second weight matrix is trained using training data. When the preset stop condition is met, the training of the neural network model is stopped. It can be seen that when training the neural network model, the embodiment of the present application no longer directly reads the weight matrix from the memory, but reads the codeword corresponding to the weight matrix to form the weight matrix for training. Since the memory space occupied by the codeword is much smaller than the memory space occupied by the weight matrix, the amount of data read from the memory can be greatly reduced, overcoming the memory bottleneck problem. Moreover, since the present application no longer calculates the update amount of the weight matrix during the model training process, but calculates the update amount of the codeword to re-determine the new weight matrix for subsequent training, it can reduce the amount of intermediate parameter calculation in the update process, thereby enabling the smooth training of the neural network model in resource-constrained scenarios.
[0319] See Figure 9 As shown, the embodiment of the present application further provides an image classification device 900. The device 900 may include: an image acquisition unit 901, an image classification unit 902 and a neural network model training unit 903. The image acquisition unit 901 is used to support the device 900 to perform Figure 6In the embodiment shown in S601, the image classification unit 902 is used to support the apparatus 900 to perform Figure 6 In the embodiment shown in S602, the neural network model training unit 903 is used to support the apparatus 900 to execute Figure 3 S301-S306 in the embodiment shown. Specifically,
[0320] An image acquisition unit 901 is used to acquire an image to be classified;
[0321] An image classification unit 902 is used to input an image to be classified into a trained neural network model and obtain an image classification result output by the neural network model;
[0322] A neural network model training unit 903 is used to train a neural network model;
[0323] The neural network model training unit 903 includes:
[0324] A first acquiring unit is configured to acquire a codeword from a memory, wherein the codeword corresponds to a first weight matrix of a neural network model;
[0325] A first training unit is configured to determine a weight matrix of the neural network model as a first weight matrix according to the codeword, and train the first weight matrix using training data; wherein the training data includes positive sample images and negative sample images;
[0326] An updating unit, configured to update the codeword to obtain an updated codeword when the neural network model outputs a probability value that the training data is a positive sample image and a preset stop condition is not satisfied;
[0327] a storage unit, configured to store the updated codeword in a memory;
[0328] A second training unit is configured to determine a weight matrix of the neural network model as a second weight matrix using the updated codeword obtained in the memory, and to train the second weight matrix using the training data;
[0329] The stopping unit is used to stop the training of the neural network model when a preset stopping condition is met.
[0330] In one implementation of this embodiment, when the first weight matrix is an initial weight matrix, the apparatus further includes:
[0331] The partitioning unit is used to partition the initial weight matrix to determine the codeword corresponding to the initial weight matrix.
[0332] In one implementation of this embodiment, the dividing unit includes:
[0333] A first division sub-unit is used to divide the initial weight matrix into k sub-matrices of the same dimension; wherein k is a positive integer greater than 1;
[0334] A clustering sub-unit, configured to cluster k sub-matrices of the same dimension to obtain n codewords corresponding to the k sub-matrices of the same dimension, where n is a positive integer greater than 0 and n≤k;
[0335] The first determining subunit is configured to determine n codewords as codewords corresponding to the initial weight matrix.
[0336] In one implementation of this embodiment, the clustering subunit includes:
[0337] The dimensionality reduction sub-unit is used to reduce the dimensions of k sub-matrices of the same dimension into one-dimensional vectors respectively, thereby obtaining k one-dimensional vectors;
[0338] A second division subunit is configured to divide the k one-dimensional vectors into n vector groups, wherein each vector group includes at least one one-dimensional vector;
[0339] A calculation subunit is used to average the element values of corresponding positions in all one-dimensional vectors belonging to the i-th vector group in the k one-dimensional vectors to obtain a codeword corresponding to all one-dimensional vectors in the i-th vector group; wherein i is an integer from 1 to n.
[0340] In one implementation of this embodiment, the apparatus further includes:
[0341] The release unit is used to release the weight matrix of the neural network model in the memory when the preset stop condition is not met.
[0342] In one implementation of this embodiment, the updating unit includes:
[0343] A second determining subunit, configured to determine a weight gradient of a first weight matrix of the neural network model when a preset stop condition is not satisfied;
[0344] The third determining subunit is configured to determine a codeword gradient according to the first weight gradient, and determine an updated codeword according to the codeword gradient.
[0345] In one implementation of this embodiment, the third determining subunit includes:
[0346] A first obtaining subunit is configured to perform weighted summation on the weight gradients of the submatrices corresponding to the index number of the j-th codeword in the weight gradient to obtain a codeword gradient corresponding to the j-th codeword; wherein j is an integer from 1 to n;
[0347] The second obtaining subunit is used to optimize the codeword gradient corresponding to the j-th codeword to obtain the update amount of the j-th codeword;
[0348] The third obtaining subunit is configured to update the j-th code word using the update amount of the j-th code word to obtain the updated j-th code word.
[0349] In one implementation of this embodiment, the device further includes:
[0350] The second acquisition unit is used to obtain an index, where the index is a correspondence between a codeword and a weight matrix of a neural network model.
[0351] In one implementation of this embodiment, the preset stop condition includes one or more of the following conditions:
[0352] The difference between the result label value corresponding to the training data and the output result of the neural network model for the training data is lower than the preset difference;
[0353] The rate of change of the difference between the result label value corresponding to the training data and the output result of the neural network model for the training data is lower than the preset change threshold;
[0354] The number of updates of the model parameters in the neural network model reaches the preset number of updates;
[0355] The output value of the loss function used by the neural network model reaches a preset threshold; among them, the loss function is used to measure the gap between the output result of the neural network model for the training data and the result label value corresponding to the training data.
[0356] See Figure 10 As shown, the embodiment of the present application also provides a text translation device 1000. The device 1000 may include: a text acquisition unit 1001, a text translation unit 1002 and a neural network model training unit 1003. The text acquisition unit 1001 is used to support the device 1000 to perform Figure 7 In the embodiment shown in S701, the text translation unit 1002 is used to support the apparatus 1000 to execute Figure 7 In the embodiment shown in S702, the neural network model training unit 1003 is used to support the apparatus 1000 to execute Figure 3 S301-S306 in the embodiment shown. Specifically,
[0357] The text acquisition unit 1001 is used to acquire the text to be translated;
[0358] The text translation unit 1002 is used to input the text to be translated into the trained neural network model and obtain the text translation result output by the neural network model;
[0359] A neural network model training unit 1003 is used to train a neural network model;
[0360] The neural network model training unit 1003 includes:
[0361] A first acquiring unit is configured to acquire a codeword from a memory, wherein the codeword corresponds to a first weight matrix of a neural network model;
[0362] A first training unit is configured to determine a weight matrix of a neural network model as a first weight matrix according to the codeword, and train the first weight matrix using training data; wherein the training data is sample text;
[0363] An updating unit, configured to update the codeword to obtain an updated codeword when the neural network model outputs a translation result of the sample text and a preset stop condition is not satisfied;
[0364] a storage unit, configured to store the updated codeword in a memory;
[0365] a second training unit, configured to determine a weight matrix of the neural network model as a second weight matrix using the updated codeword obtained in the memory, and to train the second weight matrix of the neural network model using the training data;
[0366] The stopping unit is used to stop the training of the neural network model when a preset stopping condition is met.
[0367] In one implementation of this embodiment, when the first weight matrix is an initial weight matrix, the apparatus further includes:
[0368] The partitioning unit is used to partition the initial weight matrix to determine the codeword corresponding to the initial weight matrix.
[0369] In one implementation of this embodiment, the dividing unit includes:
[0370] A first division sub-unit is used to divide the initial weight matrix into k sub-matrices of the same dimension; wherein k is a positive integer greater than 1;
[0371] A clustering sub-unit, configured to cluster k sub-matrices of the same dimension to obtain n codewords corresponding to the k sub-matrices of the same dimension, where n is a positive integer greater than 0 and n≤k;
[0372] The first determining subunit is configured to determine n codewords as codewords corresponding to the initial weight matrix.
[0373] In one implementation of this embodiment, the clustering subunit includes:
[0374] The dimensionality reduction sub-unit is used to reduce the dimensions of k sub-matrices of the same dimension into one-dimensional vectors respectively, thereby obtaining k one-dimensional vectors;
[0375] A second division subunit is configured to divide the k one-dimensional vectors into n vector groups, wherein each vector group includes at least one one-dimensional vector;
[0376] A calculation subunit is used to average the element values of corresponding positions in all one-dimensional vectors belonging to the i-th vector group in the k one-dimensional vectors to obtain a codeword corresponding to all one-dimensional vectors in the i-th vector group; wherein i is an integer from 1 to n.
[0377] In one implementation of this embodiment, the device further includes:
[0378] The release unit is used to release the weight matrix of the neural network model in the memory when the preset stop condition is not met.
[0379] In one implementation of this embodiment, the updating unit includes:
[0380] A second determining subunit, configured to determine a weight gradient of a first weight matrix of the neural network model when a preset stop condition is not satisfied;
[0381] The third determining subunit is configured to determine a codeword gradient according to the first weight gradient, and determine an updated codeword according to the codeword gradient.
[0382] In one implementation of this embodiment, the third determining subunit includes:
[0383] A first obtaining subunit is configured to perform weighted summation on the weight gradients of the submatrices corresponding to the index number of the j-th codeword in the weight gradient to obtain a codeword gradient corresponding to the j-th codeword; wherein j is an integer from 1 to n;
[0384] The second obtaining subunit is used to optimize the codeword gradient corresponding to the j-th codeword to obtain the update amount of the j-th codeword;
[0385] The third obtaining subunit is configured to update the j-th code word using the update amount of the j-th code word to obtain the updated j-th code word.
[0386] In one implementation of this embodiment, the device further includes:
[0387] The second acquisition unit is used to obtain an index, where the index is a correspondence between a codeword and a weight matrix of a neural network model.
[0388] In one implementation of this embodiment, the preset stop condition includes one or more of the following conditions:
[0389] The difference between the result label value corresponding to the training data and the output result of the neural network model for the training data is lower than the preset difference;
[0390] The rate of change of the difference between the result label value corresponding to the training data and the output result of the neural network model for the training data is lower than the preset change threshold;
[0391] The number of updates of the model parameters in the neural network model reaches the preset number of updates;
[0392] The output value of the loss function used by the neural network model reaches a preset threshold; among them, the loss function is used to measure the gap between the output result of the neural network model for the training data and the result label value corresponding to the training data.
[0393] See also Figure 11 The embodiment of the present application provides a neural network model training device 1100, which includes a memory 1101, a processor 1102 and a communication interface 1103.
[0394] Memory 1101, used for storing instructions;
[0395] Processor 1102 is used to execute the instructions in memory 1101 and execute the above application Figure 3 The neural network model training method in the illustrated embodiment;
[0396] The communication interface 1103 is used for communication.
[0397] The memory 1101, processor 1102, and communication interface 1103 are interconnected via a bus 1104. Bus 1104 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. Buses can be divided into address buses, data buses, control buses, etc. For ease of representation, Figure 11 Only one thick line is used in the diagram, but this does not mean that there is only one bus or one type of bus.
[0398] In a specific embodiment, the processor 1102 is used to first obtain the codeword corresponding to the first weight matrix of the neural network model from the memory when training the neural network model, and then determine the weight matrix of the neural network model as the first weight matrix based on the codeword, and use the training data to train the first weight matrix. When the preset stop condition is not met, the codeword is updated to obtain the updated codeword, and the updated codeword is stored in the memory. Then, the updated codeword obtained in the memory is used to determine the weight matrix of the neural network model as the second weight matrix, and the training data is used to train the second weight matrix, and then when the preset stop condition is met, the training of the neural network model is stopped. Please refer to the above for the detailed processing process of the processor 1102. Figure 3 The detailed description of S301 , S302 , S303 , S304 , S305 and S306 in the illustrated embodiment will not be repeated here.
[0399] The above-mentioned memory 1101 can be a random-access memory (RAM), a flash memory, a read-only memory (ROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a register, a hard disk, a mobile hard disk, a CD-ROM or any other form of storage medium known to those skilled in the art.
[0400] The processor 1102 may be, for example, a central processing unit (CPU), a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It may implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of the embodiments of the present application. The processor may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, and the like.
[0401] The communication interface 1103 may be, for example, an interface card, and may be an Ethernet interface or an asynchronous transfer mode (ATM) interface.
[0402] See also Figure 12 The embodiment of the present application provides an image classification device 1200, which includes a memory 1201, a processor 1202 and a communication interface 1203.
[0403] Memory 1201, used for storing instructions;
[0404] Processor 1202 is used to execute the instructions in memory 1201 and execute the above application Figure 6 The image classification method in the illustrated embodiment;
[0405] The communication interface 1203 is used for communication.
[0406] The memory 1201, processor 1202, and communication interface 1203 are interconnected via a bus 1204. Bus 1204 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. Buses can be divided into address buses, data buses, control buses, etc. For ease of representation, Figure 12 Only one thick line is used in the diagram, but this does not mean that there is only one bus or one type of bus.
[0407] In a specific embodiment, the processor 1202 is used to first obtain the image to be classified when classifying the image, and input the image to be classified into a pre-trained neural network model to obtain the image classification result corresponding to the image to be classified. Please refer to the above for the detailed processing process of the processor 1202. Figure 6 The detailed description of S601, S602 and S603 in the illustrated embodiment will not be repeated here.
[0408] The above-mentioned memory 1201 can be a random-access memory (RAM), a flash memory, a read-only memory (ROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a register, a hard disk, a mobile hard disk, a CD-ROM or any other form of storage medium known to those skilled in the art.
[0409] The processor 1202 may be, for example, a central processing unit (CPU), a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It may implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of the embodiments of the present application. The processor may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, and the like.
[0410] The communication interface 1203 may be, for example, an interface card, and may be an Ethernet interface or an asynchronous transfer mode (ATM) interface.
[0411] See also Figure 13 The embodiment of the present application provides a text translation device 1300, which includes a memory 1301, a processor 1302 and a communication interface 1303.
[0412] Memory 1301, used for storing instructions;
[0413] Processor 1302 is used to execute the instructions in memory 1301 and execute the above application Figure 7 The image classification method in the illustrated embodiment;
[0414] The communication interface 1303 is used for communication.
[0415] Memory 1301, processor 1302, and communication interface 1303 are interconnected via bus 1304; bus 1304 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. Buses can be divided into address buses, data buses, control buses, etc. For ease of representation, Figure 13 Only one thick line is used in the diagram, but this does not mean that there is only one bus or one type of bus.
[0416] In a specific embodiment, the processor 1302 is used to first obtain the text to be translated when translating the text, and input the text to be translated into a pre-trained neural network model to obtain the text translation result corresponding to the text to be translated. Please refer to the above for the detailed processing process of the processor 1302. Figure 7 The detailed description of S701, S702 and S703 in the illustrated embodiment will not be repeated here.
[0417] The above-mentioned memory 1301 can be a random-access memory (RAM), a flash memory, a read-only memory (ROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a register, a hard disk, a mobile hard disk, a CD-ROM or any other form of storage medium known to those skilled in the art.
[0418] The processor 1302 may be, for example, a central processing unit (CPU), a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It may implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of the embodiments of the present application. The processor may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, and the like.
[0419] The communication interface 1303 may be, for example, an interface card, and may be an Ethernet interface or an asynchronous transfer mode (ATM) interface.
[0420] An embodiment of the present application also provides a computer-readable storage medium comprising instructions, which, when executed on a computer, enables the computer to execute any implementation of the neural network model training method described in the above embodiments, or execute the image classification method described in the above embodiments, or execute the text translation method described in the above embodiments.
[0421] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, and this is merely a way of distinguishing the objects of the same attributes when describing them in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.
[0422] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0423] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0424] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0425] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0426] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0427] As described above, the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A neural network model training method, characterized in that: The method comprises: Retrieve a codeword from a memory, the codeword corresponding to a first weight matrix of a neural network model; Obtain an index, where the index is a correspondence between the codeword and the weight matrix of the neural network model, the index including an index value and an index number corresponding to the index value, the index value having a one-to-one correspondence with the codeword, the index number having a one-to-one correspondence with a submatrix, and the submatrix being obtained by dividing the initial weight matrix of the neural network model; Determining a weight matrix of the neural network model as the first weight matrix according to the codeword and the index, and training the first weight matrix using training data; When the preset stop condition is not satisfied, updating the codeword to obtain an updated codeword includes: When a preset stopping condition is not satisfied, determining a weight gradient of a first weight matrix of the neural network model; Performing weighted summation on the weight gradients of the submatrix corresponding to the j-th codeword in the weight gradient to obtain the codeword gradient corresponding to the j-th codeword; wherein j is an integer from 1 to n; Optimizing the codeword gradient corresponding to the j-th codeword using an optimizer to obtain an update amount of the j-th codeword; Updating the j-th code word using the update amount of the j-th code word to obtain an updated j-th code word; Storing the updated codeword in the memory; Determining a weight matrix of the neural network model as a second weight matrix using the updated codeword obtained in the memory, and training the second weight matrix using training data; When the preset stopping condition is met, the training of the neural network model is stopped.
2. The method according to claim 1, characterized in that When the first weight matrix is an initial weight matrix, the method further includes: The initial weight matrix is divided to determine the codeword corresponding to the initial weight matrix.
3. The method according to claim 2, characterized in that The dividing the initial weight matrix to determine the codeword corresponding to the initial weight matrix includes: Divide the initial weight matrix into k sub-matrices of the same dimension; k is a positive integer greater than 1; Performing clustering processing on the k sub-matrices of the same dimension to obtain n codewords corresponding to the k sub-matrices of the same dimension, where n is a positive integer greater than 0; The n codewords are determined as codewords corresponding to the initial weight matrix.
4. The method according to claim 3, characterized in that The clustering of the k sub-matrices of the same dimension to obtain n codewords corresponding to the k sub-matrices of the same dimension includes: Reducing the k sub-matrices of the same dimension into one-dimensional vectors respectively to obtain k one-dimensional vectors; Dividing the k one-dimensional vectors into n vector groups, wherein each vector group contains at least one one-dimensional vector; The element values of corresponding positions in all one-dimensional vectors belonging to the i-th vector group in the k one-dimensional vectors are averaged to obtain a codeword corresponding to all one-dimensional vectors in the i-th vector group; wherein i is an integer from 1 to n.
5. The method according to claim 1, wherein The method further comprises: When the preset stop condition is not met, the weight matrix of the neural network model is released in the memory.
6. The method according to any one of claims 1 to 5, characterized in that: The preset stop condition includes one or more of the following conditions: The difference between the result label value corresponding to the training data and the output result of the neural network model for the training data is lower than a preset difference value; The change rate of the difference between the result label value corresponding to the training data and the output result of the neural network model for the training data is lower than a preset change threshold; The number of updates of the model parameters in the neural network model reaches a preset number of updates; The output value of the loss function used by the neural network model reaches a preset threshold; the loss function is used to measure the gap between the output result of the neural network model for the training data and the result label value corresponding to the training data.
7. An image classification method, characterized in that: The method comprises: Get the image to be classified; Inputting the image to be classified into a trained neural network model to obtain an image classification result output by the neural network model; The training process of the neural network model includes: Retrieve a codeword from a memory, wherein the codeword corresponds to a first weight matrix of a neural network model; Obtain an index, where the index is a correspondence between the codeword and the weight matrix of the neural network model, the index including an index value and an index number corresponding to the index value, the index value having a one-to-one correspondence with the codeword, the index number having a one-to-one correspondence with a submatrix, and the submatrix being obtained by dividing the initial weight matrix of the neural network model; Determining a weight matrix of the neural network model as the first weight matrix according to the codeword and the index, and training the first weight matrix using training data; the training data includes positive sample images and negative sample images; When the neural network model outputs a probability value that the training data is a positive sample image, if a preset stopping condition is not satisfied, updating the codeword to obtain an updated codeword, comprising: determining a weight gradient of a first weight matrix of the neural network model when the preset stopping condition is not satisfied; performing weighted summation on the weight gradients of the submatrix corresponding to the jth codeword in the weight gradient to obtain a codeword gradient corresponding to the jth codeword; wherein j is an integer from 1 to n; optimizing the codeword gradient corresponding to the jth codeword using an optimizer to obtain an updated amount of the jth codeword; and updating the jth codeword using the updated amount of the jth codeword to obtain an updated jth codeword; storing the updated codeword in the memory; Determining a weight matrix of the neural network model as a second weight matrix using the updated codeword obtained in the memory, and training the second weight matrix using training data; When the preset stopping condition is met, the training of the neural network model is stopped.
8. A text translation method, characterized in that: The method comprises: Get the text to be translated; Inputting the text to be translated into a trained neural network model to obtain a text translation result output by the neural network model; The training process of the neural network model includes: Retrieve a codeword from a memory, wherein the codeword corresponds to a first weight matrix of a neural network model; Obtain an index, where the index is a correspondence between the codeword and the weight matrix of the neural network model, the index including an index value and an index number corresponding to the index value, the index value having a one-to-one correspondence with the codeword, the index number having a one-to-one correspondence with a submatrix, and the submatrix being obtained by dividing the initial weight matrix of the neural network model; Determining a weight matrix of the neural network model as the first weight matrix according to the codeword and the index, and training the first weight matrix using training data; the training data is sample text; After the neural network model outputs the translation result of the sample text, if a preset stopping condition is not satisfied, updating the codeword to obtain an updated codeword, comprising: determining a weight gradient of a first weight matrix of the neural network model when the preset stopping condition is not satisfied; performing weighted summation on the weight gradients of the submatrix corresponding to the jth codeword in the weight gradient to obtain a codeword gradient corresponding to the jth codeword, wherein j is an integer from 1 to n; optimizing the codeword gradient corresponding to the jth codeword using an optimizer to obtain an updated amount of the jth codeword; and updating the jth codeword using the updated amount of the jth codeword to obtain an updated jth codeword; Storing the updated codeword in the memory; Determining a weight matrix of the neural network model as a second weight matrix using the updated codeword obtained in the memory, and training the second weight matrix of the neural network model using training data; When the preset stopping condition is met, the training of the neural network model is stopped.
9. A neural network model training device, characterized in that: The device comprises: A first acquiring unit is configured to acquire a codeword from a memory, where the codeword corresponds to a first weight matrix of a neural network model; a second acquiring unit, configured to acquire an index, wherein the index is a correspondence between the codeword and the weight matrix of the neural network model, the index including an index value and an index number corresponding to the index value, the index value corresponding to the codeword in a one-to-one manner, the index number corresponding to a submatrix in a one-to-one manner, and the submatrix obtained by dividing the initial weight matrix of the neural network model; A first training unit is configured to determine, according to the codeword and the index, a weight matrix of the neural network model as the first weight matrix, and train the first weight matrix using training data; an updating unit, configured to update the codeword to obtain an updated codeword when a preset stop condition is not satisfied; a storage unit, configured to store the updated codeword in the memory; a second training unit, configured to determine a weight matrix of the neural network model as a second weight matrix using the updated codeword obtained in the memory, and train the second weight matrix using training data; A stopping unit, configured to stop the training of the neural network model when the preset stopping condition is met; The updating unit includes: A second determining subunit, configured to determine a weight gradient of a first weight matrix of the neural network model when a preset stopping condition is not satisfied; a third determining subunit, configured to determine a codeword gradient according to the first weight gradient, and determine an updated codeword according to the codeword gradient; The third determining subunit includes: A first obtaining subunit is configured to perform weighted summation on the weight gradients of the submatrix corresponding to the j-th codeword in the weight gradient to obtain a codeword gradient corresponding to the j-th codeword; wherein j is an integer from 1 to n; a second obtaining subunit, configured to optimize the codeword gradient corresponding to the j-th codeword using an optimizer to obtain an update amount of the j-th codeword; The third obtaining subunit is configured to update the j-th code word using the update amount of the j-th code word to obtain an updated j-th code word.
10. The device according to claim 9, characterized in that When the first weight matrix is an initial weight matrix, the apparatus further includes: The dividing unit is used to divide the initial weight matrix to determine the codeword corresponding to the initial weight matrix.
11. The device according to claim 10, characterized in that The division unit includes: A first division subunit is configured to divide the initial weight matrix into k sub-matrices of the same dimension; k is a positive integer greater than 1; a clustering subunit, configured to perform clustering processing on the k sub-matrices of the same dimension to obtain n codewords corresponding to the k sub-matrices of the same dimension, where n is a positive integer greater than 0; The first determining subunit is configured to determine the n codewords as codewords corresponding to the initial weight matrix.
12. The device according to claim 11, characterized in that The clustering subunit includes: A dimensionality reduction subunit, configured to reduce the dimensions of the k submatrices of the same dimension into one-dimensional vectors, thereby obtaining k one-dimensional vectors; A second division subunit is configured to divide the k one-dimensional vectors into n vector groups, wherein each vector group includes at least one one-dimensional vector; A calculation subunit is used to average the element values of corresponding positions in all one-dimensional vectors belonging to the i-th vector group in the k one-dimensional vectors to obtain a codeword corresponding to all one-dimensional vectors in the i-th vector group; wherein i is an integer from 1 to n.
13. The device according to claim 12, characterized in that The device further comprises: A releasing unit is used to release the weight matrix of the neural network model in the memory when the preset stopping condition is not met.
14. The device according to any one of claims 9 to 13, characterized in that The preset stop condition includes one or more of the following conditions: The difference between the result label value corresponding to the training data and the output result of the neural network model for the training data is lower than a preset difference value; The change rate of the difference between the result label value corresponding to the training data and the output result of the neural network model for the training data is lower than a preset change threshold; The number of updates of the model parameters in the neural network model reaches a preset number of updates; The output value of the loss function used by the neural network model reaches a preset threshold; the loss function is used to measure the gap between the output result of the neural network model for the training data and the result label value corresponding to the training data.
15. An image classification device, characterized in that: The device comprises: An image acquisition unit, configured to acquire an image to be classified; An image classification unit, configured to input the image to be classified into a trained neural network model to obtain an image classification result output by the neural network model; A neural network model training unit, used for training the neural network model; The neural network model training unit includes: A first acquiring unit is configured to acquire a codeword from a memory, where the codeword corresponds to a first weight matrix of a neural network model; a second acquiring unit, configured to acquire an index, wherein the index is a correspondence between the codeword and the weight matrix of the neural network model, the index including an index value and an index number corresponding to the index value, the index value corresponding to the codeword in a one-to-one manner, the index number corresponding to a submatrix in a one-to-one manner, and the submatrix obtained by dividing the initial weight matrix of the neural network model; a first training unit, configured to determine, based on the codeword and the index, a weight matrix of the neural network model as the first weight matrix, and train the first weight matrix using training data; the training data comprising positive sample images and negative sample images; an updating unit, configured to update the codeword to obtain an updated codeword when the neural network model outputs a probability value that the training data is a positive sample image and a preset stop condition is not satisfied; The updating unit is specifically configured to, when the neural network model outputs a probability value that the training data is a positive sample image and a preset stopping condition is not satisfied, determine a weight gradient of a first weight matrix of the neural network model; perform weighted summation on the weight gradients of the submatrix corresponding to the j-th codeword in the weight gradient to obtain a codeword gradient corresponding to the j-th codeword, wherein j is an integer from 1 to n; optimize the codeword gradient corresponding to the j-th codeword using an optimizer to obtain an update amount for the j-th codeword; and update the j-th codeword using the update amount for the j-th codeword to obtain an updated j-th codeword; a storage unit, configured to store the updated codeword in the memory; a second training unit, configured to determine a weight matrix of the neural network model as a second weight matrix using the updated codeword obtained in the memory, and train the second weight matrix using training data; A stopping unit is used to stop the training of the neural network model when the preset stopping condition is met.
16. A text translation device, characterized in that: The device comprises: A text acquisition unit, used to acquire the text to be translated; A text translation unit, configured to input the text to be translated into a trained neural network model and obtain a text translation result output by the neural network model; A neural network model training unit, used for training the neural network model; The neural network model training unit includes: A first acquiring unit is configured to acquire a codeword from a memory, where the codeword corresponds to a first weight matrix of a neural network model; a second acquiring unit, configured to acquire an index, wherein the index is a correspondence between the codeword and the weight matrix of the neural network model, the index including an index value and an index number corresponding to the index value, the index value corresponding to the codeword in a one-to-one manner, the index number corresponding to a submatrix in a one-to-one manner, and the submatrix obtained by dividing the initial weight matrix of the neural network model; a first training unit, configured to determine a weight matrix of the neural network model as the first weight matrix according to the codeword and the index, and train the first weight matrix using training data; the training data being sample text; an updating unit, configured to update the codeword to obtain an updated codeword when the neural network model outputs a translation result of the sample text and a preset stop condition is not satisfied; The updating unit is specifically configured to, when a preset stopping condition is not satisfied, determine a weight gradient of a first weight matrix of the neural network model; perform weighted summation on the weight gradients of the submatrix corresponding to the j-th codeword in the weight gradient to obtain a codeword gradient corresponding to the j-th codeword; wherein j is an integer from 1 to n; optimize the codeword gradient corresponding to the j-th codeword using an optimizer to obtain an update amount for the j-th codeword; and update the j-th codeword using the update amount for the j-th codeword to obtain an updated j-th codeword; a storage unit, configured to store the updated codeword in the memory; a second training unit, configured to determine a weight matrix of the neural network model as a second weight matrix using the updated codeword obtained in the memory, and train the second weight matrix of the neural network model using training data; A stopping unit is used to stop the training of the neural network model when the preset stopping condition is met.
17. A neural network model training device, characterized in that: The device includes a memory and a processor; The memory is used to store instructions; The processor is used to execute the instructions in the memory and perform the neural network model training method described in any one of claims 1-6.
18. An image classification device, characterized in that The device includes a memory and a processor; The memory is used to store instructions; The processor is configured to execute the instructions in the memory and perform the image classification method according to claim 7.
19. A text translation device, characterized in that: The device includes a memory and a processor; The memory is used to store instructions; The processor is configured to execute the instructions in the memory to perform the text translation method according to claim 8.
20. A computer-readable storage medium comprising instructions, which, when executed on a computer, causes the computer to execute the neural network model training method according to any one of claims 1 to 6, or implement the image classification method according to claim 7, or implement the text translation method according to claim 8.
Citation Information
Patent Citations
Convolution neural network training and testing method and training and testing device
CN107886164A
Lightweight face recognition method and system based on depth separable convolution
CN109063666A
Processing method and device
CN109697507A
System and method for neural networks
CN110998607A