A method and system for solving mathematical problems based on feature classifier-based thought chain reasoning
By constructing word-level reasoning path generation trees and feature classifier training sets, and selecting feature classifiers, the accuracy and computational resource issues of pre-trained language models in mathematical reasoning are solved, achieving efficient and accurate mathematical problem solving.
Patent Information
- Application Number
- CN202411479942.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-23
- Publication Date
- 2025-11-14
- Estimated Expiration
- 2044-10-23
AI Technical Summary
Existing pre-trained language models, when used for reasoning mathematical problems using thought chains, have limited accuracy improvements in self-consistency and thought tree search methods, high computational resource requirements, and are difficult to effectively solve complex mathematical problems.
We employ a feature classifier-based approach, which involves constructing a word-level inference path generation tree, selecting a feature classifier training set, training the feature classifier using a support vector machine algorithm, guiding the pre-trained language model to select the correct inference path, and generating high-quality and accurate mathematical problem-solving processes and answers.
It improves the accuracy and efficiency of solving mathematical problems, reduces the demand for computing resources, enhances the transferability and generalization performance of models, reduces computing costs, and promotes the interpretability of language model reasoning processes.
Smart Images

Figure CN119443267B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer application technology, and in particular to a method and system for solving mathematical problems based on feature classifiers and thought chain reasoning. Background Technology
[0002] In recent years, deep learning artificial intelligence technology has undergone the following research paradigm shift: from early task-specific models based on "supervised learning with labeled data," to pre-trained models using "pre-training with unlabeled data + fine-tuning with labeled data," and now to large-scale models using "pre-training with large-scale unlabeled data + fine-tuning with instructions + human alignment." Artificial intelligence technology is gradually entering the era of large models. Simultaneously, with the continuous increase in model parameter scale and pre-training data scale, reaching hundreds of billions, large language models have exhibited powerful context learning capabilities. This means they learn from examples in the model's input context, enabling them to perform a series of complex tasks and becoming powerful tools to help humans handle a range of automated complex tasks. As a specific application of context learning, the thought chain technique allows large language models to progressively decompose a complex problem into step-by-step sub-problems and solve them sequentially, completing the mapping from input to thought chain to output. This significantly improves the performance of large models in complex reasoning task scenarios.
[0003] Mathematical reasoning is crucial for artificial intelligence, driving the ongoing exploration of autonomous mathematical problem-solving. This process requires enhancing the reasoning capabilities of models, delving into text understanding, image recognition, table analysis, symbolic computation, logical operations, and a deep understanding of the world. Comprehensively improving the understanding capabilities of large language models across various mathematical domains not only demonstrates technological prowess but also represents a significant step towards general artificial intelligence. Existing research demonstrates that large language models are effective tools for solving mathematical problems, and their language capabilities prompt us to explore how to utilize them for mathematical reasoning, revealing new insights into the synergistic effect between language and logic.
[0004] For example, Chinese patent document CN116595159A discloses a training method and apparatus for a mathematical problem-solving model. First, a pre-trained language model with frozen parameters is used to generate a solution with reasoning process corresponding to the correct answer to a mathematical problem as an example of thinking chain learning. Then, the mathematical problem-solving model is used to generate the reasoning process and answer corresponding to the target mathematical problem to be solved multiple times. A self-consistent majority voting method is adopted to take the reasoning process and answer generated most frequently as the final result corresponding to the target mathematical problem.
[0005] Chinese patent document CN118113444A discloses a task processing method, apparatus, electronic device, and storage medium. The method uses a pre-trained language model to decompose a target task into steps based on its input content and output description, thereby generating a corresponding mind tree. The nodes of the mind tree represent the individual steps obtained from the decomposition, enabling the model to search across multiple inference chains. Based on a preset search algorithm, the optimal step path for executing the target task is found in the mind tree; then, based on this optimal step path, the target task is executed according to the input content, and the execution result is output.
[0006] However, current work on pre-trained language model reasoning, including methods like self-consistency and mind trees to improve reasoning for complex mathematical problems, focuses primarily on sequence-level reasoning paths. Their impact on improving the accuracy of reasoning results is limited and constrained by the type of mathematical problem. Furthermore, self-consistency may generate incorrect or meaningless reasoning paths, and mind tree reasoning chain search methods require more computational resources than sampling. These approaches are all limited by computational cost and performance constraints. Summary of the Invention
[0007] This invention provides a method and system for solving mathematical problems based on feature classifier-based thought chain reasoning, which can provide high-quality and accurate problem-solving processes and answers.
[0008] A method for solving mathematical problems involving thought chain reasoning based on feature classifiers includes the following steps:
[0009] (1) Obtain the mathematical problem set Q = {q1, q2, ... q} n}, for each element q i Use the mind chain hint generation method to find the two corresponding examples. and Make Get the correct answer, If incorrect answers are obtained, a new set Q is formed. ′ ={q1 ′ ,q ′ 2…q ′ n},in
[0010] (2) Based on the new set Q of the composition ′ Using the thought chain hint method as input to the pre-trained language model, a word-level reasoning path generation tree is constructed, with each node n i Save the attention weight matrix A after average pooling and interpolation operations. i ;
[0011] (3) Traverse all the inference path generation trees generated in step (2), and select nodes that meet the requirements to construct the feature classifier training set; use the attention weight matrix A of the nodes. i As features, the inference path results are used as labels to construct a set of training data sample pairs D;
[0012] (4) Based on the training set generated in step (3), train the feature classifier C using the support vector machine algorithm;
[0013] (5) In the pre-trained language model inference stage, for the target mathematical problem q to be solved, two examples d are randomly selected from the dataset. a With d b Simultaneously, reasoning is performed. If the reasoning paths are the same, prediction and generation continue until the end. If the reasoning paths are different, the feature classifier C trained in step (4) selects the word with the higher probability of correct reasoning and continues reasoning. Finally, the complete reasoning process is obtained, and the corresponding answer is extracted.
[0014] This invention first selects a subset of mathematical problems from a dataset and constructs word-level inference path generation trees using the thought chain method. Then, it filters training sample data to train a feature selector. During pre-training of the oracle model, the thought chain hint method is used to process the target mathematical problem to be solved. During inference, a feature classifier intervenes in the selection and generation of inference paths, thereby obtaining a high-quality and accurate problem-solving process and answer.
[0015] In step (1), the mind chain hint generation method is used to find the two corresponding examples. and The specific process is as follows:
[0016] Use p θ The probability distribution fitted by a pre-trained large language model with parameter θ is represented by...
[0017] N represents d A chain of thought prompts, where d i =(q i ,r i ,a i ) represents the i-th example, q i ,r i ,a i Let q represent the question, reasoning steps, and answer, respectively; if q represents the question to be reasoned, then the few-shot thought chain (FS-CoT) is defined as:
[0018]
[0019] In the formula, y = {r, a} represents the generated inference step r and the inference result a; only N is considered. dFor the case where the value is 1, for each problem q i Traverse the set of mathematical problems to find the corresponding examples. and Make The answer obtained under the condition of maximizing probability Correct, at the same time The answer obtained under the condition of maximizing probability Errors are excluded if no corresponding example is found; finally, combining the problem and its two corresponding examples yields a new set Q. ′ ={q1 ′ ,q ′ 2…q ′ m}, m≤n where
[0020] The specific process of step (2) is as follows:
[0021] For the new set Q ′ All elements within, for The input text for the pre-trained language model is obtained by concatenation. Freeze all parameters of the model and use them as input to a pre-trained language model for forward inference;
[0022] During the reasoning process, q i ′ Correspondingly generated inference path tree G i Each node n j It includes three types of attributes (f(A) j ,l),x j ,r j ), where x j The text representing the current node, r j This indicates that the process has passed through node n. j The accuracy of all reasoning paths, A j Indicates the prediction of generating x j The attention weight matrix of the time model; since the pre-trained language model uses a multi-head mask self-attention mechanism, the sequence length of its input model is different, so the f(·) function is used to transform and process the multi-head attention weight matrix.
[0023] The process of constructing the reasoning path tree is as follows: First, construct an empty node n. root Let n be the root node of the reasoning path tree and marked as a non-leaf node. When constructing the tree, find the non-leaf node among the terminal nodes of each path; let this node be n. i From the root node n root to node n i Each path can represent a reasoning path. Then determine node n i The child node situation; specifically, and When the first i text sequences are input into the pre-trained language model, the language model makes predictions based on the following probabilities:
[0024]
[0025] x i+1 There are two possible scenarios:
[0026] The first scenario: If the text generated by the prediction in the current round is the same for both prompts, that is... Then node n i A new child node n will be added. i+1 The text attribute is set to if If it is a sentence terminator, then mark the child node as a leaf node;
[0027] The second scenario: For two prompts, the texts generated in this round of prediction are different, i.e. Then let node n i Insert the left and right child nodes respectively The text attributes are set to respectively as well as if If it is a sentence terminator, then mark the child node. If it is a leaf node; If it is a sentence terminator, then mark the child node. Leaf node;
[0028] This process continues until the final node of each path in the tree is a leaf node; ultimately, the new set Q is obtained. ′ All elements within the tree generate their corresponding reasoning path trees, resulting in a set of trees G =
[0029] {G1,G2,...G m}
[0030] In step (3), nodes that meet the requirements are selected to construct a feature classifier training set. The specific process is as follows:
[0031] First, the set G of trees generated in step (2) contains m trees, corresponding to the set of mathematical problems Q. ′ The reasoning path generation tree is used for each problem, and each node in the tree contains three attributes, n. i =(f(A) i ,l),x i ,r i ), which are the feature matrix, the text, and the data passed through node n, respectively. iThe accuracy of all inference paths; before selecting training set samples, the r of the nodes needs to be calculated. i Attributes: Assuming a reasoning path spanning tree, each path from the root node to a leaf node constitutes a reasoning path, and each reasoning path has a unique attribute 'a' representing the correctness of the reasoning path's result, where 1 indicates correctness and 0 indicates error; therefore, the following calculation formula is obtained:
[0032]
[0033] Wherein, β(n) u ,S j ) represents node n j Does it belong to reasoning path S? i If a node belongs to the tree set G, the value is 1; otherwise, the value is 0. The inference path accuracy of all nodes in all trees within the tree set G is calculated using the formula above. Then, nodes meeting the requirements are selected based on the following conditions to serve as the training dataset for the feature classifier:
[0034] ① The node is neither a root node nor a leaf node;
[0035] ② The r attribute value of a node is 0% or 100%, which means that the reasoning path passing through this node is considered to have either all incorrect or all correct answers;
[0036] Form a node set N = {n1, n2, ...} of all nodes that meet the conditions.
[0037] The specific process of step (4) is as follows:
[0038] First, features of each element in the training dataset D are extracted as input, and the inference path results are used as labels. The data is then standardized. Next, a radial basis function kernel is used to map the data to a high-dimensional feature space. A support vector machine (SVM) classification model is trained with the objective function of maximizing the Lagrange duality problem. Cross-validation is used to evaluate the model's performance, and hyperparameters are adjusted as needed. Finally, the trained SVM model is saved for subsequent inference. The resulting feature classifier C is shown below:
[0039]
[0040] In the formula, x is the new input sample, processed by the kernel function K(x) i ,x) Calculate the relationship between this sample and all training samples x i The similarity is calculated, and then these similarities are weighted and summed, where α i y i The classification result is derived from the Lagrange multipliers learned during training and the labels of the training samples; finally, the bias term b is added, and the classification result is obtained through the sign function sign.
[0041] In step (5), if the reasoning paths are different, the feature classifier C trained in step (4) selects the word with the higher correct probability to continue reasoning. Specifically, this includes:
[0042] Calculate the attention weight matrices used to generate the current text for both, and perform average pooling at the layer dimension and linear interpolation at the sequence length dimension to obtain the result for example d. a The characteristic matrix A below a And example d b The characteristic matrix A below b The feature matrix is used to obtain the classification result through the feature classifier C(x). The classification result includes the following three cases, which are processed as follows:
[0043] ①、C(A a )=C(A b =1, meaning that in the current text, both play a positive role in the correctness of the reasoning path generation. In this case, the term with the larger value in the sign function of the feature classifier C is selected as the predicted content of the currently generated text.
[0044] ②、C(A a )=-1,C(A b ) = 1 or C(A) a )=1,C(A b C(x) = -1, meaning that for the current text, the two examples have positive and negative effects on the correctness of the generated inference path, respectively; in this case, the text with C(x) = 1 is selected as the predicted text content for the current generation.
[0045] ③、C(A a )=C(A b = -1, meaning that in the current text, both have a negative effect on the correctness of the reasoning path generation. In this case, the term with the smaller value in the sign function of the feature classifier C is selected as the predicted content of the currently generated text.
[0046] Based on the same inventive principle, this invention also provides a system for solving mathematical problems of thought chain reasoning based on feature classifiers, comprising:
[0047] The thought chain prompt generation module is used to obtain the mathematical reasoning problem to be processed, and select the examples and instructions that meet the requirements according to the problem to form the complete input of the pre-trained language model;
[0048] Inference path tree generation and feature selection module: used to generate word-level inference path generation trees and select feature training datasets that meet the requirements;
[0049] Feature classifier training module: Used for training feature classifiers. It introduces the support vector machine algorithm based on the feature training dataset, uses radial basis functions as kernel functions to map data to a high-dimensional feature space, and uses a sequence minimum optimization algorithm to improve the training efficiency of support vector machines.
[0050] Feature classifier-guided reasoning module: used to solve the mathematical reasoning problem to be processed; through the intervention of the feature classifier, it guides the pre-trained language model to select a more accurate reasoning path, thereby obtaining the final mathematical reasoning process and answer.
[0051] Based on the same inventive principle, the present invention also provides a system for solving mathematical problems of thought chain reasoning based on feature classifiers, including a memory and one or more processors. The memory stores executable code, and when the one or more processors execute the executable code, they are used to implement the above-mentioned method for solving mathematical problems of thought chain reasoning.
[0052] Compared with the prior art, the present invention has the following beneficial effects:
[0053] 1. This invention focuses on text-level prediction generation. Compared to current mainstream sequence-level techniques, text-level processing offers significantly finer granularity. This improves prediction accuracy and allows for more precise and effective control over the generation of inference results. In practical applications, this fine-grained text-level processing better adapts to complex and ever-changing scenarios, providing users with more targeted and reliable results.
[0054] 2. This invention innovatively utilizes a self-trained feature classifier. This classifier exhibits excellent transferability and broad generalization performance when facing various types of mathematical reasoning tasks. This means that it can quickly adapt and function in different tasks and scenarios without requiring extensive retraining and adjustments, thereby greatly improving work efficiency and the model's versatility.
[0055] 3. Compared to common methods such as self-consistency and mind tree reasoning chain search, this invention demonstrates a significant advantage in terms of computational resource requirements. Its relatively low resource requirements result in substantial savings in computational costs. This not only lowers the hardware barrier to system operation but also provides greater possibilities for large-scale applications and deployments, enabling efficient computation even in resource-constrained environments.
[0056] 4. This invention also has certain research significance for the interpretability of pre-trained language model reasoning under the guidance of thought chain prompts. It provides new ideas and methods for research and practice in this field, helps to further deepen the understanding of the language model reasoning process, and promotes the development of related technologies towards greater transparency, interpretability, and reliability. Attached Figure Description
[0057] Figure 1 This is a flowchart of a method for solving mathematical problems based on a feature classifier in the form of a thought chain reasoning method according to the present invention.
[0058] Figure 2 A diagram illustrating the reasoning path generation tree for both positive and negative examples;
[0059] Figure 3 A diagram illustrating the filtering of inference path tree nodes;
[0060] Figure 4 This is a flowchart of the training process for a support vector machine feature classifier. Detailed Implementation
[0061] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be noted that the embodiments described below are intended to facilitate the understanding of the present invention and do not constitute any limitation thereof.
[0062] like Figure 1 As shown, a method for solving mathematical problems based on feature classifier-based thought chain reasoning includes the following steps:
[0063] (1) Obtain the dataset of mathematical problems: Problem set Q = {q1, q2, ... q} n}, and for each element q i Find corresponding examples of thought chains and Make Get the correct answer, If incorrect answers are obtained, a new set Q is formed. ′ ={q1 ′ ,q ′ 2…q ′ n},in
[0064] (2) Based on the set Q ′ Using the Mind Chain Hints method to input into a pre-trained oracle model, a word-level inference path generation tree is constructed, with each node n i Save the attention weight matrix A after average pooling and interpolation operations. j .
[0065] (3) Traverse all inference path generation trees generated in step (2), and select nodes that meet the requirements to construct a feature classifier training set. The requirements are as follows: all inference paths passing through the node have the same result, i.e., all are correct or all are incorrect. The attention weight matrix A of the node is used as the basis for this process. i As features, the inference path results are used as labels to construct a set of training data sample pairs D.
[0066] (4) Based on the training set generated in step (3), train the feature classifier C using the Support Vector Machine (SVM) algorithm. First, extract the features of each element in the training dataset D as input, use the inference path results as labels, and standardize the data. Then, use radial basis functions as kernel functions to map the data to a high-dimensional feature space, train the SVM model, evaluate the model performance using cross-validation, and adjust the hyperparameters as needed. Finally, save the trained model for subsequent inference.
[0067] (5) In the pre-trained language model inference stage, for the target mathematical problem q to be solved, two examples d are randomly selected from the dataset. a With d b Simultaneously, reasoning is performed. If the reasoning paths are the same, prediction and generation continue until the end. If they are different, the feature classifier C trained in step (4) selects the word with the higher correct probability to continue reasoning. Finally, the complete reasoning process is obtained, and the corresponding answer is extracted.
[0068] In step (1), the original set of mathematical problems to be solved is obtained, and examples of forward and reverse thinking chains are selected and combined to form a new model input set. First, the set of mathematical problems to be solved is defined as Q = {q1, q2, ..., q}. n}, where each element q i The problem statement focuses on a specific issue. For each issue q... i Use the mind chain hint generation method to find the corresponding positive example. and reverse examples The method for prompting thoughts in a chain of ideas is as follows:
[0069] Use p θ Let X = {x1, x2, ..., x} be the probability distribution fitted by a pre-trained large language model with parameter θ. N} represents a text sequence of length N. When the first i text sequences are input, the language model determines the input based on probability p. θ (x i+1 ) = p θ (x i+1 |x1,…,x i To make predictions.
[0070] use N represents d A chain of thought prompts, where d i ={q i ,r i ,a i} represents the i-th example, q i ,r i ,a iLet q represent the question, reasoning steps, and answer, respectively. If q represents the question to be reasoned, then the few-shot thought process can be defined as follows:
[0071]
[0072] In the formula, y = {r, a} represents the generated inference step r and the inference result a. In this step, only N is considered. d The value is 1, therefore for each problem q i Traverse the set of mathematical problems to find the corresponding examples. and Make The answer obtained under the condition of maximizing probability Correct, at the same time The answer obtained under the condition of maximizing probability Errors are identified; if no corresponding example is found, the problem is excluded. Finally, combining the problems in the original dataset with their corresponding positive and negative examples yields a new set Q. ′ ={q1 ′ ,q ′ 2…q ′ m}, m≤n where
[0073] In step (2), the new set elements are input into the model to construct a text-level inference path generation tree, and the attention weight matrix after pooling difference processing is selected as the node feature for storage.
[0074] The new set Q generated by traversing step (1) ′ ,for The input text for the model is obtained through simple concatenation. All parameters of the frozen model are used as input to a pre-trained language model for forward inference. During inference, q i ′ Correspondingly generated inference path tree G i = {V, E}, where V represents the set of vertices and E represents the set of edges. Each node n in the vertex set... j It includes three types of attributes (f(A) j ,l),x j ,r j ), where x j The text representing the current node, r j This indicates that the process has passed through node n. j The accuracy rate of all reasoning paths. A j Indicates the prediction of generating x jThe attention weight matrix of the time model is transformed and processed using the f(·) function because the pre-trained language model uses a multi-head mask self-attention mechanism with different sequence lengths in its input model.
[0075] f(A j The function performs two main operations on the multi-head attention weight matrix. The first step uses the linear interpolation method to transform matrix A... ij The matrix is compressed or expanded from dimension j×j to a fixed length l. In the specific implementation, l=30 is set based on experimental experience. The second step is to perform average pooling on the layer dimension of the multi-head self-attention matrix to obtain a feature matrix of fixed size, which is stored as the feature matrix of the node.
[0076] After explaining the tree and the attributes contained in the nodes, the following describes the specific process of constructing the reasoning path tree. First, an empty node n is constructed. root Let n be the root node of the reasoning path tree and marked as a non-leaf node. When constructing the tree, among the terminal nodes of each path, find one non-leaf node (randomly select one if there are multiple nodes), and let this node be n. i From the root node n root to node n i Each path can represent a reasoning path. Then determine node n i The child node situation. Specifically, we will and Input the pre-trained language model respectively, such as Figure 2 As shown, when the first i text sequences are input, the language model makes predictions based on the following probabilities:
[0077]
[0078] Then x i+1 There are two possible scenarios:
[0079] The first scenario: If the text generated by the prediction in the current round is the same for both prompts, that is... Then node n i A new child node n will be added. i+1 The text attribute is set to if If it is a sentence terminator, then the child node is marked as a leaf node.
[0080] The second scenario: For two prompts, the texts generated in this round of prediction are different, i.e. Then let node n i Insert the left and right child nodes respectively The text attributes are set to respectively as well as if If it is a sentence terminator, then mark the child node. If it is a leaf node; If it is a sentence terminator, then mark the child node. It is a leaf node.
[0081] This process continues until the final node of every path in the tree is a leaf node. Finally, the new set Q is... ′ Each element within the set can generate its corresponding reasoning path tree, resulting in a set of trees G = {G1, G2, ..., G...} m}
[0082] In step (3), the inference path generation tree from step (2) is traversed, nodes that meet the requirements are selected, labeled, and used together with their feature attributes to construct a training data sample set. The specific implementation process is as follows.
[0083] First, the set G of trees generated in step (2) contains m trees, corresponding to the set of mathematical problems Q. ′ The reasoning path generation tree is used for each problem, and each node in the tree contains three attributes, n. i =(f(A) i ,l),x i ,r i ), which are the feature matrix, the text, and the data passed through node n, respectively. i The accuracy of all inference paths. Defined as follows: Assume that for a reasoning path spanning tree, the paths from the root node to a leaf node constitute a reasoning path, and each reasoning path has a unique attribute 'a' representing the correctness of the result, where 1 represents correct and 0 represents incorrect. Therefore, the following formula can be obtained:
[0084]
[0085] Where β(n) i ,S j ) represents node n j Does it belong to reasoning path S? j If it belongs to the tree set G, the value is 1; otherwise, the value is 0. The inference path accuracy of all nodes in all trees within the tree set G is calculated according to the above formula.
[0086] Then, nodes that meet the requirements are selected based on the following criteria and used as the training dataset for training the feature classifier:
[0087] 1) The node is neither a root node nor a leaf node;
[0088] 2) The r attribute value of a node is 0 or 100, which means that the reasoning path through this node is considered to have either all incorrect or all correct answers.
[0089] Finally, all nodes that meet the conditions are grouped into a node set N = {n1, n2, ...}. For example... Figure 3 As shown, within this inference path generation tree, there are multiple inference paths corresponding to correct or incorrect results. According to the above filtering conditions, the bolded nodes can be selected as the training sample set.
[0090] In step (4), a support vector machine feature classifier D(x) is trained. For example... Figure 4 As shown, the first step is to prepare the training dataset. Based on step (3), a set of nodes that meet the conditions is selected, and a training set T = {(x1,y1),(x2,y2),...,(x n ,y n )}. Where x n The representation of the node attention weight matrix after average pooling in the layer dimension and linear interpolation in the sequence length dimension, y n ∈{1,-1} are labels indicating whether the inference result is correct or incorrect. Next, a kernel function is selected and defined. This method uses radial basis functions as the kernel function, mapping the data to a high-dimensional feature space, and employs cross-validation to determine the optimal parameter values. Support Vector Machines (SVMs) use maximizing the Lagrange dual problem as the objective function. The quadratic programming problem is decomposed into a series of solvable subproblems using a sequential minimum optimization algorithm to optimize the solution of this objective function. This approach reduces computational complexity, improves the training efficiency of SVMs on large-scale datasets, and ultimately yields the Lagrange multipliers.
[0091] Based on the above, the final classification decision function is shown below. Given a new input sample x, the kernel function K(x) is used to determine the classification decision function. i ,x) Calculate the relationship between this sample and all training samples x i The similarity is calculated, and then these similarities are weighted and summed, where α i y i The classification is derived from the Lagrange multipliers learned during training and the labels of the training samples. Finally, a bias term b is added, and the classification result is obtained through the sign function sign. If the result is positive, the sample is classified as positive (+1), corresponding to the node that has a positive effect on the inference result; if the result is negative, the sample is classified as negative (-1), corresponding to the node that has a negative effect on the inference result.
[0092]
[0093] In step (5), the test set of the mathematical problem set is solved, which mainly includes four parts: example selection, reasoning of the pre-trained language model, intervention by the feature classifier trained in step (4) during the reasoning process, and finally extraction of the generated answer. Specifically:
[0094] The first step is example selection, for problem q in the set of mathematical problems to be reasoned about. i Two random problem examples d a With d b Context as a clue to the thought chain
[0095] Next is the inference of the pre-trained language model. Here, the inference generation logic of step (2) is continued. The two examples are combined with the question as input to the pre-trained language model, and the inference paths of the two are compared. If in example d a With d b As a hint, if the currently generated texts are the same, continue reasoning; if the currently generated texts are different, a feature classifier C needs to be introduced for judgment and selection. Calculate the attention weight matrices used to generate the current text for both, and perform average pooling in the layer dimension and linear interpolation in the sequence length dimension to obtain the result for example d. a The characteristic matrix A below a And example d b The characteristic matrix A below b The feature matrix is used by the feature classifier C(x) to obtain classification results (+1: positive class, -1: negative class). The classification results fall into the following three categories, and are processed accordingly:
[0096] 1. C(A) a )=C(A b If ) = 1, then in the current text, both play a positive role in the correctness of the reasoning path generation. In this case, the term with the larger value in the sign function of the feature classifier C is selected as the predicted content of the currently generated text.
[0097] 2. C(A) a )=-1,C(A b ) = 1 or C(A) a )=1,C(A b If C(x) = -1, then for the current text, the two examples have positive and negative effects on the correctness of the generated inference path, respectively. In this case, the text with C(x) = 1 is selected as the predicted text for the current generation.
[0098] 3. C(A) a )=C(A b= -1, meaning that in the current text, both have a negative effect on the correctness of the reasoning path generation. In this case, the term with the smaller value in the sign function of the feature classifier C is selected as the predicted content of the currently generated text.
[0099] Based on the above rules, the reasoning process and answer to the mathematical problem are finally obtained.
[0100] This invention also includes a system for solving mathematical problems based on a feature classifier using thought chain reasoning, which extracts instances for a certain set of mathematical problems, including:
[0101] The thought chain prompt generation module is used to obtain the mathematical reasoning problem to be processed, and select examples and instructions that meet the requirements according to the problem to form the complete input of the pre-trained language model.
[0102] Inference path tree generation and feature selection module: used to generate word-level inference path generation trees and select feature training datasets that meet the requirements.
[0103] Feature Classifier Training Module: Used for training feature classifiers. It introduces the Support Vector Machine (SVM) algorithm based on the feature training dataset, uses radial basis functions as kernel functions to map data to a high-dimensional feature space, and employs a sequence minimum optimization algorithm to improve SVM training efficiency.
[0104] Feature classifier-guided reasoning module: Used to solve the mathematical reasoning problem to be processed. By intervening with the feature classifier, the pre-trained language model is guided to select a more accurate reasoning path, thereby obtaining the final mathematical reasoning process and answer.
[0105] The embodiments described above provide a detailed explanation of the technical solutions and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the present invention. Any modifications, additions, and equivalent substitutions made within the scope of the principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for solving mathematical problems based on thought chain reasoning using feature classifiers, characterized in that, Includes the following steps: (1) Obtain the mathematical problem set Q = {q1, q2, ... q} n }, for each element q i Use the mind chain hint generation method to find the two corresponding examples. and Make Get the correct answer, If an incorrect answer is obtained, a new set Q′={q1′,q′2…q′ is formed. n },in (2) Based on the new set Q′, input the pre-trained language model to construct a text-level inference path generation tree, with each node n i Choose the attention weight matrix A after average pooling and interpolation. i It is stored as a node feature; the specific process is as follows: For all elements in the new set Q′, for The input text for the pre-trained language model is obtained by concatenation. Freeze all parameters of the model and use them as input to a pre-trained language model for forward inference; During the reasoning process, q′ i Correspondingly generated inference path tree G i Each node n j It includes three types of attributes (f(A) j ,l),x j ,r j ), where x j The text representing the current node, r j This indicates that the process has passed through node n. j The accuracy of all reasoning paths, A j Indicates the prediction of generating x j The attention weight matrix of the time model; since the pre-trained language model uses a multi-head mask self-attention mechanism, the sequence length of its input model is different, so the f(·) function is used to transform and process the multi-head attention weight matrix. The process of constructing the reasoning path tree is as follows: First, construct an empty node n. root Let n be the root node of the reasoning path tree and marked as a non-leaf node. When constructing the tree, find the non-leaf node among the terminal nodes of each path; let this node be n. i From the root node n root to node n i Each path can represent a reasoning path. Then determine node n i The child node situation; specifically, and When the first i text sequences are input into the pre-trained language model, the language model makes predictions based on the following probabilities: x i+1 There are two possible scenarios: The first scenario: If the text generated by the prediction in the current round is the same for both prompts, that is... Then node n i A new child node n will be added. i+1 The text attribute is set to if If it is a sentence terminator, then mark the child node as a leaf node; The second scenario: For two prompts, the texts generated in this round of prediction are different, i.e. Then let node n i Insert the left and right child nodes respectively The text attributes are set to respectively as well as if If it is a sentence terminator, then mark the child node. If it is a leaf node; If it is a sentence terminator, then mark the child node. Leaf node; This process continues until the terminal node of each path in the tree is a leaf node; ultimately, all elements in the new set Q′ generate their corresponding reasoning path trees, resulting in a tree set G = {G1, G2, ... G}. m }; (3) Traverse all the inference path generation trees generated in step (2), and select nodes that meet the requirements to construct the feature classifier training set; use the attention weight matrix A of the nodes. i As features, the inference path results are used as labels to construct a set of training data sample pairs D; (4) Based on the training set generated in step (3), train the feature classifier C using the support vector machine algorithm; (5) In the pre-trained language model inference stage, for the target mathematical problem q to be solved, two examples d are randomly selected from the dataset. a With d b Simultaneously, reasoning is performed. If the reasoning paths are the same, prediction and generation continue until the end. If the reasoning paths are different, the feature classifier C trained in step (4) selects the text with the higher correct probability to continue reasoning. Finally, the complete reasoning process is obtained, and the corresponding answer is extracted.
2. The method for solving mathematical problems based on feature classifier-based thought chain reasoning according to claim 1, characterized in that, In step (1), the mind chain hint generation method is used to find the two corresponding examples. and The specific process is as follows: Use p θ The probability distribution fitted by a pre-trained large language model with parameter θ is represented by... N represents d A chain of thought prompts, where d i =(q i ,r i ,a i ) represents the i-th example, q i ,r i ,a i Let q represent the question, reasoning steps, and answer, respectively; if q represents the question to be reasoned, then the few-shot thought chain (FS-CoT) is defined as: In the formula, y = {r, a} represents the generated inference step r and the inference result a; only N is considered. d For the case where the value is 1, for each problem q i Traverse the set of mathematical problems to find the corresponding examples. and Make The answer obtained under the condition of maximizing probability Correct, at the same time The answer obtained under the condition of maximizing probability Errors are excluded if no corresponding example is found; finally, combining the problem and the two corresponding examples yields a new set Q′={q1′,q′2…q′}. m }, m≤n where 3. The method for solving mathematical problems based on feature classifier-based thought chain reasoning according to claim 1, characterized in that, In step (3), nodes that meet the requirements are selected to construct the feature classifier training set. The specific process is as follows: First, the set G of trees generated in step (2) contains m trees, corresponding to the reasoning path generation tree for each problem in the mathematical problem set Q′, and each node in the tree contains three parts of attributes, n i =(f(A) i ,l),x i ,r i ), which are the feature matrix, the text, and the data passed through node n, respectively. i The accuracy of all inference paths; before selecting training set samples, the r of the nodes needs to be calculated. i Attributes: Assuming a reasoning path spanning tree, each path from the root node to a leaf node constitutes a reasoning path, and each reasoning path has a unique attribute 'a' representing the correctness of the reasoning path's result, where 1 indicates correctness and 0 indicates error; therefore, the following calculation formula is obtained: Wherein, β(n) i ,S j ) represents node n i Does it belong to reasoning path S? j If a node belongs to the tree set G, the value is 1; otherwise, the value is 0. The inference path accuracy of all nodes in all trees within the tree set G is calculated using the formula above. Then, nodes meeting the requirements are selected based on the following conditions to serve as the training dataset for the feature classifier: ① The node is neither a root node nor a leaf node; ② The r attribute value of a node is 0 or 1, that is, consider the case where all the answers of the reasoning path passing through this node are wrong or all are correct; Form a node set N = {n1, n2, ...} of all nodes that meet the conditions.
4. The method for solving mathematical problems based on feature classifier-based thought chain reasoning according to claim 1, characterized in that, The specific process of step (4) is as follows: First, features of each element in the training dataset D are extracted as input, and the inference path results are used as labels. The data is then standardized. Next, a radial basis function kernel is used to map the data to a high-dimensional feature space. A support vector machine (SVM) classification model is trained with the objective function of maximizing the Lagrange duality problem. Cross-validation is used to evaluate the model's performance, and hyperparameters are adjusted as needed. Finally, the trained SVM model is saved for subsequent inference. The resulting feature classifier C is shown below: In the formula, x is the new input sample, processed by the kernel function K(x) i ,x) Calculate the relationship between this sample and all training samples x i The similarity is calculated, and then these similarities are weighted and summed, where α i y i The classification result is derived from the Lagrange multipliers learned during training and the labels of the training samples; finally, the bias term b is added, and the classification result is obtained through the sign function sign.
5. The method for solving mathematical problems based on feature classifier-based thought chain reasoning according to claim 1, characterized in that, In step (5), if the reasoning paths are different, the feature classifier C trained in step (4) will select the text with the higher correct probability to continue reasoning. Specifically, this includes: Calculate the attention weight matrices used to generate the current text for both, and perform average pooling at the layer dimension and linear interpolation at the sequence length dimension to obtain the result for example d. a The characteristic matrix A below a And example d b The characteristic matrix A below b The feature matrix is used to obtain the classification result through the feature classifier C(x). The classification result includes the following three cases, which are processed as follows: ①、C(A a )=C(A b =1, meaning that in the current text, both play a positive role in the correctness of the reasoning path generation. In this case, the term with the larger value in the sign function of the feature classifier C is selected as the predicted content of the currently generated text. ②、C(A a )=-1,C(A b ) = 1 or C(A) a )=1,C(A b C(x) = -1, meaning that for the current text, the two examples have positive and negative effects on the correctness of the generated inference path, respectively; in this case, the text with C(x) = 1 is selected as the predicted text content for the current generation. ③、C(A a )=C(A b = -1, meaning that in the current text, both have a negative effect on the correctness of the reasoning path generation. In this case, the term with the smaller value in the sign function of the feature classifier C is selected as the predicted content of the currently generated text.
6. A system for solving mathematical problems based on a feature classifier using thought chain reasoning, characterized in that, The method includes a memory and one or more processors, wherein the memory stores executable code, and the one or more processors execute the executable code to implement the method for solving mathematical problems of thought chain reasoning as described in any one of claims 1-5.
Citation Information
Patent Citations
Task processing method and device, electronic equipment and storage medium
CN118113444A
Mathematical problem answering model training method and device
CN116595159A
Large language model rational content generation method based on implicit thinking chain
CN117892818A