Retrieval sample selection and multi-round error correction method for solving mathematical problem of large language model

By combining the thinking chain and program-assisted tips, a search sample selection based on error type and multiple rounds of error correction mechanisms are adopted to solve the problems of insufficient inference ability and weak calculation ability in solving mathematical text problems, achieving higher mathematical inference accuracy and efficiency, reducing computational costs, and expanding application potential.

CN119537567AInactive Publication Date: 2025-02-28TIANJIN UNIV

Patent Information

Application Number
CN202411616946.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-13
Publication Date
2025-02-28
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Large language models have problems such as insufficient inference ability, weak computing ability and limited data size in solving mathematical text problems. The existing methods have limitations in improving model performance.

Method used

A method combining thinking chains and program-assisted prompts is adopted to optimize the accuracy and efficiency of large language models in mathematical problem solving through error type-based search sample selection and multiple rounds of error correction mechanisms. The specific steps include using MATH and GSM8K datasets to train the model, generate inference paths containing the error correction process, and store them in the vector database as a search sample library. Given a mathematical problem, use prompt words and samples that successfully solve the problem as input, generate initial thinking chains and Python code, and execute them through the Python interpreter. If the code execution fails, select the search sample from the search sample library based on the error type and the semantic similarity of the problem, and perform the next round of thinking chain and code generation until the program runs normally.

Benefits of technology

By introducing a search sample selection mechanism based on error types and multiple rounds of error correction mechanisms, the mathematical reasoning ability of large language models is significantly optimized, the efficiency of answering complex mathematical problems is improved, the calculation cost of the model is reduced, and the application potential of the model in the field of mathematics is expanded.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119537567A_ABST
    Figure CN119537567A_ABST
Patent Text Reader

Abstract

The invention discloses a retrieval sample selection and multi-round error correction method for solving a mathematical problem of a large language model. The retrieval sample selection and multi-round error correction method comprises the following steps: S1, constructing a retrieval sample library; s2, a mathematical character problem is given, cue words and a plurality of fixed samples for successfully solving the problem are used as input, and the large language model is guided to generate an initial thinking chain and Python codes; s3, the generated initial Python code is submitted to a Python interpreter to be executed; s4, if the initial Python code is successfully executed, ending the process, and taking an execution result as a final answer; s5, if the execution of the initial Python code fails, selecting a retrieval sample from a pre-constructed retrieval sample library according to the error type and the problem semantic similarity returned by the Python interpreter; s6, taking the selected retrieval sample and the original mathematical character problem in the step S2 as new input, submitting the new input to the large language model again, and carrying out the next round of thinking chain and code generation; and S7, repeating the steps S2-S5 until the program runs normally or the preset maximum number of attempts is reached.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of artificial intelligence and natural language processing, and in particular to a retrieval sample selection and multi-round error correction method for solving mathematical problems of a large language model. Background Art

[0002] In recent years, artificial intelligence (AI) technology, especially large language models (such as GPT-3.5, GPT-40, etc.), has made breakthrough progress in the fields of natural language processing and artificial intelligence. These models have demonstrated amazing language understanding and generation capabilities, not only performing well in daily conversations and text creation, but also showing strong potential in various complex tasks, such as language generation, text classification, machine translation, semantic understanding, etc. However, large models still face challenges in practical application, mainly due to the model's lack of planning ability, logical reasoning ability and the influence of Hallucination 0.

[0003] Solving math problems requires not only language comprehension, but also logical reasoning, abstract thinking, and precise calculation capabilities, which makes the study of math problems an ideal scenario for improving and testing the comprehensive cognitive capabilities of large language models. Mathematical problems include various types, such as arithmetic, math word problems, geometry, automatic theorem proving, and multimodal math problems.

[0004] The present invention focuses on the problem of solving mathematical word problems with large language models. Mathematical word problems are mathematical problems presented in text form, which are common in educational scenarios such as elementary schools, junior high schools, and high schools. This form of problem requires the solver to deeply understand the information provided, identify relevant mathematical concepts, and construct appropriate equations or expressions to solve the problem. Structurally, each mathematical word problem contains a core question (Q) and the corresponding final answer (A), forming the most basic "question-answer" pair. Some questions may contain equations (E) required to solve the problem, forming a "question-equation-answer" structure; while others may provide detailed problem-solving steps or reasoning processes (R), forming a "question-reasoning-answer" format.

[0005] The format of mathematical text problems is very suitable for large models to process, because these problems are usually described in natural language, including the problem background, known conditions and the problem to be solved, which is highly consistent with the text input format that large models are good at processing. In addition, the difficulty of mathematical text problems is usually between simple arithmetic operations and highly abstract mathematical proofs, providing an ideal challenge level for large models.

