Method and system for solving thinking chain reasoning mathematical problem based on feature classifier

By introducing feature classifiers in thinking chain inference, filtering and training feature classifiers to guide the inference path selection of pre-trained language models, the problems of thinking chain inference accuracy and computational cost in the existing technology are solved, and more efficient and Accurate mathematical problem solving.

CN119443267AActive Publication Date: 2025-02-14ZHEJIANG UNIV

Patent Information

Application Number
CN202411479942.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-23
Publication Date
2025-02-14
Estimated Expiration
2044-10-23

AI Technical Summary

Technical Problem

In the thinking chain reasoning of existing pre-trained language models, methods such as self-consistency and thinking tree have limitations in improving the accuracy of inference of complex mathematical problems, and their computing cost and performance are limited.

Method used

Using the thinking chain reasoning method based on feature classifier, the word-level reasoning path spanning tree is constructed by obtaining the mathematical problem set and using the thinking chain prompt generation method, filtering the feature classifier training set, using the support vector machine algorithm to train the feature classifier, and booting Pre-trained language models choose more accurate inference paths.

Benefits of technology

It improves the quality and accuracy of the mathematical problem solving process, reduces the computing resource requirements, saves calculation costs, and improves the universality and interpretability of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119443267A_ABST
    Figure CN119443267A_ABST
Patent Text Reader

Abstract

The invention discloses a feature classifier-based thinking chain reasoning mathematical problem solving method and system. The method comprises the following steps of: (1) acquiring a mathematical problem set, and selecting forward and reverse thinking chain examples to splice to form a new set; (2) respectively inputting the new set elements into a model for reasoning to construct a word-level reasoning path spanning tree, and selecting an attention weight matrix after pooling difference processing as node features for storage; (3) traversing all the generated reasoning path spanning trees, and screening nodes meeting requirements to construct a feature classifier training set; (4) training a feature classifier by using a support vector machine algorithm; and (5) through the trained feature classifier, participating in path selection in a pre-training language model reasoning process, and obtaining a relatively accurate reasoning process and answers. By means of the method, adjustment and control of finer granularity of the reasoning path of the pre-training language model can be achieved, accurate reasoning solving of the pre-training language model on mathematical problems is facilitated, and the generalization level of the pre-training language model is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer application technology, and in particular to a method and system for solving mathematical problems based on thought chain reasoning of feature classifiers. Background Art

[0002] In recent years, deep learning artificial intelligence technology has undergone the following research paradigm shifts: from the early task-specific models of "supervised learning with labeled data", to the pre-trained models of "pre-training with unlabeled data + fine-tuning with labeled data", to the large models of "large-scale pre-training with unlabeled data + fine-tuning of instructions + human alignment", artificial intelligence technology is gradually entering the era of large models. At the same time, as the scale of model parameters and pre-training data continues to increase and reach the order of hundreds of billions, large language models have emerged with powerful contextual learning capabilities, that is, learning from examples of model input context, and then being able to perform a series of complex tasks, becoming a powerful tool to help humans handle a series of automated complex tasks. As a specific application of contextual learning, the thinking chain technology allows the large language model to gradually participate in decomposing a complex problem into step-by-step sub-problems and solving them one by one, completing the mapping from input to thinking chain to output, which can significantly improve the performance of large models in complex reasoning task scenarios.

[0003] Mathematical reasoning is crucial to artificial intelligence and has driven the continued exploration of autonomously solving mathematical problems. This process requires enhancing the model's reasoning capabilities and in-depth research on text understanding, image recognition, table analysis, symbolic operations, logical operations, and a deep grasp of world knowledge. Comprehensively improving the understanding ability of large language models in various mathematical fields can not only reflect technical strength, but also is an important step towards general artificial intelligence. Existing research can prove that large language models are effective tools to help solve mathematical problems. Their language capabilities have prompted us to explore how to use them for mathematical reasoning, revealing new insights into the synergy between language and logic.

[0004] For example, a Chinese patent document with publication number CN116595159A discloses a method and device for training a math problem-solving model. First, a pre-trained language model with frozen parameters is used to generate a solution with a reasoning process corresponding to the correct answer to the math problem as an example of thinking chain learning. Then, the math problem-solving model is used to generate the reasoning process and answer corresponding to the target math problem to be solved multiple times. A self-consistent majority voting method is used to use the reasoning process and answer generated the most times as the final result corresponding to the target math problem.

[0005] The Chinese patent document with publication number CN118113444A discloses a task processing method, device, electronic device and storage medium. The method uses a pre-trained language model to decompose the target task into steps according to the input content and output description of the target task, thereby generating a corresponding mind tree. The nodes of the mind tree represent the steps obtained by the step decomposition, so that the model has the ability to search between multiple reasoning chains. Based on a preset search algorithm, the best step path for executing the target task is found in the mind tree; then, based on the best step path, the target task is executed according to the input content, and its execution result is output.

