Handwritten mathematical expression recognition method based on position forest converter

Through the position forest transformer and implicit attention correction module, the position relationship between symbols in handwritten mathematical expressions is explicitly analyzed, which solves the error problem of complex expression recognition and relationship learning between symbols in the existing technology, and achieves high accuracy. Handwritten mathematical expression recognition.

CN118587720AActive Publication Date: 2024-09-03SHANGHAI JIAOTONG UNIV
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202410737906.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-07
Publication Date
2024-09-03
Estimated Expiration
2044-06-07

AI Technical Summary

Technical Problem

Existing handwritten mathematical expression recognition technology is difficult to accurately handle complex and nested mathematical expressions, and traditional methods have error accumulation problems in learning relationships between symbols.

Method used

Using a method based on the position forest transformer, by constructing a position forest structure and an implicit attention correction module, the relative position relationship and nesting level between symbols are explicitly analyzed, the symbol-level feature representation learning is optimized, and corrected in the decoder architecture Interference of structural symbols.

Benefits of technology

Significantly improves the model's image-to-sequence recognition capabilities, enhances position awareness in complex and nested expressions, and improves recognition accuracy and attention precision.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118587720A
    Figure CN118587720A
Patent Text Reader

Abstract

A handwritten mathematical expression recognition method based on a position forest converter comprises the following steps: constructing a position forest structure, and encoding a relative position relationship between symbols in a LaTeX expression by using the position forest structure so as to predict a LaTeX sequence of a mathematical expression; an implicit attention correction module is constructed, interference of structural symbols is corrected in a sequence-based decoder architecture, and attention of handwritten mathematical expression image recognition is captured; training based on the framework; and inputting a to-be-identified image into the trained position forest converter model to obtain a Latex expression of a mathematical formula. According to the method, additional data annotation is not needed, the position and hierarchical relation of the symbols are accurately described by analyzing the position identifier of each symbol in the position forest, challenges brought by complex structural relations and diversified handwriting styles are overcome to a certain extent, the recognition accuracy of the handwritten mathematical formula is improved, and the recognition efficiency is improved. And no extra delay or calculation cost is generated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of handwritten mathematical expression recognition, and in particular to a handwritten mathematical expression recognition method based on a Position Forest Transformer (PosFormer for short). Background Art

[0002] Handwritten mathematical expression recognition (HMER) is a technology that accurately converts handwritten mathematical expression images into LaTeX sequences. It is widely used in human-computer interaction scenarios such as online education, manuscript digitization, and automatic grading. However, this task faces two major challenges: first, the complex relationship between symbols makes it difficult for the model to generate structured symbols constrained by LaTeX rules; second, the diversity of handwritten input, including changes in scale and style.

[0003] Traditional methods usually involve two stages: recognizing individual symbols and making subsequent corrections based on grammatical rules. However, these methods are often not accurate enough. With the development of deep learning technology, the main research direction has shifted to tree-based methods and sequence-based methods. Tree-based methods regard each mathematical expression as a tree structure, using a tree decoder to model symbols and their hierarchical relationships, which is suitable for online datasets and complex offline HMER tasks. Such methods show low accuracy and generalization ability due to the lack of diversity of tree structures among expressions. In contrast, sequence-based methods model HMER as an end-to-end image-to-sequence task, using an attention-based encoder-decoder architecture to autoregressively predict each symbol, such as GRU with a covered attention mechanism and Transformer structure with bidirectional decoding, to improve the error accumulation problem in the recognition process. However, these methods only implicitly learn the structural relationship between symbols and are insufficient when dealing with complex and nested mathematical expressions. Summary of the invention

[0004] To overcome the shortcomings of the above-mentioned prior art, the present invention proposes a handwritten mathematical expression recognition method based on a position forest transformer, which explicitly simulates the structural relationship between symbols in mathematical expressions to achieve the recognition of complex expressions. The LaTeX mathematical expression sequence is encoded into a position forest structure, in which each symbol is assigned a position identifier to indicate its relative spatial position in a two-dimensional image. Using this position forest encoding, the nesting level and relative position of each symbol in the forest are parsed to assist in the learning of position-aware symbol-level feature representation in complex and nested mathematical expressions.

[0005] The technical solution of the present invention is as follows:

[0006] A method for recognizing handwritten mathematical expressions based on a position forest transformer is characterized by comprising:

[0007] S1. Construct a position forest structure and use it to encode the relative position relationship between symbols in LaTeX expressions, so as to predict the LaTeX sequence of mathematical expressions;

