Training method and device for formula recognition model and device for model training

By iteratively training the formula recognition model, using the loss value adjustment of the encoder and decoder and the Transformer network structure, the problem of low accuracy of the formula recognition algorithm in the existing technology is solved, and higher recognition accuracy is achieved.

CN113919294BActive Publication Date: 2024-09-24BEIJING SOGOU TECHNOLOGY DEVELOPMENT CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202111156277.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-29
Publication Date
2024-09-24
Estimated Expiration
2041-09-29

AI Technical Summary

Technical Problem

In existing formula recognition algorithms, the accumulation of errors in the staged recognition algorithm results in low accuracy, while the use of attention mechanisms in the decoding stage of the end-to-end algorithm can easily cause recognition error deviations, resulting in worse recognition accuracy.

Method used

By obtaining formula recognition samples and target recognition results, the formula recognition model is iteratively trained, using the encoder and decoder to calculate the loss value and adjust the model parameters. The decoder outputs the decoding results based on the current and previous encoding features, fully considering the encoding features. The Transformer network structure is used to focus on the information at different locations with a multi-head attention layer.

Benefits of technology

The recognition accuracy of the formula recognition model is improved, the recognition error deviation is avoided, and the recognition accuracy is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113919294B
    Figure CN113919294B
Patent Text Reader

Abstract

The embodiment of the present invention provides a training method and device for a formula recognition model and a device for model training. The method comprises: obtaining a formula recognition sample and a target recognition result corresponding to the formula recognition sample; iteratively training the formula recognition model based on the formula recognition sample, the formula recognition model comprising an encoder and a decoder; in each round of training, according to the formula recognition result output by the decoder and the target recognition result, calculating the loss value of the formula recognition model, and adjusting the model parameters of the formula recognition model according to the loss value; wherein the decoder outputs the formula recognition result based on the current encoding feature of the formula recognition sample and the decoding result of the previous encoding feature; when the joint loss value meets the convergence condition, a trained formula recognition model is obtained. The embodiment of the present invention can improve the recognition accuracy of the formula recognition model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of intelligent control technology, and in particular to a training method and device for a formula recognition model and a device for model training. Background Art

[0002] Formula recognition technology has a wide range of application needs in education fields such as automatic examination paper grading, photo search, and test digitization. Since the formula itself may have a complex two-dimensional structure, numerous symbols, similar symbols, and diverse meanings, the accuracy of formula recognition is not high.

[0003] In recent years, with the significant improvement of computer computing power and the advent of the big data era, neural network-based formula recognition algorithms have been widely used in various formula recognition scenarios. At present, there are two common formula recognition algorithms: one is a phased recognition algorithm based on the "segmentation-recognition-reprocessing" process, and the other is an end-to-end formula recognition algorithm.

[0004] However, in the staged recognition algorithm, each stage will cause errors, and the errors in each stage will accumulate, resulting in poor final accuracy. For the end-to-end formula recognition algorithm, the decoding stage mainly uses the attention mechanism, which is easy to cause recognition error offset, resulting in the longer the recognition time slice, the worse the accuracy. Summary of the invention

[0005] The embodiments of the present invention provide a training method and device for a formula recognition model and a device for model training, which can improve the recognition accuracy of the formula recognition model.

[0006] In order to solve the above problems, an embodiment of the present invention discloses a training method for a formula recognition model, the method comprising:

[0007] Obtaining a formula recognition sample and a target recognition result corresponding to the formula recognition sample;

[0008] Iteratively training a formula recognition model based on the formula recognition samples, wherein the formula recognition model includes an encoder and a decoder;

[0009] In each round of training, according to the formula recognition result output by the decoder and the target recognition result, the loss value of the formula recognition model is calculated, and the model parameters of the formula recognition model are adjusted according to the loss value; wherein the decoder outputs the formula recognition result based on the current encoding feature of the formula recognition sample and the decoding result of the previous encoding feature;

[0010] When the joint loss value meets the convergence condition, a trained formula recognition model is obtained.

[0011] Optionally, the encoding feature includes a feature map, and the calculating the loss value of the formula recognition model according to the formula recognition result output by the decoder and the target recognition result includes:

[0012] Inputting the formula recognition sample into the encoder of the formula recognition model for encoding processing to obtain a first feature map of the formula recognition sample;

[0013] Splitting the first feature map to obtain M second feature maps;

[0014] Sorting the M second feature maps according to a preset rule;

[0015] Inputting the decoding result corresponding to the N-1th second feature map and the Nth second feature map into the decoder of the formula recognition model for decoding processing, until the Mth second feature map is input into the decoder, and obtaining the formula recognition result corresponding to the formula recognition sample; wherein M and N are positive integers, and N is less than or equal to M;

[0016] The loss value of the formula recognition model is calculated according to the formula recognition result and the target recognition result.

[0017] Optionally, the splitting the first feature map to obtain M second feature maps includes:

[0018] Determining a relative position code corresponding to the first feature map;

[0019] Adding the relative position code to the first feature map to obtain a third feature map;

[0020] The third feature map is split to obtain M second feature maps.

[0021] Optionally, the splitting the first feature map to obtain M second feature maps includes:

[0022] Determining a width value of the first feature map;

[0023] The first feature map is split according to the width value of the first feature map to obtain M second feature maps.

[0024] Optionally, if the value of N is 1, the decoding result corresponding to the N-1th second feature map is a preset value.

[0025] Optionally, the method further comprises:

[0026] Acquire a target image, wherein the target image contains a formula to be recognized;

[0027] The target image is input into the trained formula recognition model for formula recognition processing to obtain a formula recognition result corresponding to the target image.

[0028] On the other hand, an embodiment of the present invention discloses a training device for a formula recognition model, the device comprising:

[0029] A training data acquisition module, used to acquire formula recognition samples and target recognition results corresponding to the formula recognition samples;

[0030] An iterative training module, used for iteratively training a formula recognition model based on the formula recognition samples, wherein the formula recognition model includes an encoder and a decoder;

[0031] A loss value calculation module, used to calculate the loss value of the formula recognition model according to the formula recognition result output by the decoder and the target recognition result in each round of training, and adjust the model parameters of the formula recognition model according to the loss value; wherein the decoder outputs the formula recognition result based on the current encoding feature of the formula recognition sample and the decoding result of the previous encoding feature;

[0032] The training completion condition determination module is used to obtain a training completed formula recognition model when the joint loss value meets the convergence condition.

[0033] Optionally, the encoding feature includes a feature map, and the loss value calculation module includes:

[0034] An encoding processing submodule, used for inputting the formula recognition sample into the encoder of the formula recognition model for encoding processing to obtain a first feature map of the formula recognition sample;

[0035] A splitting processing submodule, used for splitting the first feature map to obtain M second feature maps;

[0036] A feature map sorting submodule, used to sort the M second feature maps according to a preset rule;

[0037] A decoding processing submodule, used for inputting the decoding result corresponding to the N-1th second feature map and the Nth second feature map into the decoder of the formula recognition model for decoding processing, until the Mth second feature map is input into the decoder, and obtaining the formula recognition result corresponding to the formula recognition sample; wherein M and N are positive integers, and N is less than or equal to M;

[0038] The loss value calculation submodule is used to calculate the loss value of the formula recognition model according to the formula recognition result and the target recognition result.

[0039] Optionally, the splitting processing submodule includes:

[0040] A relative position code determining unit, used to determine a relative position code corresponding to the first feature map;

[0041] A relative position code adding unit, used for adding the relative position code to the first feature map to obtain a third feature map;

[0042] The first splitting processing unit is used to split the third feature map to obtain M second feature maps.

[0043] Optionally, the splitting processing submodule includes:

[0044] A width value determining unit, used to determine a width value of the first feature map;

[0045] The second splitting processing unit is used to split the first feature map according to the width value of the first feature map to obtain M second feature maps.

[0046] Optionally, if the value of N is 1, the decoding result corresponding to the N-1th second feature map is a preset value.

[0047] Optionally, the device further comprises:

[0048] A target image acquisition module, used to acquire a target image, wherein the target image contains a formula to be identified;

[0049] The formula recognition processing module is used to input the target image into the trained formula recognition model for formula recognition processing to obtain the formula recognition result corresponding to the target image.

[0050] On the other hand, an embodiment of the present invention discloses a device for model training, which includes a memory and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by one or more processors. The one or more programs include instructions for executing a training method for a formula recognition model as described above.

[0051] On the other hand, an embodiment of the present invention discloses a machine-readable medium having instructions stored thereon, which, when executed by one or more processors, enables the device to perform one or more of the training methods for the formula recognition model described above.

[0052] The embodiments of the present invention include the following advantages:

[0053] The embodiment of the present invention obtains a formula recognition sample and a target recognition result corresponding to the formula recognition sample; then, iteratively trains a formula recognition model based on the formula recognition sample, and the formula recognition model includes an encoder and a decoder; in each round of training, the loss value of the formula recognition model is calculated according to the formula recognition result output by the decoder and the target recognition result, and the model parameters of the formula recognition model are adjusted according to the loss value; wherein the decoder outputs the formula recognition result based on the current coding feature of the formula recognition sample and the decoding result of the previous coding feature; when the joint loss value meets the convergence condition, the trained formula recognition model is obtained. Compared with the prior art that uses the attention mechanism to construct a decoder so that the decoder only focuses on limited key information, the embodiment of the present invention predicts the decoding result of the current coding feature by introducing the decoding result corresponding to the previous coding feature of the formula recognition sample during the decoding process, and determines the formula recognition result based on the decoding results of each coding feature, which fully considers the correlation between the coding features and is conducive to improving the recognition accuracy. BRIEF DESCRIPTION OF THE DRAWINGS

[0054] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.

[0055] Figure 1 is a schematic diagram of the structure of a computer system of the present invention;

[0056] Figure 2 It is a flowchart of the steps of an embodiment of a training method of a formula recognition model of the present invention;

[0057] Figure 3 It is a structural schematic diagram of a formula recognition model of the present invention;

[0058] Figure 4 It is a structural block diagram of an embodiment of a training device for a formula recognition model of the present invention;

[0059] Figure 5 is a block diagram of a device 800 for model training of the present invention;