[0006] In order to improve the ability of large language models in solving mathematical text problems, researchers have explored various methods, including but not limited to:

[0007] 1. Design more effective prompting strategies, such as Chain of Thought 0, Complex Chain of Thought 0, Least to Most Prompt 0, etc.

[0008] 2. Combine with external tools and knowledge bases, such as Program-Aided Language 0, Thinking Program 0, etc.

[0009] 3. Improve the model’s training data and methods00.

[0010] However, these methods still have some limitations:

[0011] 1. Although the natural language reasoning method represented by the thinking chain can significantly improve the reasoning ability of the model when solving mathematical problems, it still has problems such as insufficient reasoning ability, weak computing power, and being restricted by the size of the data.

[0012] 2. Combining methods with external tools, such as using the Python interpreter to run the code generated by the model, can make up for the computational deficiencies of the model, but when solving complex mathematical problems, it is not as easy to generate executable code as on simple data sets.

[0013] 3. Improve model training data is often concentrated in the pre-training stage of large models or the fine-tuning stage of specific tasks. Although this can improve the overall performance of the model, it requires a lot of computing resources and the training process is expensive and time-consuming.

[0014] Given these limitations of existing methods, there is an urgent need for a new approach that combines the advantages of existing methods while overcoming their limitations to improve the performance of large language models in solving mathematical text problems. Summary of the invention

[0015] The purpose of the present invention is to overcome the shortcomings of the prior art and provide a retrieval sample selection and multi-round error correction method for solving large language model mathematical problems. The method combines the advantages of chain of thought (CoT) and program auxiliary prompt (PAL), and introduces a retrieval sample selection and multi-round correction mechanism based on error types to improve the accuracy and efficiency of large language models in solving complex mathematical problems.

[0016] The objective of the present invention is achieved through the following technical solutions:

[0017] A retrieval sample selection and multi-round error correction method for solving mathematical problems of a large language model, comprising:

[0018] S1. Using the training data in the MATH dataset and the GSM8K dataset as seeds, using prompt engineering, guide the large language model to generate reasoning paths including error correction processes, and then store these reasoning paths in the vector database Milvus as a retrieval sample library;

[0019] S2. Given a math word problem, use the prompt word and a number of fixed samples of successful problem solving as input to guide the large language model to generate an initial thought chain and Python code;

[0020] S3. Submit the generated initial Python code to the Python interpreter for execution;

[0021] S4. If the initial Python code is executed successfully, the process ends and the execution result is used as the final answer;

[0022] S5. If the initial Python code execution fails, select a retrieval sample from a pre-built retrieval sample library based on the error type returned by the Python interpreter and the semantic similarity of the question;

[0023] S6. The selected retrieval sample and the initial thought chain and Python code generated by the large language model in step S2 are used as new inputs and submitted to the large language model again for the next round of thought chain and code generation;

[0024] S7. Repeat steps S2-S5 until the program runs normally or the preset maximum number of attempts is reached.

[0025] Furthermore, in step S5, when selecting a retrieval sample from the pre-built retrieval sample library, a TopK approximate nearest neighbor ANN search is performed in the retrieval sample library, and the inner product IP is used as a similarity measure.

[0026] Furthermore, the all-MiniLM-L6-v2 model in the Sentence Transformers library is used to vectorize mathematical problems.

[0027] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the retrieval sample selection and multi-round error correction method for solving large language model mathematical problems are implemented.

[0028] The present invention also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the retrieval sample selection and multi-round error correction method for solving large language model mathematical problems are implemented.

[0029] Compared with the prior art, the technical solution of the present invention has the following beneficial effects:

[0030] 1. Optimize the mathematical reasoning ability of the model: This invention can help large language models generate effective reasoning paths more accurately by introducing a retrieval sample selection mechanism based on error types. By analyzing the error types and selecting corresponding retrieval samples, the mathematical reasoning chain of the model is further optimized, making it more logical and accurate in mathematical reasoning tasks.

[0031] 2. Improve the efficiency of solving complex problems: With the support of multiple rounds of error correction mechanisms, this method allows the large language model to self-correct the code errors generated for the first time, avoiding the repeated generation of wrong answers. By continuously searching, analyzing and correcting the code, the error correction mechanism of the present invention improves the efficiency of the model in solving multi-step reasoning scenarios, especially in solving complex mathematical problems, and can quickly locate the problem and gradually improve the results.

