Mathematical application question solving method and system based on few-sample thinking chain prompt
By constructing a few-sample thinking chain and programmable prompt word optimization framework, the problem of poor generalization ability in solving mathematical application problems is solved, and efficient and accurate problem solving of large language models is achieved.
Patent Information
- Application Number
- CN202510568885.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-30
- Publication Date
- 2025-08-01
AI Technical Summary
The prior art has poor generalization ability in solving mathematical application problems, especially the illusion caused by inconsistent example types of large language models and insufficient generalization ability of long string hard-coded templates.
By preprocessing the problems and inference chains in the training data, a few-sample thinking chain is constructed, clustering and selecting optimal examples similar to the problem to be solved, the programmable declarative prompt word optimization framework and the Bootstrap algorithm optimize the prompt word template, separate the prompt word parameters from the large language model parameters, and adopt structured definition.
It improves the accuracy and generalization ability of large language models in solving mathematical application problems, reduces the risk of hallucination due to inconsistent example types, and improves the accuracy and efficiency of understanding problems.
Smart Images

Figure CN120409697A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of automated problem-solving, and particularly to a method and system for solving mathematical word problems based on few-shot chain-of-thought prompting. Background Art
[0002] The statements in this section merely provide background technical information related to the present invention and do not necessarily constitute prior art.
[0003] Solving mathematical word problems is an important task in the field of natural language processing. Its main goal is to understand the semantic and numerical relationships in the problem and answer it through logical reasoning. However, due to the diversity of the forms and complexities of mathematical problems, this task faces many challenges.
[0004] Traditional methods for solving mathematical word problems usually adopt deep learning models. The Seq2Seq method regards a mathematical problem as an input sequence and maps a mathematical word problem to an answer sequence through an encoder-decoder structure; the tree-structure-based method converts a mathematical word problem into an analysis tree of a mathematical expression, where nodes represent operators or numerical values. This method constructs a tree structure according to the hierarchical relationship of mathematical operations and derives the answer through a recursive method or an analysis model based on a neural network. However, the above methods mechanically construct expression or equation templates during the solving process and have poor generalization ability for different mathematical word problems.
[0005] To solve this problem, existing technologies attempt to solve mathematical word problems through large language models. The problem-solving process usually requires step-by-step reasoning, and the language generation of large models is not sufficient to solve mathematical problems with complex logic. For example, chain-of-thought prompting guides the large language model to perform step-by-step mathematical reasoning along the reasoning path and self-verify, and tries multiple reasoning chains to obtain a more accurate answer. However, when the examples of chain-of-thought prompting are inconsistent with the type of the problem to be solved, it will cause the large language model to have hallucinations and thus get wrong answers. In addition, the hard-coded prompt template constructed using long strings also performs poorly in terms of generalization ability. Summary of the Invention
[0006] To solve the above problems, the present invention proposes a method and system for solving mathematical word problems based on few-shot chain-of-thought prompting. By preprocessing and clustering the problems and reasoning chains in the training data, an optimal example similar to the problem to be solved is constructed, reducing the risk of hallucinations caused by inconsistent example types in the large language model; at the same time, using a programmable prompt template optimization method, separating the prompt parameters from the large language model parameters, avoiding long-string hard-coded templates based on structured definitions, improving the generalization ability of the prompt template, effectively guiding the large language model to solve problems, and improving the problem-solving accuracy.
[0007] To achieve the above object, the present invention adopts the following technical solutions: In a first aspect, the present invention provides a method for solving mathematical word problems based on few-shot chain-of-thought prompting, including: Input the preprocessed problem samples into a pre-trained encoder, and encode the problem samples and their reasoning chains into feature vectors; Divide the feature vectors into multiple categories, select the first positive integer feature vectors in each category as the few-shot chain of thought; use the few-shot chain of thought to construct a prompt word to guide the large language model to construct examples for each type of problem, and obtain an example set; Select an example most similar to the problem to be solved from the example set as the optimal example; Based on the problem to be solved and the optimal example, construct an initial prompt word template; optimize the initial prompt word template based on a programmable declarative prompt word optimization framework; Use the optimized prompt word template to guide the large language model to solve the problem to be solved and obtain the final answer.
[0008] Preferably, the step of inputting the preprocessed problem samples into a pre-trained encoder and encoding the problem samples and their reasoning chains into feature vectors specifically includes: Segment the problem samples into a list of strings, tokenize the text in the list in sequence, extract the part-of-speech and analyze the dependency relationship between words; Extract numbers and number-related correlative words from the dependency relationship based on the direct object related to numbers, the nominal subject, and the noun modification scope; Input the problem samples, numbers, and number-related correlative words into the pre-trained encoder, embed and encode the problem samples and the reasoning chains, construct a digital entity embedding, and generate a feature vector with the semantics of the reasoning chain and digital features.
[0009] Preferably, the digital entity embedding includes two parts: digital position embedding and correlative word position embedding, which respectively record the position information of numbers and number-related correlative words.
[0010] Preferably, the step of selecting the first positive integer feature vectors in each category as the few-shot chain of thought; using the few-shot chain of thought to construct a prompt word to guide the large language model to construct examples for each type of problem, and obtaining an example set specifically includes: In each category, select the first positive integer problem samples closest to the centroid, and use the feature vectors to which the problem samples belong as the few-shot chain of thought; Construct the few-shot chain of thought into a prompt word and input it into the large language model. By understanding the problem of the mathematical word problem and clarifying the context and requirements of the problem, perform step-by-step reasoning to obtain examples for each type of problem; the examples include the core mathematical concepts, problem-solving ideas, and reasoning patterns of the mathematical word problem.
[0011] Preferably, select an example from the example set that is most similar to the problem to be solved as the optimal example. Specifically: By calculating the cosine similarity between the problem to be solved and the mathematical concepts of the examples, the example with the highest cosine similarity is used as the optimal example.
[0012] Preferably, based on the programmable declarative prompt optimization framework, optimize the initial prompt template. Specifically, it includes: Define the signature and the evaluation metrics for the prompt template. The evaluation metrics include two metrics: format consistency and problem-solving step effectiveness. Adopt the prompt optimizer in the programmable declarative prompt optimization framework and use the Bootstrap algorithm to optimize the prompt template. Automatically search for the combination of the optimal prompt template and its weight according to the evaluation metrics to obtain the optimized prompt template.
[0013] Preferably, the format consistency metric is used to limit the steps of the reasoning chain within a preset number of steps to prevent the large language model from overthinking; the problem-solving step effectiveness metric requires that each module in the prompt template be within the xml tags.
[0014] In a second aspect, the present invention provides a mathematical word problem solving system based on few-shot chain of thought prompting, including: An encoding module, configured to input the preprocessed problem sample into a pre-trained encoder, and encode the problem sample and its reasoning chain into feature vectors. A clustering module, configured to divide the feature vectors into multiple categories, select the first positive integer of feature vectors in each category as the few-shot chain of thought; use the few-shot chain of thought to construct prompts to guide the large language model to construct examples for each type of problem to obtain an example set. Select an example from the example set that is most similar to the problem to be solved as the optimal example. An optimization module, configured to construct an initial prompt template based on the problem to be solved and the optimal example; based on the programmable declarative prompt optimization framework, optimize the initial prompt template. An answer generation module, configured to use the optimized prompt template to guide the large language model to solve the problem to be solved to obtain the final answer.
[0015] In a third aspect, the present invention provides a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, it implements the steps in the method for solving mathematical word problems based on few-shot chain of thought prompting described in the first aspect.
[0016] Fourthly, the present invention provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the steps in the method for solving mathematical application problems based on few-shot thought chain prompting described in the first aspect are implemented.
[0017] Compared with the prior art, the beneficial effects of the present invention are as follows: By preprocessing the problems and reasoning chains in the training dataset, extracting numbers and correlation words, encoding to generate feature vectors and clustering, the present invention divides the mathematical application problems and reasoning chains into multiple categories. For each type of problem, representative examples are constructed to form an example set, and then the example with the highest cosine similarity to the mathematical concept of the problem to be solved is selected as the optimal example, ensuring a high similarity between the example and the problem to be solved and reducing the probability of hallucination caused by inconsistent example types in the large language model. At the same time, a programmable prompt template optimization method is proposed, defining signatures and evaluation metrics, and using a declarative prompt optimization framework and the Bootstrap algorithm to tune the prompt template. This method separates the prompt parameters from the large language model parameters, defines the prompt template in a structured and standardized format, avoids using long string instructions to construct hard-coded prompt templates, improves the generalization ability of the prompt template, and effectively guides the large language model to solve problems, thereby improving the problem-solving accuracy.
[0018] The advantages of the additional aspects of the present invention will be partially given in the following description, partially become apparent from the following description, or be understood through the practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The accompanying drawings forming a part of this specification are used to provide a further understanding of the present invention. The schematic embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute a limitation to the present invention.
[0020] Figure 1 It is the main flowchart of a method for solving mathematical application problems based on few-shot thought chain prompting provided by an embodiment of the present invention; Figure 2 It is the schematic flowchart of a method for solving mathematical application problems based on few-shot thought chain prompting provided by an embodiment of the present invention; Figure 3 It is the flowchart of example construction provided by an embodiment of the present invention; Figure 4 It is the schematic diagram of the optimization method based on the programmable declarative prompt optimization framework provided by an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0021] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.
[0022] Embodiment 1 As Figure 1 shown, this embodiment discloses a method for solving math word problems based on few-shot chain-of-thought prompting, including the following steps: S1: Input the preprocessed problem samples into a pre-trained encoder, and encode the problem samples and their reasoning chains into feature vectors; S2: Divide the feature vectors into multiple categories, select the first positive integer feature vectors in each category as the few-shot chain of thought; use the few-shot chain of thought to construct prompting words to guide the large language model to construct examples for each type of problem, obtaining an example set; S3: Select an example most similar to the problem to be solved from the example set as the optimal example; S4: Based on the problem to be solved and the optimal example, construct an initial prompting word template; based on a programmable declarative prompting word optimization framework, optimize the initial prompting word template; S5: Use the optimized prompting word template to guide the large language model to solve the problem to be solved, obtaining the final answer.
[0023] Next, in combination with Figure 2 , a method for solving math word problems based on few-shot chain-of-thought prompting disclosed in this embodiment will be described in detail.
[0024] In S1, obtain the original data, perform data preprocessing, and extract the problem and the reasoning chain.
[0025] Specifically, the operation of the preprocessing is to remove format symbols such as unnecessary parentheses, and convert numbers such as fractions and percentages in the problem into decimal representations.
[0026] Furthermore, divide the problem samples into a list of strings, tokenize the text in the list in sequence, extract the part-of-speech and analyze the dependency relationship between words. Among them, in natural language processing, the dependency relationship refers to the semantic dependency relationship between words in a sentence, which can reveal the grammatical structure and semantic logic of the sentence. In math word problems, common dependency relationships include subject-predicate relationships, verb-object relationships, attributive-center relationships, etc.
[0027] Based on the direct object related to numbers, nominal subject, and noun modification scope, extract numbers and number-related correlative words from the dependency relationship. The correlative words include correlative words indicating quantity comparison relationships, such as "more than...", "less than...", "several times of...", etc.; correlative words indicating the relationship between the total amount and partial amounts, such as "altogether", "in total", "among them", etc.; correlative words indicating the operation order and logical relationship, such as "first..., then...", "then", "next", etc.
[0028] Input the problem sample, the number, and the number-related correlative words into the pre-trained encoder, embed and encode the problem sample and the reasoning chain, construct the digital entity embedding, and generate a feature vector with the semantic of the reasoning chain and digital features. Among them, the digital entity embedding includes two parts: the digital position embedding and the correlative word position embedding, which record the position information of the number and the number-related correlative words respectively.
[0029] The pre-trained encoder adopts the BERT pre-trained language model, which includes a word embedding layer, a position embedding layer, a segment embedding layer, multiple encoding layers, and an output layer. In this embodiment, based on the three-layer embedding, aiming at the text characteristics of math word problems, the digital position embedding and the correlative word position embedding are integrated. By marking the positions, it aims to enhance the representation ability of the pre-trained language model for the semantic relationship of math word problems.
[0030] This process is expressed as:
[0031] Among them, represents the problem of the math word problem, represents the corresponding reasoning chain, represents the embedding generation function, is the obtained feature vector.
[0032] Furthermore, the set of feature vectors of the problem and the reasoning chain of the math word problem is represented as .
[0033] In this embodiment, by mining the key numbers and correlative words from the text, it lays a foundation for understanding the quantitative relationship of the problem. By constructing the digital entity embedding through the pre-trained encoder, fusing and encoding the problem sample and the reasoning chain information, the generated feature vector contains rich semantics and digital features, which helps to accurately classify the word problems and find similar examples in the follow-up. The recording of the position information of the numbers and correlative words enables the model to more accurately grasp the information correlation and improve the accuracy and efficiency of the large language model in solving problems.
[0034] In S2, as Figure 3 shown, cluster the feature vectors by the K-Means method, adjust the division of each class to minimize the within-class variance, and divide the problems into multiple categories, specifically:
[0035] Among them, K represents the number of clustering clusters, represents the data set of the Kth class, represents the ith data, represents the centroid of the class .
[0036] Further, the math word problems and reasoning chains are divided into K categories, denoted as , and each category is called a cluster of the clustering.
[0037] Within each clustering cluster, select the first positive integer number of math word problems and their reasoning chains that are closest to the centroid as samples, and design few-shot thought chain prompts to guide the large language model to perform context learning and step-by-step reasoning on the samples, aiming to construct examples; the examples are the problem-solving frameworks corresponding to each type of math word problem, and the content of the examples includes the core math concepts, problem-solving ideas, reasoning patterns, etc. of the math word problems.
[0038] Further, the few-shot thought chain prompt is a method of prompting the large language model to generate reasoning chains through a small number of samples.
[0039] Further, construct a representative example for each cluster of problems, and multiple examples form an example set, denoted as:
[0040] where P represents the example set, is the example in the Kth cluster of problems.
[0041] In S3, calculate the cosine similarity between the problem to be solved and the math concepts, and select the example with the highest cosine similarity as the optimal example.
[0042] The calculation of the cosine similarity between the problem to be solved and the math concepts is specifically:
[0043] where, represents the feature vector of the problem to be solved, [[ID=3२]] is the set of feature vectors of the math concepts of all clusters.
[0044] The optimal example of the problem to be solved is obtained specifically as:
[0045] where H represents the optimal example corresponding to the problem to be solved; In S4, as Figure 4 shown, the prompt template tuning and problem-solving module is provided, which provides a programmable method for prompt template tuning, and tunes the prompt template through the declarative prompt optimization framework DSPy; uses the optimized prompt template to guide the large language model to solve the problem to be solved, and obtains the final answer.
[0046] Specifically, define the signature S and construct the evaluation metrics for the prompt template; The signature S is denoted as:
[0047] The evaluation metrics for the prompt template include two metrics: format consistency and effectiveness of the problem-solving steps, specifically as follows:
[0048] Using the signature as the guiding information, the large language model constructs an initial prompt template based on the randomly sampled math word problems and the retrieved examples. The prompt optimizer in the declarative prompt optimization framework is used to compile the initial prompt template using the Bootstrap algorithm and the prompt template evaluation metrics, automatically searching for the optimal combination of the prompt template and the large language model weights to obtain the optimized prompt template.
[0049] The said prompt template evaluation metrics are specifically divided into the following two types, namely the two evaluation metrics of format integrity and effectiveness of the problem-solving steps. Format integrity limits the steps of the reasoning chain to within 10 steps to prevent the large language model from overthinking. The effectiveness of the problem-solving steps requires that each module in the prompt template is within the xml tags.
[0050] Finally, the prompt template is compiled according to whether the above evaluation metrics are consistent with the predicted answer using this template and the actual answer; In S5, the large language model is used to solve the problem to be solved; Use the optimized prompt template as the prompt, and use the prompt to guide the large language model to solve the problem to be solved.
[0051] As an implementation, the method described in this embodiment can be loaded into an intelligent teaching system such as a learning machine for solving math word problems.
[0052] For example, a learning machine loaded with the method of this embodiment needs to solve the following math word problem: "There are chickens and rabbits in a cage. The total number of heads is #35, and the total number of feet is $94... Question: How many chickens and rabbits are there?" Step 1: Preprocessing and encoding (1) Data preprocessing Remove irrelevant symbols, delete special symbols (#, $, parentheses, extra punctuation), and standardize the text: "There are chickens and rabbits in a cage. The total number of heads is 35, and the total number of feet is 94. How many chickens and rabbits are there?" Unify the numbers into decimal format (no conversion is required in this example).
[0053] (2) Semantic analysis and feature extraction Tokenization result: ["There are chickens and rabbits in a cage. The total number of heads is 35, and the total number of feet is 94. How many chickens and rabbits are there respectively?"]
[0054] Analyze the dependency relationship, identify that "the total number of heads is 35" is a subject-predicate structure, and "the total number of feet is 94" is an object-predicate structure, and clarify the quantitative relationship.
[0055] Extract the key numbers (35 heads, 94 feet) and correlation words: "total", "how many respectively".
[0056] (3) Encode as a feature vector Use a pre-trained encoder (such as BERT) to fuse the problem text, digital position embeddings (positions of 35 and 94), and correlation word position embeddings (position of "total") to generate a feature vector containing semantic and numerical features.
[0057] Step 2: Clustering and example construction (1) Cluster historical data Cluster the "chicken and rabbit in the same cage" type of problems in the training data (e.g., K = 3), and assume that the current problem is classified into the "binary linear equation" cluster.
[0058] (2) Construct a few-shot thought chain Select the example closest to the centroid within the cluster. For example: "The total number of heads is 20, and the total number of feet is 56. Find the number of chickens and rabbits."
[0059] Solution: Let the number of chickens be x and the number of rabbits be y. Then x + y = 20, 2x + 4y = 56, and the solution is x = 12, y = 8." (3) Generate an example set Guide the large language model to generate a problem-solving framework for similar problems based on the few-shot thought chain, including core concepts (equations), steps (set variables → list equations → solve).
[0060] Step 3: Select the optimal example Calculate the cosine similarity of the mathematical concepts between the problem to be solved and each example in the example set (e.g., based on features such as "binary linear equation" and "relationship between heads and feet").
[0061] Select the example with the highest similarity as a template to ensure consistent problem-solving logic.
[0062] Step 4: Prompt template tuning (1) Initial prompt template
[0063] Among them, placeholders {heads} and {legs} are used in the initial template, and these parameters need to be bound to the dynamic generation ability of the large language model. For example, the model needs to parse the placeholders and fill in specific values during the inference process, resulting in a tight coupling between the prompt parameters and the model parameters. At the same time, the problem and examples are described in the form of continuous text. This long string template requires manual format adjustment and is difficult to adapt to different problem types.
[0064] (2)Declarative optimization 1. Evaluation metrics: Format consistency: Limit the inference chain to 10 steps and use XML tags.
[0065] Problem-solving effectiveness: Ensure that the steps include variable definitions, equation establishment, and solution processes.
[0066] 2. Optimize the template weights through the Bootstrap algorithm to generate the final prompt
[0067] Among them, the mapping relationship from the problem, example to the answer is clearly defined through tags, and the problem is implicit in <solve>In the tag (such as the head and foot values), the example passes through <equation>(Equation definition) and <step>(Solution steps) Provide the complete solution logic. The answer is directly in <step>The final result is given in []. The optimized template clearly defines the derivation path from the question to the answer through the tag hierarchy.
[0068] The optimized template directly uses specific numerical values (such as 35.0 and 94.00) without the need for the model to dynamically parse placeholders. The numerical values in the prompt are completely separated from the model weights (such as attention mechanism parameters) and only serve as structured inputs to guide the model's reasoning. At the same time, through the XM tag for structured definition, the problem-solving logic is split into independent modules, and each tag, such as <equation> 、 <step>, Independently define functions to avoid the chaos of long strings. When adding new problem types, only the tag combination needs to be adjusted, without rewriting the entire template.
[0069] It should be understood that optimizing the template weight through the Bootstrap algorithm can be achieved by those skilled in the art.
[0070] Step 5: Answer generation The learning machine uses the optimized prompt to guide the large language model to reason: Suppose there are 23 chickens and 12 rabbits.
[0071] Verify the number of heads: 23 + 12 = 35.0.
[0072] Verify the number of feet: 2×23 + 4×12 = 94.00.
[0073] Output the final answer: There are 23 chickens and 12 rabbits.
[0074] This specific embodiment aims at the problem of solving difficult mathematical application problems. By preprocessing the problem samples, encoding them into feature vectors and clustering, the optimal examples similar to the problem to be solved are constructed, greatly reducing the risk of hallucinations caused by inconsistent example types in the large language model. Using the programmable prompt template optimization method, the prompt parameters are separated from the large language model parameters, avoiding hard-coded templates for long strings, and improving the generalization ability of the prompt template. It effectively guides the large language model to accurately understand the problem semantics and numerical relationships, conducts logical reasoning, significantly improves the problem-solving accuracy, and makes up for the deficiencies of the poor generalization ability of traditional deep learning models and the existing problem-solving methods of large language models.
[0075] Embodiment 2 This embodiment provides a mathematical application problem solving system based on few-shot thought chain prompting, including: An encoding module, configured to input the preprocessed problem samples into a pre-trained encoder, and encode the problem samples and their reasoning chains into feature vectors; A clustering module, configured to divide the feature vectors into multiple categories, select the first positive integer feature vectors in each category as the few-shot thought chain; use the few-shot thought chain to construct a prompt to guide the large language model to construct examples for each type of problem, and obtain an example set; Select an example most similar to the problem to be solved from the example set as the optimal example; An optimization module, configured to construct an initial prompt template based on the problem to be solved and the optimal example; optimize the initial prompt template based on the programmable declarative prompt optimization framework; An answer generation module, configured to use the optimized prompt template to guide the large language model to solve the problem to be solved and obtain the final answer.
[0076] Example 3 This embodiment provides a computer-readable storage medium, on which a computer program is stored. When the program is executed by a processor, it implements the steps in a method for solving mathematical application problems based on few-shot thought chain prompting as described in the above Embodiment 1.
[0077] Example 4 This embodiment provides a computer device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, it implements the steps in a method for solving mathematical application problems based on few-shot thought chain prompting as described in the above Embodiment 1.
[0078] The steps or modules involved in the above Embodiments 2 to 4 correspond to those in Embodiment 1. For specific implementation manners, reference may be made to the relevant description part of Embodiment 1. The term "computer-readable storage medium" should be understood to include a single medium or multiple media including one or more instruction sets; it should also be understood to include any medium that can store, encode, or carry an instruction set for execution by a processor and enable the processor to execute any method in the present invention.
[0079] The above are only the preferred embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention may have various changes and modifications. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.< / step> < / equation> < / step> < / step> < / equation> < / solve>
Claims
1. A method for solving mathematical application problems based on few-shot chain of thought prompting, characterized in that Including: Input the preprocessed problem sample into the pre-trained encoder, and encode the problem sample and its reasoning chain into feature vectors. Divide the feature vectors into multiple categories, select the first positive integer number of feature vectors in each category as the few-shot thought chain; use the few-shot thought chain to construct prompt words to guide the large language model to construct examples for each type of problem, and obtain an example set. Select an example from the example set that is most similar to the problem to be solved as the optimal example. Based on the problem to be solved and the optimal example, construct an initial prompt word template. Based on the programmable declarative prompt word optimization framework, optimize the initial prompt word template. Use the optimized prompt word template to guide the large language model to solve the problem to be solved and obtain the final answer.
2. The method for solving mathematical application problems based on few-shot thought chain prompting according to claim 1, wherein, The step of inputting the preprocessed problem sample into the pre-trained encoder and encoding the problem sample and its reasoning chain into feature vectors specifically includes: Split the problem sample into a list of strings, tokenize the text in the list in sequence, extract part-of-speech tags and analyze the dependency relationship between words. Based on the direct object related to numbers, nominal subject, and noun modification scope related to numbers, extract numbers and number-related correlative words from the dependency relationship. Input the problem sample, numbers, and number-related correlative words into the pre-trained encoder, embed and encode the problem sample and the reasoning chain, construct digital entity embeddings, and generate feature vectors with reasoning chain semantics and digital features.
3. The method for solving math word problems based on few-shot chain-of-thought prompting according to claim 2, wherein, The digital entity embeddings include two parts: digital position embeddings and correlative word position embeddings, which respectively record the position information of numbers and number-related correlative words.
4. The method for solving mathematical application problems based on few-shot chain-of-thought prompting as described in claim 1, wherein, Select the first positive integer number of feature vectors in each category as the few-shot thought chain. Using the few-shot thought chain to construct prompt words to guide the large language model to construct examples for each type of problem and obtain an example set specifically includes: In each category, select the positive integer number of problem samples closest to the centroid, and use the feature vectors to which the problem samples belong as the few-shot thought chain. Construct the few-shot thought chain into prompt words and input them into the large language model. By understanding the problem of the math word problem and clarifying the context and requirements of the problem, perform step-by-step reasoning to obtain examples for each type of problem; the examples include the core mathematical concepts, problem-solving ideas, and reasoning patterns of the math word problem.
5. The method for solving mathematical application problems based on few-shot thought chain prompting according to claim 1, wherein, The step of selecting an example from the example set that is most similar to the problem to be solved as the optimal example is specifically: by calculating the cosine similarity between the mathematical concepts of the problem to be solved and the example, select the example with the highest cosine similarity as the optimal example.
6. The method for solving mathematical application problems based on few-shot thought chain prompting according to claim 1, characterized in that The step of optimizing the initial prompt word template based on the programmable declarative prompt word optimization framework specifically includes: Define signatures and prompt word template evaluation metrics, and the evaluation metrics include two metrics: format consistency and problem-solving step effectiveness. Adopt the prompt word optimizer in the programmable declarative prompt word optimization framework, and use the Bootstrap algorithm to optimize the prompt word template. Automatically search for the combination of the optimal prompt word template and its weight according to the evaluation metrics to obtain the optimized prompt word template.
7. The method for solving mathematical word problems based on few-shot chain-of-thought prompting according to claim 6, wherein, The format consistency index is used to limit the steps of the reasoning chain within a preset number of steps to prevent the large language model from overthinking; the problem-solving step effectiveness index requires that each module in the prompt template be within xml tags.
8. A mathematical application problem solving system based on few-shot chain of thought prompting, characterized in that, Including: An encoding module, configured to input the preprocessed problem sample into a pre-trained encoder, and encode the problem sample and its reasoning chain into feature vectors; A clustering module, configured to divide the feature vectors into multiple categories, select the first positive integer feature vectors in each category as the few-shot thought chain; use the few-shot thought chain to construct a prompt to guide the large language model to construct examples for each type of problem to obtain an example set; Select an example most similar to the problem to be solved from the example set as the optimal example; An optimization module, configured to construct an initial prompt template based on the problem to be solved and the optimal example; Tune the initial prompt template based on a programmable declarative prompt optimization framework; An answer generation module, configured to use the optimized prompt template to guide the large language model to solve the problem to be solved to obtain the final answer.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by a processor, it implements the steps in a method for solving mathematical application problems based on few-shot thought chain prompts as described in any one of claims 1-7.
10. A computer device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps in a method for solving mathematical application problems based on few-shot thought chain prompts as described in any one of claims 1-7.
Citation Information
Cited By
Bayesian automatic cue word optimization method based on meta cue word
CN120832540A
Prompt word optimization method and device and electronic equipment
CN121660070A