[0008] S2. Construct an implicit attention correction module to correct the interference of structural symbols in the sequence-based decoder architecture and capture the attention of handwritten mathematical expression image recognition;

[0009] S3. By optimizing both expression recognition and location recognition tasks, we explicitly implement location-aware symbolic feature representation learning and train based on this framework.

[0010] S4. Input the image to be recognized into the trained position forest transformer model to obtain the Latex expression of the mathematical formula.

[0011] Furthermore, a position forest structure is designed to analyze the relative position relationship between symbols, specifically:

[0012] -According to the grammatical rules of LaTeX, the expression is divided into four substructures: superscript-subscript structure, fraction structure, root structure and special operator structure. These substructures are encoded from left to right. Each substructure is encoded into a tree according to the relative position relationship between symbols, with the main body as the root node, the upper part as the left node, and the lower part as the right node. These encoded trees are combined into a position forest structure in a sequence or nested form. The kth symbol in the sequence will eventually get the following identifier:

[0013]

[0014] Where “M”, “L” and “R” represent the root node, left node and right node respectively.

[0015] -The image visual features extracted by the encoder and the above identifiers are fed to the decoder, which is mainly composed of a multi-head attention module, an implicit attention correction module, and a feedforward network. During training, the model parses the nested layers p(y n ) and the relative position relationship between symbols p(y r ), as an auxiliary supervision task for symbol recognition. Combined with the symbol prediction result p(y c ), the final loss function is:

[0016]

[0017]

[0018] Where λ1 and λ2 represent the loss weights, Represents the t-th character and the true label.

[0019] and They represent the prediction results of the Latex sequence, the number of nesting levels and the relative position relationship between symbols for the t-th character, respectively, and log(·) represents the logarithmic function.

[0020] -During inference, the model does not predict the number of nesting levels and the relative position relationship between symbols, so this method has no additional latency or computational cost.

[0021] Furthermore, an implicit attention correction module is proposed to correct the interference of structural symbols in the sequence-based decoder architecture and capture the attention of handwritten mathematical expression image recognition. Specifically:

[0022] -The symbols in the Latex sequence are divided into entity symbols and structure symbols according to whether they have entities in the image.

[0023] -When decoding, the attention weights corresponding to all entity symbols before the current step are subtracted from the attention of the current step for refinement, so as to alleviate the problem of over-parsing and under-parsing.

[0024] Compared with the prior art, the present invention has the following beneficial effects:

[0025] 1) A sequence method combined with position understanding, PosFormer, is used for handwritten mathematical expression recognition. It models mathematical expressions as a position forest structure and explicitly parses the relative position relationship between symbols, significantly improving the model's end-to-end image-to-sequence recognition capability.

[0026] 2) The location recognition task is optimized to assist HMER, enabling it to learn location-aware symbolic-level feature representations in complex and nested mathematical expressions.

[0027] 3) Implicit attention correction module, which improves the accuracy of attention when parsing images. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] Figure 1 It is the overall structure of the position forest transformer in the present invention, which optimizes the two complementary tasks of expression recognition and position recognition.

[0029] Figure 2 It is the process of position forest encoding, which transforms sequences into substructures, then forms trees, and finally forms position forests. It is the key to achieving position-aware recognition in complex mathematical expressions. DETAILED DESCRIPTION

[0030] The present invention is described in detail below in conjunction with specific drawings and embodiments. The following embodiments will help those skilled in the art to further understand the present invention, but are not intended to limit the present invention in any form. It should be noted that, for those of ordinary skill in the art, several adjustments and improvements can also be made without departing from the concept of the present invention. These all belong to the protection scope of the present invention.

[0031] See also Figure 1 , Figure 1 : is a flow chart of a method for recognizing handwritten mathematical expressions based on a position forest transformer of the present invention, as shown in the figure, comprising:

[0032] S1. Construct a position forest structure to analyze the relative position relationship between symbols, specifically:

[0033] According to the grammatical rules of LaTeX, S101 divides the expression into four substructures: superscript-subscript structure, fraction structure, root structure, and special operator structure. These substructures are encoded from left to right. Each substructure is encoded into a tree according to the relative position relationship between symbols, with the main body as the root node, the upper part as the left node, and the lower part as the right node. These encoded trees are combined into a position forest structure in a sequence or nested form. The kth symbol in the sequence will eventually get the following identifier:

[0034]

[0035] Where “M”, “L” and “R” represent the root node, left node and right node respectively.