[0006] However, the subsequent work related to the pre-trained language model thinking chain reasoning, including self-consistency and thinking tree methods to improve the reasoning of complex mathematical problems, all focus on the sequence-level reasoning path, which has limited effect on improving the accuracy of the reasoning results and is constrained by the type of mathematical problems. In addition, self-consistency may generate incorrect or meaningless reasoning paths, and the reasoning chain search method of the thinking tree also requires more computing resources than sampling. Similar work is limited by computing costs and performance. Summary of the invention

[0007] The present invention provides a method and system for solving mathematical problems by chain-of-thought reasoning based on a feature classifier, which can provide a problem-solving process and answer with high quality and accuracy.

[0008] A method for solving mathematical problems by chain-of-thought reasoning based on a feature classifier comprises the following steps:

[0009] (1) Obtain a set of mathematical problems Q = {q1,q2…q n}, for each element q i , use the thought chain prompt generation method to find the corresponding two examples and Make Get the correct answer, Get the wrong answer and form a new set Q ′ ={q1 ′ ,q ′ 2…q ′ n},in

[0010] (2) New set Q based on composition ′ , use the thought chain prompt method to input the pre-trained language model and build a word-level reasoning path spanning tree. i Save the attention weight matrix A after average pooling and difference operation i ;

[0011] (3) Traverse all the inference paths generated in step (2) to generate trees, select nodes that meet the requirements to build a feature classifier training set; use the node attention weight matrix A i As features, the inference path results are labels, and a set D of training data sample pairs is constructed;

[0012] (4) Based on the training set generated in step (3), a feature classifier C is trained using a support vector machine algorithm;

[0013] (5) In the pre-trained language model reasoning phase, for the target math problem q to be solved, two examples d are randomly selected from the dataset. a With d b The reasoning is performed simultaneously. If the reasoning paths are the same, the prediction generation continues until the end. If the reasoning paths are different, the feature classifier C trained in step (4) selects the word with a higher correct probability to continue reasoning. Finally, the complete reasoning process is obtained and the corresponding answer is extracted.

[0014] The present invention first selects some problems based on the mathematical problem data set, uses the thinking chain method to construct a word granularity level reasoning path generation tree, and then screens the training sample data to train the feature selector. When the pre-training prediction model is reasoned, the thinking chain prompt method is used to process the target mathematical problem to be solved, and the feature classifier is used to intervene in the selection and generation of the reasoning path during reasoning, so as to obtain a problem solving process and answer with high quality and accuracy.

[0015] In step (1), use the thought chain prompt generation method to find the corresponding two examples and The specific process is:

[0016] Use p θ represents the probability distribution fitted by the pre-trained large language model with parameter θ, and

[0017] N d Thinking chain prompts, among which, d i =(q i ,r i ,a i ) is the i-th example, q i ,r i ,a i Represent the question, reasoning steps and answer respectively; if q is used to represent the question to be reasoned, then the few-shot thinking chain FS-CoT is defined as:

[0018]

[0019] Where y = {r, a} is the generated reasoning step r and the reasoning result a; only considering N dThe value is 1, for each question q i , traverse the math problem set to find the corresponding example and Make The answer with the highest probability Correct, at the same time The answer with the highest probability Error, if no corresponding example is found, the problem is excluded; finally, the new set Q is obtained by combining the problem and the corresponding two examples. ′ ={q1 ′ ,q ′ 2…q ′ m},m≤nwhere

[0020] The specific process of step (2) is as follows:

[0021] For the new set Q ′ For all elements in The input text of the pre-trained language model is obtained by concatenation Freeze all parameters of the model and use it as input to the pre-trained language model for forward inference;

[0022] During the reasoning process, q i ′ Corresponding to the generated inference path tree G i , each node n j Contains three types of attributes (f(A j ,l),x j ,r j ), where x j Indicates the text of the current node, r j It means passing through node n j The accuracy of all reasoning paths, A j Represents the prediction generation x j The attention weight matrix of the model at that time; since the pre-trained language model uses a multi-head masked self-attention mechanism, the sequence length of its input model is different, the f(·) function is used to transform and process the multi-head attention weight matrix;

[0023] The process of constructing the inference path tree is as follows: First, construct an empty node n root , as the root node of the inference path tree, marked as a non-leaf node; when building the tree, find one of the non-leaf nodes at the end of each path of the tree, and set the node as n i ; From the root node n root To node n i Any path can represent an inference path Then determine the node n i ; specifically, and Input the pre-trained language model separately. When the first i text sequences are input, the language model predicts according to the following probabilities:

[0024]

[0025] x i+1 There are two situations:

[0026] The first type: For two prompts, the text generated in this round of prediction is the same, that is Then node n i A new child node n will be added i+1 , the text properties are set to if If it is a sentence terminator, mark the child node as a leaf node;

[0027] The second type: For the two prompts, the text generated in this round of prediction is different, that is Then for node n i Insert the left and right child nodes respectively The text properties are set to as well as if Is a sentence terminator, then mark the child node is a leaf node; if Is a sentence terminator, then mark the child node is a leaf node;

[0028] And so on, until the end nodes of each path in the tree are leaf nodes; finally, the new set Q ′ All elements in generate their corresponding reasoning path trees, and the tree set 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 tree set G generated in step (2) contains m trees, corresponding to the mathematical problem set Q ′ The reasoning path of each question in the tree generates a tree, and each node in the tree contains three parts of attributes, n i =(f(A i ,l),x i ,r i ), which are feature matrix, text and node n respectively. iThe accuracy of all reasoning paths; before screening the training set samples, it is necessary to calculate the r of the node i Attributes, assuming that for an inference path spanning tree, the path from the root node to the leaf node constitutes an inference path, and for an inference path there is a unique attribute a that represents the correctness of the result of the inference path, where 1 represents correctness and 0 represents error; therefore, the following calculation formula is obtained:

[0032]

[0033] Among them, β(n u ,S j ) represents node n j Whether it belongs to reasoning path S i , if it belongs to the tree, the value is 1, if it does not belong to the tree, the value is 0, and the inference path accuracy of all nodes in all trees in the tree set G is calculated according to the above formula; then the nodes that meet the requirements are selected based on the following conditions as the training data set for training the feature classifier:

[0034] ①. The node is not a root node or a leaf node;

[0035] ② The r attribute value of a node is 0% or 100%, which means that the answers to the reasoning paths passing through the node are all wrong or all correct;

[0036] All nodes that meet the conditions are grouped into a node set N = {n1, n2, ...}.

[0037] The specific process of step (4) is as follows:

[0038] First, extract the features of each element of the training data set D as input, use the inference path results as labels, and standardize the data; then, use the radial basis kernel function to map the data to a high-dimensional feature space, and train the support vector machine classification model with the objective function of maximizing the Lagrangian dual problem. Use cross-validation to evaluate the model performance, and adjust the hyperparameters as needed; finally, save the trained support vector machine model for subsequent inference; the resulting feature classifier C is shown below:

[0039]

[0040] In the formula, x is a new input sample, and the kernel function K(x i ,x) calculate the sample and all training samples x i The similarities are then weighted and summed, where α i y i It comes from the Lagrange multipliers learned during the training process 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 a higher correct probability to continue reasoning, which specifically includes:

[0042] The attention weight matrices used to generate the current text are calculated for both, and the average pooling of the layer dimension and the linear interpolation of the sequence length dimension are performed to obtain a The characteristic matrix A a And example d b The characteristic matrix A b ; The feature matrix obtains 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, that is, in the current text, both play a positive role in the correctness of the reasoning path generation. In this case, the item with a larger value in the symbol function in the feature classifier C is selected as the prediction content of the currently generated text;

[0044] ②, C (A a )=-1,C(A b )=1orC(A a )=1,C(A b )=-1, that is, for the current text, the two examples play a positive and negative role in the correctness of the correct reasoning path generation respectively; in this case, the text with C(x)=1 is selected as the currently generated text prediction content;

[0045] ③、C(A a )=C(A b )=-1, that is, in the current text, both play a negative role in the correctness of the reasoning path generation. In this case, the item with a smaller value in the symbol function in the feature classifier C is selected as the prediction content of the currently generated text.

[0046] Based on the same inventive principle, the present invention also provides a thinking chain reasoning mathematical problem solving system based on a feature classifier, comprising:

[0047] Thinking chain prompt generation module: used to obtain the mathematical reasoning problems to be processed, and select examples and instructions that meet the requirements according to the problems to form the complete input of the pre-trained language model;

[0048] Reasoning path tree generation and feature screening module: used to generate word-level reasoning path generation trees and screen out feature training data sets that meet the requirements;

[0049] Feature classifier training module: used for feature classifier training. It introduces the support vector machine algorithm based on the feature training data set, uses the radial basis function as the kernel function to map the data to the high-dimensional feature space, and uses the sequence minimum optimization algorithm to improve the training efficiency of the support vector machine.

