Mathematical problem solving method and device based on large language model, computer program and storage medium
Through a mathematical problem-solving method based on a large language model, combined with text normalization, word segmentation, regular expressions, TF-IDF and MathBERT to improve the classification model, the problem-solving process is broken down into subtasks and verified, which solves the problems of incomplete problem-solving and logical discontinuities in the existing system, and improves the accuracy and credibility of the problem-solving process.
Patent Information
- Application Number
- CN202510641347.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-19
- Publication Date
- 2025-09-05
AI Technical Summary
Existing mathematical problem-solving systems have problems in the reasoning process, such as incompleteness, easily broken logical chains, insufficient use of contextual information, and lack of effective verification mechanisms, which lead to incoherent problem-solving processes and unreliable problem-solving results.
A math problem-solving method based on a large language model is adopted, which involves collecting math problems, extracting and classifying text features, building a prompt word knowledge base, solving problems step by step, and verifying the results. This includes text normalization, word segmentation, regular expression extraction, TF-IDF algorithm, MathBERT improved classification model, decomposing question-answer sequences into subtasks, and performing substitution and inverse verification.
Improve the accuracy, coherence and credibility of the problem-solving process, ensure the logical rigor of the problem-solving process, enhance the explainability and interactivity of the problem-solving process, and adapt to the analysis and solution of complex problems.
Smart Images