[0032] 3. Reduce the computational cost of the model: This invention reduces the frequency of invalid computational operations by combining a vector database and an approximate nearest neighbor search (ANN) sample retrieval method, thereby reducing the computational cost of large models. This method does not need to completely rely on the model to repeatedly generate reasoning chains, but instead improves the intelligence and efficiency of the system through vectorized retrieval and retrieval sample selection, reducing the waste of computing resources.

[0033] 4. Expand the application scenarios of the model: The combination of the chain of thought (CoT) and the program auxiliary prompt (PAL) of the present invention has the advantages of both natural language processing and code reasoning, so that the model can adapt to a variety of mathematical problems and is suitable for various mathematical scenarios that require multi-step reasoning, code generation and execution. It is especially suitable for the automated solution of mathematical text problems, which expands the application potential of large language models in education, scientific research and other fields.

[0034] Through the above improvements, the present invention can effectively improve the accuracy and efficiency of large language models in solving mathematical problems, make up for the deficiencies of existing methods in reasoning ability and calculation accuracy, and provide stronger technical support for the in-depth application of large language models in the field of mathematics. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] Figure 1a and Figure 1b It is a schematic diagram of the process of the present invention in a specific embodiment.

[0036] Figure 2 It is a schematic diagram of sample generation prompt words.

[0037] Figure 3 It is a schematic diagram of the sample generation process.

[0038] Figure 4 It is a prompt word for result judgment.

[0039] Figure 5 It is a schematic diagram of the retrieval method. DETAILED DESCRIPTION

[0040] The present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.

[0041] In the process of solving mathematical word problems, a mathematical word problem P can be represented as a pair consisting of a problem description D and an expected solution A: P = (D, A). The problem description D is a natural language text that describes the conditions and requirements of the problem; the expected solution A is a mathematical expression, a numerical value, or a series of steps that represents the solution to the problem.

[0042] LLM (Large Language Model) is a parameterized probabilistic model M for generating natural language text: M:D→T. Model M is trained with a large amount of text data and has the ability to understand and generate natural language text.

[0043] In the context of multiple rounds of interaction, we define an interaction sequence I = {(D, R_1), (F_1, R_2), ..., (F_{n-1}, R_n)}, where D is the initial question description, R_i is the model's response in the i-th round, and F_i is the feedback or additional information in the i-th round. The response R_i of each round may contain the solution process S_i and the intermediate result T_i. We then introduce a retrieval sample set E = {(D_1, S_1, A_1), (D_2, S_2, A_2), ..., (D_k, S_k, A_k)}, where k is the number of samples, S_i represents the solution process of question D_i, and A_i is the correct answer to question D_i.

[0044] In each round of interaction, given the current question state (including the initial description D, previous interaction history, and current feedback F_i) and the retrieval sample set E, the model M needs to generate a new response R_{i+1}.

[0045] Formally stated, in the i-th round of interaction, the goal of the LLM model M is to generate the response: R_{i+1}=M(E,D,I_{1:i},F_i)

[0046] Where I_{1:i} represents the interaction history of the first i rounds. During multiple rounds of interaction, if the response R_{i+1} generated by the model in the i+1th round is considered a satisfactory solution, it is taken as the final solution T, that is, T = R_{i+1}. The final solution T is the result after multiple rounds of interaction, and its correctness is evaluated by comparing it with the expected solution A, that is, T≈A. This process allows the model to gradually improve its solution through multiple rounds of interaction until a satisfactory result is achieved or a predetermined number of interaction rounds is reached.

[0047] This embodiment first uses the training set data in the MATH dataset and the GSM8K dataset as seeds, and uses a specific prompting project to guide the large language model to generate a reasoning path that includes an error correction process. These reasoning paths are then stored in a vector database (Milvus database) as a retrieval sample library. In the subsequent reasoning process, when an error occurs when the code generated by the large language model is executed, a search is performed based on the returned error type and the semantic similarity of the mathematical problem, and the K reasoning paths with the highest similarity are found from the pre-built retrieval sample library. These reasoning paths are input as samples to the large model to assist the model in self-correction until the program runs correctly and the final answer is obtained.

[0048] This comprehensive approach can effectively improve the accuracy and efficiency of the model in solving complex mathematical text problems, while also having good adaptability and scalability.

[0049] Specifically, the multi-round program-assisted error correction prompt method based on error type retrieval samples proposed in this embodiment has the following overall process: Figure 1a and Figure 1b As shown. Includes:

[0050] S1. Using the training data in the MATH dataset and the GSM8K dataset as seeds, using prompt engineering, guide the large language model to generate reasoning paths including error correction processes, and then store these reasoning paths in the vector database Milvus as a retrieval sample library;