[0050] Reasoning module guided by feature classifier: used to solve pending mathematical reasoning problems; through the intervention of feature classifier, the pre-trained language model is guided to select a more accurate reasoning path, so as to obtain the final mathematical problem reasoning process and answer.

[0051] Based on the same inventive principle, the present invention also provides a system for solving mathematical problems by chain reasoning based on a feature classifier, comprising a memory and one or more processors, wherein 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 by chain reasoning.

[0052] Compared with the prior art, the present invention has the following beneficial effects:

[0053] 1. The present invention focuses on text-level prediction generation. Compared with the current mainstream sequence-level technology, the processing granularity at the text level is significantly smaller. This improves the accuracy of the prediction and enables more precise and effective control over the generation of inference results. In practical applications, this kind of fine text-level processing can better adapt to complex and changing demand scenarios and provide users with more targeted and reliable results.

[0054] 2. The present invention innovatively uses a self-trained feature classifier. This classifier exhibits excellent transferability and broad generalization performance when faced with various types of mathematical reasoning tasks. This means that it can quickly adapt and function in different tasks and scenarios without a lot of retraining and adjustment, thereby greatly improving work efficiency and the versatility of the model.

[0055] 3. Compared with common methods such as self-consistency and mind tree reasoning chain search, the present invention shows obvious advantages in terms of computing resource requirements. It has relatively few resource requirements and can significantly save computing costs. This not only reduces the hardware threshold for system operation, but also provides greater possibilities for large-scale application and deployment, so that efficient computing can be carried out smoothly in an environment with limited resources.

[0056] 4. This invention also has certain research significance for the interpretability of pre-trained language model reasoning under the guidance of thought chain. 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 in a more transparent, interpretable and reliable direction. BRIEF DESCRIPTION OF THE DRAWINGS

[0057] Figure 1 A flow chart of a method for solving mathematical problems based on a thought chain reasoning method of a feature classifier according to the present invention;

[0058] Figure 2 Construct reasoning path generation tree diagrams for positive and negative examples;

[0059] Figure 3 A schematic diagram of the tree nodes for screening reasoning paths;

[0060] Figure 4 Flowchart for training a support vector machine feature classifier. DETAILED DESCRIPTION

[0061] The present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be pointed out that the embodiments described below are intended to facilitate the understanding of the present invention and do not have any limiting effect on the present invention.

[0062] like Figure 1 As shown, a method for solving mathematical problems based on thought chain reasoning of feature classifiers comprises the following steps:

[0063] (1) Obtain a mathematical problem data set Problem set Q = {q1, q2…q n}, and for each element q i Find the corresponding thought chain example and Make Get the correct answer, Get the wrong answer and form a new set Q ′ ={q1 ′ ,q ′ 2…q ′ n},in

[0064] (2) Composition-based set Q ′ , use the thought chain prompt method to input the pre-trained prediction model and construct a word-level reasoning path spanning tree. Each node n i Save the attention weight matrix A after average pooling and difference operation j .

[0065] (3) Traverse all the reasoning paths generated in step (2) to generate trees, select nodes that meet the requirements to build a feature classifier training set, with the following requirements: all reasoning paths passing through the node have the same results, that is, all are correct or all are wrong. i As features, the inference path results are labels, and a set D of training data sample pairs is constructed.

[0066] (4) Based on the training set generated in step (3), the feature classifier C is trained using the support vector machine (SVM) algorithm. First, the features of each element of the training data set D are extracted as input, the inference path results are used as labels, and the data is standardized. Then, the radial basis function is used as the kernel function to map the data to a high-dimensional feature space, the SVM model is trained, the model performance is evaluated using cross-validation, and the hyperparameters are adjusted as needed. Finally, the trained model is saved for subsequent reasoning.

[0067] (5) In the pre-trained language model reasoning phase, for the target math problem q to be solved, two examples d are randomly selected from the dataset. a With d b The reasoning is performed simultaneously. If the reasoning paths are the same, the prediction generation continues until the end. If they are different, the feature classifier C trained in step (4) selects the word with a 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 mathematical problem set to be solved is obtained and examples of forward and reverse thinking chains are selected to form a new model input set. First, the mathematical problem set to be solved is defined as Q = {q1, q2…q n}, where each element q i State a specific problem in the problem set. For each problem q i , use the thought chain prompt generation method to find the corresponding positive examples And the reverse example The thinking chain prompt method is as follows:

[0069] Use p θ represents the probability distribution fitted by the pre-trained large language model with parameter θ, X = {x1, x2, …, x N} represents a text sequence with an input length of N. When the first i text sequences are input, the language model uses the probability p θ (x i+1 )=p θ (x i+1 |x1,…,x i ) to make predictions.