[0060] Figure 6 It is a schematic diagram of the structure of the server in some embodiments of the present invention. DETAILED DESCRIPTION

[0061] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0062] Method Embodiment

[0063] The embodiment of the present invention provides a method for training a formula recognition model, which can be applied to a computer device with data processing capabilities. In an optional embodiment, the method for training a formula recognition model provided by the embodiment of the present invention can be applied to a personal computer, a workstation or a server, that is, formula recognition and training of a formula recognition model can be implemented by a personal computer, a workstation or a server.

[0064] The trained formula recognition model can become a part of the application and be installed in the terminal, so that the terminal can output the formula recognition result when receiving the content to be recognized; or, the trained formula recognition model is set in the background server of the application, so that the terminal with the application installed can realize the formula recognition function with the help of the background server.

[0065] Reference Figure 1 , shows a schematic diagram of the structure of a computer system provided by an embodiment of the present invention, the computer system includes a terminal 110 and a server 120. The terminal 110 and the server 120 perform data communication via a communication network. Optionally, the communication network may be a wired network or a wireless network, and the communication network may be at least one of a local area network, a metropolitan area network, and a wide area network.

[0066] The terminal 110 is installed with an application supporting the formula recognition function, which may be an e-book reading application, a web browsing application, a paper marking application, a photo search application, a social application, etc., which is not specifically limited in the embodiment of the present invention.

[0067] Optionally, the terminal 110 may be a mobile terminal such as a smart phone, a smart watch, a tablet computer, a laptop computer, an intelligent robot, or the like, or a terminal such as a desktop computer or a projection computer. The embodiment of the present invention does not limit the type of terminal.

[0068] The server 120 may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, and may also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, cloud communications, network services, middleware services, content delivery networks (CDN), and big data and artificial intelligence platforms. In an optional embodiment, the server 120 may be a background server of an application in the terminal 110.

[0069] In some embodiments, the terminal 110 includes a camera component; the terminal 110 obtains picture content through the camera component, and the picture content includes the formula to be recognized, and the terminal 110 sends the picture to the server 120. The server 120 includes a formula recognition module, and the formula recognition module includes a trained formula recognition model; the server 120 receives the picture sent by the terminal 110, recognizes the formula in the picture through the formula recognition model, and sends the recognition result to the terminal 110 for display.

[0070] Alternatively, the terminal 110 includes a formula recognition module, which includes a trained formula recognition model. After acquiring the picture, the terminal recognizes the formula in the picture through the formula recognition model to obtain a recognition result, and displays the recognition result.

[0071] It should be noted that, in the above embodiments, the display method of the terminal includes picture form or text form.

[0072] For the convenience of description, the following embodiments are described by taking the training method of the formula recognition model executed by the server as an example.

[0073] Reference Figure 2 , shows a flowchart of a training method embodiment of a formula recognition model of the present invention, and the method may specifically include the following steps:

[0074] Step 201: Obtain a formula recognition sample and a target recognition result corresponding to the formula recognition sample.

[0075] Step 202: Iteratively train a formula recognition model based on the formula recognition samples, where the formula recognition model includes an encoder and a decoder.

[0076] Step 203: In each round of training, the loss value of the formula recognition model is calculated according to the formula recognition result output by the decoder and the target recognition result, and the model parameters of the formula recognition model are adjusted according to the loss value; wherein the decoder outputs the formula recognition result based on the current encoding feature of the formula recognition sample and the decoding result of the previous encoding feature.

[0077] Step 204: When the joint loss value meets the convergence condition, a trained formula recognition model is obtained.

[0078] The formula recognition sample is an image used for training, and the image contains the formula to be recognized. The target recognition result corresponding to the formula recognition sample is the real recognition result of the formula recognition sample, which is used to verify the accuracy of the output result of the formula recognition model.

[0079] There are many ways to obtain formula recognition samples and target labels corresponding to the formula recognition samples. For example, existing formula images and formula recognition results on the Internet, formula images and recognition results stored on computer devices, etc. can all be used as formula recognition samples in embodiments of the present invention.

[0080] It should be noted that the embodiment of the present invention does not specifically limit the size of the formula recognition sample. In order to speed up the model training speed, the formula recognition sample can be preprocessed in advance. Exemplarily, the image height of each formula recognition sample can be uniformly adjusted to a preset height, for example, the image height of each formula recognition sample is fixed to 64 pixels; then, based on the height adjustment ratio of each formula recognition sample, the image width is scaled proportionally. For example, for formula recognition sample A, its image height before preprocessing is 32 pixels and its image width is 128 pixels. The image height of formula recognition sample A is adjusted to 64 pixels, and the image height of formula recognition sample A is stretched by 2 times. Therefore, its image width is also stretched by 2 times and adjusted to 256 pixels. In order to avoid the increase of training difficulty due to the large difference in the size of the formula recognition samples during the training process, the scaled formula recognition samples can be sorted in order from small to large or from large to small according to the image width, and the adjacent m formula recognition samples are taken as a sample group, and the formula recognition samples of the same sample group are synchronously processed.

