Mathematical inference method of large language model based on knowledge graph and dynamic pruning optimization

By constructing a knowledge graph and using dynamic pruning optimization methods, the hallucination problem of large language models in mathematical reasoning is solved, a more accurate and controllable problem-solving process is achieved, and the model's mathematical understanding and deductive ability are improved.

CN120671854BActive Publication Date: 2025-10-24JIANGXI NORMAL UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511163691.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-08-20
Publication Date
2025-10-24
Estimated Expiration
2045-08-20

AI Technical Summary

Technical Problem

Large language models frequently experience hallucinations in mathematical reasoning tasks. The lack of introduction and utilization of structured knowledge in the mathematical field leads to a lack of logical support and controllability in the problem-solving process, a lack of effective monitoring and intervention in the reasoning process, and an inability to adjust or eliminate unreasonable paths in a timely manner.

Method used

Build a dataset based on the knowledge graph, assign complexity scoring labels to knowledge points, optimize the reasoning path through semantic expansion and search tree optimization, dynamically prune, and combine the multi-dimensional reward model scoring to select the optimal solution path.

Benefits of technology

It significantly improves the accuracy and reliability of large language models in mathematical reasoning, provides a controllable reasoning support environment, reduces the risk of path divergence, and enhances mathematical understanding and deductive ability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120671854B_ABST
    Figure CN120671854B_ABST
Patent Text Reader

Abstract

The application discloses a large language model mathematical inference method based on a knowledge graph and dynamic pruning optimization, which constructs a mathematical data set containing multi-level knowledge points and complexity scores, establishes a structured knowledge graph integrating mathematical concepts, theorems and the like, extracts knowledge points from a problem to be solved and expands triplets to obtain a comprehensive difficulty score. When the score is less than or equal to a threshold value, a large language model is directly called for reasoning; when the score is greater than the threshold value, an initial search tree is constructed by modeling a starting point of the search tree, and an optimal path and an answer are obtained through path expansion and pruning, path scoring and optimization. The application provides reasoning support through a knowledge graph, combines difficulty parameters and dynamic pruning, and improves the mathematical understanding, deductive ability, reasoning stability and effectiveness of the model.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of large language model reasoning, in particular to a large language model mathematical inference method based on knowledge graph and dynamic pruning optimization. BACKGROUND

[0002] In recent years, large language models (LLMs) have made significant progress in natural language processing, especially in text generation, question answering, and translation tasks. However, in knowledge-intensive tasks such as mathematical reasoning, LLMs often exhibit the so-called "hallucination" problem, where the generated reasoning process or answer deviates from the truth and even contains fictional information. This phenomenon is particularly evident in solving mathematical application problems, as mathematical problems require rigorous logic and clear steps. Once a step in the reasoning process deviates, the final answer will be incorrect, affecting the reliability of the system. For example, some large models may give incorrect conclusions when comparing numerical values based on sentence patterns (e.g., misinterpreting "9.11" as greater than "9.8"), exposing the limitations of models relying on language patterns rather than real mathematical semantics.

[0003] To address this problem, the industry and academia have proposed a series of improvement schemes, but there are still deficiencies. For example, the instruction fine-tuning method fine-tunes the model on large-scale high-quality mathematical problems and detailed solution data, enabling the model to master formula theorems and problem-solving steps, thereby significantly improving the accuracy of multi-step mathematical reasoning. However, this method relies on massive high-quality data, has high fine-tuning costs and time consumption, and the model is easily limited by the distribution of training data. Once the reasoning scenario changes, the model needs to be fine-tuned again.

[0004] Another method is tool enhancement, which dynamically calls external calculators or symbolic solvers (such as Mathematica, Sympy) during reasoning to ensure the accuracy of numerical calculations and symbolic derivations. Tool enhancement improves reasoning accuracy and the ability of models to handle complex calculations, but it highly depends on the stability of external tools, increasing the complexity of system deployment and maintenance.

[0005] Overall, the prior art mainly relies on prompting engineering, instruction fine-tuning or external tools, but lacks the introduction and utilization of structured knowledge in the field of mathematics. The model lacks explicit modeling and calling of the structural relationships of knowledge points, theorems, formulas, etc., resulting in a lack of logical support in the problem-solving process and easy misuse of concepts or step-by-step reasoning. In addition, the reasoning process lacks controllability, mostly using the "one-step generation to the end" method, lacking effective monitoring and intervention of intermediate steps, and the reasoning chain is prone to jump or break, lacking explainability. At the same time, the prior art lacks a mechanism to dynamically remove unreasonable content, and cannot timely adjust or remove illogical hallucination paths. These deficiencies result in frequent hallucination of large language models in complex mathematical problems, making it difficult to meet the actual demand for accuracy and reliability. Therefore, there is an urgent need for a new method to combine structured domain knowledge and dynamically control the reasoning process to fundamentally alleviate the hallucination problem of large language models in mathematical reasoning. SUMMARY

[0006] In view of the deficiencies of the prior art, the present application provides a large language model mathematical inference method based on knowledge graph and dynamic pruning optimization, which aims to solve the problems in the background art.

[0007] To achieve the above purpose, the present application provides the following technical scheme: a large language model mathematical inference method based on knowledge graph and dynamic pruning optimization, comprising the following steps:

[0008] Step S1: constructing a data set, the data set includes a plurality of primary and secondary school mathematical problems containing multiple knowledge points; assigning knowledge attribute labels representing complexity score parameters to the knowledge points corresponding to the primary and secondary school mathematical problems;

[0009] Step S2: given a mathematical problem to be solved, extracting the initial knowledge point entity set in the mathematical problem to be solved by a large language model, performing semantic expansion on the initial knowledge point entity set, and constructing a corresponding expanded triple set;