[0070] use N d Thinking chain prompts, among which, d i = {q i ,r i ,a i} is the i-th example, q i ,r i ,a iRepresent the question, reasoning steps and answer respectively. If q is used to represent the question to be reasoned, then the few-shot thinking chain can be defined as follows:

[0071]

[0072] In the formula, y = {r, a} is the generated reasoning step r and the reasoning result a. In this step, only N d The value is 1, so for each question q i , traverse the math problem set to find the corresponding example and Make The answer with the highest probability Correct, at the same time The answer with the highest probability Error, if no corresponding example is found, the problem is excluded. Finally, the new set Q can be obtained by combining the problems in the original data set and the corresponding positive and reverse examples. ′ ={q1 ′ ,q ′ 2…q ′ m},m≤nwhere

[0073] In step (2), the new set elements are input into the model for reasoning to construct a text-level reasoning path generation tree, and the attention weight matrix after pooling difference processing is selected as the node feature for storage.

[0074] Traverse the new set Q generated by combining in step (1) ′ ,for The input text of the model is obtained by simple concatenation Freeze all parameters of the model and use it as the input of the pre-trained language model for forward reasoning. During the reasoning process, q i ′ Corresponding to the generated inference path tree G i = {V, E}, where V represents the vertex set and E represents the edge set. j Contains three types of attributes (f(A j ,l),x j ,r j ), where x j Indicates the text of the current node, r j It means passing through node n j The accuracy of all reasoning paths. j Represents the prediction generation x jThe attention weight matrix of the model is , because the pre-trained language model uses a multi-head masked self-attention mechanism, and the sequence length of its input model is different. The f(·) function is used to transform and process the multi-head attention weight matrix.

[0075] f(A j ,l) The function mainly performs two operations on the multi-head attention weight matrix. The first step uses the linear interpolation method to transform the matrix A ij Compress or expand from dimension j×j to a fixed length l. In the specific implementation process, l=30 is set based on experimental experience. In the second step, average pooling is performed on the layer dimension of the multi-head self-attention matrix to finally obtain a fixed-size feature matrix, 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 building the inference path tree. First, construct an empty node n root , as the root node of the inference path tree, marked as a non-leaf node. When constructing the tree, find one of the non-leaf nodes at the end of each path of the tree (if there are multiple nodes, randomly select one), and set the node as n i . From the root node n root To node n i Any path can represent an inference path Then determine the node n i Specifically, we will and Input the pre-trained language model respectively, such as Figure 2 As shown in Figure 1, 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 situations:

[0079] The first type: For two prompts, the text generated in this round of prediction is the same, that is Then node n i A new child node n will be added i+1 , the text properties are set to if is a sentence terminator, then mark the child node as a leaf node.

[0080] The second type: For the two prompts, the text generated in this round of prediction is different, that is Then for node n i Insert the left and right child nodes respectively The text properties are set to as well as if Is a sentence terminator, then mark the child node is a leaf node; if Is a sentence terminator, then mark the child node It is a leaf node.

[0081] And so on, until the end nodes of each path in the tree are leaf nodes. Finally, the new set Q ′ All elements in can generate their corresponding reasoning path trees, and we can get a tree set G = {G1, G2, ... G m}.

[0082] In step (3), the inference path generated by step (2) is traversed to generate a tree, nodes that meet the requirements are selected, labeled, and a training data sample set is constructed together with their feature attributes. The specific implementation process is as follows.

[0083] First, the tree set G generated in step (2) contains m trees, corresponding to the mathematical problem set Q ′ The reasoning path of each question in the tree generates a tree, and each node in the tree contains three parts of attributes, n i =(f(A i ,l),x i ,r i ), which are feature matrix, text and node n respectively. i The correctness of all reasoning paths. The definition is as follows: Assume that for a reasoning path spanning tree, the path from the root node to the leaf node constitutes a reasoning path, and for a reasoning path there is a unique attribute a that represents the correctness of the result of this reasoning path, where 1 represents correctness and 0 represents error. Therefore, the following formula can be obtained:

[0084]

[0085] Where β(n i ,S j ) represents node n j Whether it belongs to reasoning path S j , if it belongs, the value is 1, if it does not belong, the value is 0, and the inference path accuracy of all nodes of all trees in the tree set G is calculated according to the above formula.

[0086] Then, based on the following conditions, we filter out nodes that meet the requirements as the training data set for training the feature classifier:

[0087] 1) The node is not a root node or a leaf node;

[0088] 2) The r attribute value of the node is 0 or 100, that is, the answers to the reasoning paths passing through the node are all wrong or all correct.

[0089] Finally, all nodes that meet the conditions are combined into a node set N = {n1, n2, ...}. Figure 3 As shown, in the inference path generation tree, there are multiple inference paths corresponding to correct or incorrect results. According to the above screening conditions, the bold nodes can be selected as the training sample set.

