The invention relates to a memory and a training method for neutral network based on memory.
Neutral network (NN) is a mathematical model which could be applied to machine learning. In the past, neural networks might be built with mathematical models by software on computer devices, and operated by processors based on the mathematical models. As the requirements for computing speed increase, the use of memory with high-speed computing capabilities to implement neural networks has also become the focus of research. This technique is called computing in memory (CIM). Although CI has many advantages, due to the characteristics of memory, such as temperature, the number of reads and writes, the relationship between the input and output of the memory cells is usually not ideally linear. How to reduce the adverse effects of non-ideal memory on the accuracy of decisions made based on the results calculated in memory is an important issue.
An embodiment of the present invention discloses a training method for neutral network based on memory. The training method includes: obtaining one or more transfer functions of a memory corresponding to one or more influence factors: determining a training plan according to an ideal case and the one or more influence factors; training the neutral network according to the training plan and the one or more transfer functions to obtain a plurality of weights of the trained neutral network: and programming the memory according to the weights.
Another embodiment of the present invention discloses a memory. The memory includes a number of memory cells, configured to represent a number of synapses of a neutral network. Each of the memory cells includes a resistor. The resistances of the resistors are determined by the following: obtaining one or more transfer functions of the memory cells corresponding to one or more influence factors; determining a training plan according to an ideal case and the one or more influence factors; training the neutral network according to the training plan and the one or more transfer functions to obtain a plurality of weights of the trained neutral network; and programming the memory according to the weights.
The above and other aspects of the invention will become better understood with regard to the following detailed description of the preferred but non-limiting embodiment(s). The following description is made with reference to the accompanying drawings.
Referring to
The memory cells C11˜C33 could represent a number of synapses of the neutral network. The resistance R11˜R33 (or conductance, i.e., reciprocal of the resistance) of the variable resistor of the memory cells C11˜C33 could represent a number of weight of the synapses. The input voltage V1˜V3 of the word lines WL1˜WL3 could represent the input data. The output currents I1˜I3 sensed on the bit lines BL1˜BL3 would be: I1=V1*1/R11+V2*1/R21+V3*1/R31, I2=V1*1/R12+V2*1/R22+V3*1/R32, I3=V1*1/R13+V2*1/R23+V3*1/R33. The currents I1˜I3 represent the results obtained by the operation of the neutral network with the input data. The currents I1˜I3 could be sent to a decision circuit (not shown) for a subsequent operation to generate a decision.
Noted that the example in
In order to improve the accuracy of decision-making, the neutral network usually would be trained. For example, training data would be input to the neutral network for operation. Decisions would be generated according to the results calculated by the neutral network. The decisions would be compared with the ground truth corresponding to the training data. The weights of the neutral network would be modified according to the comparison results. Currently, there are two approaches for training the neutral network based on memory: (1) training by a computer device with software according to the ideal mathematical model of the neutral network, and (2) training on the memory. However, the approach (1) does not consider the non-ideal characteristics of the memory, and the approach (2) does not consider the ideal mathematical model. When performing the in-memory calculations of the neural network trained by the above two approaches, the accuracy of the decisions made based on the results of the in-memory calculations is insufficient. In order to solve the above problem, the present invention provides a training method for neutral network based on memory.
Referring to
At step S201, one or more transfer functions corresponding to one or more influence factors of a memory corresponding to a neutral network are obtained. The memory corresponding to the neutral network refers to the memory is used as a hardware for implementing the neutral network. The transfer function refers to a relationship between the input and the output of the memory cells of the memory corresponding to the influence factor. The influence factors may include different temperatures, different number of reads and writes, different input voltages, change at each read operation, memory retention, programming error and so on. The memory retention refers to the time that data stored in the memory cell. The programming error refers to the difference between the real value and the ideal value to be written while programming. For example, the influence factors may include a temperature of 40 degree Celsius, a temperature of 50 degree Celsius, 5000 reads and writes, 10000 reads and writes and so on. In actual memory, the components such as the transistors and the variable resistors of the memory cells are usually non-ideal. Such non-ideal characteristics would lead to a ratio of the input voltage to the output current of the memory cells to be not a fixed value due to the influence of the influence factors.
Referring to
Noted that the transfer functions could be obtained through actual testing, historical records and any other means. The present invention is not limited.
At step S203, a training plan is determined according to the one or more influence factors and the ideal case. The ideal case represents the memory would not be affected by any influence factor so that the ideal mathematical model of the neutral network is met. In other words, in ideal case, for each of the memory cells, the ratio of the input voltage to the output current corresponding to a specific resistance is constant. In an embodiment, determining the training plan may include steps S401˜S407, as shown in
At step S205, the neutral network is trained according to the training plan and the transfer functions associated to the training plan, by a computer device with software simulation, to obtain a number of weights of the trained neutral network. “Simulation” refers to perform the operation of the mathematical model of the neutral network by a processor of the computer device, and simulate the non-ideal cases with software. “Simulate the non-ideal cases with software” refers to, while performing the training for one of the influence factors, for each of the synapses of the neutral network, adjust the output value of the synapse according to the transfer function according to the influence factor, the weight corresponding to the synapse and the input value of the synapse. In an embodiment, the training of the neutral network could be performed sequentially according to the training plan. In another embodiment, the training of the neutral network could be performed in any order according to the training plan. In general, a process of a single training may include: inputting training data to the neutral network; calculating by the neutral network according to the training data to obtain one or more decision parameters; generating a decision according to the decision parameters; calculating a score according to the decision and the ground truth corresponding to the training data; and modifying one or more weight of the neutral network. Since the details of the training process have many existing techniques, it would not be described herein.
At step S207, the memory cells of the memory are programmed according to the weights to obtain the memory (operation memory) for implementing the neutral network.
Noted that the training method of the present invention could be applied to any suitable memory type. For example, phase-change memory (PCM), Ferroelectronic RAM (FeRAM) could apply the training method of the present invention.
In addition, according to the above training method, the present invention further provides a memory. The memory includes a number of memory cells. Each of the memory cells includes a resistor. The memory cells represent a number of synapses of a neutral network. The resistances of the resistors of the memory cells are determined according to a number of weights obtained through the above training method.
Refer to Table 1. In Table 1, ACCi is the accuracy of the decision obtained by calculation based on the computer device simulating the trained neural network in ideal case, and ACCn is the accuracy of the decision obtained by performing calculations based on the memory used to implement the trained neural network. From Table 1, in the five tests, the difference between the accuracy based on the ideal case and the accuracy based on the computing in memory is within 2%. This means that the training method proposed by the present invention could effectively improve the problem of reduced accuracy of subsequent decisions caused by the characteristics of the memory itself when the memory is used to implement a neutral network.
While the invention has been described by way of example and in terms of the preferred embodiment(s), it is to be understood that the invention is not limited thereto. On the contrary, it is intended to cover various modifications and similar arrangements and procedures, and the scope of the appended claims therefore should be accorded the broadest interpretation so as to encompass all such modifications and similar arrangements and procedures.