[0010] Step S3: constructing a structured knowledge graph based on the primary and secondary school mathematical problems, retrieving the structured knowledge graph using the expanded triples, obtaining related knowledge point subgraphs, and reading the complexity scores of the related knowledge points from the related knowledge point subgraphs as the comprehensive difficulty scores of the corresponding mathematical problem to be solved;

[0011] Step S4: when the comprehensive difficulty score ≤ preset threshold , directly calling a large language model to perform reasoning to generate a problem-solving process and an answer corresponding to the mathematical problem to be solved ;

[0012] Step S5: when the comprehensive difficulty score > preset threshold When, the corresponding mathematical problem to be solved, the relevant knowledge point subgraph and the corresponding complexity score parameter are input to the search tree starting point modeling module. In the search tree starting point modeling module, the most relevant knowledge point is selected as the starting point of the search tree by analyzing the semantic matching of the mathematical problem to be solved and the knowledge point, combining the complexity score parameter of the knowledge point, based on these information to build the initial search tree, and generate the front queue;

[0013] Step S6: input the initial search tree and the front queue to the path expansion and pruning module. In the path expansion and pruning module, the reasoning path is expanded based on the initial search tree and the front queue, and pruning is performed by calculating the path score, and the high score path is preferentially retained, and finally the path set to be evaluated and the priority queue are obtained;

[0014] Step S7: input the path set to be evaluated and the priority queue to the path scoring and optimization module. In the path scoring and optimization module, each path to be evaluated is scored using a reward model, the logical structure, semantic matching degree and target orientation of the path to be evaluated are comprehensively considered, the path with the highest score is selected through multi-dimensional evaluation, and the node state is updated based on the feedback mechanism to obtain the optimal path and the answer.

[0015] Further, the specific process of step S1 is:

[0016] Step S1.1: collect a plurality of primary and secondary school mathematics problems containing multiple levels of knowledge points;

[0017] Step S1.2: preprocessing the collected primary and secondary school mathematics problems, which includes cleaning and deduplicating the primary and secondary school mathematics problems and knowledge point annotation;

[0018] Step S1.3: assign knowledge attribute labels representing complexity scores to the knowledge points of the preprocessed primary and secondary school mathematics problems and construct a data set;

[0019] The specific process of step S1.3 is:

[0020] Step S1.31: collect a plurality of primary and secondary school mathematics problem answer data; construct a question-answerer response matrix based on the primary and secondary school mathematics problem answer data; each cell in the question-answerer response matrix represents whether the answer to the question by the answerer is correct;

[0021] Step S1.32: based on the question-answerer response matrix, using a two-parameter logistic model, estimating the discrimination parameter and difficulty parameter of each knowledge point corresponding to the primary and secondary school mathematics problem;

[0022] Step S1.33: Establish the mapping relationship between the primary and secondary school mathematics problems and knowledge points, and according to the discrimination parameter and difficulty parameter of the primary and secondary school mathematics problems, the related knowledge points are weighted and summarized to generate the complexity score of each knowledge point as the knowledge attribute label;

[0023] Step S1.34: Artificially check and correct the primary and secondary school mathematics problems corresponding to the knowledge points with knowledge attribute labels, and construct a data set.

[0024] Further, in step S2, the mathematics problem to be solved is represented as , wherein represents the token of the i-th word or word in the mathematics problem to be solved , and represents the number of words.

[0025] Further, the specific process of constructing a structured knowledge graph based on the primary and secondary school mathematics problems is as follows:

[0026] Step S3.11: Extract entities and semantic relationships in the primary and secondary school mathematics problems to form a preliminary triple set; the entities include head entities and tail entities;

[0027] Step S3.12: Import the preliminary triple set into a graph database to establish a structured knowledge graph; the structured knowledge graph adopts a directed graph structure based on triples and is represented as , wherein represents the head entity of the i-th preliminary triple , represents the semantic relationship of the i-th preliminary triple , and represents the tail entity of the i-th preliminary triple ; and represents the number of preliminary triples.

[0028] Further, the related knowledge point subgraph is represented as , wherein represents the node set in the related knowledge point subgraph , and represents the semantic edge set in the related knowledge point subgraph;

[0029] The specific process of reading the complexity score of the related knowledge point from the related knowledge point subgraph as the comprehensive difficulty score of the corresponding mathematics problem to be solved is as follows:

[0030] The set of knowledge points semantically related to the mathematics problem to be solved is identified from the related knowledge point subgraph by a large language model ​​​​,in, Represents a subgraph from related knowledge points Identify math problems to be solved Semantically related knowledge points; Represents a subgraph from related knowledge points Identify math problems to be solved Semantically related Knowledge points, ; Identified mathematical problems to be solved Semantically related knowledge points are related knowledge point subgraphs Nodes in

[0031] Calculate the math problems to be solved through a large language model With the Knowledge points The attention score between , to solve math problems Normalize the attention scores between all knowledge points to get the knowledge points Approaching math problems The importance of semantic relations ;

[0032] Based on semantic relationship importance , knowledge points Corresponding complexity scoring parameters To calculate the math problem to be solved Overall difficulty rating :

[0033] ;

[0034] in, Representing knowledge points The corresponding discrimination parameter; Representing knowledge points The corresponding difficulty parameter.

[0035] Furthermore, the specific process of step S5 is as follows:

[0036] Step S5.1: Based on the mathematical problem to be solved and related knowledge point subgraphs To construct a large language model input prompt string ;

[0037] Step S5.2: Input the large language model into the prompt string Input into the large language model and output a set of candidate knowledge points as the starting point of reasoning , Indicates the candidate knowledge points in natural language form;

