A model-based question answering method, electronic device and medium
By generating new sample mathematical problem texts and response information, expanding the dataset, and training the model, the problems of insufficient dataset size and diversity were solved, and the mathematical computation ability and response accuracy of the model were improved.
Patent Information
- Application Number
- CN202411996850.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2026-01-27
- Estimated Expiration
- 2044-12-30
AI Technical Summary
The insufficient size and diversity of datasets in existing technologies result in low mathematical computational power of models, reducing their ability to answer users' mathematical reasoning questions.
By generating new sample mathematical problem texts, expanding the dataset using preset generation rules such as number substitution rules and operator addition rules, and training the model, new sample response information is generated to improve the model's mathematical calculation ability.
Expanding the dataset enhances the model's mathematical computation capabilities, improves the accuracy of predicting responses to mathematical questions, and strengthens the model's generalization ability.
Smart Images

Figure CN119721256B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of model reasoning technology, and in particular to a model-based question-answering method, electronic device, and medium. Background Technology
[0002] With the continuous advancement of artificial intelligence technology, mathematical reasoning question-answering systems have become an important part of the field of human-computer interaction. These systems aim to simulate human mathematical thinking processes, using language processing and deep learning technologies to understand and solve mathematical problems.
[0003] The size and diversity of datasets are key factors determining model performance. How to increase the size and diversity of datasets to enhance the mathematical computational power of models, thereby improving their ability to answer users' mathematical reasoning questions, is a technical problem that urgently needs to be solved by researchers in this field. Summary of the Invention
[0004] The purpose of this invention is to provide a model-based question-answering method, electronic device, and medium to address the technical problem that the small size and diversity of datasets lead to low mathematical computational power of the model, thereby reducing the model's ability to answer users' mathematical reasoning questions.
[0005] To address the aforementioned technical problems, this invention provides a model-based question-answering method, comprising:
[0006] Obtain the initial sample math problem text set and the initial sample response information corresponding to each initial sample math problem text;
[0007] Generate new sample mathematical problem texts based on the information from each initial sample mathematical problem text;
[0008] Obtain new sample response information corresponding to new sample mathematical problem text;
[0009] The model is trained using the initial sample set of mathematical problem texts, the initial sample response information, the new sample mathematical problem texts, and the new sample response information to obtain a model for answering mathematical problem texts.
[0010] The text of the mathematical question to be answered is input into the model for answering mathematical question text, and the model for answering mathematical question text outputs the answer information corresponding to the text of the mathematical question to be answered.
[0011] On the one hand, generating new sample mathematical problem texts based on the information of each initial sample mathematical problem text includes:
[0012] Obtain preset generation rules; wherein, the preset generation rules include at least one of number replacement rules and operator addition rules;
[0013] The information of each initial sample mathematical problem text is used to generate the new sample mathematical problem text according to the preset generation rules.
[0014] On the other hand, the preset generation rule is a number substitution rule. Before generating the new sample mathematical problem text from the information of each initial sample mathematical problem text according to the preset generation rule, it also includes:
[0015] Record the position of the extracted numerical information in the corresponding initial sample mathematical problem text, as well as the number of extracted numerical information;
[0016] The process of generating the new sample mathematical problem text according to the preset generation rule from the information of each initial sample mathematical problem text includes:
[0017] Generate a random number and use the random number to replace the extracted current numerical information;
[0018] Obtain the current position of the current numerical information in the initial sample mathematical problem text;
[0019] The new sample mathematical problem text is formed by concatenating the text before the current position in the initial sample mathematical problem text, the random number, and the text after the current position in the initial sample mathematical problem text.
[0020] On the other hand, the preset generation rule is an operator addition rule, and the process of generating the new sample mathematical problem text according to the preset generation rule for each initial sample mathematical problem text includes:
[0021] Construct a predefined list of operators;
[0022] According to the preset symbol addition rules, each operator in the operator symbol list is matched with a value extracted from the initial sample mathematical problem text, and the matching result is obtained.
[0023] If the matching result is that the operator matches the value, then the operator that matches the value is determined to be the operator to be added;
[0024] Randomly select a value to be added from the matched values, and add the operator to the value to be added according to the value addition rules corresponding to the symbol.
[0025] Obtain the current position of the value to be added in the initial sample mathematical problem text;
[0026] The new sample math problem text is formed by concatenating the text before the current position in the initial sample math problem text, the numerical value with added operators, and the text after the current position in the initial sample math problem text.
[0027] The step of matching numerical values extracted from the initial sample mathematical problem text for each operator in the operator list according to preset symbol addition rules, and obtaining the matching results, includes:
[0028] Obtain the calculation results obtained by matching the current operator with each numerical value extracted from the initial sample mathematical problem text;
[0029] If all the operation results are detected to be greater than the first preset value, then the matching result is determined to be that the current operator did not match a value;
[0030] If an operation result less than or equal to the first preset value is detected, the matching result is determined to be the numerical value matched by the current operator.
[0031] On the other hand, before adding the value to be added to the operator according to the numerical addition rule corresponding to the symbol, the method further includes:
[0032] Generate a random number and determine whether the generated random number is less than or equal to a second preset value;
[0033] If so, proceed to the step of adding the operator to be added to the value to be added according to the numerical addition rule corresponding to the symbol;
[0034] If not, return to the step of randomly selecting a value to be added from the matched values.
[0035] On the other hand, the process of generating the new sample mathematical problem text from the information of each initial sample mathematical problem text according to the preset generation rules includes at least one of the following methods:
[0036] Method 1:
[0037] Obtain the value of the precision to be adjusted from the initial sample mathematical problem text;
[0038] Obtain the operator applied to the value whose precision needs to be adjusted;
[0039] Determine whether to adjust the precision of the value to be adjusted based on the numerical operation rules of the operator;
[0040] If so, then the precision of the value to be adjusted is adjusted, and the value after precision adjustment is obtained; the current position of the value to be adjusted in the initial sample mathematical problem text is obtained; the text before the current position in the initial sample mathematical problem text, the value after precision adjustment, and the text after the current position in the initial sample mathematical problem text are concatenated to form the new sample mathematical problem text;
[0041] If not, then keep the value of the precision to be adjusted unchanged;
[0042] Method 2:
[0043] Obtain each operator from the initial sample mathematical problem text;
[0044] Replace each operator in the initial sample mathematical problem text;
[0045] The initial sample mathematical problem text after replacing the operator symbols is used as the new sample mathematical problem text;
[0046] Method 3:
[0047] Obtain the location of the format to be adjusted from the initial sample mathematical problem text;
[0048] Determine whether to perform format adjustment at the location where the format to be adjusted is based on the representation of the operator;
[0049] If so, the format is adjusted at the position where the format needs to be adjusted, and the adjusted initial sample mathematical problem text is used as the new sample mathematical problem text.
[0050] If not, then cancel the format adjustment operation at the location where the format needs to be adjusted.
[0051] On the other hand, before obtaining the new sample response information corresponding to the new sample mathematical problem text, the method further includes:
[0052] Determine whether the new sample mathematical problem text meets the preset requirements;
[0053] If so, proceed to the step of obtaining the new sample response information corresponding to the new sample mathematical problem text;
[0054] If not, then remove the new sample math problem texts that do not meet the preset requirements from all the new sample math problem texts, and use the remaining sample math problem texts as the new sample math problem texts; proceed to the step of obtaining the new sample response information corresponding to the new sample math problem text.
[0055] On the other hand, obtaining new sample response information corresponding to new sample mathematical problem text includes:
[0056] According to the pre-established correspondence between operators and symbols, the operators in the new sample mathematical problem text are converted into corresponding symbols, the constant letters in the new sample mathematical problem text are replaced with corresponding numbers, and the infix expressions in the new sample mathematical problem text are generated into postfix expressions using a stack; wherein, the symbol is a single character;
[0057] Iterate through each element in the postfix expression;
[0058] The processing is performed according to the characteristics of the element; wherein, the characteristics of the element include at least whether the element is an operand, a unary operator, or a binary operator;
[0059] The expression list is concatenated based on the processed results. If a suffix expression is detected to contain a numerical value, the markers in the expression list are transformed into the corresponding operators according to the correspondence, and the transformed values are used as the new sample response information.
[0060] If the postfix expression is found to contain multiple values, return to the step of traversing each element in the postfix expression;
[0061] The corresponding processing based on the element's condition includes:
[0062] If the current element is detected to be an operand, then the current element is pushed onto the stack;
[0063] If the current element is detected to be a binary operator and the binary operator has not processed any operands, then the two operands at the top of the stack are popped, the binary operation is performed, the calculation result is pushed onto the stack, and the corresponding calculation result and the corresponding part of the new sample mathematical problem text are updated.
[0064] If the current element is detected to be a unary operator and the unary operator has not processed any operands, then pop one operand from the top of the stack, perform the unary operation, push the calculation result onto the stack, and update the corresponding part of the calculation result and the new sample mathematical problem text.
[0065] To address the aforementioned technical problems, the present invention also provides an electronic device, comprising:
[0066] Memory, used to store computer programs;
[0067] A processor is used to implement the steps of the model-based question-answering method described above when executing the computer program.
[0068] To address the aforementioned technical problems, the present invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the model-based question-answering method described above.
[0069] The beneficial effects of this invention are as follows: In this model-based question-answering method, new sample mathematical question texts are generated based on the information of each initial sample mathematical question text, and new sample response information corresponding to the new sample mathematical question texts is obtained, thus expanding the dataset. The model is trained using the initial sample mathematical question text set, initial sample response information, new sample mathematical question texts, and new sample response information, i.e., using the expanded dataset to train the model, thereby improving the model's mathematical computational capabilities. When using the trained model to answer mathematical question texts to predict the response results of the mathematical question texts to be answered, the accuracy of the prediction results is improved. Moreover, when expanding the dataset, generating new sample mathematical question texts based on the information of each initial sample mathematical question text, i.e., fine-tuning the initial sample mathematical question texts, allows for expansion of the training dataset without actually collecting more original data, enhancing the model's generalization ability.
[0070] Furthermore, new sample math problem texts are generated from the information of each initial sample math problem text according to preset generation rules (at least one of number substitution rules and operator addition rules), enabling flexible acquisition of new sample math problem texts. Specifically, new sample math problem texts are generated by replacing the numerical values in the new sample math problem texts with random numbers; new sample math problem texts are generated by adding operators, and according to preset symbol addition rules, the numerical values extracted from the initial sample math problem texts are matched for each operator in the operator list, ensuring that the generated new sample math problem texts conform to the actual calculation situation.
[0071] Before adding the operator to the value to be added according to the numerical addition rules corresponding to the symbol, the number of operator symbols added is controlled by determining whether the generated random number is less than or equal to a second preset value.
[0072] Furthermore, new sample math problem texts can be generated by adjusting the precision of the numerical values in the initial sample math problem texts, replacing the operators, or adjusting the format of the initial sample math problem texts, thereby further expanding the scale and diversity of the dataset.
[0073] Before obtaining new sample response information corresponding to new sample mathematical problem text, it is necessary to determine whether the new sample mathematical problem text meets the preset requirements, and to ensure as much as possible that only valid new sample mathematical problem texts are calculated.
[0074] Based on a pre-established correspondence between operators and symbols, the algorithm converts operators in new sample math problem texts into their corresponding symbols, replaces constant letters in the new sample math problem texts with their corresponding numbers, and generates postfix expressions from infix expressions in the new sample math problem texts using a stack. It iterates through each element in the postfix expression, processing it according to its characteristics. The processed results are then combined into an expression list. If a postfix expression is detected as a numerical value, the symbols in the expression list are transformed into their corresponding operators according to the correspondence, and the transformed value is used as the new sample response information. This process effectively determines the new sample response information corresponding to a new sample math problem text.
[0075] In addition, the present invention also provides an electronic device and a computer-readable storage medium, which have the same or corresponding technical features as the model-based question-answering method mentioned above, and have the same effect. Attached Figure Description
[0076] To more clearly illustrate the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0077] Figure 1 A flowchart illustrating a model-based question-answering method provided in an embodiment of the present invention;
[0078] Figure 2 A flowchart illustrating a method for generating complex computational problems provided in an embodiment of the present invention;
[0079] Figure 3 A flowchart illustrating a method for step-by-step solving of a generated complex computational problem, provided by an embodiment of the present invention;
[0080] Figure 4 This is a structural diagram of an electronic device provided according to an embodiment of the present invention. Detailed Implementation
[0081] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of the present invention.
[0082] The core of this invention is to provide a model-based question-answering method, electronic device, and medium to address the technical problem that the small size and diversity of datasets lead to low mathematical computational power of the model, thereby reducing the model's ability to answer users' mathematical reasoning questions.
[0083] To enable those skilled in the art to better understand the present invention, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. Figure 1 A flowchart of a model-based question-answering method provided in an embodiment of the present invention is shown below. Figure 1 As shown, the method includes:
[0084] S10: Obtain the initial sample mathematical problem text set and the initial sample response information corresponding to each initial sample mathematical problem text;
[0085] S11: Generate new sample mathematical problem texts based on the information of each initial sample mathematical problem text;
[0086] S12: Obtain the new sample response information corresponding to the new sample mathematical problem text;
[0087] S13: Use the initial sample set of mathematical problem texts, the initial sample response information, the new sample mathematical problem texts, and the new sample response information to train the model to obtain a model for answering mathematical problem texts;
[0088] S14: Input the text of the mathematical question to be answered into the model for answering mathematical question text, and output the answer information corresponding to the text of the mathematical question to be answered through the model for answering mathematical question text.
[0089] The initial sample mathematical problem text set is not limited and is determined based on the actual situation. To improve the mathematical computation capability of the model, this embodiment of the invention expands the sample dataset based on the initial sample mathematical problem text set. Expanding the dataset mainly includes two aspects: first, generating complex computational problems (such as generating sin1+cos1); second, solving the generated complex computational problems step by step (i.e., collecting solution steps, such as first solving for the value of sin1, then solving for the value of cos1, and finally adding the values of sin1 and cos1).
[0090] First, the process of generating complex computational problems will be explained.
[0091] When generating new sample mathematical problem texts based on the information of each initial sample mathematical problem text, a preset generation rule is first obtained; the preset generation rule includes at least one of the number substitution rule and the operator addition rule; then, the information of each initial sample mathematical problem text is used to generate new sample mathematical problem texts according to the preset generation rule.
[0092] Specifically, in some embodiments, the preset generation rule is a number substitution rule. Before generating new sample mathematical problem texts from the information of each initial sample mathematical problem text according to the preset generation rule, the method further includes:
[0093] Record the position of the extracted numerical information in the corresponding initial sample mathematical problem text, as well as the number of extracted numerical information.
[0094] The information from each initial sample mathematical problem text is used to generate new sample mathematical problem texts according to preset generation rules, including:
[0095] Generate a random number and use the random number to replace the extracted current numerical information;
[0096] Get the current position of the current numerical information in the initial sample mathematical problem text;
[0097] The text before the current position in the initial sample math problem text, the random number, and the text after the current position in the initial sample math problem text are concatenated to form a new sample math problem text.
[0098] In order to expand the original computational dataset, this embodiment generates different combinations by changing the numbers in the original data, and counts the position and quantity of the numbers to ultimately generate new data variants. The detailed steps and specific implementation are as follows:
[0099] Step 1: Extract the numbers from the original template data and count them.
[0100] We need to extract all the numbers from the original template data. For example, for the original data: 100 - (10 / 2), we can extract the numbers 100, 10, and 2. The extracted numbers will be stored in a list for later processing. To avoid confusion during the replacement process, such as replacing both 10 and 10 in 100 simultaneously, we need to count the number of numbers in the list to accurately locate the corresponding number based on the index.
[0101] Step 2: Generate numbers by cyclically replacing them.
[0102] In each loop, a number is selected from the extracted list of numbers and replaced according to its position in the text. To avoid confusion, the replacement operations must be performed sequentially, ensuring that each number is replaced independently. A random number (usually a random integer between 1 and 5 digits) is generated, and the text before the starting position, the randomly generated number, and the text after the starting position are concatenated to form new data.
[0103] After each loop, record the new text and continue with a similar process for the next number. Repeat this process until enough variations are generated.
[0104] The above describes how different combinations are generated by changing the numbers in the original data, and how the positions and quantities of the numbers are counted to ultimately generate new data variants, thus expanding the dataset. To further expand the dataset, in some embodiments, preset generation rules are used to add rules to the operators, generating new sample mathematical problem texts based on the information of each initial sample mathematical problem text according to the preset generation rules, including:
[0105] Construct a predefined list of operators;
[0106] According to the preset symbol addition rules, each operator in the operator symbol list is matched with the numerical values extracted from the initial sample mathematical problem text, and the matching results are obtained.
[0107] If the matching result is that the operator matches the value, then the operator that matches the value is determined to be the operator to be added;
[0108] Randomly select a value to be added from the matched values, and add the operator to the value to be added according to the value addition rules corresponding to the symbol.
[0109] Get the current position of the value to be added in the initial sample math problem text;
[0110] The text before the current position in the initial sample math problem text, the numerical value with added operators, and the text after the current position in the initial sample math problem text are concatenated to form a new sample math problem text.
[0111] Specifically, according to preset symbol addition rules, each operator in the operator symbol list is matched with numerical values extracted from the initial sample mathematical problem text, and the matching results are obtained as follows:
[0112] Get the operation results obtained by matching the current operator with each value extracted from the initial sample mathematical problem text;
[0113] If all the operation results are detected to be greater than the first preset value, then the matching result is determined to be that the current operator did not match a value.
[0114] If an operation result less than or equal to a first preset value is detected, the matching result is determined as the value matched by the current operator. The first preset value is not limited and is determined based on the actual situation.
[0115] To expand the dataset, this embodiment randomly adds some operators to the data to generate complex and diverse computational expressions. First, a list containing various operators is defined, such as ['!', 'e', 'π', '%', '°', 'sin', 'cos', 'tan', 'ln', 'lg', '√', '^', 'log']. Based on the calculation methods of different operators, different number patterns are matched, and the symbols are added to the data according to rules. The detailed steps are as follows:
[0116] Step 1: Determine whether to add the specified operator.
[0117] The loop iterates based on the order of the symbols in the list. There are no strict rules for adding operators; the rules are determined by the actual operator. For example, the factorial symbol ! can only be added after a single number from 1 to 9 because factorial calculations involve large values. If no such number is matched, the addition of the factorial symbol is skipped. For the exponentiation operator ^, to avoid excessively large values, it must match a value of at most two digits, and the condition that no other operator has been added before or after the number is met. For other operators ['e', 'π', '%', '°', 'sin', 'cos', 'tan', 'ln', 'lg', '√', 'log'], the condition that no other symbol has been added before or after the number is met is required. If no such number is matched, the addition of that operator is skipped, and the loop continues.
[0118] Step 2: Combine symbols and numbers.
[0119] Randomly select one number from the matched numbers that meet the requirements as the number to be added, and append symbols such as 'e', 'π', '%', and '°' to the end of the given number. Append symbols such as 'sin', 'cos', 'tan', 'ln', 'lg', and '√' to the beginning of the given number. Since the '^' and 'log' symbols require a base for calculation, they need to be randomly generated during concatenation. Concatenate the text before the starting position, the number with the added special operators, and the text after the starting position to form new data.
[0120] After multiple iterations, several different combinations of data can be generated. For example, for the original data 100 - (10 / 2), different combinations such as 100 - (10 / 2!) or sin(100) - (10 / cos(2)) can be generated.
[0121] Furthermore, when adding operators, the proportion of operators added can be set. Specifically, before adding the operator to be added according to the numerical addition rules corresponding to the symbol, the following steps are also included:
[0122] Generate a random number and determine whether the generated random number is less than or equal to a second preset value;
[0123] If so, proceed to the step of adding the operator to the value to be added according to the numerical addition rules corresponding to the symbol;
[0124] If not, return to the step of randomly selecting a value to be added from the matched values.
[0125] The second preset value is not limited and can be determined according to the actual situation, such as setting a random probability of 15%.
[0126] The above section describes expanding the dataset by randomly adding operators to the data to generate complex and diverse computational expressions. To further expand the dataset, in some embodiments, generating new sample mathematical problem texts from the information of each initial sample mathematical problem text according to preset generation rules includes at least one of the following methods:
[0127] Method 1:
[0128] Obtain the numerical value of the precision to be adjusted from the initial sample mathematical problem text;
[0129] Get the operator applied to the value whose precision needs to be adjusted;
[0130] Determine whether to adjust the precision of the value to be adjusted based on the numerical operation rules of the operator;
[0131] If so, then the precision of the value to be adjusted is adjusted, and the adjusted value is obtained; the current position of the value to be adjusted in the initial sample mathematical problem text is obtained; the text before the current position in the initial sample mathematical problem text, the adjusted value, and the text after the current position in the initial sample mathematical problem text are concatenated to form a new sample mathematical problem text.
[0132] If not, then keep the value of the precision to be adjusted unchanged.
[0133] Method 2:
[0134] Extract the operators from the initial sample mathematical problem text;
[0135] Replace all operators in the initial sample mathematical problem text;
[0136] The initial sample math problem text after replacing the operators is used as the new sample math problem text.
[0137] Method 3:
[0138] Obtain the location of the format to be adjusted from the initial sample mathematical problem text;
[0139] Determine whether to adjust the format at the location where the format needs to be adjusted based on the representation of the operator;
[0140] If so, then adjust the format at the location where the format needs to be adjusted, and use the adjusted initial sample mathematical problem text as the new sample mathematical problem text;
[0141] If not, then cancel the formatting adjustment operation at the location to be adjusted.
[0142] Method 1 expands the dataset by adjusting numerical precision, such as by adding decimals. Method 2 expands the dataset by replacing symbols. Method 3 expands the dataset by adjusting the format of the initial sample mathematical problem text, such as by adding spaces.
[0143] The following describes examples of using the three methods described above to expand the dataset. The diversity of the data is further enriched by randomly adding decimals, changing operators, and adding spaces. The following are some steps and methods for these modifications.
[0144] Step 1: Add decimals.
[0145] To generate more diverse numerical expressions, random decimals are added to the data. For each matched number, a factorial sign is checked. If a factorial sign is present, the number is skipped without adding a decimal. For matched numbers without a factorial sign, a random two-decimal-place number is generated. The text before the starting position, the number with the added decimal, and the text after the starting position are concatenated to form new data. For example, for the original data 100 - (10 / 2), different combinations such as 100.12 - (10 / 2) or 100 - (10.34 / 2) can be generated.
[0146] Step 2: Symbol replacement.
[0147] Symbol substitution not only increases data diversity but also ensures conversion between different formats. For example, replacing the division symbol / with ÷, the multiplication symbol * with ×, and the exponentiation operator ^ with ** can effectively change the appearance and format of expressions.
[0148] Step 3: Add spaces.
[0149] Adding random spaces before and after symbols increases the randomness of expressions while also ensuring clarity and readability in certain situations. Specifically, randomly insert spaces before and after common operators such as addition, subtraction, division, and multiplication. For the exponential operator **, avoid inserting spaces within **, as it is a single operator and separating it changes its meaning.
[0150] Similarly, when adding spaces and decimals, the proportion of addition can be controlled. For example, a random probability of 15% can be set in a loop to control the proportion of special characters, spaces, and decimals present.
[0151] The method provided in this embodiment effectively expands the original dataset by replacing the original numbers, randomly adding special operators, replacing operators, adding spaces, and adding decimals, thereby generating more diverse computational expressions. This transformation makes the generated data more random, which can help improve the model's adaptability to different writing formats during training, while ensuring that the generated expressions remain mathematically sound.
[0152] Figure 2 A flowchart illustrating a method for generating complex computational problems according to an embodiment of the present invention is shown below. Figure 2 As shown, the method includes:
[0153] S15: Original number expansion replacement;
[0154] S16: Add special operators;
[0155] S17: Add decimals, replace symbols, and add spaces.
[0156] This completes the expansion and regeneration of problems involving complex calculations beyond the four basic arithmetic operations. The next step is to solve these generated complex calculation problems step by step. Since the generated new sample mathematical problem text may contain invalid text (e.g., only a leading parenthesis, no closing parenthesis), the following steps are included before obtaining the new sample response information corresponding to the new sample mathematical problem text:
[0157] Determine whether the new sample mathematical problem text meets the preset requirements;
[0158] If so, proceed to the step of obtaining the new sample response information corresponding to the new sample mathematical problem text;
[0159] If not, remove the new sample math problem texts that do not meet the preset requirements from all the new sample math problem texts, and use the remaining sample math problem texts as new sample math problem texts; proceed to the step of obtaining the new sample response information corresponding to the new sample math problem text.
[0160] In some embodiments, obtaining new sample response information corresponding to a new sample mathematical problem text includes:
[0161] According to the pre-established correspondence between operators and symbols, the process involves converting operators in the new sample math problem text into corresponding symbols, replacing constant letters in the new sample math problem text with corresponding numbers, and generating postfix expressions (infix expressions are where operators are placed in the middle of operands, and the order of operations is usually specified by parentheses and operator precedence, e.g., 3+5 is an infix expression) from the new sample math problem text using a stack. (Postfix expressions are where operators immediately follow operands. They do not require parentheses to control the order of operations; the order of operations is determined by the order of operators and stack operations. During calculation, operands are first pushed onto the stack, and when an operator is encountered, the corresponding operand is popped from the stack for calculation. E.g., 53+ is a postfix expression). Here, a symbol is a single character.
[0162] Iterate through each element in the postfix expression;
[0163] The appropriate processing is performed based on the characteristics of the element; the characteristics of the element include at least whether the element is an operand, a unary operator, or a binary operator.
[0164] The expression list is concatenated based on the processed results. If a suffix expression is detected to contain a numerical value, the markers in the expression list are transformed into the corresponding operators according to the correspondence, and the transformed values are used as new sample response information.
[0165] If the postfix expression is found to contain multiple values, return the steps taken to iterate over each element in the postfix expression;
[0166] The corresponding processing based on the element's characteristics includes:
[0167] If the current element is detected as an operand, then push the current element onto the stack;
[0168] If the current element is detected to be a binary operator and the binary operator has not processed any operands, then pop the two operands from the top of the stack, perform the binary operation, push the calculation result onto the stack, and update the corresponding part of the calculation result and the new sample mathematical problem text.
[0169] If the current element is detected to be a unary operator and the unary operator has not processed any operands, pop one operand from the top of the stack, perform the unary operation, push the calculation result onto the stack, and update the corresponding part of the calculation result and the new sample mathematical problem text.
[0170] To help those skilled in the art better understand the process of collecting data for the above-mentioned problem calculation and solution steps (i.e., to obtain complete fine-tuning data, it is necessary to obtain the step-by-step calculation results of the corresponding problem), the following are the detailed steps:
[0171] Step 1: Check if the generated expression is valid. For example, check if the parentheses and special characters in the expression are valid.
[0172] A stack (a data structure that follows the Last-In-First-Out (LIFO) principle, meaning the last element pushed onto the stack is the first to be popped) is used to store left parentheses. When a right parenthesis is encountered, it is matched. If a match is unsuccessful, the entry is skipped. If the stack is empty after processing the entire expression, the parentheses were matched successfully; otherwise, the entry is skipped.
[0173] Store all valid characters or strings, iterate through all valid characters, and delete them one by one from the input expression. If the string is empty after deletion, it means that it only contains valid characters; otherwise, skip that data entry.
[0174] Step 2: Generate postfix expressions.
[0175] To generate a postfix expression from an infix expression using a stack, each special operator in the expression needs to be rewritten with a specific symbol, corresponding to a dictionary list of { "sin": "$", "cos": "@", "tan": "#", "ln": "&", "√": "_", "lg": "`", "log": ";"}. Constants in the expression are replaced with corresponding numbers, such as assigning 'e' to 2.718281, and corresponding operators like * and parentheses are inserted to ensure the computational relationship between symbols and numbers.
[0176] Step 3: Generate the calculation results step by step based on the postfix expression.
[0177] Create an empty stack to store operands, and initialize a flag indicating whether operands have been processed. Iterate through each element in the postfix expression, determining whether it's an operand or an operator. If the current element is a binary operator (+-* / ^) and no operands have been processed, pop the top two operands from the stack, perform the binary operation, push the result onto the stack, set the flag to True, and update the corresponding parts of the original expression with the calculated result. If the current element is a unary operator (e.g., $@#&_!`) and no operands have been processed, pop one operand from the stack, perform the unary operation, push the result onto the stack, set the flag to True, and update the corresponding parts of the original expression with the calculated result. If the current element is an operand, push it directly onto the stack.
[0178] Repeat the above steps continuously. In each iteration, concatenate the expression list and check the length of the postfix expression. If the length is less than or equal to one value, exit the loop. Then, replace the special characters in the expression list with the original sin, cos, etc. expressions, and round all floating numbers to three decimal places to obtain the complete calculation process.
[0179] The final fine-tuning data will look like this:
[0180] √(62528)-567.15=250.056-567.15=-317.094;
[0181] (232*e)*17=(232*2.718)*17=630.641*17=10720.9;
[0182] (28%)-cos(82)=(28 / 100)-cos(82)=0.28-cos(82)=0.28-0.95=-0.67;
[0183] cos(6) / log(52719)(5.62) / √(62389)-lg(7)=0.96 / log(52719)(5.62) / √(62389)-lg(7)=0.96 / 6.298 / √(62389)-lg(7)=0.152 / √(62389)-lg(7)=0.152 / 249.778-lg(7)=0.001-lg(7)=0.001-0.845=-0.844;
[0184] ln(9) / 132=2.197 / 132=0.017.
[0185] Figure 3 A flowchart illustrating a method for step-by-step solving of a generated complex computational problem, as provided in an embodiment of the present invention, is shown below. Figure 3 As shown, the method includes:
[0186] S18: Check the validity of the generated expression;
[0187] S19: Insert specific tags to generate postfix expressions;
[0188] S20: Generate calculation results step by step in a loop;
[0189] S21: Result concatenation, special symbols are replaced.
[0190] The above process enables the collection of problem calculation and solution steps.
[0191] The method provided in this embodiment of the invention utilizes an initial sample mathematical problem text set (i.e., the original dataset template), changes the numbers, randomly adds operators to the numbers according to the characteristics of special operators, randomly adds decimals after the numbers, replaces the operators in the expression, adds spaces, and obtains a construction method containing complex calculation problem expression data. At the same time, it also provides an expression verification and a data expansion method for gradually iterating and calculating to generate complete calculation and solution steps.
[0192] After obtaining the initial sample set of mathematical problem texts, initial sample response information, new sample mathematical problem texts, and new sample response information, the model is trained using these resources to obtain a model for answering mathematical problem texts. When a mathematical problem text to be answered is obtained, it can be input into the model for answering mathematical problem texts, and the model will output the corresponding response information.
[0193] In implementation, to improve the accuracy of the model's prediction of response information for the mathematical problem text to be answered, after training the model using the initial sample mathematical problem text set, initial sample response information, new sample mathematical problem text, and new sample response information to obtain a model for answering mathematical problem texts, before inputting the mathematical problem text to be answered into the model for answering mathematical problem texts, the following steps are also included:
[0194] Obtain a set of mathematical problem texts for testing;
[0195] Each test math problem text in the set of test math problem texts is input into the model for answering math problem texts, and the model for answering math problem texts outputs the answer information corresponding to each test math problem text.
[0196] Obtain the actual response information corresponding to the text of each test math problem;
[0197] If the accuracy of the response information of the set of mathematical problem texts used for testing is greater than or equal to a preset value, proceed to the step of inputting the mathematical problem text to be answered into the model used to answer the mathematical problem text.
[0198] If the accuracy of the response information in the set of mathematical problem texts used for testing is less than a preset value, the process returns to the step of generating new sample mathematical problem texts based on the information of each initial sample mathematical problem text.
[0199] Without limiting the preset values, the predicted response information of the mathematical problem text set used for testing is exactly the same as the actual response information, indicating that the higher the accuracy of the model prediction results used to answer the mathematical problem text, the better.
[0200] In this method, the accuracy of the model prediction for answering the mathematical problem text is judged by using a set of mathematical problem texts for testing. Only when the accuracy of the response information of the set of mathematical problem texts for testing is greater than or equal to a preset value is the model used to answer the mathematical problem text to predict the mathematical problem text to be answered, thus ensuring the accuracy of the model prediction results as much as possible.
[0201] This invention expands the dataset using the method described above. Numerical computation datasets play a crucial role in improving mathematical computation capabilities during large model training. These include:
[0202] 1. Strengthen basic mathematical skills.
[0203] Arithmetic operations: Through a large number of addition, subtraction, multiplication and division operations, the model is able to better understand and perform basic arithmetic operations.
[0204] 2. Improve logical reasoning ability.
[0205] Problem decomposition: Mathematical problems often need to be broken down into multiple steps to solve, which helps the model learn how to break down complex problems into smaller, manageable parts.
[0206] 3. Improve calculation accuracy.
[0207] Numerical stability: By handling a large number of mathematical calculations, the model can learn how to maintain numerical stability and avoid computational errors.
[0208] Accuracy training: Numerical computation datasets can help models be more accurate when dealing with precise numerical values such as decimals and fractions.
[0209] Numerical computation datasets allow for more accurate evaluation of model performance and identification of its weaknesses in mathematical computation. Based on the evaluation results, targeted optimizations can be made to the model. Expanding the computational data aims to increase the diversity and scale of the dataset, thereby enhancing the performance and generalization ability of large models.
[0210] For tasks that rely on large amounts of data for effective training, the size and diversity of the dataset are key factors determining model performance. Building upon commonly used open-source datasets that typically only include basic addition, subtraction, multiplication, and division, expanding the dataset exposes the model to more diverse training samples containing complex symbols and special characters, helping it learn to cope with different scenarios, features, and mutations. This method accurately and efficiently generates complex and diverse computational fine-tuning data, significantly increasing the size of the dataset and providing data support for enhancing computational capabilities in fine-tuning training of large models.
[0211] In the above embodiments, the model-based question-answering method has been described in detail. This invention also provides embodiments of a model-based question-answering device and electronic device. It should be noted that this invention describes the device embodiments from two perspectives: one based on functional modules, and the other based on hardware.
[0212] The model-based question-answering device provided in the embodiments of the present invention, from the perspective of functional modules, includes:
[0213] The first acquisition module is used to acquire the initial sample mathematical problem text set and the initial sample response information corresponding to each initial sample mathematical problem text.
[0214] The generation module is used to generate new sample mathematical problem texts based on the information of each initial sample mathematical problem text.
[0215] The second acquisition module is used to acquire new sample response information corresponding to new sample mathematical problem texts.
[0216] The training module is used to train the model using the initial sample set of math problem texts, the initial sample response information, the new sample math problem texts, and the new sample response information, so as to obtain a model for answering math problem texts.
[0217] The input and output module is used to input the text of the mathematical question to be answered into the model for answering the mathematical question text, and output the corresponding answer information of the mathematical question text to be answered through the model for answering the mathematical question text.
[0218] In some embodiments, the model-based question-answering device further includes:
[0219] The recording module is used to record the position of the extracted numerical information in the corresponding initial sample mathematical problem text, as well as the number of extracted numerical information.
[0220] In some embodiments, the model-based question-answering device further includes:
[0221] The generation and judgment module is used to generate random numbers and determine whether the generated random numbers are less than or equal to a second preset value; if yes, the addition module is triggered; if no, the extraction module is triggered.
[0222] The add module is used to add the operator to the value to be added according to the numerical addition rules corresponding to the symbol;
[0223] The extraction module is used to randomly extract a value to be added from the matched values.
[0224] In some embodiments, the model-based question-answering device further includes:
[0225] The first judgment module is used to determine whether the new sample mathematical problem text meets the preset requirements; if yes, the second acquisition module is triggered; if no, the elimination module is triggered.
[0226] The elimination module is used to remove new sample math problem texts that do not meet the preset requirements from all new sample math problem texts, and use the remaining sample math problem texts as new sample math problem texts; and trigger the second acquisition module.
[0227] Since the embodiments of the apparatus and the embodiments of the method correspond to each other, please refer to the description of the embodiments of the method for the embodiments of the apparatus, which will not be repeated here.
[0228] Figure 4 This is a structural diagram of an electronic device provided according to an embodiment of the present invention. This embodiment is based on a hardware perspective, such as... Figure 4 As shown, the electronic device includes:
[0229] Memory 20 is used to store computer programs;
[0230] The processor 21 is configured to implement the steps of the model-based question-answering method as described in the above embodiments when executing a computer program.
[0231] The processor 21 may include one or more processing cores, such as a quad-core processor or an octa-core processor. The processor 21 may be implemented using at least one of the following hardware forms: Digital Signal Processor (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array. The processor 21 may also include a main processor and a coprocessor. The main processor, also known as the Central Processing Unit (CPU), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, the processor 21 may integrate a Graphics Processing Unit (GPU), which is responsible for rendering and drawing the content to be displayed on the screen. In some embodiments, the processor 21 may also include an Artificial Intelligence (AI) processor, which handles computational operations related to machine learning.
[0232] The memory 20 may include one or more computer-readable storage media, which may be non-transitory. The memory 20 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In this embodiment, the memory 20 is used to store at least the following computer program 201, which, after being loaded and executed by the processor 21, is capable of implementing the relevant steps of the model-based question-answering method disclosed in any of the foregoing embodiments. In addition, the resources stored in the memory 20 may also include an operating system 202 and data 203, and the storage method may be temporary or permanent storage. The operating system 202 may include Windows, Unix, Linux, etc. The data 203 may include, but is not limited to, the data involved in the aforementioned model-based question-answering method.
[0233] In some embodiments, the electronic device may further include a display screen 22, an input / output interface 23, a communication interface 24, a power supply 25, and a communication bus 26.
[0234] Those skilled in the art will understand that Figure 4 The structures shown do not constitute a limitation on electronic devices and may include more or fewer components than those shown.
[0235] The electronic device provided in this embodiment of the invention includes a memory and a processor. When the processor executes a program stored in the memory, it can implement the following method: a model-based question-and-answer method, with the same effect as above.
[0236] The present invention also provides a computer program product, including a computer program / instruction that, when executed by a processor, implements the steps of the model-based question-answering method described above.
[0237] Finally, the present invention also provides an embodiment corresponding to a computer-readable storage medium. The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps described in the above method embodiments.
[0238] It is understood that if the methods in the above embodiments are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and executes all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0239] The computer-readable storage medium provided by this invention includes the model-based question-answering method mentioned above, and has the same effect.
[0240] The foregoing has provided a detailed description of the model-based question-answering method, electronic device, and medium provided by this invention. The various embodiments in the specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to the method section. It should be noted that those skilled in the art can make several improvements and modifications to this invention without departing from the principles of this invention, and these improvements and modifications also fall within the protection scope of this invention.
[0241] It should also be noted that, in this specification, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
Claims
1. A model-based question-answering method, characterized in that, include: Obtain the initial sample math problem text set and the initial sample response information corresponding to each initial sample math problem text; Generate new sample mathematical problem texts based on the information from each initial sample mathematical problem text; Obtain new sample response information corresponding to new sample mathematical problem text; The model is trained using the initial sample set of mathematical problem texts, the initial sample response information, the new sample mathematical problem texts, and the new sample response information to obtain a model for answering mathematical problem texts. The text of the mathematical question to be answered is input into the model for answering mathematical question text, and the model for answering mathematical question text outputs the answer information corresponding to the text of the mathematical question to be answered; The process of generating new sample mathematical problem texts based on the information of each initial sample mathematical problem text includes: Obtain preset generation rules; wherein, the preset generation rules include at least one of number replacement rules and operator addition rules; The information of each initial sample mathematical problem text is used to generate the new sample mathematical problem text according to the preset generation rules; The preset generation rule is an operator addition rule, and the process of generating the new sample mathematical problem text according to the preset generation rule for each initial sample mathematical problem text includes: Construct a predefined list of operators; According to the preset symbol addition rules, each operator in the operator symbol list is matched with a value extracted from the initial sample mathematical problem text, and the matching result is obtained. If the matching result is that the operator matches the value, then the operator that matches the value is determined to be the operator to be added; Randomly select a value to be added from the matched values, and add the operator to the value to be added according to the value addition rules corresponding to the symbol. Obtain the current position of the value to be added in the initial sample mathematical problem text; The new sample math problem text is formed by concatenating the text before the current position in the initial sample math problem text, the numerical value with added operators, and the text after the current position in the initial sample math problem text. The step of matching numerical values extracted from the initial sample mathematical problem text for each operator in the operator list according to preset symbol addition rules, and obtaining the matching results, includes: Obtain the calculation results obtained by matching the current operator with each numerical value extracted from the initial sample mathematical problem text; If all the operation results are detected to be greater than the first preset value, then the matching result is determined to be that the current operator did not match a value; If an operation result less than or equal to the first preset value is detected, the matching result is determined to be the numerical value matched by the current operator.
2. The model-based question-answering method according to claim 1, characterized in that, The preset generation rule is a number substitution rule. Before generating the new sample mathematical problem text from the information of each initial sample mathematical problem text according to the preset generation rule, the method further includes: Record the position of the extracted numerical information in the corresponding initial sample mathematical problem text, as well as the number of extracted numerical information; The process of generating the new sample mathematical problem text according to the preset generation rule from the information of each initial sample mathematical problem text includes: Generate a random number and use the random number to replace the extracted current numerical information; Obtain the current position of the current numerical information in the initial sample mathematical problem text; The new sample mathematical problem text is formed by concatenating the text before the current position in the initial sample mathematical problem text, the random number, and the text after the current position in the initial sample mathematical problem text.
3. The model-based question-answering method according to claim 1, characterized in that, Before adding the value to be added to the operator according to the numerical addition rules corresponding to the symbol, the method further includes: Generate a random number and determine whether the generated random number is less than or equal to a second preset value; If so, proceed to the step of adding the operator to be added to the value to be added according to the numerical addition rule corresponding to the symbol; If not, return to the step of randomly selecting a value to be added from the matched values.
4. The model-based question-answering method according to claim 2, characterized in that, The process of generating the new sample mathematical problem text from the information of each initial sample mathematical problem text according to the preset generation rule includes at least one of the following methods: Method 1: Obtain the value of the precision to be adjusted from the initial sample mathematical problem text; Obtain the operator applied to the value whose precision needs to be adjusted; Determine whether to adjust the precision of the value to be adjusted based on the numerical operation rules of the operator; If so, then the precision of the value to be adjusted is adjusted, and the value after precision adjustment is obtained; the current position of the value to be adjusted in the initial sample mathematical problem text is obtained; the text before the current position in the initial sample mathematical problem text, the value after precision adjustment, and the text after the current position in the initial sample mathematical problem text are concatenated to form the new sample mathematical problem text; If not, then keep the value of the precision to be adjusted unchanged; Method 2: Obtain each operator from the initial sample mathematical problem text; Replace each operator in the initial sample mathematical problem text; The initial sample mathematical problem text after replacing the operator symbols is used as the new sample mathematical problem text; Method 3: Obtain the location of the format to be adjusted from the initial sample mathematical problem text; Determine whether to perform format adjustment at the location where the format to be adjusted is based on the representation of the operator; If so, the format is adjusted at the position where the format needs to be adjusted, and the adjusted initial sample mathematical problem text is used as the new sample mathematical problem text. If not, then cancel the format adjustment operation at the location where the format needs to be adjusted.
5. The model-based question-answering method according to any one of claims 2 to 4, characterized in that, Before obtaining the new sample response information corresponding to the new sample mathematical problem text, the process also includes: Determine whether the new sample mathematical problem text meets the preset requirements; If so, proceed to the step of obtaining the new sample response information corresponding to the new sample mathematical problem text; If not, then remove the new sample math problem texts that do not meet the preset requirements from all the new sample math problem texts, and use the remaining sample math problem texts as the new sample math problem texts; proceed to the step of obtaining the new sample response information corresponding to the new sample math problem text.
6. The model-based question-answering method according to claim 5, characterized in that, The process of obtaining new sample response information corresponding to new sample mathematical problem text includes: According to the pre-established correspondence between operators and symbols, the operators in the new sample mathematical problem text are converted into corresponding symbols, the constant letters in the new sample mathematical problem text are replaced with corresponding numbers, and the infix expressions in the new sample mathematical problem text are generated into postfix expressions using a stack; wherein, the symbol is a single character; Iterate through each element in the postfix expression; The processing is performed according to the characteristics of the element; wherein, the characteristics of the element include at least whether the element is an operand, a unary operator, or a binary operator; The expression list is concatenated based on the processed results. If a suffix expression is detected to contain a numerical value, the markers in the expression list are transformed into the corresponding operators according to the correspondence, and the transformed values are used as the new sample response information. If the postfix expression is found to contain multiple values, return to the step of traversing each element in the postfix expression; The corresponding processing based on the element's condition includes: If the current element is detected to be an operand, then the current element is pushed onto the stack; If the current element is detected to be a binary operator and the binary operator has not processed any operands, then the two operands at the top of the stack are popped, the binary operation is performed, the calculation result is pushed onto the stack, and the corresponding calculation result and the corresponding part of the new sample mathematical problem text are updated. If the current element is detected to be a unary operator and the unary operator has not processed any operands, then pop one operand from the top of the stack, perform the unary operation, push the calculation result onto the stack, and update the corresponding part of the calculation result and the new sample mathematical problem text.
7. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor, configured to implement the steps of the model-based question-answering method as described in any one of claims 1 to 6 when executing the computer program.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the model-based question-answering method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Question and answer method, system and device based on pre-training model, medium and product
CN118886494A
Method for providing mathematical principle prediction serivce for math word problem using neural machine translation and math corpus
KR101986721B1