[0051] S2. Given a math word problem, use the prompt word and a number of fixed samples of successful problem solving as input to guide the large language model to generate an initial thought chain and Python code;

[0052] S3. Submit the generated initial Python code to the Python interpreter for execution;

[0053] S4. If the initial Python code is executed successfully, the process ends and the execution result is used as the final answer;

[0054] S5. If the initial Python code execution fails, select a retrieval sample from a pre-built retrieval sample library based on the error type returned by the Python interpreter and the semantic similarity of the question;

[0055] S6. The selected retrieval sample and the initial thought chain and Python code generated by the large language model in step S2 are used as new inputs and submitted to the large language model again for the next round of thought chain and code generation;

[0056] S7. Repeat steps S2-S5 until the program runs normally or the preset maximum number of attempts is reached.

[0057] The above method continuously optimizes the problem-solving process through multiple rounds of interaction and retrieval sample selection, thereby improving the success rate of solving complex mathematical word problems.

[0058] Specifically, the construction of the search sample library in step S1 is as follows:

[0059] First, about the generation of retrieval samples: using MATH 0 and GSM8K 0 The training set of the data set is used to construct a retrieval sample library. The reasoning paths including the error correction process are alternately formed by natural language, program code and code execution results. These reasoning paths are called samples in this embodiment, and the samples retrieved in real time using the retriever (Milvus in this embodiment) are called retrieval samples. These samples are used as examples in context learning and are used as inputs of the large model together with questions and prompt words.

[0060] After verification with the correct answer, the sample with the correct answer is stored in Milvus 0 Vector database, which is convenient for subsequent rapid retrieval.

[0061] Specific use such as Figure 2 The prompt words and a small number of fixed samples shown generate feedback in a specified format, including the reasoning process in natural language and Python code. The Python code is extracted and run using the Python interpreter. If the code execution fails, the error information is fed back to the model, requiring it to correct the code. This process is repeated many times until the correct result is obtained. After running the program for a certain number of iterations, if it still fails to run successfully or does not obtain the correct result, the reasoning path is discarded. After obtaining the correct return of the program, the result is compared with the standard answer. If it is correct, the reasoning path is retained.

[0062] The overall sample generation process is as follows: Figure 3 shown.

[0063] Secondly, regarding the control of sample quality: the correctness of the samples is ensured by comparing the generated answers with the standard answers in the MATH dataset and GSM8K dataset.

[0064] The rule-based method that comes with the dataset will produce a large number of misjudgment results, mainly for the following reasons:

[0065] (1) The same result but in different formats, for example, one is a fraction and the other is a decimal, but they are equal.

[0066] (2) Due to the limitations of the program's output format, the results of program calculations are generally numerical, but this is mathematically equal to some numbers such as 0.9999999999... and 1.

[0067] (3) Different expressions, for example, \text{11,\\! 180} is equal to 11180, and pi is equal to 3.14159265358

[0068] These situations are difficult to match using simple rules, so this embodiment uses a judgment function driven by a large model to judge the correctness of the result based on the rules.

[0069] The prompt words used are as follows: Figure 4 shown.

[0070] Compared with using only the rule-based judgment function provided by MATH, the method combining rules and large models has a higher accuracy rate. The combination method is: when the rule judges that two results are not equal, the large model is used for judgment. If the large model judges that they are equal, the two results are considered equal. Using this method, you can reduce the number of misjudgments and improve the accuracy of retrieval samples.

[0071] Finally, the construction of the retrieval sample library in this embodiment is mainly based on the Milvus database, and has the following key points:

[0072] 1. Vector representation: This example uses all-MiniLM-L6-v2 in the Sentence Transformers library 0 The model vectorizes mathematical problems. The main reasons for choosing this model are as follows: efficiency, as a lightweight model, it strikes a good balance between performance and computational cost; versatility, it has been trained on diverse data and is suitable for various text embedding tasks; performance, despite its small size, it performs well in multiple benchmarks; multilingual ability, it can handle multiple languages, which is conducive to handling diverse mathematical problems. These characteristics make the all-MiniLM-L6-v2 model very suitable for efficient and effective vectorization of mathematical problems.

[0073] 2. Index construction: Use the Milvus database to build an efficient vector index, using the IVF_FLAT index.

[0074] The reasons for choosing IVF_FLAT are: it balances query speed and accuracy. For medium-sized data sets, IVF_FLAT provides good query performance while maintaining high accuracy; it is suitable for frequent updates. Compared with HNSW, IVF_FLAT is easier to perform incremental updates, which is important for retrieving sample libraries; it has a small memory footprint. Compared with HNSW, IVF_FLAT has lower memory consumption and is suitable for resource-constrained environments.