[0038] Step S5.3: Collect candidate knowledge points The candidate knowledge points in natural language Match to relevant knowledge point subgraph The nodes in , get the mapping node set , Representing related knowledge point subgraphs Corresponding Mapping node;

[0039] Step S5.4: Calculate the mapping node and math problems to be solved Semantic relevance score :

[0040] ;

[0041] Where, Represents a mathematical problem to be solved Semantic feature vector of express The structure embedding vector of

[0042] Step S5.5: According to the mapping node Corresponding complexity scoring parameters To calculate the structural score of the mapping node ; Represents a mapping node The corresponding discrimination parameter, Represents a mapping node The corresponding difficulty parameter;

[0043] Step S5.6: Score based on semantic relevance and the structural score of the mapping node To calculate the comprehensive score of the mapping node :

[0044] ;

[0045] Where, 、 All represent adjustable hyperparameters. ;

[0046] Step S5.7: Comprehensive score of the mapping node As a basis, set the threshold , filter out the comprehensive score not lower than the threshold mapping nodes to build a search starting point candidate pool ;

[0047] Step S5.8: In the search starting point candidate pool , the mapping nodes are sorted according to the comprehensive scores , and the mapping node with the highest score is selected as the root node of the search tree ;

[0048] Step S5.9: Taking the root node of the search tree as the tree root, an initial search tree is constructed from the relevant knowledge subgraph by filtering nodes that satisfy the set semantic relationship ;

[0049] Step S5.10: All mapping nodes in the search starting point candidate pool are sorted in descending order according to the corresponding comprehensive scores to construct a frontier queue , represents the candidate nodes in the frontier queue; represents the depth of .

[0050] Further, the specific process of step S6 is as follows:

[0051] Step S6.1: Compare the depth of with the maximum depth threshold , and if , perform an expansion operation based on the semantic relationship in the initial search tree . The specific process of the expansion operation is as follows:

[0052] Define the legal adjacent point set of :

[0053] ;

[0054] wherein represents the candidate expansion node;

[0055] Add to the corresponding path of to form a set of paths to be evaluated ;

[0056] Step S6.2: Budget pruning strategy: dynamically control the expansion operation based on the comprehensive difficulty score ;

[0057] Let the total number of path nodes generated by the current search tree be , then the maximum number of nodes allowed to expand in this round is:

[0058] ;

[0059] where, is a scaling factor; is an expansion adjustment coefficient;

[0060] For all candidate expansion nodes , a semantic structure score is computed, with the score function defined as:

[0061] ;

[0062] where, is the structure embedding vector of the candidate expansion node ; is the structure score parameter of the candidate expansion node ;

[0063] The top candidate expansion nodes with the highest scores are reserved, forming a preliminary pruning set ;

[0064] Step S6.3: Logical consistency pruning strategy: define a consistency judgment function :

[0065] ;

[0066] where, is the semantic relation type between and ; is the set of allowed semantic relations; is the attribute condition of ;

[0067] According to the consistency judgment function , the preliminary pruning set is filtered to obtain an effective candidate set ;

[0068] For each , update its cumulative access count:

[0069] ;

[0070] where, is the cumulative access count of in the search process;

[0071] Step S6.4: updating the front queue to get a priority queue :

[0072] ;

[0073] wherein, represents the comprehensive score of ; represents the depth of .

[0074] Further, the specific process of step S7 is as follows:

[0075] Step S7.1: setting the set of to-be-evaluated paths as , represents the i-th to-be-evaluated path in the set of to-be-evaluated paths; represents the number of to-be-evaluated paths in the set of to-be-evaluated paths; based on the priority queue , the access state of the node in the to-be-evaluated path is recorded; Step S7.2: introducing a multi-dimensional reward model

[0076] , training the multi-dimensional reward model , inputting into the trained multi-dimensional reward model to get a three-dimensional score vector, denoted as:

[0077] ; wherein,

[0078] represents the logical consistency score of ; represents the semantic matching degree score of ; represents the target fitting degree score of ; Step S7.3: weighting and fusing the obtained three-dimensional score vector to get the reward score

[0079] of , denoted as:

[0080] ; wherein,

[0081] are all adjustable parameters, ;

[0082] Step S7.4: selecting the optimal path from the set of to-be-evaluated paths according to the reward score .​

[0083] ;

[0084] Step S7.5: The optimal path is spliced in the order of the nodes in the path to construct a mathematical problem to be solved The complete structured problem solving process is summarized to obtain the answer A.

[0085] Further, the multi-dimensional reward model is trained The specific process for training the multi-dimensional reward model is as follows: according to the standard answer database PIB, the labels are marked , combined with and the corresponding to form a labeled path sample pair , the multi-dimensional reward model is trained based on , and the training process aims to minimize the mean square error loss function. Further, a back propagation mechanism is designed to feed back the reward score of the optimal path to the intermediate nodes thereof; for the intermediate nodes of the optimal path

[0086] , the access frequency and the cumulative reward score are updated, and the average historical score is calculated. Compared with the existing technology, the present application has the following beneficial effects: (1) The present application constructs a structured knowledge graph for mathematical reasoning tasks, integrates mathematical concepts, theorems, formulas and semantic edge relationships, and introduces a discrimination-difficulty parameter mechanism to improve the discriminability and organization of knowledge points in structural reasoning, providing a controllable and searchable reasoning support environment for large language models, and significantly enhancing the mathematical understanding and deduction ability of the model.

[0087] (2) The present application combines the comprehensive difficulty of the question and the pre-defined semantic relationship to realize precise control and complexity compression during path expansion; the present application proposes a starting point modeling mechanism that integrates semantic relevance and difficulty score to accurately select high-quality starting nodes, effectively guide the construction direction of the reasoning tree, reduce the risk of path divergence, and improve the stability and effectiveness of reasoning.