[0081] The formula recognition model is used to recognize the formula content in the input image data. In an embodiment of the present invention, the formula recognition model can be constructed using an end-to-end network structure. As an example, the formula recognition model can adopt an Encoder-Decoder structure, including an encoder and a decoder.

[0082] The encoder may adopt a CNN (Convolution nNeural Networks) structure. For example, the optimal CNN network structure may be determined as the encoder of the encoding and decoding module through NAS (Neural Architecture Search) under the premise that the accuracy is not greatly affected. The decoder may adopt a Transformer network structure.

[0083] Reference Figure 3 , shows a schematic diagram of the structure of a formula recognition model according to an embodiment of the present invention. Figure 3 As shown, the formula recognition model includes an encoder and a decoder, and the decoder adopts a Transformer network structure. The decoder may include multiple decoding modules, Figure 3 Nx in represents the number of decoding modules. In an embodiment of the present invention, the value of Nx can be 3. In other words, the decoder can include 3 decoding modules. It should be noted that the network structure of each decoding module is the same, mainly including a masked multi-head attention layer (MMHA), a multi-head attention layer (MHA), and a feed forward neural network layer (FFN). Among them, the masked multi-head attention layer is mainly used to add a mask to the input data to mask some parameter values ​​so that it has no effect when the parameters are updated. The input data of the multi-head attention layer includes the output data of the encoder of the formula recognition model and the output data of the masked multi-head attention layer, that is, the current encoding feature output by the encoder and the decoding result of the previous encoding feature after adding the mask. The multi-head attention layer can extract the correlation between the decoding result of the current encoding feature and the previous encoding feature, considering the influence of the decoding result of the previous encoding feature on the decoding process of the current encoding feature. The feed forward neural network layer is used to perform nonlinear transformation processing on the output data of the multi-head attention layer.

[0084] In addition to the decoding module, the decoder also includes an output module, which is mainly composed of a linear transformation layer (Linear) and a fully connected network layer. Among them, the fully connected network layer can use a softmax activation function. The output module first performs a linear transformation on the output data of the decoding module, and then obtains the probability distribution of the prediction result based on the fully connected network layer, and outputs the prediction result with the largest output probability as the formula recognition result.

[0085] In each round of training, the formula recognition sample to be processed is input into the encoder of the formula recognition model, and the encoder encodes the formula recognition sample and outputs the encoding feature of the formula recognition sample. The decoder outputs the formula recognition result based on the current encoding feature of the formula recognition sample and the decoding result of the previous encoding feature. Then, according to the formula recognition result and the target recognition result of the formula recognition sample, the loss value of the formula recognition model is calculated, and the model parameters of the formula recognition model are adjusted according to the loss value until the convergence condition is met to obtain the trained formula recognition model. Among them, the loss value can be determined based on the cross entropy of the formula recognition result output by the formula recognition model and the target recognition result. The convergence condition can be that the loss value of the formula recognition model is less than a preset threshold in multiple rounds of training, or that the error between the loss values ​​is less than a preset value.

[0086] Compared with the prior art that uses the attention mechanism to construct a decoder, so that the decoder only focuses on limited key information, during the decoding process, the embodiment of the present invention introduces the decoding result corresponding to the previous coding feature of the formula recognition sample to predict the decoding result of the current coding feature, and determines the formula recognition result based on the decoding results of each coding feature, which fully considers the correlation between the coding features and is conducive to improving the recognition accuracy.

[0087] Moreover, in an embodiment of the present invention, a decoder constructed with a Transformer network structure can be used, thereby simultaneously paying attention to information from different representation subspaces at different positions based on a multi-head attention layer, thereby increasing the diversity of reference feature information, avoiding recognition error offset, and further improving recognition accuracy.

[0088] In an optional embodiment of the present invention, the encoding feature includes a feature map, and the step 203 of calculating the loss value of the formula recognition model according to the formula recognition result output by the decoder and the target recognition result includes:

[0089] Step S11, inputting the formula recognition sample into the encoder of the formula recognition model for encoding processing to obtain a first feature map of the formula recognition sample;

[0090] Step S12: splitting the first feature map to obtain M second feature maps;

[0091] Step S13, sorting the M second feature maps according to a preset rule;

[0092] Step S14, inputting the decoding result corresponding to the N-1th second feature map and the Nth second feature map into the decoder of the formula recognition model for decoding processing, until the Mth second feature map is input into the decoder, and obtaining the formula recognition result corresponding to the formula recognition sample; wherein M and N are positive integers, and N is less than or equal to M;

[0093] Step S15, calculating the loss value of the formula recognition model according to the formula recognition result and the target recognition result.

[0094] The encoder encodes the input formula recognition sample, which is essentially to extract features from the formula recognition sample. Taking the encoder of the formula recognition model using a CNN network as an example, the encoder performs convolution processing on the formula recognition sample to extract multiple features in the formula recognition sample into one feature, and the extracted features form a feature map of the formula recognition sample.

[0095] Among them, the first feature map is a four-dimensional feature map, and the second feature map is a three-dimensional feature map.