[0075] In addition, the selection of retrieval samples is as follows: Based on the vector representation of the current problem, a TopK approximate nearest neighbor (ANN) search is performed in Milvus, and the inner product (IP) is used as the similarity metric. The reasons for choosing IP are: it is suitable for normalized vectors. The all-MiniLM-L6-v2 model outputs normalized vectors. For such vectors, IP is equivalent to cosine similarity, but has higher computational efficiency; it retains directional information. Compared with Euclidean distance, IP better retains the directional information of the vector, which is important for capturing semantic similarity; it has high computational efficiency and is simple to calculate, which is conducive to improving the efficiency of large-scale retrieval.

[0076] like Figure 5 As shown in the figure, while performing similarity search, this study also considers the important factor of error type. By extracting error type information from samples and performing precise matching during the search process, the method of the present invention can identify samples that are not only semantically similar to the current question, but also have the same error type. This multi-dimensional matching strategy significantly improves the relevance of samples, thereby enhancing the efficiency and effectiveness of large language models learning from these samples.

[0077] Specifically, in order to prove the feasibility of the method proposed in the present invention, the method was experimented on two data sets, MATH and GSM8K. The specific evaluation indicators and experimental results are introduced as follows.

[0078] (1) Evaluation indicators

[0079] This embodiment uses accuracy as the main evaluation indicator. The specific method is as follows: extract the final answer from the output generated by the large prediction model. Use the combined rules and the judgment method of the large model described in the above sample quality control content to compare the extracted answer with the standard answer (ground truth) in the data set. Calculate the proportion of correct answers as the accuracy of the model.

[0080] (2) Dataset

[0081] This example mainly uses two data sets that are widely used to test the mathematical reasoning ability of large models:

[0082] 1. MATH dataset. Contains 12,500 challenging competition math word problems, each with a complete step-by-step solution. These solutions can be used to guide the model in generating derivations and explanations of answers to questions. Since the test set of MATH is large (5000 samples), considering the API call cost, this example uses a widely used subset MATH-minival as the test set. This subset contains 500 samples and is used in related research by OpenAI. 0 MATH-minival is evenly distributed and covers questions of various types and difficulties, which can truly reflect the ability of large models in mathematical reasoning.

[0083] 2. GSM8K dataset. Released by OpenAI, it contains 8,500 high-quality, language-diverse elementary school math word problems. These problems are written by humans and are divided into 7,500 training problems and 1,000 test problems. Each problem requires 2 to 8 steps to solve, mainly involving basic arithmetic operations (addition, subtraction, multiplication, and division) to get the final answer. GSM8K is often used to evaluate the mathematical reasoning ability of large models.

[0084] The reason for selecting these two data sets is that they are moderately difficult and are widely used to test the mathematical reasoning capabilities of large models. Therefore, the experiments in this embodiment will also be conducted based on these two data sets.

[0085] (3) Baseline method

[0086] In order to comprehensively evaluate the effect of the method of the present invention, this example selects the following commonly used baseline methods for comparison:

[0087] 301. Zero-Shot CoT 0

[0088] This method uses a simple prompt "Let's think step by step" to stimulate the model's step-by-step reasoning ability based on the chain of thoughts. No additional samples are required, and the chain of thoughts ability that the large model has learned during pre-training and supervised fine-tuning is utilized.

[0089] 302. Few-Shot CoT

[0090] Based on the chain of thought, a small number of manually written fixed samples are used as prompts to stimulate the model's step-by-step reasoning ability. This method requires adjusting the samples according to different tasks.

[0091] 303. Zero-Shot Program Assist Alert (Zero-Shot PAL)

[0092] The zero-shot PAL method relies on the model's own ability to generate code without providing samples, and executes to get the answer. In this case, since there is no similar training in the pre-training stage and no fine-tuning, the effect will be relatively poor. This baseline method is mainly used to reflect the impact of few samples on the generation effect.

[0093] 304. Few-Shot Program Assist Alert (Few-Shot PAL)

[0094] The PAL method has a fixed number of 5 samples. Because of these samples, the generated code will be more accurate and the answers obtained by execution will be more accurate.

[0095] (4) Experimental results and analysis

[0096] Using the evaluation methods mentioned above, experiments were conducted on two datasets and the performance of each method was compared. The specific experimental results are shown in Table 1:

[0097] Table 1 Accuracy of each method on different datasets

[0098]

[0099]