[0088] (3) The present application designs a back propagation mechanism to feed back the reward score of the optimal path to the intermediate nodes thereof; for the intermediate nodes of the optimal path, the access frequency and the cumulative reward score are updated, and the average historical score is calculated.

[0089] (4) The present application combines the comprehensive difficulty of the question and the pre-defined semantic relationship to realize precise control and complexity compression during path expansion; the present application proposes a starting point modeling mechanism that integrates semantic relevance and difficulty score to accurately select high-quality starting nodes, effectively guide the construction direction of the reasoning tree, reduce the risk of path divergence, and improve the stability and effectiveness of reasoning. BRIEF DESCRIPTION OF DRAWINGS

[0090] Figure 1 The step flowchart of the present application. DETAILED DESCRIPTION​​​

[0091] As Figure 1 shown, the present application provides a technical solution: a large language model mathematical inference method based on knowledge graph and dynamic pruning optimization, comprising the following steps:

[0092] Step S1: Construct a data set, which includes a number of primary and secondary school mathematics problems containing multi-level knowledge points; the knowledge attribute tags representing the complexity score parameters are assigned to the knowledge points corresponding to the primary and secondary school mathematics problems.

[0093] Since the existing public data sets are mainly composed of questions, answer steps and answers, they generally lack structured association information between questions and knowledge points, especially lack of annotation of knowledge point hierarchical classification, theorem attribution and difficulty estimation, which is difficult to meet the needs of knowledge graph construction and reasoning path control in the present application; the present application constructs a mathematical knowledge point relationship and reasoning task data set for primary and junior high school stages, the specific process is:

[0094] Step S1.1: About 24000 primary and secondary school mathematics problems containing multi-level knowledge points (12 first-level knowledge points, 75 second-level knowledge points, 395 third-level knowledge points) are collected from multiple public mathematical test paper resources and online learning platforms, covering arithmetic, algebra, geometry, application problems and other types; the definition of knowledge points is:

[0095] First-level knowledge points: broad areas of mathematics, usually divided by grade; second-level knowledge points: refinement of first-level knowledge points, usually corresponding to specific chapters, involving specific mathematical concepts and skills; third-level knowledge points: the most refined classification, focusing on specific formulas, theorems, etc., usually corresponding to the content of sections in chapters.

[0096] Step S1.2: Preprocess the collected primary and secondary school mathematics problems, which includes cleaning and deduplicating the primary and secondary school mathematics problems and knowledge point annotation; specifically:

[0097] Step S1.21: Clean and deduplicate the primary and secondary school mathematics problems, and eliminate redundant, ambiguous and inconsistent with curriculum standards.

[0098] Step S1.22: According to the mathematical knowledge point classification dictionary compiled by People's Education Press, automatically identify and preliminarily label the knowledge points in the primary and secondary school mathematics problems, the labeling system covers multi-level knowledge points, and preferentially refines to the third-level knowledge point level to improve the semantic granularity and reasoning accuracy of the graph construction.

[0099] Step S1.23: In order to ensure the quality of labeling, a label consistency evaluation mechanism is introduced to match the similarity of the labeled knowledge points, and the result with the highest consistency is selected as the final labeling.

[0100] Step S1.3: Assign knowledge attribute labels representing complexity score parameters to the knowledge points of the preprocessed primary and secondary school math problems and construct a dataset; in detail:

[0101] Step S1.31: Collect a large amount of primary and secondary school math problem answer data (real student answer records and artificial intelligence agent (AI Agent) simulation answer results of different ability levels); based on the primary and secondary school math problem answer data, construct a question-answerer response matrix; each cell in the question-answerer response matrix represents whether the answerer's answer to the question is correct.

[0102] Step S1.32: Based on the question-answerer response matrix, use the two-parameter logistic model (2PL) in the item response theory (IRT) to estimate the discrimination parameter and difficulty parameter of each knowledge point corresponding to the primary and secondary school math problem.

[0103] Step S1.33: Establish a one-to-one or many-to-many mapping relationship between primary and secondary school math problems and knowledge points, and weight the associated knowledge points according to the discrimination parameter and difficulty parameter of the primary and secondary school math problems to generate the complexity score parameter of each knowledge point as a knowledge attribute label for subsequent reasoning path scheduling and pruning control mechanisms.

[0104] Step S1.34: Manually check and correct the primary and secondary school math problems corresponding to the knowledge points assigned with the knowledge attribute labels, and retain 8962 primary and secondary school math problems to construct a dataset based on the retained primary and secondary school math problems.

[0105] Step S2: Given a math problem to be solved , extract the initial knowledge point entity set in the math problem to be solved through a large language model (LLM), perform semantic expansion on the initial knowledge point entity set , and construct a corresponding expanded triple set .

[0106] Wherein, the math problem to be solved is represented as , represents the token of the th word or word in the math problem to be solved, represents the number of words.

[0107] Step S3: Construct a structured knowledge graph based on the primary and secondary school math problems, and use the expanded triples Retrieve the structured knowledge graph, obtain the relevant knowledge point subgraph, and read the complexity scoring parameters of the relevant knowledge points from the relevant knowledge point subgraph as the corresponding mathematical problems to be solved The overall difficulty rating.

[0108] Among them, the relevant knowledge point subgraph is represented as , Represents a variety of node sets in the related knowledge point subgraph, Represents the set of semantic edges in the related knowledge point subgraph.

[0109] The specific process of constructing a structured knowledge graph based on primary and secondary school mathematics questions is as follows:

[0110] Step S3.11: Use entity dictionaries, rule templates, and dependency parsing methods to extract entities (including head entities and tail entities) and semantic relationships in primary and secondary school mathematics problems to form a preliminary set of triples.

[0111] Among them, entity types include knowledge points (Knowledge), theorems (Theorem), common formulas (Formula), variable constraints (Constraint), etc.; semantic relationship types include prerequisite relationships (Precedes), inclusion relationships (Contains), applicable conditions (ApplicableTo), reference relationships (References), etc.; each entity node also contains structural attributes, such as the textbook version, grade level, knowledge point level label, etc.

[0112] Among them, a manual review mechanism is introduced to proofread and resolve conflicts in the extracted entities and semantic relationships to ensure accuracy and consistency.

[0113] Step S3.12: Import the preliminary triple set into a graph database (such as Neo4j) to build a structured knowledge graph; the structured knowledge graph uses a directed graph structure based on triples and can be represented as , Indicates the The head entity of the preliminary triple, Indicates the The semantic relationship of the initial triples, express The tail entity of the preliminary triple; Indicates the number of preliminary triples.

[0114] Among them, in order to further enhance the representation ability of knowledge points in the atlas, the relevant knowledge point subgraphs can be Input graph convolutional neural network (GCN) to perform structure-aware embedding update on its nodes to obtain node embedding representation Specific:

[0115] Set up relevant knowledge point subgraph Contains nodes, each node is initially represented as a The nodes of the relevant knowledge point subgraph are updated through the graph convolutional neural network (GCN), and the node embedding representation is finally obtained. .

[0116] Among them, from the relevant knowledge point subgraph Read the complexity scoring parameters of relevant knowledge points as the corresponding mathematical problems to be solved The specific process of comprehensive difficulty scoring is as follows:

[0117] 1. Use the large language model to extract relevant knowledge points from the subgraph Identify math problems to be solved A collection of semantically related knowledge points ,in, Represents a subgraph from related knowledge points Identify math problems to be solved Semantically related knowledge points; Represents a subgraph from related knowledge points Identify math problems to be solved Semantically related Knowledge points, ; Identified mathematical problems to be solved Semantically related knowledge points are related knowledge point subgraphs Nodes in .

[0118] 2. Calculate the math problems to be solved through a large language model With the Knowledge points The attention score between , solve math problems through the softmax function Normalize the attention scores between all knowledge points to get the knowledge points Approaching math problems The importance of semantic relations .

[0119] 3. Based on the importance of semantic relationships , knowledge points Corresponding complexity scoring parameters To calculate the math problem to be solved Overall difficulty rating :

[0120] .

[0121] wherein, represents a knowledge point corresponding discriminativeness parameter; represents a knowledge point corresponding difficulty parameter.

[0122] Step S4: when the comprehensive difficulty score ≤ preset threshold , directly call the large language model to perform reasoning to generate the solution process and answer of the corresponding to-be-solved mathematical question .

[0123] Step S5: when the comprehensive difficulty score > preset threshold , input the corresponding to-be-solved mathematical question , related knowledge point subgraph and corresponding complexity score parameter into the search tree starting point modeling module, select the most relevant knowledge point as the starting point of the search tree by analyzing the semantic matching between the to-be-solved mathematical question and the knowledge point in the search tree starting point modeling module, combining the complexity score parameter of the knowledge point, constructing an initial search tree based on these information, and generating a front queue.

[0124] Step S5.1: based on the to-be-solved mathematical question and the related knowledge point subgraph to construct a large language model input prompt string , so as to determine the optimal starting point of the search tree.

[0125] Step S5.2: input the large language model input prompt string into the large language model, output a set of candidate knowledge points that may be used as the starting point of reasoning , represents the th natural language form of the candidate knowledge point.

[0126] Step S5.3: match the th natural language form of the candidate knowledge point in the candidate knowledge point set to the node in the related knowledge point subgraph , obtain a set of successfully matched mapping nodes , represents the th mapping node in the related knowledge point subgraph .

[0127] Step S5.4: calculate the mapping node and math problems to be solved Semantic relevance score :

[0128] ;

[0129] Where, Represents a mathematical problem to be solved Semantic feature vector of express The structure embedding vector of .

[0130] get The process is: put the first word or phrase tokens Input a large language model and output a set of semantic feature vectors , Represents the first The dimensions are Context-aware vector of .

[0131] Step S5.5: According to the mapping node Corresponding complexity scoring parameters To calculate the structural score of the mapping node ; Represents a mapping node The corresponding discrimination parameter, Represents a mapping node The corresponding difficulty parameter.

[0132] Step S5.6: Score based on semantic relevance and the structural score of the mapping node To calculate the comprehensive score of the mapping node :

[0133] ;

[0134] Where, 、 All represent adjustable hyperparameters. .

[0135] Step S5.7: Comprehensive score of the mapping node As a basis, set the threshold , filter out the comprehensive score not lower than the threshold Mapping nodes to build a search starting point candidate pool :

[0136] .

[0137] Step S5.8: In the search starting point candidate pool , the nodes are sorted according to the comprehensive scores of the nodes , and the mapping node with the highest score is selected as the root node of the search tree .

[0138] .

[0139] Step S5.9: Taking the root node of the search tree as the tree root, the semantic relationships satisfying the "Precedes" and "ApplicableTo" in the relevant knowledge point subgraph are screened to construct an initial search tree .

[0140] Step S5.10: All mapping nodes in the search starting point candidate pool are arranged in descending order according to the corresponding comprehensive scores to construct a frontier queue , wherein the candidate nodes in the frontier queue are denoted as , and the depth of is denoted as .