[0036] S102 feeds the image visual features extracted by the encoder and the above identifiers to the decoder, which is mainly composed of a multi-head attention module, an implicit attention correction module and a feedforward network. During training, the model parses the number of nested layers p(y n ) and the relative position relationship between symbols p(y r ), as an auxiliary supervision task for symbol recognition. Combined with the symbol prediction result p(y c ), the final loss function is:

[0037]

[0038] Where λ1 and λ2 represent the loss weights, represents the tth character and the true label, and They represent the prediction results of the Latex sequence, the number of nesting levels and the relative position relationship between symbols for the t-th character, respectively. Represents a logarithmic function.

[0039] During inference, the model does not predict the number of nesting levels and the relative position relationships between symbols, so this method has no additional latency or computational cost.

[0040] S2. Construct an implicit attention correction module to correct the interference of structural symbols in the sequence-based decoder architecture and accurately capture the attention of handwritten mathematical expression image recognition. Specifically:

[0041] S201. The symbols in the Latex sequence are divided into entity symbols and structure symbols according to whether they have entities in the image.

[0042] During decoding at S202, the attention weights corresponding to all entity symbols before the current step are subtracted from the attention of the current step for refinement, so as to alleviate the attention problems of over-parsing and under-parsing.

[0043] S3. By optimizing both expression recognition and location recognition tasks, we explicitly implement location-aware symbolic feature representation learning and train based on this framework.

[0044] S4. Input the image to be recognized into the trained position forest transformer model to obtain the Latex expression of the mathematical formula.

[0045] This embodiment is based on the previous Transformer sequence decoding framework, introduces the position forest module for joint optimization in the training phase, and adds the implicit attention correction module in both the training and reasoning phases. Specifically, the previous framework inputs the image into the encoder to obtain the feature map, and then inputs the feature map into the Transformer decoder to obtain the predicted Latex sequence result, and finally calculates the cross entropy loss with the real label, and back-propagates the gradient to update the parameters of the encoder and decoder.

[0046] The position forest module explicitly parses the relative position relationship between symbols, significantly improving the model's end-to-end image-to-sequence recognition capability. Specifically, we divide the formula sequence label into four substructures: superscript-subscript structure, fraction structure, square root structure, and special operator structure according to the grammatical rules of LaTeX. These substructures are encoded from left to right. Each substructure is encoded into a tree according to the relative position relationship between symbols, with the main body as the root node, the upper part as the left node, and the lower part as the right node. These encoded trees are combined into a position forest structure in a sequence or nested form. The feature map is input into the position forest module for decoding to predict the number of nested layers of symbols and the relative position relationship between symbols. The real label generated by the previous position forest identifier is used. The two subtasks calculate the cross entropy loss respectively, and the back-propagation gradient updates the parameters of the encoder and decoder to assist in the position-aware symbol-level feature representation learning in complex and nested mathematical expressions.

[0047] The implicit attention correction module corrects the interference of structure symbols in the sequence-based decoder architecture and captures the attention of handwritten mathematical expression image recognition. In HMER, there are more than a hundred LaTeX symbols in total, which are generally divided into two categories: entity symbols with corresponding entities in the image, and structure symbols without corresponding entities in the image, which are used to describe the position and hierarchical relationship between entity symbols. The coverage attention mechanism in the baseline model CoMER subtracts the attention terms of all previous symbols to perform attention refinement. However, after the subtraction operation of the structure symbols without entities, this mechanism leads to inaccurate fine-tuning of attention in the subsequent decoding steps that rely on past alignment information. To this end, zero attention is introduced as a refinement term. Specifically, when decoding an entity symbol, the attention weights associated with the previous structure symbol are reset to zero. That is, when we encourage the model to generate accurate attention for decoding entity symbols, we only need to subtract these attention weights from the parsed entity symbols because there are only entity symbols on the mathematical expression image.

[0048] Effect embodiment:

[0049] The method was evaluated on the mainstream single-line handwritten mathematical expression datasets CROHME2014 / 2016 / 2019, the multi-line handwritten mathematical expression dataset M2E, and our own multi-layer nested handwritten mathematical expression dataset MNE. CROHME2014 / 2016 / 2019 contains a total of 8836 training images, 986, 1147, and 1199 test images respectively; M2E contains 79979 training images, 9992 validation images, and 9985 test images; MNE's N1, N2, and N3 categories contain 1875, 304, and 214 images respectively.

[0050]

[0051] Table 1: Test results on CROHME

[0052]

[0053] Table 2: M 2 Test results on E