[0096] It should be noted that, in the embodiment of the present invention, the formula recognition sample is a picture containing a formula, including height, length, width, and RGB (RGB color mode, color system) channel features. Therefore, after the encoding process of the encoder, the four-dimensional features corresponding to the height, length, width, and RGB channels are usually obtained, and in the Transformer network structure, the input data of the decoder is required to be a three-dimensional feature. Therefore, in order to meet the requirements of the decoder for input data in the present invention, the first feature map can be split and processed to obtain M second feature maps. In addition, the M second feature maps are sorted, and the N-1 second feature map is used as the previous encoding feature of the formula recognition sample, and the N-1 second feature map is used as the current encoding feature of the formula recognition sample, so as to predict the decoding result of the current encoding feature based on the decoding result of the previous encoding feature. Wherein, M and N are positive integers, and N is less than or equal to M; if the value of N is 1, the decoding result corresponding to the N-1 second feature map is a preset value.

[0097] In an optional embodiment of the present invention, the step S12 of splitting the first feature map to obtain M second feature maps includes:

[0098] A11, determining a relative position code corresponding to the first feature map;

[0099] A12. Add the relative position code to the first feature map to obtain a third feature map;

[0100] A13. Split the third feature map to obtain M second feature maps.

[0101] The spatial structure of a formula is generally complex, including a variety of positional relationships, such as front-to-back, top-to-bottom, and including. Therefore, in an embodiment of the present invention, after the encoder extracts features from the formula recognition sample, a relative position code may be further added to the extracted first feature map, and the formula recognition result is jointly determined based on the extracted first feature map and the relative position code, so as to more accurately determine the relative positional relationship between the recognized characters and improve the recognition accuracy of the formula recognition model.

[0102] In an optional embodiment of the present invention, the step S12 of splitting the first feature map to obtain M second feature maps includes:

[0103] A21. Determine a width value of the first feature map;

[0104] A22. Split the first feature map according to the width value of the first feature map to obtain M second feature maps.

[0105] Assume that the first feature map obtained can be expressed as Among them, B is the formula recognition sample included in the training sample group (batch); 684 represents the sequence length of the first feature map. Of course, the sequence length of the first feature map can also be other values; 4 represents the number of extracted features. In an embodiment of the present invention, the extracted features may include height features, length features, width features, and RGB features of the formula recognition sample. Therefore, the number of extracted features is 4; w represents the width value of the first feature map. Represents the coding features corresponding to B formula recognition samples. The coding features of each formula recognition sample contain the coding matrices corresponding to 4 types of image features. The length of each column in the coding matrix is ​​684 and the width is

[0106] When the first feature map is split, the first feature map F may be split into M second feature maps according to the width value of the first feature map. The second feature map may be expressed as That is, the first feature map F is split into The second feature map F d , in, Represents the encoding features corresponding to B formula recognition samples. The encoding features of each formula recognition sample include The length of the coding sequence is 684.

[0107] Of course, the first feature map may also be split in other ways, to which the embodiment of the present invention does not specifically limit.

[0108] In an optional embodiment of the present invention, the method further includes:

[0109] Step S21, obtaining a target image, wherein the target image contains a formula to be recognized;

[0110] Step S22: input the target image into the trained formula recognition model to perform formula recognition processing to obtain a formula recognition result corresponding to the target image.

[0111] In the embodiment of the present invention, after obtaining the trained formula recognition model, the trained formula recognition model can be used to perform formula recognition processing on the target image to obtain the formula recognition result corresponding to the target image. Compared with the existing formula recognition model, the formula recognition result obtained by the trained formula recognition model in the embodiment of the present invention has higher accuracy.

[0112] It should be noted that the decoding result of the previous encoding feature of the formula recognition sample is only extracted during the model training process. When formula recognition is performed after the training is completed, it is not necessary to extract the result of the previous encoding feature of the formula recognition sample, and the formula recognition result corresponding to the formula recognition sample is directly output.

[0113] In summary, in the decoding process, the embodiment of the present invention predicts the decoding result of the current coding feature by introducing the decoding result corresponding to the previous coding feature of the formula recognition sample, and determines the formula recognition result based on the decoding results of each coding feature, which fully considers the correlation between the coding features and is conducive to improving the recognition accuracy. In addition, in the embodiment of the present invention, a decoder constructed with a Transformer network structure can be used, so that based on the multi-head attention layer, information from different representation subspaces at different positions is simultaneously paid attention to, which increases the diversity of the reference feature information, can avoid recognition error offset, and further improve recognition accuracy.

[0114] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.

[0115] Device Embodiment

[0116] Reference Figure 4, shows a structural block diagram of an embodiment of a training device for a formula recognition model of the present invention, the device may include:

[0117] The training data acquisition module 401 is used to acquire formula recognition samples and target recognition results corresponding to the formula recognition samples;

[0118] An iterative training module 402, configured to iteratively train a formula recognition model based on the formula recognition samples, wherein the formula recognition model includes an encoder and a decoder;

[0119] The loss value calculation module 403 is used to calculate the loss value of the formula recognition model according to the formula recognition result output by the decoder and the target recognition result in each round of training, and adjust the model parameters of the formula recognition model according to the loss value; wherein the decoder outputs the formula recognition result based on the current encoding feature of the formula recognition sample and the decoding result of the previous encoding feature;