[0141] Step S6: The initial search tree and the frontier queue are input into a path expansion and pruning module, in which the reasoning path is expanded based on the initial search tree and the frontier queue, and pruning is performed by calculating the path score, high-score paths are preferentially retained, and finally a set of to-be-evaluated paths and a priority queue are obtained.

[0142] Step S6.1: The depth of is compared with the maximum depth threshold , and if , an expansion operation is performed based on the semantic relationships in the initial search tree to prevent the reasoning process from falling into a redundant or non-convergent search space; the specific process of the expansion operation is as follows:

[0143] The legal adjacent point set of is defined as:

[0144] ;

[0145] wherein denotes a candidate expansion node, which must have a legal connection relationship with in the knowledge graph and the current search tree to ensure that the expanded path is still attached to the initial search tree​ effective structure.

[0146] Will Append to Corresponding path On the basis of the above, a set of paths to be evaluated is formed. :

[0147] ;

[0148] Where, Represents a path concatenation operation.

[0149] Step S6.2: Budget pruning strategy: based on comprehensive difficulty score ,dynamically control the expansion operation;

[0150] Let the total number of path nodes generated by the current search tree be , then the maximum number of nodes allowed to be expanded in this round is for:

[0151] ;

[0152] Where, represents the empirically set scaling factor; Indicates the expansion adjustment coefficient.

[0153] For all candidate expansion nodes Perform semantic structure scoring, scoring function Defined as:

[0154] ;

[0155] Where, Represents a candidate expansion node The structure embedding vector of Represents a candidate expansion node Structural scoring parameters.

[0156] Keep the highest rated candidate expansion nodes, forming a preliminary pruning set :

[0157] ;

[0158] Where, Express According to the scoring function Sort in descending order, select the top Candidate expansion node operation.

[0159] Step S6.3: Logical consistency pruning strategy: define consistency judgment function :

[0160] ;

[0161] wherein, represents semantic relation type of ; represents allowed semantic relation set; represents attribute condition.

[0162] According to the consistency judgment function , the preliminary pruning set is screened to obtain an effective candidate set :

[0163] .

[0164] To support path evaluation and reverse optimization mechanism, a node access times recording mechanism is introduced; for each , its cumulative access times is updated:

[0165] ;

[0166] wherein, represents cumulative access times in the search process.

[0167] Step S6.4: the frontier queue is updated to obtain a priority queue :

[0168] ;

[0169] wherein, represents comprehensive score of ; represents depth of

[0170] Step S7: the set of paths to be evaluated and the priority queue are input into the path scoring and optimization module, in which a reward model is used to score each path to be evaluated, considering the logical structure, semantic matching degree and target orientation of the path to be evaluated, through multi-dimensional evaluation, the highest scored path is selected, and the node state is updated based on the feedback mechanism to obtain the optimal path and the answer.

[0171] Step S7.1: set the set of paths to be evaluated as , represents the i-th path to be evaluated in the set of paths to be evaluated The nodes in the path to be evaluated represent the key information in the process of solving the math problem to be solved. Represents the multi-step problem-solving process of the mathematical problem to be solved; Indicates the number of paths to be evaluated in the set of paths to be evaluated; based on the priority queue , records the access status of nodes in the path to be evaluated, which is used to support the subsequent feedback update process.

[0172] Step S7.2: Introducing a learnable multi-dimensional reward model , for multi-dimensional reward models Conduct training, Input to the trained multi-dimensional reward model In the equation, we get a three-dimensional rating vector, which is expressed as:

[0173] ;

[0174] Where, express Logical consistency score, used to measure Whether it complies with the graph reasoning rules; express The semantic matching score of semantic rationality; express The target fit score is used to measure Whether it is close to the reasoning target.

[0175] Step S7.3: Perform weighted fusion on the obtained three-dimensional score vector to obtain Bonus score , expressed as:

[0176] ;

[0177] Where, are all adjustable parameters used to reflect the importance of the three-dimensional rating vector in the reward score. .

[0178] Among them, for the multi-dimensional reward model The specific process of training is:

[0179] According to the standard answer database PIB (including question answers and standard solution paths) Annotation Label , combined and the corresponding Form labeled path sample pairs ,based on Multi-dimensional reward model Training is performed, and during the training process, a mean square error loss function is minimized.

[0180] ;

[0181] wherein, represents a mean square error loss function; represents a parameter of a multi-dimensional reward model.

[0182] Step S7.4: According to the reward score , select the optimal path in the path set to be evaluated :

[0183] ;

[0184] wherein, in order to guide the search tree to converge in the direction of a better path, a back propagation mechanism is designed to feed back the reward score of the optimal path to the intermediate nodes thereof; for the intermediate nodes of the optimal path , the visit times and the cumulative reward score are updated, and the average historical score is calculated, which is represented as:

[0185] .

[0186] Step S7.5: The nodes in the optimal path are spliced in the order of the path to construct a complete structured problem-solving process, and the final answer A is obtained by summarizing.

[0187] Although embodiments of the present application have been shown and described, it is to be understood that various modifications, substitutions, replacements and changes can be made to these embodiments without departing from the principles and spirit of the present application, and the scope of the present application is defined by the appended claims and their equivalents.

Claims