[0100] According to the experimental results, the following analyses can be drawn:

[0101] 401. Comparison between methods:

[0102] On all three models, the proposed method achieved the best performance, which is significantly improved compared with other methods.

[0103] The 5-shot CoT method outperforms the Zero-Shot CoT method in all cases, which demonstrates the effectiveness of few-shot learning in mathematical reasoning tasks.

[0104] The PAL method (either zero-shot or few-shot) performs worse than the CoT method in most cases, which may be due to the difficulty of directly generating codes.

[0105] The method of the present invention makes up for the shortcomings of the PAL method to a certain extent, and combines the advantages of the two methods to make the generated code more accurate, thereby improving the performance of the model.

[0106] 402. Comparison between models:

[0107] The DeepSeek-V2-0628 model performs best on all methods, showing its strong mathematical reasoning ability.

[0108] The moonshot-v1-8k model has weaker overall performance, but after applying this method, the performance improvement is most significant.

[0109] This shows that the improvement brought by the proposed method on models with weaker performance (such as moonshot-v1-8k) is more significant, which shows that the method helps to make up for the shortcomings of the model itself.

[0110] 403. Comparison between data sets:

[0111] All models generally perform better on the GSM8K dataset than on the MATH-minival dataset. This may be because the problems in the GSM8K dataset are relatively simple and mainly involve elementary school-level math problems.

[0112] The MATH-minival dataset may contain more complex and diverse mathematical problems.

[0113] The performance variation on the MATH-minival dataset is even greater, likely reflecting the diversity and complexity of the problems on this dataset.

[0114] In general, the experimental results strongly support the effectiveness and excellence of the method of the present invention.

[0115] This method can not only improve model performance, but also has a more obvious improvement effect on models that have certain basic capabilities but have not been trained with a large amount of mathematical data.

[0116] This shows that the method of the present invention has the potential to become an effective tool for improving the mathematical reasoning ability of large language models.

[0117] (5) Ablation experiment

[0118] In order to further verify the effectiveness of the method of the present invention, the present invention conducted a series of ablation experiments. These experiments are aimed at analyzing the contribution of each component in the method and how they affect the overall performance. The main ablation experiments include:

[0119] 501. The Impact of Wrong Type Retrieval Sample Selection. This paper compares the performance difference between using wrong type retrieval sample selection and not using wrong type retrieval sample selection (i.e. using random samples). This helps to understand the role of wrong type retrieval sample selection strategy in improving model performance.

[0120] 502. The impact of multi-round error correction mechanism. This paper tests the performance difference between using multi-round error correction mechanism and not using multi-round error correction mechanism. This helps to understand the role of multi-round error correction mechanism in improving model performance.

[0121] 503. Effect of sample size. Increasing the sample size from 700 to 4897 brings 1.2% and 0.8% performance improvements on the MATH-minival and GSM8K datasets, respectively.

[0122] This suggests that a larger sample base can provide more diverse examples, helping the model handle various types of problems.

[0123] However, due to the difficulty in obtaining high-quality data, the size of the sample library cannot be increased indefinitely, and with current experimental methods, it is impossible to obtain more high-quality samples.

[0124] Table 2 Ablation experiment results

[0125]

[0126] From the ablation experiment results in Table 2, we can see that:

[0127] 1. The impact of retrieval sample selection:

[0128] Experimental results show that retrieval sample selection improves performance by 3.4% and 2.8% on the MATH-minival and GSM8K datasets, respectively, compared to random sample selection. This confirms the important role of retrieval sample selection strategy in improving model performance. By selecting samples that are more relevant to the current problem, the model is better able to understand and solve specific types of problems.

[0129] 2. Impact of multi-round error correction mechanism:

[0130] That is, without multi-round error correction, the model performance dropped by 10.2% and 9.4% on the MATH-minival and GSM8K datasets, respectively. This significant performance drop highlights the key role of the multi-round error correction mechanism in improving model performance. By allowing the model to try and correct errors multiple times, the multi-round error correction mechanism greatly improves the model's ability to solve complex mathematical problems. This result emphasizes the importance of identifying and correcting errors in the process of solving mathematical problems, and also illustrates the advantages of the method proposed in this invention in dealing with complex problems.

[0131] 3. Impact of sample library size:

[0132] Increasing the sample size from 700 to 4897 brought 1.2% and 0.8% performance improvements on the MATH-minival and GSM8K datasets, respectively. This shows that a larger sample library can provide more diverse examples, which helps the model handle various types of problems. However, due to the difficulty in obtaining high-quality data, the size of the sample library cannot be increased indefinitely. With the current experimental methods, it is impossible to obtain more high-quality samples. In the future, other methods can be used to obtain more high-quality samples, increase the size of the sample library, and further improve model performance.