[0120] The training completion condition determination module 404 is used to obtain a trained formula recognition model when the joint loss value meets the convergence condition.

[0121] Optionally, the encoding feature includes a feature map, and the loss value calculation module includes:

[0122] An encoding processing submodule, used for inputting the formula recognition sample into the encoder of the formula recognition model for encoding processing to obtain a first feature map of the formula recognition sample;

[0123] A splitting processing submodule, used for splitting the first feature map to obtain M second feature maps;

[0124] A feature map sorting submodule, used to sort the M second feature maps according to a preset rule;

[0125] A decoding processing submodule, used for inputting the decoding result corresponding to the N-1th second feature map and the Nth second feature map into the decoder of the formula recognition model for decoding processing, until the Mth second feature map is input into the decoder, and obtaining the formula recognition result corresponding to the formula recognition sample; wherein M and N are positive integers, and N is less than or equal to M;

[0126] The loss value calculation submodule is used to calculate the loss value of the formula recognition model according to the formula recognition result and the target recognition result.

[0127] Optionally, the splitting processing submodule includes:

[0128] A relative position code determining unit, used to determine a relative position code corresponding to the first feature map;

[0129] A relative position code adding unit, used for adding the relative position code to the first feature map to obtain a third feature map;

[0130] The first splitting processing unit is used to split the third feature map to obtain M second feature maps.

[0131] Optionally, the splitting processing submodule includes:

[0132] A width value determining unit, used to determine a width value of the first feature map;

[0133] The second splitting processing unit is used to split the first feature map according to the width value of the first feature map to obtain M second feature maps.

[0134] Optionally, if the value of N is 1, the decoding result corresponding to the N-1th second feature map is a preset value.

[0135] Optionally, the device further comprises:

[0136] A target image acquisition module, used to acquire a target image, wherein the target image contains a formula to be identified;

[0137] The formula recognition processing module is used to input the target image into the trained formula recognition model for formula recognition processing to obtain the formula recognition result corresponding to the target image.

[0138] In summary, in the decoding process, the embodiment of the present invention predicts the decoding result of the current coding feature by introducing the decoding result corresponding to the previous coding feature of the formula recognition sample, and determines the formula recognition result based on the decoding results of each coding feature, which fully considers the correlation between the coding features and is conducive to improving the recognition accuracy. In addition, in the embodiment of the present invention, a decoder constructed with a Transformer network structure can be used, so that based on the multi-head attention layer, information from different representation subspaces at different positions is simultaneously paid attention to, which increases the diversity of the reference feature information, can avoid recognition error offset, and further improve recognition accuracy.

[0139] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0140] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0141] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.

[0142] An embodiment of the present invention provides a device for formula recognition model training, the device comprising a memory and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by one or more processors. The one or more programs include instructions for performing the following operations:

[0143] P11. Obtain a formula recognition sample and a target recognition result corresponding to the formula recognition sample;

[0144] P12. Iteratively training a formula recognition model based on the formula recognition samples, wherein the formula recognition model includes an encoder and a decoder;

[0145] P13. In each round of training, according to the formula recognition result output by the decoder and the target recognition result, the loss value of the formula recognition model is calculated, and the model parameters of the formula recognition model are adjusted according to the loss value; wherein the decoder outputs the formula recognition result based on the current encoding feature of the formula recognition sample and the decoding result of the previous encoding feature;

[0146] P14. When the joint loss value meets the convergence condition, a trained formula recognition model is obtained.

[0147] Optionally, the encoding feature includes a feature map, and the calculating the loss value of the formula recognition model according to the formula recognition result output by the decoder and the target recognition result includes:

[0148] Inputting the formula recognition sample into the encoder of the formula recognition model for encoding processing to obtain a first feature map of the formula recognition sample;

[0149] Splitting the first feature map to obtain M second feature maps;

[0150] Sorting the M second feature maps according to a preset rule;

[0151] Inputting the decoding result corresponding to the N-1th second feature map and the Nth second feature map into the decoder of the formula recognition model for decoding processing, until the Mth second feature map is input into the decoder, and obtaining the formula recognition result corresponding to the formula recognition sample; wherein M and N are positive integers, and N is less than or equal to M;

[0152] The loss value of the formula recognition model is calculated according to the formula recognition result and the target recognition result.

[0153] Optionally, the splitting the first feature map to obtain M second feature maps includes:

[0154] Determining a relative position code corresponding to the first feature map;

[0155] Adding the relative position code to the first feature map to obtain a third feature map;

[0156] The third feature map is split to obtain M second feature maps.

[0157] Optionally, the splitting the first feature map to obtain M second feature maps includes:

[0158] Determining a width value of the first feature map;

[0159] The first feature map is split according to the width value of the first feature map to obtain M second feature maps.

[0160] Optionally, if the value of N is 1, the decoding result corresponding to the N-1th second feature map is a preset value.

[0161] Optionally, the device is further configured to execute, by one or more processors, the one or more programs including instructions for performing the following operations:

[0162] Acquire a target image, wherein the target image contains a formula to be recognized;

[0163] The target image is input into the trained formula recognition model for formula recognition processing to obtain a formula recognition result corresponding to the target image.

