Computer-implemented method for executing SoftMax function using piecewise approximation
By using integer operations and segmented approximation methods in the SoftMax function, the high computing resource and energy consumption problems caused by exponential operations in the prior art are solved, and efficient and accurate SoftMax calculations are realized, which are suitable for processors with limited resources.
Patent Information
- Application Number
- CN202410536831.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2023-05-02
- Filing Date
- 2024-04-30
- Publication Date
- 2024-11-05
AI Technical Summary
The prior art requires computing exponential functions when executing SoftMax functions, resulting in high computing resources and energy consumption, especially in microcontrollers or digital signal processors with limited capacity.
Using integer-based operations and segmented approximation methods, the integer part and fractional part are separated by multiplying the input number by 2, and the segmented approximation is used to generate binary numbers to represent exponential values, thereby calculating the normalized probability. Avoid exponential operations.
It significantly reduces the computational workload and running time, improves the execution efficiency and accuracy of SoftMax functions, and is suitable for processors with limited resources, and is suitable for applications such as image processing and assisted driving.
Smart Images

Figure CN118898026A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to a computer-implemented method for computing probability distributions of classification outputs using integer-based operations. In particular, the present disclosure relates to a computer-implemented method for computing a SoftMax function on a data processing device that avoids exponential operations. Background Art
[0002] The SoftMax function normalizes the input vector to a probability distribution that is proportional to the exponential of the input number. After applying the SoftMax function, each component in the probability distribution has a value between 0 and 1, and the sum of the components is 1. The SoftMax function can be used as the last activation function of a neural network (e.g., a classification neural network) to normalize the output of the neural network to a probability distribution on the predicted output class. In order to execute the SoftMax function, the processor usually needs to calculate the exponential function, which requires a lot of computing time and energy. Summary of the Invention
[0003] This article describes techniques and systems for computing probability distributions of classification outputs using integer-based operations. In particular, this article describes techniques and systems for performing a SoftMax function using piecewise approximation without using exponential operations. An example processing device includes a processor that obtains an input number y, which may deviate from an original input number x. For each input number y i , the processor passes the input number y i Multiply by the approximate reciprocal of the natural logarithm of 2 to determine the number of elements z i . Then count each element z i Divide into integer part int i and the fractional part frac i . Use the fractional part frac i The fractional component f is determined by piecewise approximation c,i The processor then uses this fractional component f c,i and the integer part int i Generate binary number q i , which represents the corresponding input number y i The exponential value of . Determine the normalized probability p based on the binary number q i In this way, the execution of the SoftMax function is optimized for integer-based processors to provide highly efficient and accurate computations.
[0004] Also described herein are methods performed by the above-described systems and other configurations set forth herein, as well as computer-executable instructions and apparatuses for performing these methods.
[0005] This summary introduces simplified concepts related to using piecewise approximation to perform the SoftMax function as described in the detailed description and figures. This summary is not intended to identify essential features of the claimed subject matter, nor is it intended to determine the scope of the claimed subject matter. BRIEF DESCRIPTION OF THE DRAWINGS
[0006] Exemplary embodiments of using piecewise approximation to perform a SoftMax function are described herein with reference to the following figures. In all figures, the same reference numerals are used to represent the same features and components.
[0007] Figure 1 An exemplary processing apparatus for performing a SoftMax function using piecewise approximation is illustrated;
[0008] Figure 2 An exemplary flow chart for performing a SoftMax function using piecewise approximation is illustrated;
[0009] Figure 3-1 and Figure 3-2 An exemplary flow chart for determining the number of elements as part of performing a SoftMax function using piecewise approximation is illustrated;
[0010] Figure 4 Another exemplary flow chart illustrating the use of piecewise approximation to perform a SoftMax function; and
[0011] Figure 5 An exemplary method for performing a SoftMax function using piecewise approximation is illustrated. DETAILED DESCRIPTION
[0012] Multilayer neural networks usually end in the penultimate layer (or the penultimate activation layer), which outputs real-valued scores or probabilities that cannot be easily scaled. The SoftMax function can be used in the last layer (or the last activation layer) of a multilayer neural network to convert the scores or probabilities into a normalized probability distribution, which can be displayed to the user or used as input to another system. In other words, the SoftMax function normalizes the input vector of real numbers (such as scores or probabilities) to a probability distribution that is proportional to the exponent of the input vector. For example, for a vector with K real numbers x i The input vector x, where i = 1, ..., K and The SoftMax function can be defined by the following mathematical formula: where σ(x) i After applying the SoftMax function, each component is in the interval (0, 1) and the sum of the components is 1.
[0013] As an illustrative example, consider a classification neural network for identifying cats and dogs in an image. The neural network obtains an image as input and outputs a vector x, which includes an example value of 2.5 for a cat, an example value of 0.5 for a dog, and an example value of 1.5 for an unknown. In the first step, the processor running the SoftMax function can first subtract the maximum input value 2.5 to convert the original input values 2.5, 0.5, and 1.5 into shifted or offset input values 0, -2, -1, which are negative or zero. The processor can then calculate the exponentials of the shifted input values (e.g., exp(0), exp(-2), exp(-1)), add the exponentials, and normalize the output by dividing each exponential by the sum of the exponentials to obtain an output value between 0 and 1, with the sum of the output values being 1. These output values provide a distribution of probabilities. In this illustrative example, the distribution of probabilities includes 56% for cats, 11% for dogs, and 33% for unknowns.
[0014] As shown in this illustrative example, the SoftMax function generates a nonlinear mapping of the input vector. In other words, the most likely result is amplified, while the less likely result (or non-significant result) is significantly reduced or even suppressed. In other words, if one of the input numbers is small or negative (e.g., 0.5 for a dog), the SoftMax function turns it into a small probability (e.g., 11% for a dog). Similarly, if the input number is positive and large (e.g., 2.5 for a cat), the SoftMax function turns it into a large probability (e.g., 56% for a cat). The sum of the probabilities (or percentages) of different categories is 100%. This nonlinear mapping is implemented using an exponential function.
[0015] To perform the SoftMax function, the processor typically needs to calculate an exponential function, which is very expensive in terms of computational resources and energy consumption. Processors typically use floating-point operations, resulting in many computation cycles, long runtimes, and high energy usage. Furthermore, in microcontrollers or digital signal processors, which have more limited capacity than other processors, floating-point numbers can be avoided due to their high energy consumption and high demands on processing resources.
[0016] This paper describes techniques and systems for performing a SoftMax function using piecewise approximation and integer-based operations. As an example, a processor obtains an input number y that may deviate from the original input number x. For each input number y i , the processor passes the input number y i Multiply by the approximate reciprocal of the natural logarithm of 2 to determine the number of elements z i . Then count each element z i Divide into integer part int i and the fractional part frac i. Use the fractional part frac i The fractional component f is determined by linear approximation, quadratic approximation or any other piecewise approximation c,i The processor then converts the fractional component f c,i right shift the integer part int i To generate the binary number q i , the binary number q i Indicates the corresponding input number y i The exponential value of the corresponding binary number q i Divide by the sum of the binary numbers q to determine the normalized probability p i . In this way, the execution of the SoftMax function is optimized for digital signal processors and similar controllers to provide efficient and accurate calculations. In particular, the processor executes the SoftMax function in a manner that requires less computational workload and less runtime. A non-limiting use of this more efficient and accurate SoftMax calculation is for image processing inside and / or outside the host vehicle. For example, the image processing can be used to classify objects (e.g., road obstacles, pedestrians, cars, bicycles, motorcycles, buildings) in the environment surrounding the host vehicle to improve assisted driving (e.g., driver alert systems) and autonomous driving operations (e.g., object tracking). Similarly, the image processing can be used to classify objects (e.g., passengers, young children, strollers, boxes, work bags) inside the host vehicle to improve internal monitoring systems (e.g., seat belt detection systems).
[0017] This example is only one example of the described techniques and systems for performing the SoftMax function using piecewise approximation. Other examples and implementations are described herein.
[0018] Figure 1 An exemplary processing device 100 for performing a SoftMax function using piecewise approximation is illustrated. The processing device 100 may be an integer-based digital signal processor, a controller, a microprocessor, or a system on a chip. The processing device 100 may include a processor 102, a computer-readable storage medium (CRM) 104, and a plurality of registers 106. The processor 102 executes instructions stored in the CRM 104, one or more disks, memories, or other non-transitory computer-readable storage media. For example, the processor 102 may execute instructions in the CRM 104 to perform Figures 2 to 5 The method described in .
[0019] The registers 106 may include a first register 108 (eg, R1 i ...R1 K ), the second register 110 (eg, R2 i ...R2 K), a third register 112 (eg, R3), a fourth register 114 (eg, R4 i ...R4 K ), the fifth register 116 (eg, R5 i ...R5 K ), the sixth register 118 (eg, R6 i ...R6 K ), a seventh register 120 (eg, R7), and an eighth register 122 (eg, R8 i ...R8 K ). In some instances, some registers may be reconfigured to other registers (e.g., the first register 108 may be reconfigured or reused as the fourth register 114). In one implementation, the registers 106 include N-bit registers and N / 2-bit registers, where the number N has 2 n In the form of , where n is an integer greater than or equal to 1 (e.g., n ≥ 1). For example, N can be equal to 32. In other examples, N can be equal to 16 or 64 or some other value. Figures 2 to 5 As described, registers 106 provide data retention elements that processor 102 can use during execution. Figures 2 to 5 The data holding element is directly accessed while performing the method described in the preceding claims.
[0020] The processing device 100 converts the exponentiation of the SoftMax function into exponentiation 2 using the following mathematical relationship in equation (1):
[0021]
[0022] in and Compared to calculating an exponential function, the processing device 100 is more efficient and performs fewer computation cycles when calculating a given exponential power of 2. To further improve the efficiency of executing the SoftMax function, the processing device 100 also uses piecewise approximation to replace the floating-point calculations of the exponential function through some shifts in registers, integer additions, integer multiplications, and restrictions on floating-point operations. In this way, the processing device 100 can provide more efficient image processing to classify objects inside or outside the host vehicle.
[0023] Figure 2 An exemplary flowchart diagram 200 for performing a SoftMax function using piecewise approximation is illustrated. The flowchart diagram 200 is shown as an exemplary operation (or action) performed, but is not necessarily limited to the order or combination of operations shown here. In addition, any one or more operations can be repeated, combined, or reorganized to provide other flowcharts. In the following discussion, reference may be made to Figure 1 The entities detailed in the Figure 1 The technology is not limited to being performed by one entity or multiple entities.
[0024] In executing the operations of flowchart diagram 200, processor 102 primarily performs integer (fixed-point) operations and some shifting in registers, which allows the corresponding input number y to be determined in a fast manner. i The probability p i The input number y typically represents an offset (and possibly scaled) value of the classification output from the neural network (e.g., the original input number x). Compared to performing exponential calculations for each input number, the runtime and energy consumption of the processor 102 are significantly reduced. In addition, a microcontroller or digital signal processor that does not have floating-point computing capabilities or a microcontroller or digital signal processor that has an integer-based architecture can easily use the SoftMax function using method 200.
[0025] In optional step 202, processor 102 receives an input vector of K raw input numbers x. The raw input numbers x are real-valued. For example, the raw input numbers x can be real-valued scores at the output of a multi-layer neural network such as a classification neural network or its penultimate activation layer.
[0026] In an example implementation, typically where the input vector is an output from a neural network, the original input vector x received in step 202 has been scaled by an input scaling factor S in Scaling. The input scaling factor is usually equal to a power or exponent of 2 (e.g., S in = 2σ) and rounded to an integer (e.g., the nearest integer) to be stored in an N-bit register. For example, scaling occurs at the input to the neural network, which passes the data to the SoftMax operator. In this case, scaling occurs outside the SoftMax operator. The input scaling factor S can be selected depending on the expected minimum and maximum values of the original input number and the size of the N-bit register. in . In S in After scaling, all scaled original input numbers x can be favorably matched to -2 N-1 and 2 N-1 -1 (represented as a signed integer).
[0027] In optional step 204, the processor 102 inputs the number y i Determined from the original input number x i (It may have been S in scaled) offset, and obtain the K original input numbers x i The number of K inputs y i(e.g., positive real value, negative real value, or zero), where i=1, ..., K. In this implementation as illustrated in Table 1 (below), the input number y is positive or zero. Therefore, from the original input number x i Determine each input number y i This involves selecting the maximum number of original inputs x max , and from the maximum original input number x max Subtract the original input number x from the equation to obtain a positive or zero input number y. In other words, based on the formula y i =x max -x i Calculate the input number y. The K input numbers y can be stored in the first N-bit register R1 by overwriting the original input number x. i (eg, first register 108). Alternatively, the K input numbers y may be stored in another N-bit register (eg, second register 110).
[0028] By determining the input number y to be positive or zero, the processor 102 implements a positive integer scheme. In an alternative implementation, the processor 102 may use a negative integer scheme. In this alternative implementation, each input number y i is negative or zero and is obtained by taking the original input number x from i Subtract the maximum original input number x from max To get the input number y i And from the original input number x i Because the negative branch of the exponential function is numerically more stable than the positive branch, this alternative implementation may be preferred. If this alternative implementation has a negative or zero value, the constants A, B, C, D, and E of the piecewise approximation in step 212 will have different values, but can be determined in a similar manner as described below.
[0029] In another implementation, the processor 102 may perform the SoftMax function using piecewise approximation without shifting the original input number x to obtain the input number y. Instead, the processor 102 may perform steps 206 to 216 (or a subset thereof) using the original input number x as input to steps 206 and 208 and obtain its normalized probability distribution.
[0030] In optional step 206, the processor 102 inputs the scaling factor S in To scale the offset of the original input number x. For example, the original input number x in Table 1 below is 2 27 Scaled and rounded to the nearest integer for storage in a 32-bit register (eg, register 106), this is illustrated in Table 2 below. The corresponding decimal values are shown in Table 2 below.
[0031] Table 1
[0032]
[0033] Table 2
[0034]
[0035] Table 1 is a table showing example original input numbers x in the first column and offset positive input numbers y in the second column (e.g., y i =x max -x i ), as discussed below with respect to step 206. For clarity, numbers are represented using decimal values rather than S. in As described in more detail above, the input number y can also be negative (e.g., i =x i -x max ). The third column contains the number of elements in the decimal domain z. i The fourth column contains the corresponding integer part in the decimal domain int i , the fifth column contains the corresponding fractional part frac in the decimal domain i The sixth column of Table 1 contains the fractional component f c,i The scaled value of , which corresponds to the fractional part of 2 indicated in the fifth column, frac i The seventh column of Table 1 contains the result registers R6 i (eg, the binary number q in the sixth register 118) i The scaled value (after converting the fractional component f c,i right shift the integer part int i Afterwards). As shown in the seventh column of Table 1, corresponding to the meaningless original input number x i (For example, x3, x5, x7, x 10 ) result register R6 i is set to zero.
[0036] In step 208, after obtaining the input vector of the input number y, the processor 102 determines the number of elements z. i Divide by an approximation of the natural logarithm of 2 (e.g., ln(2)) or multiply by an approximation of the reciprocal of the natural logarithm of 2 (e.g., 1 / ln(2), ) to obtain the corresponding number of elements z i (corresponding to z i =y i / ln(2)). In one implementation, the data stored in an N-bit register (eg, the first register 108, R1 i ) in each input number y iThe multiplication of a constant value approximating the reciprocal of the natural logarithm of 2 (e.g., 1 / ln(2)) is optimized by using a less expensive N / 2-bit by N / 2-bit multiplication to produce an N-bit result. As an illustrative example, N may be equal to 32 bits. Step 208 is performed by providing a constant value approximating the reciprocal of the natural logarithm of 2 (e.g., 1 / ln(2)). in The number of elements z in the scaled binary domain ends up being the element number z. The number of elements z can be stored in an N-bit register (e.g., the fifth register 116R5 i )middle.
[0037] In step 210, the processor 102 separates each element number z i The integer part of int i and the fractional part frac i . Integer part int i is an integer. It can be obtained from the fifth register 116R5 by right shifting by σ bits. i Resulting in discarding all fraction bits due to the right shift. i is a value less than 1 and greater than 0 or equal to 0. It is also possible to mask the integer part int by i The bit from the fifth register 116R5 i Come to.
[0038] In step 212, processor 102 determines the value corresponding to the fractional part frac i The fractional component f c,i . Use 2 N / 2 -1 scaled linear approximation or quadratic approximation to determine the fractional component f c,i For example, if N is 32, use 2 16 -1 or 65535 scaling to determine the fractional part frac i In particular, piecewise approximation is used to use the fractional part frac i approximate The linear approximation uses the following formula: c,i =A+Bx. With the endpoints (e.g., 0.0 and 1.0) chosen to match the actual values and utilizing a scaling of 65,535, the constants A and B may have values of 65,535 and -32,767, respectively. The quadratic approximation utilizes the following formula: c,i =C+Dx+Ex 2. With the endpoints and midpoints (e.g., 0.0, 0.5, and 1.0) chosen to match the actual values and a scaling of 65,535 being utilized, the constants C, D, and E may have values of 65,535, -44011.52838, and 11244.2838, respectively. The constants A, B, C, D, and E may be determined using different points that match the actual values or using different scaling. In addition, the fractional component f may be approximated using a higher-order piecewise approximation (e.g., third-order) or a Taylor approximation. c,i .
[0039] In step 214, for each input number y i , the processor 102 calculates the corresponding fractional component f c,i Shift the corresponding integer part int right i , comes in the sixth N / 2 bit register R6 i (e.g., the sixth register 118, also referred to as the result register) determines the binary number q i , the binary number q i Represents the input number y i The index value of .
[0040] Integer part int i The right shift results in discarding the r lower bits of the fractional component fci, where r is equal to int i For the integer part int i The result register R6 i All bits of the result register R6 become equal to zero. i The binary number q generated by right shifting i It can be expressed by the following formula:
[0041]
[0042] As shown in the above relationship, the binary number q i Represents the original input number x i In particular, it is related to x i Proportional to the exponent.
[0043] Then, in step 216, the processor 102 converts each binary number q into i The sum of the divided binary number q is stored in the result register R6 i The binary number q in is normalized to determine K normalized probabilities p i Specifically, the processor 102 stores all result registers R6 in a sum register R7 (eg, the seventh register 120) which is an N-bit register. iAdd (i varies from 1 to K) to obtain the sum Σ of the binary number q. In the illustrative example of Table 1, the decimal value of the sum Σ is 65995.
[0044] In one exemplary implementation, the normalization of the binary number q may involve several different steps or sub-steps. The processor 102 may obtain a normalization factor f calculated using the following formula: n : Among them, V 100 Indicates that by setting the N / 2 bit result register R6 i The value obtained by setting all bits in (e.g., the sixth register 118) to one (1) and corresponds to the binary number q giving a probability value of 100%. i , and <<S n Denotes the normalization scaling factor S used for normalization n (For example, N / 2, which corresponds to 2 in the decimal domain N / 2 In some implementations, to improve accuracy, a modified formula is used: Come to f n Round off. Normalization factor f n can be stored in a memory (e.g., CRM 104). Referring to the example in Table 1, the value V 100 is 65535, and is 65995, the scaling factor is 16, and the normalization factor f n It is given by the following formula:
[0045] Then, the processor 102 converts the normalization factor f n Applied to each result register R6 i , together with the factor 1 / S n Rescaling is performed to obtain the result register R6 i The normalized binary number q in i,n This operation can be expressed as q i_n =(q i *f n )>>S n , where >>S n Indicates result register R6 i S shifted right n The processor 102 can also pass the result register R6 i Shift right S n Previously, q i *f n Add to To round to the nearest integer. Table 1 provides the normalized binary number q for the illustrated example in the eighth column. i,nTable 1 shows the result register R6 before and after normalization. i , and indicates the normalized binary number q i_n The sum of is 65636, which corresponds to a total probability very close to 100% (slightly greater than 1 in the 100% case).
[0046] Processor 102 may then pass the result register R6 i The normalized value q in i_n Divide by the output scaling factor S out (For example, 2 in the example of Table 1 16 ), from the result register R6 i The normalized binary number q in i_n The corresponding input number z i The corresponding probability p i (It is a decimal number.) Column 9 of Table 1 contains the probability p expressed as a percentage (%) i The percentages sum to slightly more than 100%.
[0047] To improve stability, operations of flowchart illustration 200 that may overflow a register (e.g., addition, subtraction, slicing from N / 2+1 to N / 2 bits) can be performed as saturating operations. In other words, if the result of an operation in a register is greater than the maximum value that can be stored in the register, the register is set to the maximum value (e.g., all register bits are set to one).
[0048] To improve accuracy, the divisions in flowchart 200 (including any divisions implemented by performing a right shift in a register) are preferably rounded by adding half of the divisor to the dividend. In other words, any division of the type "a divided by b" is advantageously performed by adding "b / 2" to the dividend "a" before dividing by the divisor "b" (or performing a corresponding right shift in a register).
[0049] Figure 3-1 and Figure 3-2 Exemplary flowcharts 300-1 and 300-2, respectively, illustrate determining the number of elements z as part of performing a SoftMax function using piecewise approximation. Flowcharts 300-1 and 300-2 are shown as exemplary operations (or actions) performed, but are not necessarily limited to the order or combination of operations shown herein. Specifically, flowcharts 300-1 and 300-2 provide exemplary operations for performing step 208 of flowchart 200 (e.g., determining the number of elements y by multiplying by an approximation of the reciprocal of the natural logarithm of 2). In addition, any of one or more of the operations may be repeated, combined, or reorganized to provide other flowcharts. In the portions discussed below, reference may be made to the flowcharts described herein. Figure 1 The entities detailed in the Figure 1 The techniques described are not limited to performance by one or more entities.
[0050] Figure 3-1 The operation of the flowchart 300-1 begins at step 302, where the processor 102 registers the first N-bit register R1 i Provide each input number y i As an example, for Figure 1 The processing device 100, each input number y i Stored in the first 32-bit register 108 (R1 i )middle.
[0051] In optional step 304, the processor 102 processes each input number y i Specifically, the processor 102 rounds 2 N / 2-2 Add to the input number y i .
[0052] In step 306, the processor 102 converts each input number y i Shift right to the second N / 2 bit register R2 i The right shift is equal to N / 2-1. Figure 1 The processing device 100, each input number y i is right-shifted by 15 bits in the second 16-bit register 108 (R2i). In other words, the N / 2-1 (e.g., 15 in the illustrated example) lower bits are discarded by the right shift. The N / 2+1 (e.g., 17 in the given example) most significant bits are processed using one of the following rules. If the input number y after the right shift of N / 2-1 is i No overflow of the second N / 2-bit register R2 i , then the shifted input number y i,T Match or store to the second N / 2 bit register R2 i For example, when N is equal to 32, if the highest bit (for example, the 32nd bit) of the shifted input number is zero, then the input number y i The 16 least significant bits of the 17 bits are right-shifted by 15 bits and transferred to the second N / 2-bit register R2. i Otherwise, if the input number y after right shift N / 2-1 i Overflow second N / 2 bit register R2 i , then the second N / 2-bit register R2 i Saturation. For example, if the shifted input number y i,T If the most significant (Nth) bit is 1, then each of the other N / 2 (e.g., 16) most significant bits (e.g., from the N-1th bit to the N / 2th bit) is set to 1 and is transferred to the second N / 2-bit register R2 iIn the second N / 2-bit register R2 i Then it is saturated.
[0053] The shifted input number (called y i,T ) is stored in the second N / 2-bit register R2 i In. Input number y i A right shift of N / 2-1 places corresponds to a division by 2 in the decimal field. N / 2-1 .
[0054] In step 308, the processor 102 provides or loads a constant value in binary form in the third N / 2-bit register R3, which is approximately the value of 2 N / 2-1 The reciprocal of the natural logarithm of 2 minus the scale The approximate value of this constant is 0.442695041. This constant value can be pre-calculated (and optionally added to the 2 N / 2-1 After scaling) and stored in the memory of the processing device 100, or can be calculated in real time.
[0055] In step 310, the processor 102 determines or calculates the second N / 2-bit register R2 i (For example, the shifted input number y i,T ) and a third N / 2-bit register R3 (e.g., composed of 2 N / 2-1 The product is stored in the fourth N-bit register R4 i The product corresponds to By input scaling factor S in =2σ scaling.
[0056] In step 312, the processor 102 sets the first N-bit register R1 i and the fourth N-bit register R4 i The input scaling factor S is obtained by adding in The number of elements z to scale i and stores it in the fifth N-bit register R5 i Optionally, step 312 is a saturation addition, wherein if the result of the addition overflows the N-bit register R5 i (For example, it is larger than the N-bit register R5 i The maximum value in the N-bit register R5 i Set all bits in the N-bit register R5 to 1 (for example, i Saturation allows to avoid some unreasonable results (e.g. a low probability value becomes very large due to overflow caused by two's complement representation). Alternatively, in two N-bit registers R1 i The result of step 312 may be overwritten in one of R4i and R4i.
[0057] In an alternative implementation of flowchart 300-1, steps 306 and 308 are slightly changed. In the right shift of step 306, processor 102 performs a right shift on the second N / 2-bit register R2. i Enter the number y i Right shift N / 2 (eg, in the illustrated example, this results in i In step 308, the processor 102 provides or loads a constant value in binary form in the third N / 2-bit register R3, which is approximately 2 N / 2 Scaled This alternative implementation of flowchart diagram 300 - 1 is less accurate, but less computationally expensive.
[0058] Figure 3-2 The operation of the flowchart 300-2 starts from step 320. Step 320 is the same as Figure 3-1 In step 320, the processor 102 registers the first N-bit register R1 i Provide each input number y i As an example, for Figure 1 The processing device 100, each input number y i Stored in the first 32-bit register 108 (R1 i )middle.
[0059] In optional step 322, Figure 3-1 Similar to the optional step 304, the processor 102 processes each input number y i Specifically, the processor 102 rounds 2 N / 2-3 Add to the input number y i .
[0060] In step 324, Figure 3-1 Similar to step 306, the processor 102 converts each input number y i Shift right to the second N-bit register R2 i The right shift is equal to N / 2-2. Figure 1 The processing device 100, each input number y i In the second 32-bit register 108 (R2 i ) is right-shifted by 14 bits. In other words, the N / 2-2 (e.g., 14 in the example shown) lower bits are discarded by the right shift. The N / 2+2 (e.g., 18 in the given example) most significant bits are retained in the first N-bit register R2 i The first N-bit register R1 is the N / 2+2 least significant bits (e.g., the N / 2-2 most significant bits are set to 0). i and the second N-bit register R2i Can be the same N-bit register or two different N-bit registers.
[0061] In step 326, Figure 3-1 Similar to step 308, the processor 102 provides or loads a constant value in binary form in the third N-bit register R3, which is approximately the value of 2 N / 2-2 The reciprocal of the scaled natural logarithm of 2 minus 1, The approximate value of this constant is 0.442695041. This constant value can be pre-calculated (and optionally calculated by 2 N / 2-1 After scaling) and stored in the memory of the processing device 100, or can be calculated in real time.
[0062] In step 328, Figure 3-1 Similar to step 310, the processor 102 determines or calculates the second N-bit register R2 i (For example, the shifted input number y i,T ) and a third N-bit register R3 (e.g., composed of 2 N / 2-1 The product is stored in the fourth N-bit register R4 i The product corresponds to By input scaling factor S in =2 σ Zoom.
[0063] This multiplication in step 328 is more expensive in terms of computational resources than the N / 2 bit by N / 2 bit multiplication in step 318. Alternatively, the second N-bit register R2 i (When inputting the number y i In case of right shift in the same register in step 324, it may also be the first register R1 i ) can be overwritten by the result of the multiplication (instead of using another N-bit register). In other words, the fourth N-bit register R4 i It can be N-bit register R2 i .
[0064] In step 330, Figure 3-1 Similar to step 312, the processor 102 performs a first N-bit register R1 i and the fourth N-bit register R4 i Sum to obtain the input scaling factor S in The number of elements z to scale i and stores it in the fifth N-bit register R5 i Optionally, step 330 is a saturation addition, wherein if the result of the addition overflows the N-bit register R5 i (For example, it is larger than the N-bit register R5i The maximum value in the N-bit register R5 i Set all bits in the N-bit register R5 to 1 (for example, i Saturation allows to avoid some unreasonable results (e.g. a low probability value becomes very large due to overflow caused by two's complement representation). Alternatively, in two N-bit registers R1 i and R4 i In one of the above steps, the result of step 330 may be overwritten.
[0065] In flowchart 300-2, saturation is not required. The operation of flowchart 3002 is more accurate (because there is one more bit of precision for the shifted input number), but is also slightly more expensive in terms of computational resources.
[0066] Figure 4 Another exemplary flowchart 400 for performing a SoftMax function using piecewise approximation is illustrated. The flowchart 400 is shown as an exemplary operation (or action) performed, but is not necessarily limited to the order or combination of operations shown here. In addition, any of the operations in one or more operations can be repeated, combined, or reorganized to provide other flowcharts. In the following discussion, reference can be made to Figures 1 to 3-2 The entities detailed in are only referenced as examples. The described techniques are not limited to being performed by one or more entities.
[0067] In executing the operations of flowchart 400, processor 102 performs a fixed-point approach. Flowchart 400 reduces the use of floating-point operations, where processor 102 performs more fixed-point and less floating-point calculations.
[0068] In step 402, the processor 102 executes the combined Figure 2 2. The flowchart of FIG. 200 depicts steps 202 to 212 or steps 208 to 212.
[0069] In step 404, processor 102 combines the fractional components f_ c,i and the integer part int i The N-bit result register R6 i (eg, the sixth register 118) generates a floating point binary number q i,IEEE , the floating-point binary number q i,IEEE Represents each input number y iIn flowchart 400, the floating-point scheme means that all binary numbers representing the exponential values of the input number y are floating-point numbers, specifically IEEE 754 floating-point numbers. According to the IEEE Standard for Floating-Point Arithmetic (IEEE 754), an N-bit floating point has a layout defined by a sign bit (the most significant bit), an N1-bit exponent portion, and an N2-bit mantissa. In the example layout for a 32-bit floating point number (-248, 75), the exponent is an 8-bit portion, and the mantissa is a 23-bit portion.
[0070] Processor 102 stores the N-bit result register R6 i Int by combining the integer part i and IEEE 754 exponent bias (e.g., by subtracting the integer part int from the bias i ) and combines the integer part of int with the IEEE 754 exponent bias i Transfer to floating point binary number q i,IEEE The exponent part of the floating point binary number q is generated i,IEEE The processor 102 then adds the fractional component f_ to the lowest order bit by adding a bit set to 0, if necessary. c,i Transfer to N-bit result register R6 i The floating point binary number q in i,IEEE In the mantissa of (for example, if the fractional component f_ c,i If the floating-point binary number q is represented by 16 bits, it is transferred to the 16 most significant bits of the mantissa, and the other least significant bits of the mantissa are set to 0). In this way, the floating-point binary number q i,IEEE The exponent is stored in binary form in the result register R6 i The integer part of int i A combination of IEEE 754 exponent bias and the mantissa is derived directly from the fractional component f c,i In flowchart 400, the adjustment for approximating the fractional component f c,i The constants A, B, C, D, and E are arranged to match the IEEE 754 fractional components, which means that the fractional components fc are identical or can be directly converted from one to another (e.g., by simply adding zeros on the right).
[0071] Processor 102 then adds the floating point addition to result register R6 by performing the floating point addition in result register R7. i Sum to get the sum ∑ as a floating point number IEEE The processor 102 calculates and ∑ IEEE The processor 102 then stores the result in register R6 in floating point form. i Multiply by register R8. In other words, calculate each floating-point binary number qi,IEEE and and ∑ IEEE The product of the reciprocal of and is stored in register R81 which is an N-bit register. i The normalized probability p i It can be obtained by converting the floating point number stored in register R81 to a decimal value.
[0072] Figure 5 An exemplary method 500 for performing a SoftMax function using piecewise approximation is illustrated. In other words, method 500 illustrates the operation of processing the classification output (or its offset value) of a neural network to generate its normalized probability. Method 500 is shown as the operations (or actions) performed, but is not necessarily limited to the order or combination of operations shown here. In addition, any operation in one or more operations can be repeated, combined or reorganized to provide other methods. In the following discussion, reference can be made to Figure 1 The processor 102, and the example reference only Figures 1 to 4 The techniques are not limited to being performed by one or more entities.
[0073] In step 502, for the K input numbers y, the corresponding input numbers y are i Multiply by the approximate reciprocal of the natural logarithm of 2 to determine the number of elements z i For example, the processor 102 converts each input number y i Multiply by a constant representing or approximating the reciprocal of the natural logarithm of 2 to determine the corresponding number of elements z i .
[0074] In one embodiment, the processor 102 can i Store in binary form into the first N-bit register to calculate the number of each element z i , where N is a power of 2 and is greater than or equal to 2. The processor 102 may then i Shift right by N / 2-1 and convert the right-shifted input number y i,T Stored in the second N / 2-bit register. i After right shifting N / 2-1, the second N / 2-bit register does not overflow. The input number y after right shifting is i,T can be fitted into the second N / 2-bit register. If after right shifting N / 2-1, the input number y i Overflowing the second N / 2-bit register, the second N / 2-bit register can be saturated. This can also be done by shifting 2 before right shifting N / 2-1. N / 2-2 Add to the input number y i To right shift the input number y i,TThe processor 102 may then provide the constant value in binary form to the third N / 2 bit register. The constant value is approximately equal to the reciprocal of the natural logarithm of 2 minus 1 and divided by 2 N / 2-1 Scaling. The processor 102 may calculate the product of the second N / 2-bit register and the third N / 2-bit register and store the product in the fourth N-bit register. The processor 102 may then determine the sum of the first N-bit register and the fourth N-bit register using saturating addition to obtain the number of elements z. i And store the sum in the fifth N-bit register.
[0075] In another implementation, the processor 102 may i Store in binary form into the first N-bit register to calculate the number of each element z i The processor 102 may then convert the input number y i Shift right by N / 2-2, and convert the right-shifted input number y i,T Stored in the second N-bit register. This can also be done by shifting 2 before right shifting N / 2-2. N / 2-3 Add to the input number y i To right shift the input number y i,T Then, the binary form can be combined with 2 N / 2-2 The scaled constant value is provided to the third N-bit register. The constant value is approximately equal to the reciprocal of the natural logarithm of 2 minus 1. The processor 102 can then calculate the product of the second N-bit register and the third N-bit register and store the product in the fourth N-bit register. Finally, the processor 102 can determine the sum of the first N-bit register and the fourth N-bit register using saturated addition to obtain the value of the input scaling factor S. in The number of elements z to scale i and stores the sum in the fifth N-bit register.
[0076] Depending on the output of the penultimate activation layer in the multi-layer neural network, the processor 102 can select the corresponding original input number x from the input vectors contained in the K original input numbers x. i Get each input number y i The processor 102 may select the maximum original input number x from the original input number x. max For each original input number x i , the processor 102 can obtain the input number x i Subtract the maximum original input number x from max , to get a negative or zero input number y i , or from the maximum original input number x max Subtract the original input number x from i , to get a zero or positive input number yi .
[0077] In addition, each input number y i It can be in binary form and is scaled by the input factor S in Scaling. The input scaling factor S can be determined based on the expected minimum and expected maximum values of the input number y and the size N of the first register. in The processor 102 can convert each input number y into i Stored in the first N-bit register.
[0078] In step 504, for each element number z i , the number of elements z i Divide into integer part int i and the fractional part frac i For example, the processor 102 may convert the integer part int i and the fractional part frac i Provided to the corresponding register.
[0079] At step 506 and for each fractional part frac i , using the fractional part of 2, frac i the opposite power of (for example, ) is used to determine the fractional component f c,i For example, the processor 102 may utilize a linear approximation or a quadratic approximation. Specifically, the processor 102 may calculate the approximation by adding the first constant A to the second constant B and the fractional part frac. i The first product of the fractional component f is used to calculate its linear approximation. c,i The processor 102 can also add the third constant C to the fourth constant D and the fractional part frac i The second product and the fifth constant E and the fractional part frac i The third product of the squares is To approximate the fractional component f c,i , to calculate its quadratic approximation. Similarly, the processor 102 can calculate its quadratic approximation by adding the third constant C' to the fractional part frac i The product of the sum of the fourth constant D' and the fifth constant E' and the fractional part frac i The product of (for example, C′+frac i (D′+E′*frac i )) to approximate the fractional component f c,i , to calculate its quadratic approximation.
[0080] At step 508 and corresponding to each input number y i, using the fractional component f c,i and the integer part int i Generates the input number y i The binary number q of the exponential value i For example, the processor 102 may convert the fractional component f c,i right shift the integer part int i The value of each binary number q i Specifically, the processor 102 may convert the corresponding fractional component f c,i Stored in the corresponding result register, and the fractional component f c,i right shift the integer part int i In another implementation, the processor 102 may generate the binary number q in the result register in the form of an IEEE 754 floating point number including an exponent and a mantissa. i The exponent is the integer part of the binary form int i and IEEE 754 exponent bias. The mantissa is derived from the fractional component f c,i Obtained.
[0081] Steps 502 to 508 provide an example of determining a binary number q corresponding to each input number y of the classification output of the neural network. The binary number q can be determined using an approximation of the SoftMax function that uses integer-based operations rather than exponential operations. The binary number q represents the probability distribution of each input number.
[0082] In step 510, corresponding to each input number y i , determine the normalized probability p according to the binary number q i For example, the processor 102 may convert each binary number q i Specifically, the processor 102 can divide each binary number q by i The sum register is then divided by the sum register to calculate the normalized probability p. Alternatively, the processor may then multiply each result register by the inverse of the sum register (e.g., to perform a single division operation) to calculate the normalized probability p.
[0083] In another implementation, the processor 102 may add the quantity K of the result register to the sum register and then normalize the sum by scaling it with the normalization factor S. n Value V 100 Scaling is performed to obtain the normalization factor f n . Value V 100is obtained by setting all bits in the respective result registers to 1. The processor 102 may then normalize the factor f n Applied to each result register together with the normalization scaling factor S n Perform inverse scaling to obtain the normalized binary number q i_n , and then divide each result register by the sum register (for example, the normalized binary number q n and ) to calculate the normalized probability p.
[0084] Example
[0085] In the following sections, examples are provided.
[0086] Example 1. A computer-implemented method for processing a classification output of a neural network, the method comprising the steps of: for each input number y i , using the approximation of the SoftMax function to determine the binary number q i , the SoftMax function uses integer-based operations instead of exponential operations, and the binary number q i Represents the input number y i The probability distribution of each input number is the offset of the corresponding classification output of the neural network; and for each input number y i , determine the normalized probability p according to the binary number q i .
[0087] Example 2. The computer-implemented method of Example 1, wherein determining the binary number q i The steps include: for each input number y i , by taking the input number y i Multiply by the approximate reciprocal of the natural logarithm of 2 to determine the number of elements z i ; For each element number z i , the number of elements z i Divide into integer part int i and the fractional part frac i ; For each fractional part frac i , using the fractional part of 2 i The fractional component f is determined by piecewise approximation of the opposite power of c,i ; and using the fractional component f c,i and the integer part int i Generate the binary number q i , the binary number q i Corresponding to the input number y i And also represents the input number y i The index value of .
[0088] Example 3. The computer-implemented method of Example 2, wherein determining the fractional component f c,i The step includes calculating the fractional part frac of 2 by the following process i Linear approximation or quadratic approximation of the opposite power: by adding the first constant A to the second constant B with the fractional part frac i The first product is used to approximate the fractional component f c,i ; or by adding the third constant C to the fourth constant D and the fractional part frac i The second product and the fifth constant E and the fractional part frac i The fractional component f is approximated by the third product of the squares of c,i .
[0089] Example 4. The computer-implemented method of any one of Examples 1 to 3, wherein the normalized probability p is determined according to the binary number q. i The steps include: each binary number q i Put the result registers into the corresponding result registers; add the amount K of the result registers to the summing register; and multiply each result register by the reciprocal of the summing register, or divide each result register by the summing register.
[0090] Example 5. The computer-implemented method of Example 4, wherein generating the binary number q i The step includes converting the fractional component f into c,i Right shift the integer part int i The value of: the corresponding fractional component f c,i Stored into the corresponding result register, and the fractional component f c,i Right shift the integer part int i The value of the result register is written to the corresponding result register.
[0091] Example 6. A computer-implemented method according to any of the preceding examples, wherein each input number y i By input scaling factor S in Scaled and stored in the first N-bit register.
[0092] Example 7. The computer-implemented method of Example 6, wherein the input scaling factor S in It is determined based on the expected minimum value and the expected maximum value of the input number y and the size N of the first register.
[0093] Example 8. The computer-implemented method of any one of Examples 2 to 5, wherein the input number y is i Multiply by the approximate reciprocal of the natural logarithm of 2 to determine the number of elements z i The steps include: each input number y i Store the input number y in binary form into the first N-bit register; i Shift right by N / 2-1, and process the right-shifted input number y according to the following process i,T Stored in the second N / 2-bit register: - If the input number y i After the right shift of N / 2-1, the second N / 2-bit register does not overflow, and the right-shifted input number y i,T fits into the second N / 2-bit register, or - if the input number y i If the second N / 2-bit register overflows after the right shift of N / 2-1, the second N / 2-bit register is saturated; a constant value in binary form is provided to the third N / 2-bit register, and the constant value is approximately equal to the reciprocal of the natural logarithm of 2 minus 1 and then divided by 2 N / 2-1 Scaling; calculating the product of the second N / 2-bit register and the third N / 2-bit register and storing the product in a fourth N-bit register; and determining the sum of the first N-bit register and the fourth N-bit register by performing saturated addition to obtain the number of elements z i and stores the sum in the fifth N-bit register.
[0094] Example 9. The computer-implemented method of Example 8, wherein the input number y is i Multiply by the approximate reciprocal of the natural logarithm of 2 to determine the number of elements z i The step further includes: by adding the input number y i Before shifting right by N / 2-1, put 2 N / 2-2 Add to the input number y i , to the right-shifted input number y i,T Round up.
[0095] Example 10. The computer-implemented method of any one of Examples 2 to 5, wherein the input number y is i Multiply by the approximate reciprocal of the natural logarithm of 2 to determine the number of elements z i The steps include: each input number y i Store the input number y in binary form into the first N-bit register; i Shift right by N / 2-2, and convert the right-shifted input number y i,T Stored in the second N-bit register; N / 2-2The scaled binary constant value is provided to a third N-bit register (R3), the constant value being approximately equal to the reciprocal of the natural logarithm of 2 minus 1; calculating the product of the second N-bit register and the third N-bit register and storing the product in a fourth N-bit register; and determining the sum of the first N-bit register and the fourth N-bit register by performing saturated addition to obtain the value obtained by the input scaling factor S. in The number of elements z after scaling i and stores the sum in the fifth N-bit register.
[0096] Example 11. The computer-implemented method of Example 10, wherein the input number y is i Multiply by the approximate reciprocal of the natural logarithm of 2 to determine the number of elements z i The step further includes: by adding the input number y i Before shifting right N / 2-2, put 2 N / 2-3 Add to the input number y i To right shift the input number y i,T Round up.
[0097] Example 12. The computer-implemented method of Example 9 or 11, wherein determining the normalized probability p i The steps include: adding the result register to the summation register; scaling the result register by a normalization factor S n Value V 100 Scaling is performed to obtain the normalization factor f n , the value V 100 is obtained by setting all bits in each result register to 1; and the normalization factor f n Applied to each result register together with the normalization scaling factor S n Perform inverse scaling to obtain the normalized binary number q i_n .
[0098] Example 13. The computer-implemented method of Example 4, wherein the binary number q i is generated in the result register in the form of an IEEE 754 floating point number including an exponent and a mantissa, wherein the exponent is the integer part in binary form i with the IEEE 754 exponent bias, and the mantissa is derived from the fractional component f c,i Obtained.
[0099] Example 14. The computer-implemented method of any of the preceding examples, further comprising: selecting the maximum original input number x from the original input number xmax , from the corresponding original input number x i The input numbers y are obtained from i , the original input number x is the classification output of the neural network; and for each original input number x i : From x i Subtract x from max , to get a negative or zero input number y i ; or from x max Subtract x from i , to get a zero or positive input number y i .
[0100] Example 15. A system comprising one or more processors configured to perform a computer-implemented method according to any of the preceding examples.
[0101] Example 16. A non-transitory computer-readable medium storing computer-executable instructions that, when executed by a processor of a data processing device, cause the processor to perform the computer-implemented method of any one of Examples 1 to 14.
[0102] in conclusion
[0103] Although various embodiments of the present disclosure have been described in the foregoing description and shown in the accompanying drawings, it should be understood that the present disclosure is not limited thereto, but can be implemented in various ways within the scope of the appended claims. From the foregoing description, it will be apparent that various changes can be made without departing from the scope of the present disclosure as defined by the appended claims.
Claims
1. A computer-implemented method for processing a classification output of a neural network, the method comprising the steps of: For each input number y i , using the approximation of the SoftMax function to determine the binary number q i , the SoftMax function uses integer-based operations instead of exponential operations, and the binary number q i Represents the input number y i The probability distribution of each input number is the offset of the corresponding classification output of the neural network; as well as For each input number y i , determine the normalized probability p according to the binary number q i .
2. The computer-implemented method of claim 1, wherein: Determine the binary number q i The steps include: For each input number y i , by taking the input number y i Multiply by the approximation of the reciprocal of the natural logarithm of 2 to determine the number of elements z i ; For each element number z i , the number of elements z i Divide into integer part int i and the fractional part frac i ; For each fractional part frac i , using the fractional part of 2 i The fractional component f is determined by piecewise approximation of the opposite power of c,i ;as well as Using the fractional component f c,i and the integer part int i Generate the binary number q i , the binary number q i Corresponding to the input number y i And also represents the input number y i The index value of .
3. The computer-implemented method of claim 2, wherein: Determine the fractional component f c,i The step comprises calculating the fractional part frac of 2 by the following process: i Linear or quadratic approximation of the opposite power of : By adding the first constant A to the second constant B with the fractional part frac i The first product of c,i ;or By adding the third constant C to the fourth constant D and the fractional part frac i The second product and the fifth constant E and the fractional part frac i The third product of the square of c,i .
4. A computer-implemented method according to any one of claims 1 to 3, wherein: Determine the normalized probability p according to the binary number q i The steps include: Each binary number q i Put into the corresponding result register; adding the quantity K in the result register to the sum register; and Each result register is multiplied by the inverse of the sum register, or each result register is divided by the sum register.
5. The computer-implemented method of claim 4, wherein: Generate the binary number q i The step includes converting the fractional component f into c,i Shift the integer part int right i Values: The corresponding fractional component f c,i Stored into the corresponding result register, and the fractional component f c,i Shift the integer part int right i to the corresponding result register.
6. A computer-implemented method according to any one of the preceding claims, wherein: Each input number y i The input scaling factor S in Scaled and stored in the first N-bit register.
7. The computer-implemented method of claim 6, wherein: The input scaling factor S in It is determined based on the expected minimum value and the expected maximum value of the input number y and the size N of the first register.
8. A computer-implemented method according to any one of claims 2 to 5, wherein: By converting the input number y i Multiply by the approximate value of the reciprocal of the natural logarithm of 2 to determine the number of elements z i The steps include: Each input number y i Store in binary form into the first N-bit register; The input number y i Shift right by N / 2-1, and convert the right-shifted input number y into i,T Stored into the second N / 2-bit register: - If the input number y i After the right shift of N / 2-1, the second N / 2-bit register does not overflow, and the right-shifted input number y i,T fits into the second N / 2-bit register, or - If the input number y i If the second N / 2-bit register overflows after right shifting by N / 2-1, the second N / 2-bit register is saturated; A constant value in binary form is provided to the third N / 2-bit register, the constant value being approximately equal to the reciprocal of the natural logarithm of 2 minus 1 divided by 2 N / 2-1 Zoom; Calculating the product of the second N / 2-bit register and the third N / 2-bit register, and storing the product in a fourth N-bit register; and The sum of the first N-bit register and the fourth N-bit register is determined by performing saturated addition to obtain the element number z i , and stores the sum in the fifth N-bit register.
9. The computer-implemented method of claim 8, wherein: By converting the input number y i Multiply by the approximate value of the reciprocal of the natural logarithm of 2 to determine the number of elements z i The steps also include: By adding the input number y i Before shifting right by N / 2-1, put 2 N / 2-2 Add to the input number y i , to right-shift the input number y i,T Round up.
10. The computer-implemented method of any one of claims 2 to 5, wherein: By converting the input number y i Multiply by the approximate value of the reciprocal of the natural logarithm of 2 to determine the number of elements z i The steps include: Each input number y i Store in binary form into the first N-bit register; The input number y i Shift right by N / 2-2, and convert the right-shifted input number y i,T Stored in the second N-bit register; Will be 2 N / 2-2 The scaled binary constant value is provided to a third N-bit register (R3), the constant value being approximately equal to the reciprocal of the natural logarithm of 2 minus 1; Calculating the product of the second N-bit register and the third N-bit register, and storing the product in a fourth N-bit register; and The sum of the first N-bit register and the fourth N-bit register is determined by performing saturated addition to obtain the input scaling factor S in The number of elements after scaling z i , and stores the sum in the fifth N-bit register.
11. The computer-implemented method of claim 10, wherein: By converting the input number y i Multiply by the approximate value of the reciprocal of the natural logarithm of 2 to determine the number of elements z i The steps also include: By adding the input number y i Before shifting right by N / 2-2, put 2 N / 2-3 Add to the input number y i To right shift the input number y i,T Round up.
12. The computer-implemented method of claim 9 or 11, wherein: Determine the normalized probability p i The steps include: adding the result register to a summing register; By using the normalization scaling factor S n For value V 100 Scaling is performed to obtain the normalization factor f n , the value V 100 is obtained by setting all bits in each result register to 1; and The normalization factor f n Applied to each result register together with the normalization scaling factor S n Perform inverse scaling to obtain the normalized binary number q i_n .
13. The computer-implemented method of claim 4, wherein: The binary number q i is generated in the result register in the form of an IEEE 754 floating point number including an exponent and a mantissa, wherein the exponent is the integer part in binary form. i with the IEEE 754 exponent bias, and the mantissa is derived from the fractional component f c,i Obtained.
14. A computer-implemented method according to any one of the preceding claims, wherein: The computer-implemented method further comprises: By selecting the maximum original input number x from the original input number x max , from the corresponding original input number x i Each input number y is obtained i , the original input number x is the classification output of the neural network; and For each original input number x i : From x i Subtract x from max , to obtain negative or zero input number y i ;or From x max Subtract x from i , to obtain a zero or positive input number y i .
15. A system comprising one or more processors configured to perform the computer-implemented method according to any one of the preceding claims.