[0090] In step (4), train the support vector machine feature classifier D(x). Figure 4 As shown, the first step is to prepare the training data set. Based on step (3), the node set that meets the conditions is screened out to construct the training set T = {(x1, y1), (x2, y2), ..., (x n ,y n )}. n Represents the node attention weight matrix after average pooling in the layer dimension and linear interpolation in the sequence length dimension, y n ∈{1,-1} is a label, indicating the correctness or error of the inference result. Secondly, select and define the kernel function. This method uses the radial basis function as the kernel function, maps the data to a high-dimensional feature space, and uses cross-validation to determine the optimal parameter value. The support vector machine takes the maximization of the Lagrangian dual problem as the objective function, and decomposes the quadratic programming problem into a series of solvable sub-problems through the sequential minimum optimization algorithm to optimize the solution of the objective function. This approach can reduce the computational complexity and improve the training efficiency of the support vector machine on large-scale data sets, thereby obtaining the Lagrangian multiplier.

[0091] Based on the above, the final classification decision function is as follows. Given a new input sample x, through the kernel function K(x i ,x) calculate the sample and all training samples x i The similarities are then weighted and summed, where α i y i It comes from the Lagrange multiplier learned during the training process and the label of the training sample. Finally, the 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 the positive class (+1), corresponding to the node that has a positive effect on the reasoning result; if the result is negative, the sample is classified as the negative class (-1), corresponding to the node that has a negative effect on the reasoning result.

[0092]

[0093] In step (5), the test set of the math problem set is solved, which mainly includes four parts: example selection, reasoning of the pre-trained language model, intervention of the feature classifier trained in step (4) during the reasoning process, and finally extraction of the generated answer. The details are as follows:

[0094] The first step is to select examples. For the problem q in the set of mathematical problems to be reasoned, i Randomly select two problem examples d a With d b Context as a Thought Chaining Prompt

[0095] Then comes the inference of the pre-trained language model. Here, the inference generation logic of step (2) is continued. The two examples are merged with the question as the input of the pre-trained language model, and the inference paths of the two are compared. a With d b If the currently generated text is the same, the reasoning continues; if the currently generated text is different, the feature classifier C needs to be introduced for judgment and selection. The attention weight matrices used to generate the current text are calculated for both, and the average pooling of the layer dimension and the linear interpolation of the sequence length dimension are performed. For example d a The characteristic matrix A a And example d b The characteristic matrix A b The feature matrix is ​​classified by the feature classifier C(x) (+1: positive class, -1: negative class). The classification results are included in the following three cases, which are processed as follows:

[0096] 1. C(A a )=C(A b )=1, that is, in the current text, both play a positive role in the correctness of the reasoning path generation. In this case, the item with a larger value in the symbol function in the feature classifier C is selected as the prediction content of the currently generated text.

[0097] 2. C(A a )=-1,C(A b )=1orC(A a )=1,C(A b )=-1, that is, for the current text, the two examples play a positive and negative role in the correctness of the correct reasoning path generation. In this case, the text with C(x)=1 is selected as the currently generated text prediction content.

[0098] 3. C(A a )=C(A b)=-1, that is, in the current text, both play a negative role in the correctness of the reasoning path generation. In this case, the item with a smaller value in the symbol function in the feature classifier C is selected as the prediction content of the currently generated text.

[0099] Based on the above rules, we can finally get the reasoning process and answer of the mathematical problem.

[0100] The present invention also includes a thinking chain reasoning mathematical problem solving system based on a feature classifier, which extracts examples for a certain type of mathematical problem set, including:

[0101] Thinking chain prompt generation module: used to obtain the mathematical reasoning problems to be processed, and select examples and instructions that meet the requirements according to the problems to form the complete input of the pre-trained language model.

[0102] Reasoning path tree generation and feature screening module: used to generate word-level reasoning path generation trees and screen out feature training data sets that meet the requirements.

[0103] Feature classifier training module: used for feature classifier training. It introduces support vector machine algorithm based on feature training data set, uses radial basis function as kernel function to map data to high-dimensional feature space, and uses sequence minimum optimization algorithm to improve SVM training efficiency.

