Mathematical formula processing method and device, computer equipment and readable storage medium
By constructing formula error recognition strategies and start and end character recognition and repair models, the problems of incomplete detection of mathematical formula errors and high false positive rates in the existing technology are solved, and efficient and accurate multi-type error repair is achieved, which is suitable for scientific research papers, online education and AI generated content.
Patent Information
- Application Number
- CN202510948957.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-10
- Publication Date
- 2025-08-08
- Estimated Expiration
- 2045-07-10
AI Technical Summary
The prior art has insufficient context perception ability in mathematical formula error detection and repair, high false alarm rate, and insufficient detection and repair to effectively handle multiple error types.
The pre-constructed formula error recognition strategy and start-and-end character recognition repair model are used, and combined with regular matching and context analysis, non-start-end character and start-and-end character errors in mathematical formulas are identified and repaired. The mixed word participle strategy is used to train the start-and-end character recognition repair model to improve context perception ability.
It significantly expands the coverage of error detection and repair, reduces the false positive rate, improves the accuracy and efficiency of repair, meets real-time requirements, and reduces the workload of manual proofreading.
Smart Images

Figure CN120449867A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of formula editing, and in particular to a mathematical formula processing method, apparatus, computer equipment, and readable storage medium. Background Art
[0002] Mathematical formulas are used in a variety of scenarios, such as academic paper typesetting, online education question banks, and AI content generation. Related technologies primarily rely on rule matching or simple static checking tools to detect and fix errors in mathematical formulas. However, these existing technologies have the following significant shortcomings: (1) There are deficiencies in context awareness, resulting in a high false positive rate. For example, it is difficult to intelligently determine whether the `$` symbol is used correctly based on the context.
[0003] (2) It only focuses on a single error type, and error detection and repair are not comprehensive enough. Summary of the Invention
[0004] In view of this, the present application provides a mathematical formula processing method, apparatus, computer device and readable storage medium.
[0005] In a first aspect, an embodiment of the present application provides a mathematical formula processing method, comprising: Acquire a mathematical formula text, and identify a mathematical formula to be processed in the mathematical formula text; Identify errors in mathematical formulas using pre-built formula error identification strategies; For non-start and end character errors in the mathematical formula to be processed, the non-start and end character errors in the mathematical formula to be processed are repaired by using the target repair rules corresponding to the non-start and end character errors; For the start and end character errors in the mathematical formula to be processed, the start and end character errors in the mathematical formula to be processed are repaired through the pre-built start and end character recognition and repair model.
[0006] The above method according to the embodiment of the present application may also have the following additional technical features: In the above technical solution, optionally, the mathematical formula to be processed is a LaTeX formula; Identify errors in mathematical formulas using pre-built formula error identification strategies, including: By using a formula error recognition strategy, at least one of the formula start and end characters, environment structure, command spelling, bracket pairing, and symbol format of the mathematical formula to be processed is recognized.
[0007] In any of the above technical solutions, optionally, the formula error identification strategy includes at least one of the following: For formula start and end characters, the start and end character recognition and repair model is used to identify mathematical variables and / or operators. In combination with regular expression matching and context analysis strategies, it is determined whether the formula start and end characters of the mathematical formula to be processed are missing or misused. For the environment structure, the location of the environment definition command of the mathematical formula to be processed is identified to determine whether the environment definition command has an unclosed error or a nested error; For command spelling, string matching is performed based on pre-built mathematical formula dependencies to detect whether there are spelling errors in the mathematical formula to be processed; For bracket pairing, a paired symbol matching method is used to analyze whether the bracket symbols of the mathematical formula to be processed are matched in pairs; For symbol formatting, detect whether special symbols are in the mathematical formula to be processed, and whether special symbols have escape symbols, and / or determine formatting rules for the mathematical formula to be processed and subsequent characters based on the mathematical formula dependency, and determine whether the mathematical formula to be processed has formatting errors based on the formatting rules.
[0008] In any of the above technical solutions, optionally, different non-start / end character errors correspond to different repair rules, and the repair rule includes at least one of the following: For the environment structure, if there is an unclosed error in the environment definition command, the environment definition command will be completed; if there is a nesting error in the environment definition command, the position of the environment definition command will be adjusted; For command spelling, if there is a spelling error in the mathematical formula to be processed, the incorrect spelling is corrected through the string similarity algorithm; For bracket pairing, if the bracket symbols of the mathematical formula to be processed are not matched in pairs, the missing bracket symbols are completed or the redundant bracket symbols are deleted; For symbol formatting, if a special symbol is not in the math formula to be processed and has no escape character, an escape character is added. If the math formula to be processed has a format error, a space is added after the math formula to be processed.
[0009] In any of the above technical solutions, optionally, using a pre-built start-and-end character recognition and repair model to repair start-and-end character errors in the mathematical formula to be processed includes: The labeling results of the repair model are repaired through start and end character recognition, and start and end characters are automatically inserted or removed at the target position of the mathematical formula to be processed.
[0010] In any of the above technical solutions, optionally, the method further includes: After automatically inserting start and end characters at the target position of the mathematical formula to be processed, determining whether there is a conflict between the document structure of the mathematical formula to be processed and the mathematical formula text; If there is a conflict, adjust the target position for inserting the start and end characters.
[0011] In any of the above technical solutions, optionally, the method further includes: Construct formula error recognition strategies, repair rules corresponding to different non-start and end character errors, and start and end character recognition and repair models.
[0012] In any of the above technical solutions, optionally, building a start and end character recognition and repair model includes: Obtaining a mathematical formula sample text, performing word segmentation processing on the mathematical formula sample text, and obtaining a plurality of word segments; Based on the formula error recognition strategy, multiple segmentations are identified to obtain positive sample segmentations and negative sample segmentations, and noise is added to the negative sample segmentations; The preset model is trained based on positive sample segmentation and negative sample segmentation with added noise to obtain a start and end symbol recognition and repair model; wherein, the preset model includes a pre-trained language unit, a bidirectional LSTM unit and a CRF unit. The pre-trained language unit is used to extract the contextual features of the segmentation, the bidirectional LSTM unit is used to capture the long-term dependency of the contextual features, and the CRF unit is used to output the label results of the segmentation.
[0013] In any of the above technical solutions, optionally, the method further includes: After the repair is performed, the mathematical formula to be processed is continuously identified through the formula error identification strategy, and the identified start-stop character errors and / or non-start-stop character errors are repaired.
[0014] In a second aspect, an embodiment of the present application provides a mathematical formula processing device, comprising: A formula recognition module is used to obtain mathematical formula text and recognize the mathematical formula to be processed in the mathematical formula text; An error recognition module is used to identify errors in mathematical formulas to be processed using a pre-built formula error recognition strategy; The first repair module is configured to repair the non-start and end character errors in the mathematical formula to be processed by using a target repair rule corresponding to the non-start and end character errors. The second repair module is used to repair the start and end character errors in the mathematical formula to be processed by using a pre-built start and end character recognition and repair model.
[0015] In a third aspect, an embodiment of the present application provides a computer device comprising a processor and a memory, wherein the memory stores programs or instructions that can be run on the processor, and when the programs or instructions are executed by the processor, the steps of the method of the first aspect are implemented.
[0016] In a fourth aspect, an embodiment of the present application provides a readable storage medium, which stores a program or instruction. When the program or instruction is executed by a processor, the steps of the method of the first aspect are implemented.
[0017] The mathematical formula processing method, apparatus, computer equipment and readable storage medium of the embodiments of the present application, through a pre-built formula error recognition strategy, identify multiple types of errors for the mathematical formula to be processed, and implement different repair strategies based on different types of errors. Specifically, for non-start and end character errors in the formula, repairs are performed based on repair rules, and for start and end character errors in the formula, repairs are performed based on start and end character recognition and repair models, which significantly expands the coverage of error detection and repair, makes the repair more targeted, and improves the repair effect. In addition, the start and end character recognition and repair model in the present application has context-awareness capabilities, and can intelligently identify and repair start and end character errors according to the context, reduce the false alarm rate, and improve accuracy. In addition, compared with the problems of slow time consumption and low efficiency of the pure model method in the related art, the present application realizes complete automatic repair by combining models and rules, improves detection and repair efficiency, and meets real-time requirements.
[0018] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings: Figure 1 One of the flow charts of the mathematical formula processing method according to an embodiment of the present application is shown; Figure 2 The second flowchart of the mathematical formula processing method according to the embodiment of the present application is shown; Figure 3 A structural block diagram of a mathematical formula processing device according to an embodiment of the present application is shown; Figure 4 A structural block diagram of a computer device according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0020] The following will be combined with the accompanying drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the embodiments described are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field are within the scope of protection of this application.
[0021] The terms "first," "second," and the like in the specification and claims of this application are used to distinguish similar objects, and are not used to describe a specific order or precedence. It should be understood that the terms used in this manner are interchangeable where appropriate, so that the embodiments of this application can be implemented in an order other than that illustrated or described herein, and that the objects distinguished by "first," "second," and the like are generally of the same type, and do not limit the number of objects; for example, the first object can be one or more. In addition, the term "and / or" in the specification and claims refers to at least one of the connected objects, and the character " / " generally indicates that the objects connected are in an "or" relationship.
[0022] The mathematical formula processing method, apparatus, computer device, and readable storage medium provided in the embodiments of the present application are described in detail below with reference to the accompanying drawings through specific embodiments and their application scenarios. Unless there is a conflict, the following embodiments and features in the embodiments may be combined with each other.
[0023] The present application embodiment provides a mathematical formula processing method, such as Figure 1 As shown, the method includes: Step 101: Acquire mathematical formula text and identify the mathematical formula to be processed in the mathematical formula text.
[0024] In this step, the content wrapped by the start and end characters of the input mathematical formula text is preliminarily identified to obtain the mathematical formula range, that is, the mathematical formula to be processed, and then subsequent error identification and repair are performed on the mathematical formula to be processed. In one embodiment, the mathematical formula to be processed can be a LaTeX formula.
[0025] Step 102 : performing error recognition on the mathematical formula to be processed using a pre-built formula error recognition strategy.
[0026] In this step, a formula error recognition strategy is pre-built for formula error recognition, and the obtained mathematical formula to be processed is used to identify errors. Specifically, one or more of the formula start and end characters, environment structure, command spelling, bracket pairing, and symbol format of the mathematical formula to be processed can be identified.
[0027] In one embodiment of the present application, the formula error identification strategy includes one or more of the following: For formula start and end characters, the start and end character recognition and repair model is used to identify mathematical variables and / or operators. In combination with regular expression matching and context analysis strategies, it is determined whether the formula start and end characters of the mathematical formula to be processed are missing or misused. For the environment structure, the location of the environment definition command of the mathematical formula to be processed is identified to determine whether the environment definition command has an unclosed error or a nested error; For command spelling, string matching is performed based on pre-built mathematical formula dependencies to detect whether there are spelling errors in the mathematical formula to be processed; For bracket pairing, a paired symbol matching method is used to analyze whether the bracket symbols of the mathematical formula to be processed are matched in pairs; For symbol formatting, detect whether special symbols are in the mathematical formula to be processed, and whether special symbols have escape symbols, and / or determine formatting rules for the mathematical formula to be processed and subsequent characters based on the mathematical formula dependency, and determine whether the mathematical formula to be processed has formatting errors based on the formatting rules.
[0028] In this embodiment, a mathematical formula dependency is pre-built, which collects common LaTeX formula representations. Then, for each LaTeX symbol, it is checked whether it has an association relationship with other LaTeX symbols. If so, the other LaTeX symbols with the association relationship are added to the dictionary of the mathematical formula dependency relationship of the LaTeX symbol. Subsequently, the mathematical formula dependency relationship can be used to understand the hierarchy and inclusion relationship between different LaTeX symbols, verify whether the use of symbols is reasonable, whether there are incompatible or incorrect symbol combinations, etc., so as to better check and correct formula errors.
[0029] The formula error recognition strategy includes recognition strategies for multiple formula errors, which can recognize different types of LaTeX errors, as shown in Table 1: Table 1
[0030] The identification strategies corresponding to specific error types include: (1) For formula start and end characters `$`: mathematical variables and / or operators are identified through the start and end character recognition and repair model, and regular matching and context analysis strategies are combined to determine whether the formula start and end characters of the mathematical formula to be processed are missing or misused.
[0031] The start and end character recognition and repair model can be a Named Entity Recognition (NER) model. It uses the NER model to identify mathematical variables and operators, and combines regular expression matching and context analysis strategies to determine whether the formula start and end characters `$` are missing or misused. For example, context analysis is used to identify the content enclosed by `$`. If the content only contains ordinary text or numbers, it is marked as misused. For example, `$2023$` should be `2023` and should not have the formula start and end characters `$`, which is a misuse of the formula start and end characters `$`. For the formula `Let x_i = y^2 + 3`, the formula start and end characters `$` should be present at both ends, which is a missing formula start and end characters `$`.
[0032] In one embodiment, a stack matching method can be used, that is, similar to the method of checking bracket matching, to track the formula start and end characters `$` to ensure that they appear in pairs, and use recursive detection to identify whether the formula start and end characters `$` are missing, so as to avoid compilation failure due to `$` mismatch in the mathematical environment.
[0033] It should be noted that in related technologies, formula errors are located through regular expressions or hard-coded rules, which have a high false positive rate due to a lack of understanding of the context. In the embodiment of the present application, a named entity recognition model is used to identify the mathematical pattern symbol `$` in the input mathematical formula to be processed, and intelligently determine where the mathematical pattern start and end symbols `$` should be located, thereby accurately locating the omitted or misused `$` symbol and reducing the false positive rate.
[0034] (2) For environment structure: Identify the location of the environment definition commands in the mathematical formula to be processed to determine whether there are unclosed errors or nesting errors in the environment definition commands. For example, for environment nesting errors, record the location of `\begin{}` and `\end{}`, detect unclosed or nested errors, and ensure that all environments are correctly matched. For another example, for environment crossing errors, check the LaTeX code structure to ensure that `\begin{}` and `\end{}` are nested in the correct order to prevent environments such as `align` and `equation` from being incorrectly nested or ending prematurely, causing compilation failure.
[0035] (3) For command spelling: perform string matching based on pre-built mathematical formula dependencies and recommend the correct spelling in combination with a similarity algorithm to detect whether there are spelling errors in the mathematical formula to be processed, and avoid errors such as `\summ_{i=1}^{n} i^2` (actually should be `\sum`).
[0036] The similarity algorithm can be the Levenshtein distance algorithm. Levenshtein distance is a string similarity algorithm that calculates the minimum number of single-character edit operations (insertion, deletion, and substitution) required to transform one string into another. The smaller the Levenshtein distance, the more similar the two strings are. Using the Levenshtein distance algorithm, a similarity score is calculated between the string representing the mathematical formula to be processed and the strings in the mathematical formula dependency relationship. A higher similarity score indicates that the spelling is correct.
[0037] (4) For bracket pairing: Use paired symbol matching method and nested matching algorithm to analyze whether the bracket symbols such as `()`, `{}`, `[]` and `\left(...\right)` in the mathematical formula to be processed are matched in pairs to avoid incomplete expressions such as `f(x= \left( a + b \right`.
[0038] (5) Symbol format: Special symbols include `%`, `&`, etc., and errors such as symbol escape, space format, and misuse of special characters are detected. The special symbol list is scanned to detect whether the special symbol is in the mathematical formula to be processed and whether the special symbol has an escape symbol. If the special symbol is not in the mathematical formula to be processed and the special symbol has no escape symbol, it is marked as an error. For example, `10%` is an error, and the correct one should be `10\%`.
[0039] Furthermore, the formatting rules of the mathematical formula to be processed and subsequent characters are determined based on the dependency relationship of the mathematical formula, and whether the mathematical formula to be processed lacks necessary spaces is detected. For example, `\cdotx` is a space error, and the correct one should be `\cdot x`.
[0040] Also, parse the math formula to be processed and check whether `_` or `^` appears outside the math formula to be processed. If so, mark the special character misuse error. For example, `variable_x` is a misuse error, and the correct one should be `$x_i$`.
[0041] The embodiment of the present application can identify errors in the formula start and end characters, environment structure, command spelling, bracket pairing, symbol format, etc. for the processed mathematical formula based on a pre-built formula error recognition strategy. Through a multi-level detection strategy, it ensures that errors in all aspects can be accurately identified, improves the accuracy and stability of LaTeX formula automatic detection, and provides high-quality error reports for subsequent automatic error repair, so as to ensure that the final repaired LaTeX document format is correct, compilable and complies with typesetting specifications.
[0042] Step 103: For non-start and end character errors in the mathematical formula to be processed, the non-start and end character errors are repaired by using the target repair rules corresponding to the non-start and end character errors; for start and end character errors in the mathematical formula to be processed, the start and end character errors are repaired by using the pre-built start and end character recognition and repair model.
[0043] In this step, after the error is identified, the formula error is repaired. The repair of the present application is divided into two strategies, including rule-based repair and model-based repair. Specifically, repair rules corresponding to different non-start-end character errors and start-end character recognition and repair models are pre-built. If a non-start-end character error is identified in the mathematical formula to be processed, the non-start-end character error is repaired by the target repair rule corresponding to the non-start-end character error; if a start-end character error is identified in the mathematical formula to be processed, the start-end character error is repaired by the pre-built start-end character recognition and repair model.
[0044] In one embodiment of the present application, different non-start / stop character errors correspond to different repair rules, and the repair rule includes at least one of the following: For the environment structure, if there is an unclosed error in the environment definition command, the environment definition command will be completed; if there is a nesting error in the environment definition command, the position of the environment definition command will be adjusted; For command spelling, if there is a spelling error in the mathematical formula to be processed, the incorrect spelling is corrected through the string similarity algorithm; For bracket pairing, if the bracket symbols of the mathematical formula to be processed are not matched in pairs, the missing bracket symbols are completed or the redundant bracket symbols are deleted; For symbol formatting, if a special symbol is not in the math formula to be processed and has no escape character, an escape character is added. If the math formula to be processed has a format error, a space is added after the math formula to be processed.
[0045] In this embodiment, different rule-based repair methods are used for each type of non-start / end character error, including: (1) Fixing environment structure errors: If an environment definition command is not closed, the environment definition command is completed. For example, it is checked whether `\begin{}` and `\end{}` appear in pairs. If `\end{}` is missing, it is automatically completed. If an environment definition command is nested incorrectly, the position of the environment definition command is adjusted. For example, the position of `\begin{}` and `\end{}` is adjusted to ensure the correct order.
[0046] (2) Repair of command spelling errors: If there are spelling errors in the mathematical formula to be processed, the correct spelling is recommended through a string similarity algorithm (such as the Levenshtein distance algorithm), and the incorrect spelling is modified to the correct spelling, thereby ensuring that the command in the formula is spelled correctly.
[0047] (3) Fixing bracket pairing errors: If the bracket symbols in the mathematical formula to be processed are not matched, for example, `()`, `{}`, `[]`, and `\left(...\right)` are not matched, if they are missing, the missing bracket symbols will be completed; if they are redundant, the redundant bracket symbols will be deleted. This ensures that the bracket structure in the formula is correct and prevents accidental deletion or addition from affecting the parsing of mathematical expressions.
[0048] (4) Repair of symbol format errors: If the special symbol is not in the mathematical formula to be processed and there is no escape symbol, the escape symbol `\` is automatically added for correction to ensure that the LaTeX code can be compiled correctly. In one embodiment, the mathematical formula dependency is used to ensure that the intermediate symbol will not be replaced. The wrong symbol can be replaced with other special characters first, and then replaced back after adding the escape symbol `\`. For example, `$a dot b \cdot b$`. If the escape symbol `\` is directly added to dot, it will become `$a \dot b \c\dot b$`. In this case, the contained "cdot" can be replaced with other special characters, and then replaced back after the repair is completed. That is, replace \cdot with _tmp1_: `$a dot b _tmp1_ b$`, repair dot to get: `$a \dot b _tmp1_ b$`, restore _tmp1_, `$a \dot b \cdotb$`.
[0049] If the LaTeX command in the mathematical formula being processed contains formatting errors, add spaces after the LaTeX command. For example, check the dependencies of the mathematical formula to ensure that there are appropriate spaces after LaTeX commands such as `\cdot`, `\frac`, and `\sum` to prevent `\cdotx` from being mistakenly parsed as `\cdot x`, which would affect the correctness of the mathematical expression.
[0050] If special characters are misused, they are replaced. For example, `*` is detected for misuse and replaced with `\times` if it appears in the mathematical formula being processed. `\cdot` is checked for a variable and automatically added with a space if there is no space, ensuring that symbol spacing complies with LaTeX standards.
[0051] In the embodiment of the present application, different non-start and end character errors correspond to different repair rules, and automatic repair of different types of non-start and end character errors is achieved through multiple repair rules, ensuring the efficiency and reliability of the repair.
[0052] In one embodiment of the present application, a pre-built start-and-end character recognition and repair model is used to repair start-and-end character errors in a mathematical formula to be processed, including: The labeling results of the repair model are repaired through start and end character recognition, and start and end characters are automatically inserted or removed at the target position of the mathematical formula to be processed.
[0053] In this embodiment, the start-and-end character recognition and repair model is a pre-built model for identifying and repairing start-and-end character errors in mathematical formulas. For start-and-end character errors identified in the mathematical formula to be processed, the start-and-end character recognition and repair model is combined with context analysis to determine which text should be wrapped with `$` and output a label result. Based on the label result, the start-and-end character `$` is automatically inserted or removed at the target position of the mathematical formula to be processed. In this way, the start-and-end character error application model can be accurately corrected.
[0054] In one embodiment of the present application, the method further comprises: After automatically inserting start and end characters at the target position of the mathematical formula to be processed, determining whether there is a conflict between the document structure of the mathematical formula to be processed and the mathematical formula text; If there is a conflict, adjust the target position for inserting the start and end characters.
[0055] In this embodiment, after the start and end characters `$` are automatically inserted at the target position of the mathematical formula to be processed, if the predicted mathematical formula conflicts with the document structure of the mathematical formula text, for example, if it spans an unclosed `\left(...\right` bracket or a `\begin{equation}` environment, the structural error is corrected first and the insertion position of `$` is adjusted based on the nesting relationship. In this way, it is ensured that the repair of the start and end characters does not conflict with the document structure of the mathematical formula text, ensuring that the final repaired LaTeX document is correctly formatted, compilable, and complies with typesetting specifications.
[0056] In the embodiment of the present application, a pipeline for “identification-repair” of mathematical formula errors is built. Through a pre-built formula error recognition strategy, multiple types of errors are recognized for the mathematical formulas to be processed, and different repair strategies are implemented based on different types of errors. Specifically, non-start-end character errors in the formula are repaired based on repair rules, and start-end character errors in the formula are repaired based on a start-end character recognition and repair model. This significantly expands the coverage of error detection and repair, makes the repair more targeted, and improves the repair effect. In addition, the start-end character recognition and repair model in the present application has context-awareness capabilities, and can intelligently identify and repair start-end character errors based on the context, reduce the false alarm rate, and improve accuracy. In addition, compared with the problems of slow time consumption and low efficiency of the pure model method in the related art, the present application realizes complete automatic repair by combining models and rules, improves detection and repair efficiency, and meets real-time requirements.
[0057] The embodiments of the present application can be applied to scenarios such as scientific research paper writing, online education question banks, and AI content generation. In scientific research paper writing, this application can automatically check and repair mathematical formula typesetting errors in the paper, improve typesetting efficiency and accuracy, and reduce the workload of manual proofreading. For online education question banks, this application can batch detect formula formatting problems in the question bank, automatically complete the repair, and ensure that the questions are displayed efficiently and correctly. For AI-generated content correction, this application can detect formula formatting problems in AI-generated content, automatically complete the repair, and ensure the accuracy of the formulas in the AI-generated content.
[0058] In one embodiment of the present application, building a start-end character recognition and repair model includes: Obtaining a mathematical formula sample text, performing word segmentation processing on the mathematical formula sample text, and obtaining a plurality of word segments; Based on the formula error recognition strategy, multiple segmentations are identified to obtain positive sample segmentations and negative sample segmentations, and noise is added to the negative sample segmentations; The preset model is trained based on positive sample word segmentation and negative sample word segmentation with added noise to obtain a start and end symbol recognition and repair model; the preset model includes a pre-trained language unit, a bidirectional LSTM unit, and a CRF unit. The pre-trained language unit is used to extract contextual features of word segmentation, the bidirectional LSTM (Long Short-Term Memory) unit is used to capture the long-term dependencies of contextual features, and the CRF (Conditional Random Field) unit is used to output the label results of word segmentation.
[0059] In this embodiment, a hybrid word segmentation strategy is adopted to perform context-aware word segmentation on the mathematical formula sample text. The LaTeX commands (such as `\sin`, `\begin{equation}`) are retained as independent tokens, the continuous text is segmented by spaces / punctuations (for example, splitting "Let \(x_i\) denote" into ["Let", "\(x_i\)", "denote"]), and the special symbols (`$`, `_`, `^`) are treated as independent tokens separately to avoid destroying the semantic structure of the formula.
[0060] Based on the formula error recognition strategy, multiple word segments are recognized for errors. The common word segments with errors are used as negative samples, and the common word segments without errors are used as positive samples. Moreover, error-containing data is artificially constructed, such as randomly deleting `$`, inserting redundant symbols, spaces, and mixing Chinese and English symbols, as noise, which is added to the negative samples. The positive samples and the noisy negative samples constitute the training data set to enhance the robustness of the model.
[0061] A preset model is determined, which can be BERT (Bidirectional Encoder Representations from Transformers), RoBERTa (Robustly Optimized BERT Pretraining Approach), or other models.
[0062] Based on the preset model, context features are extracted, and the bidirectional LSTM is combined to capture long-distance dependencies. The label sequence is output through the CRF layer. For example, `B-MATH` / `I-MATH` are used to mark the start and end of the mathematical formula, and `O` is used to mark ordinary text. Then, "calculate / sqrt(α)" is labeled as `[O, B-MATH, O, O]`. Finally, a start and end symbol recognition and repair model is obtained.
[0063] In the embodiment of this application, a start and end symbol recognition and repair model with context awareness ability is constructed to subsequently achieve fast and accurate recognition and repair of formula errors.
[0064] In practice, single repair often cannot solve the problem. Each time, only part of the errors may be solved. This application introduces a multiple detection and repair pipeline to improve the repair accuracy and ensure that the repair process is more robust. As Figure 2 shown, this method includes: The system inputs the mathematical formula to be tested, and uses the formula error recognition strategy to check for errors in the LaTeX formula within the formula. A check is performed to determine if the test passes. If there are no errors, the formula text is output. If there are errors, the system proceeds to the next step of the repair process. This involves automatically correcting non-start-end character errors, such as errors in the environment, command spelling, bracket pairing, and symbol escapes, based on repair rules. After correcting non-start-end character errors, the system is tested again. If the test still fails, the system proceeds to the start-end character error repair phase. This involves automatically correcting problems related to `$` in mathematical formulas, such as misuse, omission, or unpaired `$`, using a NER model combined with contextual analysis.
[0065] After fixing the start and end character errors, perform error detection again and continue the repair process. Through multiple detection and repair, ensure that the repaired LaTeX formula fully complies with the grammatical specifications.
[0066] Set the maximum number of detection executions, for example, 3 times. When the maximum number of detection executions is reached and problems still exist, an alarm message is output to prompt the user that there is an error in the formula.
[0067] It's important to note that when using a pre-built formula error detection strategy to identify errors in a mathematical formula, you can first identify errors that don't represent start or end characters. Once these errors are identified, you can then fix them based on the repair rules, and then fix the start or end character errors. Because rule-based repair is faster than model-based repair, performing rule-based repair first can improve the efficiency of fixing errors that don't represent start or end characters.
[0068] As a specific implementation of the above-mentioned mathematical formula processing method, the embodiment of the present application provides a mathematical formula processing device. Figure 3 As shown, the mathematical formula processing device 400 includes: a formula recognition module 301 , an error recognition module 302 , a first repairing module 303 and a second repairing module 304 .
[0069] The formula recognition module 301 is used to obtain a mathematical formula text and recognize a mathematical formula to be processed in the mathematical formula text; An error recognition module 302 is configured to perform error recognition on a mathematical formula to be processed using a pre-built formula error recognition strategy; The first repair module 303 is configured to repair the non-start-end character error in the mathematical formula to be processed by using a target repair rule corresponding to the non-start-end character error. The second repairing module 304 is configured to repair the start and end character errors in the mathematical formula to be processed by using a pre-built start and end character recognition and repair model.
[0070] Furthermore, the mathematical formula to be processed is a LaTeX formula; the formula recognition module 301 is specifically used to: By using a formula error recognition strategy, at least one of the formula start and end characters, environment structure, command spelling, bracket pairing, and symbol format of the mathematical formula to be processed is recognized.
[0071] Furthermore, the formula error identification strategy includes at least one of the following: For formula start and end characters, the start and end character recognition and repair model is used to identify mathematical variables and / or operators. In combination with regular expression matching and context analysis strategies, it is determined whether the formula start and end characters of the mathematical formula to be processed are missing or misused. For the environment structure, the location of the environment definition command of the mathematical formula to be processed is identified to determine whether the environment definition command has an unclosed error or a nested error; For command spelling, string matching is performed based on pre-built mathematical formula dependencies to detect whether there are spelling errors in the mathematical formula to be processed; For bracket pairing, a paired symbol matching method is used to analyze whether the bracket symbols of the mathematical formula to be processed are matched in pairs; For symbol formatting, detect whether special symbols are in the mathematical formula to be processed, and whether special symbols have escape symbols, and / or determine formatting rules for the mathematical formula to be processed and subsequent characters based on the mathematical formula dependency, and determine whether the mathematical formula to be processed has formatting errors based on the formatting rules.
[0072] Furthermore, different non-start / end character errors correspond to different repair rules, and the repair rules include at least one of the following: For the environment structure, if there is an unclosed error in the environment definition command, the environment definition command will be completed; if there is a nesting error in the environment definition command, the position of the environment definition command will be adjusted; For command spelling, if there is a spelling error in the mathematical formula to be processed, the incorrect spelling is corrected through the string similarity algorithm; For bracket pairing, if the bracket symbols of the mathematical formula to be processed are not matched in pairs, the missing bracket symbols are completed or the redundant bracket symbols are deleted; For symbol formatting, if a special symbol is not in the math formula to be processed and has no escape character, an escape character is added. If the math formula to be processed has a format error, a space is added after the math formula to be processed.
[0073] Furthermore, the second repair module 304 is specifically configured to: The labeling results of the repair model are repaired through start and end character recognition, and start and end characters are automatically inserted or removed at the target position of the mathematical formula to be processed.
[0074] Furthermore, the device further includes: an adjustment module, configured to: After automatically inserting start and end characters at the target position of the mathematical formula to be processed, determining whether there is a conflict between the document structure of the mathematical formula to be processed and the mathematical formula text; If there is a conflict, adjust the target position for inserting the start and end characters.
[0075] Furthermore, the device further comprises: a building module, configured to: Construct formula error recognition strategies, repair rules corresponding to different non-start and end character errors, and start and end character recognition and repair models.
[0076] Furthermore, the building blocks are specifically used to: Obtaining a mathematical formula sample text, performing word segmentation processing on the mathematical formula sample text, and obtaining a plurality of word segments; Based on the formula error recognition strategy, multiple segmentations are identified to obtain positive sample segmentations and negative sample segmentations, and noise is added to the negative sample segmentations; The preset model is trained based on positive sample segmentation and negative sample segmentation with added noise to obtain a start and end symbol recognition and repair model; wherein, the preset model includes a pre-trained language unit, a bidirectional LSTM unit and a CRF unit. The pre-trained language unit is used to extract the contextual features of the segmentation, the bidirectional LSTM unit is used to capture the long-term dependency of the contextual features, and the CRF unit is used to output the label results of the segmentation.
[0077] Furthermore, the formula recognition module 301 is further configured to: After the repair is performed, the mathematical formula to be processed is continuously identified through the formula error identification strategy, and the identified start-stop character errors and / or non-start-stop character errors are repaired.
[0078] The mathematical formula processing device 300 in the embodiment of the present application can be a computer device, or a component in a computer device, such as an integrated circuit or a chip. The computer device can be a terminal, or other devices other than a terminal. The mathematical formula processing device 300 provided in the embodiment of the present application can realize Figure 1 To avoid repetition, the various processes implemented in the embodiment of the mathematical formula processing method are not described here.
[0079] The present application also provides a computer device, such as Figure 4 As shown, the computer device 400 includes a processor 401 and a memory 402. The memory 402 stores programs or instructions that can be run on the processor 401. When the program or instructions are executed by the processor 401, the various steps of the above-mentioned mathematical formula processing method embodiment are implemented and the same technical effect can be achieved. To avoid repetition, they are not repeated here.
[0080] Memory 402 can be used to store software programs and various data. Memory 402 may primarily include a first storage area for storing programs or instructions and a second storage area for storing data. The first storage area may store an operating system, applications or instructions required for at least one function (such as sound playback or image playback), and the like. Furthermore, memory 402 may include volatile memory or non-volatile memory, or both. Non-volatile memory may be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct RAM bus random access memory (DRRAM). The memory 402 in the embodiment of the present application includes but is not limited to these and any other suitable types of memory.
[0081] Processor 401 may include one or more processing units. Optionally, processor 401 integrates an application processor and a modem processor. The application processor primarily handles operations related to the operating system, user interface, and application programs, while the modem processor primarily processes wireless communication signals, such as a baseband processor. It is understood that the modem processor may not be integrated into processor 401.
[0082] An embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the various processes of the above-mentioned mathematical formula processing method embodiment are implemented and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0083] It should be noted that, in this article, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device comprising the element. In addition, it should be noted that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in the opposite order according to the functions involved. For example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.
[0084] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of this application, ordinary technicians in this field can also make many forms without departing from the purpose of this application and the scope of protection of the claims, all of which are within the protection of this application.
Claims
1. A mathematical formula processing method, characterized in that: include: Acquire a mathematical formula text, and identify a mathematical formula to be processed in the mathematical formula text; Performing error identification on the mathematical formula to be processed by using a pre-built formula error identification strategy; For the non-start-end character error in the mathematical formula to be processed, repair the non-start-end character error in the mathematical formula to be processed by using a target repair rule corresponding to the non-start-end character error; With respect to the start and end character errors existing in the mathematical formula to be processed, the start and end character errors of the mathematical formula to be processed are repaired by using a pre-built start and end character recognition and repair model.
2. The method according to claim 1, characterized in that The mathematical formula to be processed is a LaTeX formula; The method of performing error identification on the mathematical formula to be processed by using a pre-built formula error identification strategy includes: By using the formula error recognition strategy, at least one of the formula start and end characters, environment structure, command spelling, bracket pairing, and symbol format of the mathematical formula to be processed is recognized.
3. The method according to claim 2, characterized in that The formula error identification strategy includes at least one of the following: For formula start and end symbols, the mathematical variables and / or operators are identified by the start and end symbol recognition and repair model, and regular matching and context analysis strategies are combined to determine whether the formula start and end symbols of the mathematical formula to be processed are missing or misused; For the environment structure, identifying the location of the environment definition command of the mathematical formula to be processed to determine whether the environment definition command has an unclosed error or a nested error; For command spelling, string matching is performed based on pre-built mathematical formula dependencies to detect whether there are spelling errors in the mathematical formula to be processed; For bracket pairing, a paired symbol matching method is used to analyze whether the bracket symbols of the mathematical formula to be processed are matched in pairs; For the symbol format, detect whether special symbols are in the mathematical formula to be processed, and whether special symbols have escape symbols, and / or determine the format rules of the mathematical formula to be processed and subsequent characters based on the dependency relationship of the mathematical formula, and determine whether the mathematical formula to be processed has format errors based on the format rules.
4. The method according to claim 3, characterized in that Different non-start / end character errors correspond to different repair rules, and the repair rules include at least one of the following: For the environment structure, if the environment definition command has an unclosed error, the environment definition command is completed; if the environment definition command has a nesting error, the position of the environment definition command is adjusted; For command spelling, if there is a spelling error in the mathematical formula to be processed, the incorrect spelling is modified to the correct spelling through a string similarity algorithm; For bracket pairing, if the bracket symbols of the mathematical formula to be processed are not matched in pairs, then the missing bracket symbols are completed or the redundant bracket symbols are deleted; For the symbol format, if the special symbol is not in the mathematical formula to be processed and there is no escape symbol, an escape symbol is added; if the mathematical formula to be processed has a format error, a space is added after the mathematical formula to be processed.
5. The method according to claim 1, wherein The method of repairing the start and end character errors of the mathematical formula to be processed by using the pre-built start and end character recognition and repair model includes: The label result of the repair model is repaired by identifying the start and end characters, and the start and end characters are automatically inserted or removed at the target position of the mathematical formula to be processed.
6. The method according to claim 5, characterized in that The method further comprises: After automatically inserting start and end characters at the target position of the mathematical formula to be processed, determining whether there is a conflict between the mathematical formula to be processed and the document structure of the mathematical formula text; If there is a conflict, the target position for inserting the start and end characters is adjusted.
7. The method according to claim 1, characterized in that The method further comprises: Construct the formula error recognition strategy, the repair rules corresponding to the non-start and end character errors, and the start and end character recognition and repair model.
8. The method according to claim 7, characterized in that Constructing the start and end character recognition and repair model includes: Obtaining a mathematical formula sample text, and performing word segmentation processing on the mathematical formula sample text to obtain a plurality of word segments; Identify the plurality of segmented words based on the formula error identification strategy to obtain positive sample segmented words and negative sample segmented words, and add noise to the negative sample segmented words; The preset model is trained based on the positive sample word segmentation and the negative sample word segmentation after adding noise to obtain the start and end symbol recognition and repair model; wherein, the preset model includes a pre-trained language unit, a bidirectional LSTM unit and a CRF unit, the pre-trained language unit is used to extract the contextual features of the word segmentation, the bidirectional LSTM unit is used to capture the long-term dependency of the contextual features, and the CRF unit is used to output the label results of the word segmentation.
9. The method according to any one of claims 1 to 8, characterized in that The method further comprises: After the repair is performed, the mathematical formula to be processed is further identified using the formula error identification strategy, and the identified start-end character errors and / or non-start-end character errors are repaired.
10. A mathematical formula processing device, characterized in that: include: A formula recognition module is used to obtain a mathematical formula text and recognize a mathematical formula to be processed in the mathematical formula text; An error recognition module, configured to perform error recognition on the mathematical formula to be processed using a pre-built formula error recognition strategy; a first repairing module, configured to repair the non-starting and ending character errors in the mathematical formula to be processed by using a target repair rule corresponding to the non-starting and ending character errors; The second repairing module is used to repair the start and end character errors in the mathematical formula to be processed by using a pre-built start and end character recognition and repair model.
11. A computer device, characterized in that: The method comprises a processor and a memory, wherein the memory stores a program or instruction running on the processor, and when the program or instruction is executed by the processor, the steps of the mathematical formula processing method according to any one of claims 1 to 9 are implemented.
12. A readable storage medium having a program or instruction stored thereon, characterized in that: When the program or instruction is executed by a processor, the steps of the mathematical formula processing method according to any one of claims 1 to 9 are implemented.
Citation Information
Patent Citations
Automatic formula checking calculation method based on large model
CN118072329A
Data enhancement method for mathematical formula identification model
CN119049064A
Editing text optimization method and device, electronic equipment and storage medium
CN119476217A
Large language model reasoning error correction method and device, equipment and medium
CN120197703A
Symbolic model discovery rectification
US20240346106A1
Cited By
Report generation method based on WPS standard format
CN120745578A