[0164] Figure 5 8 is a block diagram of an apparatus 800 for model training according to an exemplary embodiment. For example, the apparatus 800 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.

[0165] Reference Figure 5 , the device 800 may include one or more of the following components: a processing component 802 , a memory 804 , a power component 806 , a multimedia component 808 , an audio component 810 , an input / output (I / O) interface 812 , a sensor component 814 , and a communication component 816 .

[0166] The processing component 802 generally controls the overall operation of the device 800, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 802 may include one or more processors 820 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 802 may include one or more modules to facilitate the interaction between the processing component 802 and other components. For example, the processing component 802 may include a multimedia module to facilitate the interaction between the multimedia component 808 and the processing component 802.

[0167] The memory 804 is configured to store various types of data to support operations on the device 800. Examples of such data include instructions for any application or method operating on the device 800, contact data, phone book data, messages, pictures, videos, etc. The memory 804 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.

[0168] The power supply component 806 provides power to the various components of the device 800. The power supply component 806 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the device 800.

[0169] The multimedia component 808 includes a screen that provides an output interface between the device 800 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 808 includes a front camera and / or a rear camera. When the device 800 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.

[0170] The audio component 810 is configured to output and / or input audio signals. For example, the audio component 810 includes a microphone (MIC), and when the device 800 is in an operating mode, such as a call mode, a recording mode, and a voice information processing mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 804 or sent via the communication component 816. In some embodiments, the audio component 810 also includes a speaker for outputting audio signals.

[0171] I / O interface 812 provides an interface between processing component 802 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: home button, volume button, start button, and lock button.

[0172] The sensor assembly 814 includes one or more sensors for providing various aspects of status assessment for the device 800. For example, the sensor assembly 814 can detect the open / closed state of the device 800, the relative positioning of components, such as the display and keypad of the device 800, the sensor assembly 814 can also detect the position change of the voice processing device 800 or a component of the device 800, the presence or absence of user contact with the device 800, the orientation or acceleration / deceleration of the device 800, and the temperature change of the device 800. The sensor assembly 814 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 814 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 814 may also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.

[0173] The communication component 816 is configured to facilitate wired or wireless communication between the device 800 and other devices. The device 800 can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 816 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 816 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency information processing (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.

[0174] In an exemplary embodiment, the apparatus 800 may be implemented by one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components to perform the above method.

[0175] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 804 including instructions, and the instructions can be executed by the processor 820 of the device 800 to perform the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.

[0176] Figure 6 1 is a schematic diagram of the structure of the server in some embodiments of the present invention. The server 1900 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPU) 1922 (for example, one or more processors) and memory 1932, and one or more storage media 1930 (for example, one or more mass storage devices) storing application programs 1942 or data 1944. Among them, the memory 1932 and the storage medium 1930 can be short-term storage or permanent storage. The program stored in the storage medium 1930 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the server. Furthermore, the central processing unit 1922 can be configured to communicate with the storage medium 1930 and execute a series of instruction operations in the storage medium 1930 on the server 1900.

[0177] The server 1900 may also include one or more power supplies 1926, one or more wired or wireless network interfaces 1950, one or more input and output interfaces 1958, one or more keyboards 1956, and / or, one or more operating systems 1941, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.

[0178] A non-transitory computer-readable storage medium, when the instructions in the storage medium are executed by a processor of a device (server or terminal), enables the device to perform Figure 2 The training method of the formula recognition model is shown.

[0179] A non-temporary computer-readable storage medium, when the instructions in the storage medium are executed by a processor of a device (server or terminal), enables the device to execute a training method for a formula recognition model, the method comprising: obtaining a formula recognition sample and a target recognition result corresponding to the formula recognition sample; iteratively training the formula recognition model based on the formula recognition sample, the formula recognition model comprising an encoder and a decoder; in each round of training, calculating the loss value of the formula recognition model according to the formula recognition result and the target recognition result output by the decoder, and adjusting the model parameters of the formula recognition model according to the loss value; wherein the decoder outputs a formula recognition result based on the current encoding feature of the formula recognition sample and the decoding result of the previous encoding feature; when the joint loss value meets the convergence condition, a trained formula recognition model is obtained.

[0180] Those skilled in the art will readily appreciate other embodiments of the invention after considering the specification and practicing the invention disclosed herein. The present invention is intended to cover any variations, uses or adaptations of the present invention that follow the general principles of the present invention and include common knowledge or customary techniques in the art that are not disclosed in this disclosure. The description and examples are to be considered exemplary only, and the true scope and spirit of the present invention are indicated by the following claims.

[0181] It should be understood that the present invention is not limited to the exact construction that has been described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the present invention is limited only by the appended claims.

[0182] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