[0104] Reasoning module guided by feature classifier: used to solve pending mathematical reasoning problems. Through the intervention of 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 description of the technical solutions and beneficial effects of the present invention. It should be understood that the above are only specific embodiments of the present invention and are not intended to limit the present invention. Any modifications, supplements and equivalent substitutions made within the scope of the principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A method for solving mathematical problems by chain reasoning based on feature classifier, characterized in that: The following steps are involved: (1) Obtain a set of mathematical problems Q = {q1,q2…q n }, for each element q i , use the thought chain prompt generation method to find the corresponding two examples and Make Get the correct answer, Get the wrong answer and form a new set Q ′ ={q1 ′ ,q ′ 2…q ′ n },in (2) New set Q based on composition ′ , use the thought chain prompt method to input the pre-trained language model and build a word-level reasoning path spanning tree. i Save the attention weight matrix A after average pooling and difference operation i ; (3) Traverse all the inference paths generated in step (2) to generate trees, select nodes that meet the requirements to build a feature classifier training set; use the node attention weight matrix A i As features, the inference path results are labels, and a set D of training data sample pairs is constructed; (4) Based on the training set generated in step (3), a feature classifier C is trained using a support vector machine algorithm; (5) In the pre-trained language model reasoning phase, for the target math problem q to be solved, two examples d are randomly selected from the dataset. a With d b The reasoning is performed simultaneously. If the reasoning paths are the same, the prediction generation continues until the end. If the reasoning paths are different, the feature classifier C trained in step (4) selects the word with a 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 by chain reasoning based on feature classifier according to claim 1 is characterized in that: In step (1), use the thought chain prompt generation method to find the corresponding two examples and The specific process is: Use p θ represents the probability distribution fitted by the pre-trained large language model with parameter θ, and N d Thinking chain prompts, among which, d i =(q i ,r i ,a i ) is the i-th example, q i ,r i ,a i Represent the question, reasoning steps and answer respectively; if q is used to represent the question to be reasoned, then the few-shot thinking chain FS-CoT is defined as: Where y = {r, a} is the generated reasoning step r and the reasoning result a; only considering N d The value is 1, for each question q i , traverse the math problem set to find the corresponding example and Make The answer with the highest probability Correct, at the same time The answer with the highest probability Error, if no corresponding example is found, the problem is excluded; finally, the new set Q is obtained by combining the problem and the corresponding two examples. ′ ={q1 ′ ,q ′ 2…q ′ m },m≤nwhere 3. The method for solving mathematical problems by chain reasoning based on feature classifier according to claim 1 is characterized in that: The specific process of step (2) is as follows: For the new set Q ′ For all elements in The input text of the pre-trained language model is obtained by concatenation Freeze all parameters of the model and use it as input to the pre-trained language model for forward inference; During the reasoning process, q i ′ Corresponding to the generated inference path tree G i , each node n j Contains three types of attributes (f(A j ,l),x j ,r j ), where x j Indicates the text of the current node, r j It means passing through node n j The accuracy of all reasoning paths, A j Represents the prediction generation x j The attention weight matrix of the model at that time; since the pre-trained language model uses a multi-head masked self-attention mechanism, the sequence length of its input model is different, the f(·) function is used to transform and process the multi-head attention weight matrix; The process of constructing the inference path tree is as follows: First, construct an empty node n root , as the root node of the inference path tree, marked as a non-leaf node; when building the tree, find one of the non-leaf nodes at the end of each path of the tree, and set the node as n i ; From the root node n root To node n i Any path can represent an inference path Then determine the node n i ; specifically, and Input the pre-trained language model separately. When the first i text sequences are input, the language model predicts according to the following probabilities: x i+1 There are two situations: The first type: For two prompts, the text generated in this round of prediction is the same, that is Then node n i A new child node n will be added i+1 , the text properties are set to if If it is a sentence terminator, mark the child node as a leaf node; The second type: For the two prompts, the text generated in this round of prediction is different, that is Then for node n i Insert the left and right child nodes respectively The text properties are set to as well as if Is a sentence terminator, then mark the child node is a leaf node; if Is a sentence terminator, then mark the child node is a leaf node; And so on, until the end nodes of each path in the tree are leaf nodes; finally, the new set Q ′ All elements in generate their corresponding reasoning path trees, and the tree set G = {G1,G2,...G m }。 4. The method for solving mathematical problems by chain reasoning based on feature classifier according to claim 1 is characterized in that: In step (3), nodes that meet the requirements are selected to construct a feature classifier training set. The specific process is as follows: First, the tree set G generated in step (2) contains m trees, corresponding to the mathematical problem set Q ′ The reasoning path of each question in the tree generates a tree, and each node in the tree contains three parts of attributes, n i =(f(A i ,l),x i ,r i ), which are feature matrix, text and node n respectively. i The accuracy of all reasoning paths; before screening the training set samples, it is necessary to calculate the r of the node i Attributes, assuming that for an inference path spanning tree, the path from the root node to the leaf node constitutes an inference path, and for an inference path there is a unique attribute a that represents the correctness of the result of the inference path, where 1 represents correctness and 0 represents error; therefore, the following calculation formula is obtained: Among them, β(n i ,S j ) represents node n j Whether it belongs to reasoning path S i , if it belongs to the tree, the value is 1, if it does not belong to the tree, the value is 0, and the inference path accuracy of all nodes in all trees in the tree set G is calculated according to the above formula; then the nodes that meet the requirements are selected based on the following conditions as the training data set for training the feature classifier: ①. The node is not a root node or a leaf node; ② The r attribute value of a node is 0% or 100%, which means that the answers to the reasoning paths passing through the node are all wrong or all correct; All nodes that meet the conditions are grouped into a node set N = {n1, n2, ...}.