Figure CN120596762A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of artificial intelligence and natural language processing, and also to the technical field of mathematical solution and solution process demonstration based on artificial intelligence. Background Art
[0002] As computers' data processing capabilities improve, mathematical problem-solving methods implemented by computers are playing a crucial role in a variety of scenarios, including education and teaching, scientific research, and intelligent decision-making. In education, they provide students with guidance on problem-solving strategies and methods, helping them master mathematical knowledge. In scientific research, they help researchers overcome complex mathematical problems and promote academic progress. In intelligent systems, they serve as core technologies, providing solutions to various mathematical problems.
[0003] Traditional math problem-solving systems rely on large, manually curated question banks and pre-designed problem-solving templates. Using keyword matching, they map user-entered questions to similar, classic problems and then return prepared solutions. While this approach can quickly generate answers for standardized, fixed-format questions, it struggles to adapt to novel question types and complex scenarios. Furthermore, maintaining the question bank and designing templates requires significant manpower, making it difficult to meet the demands of efficient, dynamic teaching and research.
[0004] With the rise of computer algebra systems (CAS) and automated theorem proving technology, tools such as Mathematica, Maple, and Coq have demonstrated powerful capabilities in symbolic computation and rigorous proofs. These systems can automate computation and logical deduction to a certain extent, facilitating mathematical research. However, CAS systems are often based on predefined rules and algorithms, and their reasoning processes are often "black-boxed," which can hinder their effectiveness in solving problems requiring flexible thinking and innovation.
[0005] In recent years, thanks to the development of deep learning and large-scale pre-trained models, breakthroughs have been made in mathematical problem-solving technology based on large language models (LLMs). Trained with massive amounts of text and formula data, these models are able to connect natural language descriptions with mathematical expressions and generate problem-solving ideas and steps in near real time. They have demonstrated tremendous potential in improving problem-solving efficiency, expanding the scope of problem types, and providing intelligent teaching assistance, driving the transformation of mathematical tools from "tools" to "intelligent assistants."
[0006] Despite this, current large-scale models still have some shortcomings in solving mathematical problems. For one thing, the models are prone to missing steps or interrupting the logical chain during derivation, resulting in an incoherent and incomplete problem-solving process. Furthermore, when faced with long, multi-step questions, the models tend to overlook key information in the questions and fail to fully utilize contextual information for systematic derivation. Furthermore, because existing problem-solving processes mostly rely on model-generated, personalized prompts based on question type are lacking, problem-solving methods become generalized, making it difficult to provide precise solutions for different question types. Furthermore, the problem-solving processes generated by the models lack a systematic verification mechanism, making it difficult to detect and correct errors in a timely manner, reducing the credibility of the problem-solving process and the effectiveness of teaching assistance. Summary of the Invention
[0007] To address the problems of existing math problem-solving systems, such as incomplete reasoning, easily broken logical chains, insufficient use of contextual information, and a lack of effective verification mechanisms, this paper proposes a math problem-solving system based on a large language model that features structured problem analysis, prompt word knowledge base guidance, step-by-step problem solving, and result verification.
[0008] A mathematical problem-solving method based on a large language model, the method comprising:
[0009] S1. Steps for collecting math problems;
[0010] S2, extracting and classifying text features of the math problem to obtain classification results;
[0011] S3: building a prompt word knowledge base, matching corresponding prompt words according to the classification results, and obtaining a question-answer sequence;
[0012] S4, decomposing the question-answering sequence into four subtasks: analyzing question conditions, applying key formulas, verifying calculations, and summarizing results, to obtain preliminary answers;
[0013] S5. Verify the preliminary answer.
[0014] Furthermore, the method for collecting math problems in S1 is: receiving input math problems, filtering out characters and non-mathematical symbols that are not related to math problem solving, and converting the math problems into LaTeX or MathML format through a text normalization method.
[0015] Furthermore, the method for obtaining the classification result described in S2 is:
[0016] S21. Segment the math problem using a word segmentation tool to obtain a word segmentation result;
[0017] S22, extracting mathematical symbols and variable names of the math problem by using regular expressions;
[0018] S23, obtaining the weight of the word segmentation result in the math problem by using the TF-IDF algorithm, and combining the position coding to enhance the position information of the word to obtain a weighted word feature vector;
[0019] S24. Input the term feature vector into the improved classification model based on MathBERT to predict the question type and obtain the classification result.
[0020] Furthermore, the method for obtaining the question-answer sequence described in S3 is:
[0021] S31. Constructing a knowledge base of prompt words for math problems based on the math problems and the classification results, wherein the prompt words include general problem-solving steps generated by the large language model and key knowledge points and example problem ideas extracted from the textbook;
[0022] S32. Setting a search category label in the knowledge base according to the classification result;
[0023] S33, matching a prompt word set corresponding to the math problem in the knowledge base using the search category label;
[0024] S34. Integrate the matched prompt word set with the question to construct a question-answer sequence.
[0025] Furthermore, the method for obtaining the preliminary answer described in S4 is:
[0026] S41. Divide the question-answering sequence into four subtasks: question condition analysis, key formula application, calculation verification, and result summary;
[0027] S42. Execute each subtask in sequence, respectively: analyze the question conditions, call the key formula for calculation, verify the calculation process, summarize the problem-solving results, and obtain a preliminary answer.
[0028] Furthermore, in S5, the method for verifying whether the preliminary answer is correct is as follows:
[0029] S51, review and reflect on the prompt words obtained in S3 and the preliminary answers obtained in S4, and check whether the execution process of each subtask conforms to the mathematical rules and the problem-solving ideas provided by the prompt words;
[0030] S52. Verify the problem-solving process and results by substitution, inverse reasoning, or proof by contradiction to determine whether they meet the requirements of the problem. If so, the verification passes; otherwise, the verification fails.
[0031] S53. If the verification is successful, the final answer is output; if the verification is unsuccessful, the process returns to S3 until the verification is successful.
[0032] Based on the same inventive concept, the present invention also proposes a mathematical problem-solving device based on a large language model, which includes the following modules:
[0033] Module for collecting math problems;
[0034] A module for extracting and classifying text features of the math problem to obtain classification results;
[0035] A module for building a prompt word knowledge base, matching corresponding prompt words based on classification results, and obtaining question-answer sequences;
[0036] A module for decomposing the question-answering sequence into four subtasks: question condition analysis, key formula application, calculation verification, and result summarization, to obtain preliminary answers;
[0037] A module for verifying the preliminary answer.
[0038] Based on the same inventive concept, the present invention also proposes a computer storage medium for storing a computer program. When the computer program is read by a computer, the computer executes any one of the methods described in the present invention.
[0039] Based on the same inventive concept, the present invention also proposes a computer, comprising a processor and a storage medium. When the processor reads the computer program stored in the storage medium, the computer executes any one of the methods described in the present invention.
[0040] Based on the same inventive concept, the present invention also proposes a computer program product, which is a computer program. When the computer program is read, it implements any one of the methods described in the present invention.
[0041] Compared with the prior art, the present invention has the following beneficial effects:
[0042] 1. The present invention provides a math problem-solving method based on a large language model. By receiving math problem input, filtering non-mathematical characters, and uniformly converting the problems into LaTeX or MathML format, the method combines word segmentation, regular expression extraction, TF-IDF weight calculation, and a classification model improved by MathBERT to predict the question type. This method can improve the accuracy of question comprehension and classification. Compared with existing technologies, it avoids classification errors caused by differences in question wording, and improves the accuracy and stability of the problem-solving process.
[0043] 2. The present invention sets the retrieval category labels of the prompt word knowledge base based on the results of math problem classification, and combines the general problem-solving steps generated by the large language model, the key knowledge points extracted from the textbook, and the example problem ideas to match the corresponding prompt word set, and constructs a question-specific question and answer sequence. It can provide targeted prompt word guidance for different question types. Compared with the existing technology, it effectively overcomes the problems of generalized prompt content and lack of logical guidance in the problem-solving process, and improves the standardization and scientific nature of problem-solving ideas.
[0044] 3. By dividing the question-answering sequence into four standardized subtasks: question condition analysis, key formula application, calculation verification, and result summary, and executing each subtask in sequence, the present invention can ensure the integrity and coherence of the problem-solving reasoning chain. Compared with the existing technology, it avoids problems such as reasoning skipping and logical breaks in the problem-solving process, and improves the systematicness and accuracy of the problem-solving process.
[0045] 4. By combining the prompt word knowledge base with the problem-solving process and applying mathematical verification methods such as substitution, inference, and proof by contradiction, the present invention gradually reviews and reflects on preliminary answers to check whether they conform to the mathematical rules and problem-solving ideas guided by the prompt words. This can ensure that the problem-solving process and results conform to mathematical logic rules. Compared with existing technologies, this method overcomes the problems of lack of systematic verification in the problem-solving process and unreliable problem-solving results, thereby improving the accuracy and credibility of the problem-solving results.
[0046] 5. The present invention automatically returns to the prompt word matching and problem-solving task decomposition stage when the verification fails, forming a dynamic cyclic error correction and re-solving mechanism, which can achieve self-optimization and iterative improvement of the problem-solving process. Compared with the existing technology, it reduces the need for manual intervention and improves the problem-solving efficiency and intelligence level.
[0047] 6. By combining prompt words, task decomposition and verification steps in the problem-solving process, the present invention gradually displays the analysis of problem-solving conditions, formula application, calculation process and verification conclusions, which can significantly enhance the interpretability of the problem-solving process. Compared with the existing technology, it overcomes the drawbacks of "black box" reasoning and difficult to trace results when solving problems with large language models, and improves the application value of the problem-solving process in education and scientific research scenarios.
[0048] 7. By optimizing contextual information management during the problem-solving process, combined with step-by-step task execution and a cyclical verification mechanism, this invention can fully utilize all the information in complex problems and support the parsing and solving of multi-step, long-text math problems. Compared with existing technologies, this effectively avoids the problem of large language models forgetting key information when processing long problems, thereby broadening the application scenarios of math problem-solving.
[0049] 8. The present invention adds a problem-solving process demonstration function to the problem-solving process. While executing sub-tasks such as problem condition analysis, formula application, calculation verification and result induction, it generates a structured intermediate reasoning process and key calculation step display in real time, enabling users to intuitively understand the entire problem-solving process. Compared with the existing technology, it not only improves the transparency of problem-solving, but also enhances the interactivity and demonstration of the system in educational and teaching scenarios, helping students to master problem-solving ideas and methods; at the same time, this function can also be applied to scientific research or engineering calculation scenarios to realize auxiliary verification and result tracking of complex calculation processes, thereby improving the applicability and practical value of the system in professional decision-making assistance.
[0050] The present invention relates to the fields of artificial intelligence, natural language processing, and automatic mathematical problem-solving technology, and specifically to a method for solving mathematical problems and demonstrating the problem-solving process based on a large language model. The method is particularly suitable for scenarios with strong demands for understanding, reasoning, verification, and interpretability of results in dealing with complex mathematical problems, such as: educational and teaching assistance, scientific research computing support, intelligent decision-making assistance, online question-answering systems, mathematical question bank construction, intelligent teaching software, and other scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] Figure 1 is a flowchart of a mathematical problem-solving method based on a large language model described in Implementation Method 1;
[0052] Figure 2 is a flowchart of obtaining the classification result described in the seventh embodiment;
[0053] Figure 3 This is an architectural diagram of the problem-solving process described in Implementation Method 7;
[0054] Figure 4 This is a result display diagram of the problem-solving example described in Implementation Method 7. Implementation Method
[0055] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making any creative efforts shall fall within the scope of protection of the present invention.
[0056] Implementation Method 1
[0057] like Figure 1 As shown, a mathematical problem-solving method based on a large language model includes:
[0058] S1. Steps for collecting math problems;
[0059] S2, extracting and classifying text features of the math problem to obtain classification results;
[0060] S3: building a prompt word knowledge base, matching corresponding prompt words according to the classification results, and obtaining a question-answer sequence;
[0061] S4, decomposing the question-answering sequence into four subtasks: analyzing question conditions, applying key formulas, verifying calculations, and summarizing results, to obtain preliminary answers;
[0062] S5. A step of verifying the preliminary answer.
[0063] This implementation method adopts a multi-stage problem-solving process based on a large language model, dividing the processing of mathematical problems into steps such as collection, feature extraction, prompt word guidance, step-by-step problem-solving and verification. It optimizes the systematicness and standardization of the problem-solving process as a whole, supports decomposition-based reasoning for complex problems, and enhances the logical coherence of the problem-solving process and the reliability of the results.
[0064] Implementation Method 2
[0065] This embodiment is a further limitation of the first embodiment. Furthermore, the method for collecting math problems described in S1 is: receiving input math problems, filtering out characters and non-mathematical symbols that are not related to math problem solving, and converting the math problems into LaTeX or MathML format through a text normalization method.
[0066] This implementation improves the consistency and standardization of math problem input data by performing character cleaning and symbol normalization on the collected math problems and converting them uniformly into LaTeX or MathML formats, avoiding problem parsing deviations caused by non-standard formats and ensuring the basic accuracy of subsequent problem-solving steps.
[0067] Implementation Method 3
[0068] This embodiment further limits the first embodiment. Furthermore, the method for obtaining the classification result in S2 is:
[0069] S21. Segment the math problem using a word segmentation tool to obtain a word segmentation result;
[0070] S22, extracting mathematical symbols and variable names of the math problem by using regular expressions;
[0071] S23, obtaining the weight of the word segmentation result in the math problem by using the TF-IDF algorithm, and combining the position coding to enhance the position information of the word to obtain a weighted word feature vector;
[0072] S24. Input the term feature vector into the improved classification model based on MathBERT to predict the question type and obtain the classification result.
[0073] The improved method of the classification model based on MathBERT is as follows: based on the MathBERT model, a fully connected layer is added;
[0074] While the traditional MathBERT model has strong semantic representation capabilities for mathematical text, its output is primarily a general feature vector, lacking the ability to directly output specific classification tasks. To overcome this issue, the inventive team, based on an in-depth analysis of MathBERT's structure and its application limitations, proposed a structural improvement: adding at least one fully connected layer to the output of MathBERT's basic network. This directly maps the model's high-dimensional semantic feature vector output to the question type classification result space, thus enabling the model to achieve end-to-end classification capabilities.
[0075] This implementation makes structural improvements to the existing MathBERT model to better suit the needs of math problem classification tasks. This overcomes the problems encountered by the traditional MathBERT model, which still requires an external classification module, resulting in complex training and deployment processes, and the overall performance of the model being susceptible to the gap between feature separation and task adaptation.
[0076] The introduction of the fully connected layer not only realizes the conversion of feature vectors into specific classification labels, but also supports unified training using the cross-entropy loss function, thereby improving the model's ability to recognize semantic boundaries between various question types and classification accuracy.
[0077] The improved solution in this implementation effectively establishes a structural link between mathematical semantic modeling and task output, enabling the model to better identify question types while processing mathematical text, significantly improving the overall efficiency and intelligence of the problem-solving system. Compared to existing technologies, this structural optimization not only enhances system integration and deployment ease, but also demonstrates the inventive team's creative efforts in integrating model structure design with practical application requirements.
[0078] This implementation combines technologies such as word segmentation, regular expression extraction, TF-IDF weight calculation, and positional encoding to achieve question type prediction based on the improved MathBERT model, improving the accuracy and flexibility of math question classification, enabling the system to adapt to the diversity of question language expression and structural complexity, and enhancing the wide applicability of question type identification.
[0079] Implementation Method 4
[0080] This embodiment further limits the first embodiment. Furthermore, the method for obtaining the question-answer sequence in S3 is:
[0081] S31. Constructing a knowledge base of prompt words for math problems based on the math problems and the classification results, wherein the prompt words include general problem-solving steps generated by the large language model and key knowledge points and example problem ideas extracted from the textbook;
[0082] S32. Setting a search category label in the knowledge base according to the classification result;
[0083] S33, matching a prompt word set corresponding to the math problem in the knowledge base using the search category label;
[0084] S34. Integrate the matched prompt word set with the question to construct a question-answer sequence.
[0085] Based on the classification results, this implementation method retrieves a matching prompt word set through a prompt word knowledge base and integrates the question content to construct a question-answer sequence, thereby improving the prompt accuracy and logical guidance effect in the model problem-solving process, making the problem-solving process more organized and clear, and reducing the reasoning deviation caused by inaccurate prompts.
[0086] Implementation Method Five
[0087] This embodiment further limits the first embodiment. Furthermore, the method for obtaining the preliminary answer in S4 is:
[0088] S41. Divide the question-answering sequence into four subtasks: question condition analysis, key formula application, calculation verification, and result summary;
[0089] S42. Execute each subtask in sequence, respectively: analyze the question conditions, call the key formula for calculation, verify the calculation process, summarize the problem-solving results, and obtain a preliminary answer.
[0090] This implementation method divides the question-answering sequence into four subtasks: question condition analysis, key formula application, calculation verification, and result summary. Each link is executed in sequence to optimize the logical rigor and step completeness of the problem-solving process, and avoid logical breaks or information loss during the problem-solving process.
[0091] Implementation Method 6
[0092] This embodiment is a further limitation of the first embodiment. Furthermore, in S5, the method for verifying the preliminary answer and determining whether it is correct is as follows:
[0093] S51, review and reflect on the prompt words obtained in S3 and the preliminary answers obtained in S4, and check whether the execution process of each subtask conforms to the mathematical rules and the problem-solving ideas provided by the prompt words;
[0094] S52. Verify the problem-solving process and results by substitution, inverse reasoning, or proof by contradiction to determine whether they meet the requirements of the problem. If so, the verification passes; otherwise, the verification fails.
[0095] S53. If the verification is successful, the final answer is output; if the verification is unsuccessful, the process returns to S3 until the verification is successful.
[0096] This implementation introduces a review and reflection mechanism for the problem-solving process, and combines mathematical verification methods such as substitution, inverse reasoning, and proof by contradiction to verify the preliminary answers, effectively improving the rigor of the problem-solving process and the reliability of the results, and reducing the risk of reasoning errors in the model problem-solving process.
[0097] The specific technical means further described in the above embodiments 2 to 6 can also be reasonably combined with each other to form new embodiments.
[0098] Implementation Method Seven
[0099] This embodiment integrates the technical solutions described in the aforementioned multiple embodiments, combines actual application scenarios and the use process of the computer program product that implements the method described in the present invention, and further verifies and explains the technical effects of the present invention through specific examples.
[0100] A mathematical problem-solving method based on a large language model, which has the capabilities of classification guidance, task decomposition, and planning reflection, specifically includes the following steps:
[0101] Step 1: Enter the system, read the input math problem and load the model and prompt word template;
[0102] When the user turns on the math problem-solving system, the system first enters the startup state. At this point, the system will immediately start two parallel operations: on the one hand, through a specific input interface, it accurately reads the content of the math problem entered by the user, whether it is a simple arithmetic problem or a complex function, geometry proof problem, etc., it can accurately obtain the text information of the problem; on the other hand, the system loads a pre-trained model that supports long context to meet the context length of distributed thinking. At the same time, it loads matching prompt word templates, which are carefully designed according to different math problem types and problem-solving ideas, providing guidance for the subsequent problem-solving process. This step is one of the pre-steps, and the above information will be applied to steps two and three.
[0103] Step 2: Extract the text features of the questions and classify them;
[0104] like Figure 2As shown, this step is a pre-step. Using the math problems read in step 1 and the resources loaded, the problem text is analyzed to extract key features. Based on these features, the math problems are then categorized into corresponding categories, such as trigonometric functions or analytic geometry. The classification results are used in step 3 to match corresponding prompt words in the knowledge base.
[0105] Step 3: Match the corresponding prompt words in the knowledge base according to the category;
[0106] This step is part of the prompt word matching process. Based on the question category determined in Step 2, the system's knowledge base searches for and matches corresponding prompt words. These prompt words include common problem-solving strategies, key knowledge points, and common error points for different question types. These prompt words provide guidance for subsequent task analysis and problem-solving, with specific prompts for different question categories. This step is crucial, providing effective guidance and support for Step 4.
[0107] Step 4: Break the task into multiple subtasks, and use the dynamic feedback mechanism to execute and optimize them step by step;
[0108] like Figure 3 As shown, this step is one of the specific execution steps for solving the problem. After receiving the data from step three, this method breaks down the entire problem-solving task into multiple subtasks. At the same time, when these subtasks are executed step by step, the dynamic feedback mechanism begins to play a role. The system monitors the execution status of each subtask in real time, such as whether the calculation result is within a reasonable numerical range, whether the reasoning process conforms to mathematical logic, etc. Once deviations or difficulties are found during the execution process, the dynamic feedback mechanism will immediately feedback relevant information to the system. Based on the feedback information, the system optimizes and adjusts the execution strategy of subsequent subtasks, and may re-call relevant knowledge in the knowledge base and re-split and plan subtasks to ensure the accuracy of the entire problem-solving process.
[0109] Step 5: Reflect and verify the correctness to obtain the final correct answer;
[0110] This step summarizes Steps 3 and 4. After completing the step-by-step execution and optimization, the system reflects on and verifies the solution to check whether the answer complies with the mathematical logic and the problem requirements. The system uses various verification methods, such as substitution (for equation-solving problems, substituting the answer into the original equation to verify the equation) and reverse reasoning (starting from the answer and working backward to see if it can be restored to the problem conditions). If the verification result is correct, the entire problem-solving system is terminated; if not, the system returns to Step 3 and readjusts the problem-solving strategy and execution process.
[0111] Specifically, in step 1, the input math problem is read and the model and prompt word template are loaded. The specific implementation process includes the following steps:
[0112] Step 1.1 Read the input math problems in the form of text, files, etc., filter out non-mathematical symbols, and standardize the format (such as LaTeX). Store the standardized problems for subsequent steps;
[0113] In step 1.2, use the OPENAI library function in the Python programming language to call a large language model with a 1MB context from the cloud to support the context length of subsequent task decomposition and feedback thinking.
[0114] Step 1.3: Load the prompt word templates. These templates are carefully designed based on different math problem types (such as algebra, geometry, and probability) and problem-solving approaches (such as forward reasoning, backward reasoning, and induction). Once loaded, the system integrates the pre-trained model and prompt word templates so that they work together to provide support and guidance for subsequent steps.
[0115] Specifically, the feature extraction and classification of the extracted questions in step 2 specifically includes the following steps:
[0116] like Figure 2 As shown, the feature extraction and classification of the extracted questions in step 2 specifically include the following steps:
[0117] Step 2.1 Use the word segmentation tool to segment the text obtained in step 1 to obtain the word segmentation results;
[0118] Step 2.2: Use regular expressions to extract features from the title. Use regular expressions:
[0119] r'[+\-* / ^=<>()\[\]{}|! ~%@#$]'
[0120] Extract mathematical symbols,
[0121] Using regular expressions:
[0122] r′\b[a-zA-A]\w*\b′
[0123] Ability to recognize features such as variable names;
[0124] Step 2.3 uses the feature formula to extract the text features of the title. The TF-IDF weight is introduced to measure the importance of a word in the document. The calculation formula is:
[0125]
[0126] Here, tf(t,d) represents the frequency of word t in document d, N1 is the total number of documents, and df(t) is the number of documents containing word t. For a single question, both N1 and df(t) should be 1.
[0127] At the same time, combined with positional encoding and attention mechanisms, the model can perceive the positional information of words and focus on information at different positions when processing longer questions. Combining positional encoding technology to enhance the positional information perception of words, the following positional encoding formula is used:
[0128]
[0129] Among them, pos represents position, i represents dimension, d model Represents the dimensions of the model;
[0130] The attention mechanism is introduced to perform weighted processing on the word feature vectors, so that the model can focus on the word information that plays a key role in solving long questions. The calculation formula of the attention mechanism is:
[0131]
[0132] Among them, Q, K, V represent query, key, and value matrices respectively, d k Represents the dimension of the key;
[0133] Step 2.4: Build a classification model: Based on the MathBERT model, add a fully connected layer. The fully connected layer can map the feature vector output by MathBERT to the classification result space and finally output the classification result.
[0134] Step 2.5 uses both rule matching and model prediction to classify math text question types. For rule matching, a simple yet effective classification method based on regular expressions is used. Regular expressions are used to match features expected in specific questions. For example, in trigonometric questions, text containing trigonometric function names like sin, cos, and tan is common. In analytic geometry, keywords like coordinates, variables, and expressions are common.
[0135] At the same time, the classification model constructed in step 2.4 is also used for classification, using the cross entropy loss function, and the calculation formula is:
[0136]
[0137] Among them, y is the true label, is the probability predicted by the model, and N2 is the number of samples.
[0138] Based on the above content, construct the model classification formula:
[0139] y pred =argmax(softmax(W hidden ×h+b))
[0140] Among them, W hiddenis the weight matrix in the classification model, h is the feature vector, and b is the bias term.
[0141] Step 2.6 introduces a threshold decision mechanism to ensure the reliability of the classification results. This mechanism balances the results of rule matching and model prediction. When the confidence level of the model prediction is greater than 0.8, the model's classification result is used, as the model is highly confident in the classification. When the confidence level is less than or equal to 0.8, rule matching is activated as a fallback to ensure the accuracy of the classification results.
[0142] Specifically, in step 3, based on the questions and categories obtained in steps 1 and 2, the corresponding prompt words are matched in the knowledge base. The specific steps are as follows:
[0143] Step 3.1 Constructing Prompts: These prompts cover several key aspects, including common problem-solving strategies, key knowledge points, and key knowledge points. For different types of questions, constructing appropriate prompts focuses on two key aspects. First, leverage a large-scale thinking model or problem-solving model. While these models offer certain advantages in problem-solving strategies, they are often limited by model parameters or context length, making direct answers to complex questions often less successful. First, precisely and clearly define the problem type, for example, specifying whether it falls into specific categories such as geometric proof, function evaluation, and sequence operations. Then, input the complete problem content, along with all the required conditions, into the large-scale model. At this point, specific instructions are used to instruct the large-scale model to provide a general problem-solving framework. For example, for a function extremum problem, the instruction "Please list the key steps to solving this function extremum problem" can be given. The large-scale model, drawing on its own algorithms and knowledge base, will then outline key steps, such as determining the function's domain, taking derivatives, finding stationary points, and determining the properties of stationary points, providing high-level guidance for subsequent problem-solving. At the same time, this implementation method also refers to the textbook construction prompt words. It is necessary to first accurately locate the textbook chapter corresponding to the knowledge point involved in the question based on the knowledge points. Further, in this chapter, carefully extract the explanation of relevant concepts and theorems in the knowledge sorting part, deeply analyze the example problem ideas, clarify the basis and purpose of each step of the derivation, and summarize the problem-solving methods. Based on these extracted contents, prompts such as "Refer to the solution process of the general formula of the series in the textbook to explain the solution steps of this question" are formed. In this way, it can be closely combined with the authoritative content of the textbook, and each step in the problem-solving process can be strictly controlled to make the problem-solving process more logical and standardized. Finally, the distributed problem-solving guidance constructed for different question types is stored in the knowledge base to guide the task disassembly and execution of step four.
[0144] Step 3.2: Determine the search category: After classifying the math problem in Step 2, the system uses the resulting category information as a search basis. Categories such as trigonometric functions, analytic geometry, and calculus form the key index for search prompts in the knowledge base. For example, if Step 2 determines that the problem falls under the trigonometric function category, the system will set "trigonometric functions" as the search category label.
[0145] Step 3.3 Knowledge Base Matching: Based on the search categories determined in Step 3.2, the system performs an exact match within the knowledge base. The knowledge base utilizes a structured design, storing information such as problem-solving strategies, key knowledge points, and common error-prone areas, categorized by question type. The system then locates the storage area associated with the identified category and finds matching sets of prompts. For example, it may match the double angle formula for trigonometric functions, hints on the use of induced formulas, and common error-prone areas related to the domain and range of trigonometric functions.
[0146] Step 3.4: Constructing a Question-Answer Sequence: After completing the matching process, the system will output the selected prompts. These prompts will serve as guidance for solving the problem, serving the subsequent task analysis and problem-solving phases. Integrating these with the question, a question-answer sequence for the model will be constructed, providing directional guidance and knowledge support for in-depth problem-solving in Step 4.
[0147] Specifically, step 4 involves breaking down the task into multiple subtasks, and using a dynamic feedback mechanism to execute and optimize them step by step. The specific steps are as follows:
[0148] Step 4.1: After obtaining the question-answer sequence output from Step 3, the model will follow the instructions to break down the entire problem-solving task into multiple subtasks. This process is based on the question type and problem-solving strategy.
[0149] Step 4.2: Execute the subtasks step by step: After completing the task breakdown, the system will execute the subtasks in the order in which they were created. When executing each subtask, the system will follow the key knowledge points and problem-solving ideas in the prompt words.
[0150] During the execution of the subtasks in step 4.3, the dynamic feedback mechanism comes into play. The system reflects on and checks the execution of each subtask. First, it checks whether the calculation results are within a reasonable range. For example, when calculating the area of a triangle, if the resulting area is negative, it clearly does not conform to the actual situation, indicating that there may be an error in the calculation process. Second, it checks whether the reasoning process conforms to mathematical logic. For example, when proving a geometric theorem, the reasoning steps follow the corresponding axioms and theorems.
[0151] Step 4.4: If the dynamic feedback mechanism detects deviations or difficulties during execution, it immediately provides relevant information to the system. Based on this feedback, the system optimizes and adjusts the execution strategy for subsequent subtasks. This may involve re-calling relevant knowledge from the knowledge base, re-splitting and planning subtasks, and strengthening the application and processing of relevant knowledge points to ensure accuracy throughout the entire problem-solving process.
[0152] Specifically, in step five, the content obtained in steps three and four is summarized and reflected upon. The specific steps are as follows:
[0153] Step 5.1: Enter the reflection and verification phase. Review the entire problem-solving process, examining the logical rigor of each subtask and whether it adheres to the mathematical rules and the problem-solving ideas provided by the prompts in Step 3. For example, in a problem involving the simplification of trigonometric functions, reflect on whether the trigonometric formulas were used correctly and whether the transformations in each step were reasonable.
[0154] Step 5.2 Verify using verification methods: To ensure the correctness of the solution, the system uses a variety of verification methods, including substitution (for equation-solving problems, substituting the answer into the original equation to check whether the equation holds), reverse reasoning (starting from the answer, working backward to see if it can be restored to the problem conditions), and proof by contradiction.
[0155] Step 5.3 performs the corresponding processing based on the verification results of steps 5.1 and 5.2. If the verification results indicate that the answer conforms to the mathematical logic and the requirements of the question, that is, it passes the verification method such as substitution or inverse reasoning, then the entire problem-solving system ends and outputs the answer as the final correct answer. If the verification finds that the answer is incorrect, the system will backtrack to step 4. In step 4, the system will readjust the problem-solving strategy and execution process, and may re-call the prompt words in the knowledge base and re-disassemble the subtasks to correct the errors that occurred in the previous problem-solving process. The subtasks will then be executed again and verified until the correct answer is obtained.
[0156] The present invention, following the established steps, can create a simple automated mathematical problem-solving module that has excellent compatibility and can be seamlessly embedded into various existing systems, achieving plug-and-play functionality. The following details the process of verifying the beneficial effects of the present invention:
[0157] This verification is based on Figure 1The problem-solving system built using this invention mainly covers three major sections: data entry, problem-solving execution, and feedback thinking. The data entry section is responsible for collecting various math problems, entering them into the system, and properly storing them; the problem-solving execution section systematically classifies problems, calls adaptive prompts to guide reasoning, and inserts tasks; the feedback thinking section performs operations such as reflection optimization and answer summary, and ultimately outputs accurate problem-solving steps and answers.
[0158] Figure 4 The system presents example problems solved by the system and the resulting output. Upon startup, the system built by this invention first loads a pre-trained model. Subsequently, the user enters a math problem into the system, which quickly identifies the problem type and, based on the classification results, calls the corresponding prompt template, guiding the model through problem-solving in stages. During the problem-solving process, the system simultaneously reflects on and verifies the solution steps, and optimizes and adjusts any logical loopholes or errors discovered.
[0159] If any abnormality occurs during the above process, such as data entry errors, model operation failures, etc., the problem-solving execution module will terminate immediately, exit the system and feedback an error message.
[0160] from Figure 4 It can be seen from the problem-solving results that the mathematical problem-solving implemented by the present invention can not only obtain the correct answer, but also provide a clear and complete problem-solving idea. Taking the high school number series problem as an example, after classification, the system gradually disassembles, plans tasks, and analyzes the problem according to the prompt words, outputs each step of the reasoning process, and makes the problem-solving logic clear at a glance. At the same time, considering the diversity and complexity of mathematical problems, the present invention innovatively integrates the hierarchical task disassembly mechanism and the planning reflection framework to ensure the accuracy and completeness of problem-solving from multiple dimensions.
[0161] The technical solution provided by the present invention is further described in detail through the above specific embodiments in order to highlight the advantages and benefits of the technical solution provided by the present invention. However, the above specific embodiments are not intended to limit the present invention. Any reasonable modification and improvement of the present invention, combination of embodiments and equivalent replacement, etc. based on the spirit and principles of the present invention should be included in the scope of protection of the present invention.
[0162] Those skilled in the art will understand that the above description is only a preferred embodiment of the present invention, and the various embodiments disclosed in the present invention and / or the features described in the claims can be combined or coupled in various ways, even if such combinations or couplings are not explicitly described in the disclosure of the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art can still modify the technical solutions described in the aforementioned embodiments, or make equivalent substitutions for some of the technical features therein. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
[0163] Although preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they are aware of the basic inventive concepts. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention. Obviously, those skilled in the art may make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, the present invention is intended to include such changes and modifications as fall within the scope of the claims and their equivalents.
Claims
1. A mathematical problem-solving method based on a large language model, characterized in that: The method comprises: S1. Steps for collecting math problems; S2, extracting and classifying text features of the math problem to obtain classification results; S3: Build a prompt word knowledge base, match corresponding prompt words according to the classification results, and obtain the question and answer sequence; S4, decomposing the question-answering sequence into four subtasks: analyzing question conditions, applying key formulas, verifying calculations, and summarizing results, to obtain preliminary answers; S5. Verify the preliminary answer.
2. The method according to claim 1, characterized in that The method for collecting math problems described in S1 is: receiving input math problems, filtering out characters and non-mathematical symbols that are not related to math problem solving, and converting the math problems into LaTeX or MathML format using a text normalization method.
3. The method according to claim 1, characterized in that The method for obtaining the classification results described in S2 is: S21. Segment the math problem using a word segmentation tool to obtain a word segmentation result; S22, extracting mathematical symbols and variable names of the math problem by using regular expressions; S23, obtaining the weight of the word segmentation result in the math problem by using the TF-IDF algorithm, and combining the position coding to enhance the position information of the word to obtain a weighted word feature vector; S24. Input the term feature vector into the improved classification model based on MathBERT to predict the question type and obtain the classification result.
4. The method according to claim 1, wherein The method for obtaining the question-answer sequence described in S3 is: S31. Constructing a knowledge base of prompt words for math problems based on the math problems and the classification results, wherein the prompt words include general problem-solving steps generated by the large language model and key knowledge points and example problem ideas extracted from the textbook; S32. Setting a search category label in the knowledge base according to the classification result; S33, matching a prompt word set corresponding to the math problem in the knowledge base using the search category label; S34. Integrate the matched prompt word set with the question to construct a question-answer sequence.
5. The method according to claim 1, wherein The method described in S4 to obtain a preliminary answer is: S41. Divide the question-answering sequence into four subtasks: question condition analysis, key formula application, calculation verification, and result summary; S42. Execute each subtask in sequence, respectively: analyze the question conditions, call the key formula for calculation, verify the calculation process, summarize the problem-solving results, and obtain a preliminary answer.
6. The method according to claim 1, characterized in that In S5, the method for verifying whether the preliminary answer is correct is as follows: S51, review and reflect on the prompt words obtained in S3 and the preliminary answers obtained in S4, and check whether the execution process of each subtask conforms to the mathematical rules and the problem-solving ideas provided by the prompt words; S52. Verify the problem-solving process and results by substitution, inverse reasoning, or proof by contradiction to determine whether they meet the requirements of the problem. If so, the verification passes; otherwise, the verification fails. S53. If the verification is successful, the final answer is output; if the verification is unsuccessful, the process returns to S3 until the verification is successful.
7. A mathematical problem-solving device based on a large language model, characterized in that: The device comprises the following modules: Module for collecting math problems; A module for extracting and classifying text features of the math problem to obtain classification results; A module for building a prompt word knowledge base, matching corresponding prompt words based on classification results, and obtaining question-answer sequences; A module for decomposing the question-answering sequence into four subtasks: question condition analysis, key formula application, calculation verification, and result summarization, to obtain preliminary answers; A module for verifying the preliminary answer.
8. A computer storage medium for storing a computer program, characterized in that When the computer program is read by a computer, the computer executes the method according to any one of claims 1 to 6.
9. A computer comprising a processor and a storage medium, characterized in that When the processor reads the computer program stored in the storage medium, the computer executes the method according to any one of claims 1 to 6.
10. A computer program product, being a computer program, characterized in that When the computer program is read, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Cited By
Method and system for testing mathematical literal question solver
CN121350520A
Mathematical application problem solving method and system based on multi-path search
CN121809704A