[0133] Preferably, the embodiments of the present application also provide a specific implementation of an electronic device capable of implementing all steps in the retrieval sample selection and multi-round error correction method for solving a large language model mathematical problem in the above embodiment, and the electronic device specifically includes the following contents:

[0134] Processor, memory, communications interface and bus;

[0135] Among them, the processor, memory, and communication interface communicate with each other through the bus; the communication interface is used to realize information transmission between related devices such as server-side devices, metering devices, and user-side devices.

[0136] The processor is used to call the computer program in the memory. When the processor executes the computer program, all steps in the retrieval sample selection and multi-round error correction method for solving large language model mathematical problems in the above embodiment are implemented.

[0137] An embodiment of the present application also provides a computer-readable storage medium capable of implementing all steps of the retrieval sample selection and multi-round error correction method for solving large language model mathematical problems in the above-mentioned embodiment. A computer program is stored on the computer-readable storage medium. When the computer program is executed by a processor, all steps of the retrieval sample selection and multi-round error correction method for solving large language model mathematical problems in the above-mentioned embodiment are implemented.

[0138] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the hardware + program embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0139] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0140] Although the present application provides method operation steps such as embodiments or flow charts, more or fewer operation steps may be included based on conventional or non-creative labor. The order of steps listed in the embodiments is only one way of executing the order of many steps and does not represent the only execution order. When the actual device or client product is executed, it can be executed in the order of the method shown in the embodiments or the drawings or in parallel (for example, in a parallel processor or multi-threaded processing environment).

[0141] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0142] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device that implements the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.

[0143] These computer program instructions may also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, whereby the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.

[0144] The present invention is not limited to the embodiments described above. The above description of the specific embodiments is intended to describe and illustrate the technical solution of the present invention. The above specific embodiments are merely illustrative and not restrictive. Without departing from the scope of the present invention and the scope of protection of the claims, a person of ordinary skill in the art can also make many forms of specific changes under the guidance of the present invention, which all fall within the scope of protection of the present invention.

[0145] References

[0146] [1] S. Bubeck et al., "Sparks of Artificial General Intelligence: Early experiments with GPT-4," Apr.13, 2023, arXiv:arXiv:2303.12712.doi:10.48550 / arXiv.2303.12712.

[0147] [2] J.Li, K.Bali,Eds.,Singapore:Association for ComputationalLinguistics,Dec.2023,pp.6449–6464.doi:10.18653 / v1 / 2023.emnlp-main.397.

[0148] [3] J.Ahn, R.Verma, R.Lou, D.Liu, R.Zhang, and W.Yin, "Large Language Models for Mathematical Reasoning: Progresses and Challenges," Apr.05, 2024, arXiv:arXiv:2402.00157.doi:10.48550 / arXiv.2402.00157.

[0149] [4]K.Cobbe et al.,“Training Verifiers to Solve Math Word Problems,”Nov.17,2021,arXiv:arXiv:2110.14168.Accessed:Mar.21,2023.[Online].Available:http: / / arxiv.org / abs / 2110.14168

[0150] [5]J.Wei et al.,“Chain-of-Thought Prompting Elicits Reasoning inLarge Language Models,”Advances in Neural Information Processing Systems,vol.35,pp.24824–24837,Dec.2022.

[0151] [6]Y.Fu,H.Peng,A.Sabharwal,P.Clark,and T.Khot,“Complexity-BasedPrompting for Multi-step Reasoning,”presented at the The EleventhInternational Conference on Learning Representations,Sep.2022.Accessed:Sep.25,2024.[Online].Available:https: / / openreview.net / forum?id=yf1icZHC-l9

[0152] [7]D.Zhou et al.,“Least-to-Most Prompting Enables Complex Reasoningin Large Language Models,”Oct.06,2022,arXiv:arXiv:2205.10625.Accessed:Mar.08,2023.[Online].Available:http: / / arxiv.org / abs / 2205.10625

[0153] [8]L.Gao et al.,“PAL:Program-aided Language Models,”in Proceedings ofthe 40th International Conference on Machine Learning,PMLR,Jul.2023,pp.10764–10799.Accessed:Jun.26,2024.[Online].Available:https: / / proceedings.mlr.press / v202 / gao23f.html

[0154] [9]W.Chen,X.Ma,X.Wang,and W.W.Cohen,“Program of Thoughts Prompting:Disentangling Computation from Reasoning for Numerical Reasoning Tasks,”Oct.22,2023,arXiv:arXiv:2211.12588.doi:10.48550 / arXiv.2211.12588.