5. The method for solving mathematical problems by chain reasoning based on feature classifier according to claim 1 is characterized in that: The specific process of step (4) is as follows: First, extract the features of each element of the training data set D as input, use the inference path results as labels, and standardize the data; then, use the radial basis kernel function to map the data to a high-dimensional feature space, and train the support vector machine classification model with the objective function of maximizing the Lagrangian dual problem. Use cross-validation to evaluate the model performance, and adjust the hyperparameters as needed; finally, save the trained support vector machine model for subsequent inference; the resulting feature classifier C is shown below: In the formula, x is a new input sample, and the kernel function K(x i ,x) calculate the sample and all training samples x i The similarities are then weighted and summed, where α i y i It comes from the Lagrange multipliers learned during the training process 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.

6. The method for solving mathematical problems by chain reasoning based on feature classifier according to claim 1 is characterized in that: In step (5), if the reasoning paths are different, the feature classifier C trained in step (4) selects the word with a higher correct probability to continue reasoning, which specifically includes: The attention weight matrices used to generate the current text are calculated for both, and the average pooling of the layer dimension and the linear interpolation of the sequence length dimension are performed to obtain a The characteristic matrix A a And example d b The characteristic matrix A b ; The feature matrix obtains 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, that is, in the current text, both play a positive role in the correctness of the reasoning path generation. In this case, the item with a larger value in the symbol function in the feature classifier C is selected as the prediction content of the currently generated text; ②, C (A a )=-1,C(A b )=1orC(A a )=1,C(A b )=-1, that is, for the current text, the two examples play a positive and negative role in the correctness of the correct reasoning path generation respectively; in this case, the text with C(x)=1 is selected as the currently generated text prediction content; ③、C(A a )=C(A b )=-1, that is, in the current text, both play a negative role in the correctness of the reasoning path generation. In this case, the item with a smaller value in the symbol function in the feature classifier C is selected as the prediction content of the currently generated text.

7. A thinking chain reasoning mathematical problem solving system based on feature classifier, characterized in that: include: Thinking chain prompt generation module: used to obtain the mathematical reasoning problems to be processed, and select examples and instructions that meet the requirements according to the problems to form the complete input of the pre-trained language model; Reasoning path tree generation and feature screening module: used to generate word-level reasoning path generation trees and screen out feature training data sets that meet the requirements; Feature classifier training module: used for feature classifier training. It introduces the support vector machine algorithm based on the feature training data set, uses the radial basis function as the kernel function to map the data to the high-dimensional feature space, and uses the sequence minimum optimization algorithm to improve the training efficiency of the support vector machine. Feature classifier-guided reasoning module: used to solve the mathematical reasoning problems to be processed; Through the intervention of feature classifiers, the pre-trained language model is guided to select a more accurate reasoning path, thereby obtaining the final reasoning process and answer to the mathematical problem.

8. A mathematical problem solving system based on feature classifier and chain reasoning, characterized in that: It comprises a memory and one or more processors, wherein the memory stores executable code, and when the one or more processors execute the executable code, it is used to implement the method for solving mathematical problems by thinking chain reasoning as described in any one of claims 1-6.

Citation Information

Patent Citations

  • Task processing method and device, electronic equipment and storage medium

    CN118113444A

  • Mathematical problem answering model training method and device

    CN116595159A

  • Depth fine tuning method for generating Chinese text logical reasoning thinking chain

    CN117669536A

  • Large language model rational content generation method based on implicit thinking chain

    CN117892818A

  • Flexible thinking chain learning method and device based on large language model and medium

    CN118333153A

Cited By

  • Test question label prediction method and device, storage medium and equipment

    CN119621974A

  • A test question label prediction method, device, storage medium and equipment

    CN119621974B

  • Intelligent decision-making method, computer equipment and computer readable storage medium

    CN119808966A

  • Mathematical inference-oriented visual thinking operation system and mathematical inference method

    CN119808967A

  • Automatic thinking chain prompt generation method based on black box optimization and vulnerability quantification

    CN120336491A