Mathematical formula processing method and device, computer device and readable storage medium
By constructing a formula error identification strategy and a start/end character identification and repair model, the problem of incomplete mathematical formula error detection in existing technologies has been solved. This has enabled efficient and accurate identification and repair of multiple types of errors, reduced the false alarm rate, and improved detection and repair efficiency.
Patent Information
- Application Number
- CN202510948957.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-10
- Publication Date
- 2025-11-21
- Estimated Expiration
- 2045-07-10
AI Technical Summary
Existing technologies for detecting and correcting errors in mathematical formulas suffer from insufficient context awareness, high false alarm rates, incomplete detection and correction, and difficulty in identifying multiple error types.
By constructing a formula error identification strategy and a start-end character identification and repair model, and combining regular expression matching and context analysis, errors such as start-end characters, environment structure, command spelling, bracket pairing, and symbol format in mathematical formulas are identified and repaired. A hybrid word segmentation strategy is used to train the start-end character identification and repair model to improve context awareness.
It significantly expands the coverage of error detection and repair, reduces the false alarm rate, improves the accuracy and efficiency of detection and repair, meets real-time requirements, and reduces the workload of manual verification.
Smart Images

Figure CN120449867B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of formula editing, and in particular to a mathematical formula processing method, apparatus, computer device, and readable storage medium. Background Technology
[0002] Mathematical formulas are applied in various scenarios, such as academic paper formatting, online education question banks, and AI content generation. In related technologies, error detection and repair of mathematical formulas mainly rely on rule matching or simple static analysis tools, but these existing technologies have the following significant shortcomings:
[0003] (1) There is a problem of context awareness, resulting in a high false alarm rate. For example, it is difficult to intelligently determine whether the use of the $ symbol is correct based on the context.
[0004] (2) Focusing only on a single error type, error detection and repair are not comprehensive enough. Summary of the Invention
[0005] In view of this, this application provides a mathematical formula processing method, apparatus, computer device, and readable storage medium.
[0006] In a first aspect, embodiments of this application provide a mathematical formula processing method, including:
[0007] Obtain mathematical formula text and identify the mathematical formulas to be processed within the mathematical formula text;
[0008] The mathematical formulas to be processed are identified by a pre-built formula error identification strategy.
[0009] 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.
[0010] For the start and end character errors in the mathematical formula to be processed, a pre-built start and end character recognition and repair model is used to correct the start and end character errors in the mathematical formula to be processed.
[0011] The method described in the embodiments of this application may also have the following additional technical features:
[0012] In the above technical solution, optionally, the mathematical formula to be processed is a LaTeX formula;
[0013] The mathematical formulas to be processed are identified using a pre-built formula error detection strategy, including:
[0014] The formula error identification strategy identifies at least one of the following in the mathematical formula to be processed: formula start and end marks, environment structure, command spelling, bracket pairing, and symbol format.
[0015] In any of the above technical solutions, the formula error identification strategy may optionally include at least one of the following:
[0016] For formula start and end marks, the start and end mark recognition and repair model identifies mathematical variables and / or operators, and combines regular expression matching and context analysis strategies to determine whether the start and end marks of the mathematical formula to be processed are missing or misused.
[0017] For the environment structure, identify the location of the environment definition command for the mathematical formula to be processed in order to determine whether there are unclosed errors or nested errors in the environment definition command;
[0018] 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;
[0019] For bracket pairing, a pair symbol matching method is used to parse whether the bracket symbols in the mathematical formula to be processed are paired.
[0020] For symbol formatting, it detects whether special symbols are in the mathematical formula to be processed, whether special symbols have escape characters, and / or determines the format rules of the mathematical formula to be processed and subsequent characters based on the mathematical formula dependencies, and judges whether there are format errors in the mathematical formula to be processed based on the format rules.
[0021] In any of the above technical solutions, optionally, different non-start / end character errors correspond to different repair rules, and the repair rules include at least one of the following:
[0022] For environment structures, if there is an unclosed error in the environment definition command, the environment definition command is completed; if there is a nesting error in the environment definition command, the position of the environment definition command is adjusted.
[0023] For command spelling, if the mathematical formula to be processed contains spelling errors, the incorrect spelling will be corrected to the correct spelling using a string similarity algorithm;
[0024] For parenthesis pairing, if the parenthesis symbols in the mathematical formula to be processed are not paired, then the missing parenthesis symbols are filled in or the redundant parenthesis symbols are deleted.
[0025] For symbol formatting, if a special symbol is not in the mathematical formula to be processed and there is no escape character, then an escape character is added. If the mathematical formula to be processed has a formatting error, then a space is added after the mathematical formula to be processed.
[0026] Optionally, in any of the above technical solutions, a pre-built start-end character recognition and repair model is used to repair start-end character errors in the mathematical formula to be processed, including:
[0027] By identifying start and stop characters in the label results of the repair model, start and stop characters are automatically inserted or removed at the target position of the mathematical formula to be processed.
[0028] Optionally, in any of the above technical solutions, the method further includes:
[0029] After automatically inserting start and end marks at the target position of the mathematical formula to be processed, it is determined whether there is a conflict between the document structure of the mathematical formula to be processed and the mathematical formula text.
[0030] If a conflict exists, adjust the target position for inserting the start and end characters.
[0031] Optionally, in any of the above technical solutions, the method further includes:
[0032] Construct a formula error identification strategy, repair rules for different non-start and stop character errors, and a start and stop character identification and repair model.
[0033] Optionally, in any of the above technical solutions, a start / end mark recognition and repair model is constructed, including:
[0034] Obtain sample text of mathematical formulas, perform word segmentation on the sample text of mathematical formulas, and obtain multiple word segments;
[0035] Based on the formula error identification strategy, multiple word segments are identified to obtain positive sample word segments and negative sample word segments, and noise is added to the negative sample word segments;
[0036] The preset model is trained based on positive sample word segmentation and negative sample word segmentation with added noise to obtain the start and end character 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 the context features of word segmentation, the bidirectional LSTM unit is used to capture the long-term dependencies of context features, and the CRF unit is used to output the label results of word segmentation.
[0037] Optionally, in any of the above technical solutions, the method further includes:
[0038] After the repair is performed, the mathematical formula to be processed is identified again through the formula error identification strategy, and the identified start and end character errors and / or non-start and end character errors are repaired.
[0039] Secondly, embodiments of this application provide a mathematical formula processing apparatus, including:
[0040] The formula recognition module is used to acquire mathematical formula text and identify the mathematical formulas to be processed in the mathematical formula text;
[0041] The error identification module is used to identify errors in the mathematical formulas to be processed using a pre-built formula error identification strategy.
[0042] The first repair module is used to repair non-start and end character errors in the mathematical formula to be processed by using the target repair rules corresponding to the non-start and end character errors.
[0043] The second repair module is used to repair 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.
[0044] Thirdly, embodiments of this application provide a computer device including a processor and a memory, the memory storing programs or instructions that can run on the processor, the programs or instructions implementing the steps of the method as described in the first aspect when executed by the processor.
[0045] Fourthly, embodiments of this application provide a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the method as described in the first aspect.
[0046] The mathematical formula processing method, apparatus, computer device, and readable storage medium of this application, through a pre-constructed formula error identification strategy, identify multiple types of errors in the mathematical formula to be processed, and apply different repair strategies based on different types of errors. Specifically, for non-start / end character errors in the formula, repair is performed based on repair rules; for start / end character errors in the formula, repair is performed 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. Furthermore, the start / end character recognition and repair model in this application has context-aware capabilities, enabling intelligent identification and repair of start / end character errors based on context, reducing the false alarm rate and improving accuracy. In addition, compared to the slow and inefficient nature of pure model-based methods in related technologies, this application achieves complete automated repair by combining models and rules, improving detection and repair efficiency and meeting real-time requirements.
[0047] The above description is only an overview of the technical solution of this application. In order to better understand the technical means of this application and to implement it in accordance with the contents of the specification, and to make the above and other objects, features and advantages of this application more obvious and understandable, the following are specific embodiments of this application. Attached Figure Description
[0048] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0049] Figure 1One of the flowcharts illustrating a mathematical formula processing method according to an embodiment of this application is shown;
[0050] Figure 2 A second schematic flowchart of the mathematical formula processing method according to an embodiment of this application is shown;
[0051] Figure 3 A structural block diagram of a mathematical formula processing apparatus according to an embodiment of this application is shown;
[0052] Figure 4 A structural block diagram of a computer device according to an embodiment of this application is shown. Detailed Implementation
[0053] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.
[0054] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0055] The mathematical formula processing method, apparatus, computer equipment, and readable storage medium provided in this application will be described in detail below with reference to the accompanying drawings and through specific embodiments and application scenarios. Unless otherwise specified, the following embodiments and features can be combined with each other.
[0056] This application provides a method for processing mathematical formulas, such as... Figure 1 As shown, the method includes:
[0057] Step 101: Obtain the mathematical formula text and identify the mathematical formulas to be processed in the mathematical formula text.
[0058] In this step, the content enclosed by start and end marks is initially identified in the input mathematical formula text to obtain the range of the mathematical formula, i.e., the mathematical formula to be processed. Then, subsequent error identification and correction are performed on the mathematical formula to be processed. In one embodiment, the mathematical formula to be processed can be a LaTeX formula.
[0059] Step 102: Errors are identified in the mathematical formulas to be processed using a pre-built formula error identification strategy.
[0060] In this step, a formula error detection strategy is pre-built to identify errors in the acquired mathematical formulas to be processed. Specifically, this strategy can identify one or more of the following: formula start and end marks, environment structure, command spelling, parenthesis pairing, and symbol format.
[0061] In one embodiment of this application, the formula error identification strategy includes one or more of the following:
[0062] For formula start and end marks, the start and end mark recognition and repair model identifies mathematical variables and / or operators, and combines regular expression matching and context analysis strategies to determine whether the start and end marks of the mathematical formula to be processed are missing or misused.
[0063] For the environment structure, identify the location of the environment definition command for the mathematical formula to be processed in order to determine whether there are unclosed errors or nested errors in the environment definition command;
[0064] 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;
[0065] For bracket pairing, a pair symbol matching method is used to parse whether the bracket symbols in the mathematical formula to be processed are paired.
[0066] For symbol formatting, it detects whether special symbols are in the mathematical formula to be processed, whether special symbols have escape characters, and / or determines the format rules of the mathematical formula to be processed and subsequent characters based on the mathematical formula dependencies, and judges whether there are format errors in the mathematical formula to be processed based on the format rules.
[0067] In this embodiment, a mathematical formula dependency relationship is pre-constructed, which collects common LaTeX formula representations. Then, for each LaTeX symbol, it is checked whether it has a relationship with other LaTeX symbols. If so, the other related LaTeX symbols are added to the dictionary of mathematical formula dependencies for that LaTeX symbol. Subsequently, this mathematical formula dependency relationship can be used to understand the hierarchy and inclusion relationships between different LaTeX symbols, verify whether the use of symbols is reasonable, and whether there are incompatible or incorrect symbol combinations, thereby better checking and correcting formula errors.
[0068] The formula error identification strategy includes identification strategies for various formula errors, which can identify different types of LaTeX errors, as shown in Table 1:
[0069] Table 1
[0070]
[0071] The specific error types and their corresponding identification strategies include:
[0072] (1) For formula start and end marks `$`: The start and end mark identification and repair model identifies mathematical variables and / or operators, and combines regular expression matching and context analysis strategies to determine whether the start and end marks of the mathematical formula to be processed are missing or misused.
[0073] The start and end character recognition and repair model can be a Named Entity Recognition (NER) model. It uses NER to identify mathematical variables and operators, and combines regular expression matching and context analysis strategies to determine whether the start and end characters `$` are missing or misused. For example, by combining context analysis to identify the content enclosed by `$`, if the content only contains plain text or numbers, it is marked as misused. For example, `$2023$` should be `2023`, and should not have the start and end characters `$`, which is a misuse of the start and end characters `$`. Similarly, for the formula `Let x_i = y^2 + 3`, both ends should have the start and end characters `$`, indicating a missing start and end character `$`.
[0074] In one embodiment, a stack matching method can be used, which is similar to checking bracket matching, to track the start and end marks `$` of the formula to ensure that they appear in pairs, and to use recursive detection to identify whether the start and end marks `$` of the formula are missing, so as to avoid the mathematical environment from failing to compile due to mismatched `$`.
[0075] It should be noted that related technologies use regular expressions or hard-coded rules to locate formula errors, which have a high false positive rate due to a lack of understanding of the context. In this embodiment, a named entity recognition model is used to identify the mathematical pattern symbol `$` in the input mathematical formula, intelligently determining which positions should have the start and end symbols `$`, thereby accurately locating missing or misused `$` symbols and reducing the false positive rate.
[0076] (2) For environment structure: Identify the location of environment definition commands for the mathematical formula to be processed to determine whether there are unclosed or nested errors in the environment definition commands. For example, for environment nesting errors, record the positions of `\begin{}` and `\end{}`, detect unclosed or nested errors, and ensure that all environments match correctly. For environment crossover errors, check the LaTeX code structure to ensure that `\begin{}` and `\end{}` are nested in the correct order, preventing environment errors such as `align` and `equation` from being nested or prematurely terminated, leading to compilation failure.
[0077] (3) For command spelling: String matching is performed based on the pre-built mathematical formula dependency relationship, and the correct spelling is recommended in combination with the similarity algorithm to detect whether there is a spelling error in the mathematical formula to be processed, so as to avoid errors such as `\summ_{i=1}^{n} i^2` (which should actually be `\sum`).
[0078] A similarity algorithm can be the Levenshtein distance algorithm, a string similarity algorithm that calculates the minimum number of single-character editing operations (insertion, deletion, replacement) required to transform one string into another. A smaller Levenshtein distance indicates that the two strings are more similar. Using the Levenshtein distance algorithm, a similarity score is calculated between the string representing the mathematical formula and the strings in the formula's dependencies; a higher similarity score indicates correct spelling.
[0079] (4) For bracket pairing: Use the 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 paired and matched to avoid incomplete expressions such as `f(x= \left( a + b \right`).
[0080] (5) For symbol format: Special symbols include `%`, `&`, etc., and errors such as symbol escaping, space formatting, and misuse of special characters are judged. The special symbol list is scanned to check whether the special symbol is in the mathematical formula to be processed, and whether the special symbol has an escape character. If the special symbol is not in the mathematical formula to be processed and the special symbol has no escape character, it is marked as an error. For example, `10%` is an error, and the correct one should be `10\%`.
[0081] Furthermore, based on the dependencies between mathematical formulas, the format rules of the mathematical formulas to be processed and subsequent characters are determined, and it is detected whether the mathematical formulas to be processed are missing necessary spaces. For example, `\cdotx` is a space error, and the correct format should be `\cdot x`.
[0082] Additionally, it parses the mathematical formula to be processed, checks whether `_` and `^` appear outside the mathematical formula to be processed. If they do, it marks the special character misuse error. For example, `variable_x` is misused, and the correct one should be `$x_i$`.
[0083] This application embodiment can identify errors in mathematical formulas based on a pre-built formula error identification strategy, including errors in formula start and end marks, environment structure, command spelling, bracket matching, and symbol format. Through a multi-level detection strategy, it ensures that errors in all aspects can be accurately identified, improving the accuracy and stability of automatic LaTeX formula detection. This provides high-quality error reports for subsequent automatic error repair, ensuring that the final repaired LaTeX document is correctly formatted, compileable, and conforms to typesetting standards.
[0084] 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.
[0085] In this step, after identifying the error, the formula error is repaired. The repair in this application employs two strategies: rule-based repair and model-based repair. Specifically, repair rules and start-stop identification repair models corresponding to different non-start-stop errors are pre-constructed. If a non-start-stop error is identified in the mathematical formula to be processed, it is repaired using the target repair rule corresponding to the non-start-stop error. If a start-stop error is identified in the mathematical formula to be processed, it is repaired using the pre-constructed start-stop identification repair model.
[0086] In one embodiment of this application, different non-start / endpoint errors correspond to different repair rules, and the repair rules include at least one of the following:
[0087] For environment structures, if there is an unclosed error in the environment definition command, the environment definition command is completed; if there is a nesting error in the environment definition command, the position of the environment definition command is adjusted.
[0088] For command spelling, if the mathematical formula to be processed contains spelling errors, the incorrect spelling will be corrected to the correct spelling using a string similarity algorithm;
[0089] For parenthesis pairing, if the parenthesis symbols in the mathematical formula to be processed are not paired, then the missing parenthesis symbols are filled in or the redundant parenthesis symbols are deleted.
[0090] For symbol formatting, if a special symbol is not in the mathematical formula to be processed and there is no escape character, then an escape character is added. If the mathematical formula to be processed has a formatting error, then a space is added after the mathematical formula to be processed.
[0091] In this embodiment, different rule-based repair methods are adopted for each type of non-start / endpoint error, specifically including:
[0092] (1) Correction of environment structure errors: If there is an unclosed error in the environment definition command, the environment definition command is completed. For example, check whether `\begin{}` and `\end{}` appear in pairs. If `\end{}` is missing, it is automatically completed. If there is a nesting error in the environment definition command, the position of the environment definition command is adjusted. For example, the positions of `\begin{}` and `\end{}` are adjusted to ensure the correct order.
[0093] (2) Correction of spelling errors in commands: If there are spelling errors in the mathematical formula to be processed, the correct spelling is recommended by the string similarity algorithm (e.g., Levenshtein distance algorithm), and the incorrect spelling is corrected to the correct spelling, thereby ensuring that the commands in the formula are spelled correctly.
[0094] (3) Correction of parenthesis pairing errors: If the parenthesis symbols in the mathematical formula to be processed are not paired, such as `()`, `{}`, `[]`, and `\left(...\right)`, if they are missing, then fill in the missing parenthesis symbols; if they are redundant, then delete the redundant parenthesis symbols. This ensures that the parenthesis structure in the formula is correct and prevents accidental deletion or addition from affecting the parsing of the mathematical expression.
[0095] (4) Correction of symbol format errors: If a special symbol is not in the mathematical formula to be processed and there is no escape character, an escape character `\` will be automatically added to correct it, ensuring that the LaTeX code can be compiled correctly. In one embodiment, the mathematical formula dependency is used to ensure that the symbol is not replaced by an intermediate symbol. The incorrect symbol can be replaced with other special characters first, and then replaced back after adding the escape character `\`. For example, if you directly add the escape character `\` to `dot` in `$a dot b \c\dot b$`, it will become `$a \dot b \c\dot b$`. In this case, you can replace the included "cdot" with other special characters, and then replace it back after the correction is completed. That is, replace \cdot with _tmp1_: `$a dot b _tmp1_ b$`, correct dot to get: `$a \dot b _tmp1_ b$`, restore _tmp1_, `$a \dot b \cdotb$`.
[0096] If the LaTeX command used to process a mathematical formula contains formatting errors, add a space after the command. For example, check the dependencies in the mathematical formula to ensure that there are reasonable spaces after LaTeX commands such as `\cdot`, `\frac`, and `\sum`, to prevent `\cdotx` from being misinterpreted as `\cdot x`, which would affect the correctness of the mathematical expression.
[0097] If any special characters are misused, they will be replaced. For example, check if `*` is misused; if it appears in a mathematical formula, replace it with `\times`. Check if `\cdot` is immediately followed by a variable; if there is no space, add one automatically to ensure that the symbol spacing conforms to LaTeX specifications.
[0098] In this application embodiment, different non-start / end character errors correspond to different repair rules. By using multiple repair rules, different types of non-start / end character errors can be automatically repaired, ensuring the efficiency and reliability of the repair.
[0099] In one embodiment of this application, a pre-built start-end character recognition and repair model is used to repair start-end character errors in the mathematical formula to be processed, including:
[0100] By identifying start and stop characters in the label results of the repair model, start and stop characters are automatically inserted or removed at the target position of the mathematical formula to be processed.
[0101] In this embodiment, the start / end character recognition and repair model is a pre-built model for identifying and correcting errors in start and end characters within mathematical formulas. For start / end character errors identified in the mathematical formula to be processed, the start / end character recognition and repair model, combined with context analysis, determines which text should be enclosed in `$` and outputs a label result. Based on this label result, the start / end character `$` is automatically inserted or removed at the target position in the mathematical formula to be processed. In this way, the model can accurately correct start / end character errors.
[0102] In one embodiment of this application, the method further includes:
[0103] After automatically inserting start and end marks at the target position of the mathematical formula to be processed, it is determined whether there is a conflict between the document structure of the mathematical formula to be processed and the mathematical formula text.
[0104] If a conflict exists, adjust the target position for inserting the start and end characters.
[0105] In this embodiment, after automatically inserting start and end marks `$` 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, by crossing unclosed `\left(...\right` brackets or `\begin{equation}` environments, the structural errors are corrected first and the insertion position of `$` is adjusted according to the nesting relationship. This method ensures that the repair of start and end marks does not conflict with the document structure of the mathematical formula text, guaranteeing that the final repaired LaTeX document is correctly formatted, compileable, and conforms to typesetting standards.
[0106] This application establishes a pipeline for "identification-repair" of mathematical formula errors. Through a pre-constructed formula error identification strategy, it identifies multiple types of errors in the mathematical formulas to be processed and applies different repair strategies based on different error types. Specifically, for non-start / end character errors in the formula, repair is performed based on repair rules; for start / end character errors in the formula, repair is performed based on a start / end character recognition and repair model. This significantly expands the coverage of error detection and repair, making the repair more targeted and improving the repair effect. Furthermore, the start / end character recognition and repair model in this application has context-aware capabilities, enabling intelligent identification and repair of start / end character errors based on context, reducing the false alarm rate and improving accuracy. In addition, compared to the slow and inefficient nature of pure model-based methods in related technologies, this application achieves complete automated repair by combining models and rules, improving detection and repair efficiency and meeting real-time requirements.
[0107] The embodiments of this 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 typesetting errors of mathematical formulas in papers, improve typesetting efficiency and accuracy, and reduce the workload of manual proofreading. For online education question banks, this application can batch detect formula format problems in the question bank and automatically complete the repair to ensure efficient and correct display of questions. For the correction of AI-generated content, this application can detect formula format problems in AI-generated content and automatically complete the repair to ensure the accuracy of formulas in AI-generated content.
[0108] In one embodiment of this application, a start and end symbol recognition and repair model is constructed, including:
[0109] Obtain the mathematical formula sample text, perform word segmentation on the mathematical formula sample text to obtain multiple word segments;
[0110] Based on the formula error recognition strategy, identify the multiple word segments to obtain positive sample word segments and negative sample word segments, and add noise to the negative sample word segments;
[0111] Train a preset model based on the positive sample word segments and the negative sample word segments with added noise to obtain a start and end symbol recognition and repair model; where 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 context features of the word segments, the bidirectional LSTM (Long Short-Term Memory) unit is used to capture the long-term dependence relationship of the context features, and the CRF (Conditional Random Field) unit is used to output the label results of the word segments.
[0112] In this embodiment, a context-aware word segmentation process is performed on the mathematical formula sample text using a hybrid word segmentation strategy, retaining LaTeX commands (such as `\sin`, `\begin{equation}`) as independent tokens, splitting continuous text by spaces / punctuation (such as splitting "Let \(x_i\) denote" into ["Let", "\(x_i\)", "denote"]), and treating special symbols (`$`, `_`, `^`) as separate tokens to avoid destroying the formula semantic structure.
[0113] Based on the formula error recognition strategy, identify errors in the multiple word segments, use the common word segments with errors as negative samples, and use the common word segments without errors as positive samples. Moreover, artificially construct error-containing data, such as randomly deleting `$`, inserting redundant symbols, spaces, and mixing Chinese and English symbols, as noise and add it to the negative samples. The positive samples and the negative samples with noise constitute the training data set to enhance the robustness of the model.
[0114] The pre-defined model can be BERT (Bidirectional Encoder Representations from Transformers), RoBERTa (Robustly Optimized BERTPretraining Approach), or other models.
[0115] Contextual features are extracted based on a pre-defined model, and long-distance dependencies are captured using a bidirectional LSTM. A label sequence is output through a CRF layer. For example, `B-MATH` / `I-MATH` marks the start and end of a mathematical formula, and `O` marks ordinary text. Thus, "calculate the square root of / α / " is labeled as `[O, B-MATH, O, O]`. Finally, a start and end character recognition and repair model is obtained.
[0116] In this embodiment, a start and end character recognition and repair model capable of sensing context is constructed, which enables rapid and accurate identification and repair of formula errors.
[0117] In practice, a single repair often fails to resolve the issue, and each attempt may only correct a portion of the errors. This application introduces a multi-stage inspection and repair pipeline to improve repair accuracy and ensure a more robust repair process. Figure 2 As shown, the method includes:
[0118] Input the text of the mathematical formula to be checked. Based on the formula error identification strategy, check for errors in the LaTeX formulas within the text. Determine if the check is successful. If no errors are found, the mathematical formula text is output; otherwise, if errors are found, the process proceeds to the next step: repair. This involves automatically correcting non-start / end character errors such as environment, command spelling, bracket pairing, and symbol escaping based on repair rules. After repairing non-start / end character errors, a second check is performed. If the check still fails, the process enters the start / end character error repair stage. This stage addresses issues related to the backslashes `$` in mathematical formulas, such as misuse, missing, or unpaired `$`, using a NER model combined with context analysis for automatic repair.
[0119] After fixing the start and end character errors, perform error detection again and continue the repair process. Through multiple checks and repairs, ensure that the repaired LaTeX formulas fully comply with the syntax specifications.
[0120] Set the maximum number of times the check can be executed, for example, 3 times. If the maximum number of checks is reached and problems still exist, output an alarm message to inform the user that there is an error in the formula.
[0121] It should be noted that when identifying errors in the mathematical formulas to be processed using a pre-built formula error identification strategy, non-start / endpoint errors can be identified first. After identifying non-start / endpoint errors, they can be repaired based on the repair rules, and then start / endpoint errors can be repaired. Since rule repair is faster than model repair, performing rule repair first can improve the efficiency of non-start / endpoint error repair.
[0122] As a specific implementation of the above-mentioned mathematical formula processing method, this application provides a mathematical formula processing device. For example... Figure 3 As shown, the mathematical formula processing device 400 includes: a formula recognition module 301, an error recognition module 302, a first repair module 303, and a second repair module 304.
[0123] The formula recognition module 301 is used to acquire mathematical formula text and recognize the mathematical formula to be processed in the mathematical formula text.
[0124] Error identification module 302 is used to identify errors in the mathematical formula to be processed using a pre-built formula error identification strategy;
[0125] The first repair module 303 is used to repair non-start and end character errors in the mathematical formula to be processed by using the target repair rules corresponding to the non-start and end character errors.
[0126] The second repair module 304 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.
[0127] Furthermore, the mathematical formula to be processed is a LaTeX formula; the formula recognition module 301 is specifically used for:
[0128] The formula error identification strategy identifies at least one of the following in the mathematical formula to be processed: formula start and end marks, environment structure, command spelling, bracket pairing, and symbol format.
[0129] Furthermore, the formula error detection strategy includes at least one of the following:
[0130] For formula start and end marks, the start and end mark recognition and repair model identifies mathematical variables and / or operators, and combines regular expression matching and context analysis strategies to determine whether the start and end marks of the mathematical formula to be processed are missing or misused.
[0131] For the environment structure, identify the location of the environment definition command for the mathematical formula to be processed in order to determine whether there are unclosed errors or nested errors in the environment definition command;
[0132] 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;
[0133] For bracket pairing, a pair symbol matching method is used to parse whether the bracket symbols in the mathematical formula to be processed are paired.
[0134] For symbol formatting, it detects whether special symbols are in the mathematical formula to be processed, whether special symbols have escape characters, and / or determines the format rules of the mathematical formula to be processed and subsequent characters based on the mathematical formula dependencies, and judges whether there are format errors in the mathematical formula to be processed based on the format rules.
[0135] Furthermore, different non-start / endpoint errors correspond to different repair rules, and the repair rules include at least one of the following:
[0136] For environment structures, if there is an unclosed error in the environment definition command, the environment definition command is completed; if there is a nesting error in the environment definition command, the position of the environment definition command is adjusted.
[0137] For command spelling, if the mathematical formula to be processed contains spelling errors, the incorrect spelling will be corrected to the correct spelling using a string similarity algorithm;
[0138] For parenthesis pairing, if the parenthesis symbols in the mathematical formula to be processed are not paired, then the missing parenthesis symbols are filled in or the redundant parenthesis symbols are deleted.
[0139] For symbol formatting, if a special symbol is not in the mathematical formula to be processed and there is no escape character, then an escape character is added. If the mathematical formula to be processed has a formatting error, then a space is added after the mathematical formula to be processed.
[0140] Furthermore, the second repair module 304 is specifically used for:
[0141] By identifying start and stop characters in the label results of the repair model, start and stop characters are automatically inserted or removed at the target position of the mathematical formula to be processed.
[0142] Furthermore, the device also includes: an adjustment module for:
[0143] After automatically inserting start and end marks at the target position of the mathematical formula to be processed, it is determined whether there is a conflict between the document structure of the mathematical formula to be processed and the mathematical formula text.
[0144] If a conflict exists, adjust the target position for inserting the start and end characters.
[0145] Furthermore, the device also includes: a building module for:
[0146] Construct a formula error identification strategy, repair rules for different non-start and stop character errors, and a start and stop character identification and repair model.
[0147] Furthermore, building modules are specifically used for:
[0148] Obtain sample text of mathematical formulas, perform word segmentation on the sample text of mathematical formulas, and obtain multiple word segments;
[0149] Based on the formula error identification strategy, multiple word segments are identified to obtain positive sample word segments and negative sample word segments, and noise is added to the negative sample word segments;
[0150] The preset model is trained based on positive sample word segmentation and negative sample word segmentation with added noise to obtain the start and end character 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 the context features of word segmentation, the bidirectional LSTM unit is used to capture the long-term dependencies of context features, and the CRF unit is used to output the label results of word segmentation.
[0151] Furthermore, the formula recognition module 301 is also used for:
[0152] After the repair is performed, the mathematical formula to be processed is identified again through the formula error identification strategy, and the identified start and end character errors and / or non-start and end character errors are repaired.
[0153] The mathematical formula processing device 300 in this application embodiment can be a computer device or a component within a computer device, such as an integrated circuit or a chip. The computer device can be a terminal or other device besides a terminal. The mathematical formula processing device 300 provided in this application embodiment can achieve… Figure 1 The various processes implemented in the mathematical formula processing method embodiment will not be described again here to avoid repetition.
[0154] This 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 a program or instruction that can run on the processor 401. When the program or instruction is executed by the processor 401, it implements the various steps of the above-described mathematical formula processing method embodiment and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0155] The memory 402 can be used to store software programs and various data. The 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 the operating system, application programs or instructions required for at least one function (such as sound playback, image playback, etc.). Furthermore, the memory 402 may include volatile memory or non-volatile memory, or both. The 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 memory bus RAM (DRRAM). The memory 402 in this embodiment includes, but is not limited to, these and any other suitable types of memory.
[0156] Processor 401 may include one or more processing units; optionally, processor 401 integrates an application processor and a modem processor, wherein the application processor mainly handles operations involving the operating system, user interface, and applications, and the modem processor mainly handles wireless communication signals, such as a baseband processor. It is understood that the aforementioned modem processor may also not be integrated into processor 401.
[0157] This application also provides a readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the above-described mathematical formula processing method embodiments and achieve the same technical effect. To avoid repetition, they will not be described again here.
[0158] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
[0159] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
Claims
1. A method for processing mathematical formulas, characterized in that, include: Obtain mathematical formula text and identify the mathematical formula to be processed in the mathematical formula text; The mathematical formula to be processed is identified by a pre-built formula error identification strategy. For the 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. To address the start and end character errors in the mathematical formula to be processed, a pre-constructed start and end character recognition and repair model is used to correct these errors. Specifically, the start-stop error is identified using the start-stop recognition and repair model. The start-stop recognition and repair 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 dependencies of the contextual features, and the CRF unit is used to output the label results of the word segmentation.
2. The method according to claim 1, characterized in that, The mathematical formula to be processed is a LaTeX formula; The step of identifying errors in the mathematical formula to be processed using a pre-built formula error identification strategy includes: The formula error identification strategy identifies at least one of the following in the mathematical formula to be processed: formula start and end marks, environment structure, command spelling, bracket pairing, and symbol format.
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 marks, the mathematical variables and / or operators are identified through the start and end mark identification and repair model, and combined with regular expression matching and context analysis strategies, it is determined whether the formula start and end marks of the mathematical formula to be processed are missing or misused. For the environment structure, identify the location of the environment definition command of the mathematical formula to be processed in order to determine whether there is an unclosed error or a nesting error in the environment definition command; 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 pair symbol matching method is used to parse whether the bracket symbols in the mathematical formula to be processed are paired. For symbol format, detect whether special symbols are in the mathematical formula to be processed, and whether special symbols have escape characters, and / or, determine the format rules of the mathematical formula to be processed and subsequent characters based on the mathematical formula dependency relationship, and determine whether the mathematical formula to be processed has a format error based on the format rules.
4. The method according to claim 3, characterized in that, Different non-start / endpoint 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, then complete the environment definition command; if the environment definition command has a nesting error, then adjust the position of the environment definition command. For command spelling, if the mathematical formula to be processed contains spelling errors, the incorrect spelling will be corrected to the correct spelling using a string similarity algorithm; For bracket pairing, if the bracket symbols in the mathematical formula to be processed are not paired, then the missing bracket symbols are filled in or the redundant bracket symbols are deleted. For symbol formatting, if a special symbol is not in the mathematical formula to be processed and there is no escape symbol, then an escape symbol is added. If the mathematical formula to be processed has a formatting error, then a space is added after the mathematical formula to be processed.
5. The method according to claim 1, characterized in that, The step of correcting start and end point errors in the mathematical formula to be processed using a pre-built start and end point recognition and repair model includes: By identifying the label results of the repair model through the start and stop symbols, start and stop symbols 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 includes: After automatically inserting start and end marks at the target position of the mathematical formula to be processed, it is determined whether there is a conflict between the document structure of the mathematical formula to be processed and the mathematical formula text. If a conflict exists, the target position for inserting the start and stop symbols will be adjusted.
7. The method according to claim 1, characterized in that, The method further includes: Construct the formula error identification strategy, the repair rules corresponding to different non-start and stop character errors, and the start and stop character identification and repair model.
8. The method according to claim 7, characterized in that, Constructing the start and end character recognition and repair model includes: Obtain mathematical formula sample text, and perform word segmentation on the mathematical formula sample text to obtain multiple word segments; Based on the error identification strategy described in the formula, multiple word segments are identified to obtain positive sample word segments and negative sample word segments, and noise is added to the negative sample word segments; 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 character 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 context features of word segmentation, the bidirectional LSTM unit is used to capture the long-term dependencies of the context features, and the CRF unit is used to output the label results of word segmentation.
9. The method according to any one of claims 1 to 8, characterized in that, The method further includes: After the repair is performed, the mathematical formula to be processed is identified again through the formula error identification strategy, and the identified start and end character errors and / or non-start and end character errors are repaired.
10. A mathematical formula processing device, characterized in that, include: The formula recognition module is used to acquire mathematical formula text and identify the mathematical formula to be processed in the mathematical formula text; An error identification module is used to identify errors in the mathematical formula to be processed using a pre-built formula error identification strategy. The first repair module is used to repair the non-start and end character errors in the mathematical formula to be processed by using the target repair rules 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. Specifically, the start-stop error is identified using the start-stop recognition and repair model. The start-stop recognition and repair 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 dependencies of the contextual features, and the CRF unit is used to output the label results of the word segmentation.
11. A computer device, characterized in that, It includes a processor and a memory, the memory storing a program or instructions that run on the processor, the program or instructions being executed by the processor to implement the steps of the mathematical formula processing method as described in any one of claims 1 to 9.
12. A readable storage medium having a program or instructions stored thereon, characterized in that, When the program or instructions are executed by the processor, they implement the steps of the mathematical formula processing method as described in any one of claims 1 to 9.
Citation Information
Patent Citations
Automatic formula checking calculation method based on large model
CN118072329A
Editing text optimization method and device, electronic equipment and storage medium
CN119476217A