1. A large language model mathematical inference method based on a knowledge graph and dynamic pruning optimization, characterized in that, Comprising the following steps: Step S1: constructing a data set, the data set includes a plurality of primary and secondary school mathematics problems containing multi-level knowledge points; the knowledge points corresponding to the primary and secondary school mathematics problems are assigned knowledge attribute labels representing complexity score parameters; Step S2: given a mathematical problem to be solved, the initial knowledge point entity set in the mathematical problem to be solved is extracted by a large language model, the initial knowledge point entity set is semantically expanded, and a corresponding expanded triple set is constructed; Step S3: constructing a structured knowledge graph based on the primary and secondary school mathematics problems, retrieving the structured knowledge graph using the expanded triples, obtaining related knowledge point subgraphs, and reading the complexity scores of the related knowledge points from the related knowledge point subgraphs as the comprehensive difficulty scores of the corresponding mathematical problems to be solved; Step S4: when the comprehensive difficulty score ≤ preset threshold , directly calling a large language model to perform inference to generate a solution process and an answer of the corresponding to-be-solved mathematical question ; Step S5: when the comprehensive difficulty score > preset threshold is greater than or equal to the preset threshold, the corresponding mathematical problem to be solved, the relevant knowledge point subgraph, and the corresponding complexity score parameter are input into a search tree starting point modeling module. In the search tree starting point modeling module, the most relevant knowledge point is selected as the starting point of the search tree by analyzing the semantic matching of the mathematical problem to be solved and the knowledge points, combining the complexity score parameters of the knowledge points, constructing an initial search tree based on these information, and generating a front queue. Step S6: inputting the initial search tree and the frontier queue into the path expansion and pruning module, expanding the reasoning path based on the initial search tree and the frontier queue in the path expansion and pruning module, and pruning by calculating the path score, preferentially retaining high-score paths, and finally obtaining a set of to-be-evaluated paths and a priority queue; Step S7: inputting the set of to-be-evaluated paths and the priority queue into the path scoring and optimization module, scoring each to-be-evaluated path using a reward model in the path scoring and optimization module, comprehensively considering the logical structure, semantic matching degree and target orientation of the to-be-evaluated path, selecting the path with the highest score through multi-dimensional evaluation, and updating the node state based on the feedback mechanism to obtain the optimal path and the answer.

2. The knowledge graph and dynamic pruning optimization-based large language model mathematical inference method according to claim 1, characterized in that: The specific process of step S1 is: Step S1.1: collecting a plurality of primary and secondary school mathematics problems containing multi-level knowledge points; Step S1.2: preprocessing the collected primary and secondary school mathematics problems, which includes cleaning and deduplicating the primary and secondary school mathematics problems and knowledge point annotation; Step S1.3: assigning knowledge attribute labels representing complexity scores to the knowledge points of the preprocessed primary and secondary school mathematics problems and constructing a data set; The specific process of step S1.3 is: Step S1.31: collecting a plurality of primary and secondary school mathematics problem answer data; constructing a question-answerer response matrix based on the primary and secondary school mathematics problem answer data; each cell in the question-answerer response matrix represents whether the answer to the question is correct; Step S1.32: Based on the item-examinee response matrix, estimate the discrimination parameter and difficulty parameter of each primary and secondary school mathematics item corresponding to each knowledge point using the two-parameter logistic model and difficulty parameter ; Step S1.33: Establish the mapping relationship between the primary and secondary school mathematics questions and knowledge points, and according to the discrimination parameter and difficulty parameter of the primary and secondary school mathematics questions, the related knowledge points are weighted and summarized to generate the complexity score of each knowledge point as the knowledge attribute label; Step S1.34: manually checking and correcting the primary and secondary school mathematics problems corresponding to the knowledge points assigned with the knowledge attribute labels, and constructing a data set.

3. The knowledge graph and dynamic pruning optimization-based large language model mathematical inference method according to claim 2, characterized in that: In step S2, the mathematical problem to be solved is represented as , represents a token of the th word or term in the mathematical problem to be solved, represents the number of words or terms.

4. The knowledge graph and dynamic pruning optimization-based large language model mathematical inference method according to claim 3, characterized in that: The specific process of constructing a structured knowledge graph based on primary and secondary school mathematics problems is: Step S3.11: extracting entities and semantic relationships in the primary and secondary school mathematics problems to form a preliminary triple set; the entities include head entities and tail entities; Step S3.12: importing the preliminary triple set into a graph database to establish a structured knowledge graph; The structured knowledge graph adopts a directed graph structure based on triplets, and is represented as , represents the head entity of the i-th preliminary triplet, represents the semantic relationship of the i-th preliminary triplet, represents the tail entity of the i-th preliminary triplet; represents the number of preliminary triplets.​​​ 5. The knowledge graph and dynamic pruning optimization-based large language model mathematical inference method according to claim 4, characterized in that: The related knowledge point subgraph is represented as , represents a node set in the related knowledge point subgraph, represents a semantic edge set in the related knowledge point subgraph; The complexity score of the relevant knowledge points is read from the subgraph of relevant knowledge points as the specific process of the comprehensive difficulty score of the corresponding to-be-solved mathematical question . From the relevant knowledge point subgraph through the large language model Identify math problems to be solved A collection of semantically related knowledge points ,in, Represents a subgraph from related knowledge points Identify math problems to be solved Semantically related knowledge points; Represents a subgraph from related knowledge points Identify math problems to be solved Semantically related Knowledge points, ; Identified mathematical problems to be solved Semantically related knowledge points are related knowledge point subgraphs Nodes in Calculating a to-be-solved mathematical question by a large language model and the attention score between the first knowledge point and the to-be-solved mathematical question , normalizing the attention scores between the to-be-solved mathematical question and all knowledge points, obtaining the semantic relationship importance of the to-be-solved mathematical question to the knowledge points ; Based on semantic relation importance , knowledge points Corresponding complexity score parameters To calculate the comprehensive difficulty score of a mathematical problem to be solved :​ ; wherein, represents a knowledge point a corresponding discrimination parameter; represents a knowledge point a corresponding difficulty parameter.

