Task classification method, device, electronic device and storage medium
By determining the comparison result between the original maximum data in the vector to be classified and the negative infinite, determining the target data, and optimizing the data in the vector to be classified, the problem of overflowing the exponential operation results of the normalized exponential function is solved, and the accuracy of the operation results is achieved.
Patent Information
- Application Number
- CN202210200107.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-02
- Publication Date
- 2025-08-22
- Estimated Expiration
- 2042-03-02
AI Technical Summary
In the prior art, during the exponential operation of normalized exponential functions, due to the limited range of hardware data types, the input data will increase several times after exponential operation, resulting in overflow of the calculation results and an error occurs.
By determining the comparison result between the original maximum data in the vector to be classified and the negative infinite, the target data is determined, and the data in the vector to be classified is optimized based on the target data, including subtraction operations and assignment processing, to avoid overflowing of the exponential operation results.
Without changing the final result, the validity of data during the calculation process is guaranteed to the greatest extent, the accuracy of the calculation results is achieved, and the situation of invalid data is avoided.
Smart Images

Figure CN114743040B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a task classification method, device, electronic device and storage medium. Background Art
[0002] The normalized exponential function is an activation function used in deep neural networks. In neural network-based classification tasks, it is often used to normalize the multi-dimensional output of the neural network to obtain a probability vector, thereby achieving multi-task classification.
[0003] Normalizing the multidimensional data in a vector using a normalized exponential function can highlight the maximum value and suppress other components that are far below the maximum value. However, during the exponential operation of the normalized exponential function, due to the limited range of hardware data types, the input data will increase several times after the exponential operation of the normalized exponential function. This will undoubtedly cause the exponential operation result to overflow during the operation, resulting in an error in the operation result. Summary of the Invention
[0004] The present invention provides a task classification method, device, electronic device and storage medium, which are used to solve the defect in the prior art that input data will increase several times after the exponential operation of the normalized exponential function, thereby causing overflow of the exponential operation result.
[0005] The present invention provides a task classification method, comprising:
[0006] Determine each data in the vector to be classified;
[0007] Comparing each data in the vector to be classified to obtain the original maximum data in the vector to be classified;
[0008] Determining target data based on a comparison result between the original maximum data and negative infinity;
[0009] Based on the target data, each data in the vector to be classified is optimized, and based on the optimized each data in the vector to be classified, classification is performed to obtain a classification result.
[0010] According to a task classification method provided by the present invention, determining target data based on a comparison result between the original maximum data and negative infinity includes:
[0011] Based on the data comparison instruction and thread control, the original maximum data is compared with negative infinity to obtain a comparison result between the original maximum data and negative infinity;
[0012] If the comparison result indicates that the original maximum data is equal to negative infinity, setting the thread-controlled register to an active state, wherein the active state is used to indicate that the assignment instruction is valid;
[0013] Based on the assignment instruction, the target data is assigned.
[0014] According to a task classification method provided by the present invention, the method compares the original maximum data with negative infinity based on the data comparison instruction and thread control to obtain a comparison result between the original maximum data and negative infinity, and then further includes:
[0015] If the comparison result indicates that the original maximum data is not equal to negative infinity, the thread control register is set to an invalid state, and the target data is determined based on the original maximum data.
[0016] According to a task classification method provided by the present invention, the method optimizes each data in the vector to be classified based on the target data, and classifies each data in the optimized vector to be classified to obtain a classification result, including:
[0017] Performing a subtraction operation on each data in the to-be-classified vector and the target data to obtain input data of a task classification normalized exponential function;
[0018] The input data is input into the task classification normalized index function to obtain a classification result output by the task classification normalized index function.
[0019] According to a task classification method provided by the present invention, determining each data in the vector to be classified includes:
[0020] Loading each data in the vector to be classified based on data attributes of each data in the vector to be classified;
[0021] The data attributes include at least one of data source, data format, arrangement method, and data type.
[0022] According to a task classification method provided by the present invention, the step of loading each data in the vector to be classified based on the data attribute of each data in the vector to be classified includes:
[0023] If the data source in the data attribute is a memory, then loading each data in the vector to be classified based on the arrangement mode in the data attribute;
[0024] If the data in the data attribute comes from other operation modules, then the data in the vector to be classified is loaded based on the data format in the data attribute.
[0025] According to a task classification method provided by the present invention, comparing the data in the vector to be classified to obtain the original maximum data in the vector to be classified includes:
[0026] Initialize the temporary register to the first data in the vector to be classified;
[0027] The first data in the temporary register is compared with other data in the vector to be classified to obtain the original maximum data in the vector to be classified.
[0028] The present invention also provides a task classification device, comprising:
[0029] A determination unit, used for determining each data in the vector to be classified;
[0030] an original maximum data determining unit, configured to compare each data in the vector to be classified to obtain the original maximum data in the vector to be classified;
[0031] a target data determining unit, configured to determine target data based on a comparison result between the original maximum data and negative infinity;
[0032] The optimization classification unit is used to optimize each data in the vector to be classified based on the target data, and classify each data in the vector to be classified based on the optimized data to obtain a classification result.
[0033] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, any of the above-described task classification methods is implemented.
[0034] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which implements any of the above-mentioned task classification methods when executed by a processor.
[0035] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements any of the above-mentioned task classification methods.
[0036] The task classification method, device, electronic device and storage medium provided by the present invention determine target data based on the comparison result of the original maximum data in the vector to be classified and negative infinity. Then, based on the target data, each data in the vector to be classified is optimized, and classification is performed according to each data in the optimized vector to be classified to obtain a classification result. This overcomes the defect in traditional solutions that the input data will increase several times after the exponential operation of the normalized exponential function, thereby causing the exponential operation result to overflow. In addition, it can perfectly avoid the situation where the input data becomes invalid data after optimization when all data are negative infinity. Without changing the final result, the validity of the data during the operation is guaranteed to the greatest extent, thereby achieving the accuracy of the operation result. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the technical solutions in the present invention or the prior art, a brief introduction is given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0038] Figure 1 It is a flowchart of the task classification method provided by the present invention;
[0039] Figure 2 This is a code example diagram of the optimization process based on the original maximum data provided by the present invention;
[0040] Figure 3 This is an example diagram before and after adjustment based on the original maximum data provided by the present invention;
[0041] Figure 4 It is an overall flow chart of the task classification method provided by the present invention;
[0042] Figure 5 It is a structural diagram of the task classification device provided by the present invention;
[0043] Figure 6 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0044] To make the objectives, technical solutions, and advantages of the present invention more clear, the technical solutions of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the embodiments described are only some of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.
[0045] The normalized exponential function (Softmax function) is an activation function used in a variety of deep neural networks, such as ResNet (Residual Network) and Bert (Bidirectional Encoder Representation from Transformers). In neural network-based classification tasks, it is often used to normalize the multidimensional output of the neural network, that is, to normalize the multidimensional output of the neural network into a probability vector, thereby achieving task classification. Normalizing the multidimensional data in the vector using the normalized exponential function in the neural network can not only highlight the maximum value in the vector, but also suppress other components that are far below the maximum value.
[0046] The calculation formula of the normalized exponential function is shown as follows:
[0047]
[0048] Among them, x i Represents the input data in the vector, j represents the category, and n represents the number of elements in the vector, that is, the number of input data.
[0049] The following describes the calculation process of the normalized exponential function in the traditional solution, combined with the calculation formula of the normalized exponential function:
[0050] First, based on the data dimension of the input data, the input data is loaded, that is, each input data is loaded into m general registers according to its data dimension, where m = n / 2 a , and the value of a is determined based on the register size and data type length;
[0051] Subsequently, performing an exponential operation on each input data in each vector, adding the exponential operation results of each input data in each vector, and storing the sum of the exponential operation results of each vector obtained by the addition, that is, storing the sum of the exponential operation results of different vectors in another register respectively;
[0052] Thereafter, a division operation is performed on the input data in each vector and the sum of the exponential operation results of the corresponding vector obtained in the previous step, or a multiplication operation is performed on the input data in each vector and the inverse of the sum of the exponential operation results of the corresponding vector to obtain an output result, and this output result is stored in the memory.
[0053] However, in the exponential operation process based on the normalized exponential function, due to the limited range of hardware data types, the input data will increase several times after the exponential operation, causing the exponential operation result to overflow during the operation process, and then leading to errors in the calculation results.
[0054] In view of the above situation, the present invention provides a task classification method, which aims to optimize the input data of the normalized exponential function, thereby avoiding the overflow of the exponential operation result and achieving the accuracy of the operation result. Figure 1 It is a flowchart of the task classification method provided by the present invention, such as Figure 1 As shown, the method includes:
[0055] Step 110, determining each data in the vector to be classified;
[0056] Specifically, before performing task classification, it is first necessary to determine the classification object, that is, the vector to be classified. The vector to be classified here can be text, image, etc.
[0057] After determining the vector to be classified, the data within the vector must be determined. This data can be attribute values representing attributes of the vector to be classified, or it can be feature values representing features of the vector to be classified, though this is not specifically limited in the present embodiment. For example, if the vector to be classified is text, the data within the vector can be the number of characters in the text, feature values of semantic features, etc.; if the vector to be classified is an image, the data within the vector can be grayscale values, pixel values, etc.
[0058] It should be noted that, in an embodiment of the present invention, determining each data in the vector to be classified is actually loading each data in the vector to be classified into a general register. The specific loading method can be determined according to the data attributes of each data in the vector to be classified, and the data attributes can be data source, data format, arrangement method, etc.
[0059] Step 120, comparing each data in the vector to be classified to obtain the original maximum data in the vector to be classified;
[0060] Taking into account the situation that the exponential operation results of each data may overflow during the exponential operation process in traditional solutions, in the embodiment of the present invention, each data in the vector to be classified can be optimized, and the key to this optimization process is the original maximum data in the vector to be classified.
[0061] Based on this, in an embodiment of the present invention, after obtaining each data in the vector to be classified, the original maximum data can be determined from each data. That is, the data in the vector to be classified are compared, and the original maximum data is determined based on the comparison results. The specific process includes the following steps:
[0062] First, the temporary register is initialized based on the first data in the vector to be classified. That is, the temporary register is initialized to the first data in the vector to be classified. This can reduce some processes in the comparison process and simplify the comparison process.
[0063] Then, the first data in the vector to be classified stored in the temporary register is compared one by one with the other data in the vector to be classified, and the original maximum data in the vector to be classified is determined based on the comparison results and stored in the temporary register to provide support for the subsequent optimization process of each data in the vector to be classified.
[0064] Step 130, determining target data based on the comparison result between the original maximum data and negative infinity;
[0065] Specifically, after obtaining the original maximum data in the vector to be classified in step 120, the data in the vector to be classified can be optimized based on the original maximum data, and classification is performed based on the optimized data to obtain a classification result.
[0066] Figure 2 This is an example diagram of the optimization process code based on the original maximum data provided by the present invention. Figure 2 After the processing shown, there will be a special case, that is, the data in the vector to be classified are all negative infinity. At this time, the original maximum data is also negative infinity. Taking negative infinity as the benchmark, optimizing the data that are all negative infinity will undoubtedly result in the optimized data, that is, negative infinity plus the opposite of negative infinity, or negative infinity minus negative infinity. It can also be understood that negative infinity plus positive infinity is Not a Number (NaN), and Not a Number is invalid data.
[0067] Therefore, in order to overcome the above-mentioned defects, in an embodiment of the present invention, after obtaining the original maximum data in the vector to be classified, it is necessary to determine whether the original maximum data is equal to negative infinity, and determine the target data based on the judgment result, that is, the target data is determined based on the comparison result between the original maximum data and negative infinity; it should be noted that the target data here can be a constant (0, 1, 2, 3, etc.) or positive infinity, that is, it can be selected accordingly according to actual needs. The reason for determining this target data is that after adding a constant to the input data of the normalized exponential function, the exponential operation result obtained by the exponential operation is consistent with the exponential operation result obtained by the exponential operation of the input data without adding the constant.
[0068] The above process of determining the target data may specifically be to compare the original maximum data in the data to be classified with negative infinity, thereby obtaining a comparison result between the original maximum data and negative infinity; further, if the comparison result indicates that the original maximum data is not equal to negative infinity, the original maximum data in the temporary register may be directly used as the target data.
[0069] Correspondingly, if the comparison result shows that the original maximum data is equal to negative infinity, then, in order to avoid the occurrence of non-number situations, the original maximum data cannot be directly used as the target data, and the original maximum data in the temporary register needs to be adjusted. Specifically, the original maximum data in the temporary register can be assigned a value, that is, a constant or positive infinity is assigned to the original maximum data in the temporary register, and the original maximum data in the temporary register after assignment is directly used as the target data.
[0070] Directly using the original maximum data in the temporary register after assignment as the target data can be understood as the original maximum data after assignment being equal to the target data. Therefore, the process of assigning the original maximum data in the temporary register can be equivalent to the process of directly assigning the target data.
[0071] The following is an explanation of the above process based on a specific example:
[0072] Figure 3 This is an example diagram of the original maximum data before and after adjustment provided by the present invention, such as Figure 3 As shown in the figure, when all the data in the vector to be classified (X) are negative infinity (-inf), the original maximum data (Max value) is also negative infinity (-inf). At this time, the original maximum data in the temporary register needs to be adjusted, that is, a constant or positive infinity is assigned to the original maximum data in the temporary register. The assignment process here selects the constant 0, and the original maximum data (0) after assignment is used as the target data, which can avoid the occurrence of invalid data in the subsequent optimization process based on the target data (0), thereby ensuring the validity of the data.
[0073] Step 140 : Optimizing each data in the to-be-classified vector based on the target data, and classifying each data in the to-be-classified vector based on the optimized data to obtain a classification result.
[0074] Specifically, after determining the data in the vector to be classified and the target data through the above steps, step 140 can be executed. The specific process includes the following steps:
[0075] First, each data in the vector to be classified is optimized based on the target data. Specifically, a subtraction operation can be performed between each data in the vector to be classified and the target data, that is, the target data is subtracted from each data in the vector to be classified, which can also be understood as adding the opposite of the target data, thereby obtaining each data in the vector to be classified after optimization.
[0076] Subsequently, classification is performed according to the data in the optimized vector to be classified, that is, the data in the optimized vector to be classified is input into the task classification normalization exponential function, and the task classification normalization exponential function normalizes the input data, that is, normalizes the data into a probability vector, and finally obtains the classification result output by the task classification normalization exponential function. Through the normalization processing of the task classification normalization exponential function, not only the maximum possibility of the category to which the vector to be classified belongs is highlighted, but also other possibilities that are far lower than the maximum possibility are suppressed.
[0077] It should be noted that after obtaining the classification result, taking into account the hardware characteristics and subsequent usage requirements, the classification result can also be stored in a register or memory in a certain data format.
[0078] The following is an explanation of the above process based on a specific example:
[0079] When the vector to be classified is an image, the grayscale value, pixel value and other data in the vector to be classified can be optimized based on the target data, so as to obtain the optimized data in the vector to be classified, that is, the optimized pixel value, grayscale value and other data, and the optimized data in the vector to be classified are input into the task classification normalized exponential function to obtain the classification result output by the task classification normalized exponential function, that is, the category to which the vector to be classified (image) belongs, which can be scenery, people, animals and plants, etc.
[0080] The task classification method provided by the present invention determines target data based on the comparison result of the original maximum data in the vector to be classified and negative infinity. Then, based on the target data, each data in the vector to be classified is optimized, and classification is performed according to each data in the optimized vector to be classified to obtain a classification result. This method overcomes the defect in traditional solutions that the input data will increase several times after the exponential operation of the normalized exponential function, thereby causing the exponential operation result to overflow. In addition, it can perfectly avoid the situation where the input data becomes invalid data after optimization when all data are negative infinity. Without changing the final result, the validity of the data in the operation process is guaranteed to the greatest extent, thereby achieving the accuracy of the operation result.
[0081] Based on the above embodiment, step 130 includes:
[0082] Based on the data comparison instruction and thread control, the original maximum data and negative infinity are compared to obtain the comparison result between the original maximum data and negative infinity;
[0083] If the comparison result indicates that the original maximum data is equal to negative infinity, setting the thread control register to an active state, the active state is used to indicate that the assignment instruction is valid;
[0084] Based on the assignment instruction, the target data is assigned.
[0085] Specifically, in step 130, the process of determining the target data based on the comparison result between the original maximum data and negative infinity includes the following steps:
[0086] First, the original maximum data in the temporary register is compared with negative infinity. This process can be implemented through data comparison instructions and thread control. Specifically, the register is initialized to negative infinity. Then, based on the data comparison instruction, the negative infinity stored in this register is compared with the original maximum data in the temporary register to determine whether the original maximum data in the temporary register is equal to negative infinity. The comparison result between the original maximum data and negative infinity is obtained and stored in the thread-controlled register (mask).
[0087] Furthermore, if the comparison result of the original maximum data and negative infinity shows that the two are equal, that is, the original maximum data is equal to negative infinity, then it is necessary to assign the original maximum data in the temporary register, which can also be understood as directly assigning the target data. Specifically, the thread-controlled register can be set to an active state, and this active state is used to indicate that the assignment instruction is valid; thereafter, the target data can be assigned through an assignment instruction, that is, a constant or positive infinity is assigned to the target data, or it can be understood as assigning the original maximum data in the temporary register through an assignment instruction, that is, assigning a constant or positive infinity to the temporary register storing the original maximum data, and then the assigned original maximum data is directly used as the target data.
[0088] Based on the above embodiment, in step 130, based on the data comparison instruction and thread control, the original maximum data is compared with negative infinity to obtain a comparison result between the original maximum data and negative infinity, and then the following steps are further included:
[0089] If the comparison result indicates that the original maximum data is not equal to negative infinity, the register controlled by the thread is set to an invalid state, and the target data is determined based on the original maximum data.
[0090] Specifically, in step 130, after the original maximum data and negative infinity are compared according to the data comparison instruction and thread control, and a comparison result of the original maximum data and negative infinity is obtained, if the comparison result indicates that the original maximum data is equal to negative infinity, the target data is assigned through an assignment instruction. Correspondingly, if the comparison result of the original maximum data and negative infinity indicates that the two are not equal, that is, the original maximum data is not equal to negative infinity, then the thread control register (mask) can be directly set to an invalid (inactive) state. The invalid state indicates that the assignment instruction is not effective, that is, there is no need to assign a value through the assignment instruction. At this time, the target data can be directly determined based on the original maximum data in the temporary register, that is, the original maximum data in the temporary register is directly used as the target data.
[0091] Based on the above embodiment, step 140 includes:
[0092] Perform subtraction operation on each data in the vector to be classified and the target data to obtain the input data of the normalized exponential function of task classification;
[0093] Input the input data into the task classification normalized exponential function to obtain the classification result output by the task classification normalized exponential function.
[0094] Specifically, after obtaining the data in the vector to be classified and the target data through the above steps, the data in the vector to be classified can be optimized based on the target data. In the classification task based on the normalized exponential function, after adding a constant to the input data of the normalized exponential function, the exponential operation result obtained by the exponential operation is consistent with the exponential operation result obtained by the exponential operation of the input data without adding the constant. The derivation process of this conclusion is shown in the following formula:
[0095]
[0096] Therefore, in an embodiment of the present invention, each data in the vector to be classified is optimized. Specifically, a constant can be added to each data in the vector to be classified. To avoid overflow of the exponential operation result, this constant can be determined as the opposite of the original maximum data. Adding the opposite of the original maximum data is equal to subtracting the original maximum data, and the target data is determined based on the original maximum data in the temporary register or the original maximum data in the temporary register after assignment. Therefore, the above process is actually to perform a subtraction operation on each data in the vector to be classified and the target data, that is, to subtract the target data from each data in the vector to be classified, so as to obtain the optimized (subtraction operation) data in the vector to be classified.
[0097] It should be noted that, since classification is required based on the data in the optimized vector to be classified, and the classification task is completed with the help of the task classification normalized exponential function, the data in the optimized vector to be classified obtained at this time can also be called the input data of the task classification normalized exponential function.
[0098] The task classification process based on the input data of the task classification normalized exponential function can be specifically as follows: first, the input data obtained in the previous step is input into the task classification normalized exponential function; then, the task classification normalized exponential function normalizes the input data, that is, normalizes the input data into a probability vector, and finally obtains the classification result output by the task classification normalized exponential function. Through the normalization processing of the task classification normalized exponential function, not only the maximum possibility of the category to which the vector to be classified belongs is highlighted, but also other possibilities that are far lower than the maximum possibility are suppressed.
[0099] Based on the above embodiment, step 110 includes:
[0100] Loading each data in the vector to be classified based on the data attributes of each data in the vector to be classified;
[0101] Data attributes include at least one of data source, data format, arrangement method, and data type.
[0102] Specifically, in step 110, the process of determining each data in the vector to be classified is actually the process of loading each data in the vector to be classified into a general register, and the data loading process needs to be based on the data attributes of each data. The data attributes here can be one or more of the data source, data format, arrangement method, and data type of each data. Among them, the data source is the previous storage location of the data, which can be a memory, other computing modules, etc.; the data format indicates the storage format of each data in its data source; the arrangement method is the arrangement method and layout method of each data in the data source; there are many data types, which can be int, byte, char, etc.
[0103] Based on this, the above process of loading each data in the vector to be classified based on the data attributes of each data in the vector to be classified can specifically be based on any one, two or three of the data source, data format, arrangement method, and data type of each data in the vector to be classified. Of course, the above four factors can also be combined to determine the loading method suitable for the corresponding data, and load the corresponding data according to this loading method.
[0104] Based on the above embodiment, in step 110, the data attributes of each data in the vector to be classified are loaded, including:
[0105] If the data source in the data attribute is a memory, then the data in the vector to be classified is loaded based on the arrangement in the data attribute;
[0106] If the data source in the data attribute is other operation modules, then the data in the vector to be classified is loaded based on the data format in the data attribute.
[0107] Specifically, the process of loading each data in the vector to be classified based on the data attributes of each data in the vector to be classified includes the following situations:
[0108] When the data source in the data attributes of each data in the vector to be classified is a memory, the arrangement method in its data attributes can be used as a basis, and on this basis combined with the hardware characteristics, a loading method suitable for the corresponding data can be jointly determined, and based on this loading method, each data in the vector to be classified is loaded into a general register.
[0109] Correspondingly, when the data source in the data attributes of each data in the vector to be classified is other operation modules, the storage format of the loaded data must conform to the output format of its data source (other operation module). Therefore, at this time, the data format in its data attributes can be used as a reference to load each data in the vector to be classified.
[0110] Based on the above embodiment, step 120 includes:
[0111] Initialize the temporary register to the first data in the vector to be sorted;
[0112] The first data in the temporary register is compared with the other data in the vector to be classified to obtain the original maximum data in the vector to be classified.
[0113] Specifically, in step 120, the process of comparing the data in the vector to be classified to obtain the original maximum data in the vector to be classified includes the following steps:
[0114] First, the temporary register is initialized. This initialization is performed based on the first data in the vector to be classified. That is, the temporary register is initialized to the first data in the vector to be classified. This can reduce some processes in the comparison process, thereby simplifying the comparison process of each data in the vector to be classified.
[0115] Then, the first data in the vector to be classified stored in the temporary register is compared one by one with the other data in the vector to be classified stored in the general register. Then, based on the comparison result, the original maximum data is determined from the data of the vector to be classified, and the original maximum data is saved in the temporary register, which provides support for the subsequent optimization process of each data in the vector to be classified.
[0116] Figure 4 This is the overall flow chart of the task classification method provided by the present invention, such as Figure 4 As shown, the method includes:
[0117] Step 410: Load each data in the vector to be classified based on the data attributes of each data in the vector to be classified; the data attributes include at least one of data source, data format, arrangement mode, and data type;
[0118] Step 421, initializing the temporary register to the first data in the vector to be classified;
[0119] Step 422 , comparing the first data in the temporary register with the other data in the vector to be classified to obtain the original maximum data in the vector to be classified;
[0120] Step 431 , based on the data comparison instruction and thread control, the original maximum data is compared with negative infinity to obtain a comparison result between the original maximum data and negative infinity;
[0121] Step 432 , if the comparison result indicates that the original maximum data is equal to negative infinity, then setting the thread control register to an active state, where the active state is used to indicate that the assignment instruction is valid;
[0122] Step 433, assigning a value to the target data based on the assignment instruction;
[0123] Step 434 , if the comparison result indicates that the original maximum data is not equal to negative infinity, then the thread control register is set to an invalid state, and the target data is determined based on the original maximum data;
[0124] Step 441 , performing a subtraction operation on each data in the vector to be classified and the target data to obtain input data of the task classification normalized exponential function;
[0125] Step 442: Input the input data into the task classification normalized index function to obtain the classification result output by the task classification normalized index function.
[0126] The task classification method provided by the embodiment of the present invention determines target data based on the comparison result of the original maximum data in the vector to be classified with negative infinity. Then, based on the target data, each data in the vector to be classified is optimized, and classification is performed based on each data in the optimized vector to be classified to obtain a classification result. This overcomes the defect in traditional solutions that the input data increases several times after the exponential operation of the normalized exponential function, thereby causing the exponential operation result to overflow. In addition, it can perfectly avoid the situation where the input data becomes invalid data after optimization when all data are negative infinity. Without changing the final result, the validity of the data during the operation is guaranteed to the greatest extent, thereby achieving the accuracy of the operation result.
[0127] The task classification device provided by the present invention is described below. The task classification device described below and the task classification method described above can be referenced to each other.
[0128] Figure 5 is a structural diagram of the task classification device provided by the present invention, such as Figure 5 As shown, the device includes:
[0129] A determination unit 510 is used to determine each data in the vector to be classified;
[0130] an original maximum data determining unit 520, configured to compare each data in the vector to be classified to obtain the original maximum data in the vector to be classified;
[0131] a target data determining unit 530, configured to determine target data based on a comparison result between the original maximum data and negative infinity;
[0132] The optimization classification unit 540 is configured to optimize each data in the vector to be classified based on the target data, and classify each data in the vector to be classified based on the optimized data to obtain a classification result.
[0133] The task classification device provided by the present invention determines target data based on the comparison result between the original maximum data and negative infinity in the vector to be classified, then optimizes each data in the vector to be classified based on the target data, and classifies each data in the optimized vector to be classified to obtain a classification result. This overcomes the defect in traditional solutions that the input data will increase several times after the exponential operation of the normalized exponential function, thereby causing the exponential operation result to overflow. In addition, it can perfectly avoid the situation where the input data becomes invalid data after optimization when all data are negative infinity. Without changing the final result, the validity of the data in the operation process is guaranteed to the greatest extent, thereby achieving the accuracy of the operation result.
[0134] Based on the above embodiment, the target data determination unit 530 is configured to:
[0135] Based on the data comparison instruction and thread control, the original maximum data is compared with negative infinity to obtain a comparison result between the original maximum data and negative infinity;
[0136] If the comparison result indicates that the original maximum data is equal to negative infinity, setting the thread-controlled register to an active state, wherein the active state is used to indicate that the assignment instruction is valid;
[0137] Based on the assignment instruction, the target data is assigned.
[0138] Based on the above embodiment, the target data determination unit 530 is configured to:
[0139] If the comparison result indicates that the original maximum data is not equal to negative infinity, the thread control register is set to an invalid state, and the target data is determined based on the original maximum data.
[0140] Based on the above embodiment, the optimization classification unit 540 is used to:
[0141] Performing a subtraction operation on each data in the to-be-classified vector and the target data to obtain input data of a task classification normalized exponential function;
[0142] The input data is input into the task classification normalized index function to obtain a classification result output by the task classification normalized index function.
[0143] Based on the above embodiment, the determining unit 510 is configured to:
[0144] Loading each data in the vector to be classified based on data attributes of each data in the vector to be classified;
[0145] The data attributes include at least one of data source, data format, arrangement method, and data type.
[0146] Based on the above embodiment, the determining unit 510 is configured to:
[0147] If the data source in the data attribute is a memory, then loading each data in the vector to be classified based on the arrangement mode in the data attribute;
[0148] If the data in the data attribute comes from other operation modules, then the data in the vector to be classified is loaded based on the data format in the data attribute.
[0149] Based on the above embodiment, the original maximum data determining unit 520 is configured to:
[0150] Initialize the temporary register to the first data in the vector to be classified;
[0151] The first data in the temporary register is compared with other data in the vector to be classified to obtain the original maximum data in the vector to be classified.
[0152] Figure 6 An example of a physical structure diagram of an electronic device is shown below. Figure 6As shown, the electronic device may include: a processor 610, a communications interface 620, a memory 630, and a communications bus 640, wherein the processor 610, the communications interface 620, and the memory 630 communicate with each other via the communications bus 640. The processor 610 may call logic instructions in the memory 630 to execute a task classification method, which includes: determining each data in a vector to be classified; comparing each data in the vector to be classified to obtain the original maximum data in the vector to be classified; determining target data based on the comparison result of the original maximum data with negative infinity; optimizing each data in the vector to be classified based on the target data, and classifying each data in the optimized vector to be classified to obtain a classification result.
[0153] In addition, the logic instructions in the above-mentioned memory 630 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. 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.
[0154] On the other hand, the present invention also provides a computer program product, which includes a computer program, which can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the task classification method provided by the above methods, which includes: determining each data in the vector to be classified; comparing each data in the vector to be classified to obtain the original maximum data in the vector to be classified; determining target data based on the comparison result of the original maximum data and negative infinity; optimizing each data in the vector to be classified based on the target data, and classifying each data in the optimized vector to be classified to obtain a classification result.
[0155] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the task classification method provided by the above-mentioned methods, the method comprising: determining each data in the vector to be classified; comparing each data in the vector to be classified to obtain the original maximum data in the vector to be classified; determining target data based on the comparison result of the original maximum data and negative infinity; optimizing each data in the vector to be classified based on the target data, and classifying each data in the optimized vector to be classified to obtain a classification result.
[0156] The device embodiments described above are merely illustrative. 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, i.e., they may be located in one location or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of the present embodiment. Persons of ordinary skill in the art will be able to understand and implement the present invention without inventive effort.
[0157] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, or of course, by hardware. Based on this understanding, the essence of the above technical solution or the part that contributes to the existing technology can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or certain parts of the embodiments.
[0158] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned 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 various embodiments of the present invention.
Claims
1. A task classification method, characterized in that: include: Determine each data in the vector to be classified; Comparing each data in the vector to be classified to obtain the original maximum data in the vector to be classified; Determining target data based on a comparison result between the original maximum data and negative infinity; Optimizing each data in the vector to be classified based on the target data, and classifying each data in the vector to be classified based on the optimized data to obtain a classification result; The determining of target data based on the comparison result between the original maximum data and negative infinity includes: If the comparison result indicates that the original maximum data is equal to negative infinity, setting the thread-controlled register to an active state, wherein the active state is used to indicate that the assignment instruction is valid; Based on the assignment instruction, the target data is assigned.
2. The task classification method according to claim 1, characterized in that: The comparison result is determined based on the following steps: Based on the data comparison instruction and thread control, the original maximum data is compared with negative infinity to obtain a comparison result between the original maximum data and negative infinity.
3. The task classification method according to claim 2, characterized in that: The method further includes comparing the original maximum data with negative infinity based on the data comparison instruction and thread control to obtain a comparison result between the original maximum data and negative infinity, and then further including: If the comparison result indicates that the original maximum data is not equal to negative infinity, the thread control register is set to an invalid state, and the target data is determined based on the original maximum data.
4. The task classification method according to any one of claims 1 to 3, characterized in that: The step of optimizing each data in the vector to be classified based on the target data, and classifying each data in the vector to be classified based on the optimized data to obtain a classification result includes: Performing a subtraction operation on each data in the to-be-classified vector and the target data to obtain input data of a task classification normalized exponential function; The input data is input into the task classification normalized index function to obtain a classification result output by the task classification normalized index function.
5. The task classification method according to any one of claims 1 to 3, characterized in that: The determining of each data in the vector to be classified includes: Loading each data in the vector to be classified based on data attributes of each data in the vector to be classified; The data attributes include at least one of data source, data format, arrangement method, and data type.
6. The task classification method according to claim 5, characterized in that: The step of loading each data in the vector to be classified based on the data attribute of each data in the vector to be classified includes: If the data source in the data attribute is a memory, then loading each data in the vector to be classified based on the arrangement mode in the data attribute; If the data in the data attribute comes from other operation modules, then the data in the vector to be classified is loaded based on the data format in the data attribute.
7. The task classification method according to any one of claims 1 to 3, characterized in that: The comparing of the data in the vector to be classified to obtain the original maximum data in the vector to be classified includes: Initialize the temporary register to the first data in the vector to be classified; The first data in the temporary register is compared with other data in the vector to be classified to obtain the original maximum data in the vector to be classified.
8. A task classification device, characterized in that: include: A determination unit, used for determining each data in the vector to be classified; an original maximum data determining unit, configured to compare each data in the vector to be classified to obtain the original maximum data in the vector to be classified; a target data determining unit, configured to determine target data based on a comparison result between the original maximum data and negative infinity; an optimization classification unit, configured to optimize each data in the vector to be classified based on the target data, and classify each data in the vector to be classified based on the optimized data to obtain a classification result; The determining of target data based on the comparison result between the original maximum data and negative infinity includes: If the comparison result indicates that the original maximum data is equal to negative infinity, setting the thread-controlled register to an active state, wherein the active state is used to indicate that the assignment instruction is valid; Based on the assignment instruction, the target data is assigned.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the task classification method according to any one of claims 1 to 7 is implemented.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the task classification method according to any one of claims 1 to 7 is implemented.
11. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the task classification method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Format conversion during load / store operations in vector processor
CN105940373A
Vector calculation device and method
CN113407154A