Improved mathematical formula identification method based on Res2Net model
By adopting the feature extraction method of vertical and horizontal pooling in the Res2Net model, combined with the LSTM decoder and global attention mechanism, the problem of vertical and horizontal feature extraction in mathematical formula recognition is solved, and the recognition accuracy and Generalization ability.
Patent Information
- Application Number
- CN202411148991.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-21
- Publication Date
- 2024-11-01
AI Technical Summary
The existing Res2Net model is difficult to effectively capture and represent the vertical and horizontal features of mathematical formulas in mathematical formula recognition, resulting in increased recognition difficulty, and conventional attention mechanisms may have problems of excessive attention or lack of attention, affecting the accuracy of recognition.
By replacing the maximum pooling operation in the Res2Net model, features are extracted using vertical and horizontal pooling addition, and combined with the LSTM decoder and the global attention mechanism, an overlay mechanism is introduced to adjust the attention position to form the VHP-Res2Net model, and enhance the Feature representation and decoding performance.
Effectively extracting multi-scale features of mathematical formulas improves the ability to identify and analyze complex formulas, alleviates the problems of excessive attention or lack of attention, and improves the accuracy and generalization ability of the model.
Smart Images

Figure CN118887680A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of formula recognition, and in particular to a mathematical formula recognition method based on an improved Res2Net model. Background Art
[0002] Mathematical formula recognition technology is a key technology in the field of electronic transcription of paper documents. Its significance and application value cannot be ignored. Since mathematical formulas usually contain complex structures and symbols, such as superscripts and subscripts, fraction lines, square roots, and combinations of various mathematical symbols, mathematical formulas are difficult to enter directly into electronic devices. Especially when it comes to formulas in handwritten or printed documents, traditional text input methods and optical character recognition technology are often difficult to accurately recognize and process.
[0003] Mathematical formula recognition research is not only of great value in the academic and educational fields, but also provides valuable experience and technical accumulation for the advancement of optical character recognition technology in other fields. The challenges faced by handwriting recognition technology include handwriting diversity, individual differences in writing styles, etc. The solution to these problems is of guiding significance for improving the accuracy and robustness of optical character recognition technology, and also promotes the technological progress of the entire optical character recognition field.
[0004] Traditional mathematical formula recognition usually includes three main steps: character segmentation, character recognition, and structural reorganization. First, the character segmentation stage aims to decompose complex mathematical expressions into individual characters to provide input for the subsequent recognition process. Secondly, the character recognition stage recognizes each segmented character and tries to map it to the corresponding mathematical symbol or character. Finally, the recognized characters will be reassembled into a complete mathematical formula to complete the entire mathematical formula recognition process.
[0005] The LaTeX sequence of mathematical formulas is usually much longer than the text in the image description task. This difference mainly stems from the complexity and flexibility of mathematical formulas. Compared with objects described in natural language, mathematical formulas usually contain more symbols, operators, and structures. Therefore, in order to accurately represent mathematical formulas, a longer sequence length is required to capture its rich information and structure, which is a significant feature compared to the image description task. Conventional encoder-decoder frameworks usually have difficulty dealing with long sequence problems, and attention mechanisms can deal with this situation well, because the attention mechanism allows the model to pay attention to what should be paid attention to when decoding. Although the attention mechanism can alleviate the problems caused by long sequences to the encoder-decoder model to a certain extent, the conventional attention mechanism may have problems of over-attention or lack of attention, that is, the model repeatedly pays attention to a certain feature in the decoding stage, causing the model to make incorrect decoding outputs.
[0006] Mathematical formula recognition models based on deep learning usually adopt an encoder-decoder framework. In this framework, the model uses a convolutional neural network to extract features from mathematical formula images and convert them into intermediate vectors of fixed dimensions. These intermediate vectors are passed to the decoder, which decodes the intermediate vectors into LaTeX sequences, which are the final mathematical formula representations. This encoder-decoder framework can effectively handle mathematical formula recognition tasks, allowing the model to complete the conversion from mathematical formula images to LaTeX sequences end-to-end. The complex structure, diverse symbol types and different lengths of mathematical formulas, and the accuracy of feature extraction are likely to determine the effect of the final mathematical formula recognition model. Therefore, the design of the encoder used to extract features is the focus of the mathematical formula recognition task. Currently, commonly used image feature extraction networks usually use convolutional neural networks and their variants, including AlexNet, VGGNet, DenseNet, ResNet, etc.
[0007] Although there may be some differences between different recognition methods, the challenges generally faced in the process of mathematical formula recognition mainly stem from the diversity and size of mathematical symbols, as well as the relatively complex and flexible hierarchical structure of mathematical formulas. Mathematical symbols may have different shapes, sizes and styles, which increases the difficulty of recognition. In addition, the hierarchical structure of mathematical formulas is usually more complex, containing multiple nested sub-expressions and operators. At the same time, the composition structure of the mathematical formula itself not only includes left and right structures, but also upper and lower structures such as exponential subscripts and inner and outer nested enclosing structures such as square roots. The composition form of a mathematical expression is very flexible, so how to pay attention to and correctly recognize this two-dimensional structure of mathematical formulas is also a difficult problem. Therefore, it is necessary to accurately capture and represent its structure. Among them, mathematical formula recognition technology also has the following challenges: First, the diversity and complexity of mathematical symbols and the flexibility of the hierarchical structure lead to great difficulty in recognition, so how to accurately capture and represent its structure is an urgent problem to be solved; second, the design of encoders used to extract features is an important part of the mathematical formula recognition task, and how to improve encoders is an important research topic at present and in the future.
[0008] As we all know, ResNet, also known as deep residual network, is one of the most important methods currently used for image feature extraction networks. Its method is proposed to solve the problem of network degradation, and it can also alleviate the problems of overfitting and gradient disappearance or explosion, which has a profound impact on the design of subsequent deep neural networks. Whether it is a convolutional network or a fully connected network, almost all networks now use it, because only in this way can the network be built deeper, so it has been widely used in various fields. Res2Net is a variant of ResNet. By improving the residual module in ResNet and adding smaller residual connections, the receptive field of each layer of residual blocks is expanded. Under the premise of almost no change in the amount of calculation, the ability of the network to extract multi-scale features is improved. The Res2Net structure effectively extracts global and local features in the image through its unique residual connection method and multi-scale feature representation, which is very suitable for mathematical formula recognition tasks with multi-scale features. However, mathematical formulas have obvious two-dimensional structural characteristics, namely horizontal and vertical features. However, Res2Net does not consider horizontal and vertical features, so it is not enough to use Res2Net as an encoder in the mathematical formula recognition task to extract features. In summary, how to improve the existing Res2Net model and enhance the mathematical formula recognition capability has become a technical problem that needs to be urgently solved by technicians in this field. Summary of the invention
[0009] The technical problem to be solved by the present invention is to overcome the deficiencies in the prior art and provide a mathematical formula recognition method based on an improved Res2Net model.
[0010] The present invention is achieved through the following technical solutions:
[0011] A mathematical formula recognition method based on an improved Res2Net model includes the following steps:
[0012] S1. Input the mathematical formula image to be recognized;
[0013] S2. extracting feature information in the horizontal and vertical directions of the mathematical formula image based on the Res2Net model, and obtaining a series of feature vectors as an input feature sequence of the decoder;
[0014] S3. Based on LSTM as a decoder, the attention mechanism is used to decode the input feature sequence into a LaTeX sequence, that is, the final mathematical formula representation.
[0015] According to the above technical solution, preferably, in step S1, character segmentation is performed on the mathematical formula image to decompose it into single characters.
[0016] According to the above technical solution, preferably, step S2 includes:
[0017] Performing longitudinal pooling and transverse pooling on the mathematical formula image respectively, and adding them as input of a subsequent residual block;
[0018] The global and local features of the residual block are extracted in the encoder to obtain a series of feature vectors.
[0019] According to the above technical solution, preferably, in step S3, the decoder adopts a 4-layer LSTM stack of two forward layers and two reverse layers as the model architecture of the decoder.
[0020] According to the above technical solution, preferably, step S3 includes:
[0021] Using the attention mechanism, the most relevant information about the currently generated target word is dynamically selected from the input sequence according to the current decoding state, and the weight of the position is calculated;
[0022] The new vector is obtained by combining the feature vector in step S2, input into the decoder for decoding, and outputs a mathematical formula in Latex format.
[0023] According to the above technical solution, preferably, in step S3, after the attention mechanism is introduced, at each decoding time step t, V = {v1, ..., v i}Calculate the relevant attention weights;
[0024] At decoding time step t, the context vector ct is calculated as:
[0025]
[0026] in, represents the feature v at source position i at decoder time step t i For the context vector c t The weight of the contribution, is the attention weight distribution at time t, Defined as:
[0027]
[0028] Among them, h t represents the LSTM hidden state of the decoder at time step t, score(v i ,h t ) is used to measure v i and h t The correlation between
[0029] W a1 , W a1 Respectively represent the corresponding vi and h t Weight.
[0030] According to the above technical solution, preferably, in step S3, an overwriting mechanism is introduced, and the mechanism adjusts the alignment position of the subsequent steps by recording the historical information of the input feature sequence position that has been paid attention to in each decoding step.
[0031] The beneficial effects of the present invention are:
[0032] The present invention is based on the improvement of Res2Net, and replaces the initial maximum pooling operation in Res2Net, that is, vertical pooling and horizontal pooling are performed separately and then multiplied, which can strengthen the vertical and horizontal features in the mathematical formula to a certain extent, thereby improving the model performance, that is, forming the improved model encoder VHP-Res2Net of the present invention, which can effectively extract multi-scale features in mathematical formulas and can effectively identify tiny features in mathematical formulas;
[0033] The decoder layer uses a bidirectional long short-term memory network, which allows the model to use not only historical information but also future information in mathematical formula recognition tasks. In order to further improve the decoding performance, two bidirectional long short-term memory networks are stacked;
[0034] The model of the present invention introduces a global attention mechanism, which allows the model to pay attention to the areas that should be paid attention to when decoding the output, thereby enhancing the performance of the model in dealing with long sequences of mathematical formulas, and proposes a coverage mechanism to suppress the weights of features that have been noticed, thereby alleviating the problem of over-attention or under-attention. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 It is a schematic flow chart of the method of the present invention.
[0036] Figure 2 It is a schematic diagram of the model structure of Res2Net and VHP-Res2Net of the present invention.
[0037] Figure 3 It is a schematic diagram of the double-layer bidirectional LSTM model architecture in the present invention.
[0038] Figure 4 It is a comparison chart of the experimental results of the IM2LATEX-100K test set in the present invention.
[0039] Figure 5 It is a comparison diagram of the recognition effect on CROHME in the present invention. DETAILED DESCRIPTION
[0040] In order to enable those skilled in the art to better understand the technical solution of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and the best embodiment. Based on the embodiments in the invention, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the invention.
[0041] As shown in the figure, the present invention comprises the following steps:
[0042] S1. Input a mathematical formula image to be recognized, and perform character segmentation on the mathematical formula image to decompose it into individual characters.
[0043] S2. Extract feature information in the horizontal and vertical directions from the mathematical formula image based on the Res2Net model, and obtain a series of feature vectors as an input feature sequence of the decoder.
[0044] Specifically, the mathematical formula image is subjected to longitudinal pooling and transverse pooling respectively, and the pooling is added as the input of the subsequent residual block; the global and local features of the residual block are extracted in the encoder to obtain a series of feature vectors.
[0045] This application aims to improve the existing Res2Net model and enhance its mathematical formula recognition capability. The modified model is called VHP-Res2Net, and its structure is as follows: Figure 2 As shown in the figure, the left side is the original Res2Net model structure diagram, and the right side is the improved model VHP-Res2Net structure diagram. In the initial stage, Res2Net uses the maximum pooling method to reduce the dimension of the input information, but the maximum pooling operation can only extract the most obvious features of the local area, and it is difficult to capture the vertical and horizontal features.
[0046] The modified model VHP-Res2Net replaces the maximum pooling operation with longitudinal pooling and transverse pooling respectively, and then adds the two pooling results as the input of the subsequent residual block. This combination can better enhance the representation of feature information in the horizontal and vertical directions in mathematical formulas, and provide more effective feature information for the decoding stage. By combining the results of longitudinal and transverse pooling, the model can more fully capture the feature information in different directions and effectively integrate these feature information, thereby improving the model's decoding accuracy for data with obvious two-dimensional structural features such as mathematical formulas. This improved method can improve the accuracy and generalization ability of the model in the decoding stage. By enhancing the ability of feature representation, the model can better understand the horizontal and vertical relationships in mathematical formulas, thereby improving the recognition and parsing capabilities of complex formulas. Therefore, this improvement to the Res2Net model provides new ideas and methods for solving the problems of multi-scale and horizontal and vertical features in mathematical formula recognition.
[0047] S3. Based on LSTM as a decoder, the attention mechanism is used to decode the input feature sequence into a LaTeX sequence, that is, the final mathematical formula representation.
[0048] The decoder is used to convert the feature sequence into the target sequence. For sequence-to-sequence tasks, a recurrent neural network is a good choice. Therefore, in this example, a variant of the recurrent neural network, LSTM, is used as the decoder, and multiple layers are stacked and combined with an attention mechanism to achieve better performance. For the decoder, consider using a multi-layer network to improve performance. In this example, a 4-layer LSTM stack containing two forward layers and two reverse layers is used as the decoder model architecture, as shown in the figure. Figure 3 shown.
[0049] In the encoder-decoder framework, the role of the encoder part is to convert the input sequence into a unified semantic feature vector, which is designed to capture and compress all the information of the input sequence. However, this design concept has encountered a key challenge in practice: the vector length becomes a bottleneck that limits the performance of the model. This problem becomes particularly prominent in complex sequence learning tasks. The reason is that it is extremely difficult to encode input sequences of various lengths and complexities into a fixed-length vector and retain all necessary information. For long sequences, the structural effectiveness of this method will be significantly reduced because it is difficult for a fixed-length vector to contain enough information to reflect the complexity and details of the entire sequence.
[0050] The introduction of the attention mechanism provides an effective solution to the above problems. This mechanism allows the model to selectively focus on specific parts of the input sequence during the decoding stage. Specifically, the attention mechanism can dynamically select the most relevant information from the input sequence to the currently generated target word based on the current decoding state. This means that instead of relying on a single, fixed-length feature vector for decoding at all time steps, the decoder can utilize the entire input sequence and focus on the most relevant parts as needed. This dynamic, content-related selection mechanism ensures the comprehensive retention of source sequence information and strengthens the model's utilization of key features, greatly improving the accuracy and quality of the decoded output. When processing long sequence inputs, the attention mechanism alleviates the problem of information loss caused by sequence length by allowing the model to "look back" at any part of the input sequence. Therefore, the attention mechanism not only enhances the model's ability to handle long-distance dependencies, but also improves the overall sequence-to-sequence learning performance. After the introduction of the attention mechanism, at each decoding time step t, V = {v1,...,v i} Calculate the relevant attention weights. This patent uses a global attention mechanism, that is, each decoding step considers the features of all input positions at the same time, and the weights of different positions are different. At the decoding time step t, the context vector c t The calculation formula is as follows:
[0051]
[0052] in, represents the feature v at source position i at decoder time step t i For the context vector c t The weight of the contribution, is the attention weight distribution at time t, Defined as:
[0053]
[0054] Among them, h t represents the LSTM hidden state of the decoder at time step t, score(v i ,h t ) is used to measure v i and h t The correlation between
[0055] W a1 , W a1 Respectively represent the corresponding v i and h t Weight.
[0056] In order to overcome the problem of ignoring historical information that may be caused by the global attention mechanism, an overlay mechanism is also introduced in this example. The overlay mechanism adjusts the alignment position of the subsequent steps by recording the historical information of the input sequence positions that have been paid attention to during each decoding step. The purpose of this is to reduce the possibility of repeated alignment and increase the alignment opportunities for positions that have not been fully paid attention to. This adjustment of the overlay mechanism allows the model to dynamically adjust the attention to each source sequence position based on the historical alignment information of each position and the current context requirements, thereby improving translation efficiency while maintaining translation quality.
[0057] The coverage mechanism proposed in this example is defined as follows:
[0058] V G =V*G(z t )
[0059] G(z t )=1-tanh(W z z t )
[0060]
[0061] Among them, V is the original feature sequence, V G is the calculated feature, G(z t ) represents the covering function at time t, where z t is the coverage vector at time t, representing the part of the formula image that has been recognized. At the initial time, z 0 A vector with all values 0 indicates that there is no part of the image that has been focused on. represents the feature v at source position i at decoder time step t i For the context vector c t The weight of the contribution, is the attention weight distribution at time t.
[0062] It can be seen that when the coverage function can suppress the part of V that has been paid attention to, the attention weight at this time It becomes the following form:
[0063]
[0064] On this basis, a complete attention-based encoder-decoder formula recognition model can be constructed. Figure 1 As shown in Figure 1, the formula recognition model completes the task of converting the input mathematical formula image into the output LaTeX expression.
[0065] In addition, in order to verify the technical effect of the mathematical formula recognition model proposed in this application, Figure 4 The experimental results of the model disclosed in this application are compared with the model based on the encoder-decoder architecture in the prior art on the IM2LATEX-100K test set. The compared models include the coarse-grained to fine-grained attention mechanism model (CFA) of Y. Deng et al., the dual attention mechanism model (DA) of J. Zhang et al., the joint channel attention mechanism model (DJA) of J. Wang et al., the multi-scale attention mechanism model (DMSA) of W. Zhang et al., the position encoding enhancement model (PEE) of Z. Wang et al., and the visual attention mechanism model (VA) of M. Zhou et al.
[0066] Depend on Figure 4It can be seen that the model proposed in this application has a good performance in printed formula recognition. Although the BLEU-4 score of the model is 0.89% lower than the optimal model in the table, the complete match score is 2.28% higher than the optimal model. Considering that there may be multiple reasonable expressions of mathematical formulas themselves, this diversity makes the complete match score relatively high, but there will be deviations in the BLEU-4 score. Therefore, the higher complete match score of this application and the slightly lower BLEU-4 score can be considered that the model disclosed in this application has a better recognition effect.
[0067] Figure 5 The experimental results of the model of this application are compared with those of the existing models based on the encoder-decoder architecture on the CROHME 2014 test set. The models compared with the model of this application include the model of Zhang et al. that combines the full coverage attention mechanism, in which the encoder uses VGGNet and the decoder uses a recurrent neural network, which is referred to as WAP; the model of J. Zhang et al. that uses DenseNet as the encoder and designs a multi-scale feature extraction model, which is referred to as DMSA; the model of J. Wu et al. that uses a mapping input method from printed text to handwritten images in order to recognize more handwriting styles, and uses an adversarial learning model, which is referred to as PAL; the model of J. Wu, F. Yin et al. that replaces VGGNet with Den seNet is used as an encoder and a bidirectional recurrent neural network is used to obtain historical and future information, which is called PAL-V2 here; the model of A.D.Le et al. uses the L2 loss function to minimize the distance between printed image features and handwritten image features to better recognize handwritten formulas of different styles, which is called DLA here; the model of S. Zhong et al. introduces a tree-structured attention mechanism, which is called TSD here; B. Li et al. combine the symbol counting module with the attention mechanism to improve the effect of the attention mechanism in the model recognition process, which is called CAN here; the model of H. Cheng et al. combines online handwritten formula features, which is called OFAN here.
[0068] Depend on Figure 5 It can be seen that the models disclosed in this application have good performance in the three evaluation indicators. Since the OFAN model combines the trajectory characteristics of online formula data, while this application only uses the offline formula data characteristics, the accuracy of the model of this application is not as high as that of the OFAN model. However, the model of this application is 2.39% higher than the suboptimal model in the table, and the accuracy is improved when the number of tolerated errors is less than or equal to 1 and less than or equal to 2, which proves the effectiveness of the model proposed in this application for handwritten mathematical formula recognition.
[0069] The present invention is based on the improvement of Res2Net, and replaces the initial maximum pooling operation in Res2Net, that is, first perform longitudinal pooling and transverse pooling respectively and then multiply them, so that the longitudinal and transverse features in the mathematical formula can be strengthened to a certain extent, thereby improving the model performance, that is, forming the improved model encoder VHP-Res2Net of the present invention, which can effectively extract the multi-scale features in the mathematical formula and can effectively identify the tiny features in the mathematical formula. At the same time, the decoder layer of the present invention uses a bidirectional long short-term memory network, which can enable the model to not only use historical information in the mathematical formula recognition task, but also use future information. And in order to further improve the decoding performance, two bidirectional long short-term memory networks are stacked. In addition, a global attention mechanism is introduced in the model of the present invention, so that the model can pay attention to the places that should be paid attention to when decoding the output, and the performance of the model in dealing with long sequence mathematical formulas is strengthened, and a coverage mechanism is proposed to suppress the weights of the features that have been noticed, thereby alleviating the problem of excessive attention or lack of attention.
[0070] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A mathematical formula recognition method based on the improved Res2Net model, characterized in that: The steps include: S1. Input the mathematical formula image to be recognized; S2. extracting feature information in the horizontal and vertical directions of the mathematical formula image based on the Res2Net model, and obtaining a series of feature vectors as an input feature sequence of the decoder; S3. Based on LSTM as a decoder, the attention mechanism is used to decode the input feature sequence into a LaTeX sequence, that is, the final mathematical formula representation.
2. According to claim 1, a mathematical formula recognition method based on the improved Res2Net model is characterized in that: In step S1, character segmentation is performed on the mathematical formula image to decompose it into individual characters.
3. According to claim 1, a mathematical formula recognition method based on the improved Res2Net model is characterized in that: Step S2 includes: Performing longitudinal pooling and transverse pooling on the mathematical formula image respectively, and adding them as input of a subsequent residual block; The global and local features of the residual block are extracted in the encoder to obtain a series of feature vectors.
4. According to claim 3, a mathematical formula recognition method based on the improved Res2Net model is characterized in that: In step S3, the decoder adopts a 4-layer LSTM stack of two forward layers and two reverse layers as the model architecture of the decoder.
5. According to claim 3 or 4, a mathematical formula recognition method based on the improved Res2Net model is characterized in that: Step S3 includes: Using the attention mechanism, the most relevant information about the currently generated target word is dynamically selected from the input sequence according to the current decoding state, and the weight of the position is calculated; The new vector is obtained by combining the feature vector in step S2, input into the decoder for decoding, and outputs a mathematical formula in Latex format.
6. According to claim 5, a mathematical formula recognition method based on the improved Res2Net model is characterized in that: In step S3, after the attention mechanism is introduced, at each decoding time step t, the source feature sequence V = {v1, ..., v i }Calculate the relevant attention weights; At decoding time step t, the context vector ct is calculated as: in, represents the feature v at source position i at decoder time step t i For the context vector c t The weight of the contribution, is the attention weight distribution at time t, Defined as: Among them, h t represents the LSTM hidden state of the decoder at time step t. score(v i ,h t ) is used to measure v i and h t The correlation between W a1 , W a1 Respectively represent the corresponding v i and h t Weight.
7. According to claim 6, a mathematical formula recognition method based on the improved Res2Net model is characterized in that: In step S3, an overwriting mechanism is introduced, which adjusts the alignment position of subsequent steps by recording the historical information of the input feature sequence position that has been paid attention to in each decoding step.