[0155]

[10] Z.Shao et al.,“DeepSeekMath:Pushing the Limits of MathematicalReasoning in Open Language Models,”Apr.27,2024,arXiv:arXiv:2402.03300.Accessed:Aug.24,2024.[Online].Available:http: / / arxiv.org / abs / 2402.03300

[0156]

[11] H.Luo et al.,“WizardMath:Empowering Mathematical Reasoning forLarge Language Models via Reinforced Evol-Instruct,”Aug.18,2023,arXiv:arXiv:2308.09583.doi:10.48550 / arXiv.2308.09583.

[0157]

[12] D.Hendrycks et al.,“Measuring Mathematical Problem Solving Withthe MATH Dataset,”Nov.08,2021,arXiv:arXiv:2103.03874.doi:10.48550 / arXiv.2103.03874.

[0158]

[13] J.Wang et al.,“Milvus:A Purpose-Built Vector Data ManagementSystem,”in Proceedings of the 2021 International Conference on Management ofData,Virtual Event China:ACM,Jun.2021,pp.2614–2627.doi:10.1145 / 3448016.3457550.

[0159]

[14] N.Reimers and I.Gurevych,“Sentence-BERT:Sentence Embeddings usingSiamese BERT-Networks,”in Proceedings of the 2019 Conference on EmpiricalMethods in Natural Language Processing and the 9th International JointConference on Natural Language Processing(EMNLP-IJCNLP),Hong Kong,China:Association for Computational Linguistics,2019,pp.3980–3990.doi:10.18653 / v1 / D19-1410.

[0160]

[15] H.Lightman et al.,“Let’s Verify Step by Step,”May 31,2023,arXiv:arXiv:2305.20050.doi:10.48550 / arXiv.2305.20050.

[0161]

[16] T.Kojima,S.(Shane)Gu,M.Reid,Y.Matsuo,and Y.Iwasawa,“LargeLanguage Models are Zero-Shot Reasoners,”Advances in Neural InformationProcessing Systems,vol.35,pp.22199–22213,Dec.2022.

Claims

1. A retrieval sample selection and multi-round error correction method for solving mathematical problems of large language models, characterized in that: include: S1. Using the training data in the MATH dataset and the GSM8K dataset as seeds, using prompt engineering, guide the large language model to generate reasoning paths including error correction processes, and then store these reasoning paths in the vector database Milvus as a retrieval sample library; S2. Given a math word problem, use the prompt word and a number of fixed samples of successful problem solving as input to guide the large language model to generate an initial thought chain and Python code; S3. Submit the generated initial Python code to the Python interpreter for execution; S4. If the initial Python code is executed successfully, the process ends and the execution result is used as the final answer; S5. If the initial Python code execution fails, select a retrieval sample from a pre-built retrieval sample library based on the error type returned by the Python interpreter and the semantic similarity of the question; S6. The selected retrieval sample and the initial thought chain and Python code generated by the large language model in step S2 are used as new inputs and submitted to the large language model again for the next round of thought chain and code generation; S7. Repeat steps S2-S5 until the program runs normally or the preset maximum number of attempts is reached.

2. According to claim 1, a retrieval sample selection and multi-round error correction method for solving large language model mathematical problems is characterized in that: In step S5, when selecting a retrieval sample from the pre-built retrieval sample library, a TopK approximate nearest neighbor ANN search is performed in the retrieval sample library, and the inner product IP is used as the similarity metric.

3. According to claim 1, a retrieval sample selection and multi-round error correction method for solving large language model mathematical problems is characterized in that: The all-MiniLM-L6-v2 model from the Sentence Transformers library is used to vectorize math problems.

4. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of the retrieval sample selection and multi-round error correction method for solving large language model mathematical problems as described in any one of claims 1 to 3 are implemented.

5. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the retrieval sample selection and multi-round error correction method for solving large language model mathematical problems described in any one of claims 1 to 3 are implemented.

Citation Information

Patent Citations

  • Method and device for determining answer to question based on thinking chain, and electronic equipment

    CN117787421A

  • Self-guiding code error correction data set generation method for teenager programming scene

    CN117971704A

  • Method and device for predicting and enhancing query instruction of electric power customer service system

    CN118152428A

  • Data enhancement method and device based on large model and multi-order retrieval

    CN118193695A

  • Interactive RPA flow generation method and related device

    CN118426754A

Cited By

  • Text processing model training method and device and storage medium

    CN120012942A