[0183] The above is a detailed introduction to a training method for a formula recognition model, a training device for a formula recognition model and a device for model training provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the ideas of the present invention, there will be changes in the specific implementation methods and application scopes. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. A training method for a formula recognition model, characterized in that: The method comprises: Obtaining a formula recognition sample and a target recognition result corresponding to the formula recognition sample; Iteratively training a formula recognition model based on the formula recognition samples, wherein the formula recognition model includes an encoder and a decoder; In each round of training, according to the formula recognition result output by the decoder and the target recognition result, the loss value of the formula recognition model is calculated, and the model parameters of the formula recognition model are adjusted according to the loss value; wherein the decoder outputs the formula recognition result based on the current encoding feature of the formula recognition sample and the decoding result of the previous encoding feature; When the joint loss value meets the convergence condition, the trained formula recognition model is obtained; The encoding feature includes a feature map, and the loss value of the formula recognition model is calculated according to the formula recognition result output by the decoder and the target recognition result, including: Inputting the formula recognition sample into the encoder of the formula recognition model for encoding processing to obtain a first feature map of the formula recognition sample; Splitting the first feature map to obtain M second feature maps; Sorting the M second feature maps according to a preset rule; Inputting the decoding result corresponding to the N-1th second feature map and the Nth second feature map into the decoder of the formula recognition model for decoding processing, until the Mth second feature map is input into the decoder, and obtaining the formula recognition result corresponding to the formula recognition sample; wherein M and N are positive integers, and N is less than or equal to M; The loss value of the formula recognition model is calculated according to the formula recognition result and the target recognition result.

2. The method according to claim 1, characterized in that The splitting process of the first feature map to obtain M second feature maps includes: Determining a relative position code corresponding to the first feature map; Adding the relative position code to the first feature map to obtain a third feature map; The third feature map is split to obtain M second feature maps.

3. The method according to claim 1, characterized in that The splitting process of the first feature map to obtain M second feature maps includes: Determining a width value of the first feature map; The first feature map is split according to the width value of the first feature map to obtain M second feature maps.

4. The method according to claim 1, characterized in that: If the value of N is 1, the decoding result corresponding to the N-1th second feature map is a preset value.

5. The method according to any one of claims 1 to 4, characterized in that: The method further comprises: Acquire a target image, wherein the target image contains a formula to be recognized; The target image is input into the trained formula recognition model for formula recognition processing to obtain a formula recognition result corresponding to the target image.

6. A training device for a formula recognition model, characterized in that: The device comprises: A training data acquisition module, used to acquire formula recognition samples and target recognition results corresponding to the formula recognition samples; An iterative training module, used for iteratively training a formula recognition model based on the formula recognition samples, wherein the formula recognition model includes an encoder and a decoder; A loss value calculation module, used to calculate the loss value of the formula recognition model according to the formula recognition result output by the decoder and the target recognition result in each round of training, and adjust the model parameters of the formula recognition model according to the loss value; wherein the decoder outputs the formula recognition result based on the current encoding feature of the formula recognition sample and the decoding result of the previous encoding feature; A training completion condition determination module is used to obtain a training completion formula recognition model when the joint loss value meets the convergence condition; The encoding feature includes a feature map, and the loss value calculation module includes: An encoding processing submodule, used for inputting the formula recognition sample into the encoder of the formula recognition model for encoding processing to obtain a first feature map of the formula recognition sample; A splitting processing submodule, used for splitting the first feature map to obtain M second feature maps; A feature map sorting submodule, used to sort the M second feature maps according to a preset rule; A decoding processing submodule, used for inputting the decoding result corresponding to the N-1th second feature map and the Nth second feature map into the decoder of the formula recognition model for decoding processing, until the Mth second feature map is input into the decoder, and obtaining the formula recognition result corresponding to the formula recognition sample; wherein M and N are positive integers, and N is less than or equal to M; The loss value calculation submodule is used to calculate the loss value of the formula recognition model according to the formula recognition result and the target recognition result.

7. The device according to claim 6, characterized in that The splitting processing submodule includes: A relative position code determining unit, used to determine a relative position code corresponding to the first feature map; A relative position code adding unit, used for adding the relative position code to the first feature map to obtain a third feature map; The first splitting processing unit is used to split the third feature map to obtain M second feature maps.

8. The device according to claim 6, characterized in that The splitting processing submodule includes: A width value determining unit, used to determine a width value of the first feature map; The second splitting processing unit is used to split the first feature map according to the width value of the first feature map to obtain M second feature maps.

9. The device according to claim 6, characterized in that If the value of N is 1, the decoding result corresponding to the N-1th second feature map is a preset value.

10. The device according to any one of claims 6 to 9, characterized in that: The device also includes: A target image acquisition module, used to acquire a target image, wherein the target image contains a formula to be identified; The formula recognition processing module is used to input the target image into the trained formula recognition model for formula recognition processing to obtain the formula recognition result corresponding to the target image.

11. A device for model training, characterized in that: The device includes a memory and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by one or more processors. The one or more programs include instructions for executing the training method of the formula recognition model as described in any one of claims 1 to 5.

12. A machine-readable medium having instructions stored thereon, which, when executed by one or more processors, causes a device to execute the method for training a formula recognition model as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Mathematical formula automatic identification method and device, and model training method and device

    CN110705459A

  • Formula identification method and device

    CN111046751A

  • Image character recognition method and device and electronic equipment

    CN112699882A

  • Formula identification method and device and device for formula identification

    CN113408417A

  • Systems and methods for end-to-end handwritten text recognition using neural networks

    US20200026951A1