[0054]

[0055] Table 3: Test results on MNE

[0056] The evaluation shows that the proposed method has achieved good results on the three datasets. As shown in Tables 1, 2, and 3, without data enhancement, the results on CROHME2014 / 2016 / 2019 are improved by 3.25% / 4.79% / 5.88% respectively, and on M 2 The accuracy of handwritten mathematical expression recognition is improved by 1.83% on E and 0.96% / 2.31% / 16.36% on MNE N1 / N2 / N3 respectively. The present invention effectively improves the accuracy of handwritten mathematical expression recognition by designing a position forest structure and an implicit attention correction module. It can not only accurately capture the relative position relationship between symbols, but also correct the interference of structural symbols during the decoding process, thus achieving efficient and accurate handwritten mathematical expression recognition.

Claims

1. A method for recognizing handwritten mathematical expressions based on position forest transformer, characterized in that: include: S1. Construct a position forest structure and use it to encode the relative position relationship between symbols in LaTeX expressions, so as to predict the LaTeX sequence of mathematical expressions; S2. Construct an implicit attention correction module to correct the interference of structural symbols in the sequence-based decoder architecture and capture the attention of handwritten mathematical expression image recognition; S3. By optimizing both expression recognition and location recognition tasks, we explicitly implement location-aware symbolic feature representation learning and train based on this framework. S4. Input the image to be recognized into the trained position forest transformer model to obtain the Latex expression of the mathematical formula.

2. The method for recognizing handwritten mathematical expressions based on position forest transformer according to claim 1, characterized in that: The step S1 constructs a position forest structure and uses the position forest structure to encode the relative position relationship between symbols in the LaTeX expression, thereby predicting the LaTeX sequence of the mathematical expression, which specifically includes: S101. Design location forest structure - Substructure: Divide LaTeX expressions into superscript-subscript structure, fraction structure, root structure and special operator structure; - Tree coding: Encode these substructures in order from left to right; each substructure is encoded into a tree according to the relative position relationship between symbols, where the main body is represented by M as the root node, the upper part is represented by L as the left node, and the lower part is represented by R as the right node; - All these tree structures are combined into a position forest structure in a sequence or nested form to capture the relative position relationship between symbols in LaTeX expressions; Each symbol in a LaTeX sequence gets an identifier determined by its position in the position forest, i.e., the identifier I for the kth symbol in the sequence is k It is composed of multiple "M", "L" and "R" combinations, reflecting the position of the kth symbol in the position forest structure. The formula is as follows: Where q refers to the identity of each symbol in the identifier set; S102. Encoding and decoding - The encoder is responsible for extracting visual features from the image, which are image representations of mathematical expressions; -The decoder receives the visual features and the identifier from the encoder and outputs the prediction results of the LaTeX sequence of the mathematical expression, the number of nesting levels and the relative position relationship between symbols; -During the training process, the model uses two recognition heads to analyze the number of nested layers of mathematical expressions and the relative position relationship between symbols; -The loss function combines the losses of symbol prediction results, nested layer prediction results, and relative position relationship prediction results between symbols, weights them by loss weights, and finally trains the model by optimizing the loss function.

3. The method for recognizing handwritten mathematical expressions based on position forest transformer according to claim 2, characterized in that: The loss function is expressed as: Where λ1 and λ2 represent the loss weights, represents the tth character and the true label, and They represent the prediction results of the Latex sequence, the number of nesting levels and the relative position relationship between symbols for the t-th character, respectively, and log(·) represents the logarithmic function.

4. The method for recognizing handwritten mathematical expressions based on position forest transformer according to claim 1, characterized in that: The step S2. constructs an implicit attention correction module to correct the interference of structural symbols in the sequence-based decoder architecture and capture the attention of handwritten mathematical expression image recognition, specifically including: S201 symbol classification: - Symbols with clear visual expressions, specific shapes and positions in the image are regarded as physical symbols; - symbols that make sense in LaTeX representation but have no direct visual counterpart in images of handwritten mathematical expressions as structural symbols; S202 attention mechanism adjustment: -During the decoding process, the attention weight of the current image region is calculated to determine what should be paid attention to next; -In the attention calculation of the current step, subtract the attention weights corresponding to all entity symbols in the previous step.

Citation Information

Patent Citations

  • Handwritten mathematical expression recognition method and device based on deep learning

    CN110766012A

  • Handwritten mathematical formula identification method

    CN117542064A

  • Text input method and device for smart watch

    WO2018036023A1