6. The knowledge graph and dynamic pruning optimization-based large language model mathematical inference method according to claim 5, characterized in that: The specific process of step S5 is: Step S5.1: constructing a large language model input prompt string based on the mathematical problem to be solved and related knowledge points subgraph to construct a large language model input prompt string ; Step S5.2: input the large language model into the prompt string , , represent the first natural language form of candidate knowledge points; Step S5.3: Collect candidate knowledge points The candidate knowledge points in natural language Match to relevant knowledge point subgraph The nodes in , get the mapping node set , Representing related knowledge point subgraphs Corresponding Mapping node; Step S5.4: Calculate mapping node with the semantic relevance score of the mathematical problem to be solved :​ ; wherein represents a semantic feature vector of a mathematical problem to be solved; represents a structural embedding vector of a mathematical problem to be solved; represents a structural embedding vector of a mathematical problem to be solved;​ Step S5.5: Calculate the structure score of the mapping node according to the mapping node the corresponding complexity score parameter to calculate the structure score of the mapping node ; denotes the mapping node the corresponding distinctness parameter, denotes the mapping node the corresponding difficulty parameter; Step S5.6: Calculate the semantic relevance score based on the structure score of the mapping node and the structure score of the mapping node to calculate the overall score of the mapping node : ; wherein , both represent adjustable hyperparameters, ; Step S5.7: mapping nodes are ranked according to their comprehensive scores Based on the ranking, a threshold is set Mapping nodes with a comprehensive score not lower than the threshold are selected to form a candidate pool of search starting points ;​ Step S5.8: In the search starting point candidate pool , according to the comprehensive score of the node , the mapping node with the highest score is selected as the root node of the search tree ; Step S5.9: taking the root node of the search tree For tree root, filter the subgraph of related knowledge points to construct an initial search tree that meets the set semantic relationship ;​ Step S5.10: Sort all the mapping nodes in the search starting point candidate pool according to the corresponding comprehensive scores in descending order to construct a front queue represents the candidate nodes in the front queue. represents the depth of .​​​ 7. The knowledge graph and dynamic pruning optimization-based large language model mathematical inference method according to claim 6, characterized in that: The specific process of step S6 is: Step S6.1: comparing the depth of the initial search tree with a maximum depth threshold value then an expansion operation is performed based on the semantic relations in the initial search tree; the specific process of the expansion operation is as follows:​​​​ Definitions set of legal abutment points : ; In the formula, represents a candidate extension node; will be added to the set of paths to be evaluated additional paths are added to the set of paths to be evaluated corresponding paths above, a set of paths to be evaluated is formed ; Step S6.2: Budget Pruning Strategy: Based on the Integrated Difficulty Score Dynamic control of the expansion operation; Let the total number of path nodes generated by the current search tree be Then the maximum number of nodes allowed to expand in this round is ​ ; wherein denotes a scaling factor; denotes an extension adjustment coefficient; For all candidate expansion nodes perform semantic structure scoring, scoring function defined as: ; wherein represents a structural embedding vector of the candidate extension node ; represents a structural score parameter of the candidate extension node ; retain the top scoring candidate expansion nodes, constituting a preliminary pruned set ​ Step S6.3: Logic consistency pruning strategy: define consistency judgment function : ; In the formula, represents to semantic relationship types; represents the allowed semantic relationship set; represents attribute conditions; According to a consistency judging function To a preliminary pruning set Screening to obtain an effective candidate set ; For each , update its cumulative access count: ; In the formula, denotes cumulative access count during the search process; Step S6.4: Update the frontiers queue with the updated priority queue : ; In the formula, represents the comprehensive score of represents the depth of .​ 8. The knowledge graph and dynamic pruning optimization-based large language model mathematical inference method according to claim 7, characterized in that: The specific process of step S7 is: Step S7.1: Set the set of paths to be evaluated as , represents the i-th path to be evaluated in the set of paths to be evaluated; represents the number of paths to be evaluated in the set of paths to be evaluated; based on the priority queue , record the access state of the nodes in the path to be evaluated;​ Step S7.2: Introducing a multi-dimensional reward model , the multi-dimensional reward model is trained , the multi-dimensional reward model is trained , the multi-dimensional reward model is trained , the multi-dimensional reward model is trained ; In the formula, represents a logical consistency score of represents a semantic matching degree score of represents a target fitting degree score of ​​​ Step S7.3: The obtained three-dimensional score vectors are fused by weighting, obtaining a reward score , expressed as: ; wherein are adjustable parameters, ; Step S7.4: Selecting the optimal path from the set of paths to be evaluated based on the reward score :​​ ; Step S7.5: The optimal path is spliced by each node in the path order to construct a mathematical problem to be solved Step S7.5: The optimal path is spliced by each node in the path order to construct a mathematical problem to be solved The complete structured problem-solving process is summarized to obtain the answer A.

9. The knowledge graph and dynamic pruning optimization-based large language model mathematical inference method according to claim 8, characterized in that: Multi-dimensional reward model The specific process of training is: according to the standard answer database PIB Annotate the label , combine And the corresponding Form a labeled path sample pair , train the multi-dimensional reward model based on , and the training process aims to minimize the mean square error loss function.

10. The knowledge graph and dynamic pruning optimization-based large language model mathematical inference method according to claim 9, characterized in that: Design a back-propagation mechanism to convert the optimal path Bonus score Feedback to its own intermediate node; for the optimal path The intermediate node , update its visit count and accumulated reward points , and calculate its average historical score .

Citation Information

Patent Citations

  • Knowledge graph question and answer retrieval method based on large language model and MCTS algorithm

    CN118296114A

  • Chemical reaction path reasoning method and device, related equipment and program product

    CN120340650A